| 87 | } |
| 88 | |
| 89 | int |
| 90 | TWScriptableWindow::addScriptsToMenu(QMenu *menu, TWScriptList *scripts) |
| 91 | { |
| 92 | int count = 0; |
| 93 | foreach (QObject *obj, scripts->children()) { |
| 94 | Tw::Scripting::ScriptObject *scriptObject = qobject_cast<Tw::Scripting::ScriptObject*>(obj); |
| 95 | if (scriptObject) { |
| 96 | if (!scriptObject->isEnabled()) |
| 97 | continue; |
| 98 | if (scriptObject->getContext().isEmpty() || scriptObject->getContext() == scriptContext()) { |
| 99 | QAction *a = menu->addAction(scriptObject->getTitle()); |
| 100 | connect(scriptObject, &Tw::Scripting::ScriptObject::destroyed, this, [this,a]() { scriptsMenu->removeAction(a); }); |
| 101 | if (!scriptObject->getKeySequence().isEmpty()) |
| 102 | a->setShortcut(scriptObject->getKeySequence()); |
| 103 | // a->setEnabled(script->isEnabled()); |
| 104 | // give the action an object name so it could possibly included in the |
| 105 | // customization process of keyboard shortcuts in the future |
| 106 | a->setObjectName(QString::fromLatin1("Script: %1").arg(scriptObject->getTitle())); |
| 107 | a->setStatusTip(scriptObject->getDescription()); |
| 108 | connect(a, &QAction::triggered, this, [this, scriptObject](){ runScript(scriptObject); }); |
| 109 | ++count; |
| 110 | } |
| 111 | continue; |
| 112 | } |
| 113 | TWScriptList *list = qobject_cast<TWScriptList*>(obj); |
| 114 | if (list) { |
| 115 | QMenu *m = menu->addMenu(list->getName()); |
| 116 | if (addScriptsToMenu(m, list) == 0) { |
| 117 | menu->removeAction(m->menuAction()); |
| 118 | } |
| 119 | else { |
| 120 | ++count; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | return count; |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | TWScriptableWindow::runScript(QObject* scriptObj, Tw::Scripting::Script::ScriptType scriptType) |
nothing calls this directly
no test coverage detected