New way to open debug consoles

Replace broken old utils.debug(...) (since the utils.js → Utils.qml
transition) with a declarative approach:
a console can now be opened with by placing a `DebugConsoleLoader {}`
anywhere.
mainUI has a default console opened by F1/alt-shit-c when no other
console is loaded.
This commit is contained in:
miruka 2019-12-19 13:41:57 -04:00
parent f4beb52e0c
commit 2229b41af1
6 changed files with 81 additions and 21 deletions

View File

@ -17,9 +17,9 @@ HDrawer {
z: 9999
position: 0
property var previouslyFocused: null
property Item previouslyFocused: null
property var target: null
property QtObject target: null
property alias t: debugConsole.target
property var history: window.history.console
@ -51,10 +51,6 @@ HDrawer {
Component.onCompleted: {
if (mainUI.shortcuts.debugConsole)
mainUI.shortcuts.debugConsole.destroy()
mainUI.shortcuts.debugConsole = debugConsole
position = 1
commandsView.model.insert(0, {
input: "t = " + String(target),

View File

@ -0,0 +1,43 @@
import QtQuick 2.12
import "Base"
HLoader {
id: loader
onLoaded: {
if (! isDefault)
shortcuts.defaultDebugConsoleLoader.active = false
if (shortcuts.debugConsoleLoader)
shortcuts.debugConsoleLoader.active = false
shortcuts.debugConsoleLoader = this
}
onActiveChanged: if (! active) shortcuts.debugConsoleLoader = null
Component.onDestruction: shortcuts.debugConsoleLoader = null
sourceComponent: DebugConsole {
target: loader.target
property HLoader parentLoader: loader
}
property QtObject target: parent
readonly property bool isDefault:
shortcuts.defaultDebugConsoleLoader &&
shortcuts.defaultDebugConsoleLoader === this
function toggle() {
if (! loader.active) {
loader.active = true
return
}
loader.item.visible = ! loader.item.visible
}
}

View File

@ -13,12 +13,23 @@ Item {
// A QQC Container that should be affected by tab navigation shortcuts
property Container tabsTarget
// DebugConsole that should be affected by console shortcuts
property DebugConsole debugConsole
// DebugConsoleLoader that should be affected by console shortcuts
property DebugConsoleLoader debugConsoleLoader
// DebugConsoleLoader to activate if no other loader is active and the
// shortcut to bring up a console is pressed
property DebugConsoleLoader defaultDebugConsoleLoader
readonly property DebugConsole debugConsole:
debugConsoleLoader ? debugConsoleLoader.item : null
readonly property DebugConsole defaultDebugConsole:
defaultDebugConsoleLoader ? defaultDebugConsoleLoader.item : null
readonly property Item toFlick:
debugConsole && debugConsole.activeFocus ?
debugConsole.commandsView : flickTarget
debugConsole.commandsView :
flickTarget
// App
@ -35,8 +46,12 @@ Item {
onActivated: {
if (debugConsole) {
debugConsole.visible = ! debugConsole.visible
} else if (! defaultDebugConsoleLoader.active) {
defaultDebugConsoleLoader.active = true
} else {
utils.debug(mainUI || window)
defaultDebugConsole.visible = ! defaultDebugConsole.visible
}
}
}

View File

@ -3,6 +3,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../../../Base"
import "../../.."
HRowLayout {
id: eventContent
@ -40,8 +41,13 @@ HRowLayout {
TapHandler {
enabled: debugMode
onDoubleTapped:
utils.debug(eventContent, null, con => { con.runJS("json()") })
onDoubleTapped: debugConsoleLoader.toggle()
}
DebugConsoleLoader {
id: debugConsoleLoader
active: false
onLoaded: item.runJS("json()")
}
Item {

View File

@ -35,7 +35,15 @@ Item {
}
}
GlobalShortcuts { id: shortcuts }
GlobalShortcuts {
id: shortcuts
defaultDebugConsoleLoader: debugConsoleLoader
}
DebugConsoleLoader {
id: debugConsoleLoader
active: false
}
HImage {
id: mainUIBackground

View File

@ -57,14 +57,6 @@ QtObject {
}
function debug(target, parent=null, callback=null) {
parent = parent || target
return utils.makeObject(
"DebugConsole.qml", parent, { target }, callback,
)
}
function isEmptyObject(obj) {
return Object.entries(obj).length === 0 && obj.constructor === Object
}