disable reload default scripts by default

This commit is contained in:
Dante Ruiz 2017-07-20 21:15:00 +01:00
parent 87d9dfd243
commit 3c862c34b2
4 changed files with 51 additions and 6 deletions

View file

@ -16,6 +16,7 @@ import Qt.labs.settings 1.0
import "../../styles-uit" import "../../styles-uit"
import "../../controls-uit" as HifiControls import "../../controls-uit" as HifiControls
import "../../windows" import "../../windows"
import "../"
Rectangle { Rectangle {
id: root id: root
@ -26,10 +27,26 @@ Rectangle {
property var scripts: ScriptDiscoveryService; property var scripts: ScriptDiscoveryService;
property var scriptsModel: scripts.scriptsModelFilter property var scriptsModel: scripts.scriptsModelFilter
property var runningScriptsModel: ListModel { } property var runningScriptsModel: ListModel { }
property bool developerMenuEnabled: false
property bool isHMD: false property bool isHMD: false
color: hifi.colors.baseGray color: hifi.colors.baseGray
LetterboxMessage {
id: letterBoxMessage
z: 999
visible: false
}
function letterBox(glyph, text, message) {
letterBoxMessage.headerGlyph = glyph;
letterBoxMessage.headerText = text;
letterBoxMessage.text = message;
letterBoxMessage.visible = true;
letterBoxMessage.popupRadius = 0;
}
Connections { Connections {
target: ScriptDiscoveryService target: ScriptDiscoveryService
onScriptCountChanged: updateRunningScripts(); onScriptCountChanged: updateRunningScripts();
@ -38,6 +55,7 @@ Rectangle {
Component.onCompleted: { Component.onCompleted: {
isHMD = HMD.active; isHMD = HMD.active;
updateRunningScripts(); updateRunningScripts();
developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus");
} }
function updateRunningScripts() { function updateRunningScripts() {
@ -78,6 +96,14 @@ Rectangle {
scripts.stopAllScripts(); scripts.stopAllScripts();
} }
function canEditScript(script) {
if ((script === "controllerScripts.js") || (script === "defaultScripts.js")) {
return developerMenuEnabled;
}
return true;
}
Flickable { Flickable {
id: flickable id: flickable
width: tabletRoot.width width: tabletRoot.width
@ -125,6 +151,7 @@ Rectangle {
expandSelectedRow: true expandSelectedRow: true
itemDelegate: Item { itemDelegate: Item {
property bool canEdit: canEditScript(styleData.value);
anchors { anchors {
left: parent ? parent.left : undefined left: parent ? parent.left : undefined
leftMargin: hifi.dimensions.tablePadding leftMargin: hifi.dimensions.tablePadding
@ -148,7 +175,7 @@ Rectangle {
HiFiGlyphs { HiFiGlyphs {
id: reloadButton id: reloadButton
text: hifi.glyphs.reloadSmall text: ((canEditScript(styleData.value)) ? hifi.glyphs.reloadSmall : hifi.glyphs.lock)
color: reloadButtonArea.pressed ? hifi.colors.white : parent.color color: reloadButtonArea.pressed ? hifi.colors.white : parent.color
anchors { anchors {
top: parent.top top: parent.top
@ -158,7 +185,17 @@ Rectangle {
MouseArea { MouseArea {
id: reloadButtonArea id: reloadButtonArea
anchors { fill: parent; margins: -2 } anchors { fill: parent; margins: -2 }
onClicked: reloadScript(model.url) onClicked: {
if (canEdit) {
reloadScript(model.url)
} else {
letterBox(hifi.glyphs.lock,
"Need Developer Mode On",
"In order to edit, delete or reload this script," +
" turn on Developer Mode by going to:" +
" Menu > Settings > Developer Menus");
}
}
} }
} }
@ -166,6 +203,7 @@ Rectangle {
id: stopButton id: stopButton
text: hifi.glyphs.closeSmall text: hifi.glyphs.closeSmall
color: stopButtonArea.pressed ? hifi.colors.white : parent.color color: stopButtonArea.pressed ? hifi.colors.white : parent.color
visible: canEditScript(styleData.value)
anchors { anchors {
top: parent.top top: parent.top
right: parent.right right: parent.right
@ -174,7 +212,11 @@ Rectangle {
MouseArea { MouseArea {
id: stopButtonArea id: stopButtonArea
anchors { fill: parent; margins: -2 } anchors { fill: parent; margins: -2 }
onClicked: stopScript(model.url) onClicked: {
if (canEdit) {
stopScript(model.url)
}
}
} }
} }

View file

@ -337,5 +337,6 @@ Item {
readonly property string playback_play: "\ue01d" readonly property string playback_play: "\ue01d"
readonly property string stop_square: "\ue01e" readonly property string stop_square: "\ue01e"
readonly property string avatarTPose: "\ue01f" readonly property string avatarTPose: "\ue01f"
readonly property string lock: "\ue006"
} }
} }

View file

@ -98,10 +98,10 @@ Menu::Menu() {
// Edit > Running Scripts // Edit > Running Scripts
auto action = addActionToQMenuAndActionHash(editMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J); auto action = addActionToQMenuAndActionHash(editMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J);
connect(action, &QAction::triggered, [] { connect(action, &QAction::triggered, [] {
static const QUrl widgetUrl("hifi/dialogs/RunningScripts.qml");
static const QUrl tabletUrl("../../hifi/dialogs/TabletRunningScripts.qml"); static const QUrl tabletUrl("../../hifi/dialogs/TabletRunningScripts.qml");
static const QString name("RunningScripts"); auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
qApp->showDialog(widgetUrl, tabletUrl, name); TabletProxy* tablet = tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system");
tablet->pushOntoStack(tabletUrl);
}); });
// Edit > Open and Run Script from File... [advanced] // Edit > Open and Run Script from File... [advanced]

View file

@ -38,6 +38,7 @@
#include "scripting/AccountScriptingInterface.h" #include "scripting/AccountScriptingInterface.h"
#include "scripting/HMDScriptingInterface.h" #include "scripting/HMDScriptingInterface.h"
#include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h"
#include "scripting/MenuScriptingInterface.h"
#include <Preferences.h> #include <Preferences.h>
#include <ScriptEngines.h> #include <ScriptEngines.h>
#include "FileDialogHelper.h" #include "FileDialogHelper.h"
@ -203,6 +204,7 @@ void Web3DOverlay::loadSourceURL() {
_webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data()); _webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
_webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data()); _webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
_webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("pathToFonts", "../../"); _webSurface->getSurfaceContext()->setContextProperty("pathToFonts", "../../");
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface.data()); tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface.data());