mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Merge pull request #4610 from thoys/20367
CR for Job #20367 - Enable getPublicScripts, and getRunningScripts
This commit is contained in:
commit
0a5ae8e7e1
4 changed files with 122 additions and 1 deletions
41
examples/example/misc/listAllScripts.js
Normal file
41
examples/example/misc/listAllScripts.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// listAllScripts.js
|
||||
// examples/example/misc
|
||||
//
|
||||
// Created by Thijs Wenker on 7 Apr 2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Outputs the running, public and local scripts to the console.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var runningScripts = ScriptDiscoveryService.getRunning();
|
||||
print("Running Scripts:");
|
||||
for (var i = 0; i < runningScripts.length; i++) {
|
||||
print(" - " + runningScripts[i].name + (runningScripts[i].local ? "[Local]" : "") + " {" + runningScripts[i].url + "}");
|
||||
}
|
||||
|
||||
var localScripts = ScriptDiscoveryService.getLocal();
|
||||
print("Local Scripts:");
|
||||
for (var i = 0; i < localScripts.length; i++) {
|
||||
print(" - " + localScripts[i].name + " {" + localScripts[i].path + "}");
|
||||
}
|
||||
|
||||
// recursive function to walk through all folders in public scripts
|
||||
// adding 2 spaces to the prefix per depth level
|
||||
function displayPublicScriptFolder(nodes, prefix) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i].type == "folder") {
|
||||
print(prefix + "<" + nodes[i].name + ">");
|
||||
displayPublicScriptFolder(nodes[i].children, " " + prefix);
|
||||
continue;
|
||||
}
|
||||
print(prefix + nodes[i].name + " {" + nodes[i].url + "}");
|
||||
}
|
||||
}
|
||||
|
||||
var publicScripts = ScriptDiscoveryService.getPublic();
|
||||
print("Public Scripts:");
|
||||
displayPublicScriptFolder(publicScripts, " - ");
|
|
@ -3617,6 +3617,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
|
||||
scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget());
|
||||
|
||||
#ifdef HAVE_RTMIDI
|
||||
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
||||
#endif
|
||||
|
|
|
@ -210,3 +210,74 @@ void RunningScriptsWidget::scriptStopped(const QString& scriptName) {
|
|||
void RunningScriptsWidget::allScriptsStopped() {
|
||||
Application::getInstance()->stopAllScripts();
|
||||
}
|
||||
|
||||
QVariantList RunningScriptsWidget::getRunning() {
|
||||
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
||||
QVariantList result;
|
||||
QStringList runningScripts = Application::getInstance()->getRunningScripts();
|
||||
for (int i = 0; i < runningScripts.size(); i++) {
|
||||
QUrl runningScriptURL = QUrl(runningScripts.at(i));
|
||||
if (runningScriptURL.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
|
||||
runningScriptURL = QUrl::fromLocalFile(runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
}
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", runningScriptURL.fileName());
|
||||
resultNode.insert("url", runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
resultNode.insert("local", runningScriptURL.isLocalFile());
|
||||
result.append(resultNode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantList RunningScriptsWidget::getPublic() {
|
||||
return getPublicChildNodes(NULL);
|
||||
}
|
||||
|
||||
QVariantList RunningScriptsWidget::getPublicChildNodes(TreeNodeFolder* parent) {
|
||||
QVariantList result;
|
||||
QList<TreeNodeBase*> treeNodes = Application::getInstance()->getRunningScriptsWidget()->getScriptsModel()
|
||||
->getFolderNodes(parent);
|
||||
for (int i = 0; i < treeNodes.size(); i++) {
|
||||
TreeNodeBase* node = treeNodes.at(i);
|
||||
if (node->getType() == TREE_NODE_TYPE_FOLDER) {
|
||||
TreeNodeFolder* folder = static_cast<TreeNodeFolder*>(node);
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", node->getName());
|
||||
resultNode.insert("type", "folder");
|
||||
resultNode.insert("children", getPublicChildNodes(folder));
|
||||
result.append(resultNode);
|
||||
continue;
|
||||
}
|
||||
TreeNodeScript* script = static_cast<TreeNodeScript*>(node);
|
||||
if (script->getOrigin() == ScriptOrigin::SCRIPT_ORIGIN_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", node->getName());
|
||||
resultNode.insert("type", "script");
|
||||
resultNode.insert("url", script->getFullPath());
|
||||
result.append(resultNode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantList RunningScriptsWidget::getLocal() {
|
||||
QVariantList result;
|
||||
QList<TreeNodeBase*> treeNodes = Application::getInstance()->getRunningScriptsWidget()->getScriptsModel()
|
||||
->getFolderNodes(NULL);
|
||||
for (int i = 0; i < treeNodes.size(); i++) {
|
||||
TreeNodeBase* node = treeNodes.at(i);
|
||||
if (node->getType() != TREE_NODE_TYPE_SCRIPT) {
|
||||
continue;
|
||||
}
|
||||
TreeNodeScript* script = static_cast<TreeNodeScript*>(node);
|
||||
if (script->getOrigin() != ScriptOrigin::SCRIPT_ORIGIN_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", node->getName());
|
||||
resultNode.insert("path", script->getFullPath());
|
||||
result.append(resultNode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
|
||||
void setRunningScripts(const QStringList& list);
|
||||
|
||||
const ScriptsModel* getScriptsModel() { return &_scriptsModel; }
|
||||
|
||||
signals:
|
||||
void stopScriptName(const QString& name);
|
||||
|
||||
|
@ -44,7 +46,10 @@ protected:
|
|||
|
||||
public slots:
|
||||
void scriptStopped(const QString& scriptName);
|
||||
|
||||
QVariantList getRunning();
|
||||
QVariantList getPublic();
|
||||
QVariantList getLocal();
|
||||
|
||||
private slots:
|
||||
void allScriptsStopped();
|
||||
void updateFileFilter(const QString& filter);
|
||||
|
@ -60,6 +65,8 @@ private:
|
|||
ScriptsTableWidget* _recentlyLoadedScriptsTable;
|
||||
QStringList _recentlyLoadedScripts;
|
||||
QString _lastStoppedScript;
|
||||
|
||||
QVariantList getPublicChildNodes(TreeNodeFolder* parent);
|
||||
};
|
||||
|
||||
#endif // hifi_RunningScriptsWidget_h
|
||||
|
|
Loading…
Reference in a new issue