// Copyright (C) 2026 Danilo M. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. import QtQuick import "../.." import "../../assistant/Presets.js" as Presets // The assistant canvas's Ask row: the canned questions offered for the // staged files. They live in Prefs and the canvas reads them live, so // unlike the daemon's settings these need no restart. The page edits a // draft here; Save hands it to Prefs. Module { id: pm name: "presets" label: "Ask presets" // nf-fa-lightbulb_o, present in Inconsolata Nerd Font. icon: "" settings: true group: "Assistant" keywords: ["assistant", "canvas", "ask", "question", "prompt", "summarize", "files"] searchItems: pm.shown.map((p, i) => ({ text: p.label + ": " + p.prompt, key: "preset:" + i })) // null while there are no edits: the page then shows Prefs' list. property var draft: null // Reset to defaults was pressed: Save drops the saved list rather than // saving a copy of the defaults, so later default changes still arrive. property bool resetting: false readonly property var shown: pm.draft ?? Presets.list(Prefs.presets) // Presets with an empty label or question, by index; Save waits. readonly property bool valid: pm.shown.every(p => p.label.trim() !== "" && p.prompt.trim() !== "") dirty: pm.draft !== null function edit(list) { pm.draft = list; pm.resetting = false; } function reset() { pm.draft = Presets.list(null).map(p => Object.assign({}, p, { kinds: p.kinds.slice() })); pm.resetting = true; } function save() { if (pm.resetting) Prefs.resetPresets(); else Prefs.setPresets(pm.draft); pm.discard(); } function discard() { pm.draft = null; pm.resetting = false; } page: Component { Page { title: "Ask presets" actions: Component { SaveBar { dirty: pm.dirty; valid: pm.valid; note: "every preset needs a label and a question" onSave: pm.save(); onDiscard: pm.discard() } } PresetsPage { width: parent.width; owner: pm } } } }