ScriptApp.h header

#include <ew/app/ScriptApp.h>

Namespace ew::app

Command struct

struct ew::app::Command

One registered command: its display name and the JavaScript function (a QVariant-wrapped callable) that runs it.

Members

QString ew::app::ScriptApp::Command::name

The command's display name.

QVariant ew::app::ScriptApp::Command::function

The JavaScript callable (QVariant-wrapped) that runs the command.

ScriptApp class

class ew::app::ScriptApp

The application-level bridge exposed to a ScriptHost as the global JavaScript object app – install it with host.registerGlobal("app", &scriptApp). Where the world bridge (ScriptWorld) is about reading and changing project data, app is about extending the application: a script registers named commands that then appear in the app's script-command menu and run on demand, so a macro is no longer a one-shot – it becomes a reusable workflow the user can invoke whenever they like (DESIGN §6.11 extensibility).

The command's function is received as a QVariant (which wraps the JavaScript callable the engine passes) so this public header stays QtQml-free – the QJSValue handling lives entirely in the implementation, matching ScriptHost's discipline of keeping QtQml a private dependency. The bridge must live on the ScriptHost's thread and must not outlive its engine (the wrapped callables reference it).

Members

ew::app::ScriptApp::ScriptApp(QObject *parent=nullptr)

parent is the usual QObject parent for lifetime management.

Q_INVOKABLE void ew::app::ScriptApp::registerCommand(const QString &name, const QVariant &function)

Registers a command named name that runs function (a JavaScript callable, passed by the engine as a QVariant) when invoked, adding it to the app's script-command menu. Registering the same name again replaces the earlier command in place (so re-running a macro that registers commands does not duplicate them). A no-op for an empty name or a non-callable function. Emits commandsChanged.

QStringList ew::app::ScriptApp::commandNames() const

The names of the registered commands, in registration order – the list the desktop builds its script-command menu from.

bool ew::app::ScriptApp::hasCommand(const QString &name) const

True when a command named name is registered.

QString ew::app::ScriptApp::runCommand(const QString &name)

Runs the command named name by calling its function. Returns an empty string on success (or when no such command exists); otherwise the JavaScript error message the function threw, so the caller can surface it. The function runs on this bridge's (the engine's) thread.

void ew::app::ScriptApp::clearCommands()

Forgets every registered command (e.g. when the project the commands were written against is closed). Emits commandsChanged when anything was removed.

void ew::app::ScriptApp::commandsChanged()

Emitted whenever the set of registered commands changes, so the desktop can rebuild its menu.