mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 12:43:19 +02:00
- Scripts JS object renamed to ScriptDiscoveryService.
- Renamed Example script file for the ScriptDiscoveryService. - Moved ScriptDiscoveryService functions to the RunningScriptWidget
This commit is contained in:
parent
af34add63c
commit
0cb5ee5bd1
6 changed files with 82 additions and 129 deletions
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// scriptsExample.js
|
||||
// listAllScripts.js
|
||||
// examples/example/misc
|
||||
//
|
||||
// Created by Thijs Wenker on 7 Apr 2015
|
||||
|
@ -11,13 +11,13 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var runningScripts = Scripts.getRunning();
|
||||
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 = Scripts.getLocal();
|
||||
var localScripts = ScriptDiscoveryService.getLocal();
|
||||
print("Local Scripts:");
|
||||
for (var i = 0; i < localScripts.length; i++) {
|
||||
print(" - " + localScripts[i].name + " {" + localScripts[i].path + "}");
|
||||
|
@ -36,6 +36,6 @@ function displayPublicScriptFolder(nodes, prefix) {
|
|||
}
|
||||
}
|
||||
|
||||
var publicScripts = Scripts.getPublic();
|
||||
var publicScripts = ScriptDiscoveryService.getPublic();
|
||||
print("Public Scripts:");
|
||||
displayPublicScriptFolder(publicScripts, " - ");
|
|
@ -121,7 +121,6 @@
|
|||
#include "scripting/GlobalServicesScriptingInterface.h"
|
||||
#include "scripting/LocationScriptingInterface.h"
|
||||
#include "scripting/MenuScriptingInterface.h"
|
||||
#include "scripting/ScriptsScriptingInterface.h"
|
||||
#include "scripting/SettingsScriptingInterface.h"
|
||||
#include "scripting/WindowScriptingInterface.h"
|
||||
#include "scripting/WebWindowClass.h"
|
||||
|
@ -3609,7 +3608,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
|
||||
scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
|
||||
|
||||
scriptEngine->registerGlobalObject("Scripts", ScriptsScriptingInterface::getInstance());
|
||||
scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget());
|
||||
|
||||
#ifdef HAVE_RTMIDI
|
||||
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
//
|
||||
// ScriptsScriptingInterface.cpp
|
||||
// interface/src/scripting
|
||||
//
|
||||
// Created by Thijs Wenker on 3/31/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include "ScriptsScriptingInterface.h"
|
||||
|
||||
ScriptsScriptingInterface* ScriptsScriptingInterface::getInstance() {
|
||||
static ScriptsScriptingInterface sharedInstance;
|
||||
return &sharedInstance;
|
||||
}
|
||||
|
||||
QVariantList ScriptsScriptingInterface::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 ScriptsScriptingInterface::getPublic() {
|
||||
return getPublicChildNodes(NULL);
|
||||
}
|
||||
|
||||
QVariantList ScriptsScriptingInterface::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 ScriptsScriptingInterface::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;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
//
|
||||
// ScriptsScriptingInterface.h
|
||||
// interface/src/scripting
|
||||
//
|
||||
// Created by Thijs Wenker on 3/31/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_ScriptsScriptingInterface_h
|
||||
#define hifi_ScriptsScriptingInterface_h
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ScriptsScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScriptsScriptingInterface() {};
|
||||
static ScriptsScriptingInterface* getInstance();
|
||||
|
||||
public slots:
|
||||
QVariantList getRunning();
|
||||
QVariantList getPublic();
|
||||
QVariantList getLocal();
|
||||
|
||||
private:
|
||||
QVariantList getPublicChildNodes(TreeNodeFolder* parent);
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptsScriptingInterface_h
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -46,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);
|
||||
|
@ -62,6 +65,8 @@ private:
|
|||
ScriptsTableWidget* _recentlyLoadedScriptsTable;
|
||||
QStringList _recentlyLoadedScripts;
|
||||
QString _lastStoppedScript;
|
||||
|
||||
QVariantList getPublicChildNodes(TreeNodeFolder* parent);
|
||||
};
|
||||
|
||||
#endif // hifi_RunningScriptsWidget_h
|
||||
|
|
Loading…
Reference in a new issue