aboutsummaryrefslogtreecommitdiffstats
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/modules/mimeapps/MimeAppsModule.qml30
-rw-r--r--desktop/modules/mimeapps/MimeAppsPage.qml6
-rw-r--r--desktop/modules/mimeapps/README.md3
3 files changed, 30 insertions, 9 deletions
diff --git a/desktop/modules/mimeapps/MimeAppsModule.qml b/desktop/modules/mimeapps/MimeAppsModule.qml
index 7aa9ad9..3b0dd02 100644
--- a/desktop/modules/mimeapps/MimeAppsModule.qml
+++ b/desktop/modules/mimeapps/MimeAppsModule.qml
@@ -36,11 +36,16 @@ Module {
// The file's text as last read or written: FileView.text() lags
// setText() (AGENTS.md), so edits build on this copy.
property string text: ""
- // No write before the first read, which would replace the file with
+ // What the page edits; nothing reaches the file until Save. It follows
+ // the file while there are no unsaved edits.
+ property string draft: ""
+ dirty: mm.draft !== mm.text
+ // No save before the first read, which would replace the file with
// only the edit.
property bool loaded: false
property string error: ""
- readonly property var defaults: M.parse(mm.text)
+ property string notice: ""
+ readonly property var defaults: M.parse(mm.draft)
// { desktopId: [mimes] }, from the .desktop files.
property var apps: ({})
@@ -52,11 +57,19 @@ Module {
scanner.running = false;
scanner.running = true;
}
- function write(t) {
+ function stage(t) { mm.draft = t; mm.notice = ""; mm.error = ""; }
+ function discard() { mm.draft = mm.text; mm.notice = ""; mm.error = ""; }
+ function save() {
if (!mm.loaded) { mm.error = "mimeapps.list not read yet."; return; }
mm.error = "";
+ mm.text = mm.draft;
+ fv.setText(mm.draft);
+ }
+ // The file as read: the draft follows it unless edits are pending.
+ function took(t) {
+ if (!mm.dirty) mm.draft = t;
mm.text = t;
- fv.setText(t);
+ mm.loaded = true;
}
property FileView fv: FileView {
@@ -64,12 +77,13 @@ Module {
printErrors: false
watchChanges: true
onFileChanged: reload()
- onLoaded: { mm.text = text(); mm.loaded = true; }
+ onLoaded: mm.took(text())
// A missing file is an empty one; the first write creates it.
onLoadFailed: err => {
- if (err === FileViewError.FileNotFound) { mm.text = ""; mm.loaded = true; }
+ if (err === FileViewError.FileNotFound) mm.took("");
else mm.error = "Cannot read " + path + ": " + FileViewError.toString(err);
}
+ onSaved: mm.notice = "saved"
onSaveFailed: err => mm.error = "Cannot write " + path + ": " + FileViewError.toString(err)
}
@@ -82,6 +96,10 @@ Module {
page: Component {
Page {
title: "Default apps"
+ actions: Component {
+ SaveBar { dirty: mm.dirty; notice: mm.notice; error: mm.error
+ onSave: mm.save(); onDiscard: mm.discard() }
+ }
MimeAppsPage { width: parent.width; ma: mm }
}
}
diff --git a/desktop/modules/mimeapps/MimeAppsPage.qml b/desktop/modules/mimeapps/MimeAppsPage.qml
index 6103e5c..8ebe880 100644
--- a/desktop/modules/mimeapps/MimeAppsPage.qml
+++ b/desktop/modules/mimeapps/MimeAppsPage.qml
@@ -62,7 +62,7 @@ Column {
.slice(0, 10);
}
function pick(mimes, id) {
- page.ma.write(mimes.reduce((t, m) => M.set(t, m, id), page.ma.text));
+ page.ma.stage(mimes.reduce((t, m) => M.set(t, m, id), page.ma.draft));
page.editing = "";
page.query = "";
page.all = false;
@@ -168,7 +168,7 @@ Column {
anchors { right: parent.right; verticalCenter: parent.verticalCenter }
text: "Remove"
danger: true
- onClicked: page.ma.write(M.remove(page.ma.text, assoc.mimes[0]))
+ onClicked: page.ma.stage(M.remove(page.ma.draft, assoc.mimes[0]))
}
}
@@ -245,7 +245,7 @@ Column {
Small {
width: parent.width
wrapMode: Text.Wrap
- text: "What xdg-open uses, from " + page.ma.file + ". Applies at once."
+ text: "What xdg-open uses, from " + page.ma.file + ". Nothing is written until Save."
}
Text {
diff --git a/desktop/modules/mimeapps/README.md b/desktop/modules/mimeapps/README.md
index e63b7bb..4d960d7 100644
--- a/desktop/modules/mimeapps/README.md
+++ b/desktop/modules/mimeapps/README.md
@@ -16,6 +16,9 @@ The picker lists the apps whose `.desktop` declares the type (one `grep` over
the XDG applications directories, since Quickshell's `DesktopEntry` has no
`mimeTypes`), or every app with "Show all apps".
+Edits are staged in a draft; Save in the header writes them, Discard drops
+them, as on the other settings pages.
+
Only `[Default Applications]` is edited; `[Added Associations]`, comments and
other sections are left as they are. Not handled: system-wide and
desktop-specific `mimeapps.list` files.