diff options
Diffstat (limited to 'desktop/modules/mimeapps/MimeAppsModule.qml')
| -rw-r--r-- | desktop/modules/mimeapps/MimeAppsModule.qml | 30 |
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 } } } |
