aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/mimeapps/MimeAppsModule.qml
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-26 11:25:19 +0100
committerDanilo M. <danix@danix.xyz>2026-11-26 11:25:19 +0100
commit262d125471c7d5a06da33af8d7995570dda8f97d (patch)
tree394442af3b33190c326cd205a138b8037289dae9 /desktop/modules/mimeapps/MimeAppsModule.qml
parentf19453f25a04b0760ff1303388d136a8b60c2c04 (diff)
downloadquickshell-262d125471c7d5a06da33af8d7995570dda8f97d.tar.gz
quickshell-262d125471c7d5a06da33af8d7995570dda8f97d.zip
feat(mimeapps): stage edits behind Save and Discard
Picks and removes went straight to mimeapps.list, unlike every other settings page, which edits a draft and commits from the SaveBar in the header. The page now edits a draft of the file text; Save writes it, Discard drops it, and the sidebar marks unsaved changes through dirty. The draft follows the file while nothing is pending, so an outside change still shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/mimeapps/MimeAppsModule.qml')
-rw-r--r--desktop/modules/mimeapps/MimeAppsModule.qml30
1 files changed, 24 insertions, 6 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 }
}
}