// 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 "../../companion/Lines.js" as Lines // The lines the companion says when focus moves to a program she // recognizes, by its lowercased window class. They live in Prefs and she // reads them live, so a save needs no restart. The page edits a draft here; // Save hands it to Prefs, Reset drops the saved set so Lines.js' defaults // show again. Module { id: pm name: "phrases" label: "Companion phrases" // nf-fa-comment, present in Inconsolata Nerd Font. icon: "\uf075" settings: true group: "Companion" keywords: ["companion", "phrase", "line", "say", "speak", "app", "program", "window", "class", "firefox", "2b"] searchItems: pm.shown.map((a, i) => ({ text: a.cls + ": " + a.lines.join(" / "), key: "app:" + i })) // null while there are no edits: the page then shows the saved set, or // Lines.js' defaults when nothing is saved. property var draft: null // Reset was pressed: Save drops the saved set rather than saving a copy // of the defaults, so later default changes still arrive. property bool resetting: false readonly property var shown: pm.draft ?? Lines.appList(Prefs.companionApps) // Every app needs a class and at least one non-empty phrase; Save waits. readonly property bool valid: pm.shown.every(a => String(a.cls).trim() !== "" && (a.lines || []).some(l => String(l).trim() !== "")) dirty: pm.draft !== null function edit(list) { pm.draft = list; pm.resetting = false; } function reset() { pm.draft = Lines.appList(null); pm.resetting = true; } function save() { if (pm.resetting) Prefs.resetCompanionApps(); else Prefs.setCompanionApps(Lines.toMap(pm.draft)); pm.discard(); } function discard() { pm.draft = null; pm.resetting = false; } page: Component { Page { title: "Companion phrases" actions: Component { SaveBar { dirty: pm.dirty; valid: pm.valid; note: "every app needs a class and a phrase" onSave: pm.save(); onDiscard: pm.discard() } } PhrasesPage { width: parent.width; owner: pm } } } }