From e6a20102d4653e17ad9b6383a31bc6253dc69007 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 21 Dec 2016 11:31:34 -0800 Subject: [PATCH] debug window enhancements --- interface/src/Menu.cpp | 9 ++++++++ scripts/developer/debugging/debugWindow.js | 24 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index b20343c439..4819220400 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -704,6 +704,15 @@ Menu::Menu() { addActionToQMenuAndActionHash(developerMenu, MenuOption::Log, Qt::CTRL | Qt::SHIFT | Qt::Key_L, qApp, SLOT(toggleLogDialog())); + action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)..."); + connect(action, &QAction::triggered, [] { + auto scriptEngines = DependencyManager::get(); + QUrl defaultScriptsLoc = defaultScriptsLocation(); + defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/debugging/debugWindow.js"); + scriptEngines->loadScript(defaultScriptsLoc.toString()); + }); + + // Developer > Stats addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::Stats); diff --git a/scripts/developer/debugging/debugWindow.js b/scripts/developer/debugging/debugWindow.js index fb9f3f4847..30a050e667 100644 --- a/scripts/developer/debugging/debugWindow.js +++ b/scripts/developer/debugging/debugWindow.js @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +(function() { // BEGIN LOCAL_SCOPE // Set up the qml ui var qml = Script.resolvePath('debugWindow.qml'); @@ -19,18 +20,33 @@ var window = new OverlayWindow({ window.setPosition(25, 50); window.closed.connect(function() { Script.stop(); }); +var getFormattedDate = function() { + var date = new Date(); + return date.getMonth() + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); +}; + +var sendToLogWindow = function(type, message, scriptFileName) { + var typeFormatted = ""; + if (type) { + typeFormatted = type + " - "; + } + window.sendToQml("[" + getFormattedDate() + "] " + "[" + scriptFileName + "] " + typeFormatted + message); +}; + ScriptDiscoveryService.printedMessage.connect(function(message, scriptFileName) { - window.sendToQml("[" + scriptFileName + "] " + message); + sendToLogWindow("", message, scriptFileName); }); ScriptDiscoveryService.warningMessage.connect(function(message, scriptFileName) { - window.sendToQml("[" + scriptFileName + "] WARNING - " + message); + sendToLogWindow("WARNING", message, scriptFileName); }); ScriptDiscoveryService.errorMessage.connect(function(message, scriptFileName) { - window.sendToQml("[" + scriptFileName + "] ERROR - " + message); + sendToLogWindow("ERROR", message, scriptFileName); }); ScriptDiscoveryService.infoMessage.connect(function(message, scriptFileName) { - window.sendToQml("[" + scriptFileName + "] INFO - " + message); + sendToLogWindow("INFO", message, scriptFileName); }); + +}()); // END LOCAL_SCOPE \ No newline at end of file