aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/SceneIcons.qml
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/island/SceneIcons.qml')
-rw-r--r--desktop/island/SceneIcons.qml46
1 files changed, 44 insertions, 2 deletions
diff --git a/desktop/island/SceneIcons.qml b/desktop/island/SceneIcons.qml
index 44bcf9c..b8fe6b8 100644
--- a/desktop/island/SceneIcons.qml
+++ b/desktop/island/SceneIcons.qml
@@ -27,11 +27,53 @@ Singleton {
property var map: Icons.defaults
+ // The settings page's draft, null when not editing. Every edit reassigns
+ // draft so the page's bindings fire; Save normalizes and writes.
+ property var draft: null
+ property bool dirty: false
+ readonly property bool valid: draft !== null && Icons.validMap(draft)
+ // Emitted when the draft is dropped, so the page rebuilds its fields:
+ // TextInput breaks its text binding on user edit, so a Discard would
+ // otherwise leave the old glyph on screen.
+ signal reset
+
function iconFor(name) { return Icons.iconFor(root.map, name); }
+ function validGlyph(s) { return Icons.validGlyph(s); }
+
+ function begin() {
+ if (!root.dirty)
+ root.draft = Icons.parse(Icons.serialize(root.map));
+ }
+
+ function editScene(name, text) {
+ if (!root.draft) root.begin();
+ const scenes = Object.assign({}, root.draft.scenes);
+ if (text === "") delete scenes[name];
+ else scenes[name] = text;
+ root.draft = Object.assign({}, root.draft, { scenes: scenes });
+ root.dirty = true;
+ }
+
+ function editGeneric(text) {
+ if (!root.draft) root.begin();
+ root.draft = Object.assign({}, root.draft, { generic: text });
+ root.dirty = true;
+ }
+
+ function discard() {
+ root.draft = null;
+ root.dirty = false;
+ root.reset();
+ }
function save(map) {
- root.map = map;
- fv.setText(Icons.serialize(map));
+ if (!map) return;
+ const out = Icons.normalize(map);
+ root.map = out;
+ fv.setText(Icons.serialize(out));
+ root.draft = null;
+ root.dirty = false;
+ root.reset();
}
FileView {