Script buttons: a manager to write, try and delete stored scripts

Projet > Scripts > Gérer les scripts… lists the stored scripts with their
icons, and the files that get no button with the reason. For each one it
edits the name, icon (a file copied next to the script, a theme icon, or
the initials), tooltip, shortcut, when it is enabled, and the script
itself; "Tester" saves it and runs it on the current project, one Ctrl+Z
to undo; "Supprimer" deletes it with its icon if no other script uses it.

It only reads and writes the files in the scripts folder, so a script
written here, by hand or by an assistant over the qet MCP server is the
same thing, and the folder's watcher turns each into a button.

ScriptHeader gains compose(), bodyOf() and idFor(), header-only and
tested: what the manager writes reads back as what was typed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-02 09:22:10 +13:00
parent e03e523069
commit 4f47093cb2
7 changed files with 604 additions and 0 deletions
+42
View File
@@ -83,6 +83,48 @@ private slots:
QCOMPARE(h.name, QStringLiteral("Real"));
}
// What the script manager writes reads back as what was typed, and
// leaves the script's code as it was.
void composeReadsBack()
{
const QString body = QStringLiteral("var f = qet.currentFolio();\nqet.addText(f, 'x', 0, 0);\n");
const QString text = ScriptHeader::compose(
QStringLiteral(" Add note "), QStringLiteral("note.svg"),
QStringLiteral("A tip"), QStringLiteral("Ctrl+Alt+N"),
QStringLiteral("conductor"), body);
const ScriptHeader h = ScriptHeader::parse(text, QStringLiteral("add-note"));
QVERIFY2(h.isValid(), qPrintable(h.error));
QCOMPARE(h.name, QStringLiteral("Add note"));
QCOMPARE(h.icon, QStringLiteral("note.svg"));
QCOMPARE(h.tooltip, QStringLiteral("A tip"));
QCOMPARE(h.shortcut, QStringLiteral("Ctrl+Alt+N"));
QCOMPARE(h.context, QStringLiteral("conductor"));
QCOMPARE(ScriptHeader::bodyOf(text), body);
// empty fields and the default context are left out
const QString bare = ScriptHeader::compose(QStringLiteral("A"), QString(), QString(),
QString(), QStringLiteral("canvas"),
QStringLiteral("qet.log(1);"));
QCOMPARE(bare, QStringLiteral("// ==QETScript==\n// @name A\n// @api 1\n"
"// ==/QETScript==\nqet.log(1);\n"));
}
void bodyWithoutHeader()
{
QCOMPARE(ScriptHeader::bodyOf(QStringLiteral("qet.log(1);\n")),
QStringLiteral("qet.log(1);\n"));
}
void idFor()
{
QCOMPARE(ScriptHeader::idFor(QStringLiteral("Numéroter les fils !"), {}),
QStringLiteral("numeroter-les-fils"));
QCOMPARE(ScriptHeader::idFor(QStringLiteral("Add note"),
{QStringLiteral("add-note"), QStringLiteral("add-note-2")}),
QStringLiteral("add-note-3"));
QCOMPARE(ScriptHeader::idFor(QStringLiteral("!!!"), {}), QStringLiteral("script"));
}
// Two windows register one id; the id stays until both are gone, and a
// script that comes back under a new name is listed by that name.
void unregisterAction()