1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// 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 }
}
}
}
|