Merge pull request #9965 from vladest/tablet-ui-script-logs

Scripts debug window in Tablet UI
This commit is contained in:
Seth Alves 2017-03-21 08:35:12 -08:00 committed by GitHub
commit b0b3fe2f2f
4 changed files with 99 additions and 8 deletions

View file

@ -0,0 +1,78 @@
//
// TabletDebugWindow.qml
//
// Vlad Stelmahovsky, created on 20/03/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 Hifi 1.0 as Hifi
import "../../styles-uit"
import "../../controls-uit" as HifiControls
Rectangle {
id: root
objectName: "DebugWindow"
property var eventBridge;
property var title: "Debug Window"
property bool isHMD: false
color: hifi.colors.baseGray
HifiConstants { id: hifi }
signal sendToScript(var message);
property int colorScheme: hifi.colorSchemes.dark
property var channel;
property var scripts: ScriptDiscoveryService;
function fromScript(message) {
var MAX_LINE_COUNT = 2000;
var TRIM_LINES = 500;
if (textArea.lineCount > MAX_LINE_COUNT) {
var lines = textArea.text.split('\n');
lines.splice(0, TRIM_LINES);
textArea.text = lines.join('\n');
}
textArea.append(message);
}
function getFormattedDate() {
var date = new Date();
return date.getMonth() + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}
function sendToLogWindow(type, message, scriptFileName) {
var typeFormatted = "";
if (type) {
typeFormatted = type + " - ";
}
fromScript("[" + getFormattedDate() + "] " + "[" + scriptFileName + "] " + typeFormatted + message);
}
Connections {
target: ScriptDiscoveryService
onPrintedMessage: sendToLogWindow("", message, engineName);
onWarningMessage: sendToLogWindow("WARNING", message, engineName);
onErrorMessage: sendToLogWindow("ERROR", message, engineName);
onInfoMessage: sendToLogWindow("INFO", message, engineName);
}
TextArea {
id: textArea
width: parent.width
height: parent.height
backgroundVisible: false
textColor: hifi.colors.white
text:""
}
}

View file

@ -5855,6 +5855,24 @@ void Application::toggleRunningScriptsWidget() const {
//}
}
void Application::showScriptLogs() {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
auto scriptEngines = DependencyManager::get<ScriptEngines>();
QUrl defaultScriptsLoc = defaultScriptsLocation();
defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js");
if (tablet->getToolbarMode()) {
scriptEngines->loadScript(defaultScriptsLoc.toString());
} else {
QQuickItem* tabletRoot = tablet->getTabletRoot();
if (!tabletRoot && !isHMDMode()) {
scriptEngines->loadScript(defaultScriptsLoc.toString());
} else {
tablet->pushOntoStack("../../hifi/dialogs/TabletDebugWindow.qml");
}
}
}
void Application::showAssetServerWidget(QString filePath) {
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {

View file

@ -408,6 +408,7 @@ public slots:
void loadLODToolsDialog();
void loadEntityStatisticsDialog();
void loadDomainConnectionDialog();
void showScriptLogs();
private slots:
void showDesktop();

View file

@ -719,14 +719,8 @@ Menu::Menu() {
});
essLogAction->setEnabled(nodeList->getThisNodeCanRez());
action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)...");
connect(action, &QAction::triggered, [] {
auto scriptEngines = DependencyManager::get<ScriptEngines>();
QUrl defaultScriptsLoc = defaultScriptsLocation();
defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js");
scriptEngines->loadScript(defaultScriptsLoc.toString());
});
action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)...", Qt::NoButton,
qApp, SLOT(showScriptLogs()));
// Developer > Stats
addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::Stats);