mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:17:58 +02:00
Merge pull request #11120 from mukulHF/bug-lock-default-scripts
Disable the ability for a user to edit default scripts if developer settings is not enabled - adjusting values
This commit is contained in:
commit
d812c293e8
6 changed files with 378 additions and 32 deletions
158
interface/resources/qml/hifi/DesktopLetterboxMessage.qml
Normal file
158
interface/resources/qml/hifi/DesktopLetterboxMessage.qml
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
//
|
||||||
|
// LetterboxMessage.qml
|
||||||
|
// qml/hifi
|
||||||
|
//
|
||||||
|
// Created by Dante Ruiz on 7/21/2017
|
||||||
|
// Copyright 2017 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
|
||||||
|
//
|
||||||
|
|
||||||
|
import QtQuick 2.5
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
import "../styles-uit"
|
||||||
|
|
||||||
|
Item {
|
||||||
|
property alias text: popupText.text
|
||||||
|
property alias headerGlyph: headerGlyph.text
|
||||||
|
property alias headerText: headerText.text
|
||||||
|
property alias headerGlyphSize: headerGlyph.size
|
||||||
|
property real popupRadius: hifi.dimensions.borderRadius
|
||||||
|
property real headerTextPixelSize: 22
|
||||||
|
property real popupTextPixelSize: 16
|
||||||
|
property real headerTextMargin: -5
|
||||||
|
property real headerGlyphMargin: -15
|
||||||
|
property bool isDesktop: false
|
||||||
|
FontLoader { id: ralewayRegular; source: "../../fonts/Raleway-Regular.ttf"; }
|
||||||
|
FontLoader { id: ralewaySemiBold; source: "../../fonts/Raleway-SemiBold.ttf"; }
|
||||||
|
visible: false
|
||||||
|
id: letterbox
|
||||||
|
anchors.fill: parent
|
||||||
|
Rectangle {
|
||||||
|
id: textContainer;
|
||||||
|
width: parent.width
|
||||||
|
height: parent.height
|
||||||
|
anchors.centerIn: parent
|
||||||
|
radius: popupRadius
|
||||||
|
color: "white"
|
||||||
|
Item {
|
||||||
|
id: contentContainer
|
||||||
|
width: parent.width - 50
|
||||||
|
height: childrenRect.height
|
||||||
|
anchors.centerIn: parent
|
||||||
|
Item {
|
||||||
|
id: popupHeaderContainer
|
||||||
|
visible: headerText.text !== "" || headerGlyph.text !== ""
|
||||||
|
height: 30
|
||||||
|
// Anchors
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
// Header Glyph
|
||||||
|
HiFiGlyphs {
|
||||||
|
id: headerGlyph
|
||||||
|
visible: headerGlyph.text !== ""
|
||||||
|
// Size
|
||||||
|
height: parent.height
|
||||||
|
// Anchors
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: headerGlyphMargin
|
||||||
|
// Text Size
|
||||||
|
size: headerTextPixelSize*2.5
|
||||||
|
// Style
|
||||||
|
horizontalAlignment: Text.AlignHLeft
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
color: hifi.colors.darkGray
|
||||||
|
}
|
||||||
|
// Header Text
|
||||||
|
Text {
|
||||||
|
id: headerText
|
||||||
|
visible: headerText.text !== ""
|
||||||
|
// Size
|
||||||
|
|
||||||
|
height: parent.height
|
||||||
|
// Anchors
|
||||||
|
anchors.left: headerGlyph.right
|
||||||
|
anchors.leftMargin: headerTextMargin
|
||||||
|
// Text Size
|
||||||
|
font.pixelSize: headerTextPixelSize
|
||||||
|
// Style
|
||||||
|
font.family: ralewaySemiBold.name
|
||||||
|
color: hifi.colors.darkGray
|
||||||
|
horizontalAlignment: Text.AlignHLeft
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
textFormat: Text.StyledText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Popup Text
|
||||||
|
Text {
|
||||||
|
id: popupText
|
||||||
|
// Size
|
||||||
|
width: parent.width
|
||||||
|
// Anchors
|
||||||
|
anchors.top: popupHeaderContainer.visible ? popupHeaderContainer.bottom : parent.top
|
||||||
|
anchors.topMargin: popupHeaderContainer.visible ? 15 : 0
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
// Text alignment
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
horizontalAlignment: Text.AlignHLeft
|
||||||
|
// Style
|
||||||
|
font.pixelSize: popupTextPixelSize
|
||||||
|
font.family: ralewayRegular.name
|
||||||
|
color: hifi.colors.darkGray
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
textFormat: Text.StyledText
|
||||||
|
onLinkActivated: {
|
||||||
|
Qt.openUrlExternally(link)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Left gray MouseArea
|
||||||
|
MouseArea {
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.right: textContainer.left;
|
||||||
|
anchors.top: textContainer.top;
|
||||||
|
anchors.bottom: textContainer.bottom;
|
||||||
|
acceptedButtons: Qt.LeftButton
|
||||||
|
onClicked: {
|
||||||
|
letterbox.visible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Right gray MouseArea
|
||||||
|
MouseArea {
|
||||||
|
anchors.left: textContainer.left;
|
||||||
|
anchors.right: parent.left;
|
||||||
|
anchors.top: textContainer.top;
|
||||||
|
anchors.bottom: textContainer.bottom;
|
||||||
|
acceptedButtons: Qt.LeftButton
|
||||||
|
onClicked: {
|
||||||
|
letterbox.visible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Top gray MouseArea
|
||||||
|
MouseArea {
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.right: parent.right;
|
||||||
|
anchors.top: parent.top;
|
||||||
|
anchors.bottom: textContainer.top;
|
||||||
|
acceptedButtons: Qt.LeftButton
|
||||||
|
onClicked: {
|
||||||
|
letterbox.visible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bottom gray MouseArea
|
||||||
|
MouseArea {
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.right: parent.right;
|
||||||
|
anchors.top: textContainer.bottom;
|
||||||
|
anchors.bottom: parent.bottom;
|
||||||
|
acceptedButtons: Qt.LeftButton
|
||||||
|
onClicked: {
|
||||||
|
letterbox.visible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,9 +17,12 @@ Item {
|
||||||
property alias text: popupText.text
|
property alias text: popupText.text
|
||||||
property alias headerGlyph: headerGlyph.text
|
property alias headerGlyph: headerGlyph.text
|
||||||
property alias headerText: headerText.text
|
property alias headerText: headerText.text
|
||||||
|
property alias headerGlyphSize: headerGlyph.size
|
||||||
property real popupRadius: hifi.dimensions.borderRadius
|
property real popupRadius: hifi.dimensions.borderRadius
|
||||||
property real headerTextPixelSize: 22
|
property real headerTextPixelSize: 22
|
||||||
property real popupTextPixelSize: 16
|
property real popupTextPixelSize: 16
|
||||||
|
property real headerTextMargin: -5
|
||||||
|
property real headerGlyphMargin: -15
|
||||||
FontLoader { id: ralewayRegular; source: "../../fonts/Raleway-Regular.ttf"; }
|
FontLoader { id: ralewayRegular; source: "../../fonts/Raleway-Regular.ttf"; }
|
||||||
FontLoader { id: ralewaySemiBold; source: "../../fonts/Raleway-SemiBold.ttf"; }
|
FontLoader { id: ralewaySemiBold; source: "../../fonts/Raleway-SemiBold.ttf"; }
|
||||||
visible: false
|
visible: false
|
||||||
|
@ -59,7 +62,7 @@ Item {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
// Anchors
|
// Anchors
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: -15
|
anchors.leftMargin: headerGlyphMargin
|
||||||
// Text Size
|
// Text Size
|
||||||
size: headerTextPixelSize*2.5
|
size: headerTextPixelSize*2.5
|
||||||
// Style
|
// Style
|
||||||
|
@ -75,7 +78,7 @@ Item {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
// Anchors
|
// Anchors
|
||||||
anchors.left: headerGlyph.right
|
anchors.left: headerGlyph.right
|
||||||
anchors.leftMargin: -5
|
anchors.leftMargin: headerTextMargin
|
||||||
// Text Size
|
// Text Size
|
||||||
font.pixelSize: headerTextPixelSize
|
font.pixelSize: headerTextPixelSize
|
||||||
// Style
|
// Style
|
||||||
|
|
|
@ -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 "../"
|
||||||
|
|
||||||
ScrollingWindow {
|
ScrollingWindow {
|
||||||
id: root
|
id: root
|
||||||
|
@ -28,10 +29,11 @@ ScrollingWindow {
|
||||||
minSize: Qt.vector2d(424, 300)
|
minSize: Qt.vector2d(424, 300)
|
||||||
|
|
||||||
HifiConstants { id: hifi }
|
HifiConstants { id: hifi }
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
|
@ -39,6 +41,28 @@ ScrollingWindow {
|
||||||
property alias x: root.x
|
property alias x: root.x
|
||||||
property alias y: root.y
|
property alias y: root.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: letterBoxMessage
|
||||||
|
Window {
|
||||||
|
implicitWidth: 400
|
||||||
|
implicitHeight: 300
|
||||||
|
minSize: Qt.vector2d(424, 300)
|
||||||
|
DesktopLetterboxMessage {
|
||||||
|
visible: true
|
||||||
|
headerGlyph: hifi.glyphs.lock
|
||||||
|
headerText: "Developer Mode only"
|
||||||
|
text: ( "In order to edit, delete or reload this script," +
|
||||||
|
" turn on Developer Mode by going to:" +
|
||||||
|
" Menu > Settings > Developer Menus")
|
||||||
|
popupRadius: 0
|
||||||
|
headerGlyphSize: 20
|
||||||
|
headerTextMargin: 2
|
||||||
|
headerGlyphMargin: -3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: refreshTimer
|
id: refreshTimer
|
||||||
|
@ -47,6 +71,15 @@ ScrollingWindow {
|
||||||
running: false
|
running: false
|
||||||
onTriggered: updateRunningScripts();
|
onTriggered: updateRunningScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: checkMenu
|
||||||
|
interval: 1000
|
||||||
|
repeat: true
|
||||||
|
running: false
|
||||||
|
onTriggered: developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus");
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: listModelBuilder
|
id: listModelBuilder
|
||||||
|
@ -64,6 +97,8 @@ ScrollingWindow {
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
isHMD = HMD.active;
|
isHMD = HMD.active;
|
||||||
updateRunningScripts();
|
updateRunningScripts();
|
||||||
|
developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus");
|
||||||
|
checkMenu.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRunningScripts() {
|
function updateRunningScripts() {
|
||||||
|
@ -110,7 +145,17 @@ ScrollingWindow {
|
||||||
|
|
||||||
function reloadAll() {
|
function reloadAll() {
|
||||||
console.log("Reload all scripts");
|
console.log("Reload all scripts");
|
||||||
scripts.reloadAllScripts();
|
if (!developerMenuEnabled) {
|
||||||
|
for (var index = 0; index < runningScriptsModel.count; index++) {
|
||||||
|
var url = runningScriptsModel.get(index).url;
|
||||||
|
var fileName = url.substring(url.lastIndexOf('/')+1);
|
||||||
|
if (canEditScript(fileName)) {
|
||||||
|
scripts.stopScript(url, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scripts.reloadAllScripts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDefaults() {
|
function loadDefaults() {
|
||||||
|
@ -120,7 +165,22 @@ ScrollingWindow {
|
||||||
|
|
||||||
function stopAll() {
|
function stopAll() {
|
||||||
console.log("Stop all scripts");
|
console.log("Stop all scripts");
|
||||||
scripts.stopAllScripts();
|
for (var index = 0; index < runningScriptsModel.count; index++) {
|
||||||
|
var url = runningScriptsModel.get(index).url;
|
||||||
|
var fileName = url.substring(url.lastIndexOf('/')+1);
|
||||||
|
if (canEditScript(fileName)) {
|
||||||
|
scripts.stopScript(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function canEditScript(script) {
|
||||||
|
if ((script === "controllerScripts.js") || (script === "defaultScripts.js")) {
|
||||||
|
return developerMenuEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
@ -146,6 +206,14 @@ ScrollingWindow {
|
||||||
color: hifi.buttons.red
|
color: hifi.buttons.red
|
||||||
onClicked: stopAll()
|
onClicked: stopAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HifiControls.Button {
|
||||||
|
text: "Load Defaults"
|
||||||
|
color: hifi.buttons.black
|
||||||
|
height: 26
|
||||||
|
visible: root.developerMenuEnabled;
|
||||||
|
onClicked: loadDefaults()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.VerticalSpacer {
|
HifiControls.VerticalSpacer {
|
||||||
|
@ -162,6 +230,7 @@ ScrollingWindow {
|
||||||
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
|
||||||
|
@ -185,8 +254,9 @@ ScrollingWindow {
|
||||||
|
|
||||||
HiFiGlyphs {
|
HiFiGlyphs {
|
||||||
id: reloadButton
|
id: reloadButton
|
||||||
text: hifi.glyphs.reloadSmall
|
text: ((canEditScript(styleData.value)) ? hifi.glyphs.reload : hifi.glyphs.lock)
|
||||||
color: reloadButtonArea.pressed ? hifi.colors.white : parent.color
|
color: reloadButtonArea.pressed ? hifi.colors.white : parent.color
|
||||||
|
size: 21
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
right: stopButton.left
|
right: stopButton.left
|
||||||
|
@ -195,7 +265,13 @@ ScrollingWindow {
|
||||||
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 {
|
||||||
|
letterBoxMessage.createObject(desktop)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,6 +279,7 @@ ScrollingWindow {
|
||||||
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
|
||||||
|
@ -211,7 +288,11 @@ ScrollingWindow {
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,13 +345,6 @@ ScrollingWindow {
|
||||||
height: 26
|
height: 26
|
||||||
onClickedQueued: ApplicationInterface.loadDialog()
|
onClickedQueued: ApplicationInterface.loadDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.Button {
|
|
||||||
text: "Load Defaults"
|
|
||||||
color: hifi.buttons.black
|
|
||||||
height: 26
|
|
||||||
onClicked: loadDefaults()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.VerticalSpacer {}
|
HifiControls.VerticalSpacer {}
|
||||||
|
|
|
@ -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,26 +27,90 @@ 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;
|
||||||
|
letterBoxMessage.headerGlyphSize = 20
|
||||||
|
letterBoxMessage.headerTextMargin = 2
|
||||||
|
letterBoxMessage.headerGlyphMargin = -3
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: refreshTimer
|
||||||
|
interval: 100
|
||||||
|
repeat: false
|
||||||
|
running: false
|
||||||
|
onTriggered: updateRunningScripts();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: checkMenu
|
||||||
|
interval: 1000
|
||||||
|
repeat: true
|
||||||
|
running: false
|
||||||
|
onTriggered: developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus");
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: listModelBuilder
|
||||||
|
ListModel {}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: ScriptDiscoveryService
|
target: ScriptDiscoveryService
|
||||||
onScriptCountChanged: updateRunningScripts();
|
onScriptCountChanged: {
|
||||||
|
runningScriptsModel = listModelBuilder.createObject(root);
|
||||||
|
refreshTimer.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
isHMD = HMD.active;
|
isHMD = HMD.active;
|
||||||
updateRunningScripts();
|
updateRunningScripts();
|
||||||
|
developerMenuEnabled = MenuInterface.isMenuEnabled("Developer Menus");
|
||||||
|
checkMenu.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRunningScripts() {
|
function updateRunningScripts() {
|
||||||
var runningScripts = ScriptDiscoveryService.getRunning();
|
function simplify(path) {
|
||||||
runningScriptsModel.clear()
|
// trim URI querystring/fragment
|
||||||
for (var i = 0; i < runningScripts.length; ++i) {
|
path = (path+'').replace(/[#?].*$/,'');
|
||||||
runningScriptsModel.append(runningScripts[i]);
|
// normalize separators and grab last path segment (ie: just the filename)
|
||||||
|
path = path.replace(/\\/g, '/').split('/').pop();
|
||||||
|
// return lowercased because we want to sort mnemonically
|
||||||
|
return path.toLowerCase();
|
||||||
}
|
}
|
||||||
|
var runningScripts = ScriptDiscoveryService.getRunning();
|
||||||
|
runningScripts.sort(function(a,b) {
|
||||||
|
a = simplify(a.path);
|
||||||
|
b = simplify(b.path);
|
||||||
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
|
});
|
||||||
|
// Calling `runningScriptsModel.clear()` here instead of creating a new object
|
||||||
|
// triggers some kind of weird heap corruption deep inside Qt. So instead of
|
||||||
|
// modifying the model in place, possibly triggering behaviors in the table
|
||||||
|
// instead we create a new `ListModel`, populate it and update the
|
||||||
|
// existing model atomically.
|
||||||
|
var newRunningScriptsModel = listModelBuilder.createObject(root);
|
||||||
|
for (var i = 0; i < runningScripts.length; ++i) {
|
||||||
|
newRunningScriptsModel.append(runningScripts[i]);
|
||||||
|
}
|
||||||
|
runningScriptsModel = newRunningScriptsModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadScript(script) {
|
function loadScript(script) {
|
||||||
|
@ -65,7 +130,17 @@ Rectangle {
|
||||||
|
|
||||||
function reloadAll() {
|
function reloadAll() {
|
||||||
console.log("Reload all scripts");
|
console.log("Reload all scripts");
|
||||||
scripts.reloadAllScripts();
|
if (!developerMenuEnabled) {
|
||||||
|
for (var index = 0; index < runningScriptsModel.count; index++) {
|
||||||
|
var url = runningScriptsModel.get(index).url;
|
||||||
|
var fileName = url.substring(url.lastIndexOf('/')+1);
|
||||||
|
if (canEditScript(fileName)) {
|
||||||
|
scripts.stopScript(url, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scripts.reloadAllScripts();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDefaults() {
|
function loadDefaults() {
|
||||||
|
@ -75,7 +150,22 @@ Rectangle {
|
||||||
|
|
||||||
function stopAll() {
|
function stopAll() {
|
||||||
console.log("Stop all scripts");
|
console.log("Stop all scripts");
|
||||||
scripts.stopAllScripts();
|
for (var index = 0; index < runningScriptsModel.count; index++) {
|
||||||
|
var url = runningScriptsModel.get(index).url;
|
||||||
|
console.log(url);
|
||||||
|
var fileName = url.substring(url.lastIndexOf('/')+1);
|
||||||
|
if (canEditScript(fileName)) {
|
||||||
|
scripts.stopScript(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function canEditScript(script) {
|
||||||
|
if ((script === "controllerScripts.js") || (script === "defaultScripts.js")) {
|
||||||
|
return developerMenuEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
|
@ -110,6 +200,14 @@ Rectangle {
|
||||||
color: hifi.buttons.red
|
color: hifi.buttons.red
|
||||||
onClicked: stopAll()
|
onClicked: stopAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HifiControls.Button {
|
||||||
|
text: "Load Defaults"
|
||||||
|
color: hifi.buttons.black
|
||||||
|
height: 26
|
||||||
|
visible: root.developerMenuEnabled;
|
||||||
|
onClicked: loadDefaults()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.VerticalSpacer {
|
HifiControls.VerticalSpacer {
|
||||||
|
@ -125,6 +223,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,8 +247,9 @@ Rectangle {
|
||||||
|
|
||||||
HiFiGlyphs {
|
HiFiGlyphs {
|
||||||
id: reloadButton
|
id: reloadButton
|
||||||
text: hifi.glyphs.reloadSmall
|
text: ((canEditScript(styleData.value)) ? hifi.glyphs.reload : hifi.glyphs.lock)
|
||||||
color: reloadButtonArea.pressed ? hifi.colors.white : parent.color
|
color: reloadButtonArea.pressed ? hifi.colors.white : parent.color
|
||||||
|
size: 21
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
right: stopButton.left
|
right: stopButton.left
|
||||||
|
@ -158,7 +258,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,
|
||||||
|
"Developer Mode only",
|
||||||
|
"In order to edit, delete or reload this script," +
|
||||||
|
" turn on Developer Mode by going to:" +
|
||||||
|
" Menu > Settings > Developer Menus");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +276,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 +285,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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,13 +365,6 @@ Rectangle {
|
||||||
onTriggered: ApplicationInterface.loadDialog();
|
onTriggered: ApplicationInterface.loadDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.Button {
|
|
||||||
text: "Load Defaults"
|
|
||||||
color: hifi.buttons.black
|
|
||||||
height: 26
|
|
||||||
onClicked: loadDefaults()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiControls.VerticalSpacer {}
|
HifiControls.VerticalSpacer {}
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -191,6 +192,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", "../../");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue