DebugConsole must now be created from components

Remove the default console from UI.qml and add a utils.js function
to create one quickly.
Using this function from the component we actually want to debug gives
the console full access to that component's scope, children IDs, etc.
This commit is contained in:
miruka 2019-09-19 16:47:35 -04:00
parent d20ab5a348
commit 7b482de727
5 changed files with 22 additions and 16 deletions

View File

@ -170,10 +170,8 @@ Column {
icon.name: "settings"
text: qsTr("Set as debug console target")
visible: debugMode
onTriggered: {
mainUI.debugConsole.target = [eventDelegate, eventContent]
mainUI.debugConsole.runJS("t[0].json()")
}
onTriggered:
Utils.debug(eventDelegate, con => { con.runJS("json()") })
}
}
}

View File

@ -17,9 +17,11 @@ Window {
property alias t: debugConsole.target
onTargetChanged: {
Component.onCompleted: {
print(parent)
mainUI.shortcuts.debugConsole = debugConsole
commandsView.model.insert(0, {
input: "t = " + String(target),
input: "target = " + String(target),
output: "",
error: false,
})

View File

@ -3,7 +3,8 @@ import "Base"
import "utils.js" as Utils
HShortcutHandler {
property Item flickTarget: Item {}
property Item flickTarget
property DebugConsole debugConsole
// App
@ -14,9 +15,9 @@ HShortcutHandler {
}
HShortcut {
enabled: debugMode
enabled: debugMode && debugConsole
sequences: settings.keys.toggleDebugConsole
onPressed: mainUI.debugConsole.visible = ! mainUI.debugConsole.visible
onPressed: debugConsole.visible = ! debugConsole.visible
}
HShortcut {
@ -27,18 +28,21 @@ HShortcutHandler {
// Page scrolling
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollUp
onPressed: Utils.smartVerticalFlick(flickTarget, -335)
onHeld: pressed(event)
}
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollDown
onPressed: Utils.smartVerticalFlick(flickTarget, 335)
onHeld: pressed(event)
}
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollPageUp
onPressed: Utils.smartVerticalFlick(
flickTarget, -2.3 * flickTarget.height, 8,
@ -49,6 +53,7 @@ HShortcutHandler {
}
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollPageDown
onPressed: Utils.smartVerticalFlick(
flickTarget, 2.3 * flickTarget.height, 8,
@ -58,12 +63,14 @@ HShortcutHandler {
}
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollToTop
onPressed: Utils.flickToTop(flickTarget)
onHeld: pressed(event)
}
HShortcut {
enabled: flickTarget
sequences: settings.keys.scrollToBottom
onPressed: Utils.flickToBottom(flickTarget)
onHeld: pressed(event)

View File

@ -5,6 +5,7 @@ import QtQuick.Window 2.7
import QtGraphicalEffects 1.12
import "Base"
import "SidePane"
import "utils.js" as Utils
Item {
id: mainUI
@ -16,7 +17,6 @@ Item {
readonly property alias sidePane: sidePane
readonly property alias pageLoader: pageLoader
readonly property alias pressAnimation: pressAnimation
readonly property alias debugConsole: debugConsoleLoader.item
readonly property alias fullScreenPopup: fullScreenPopup
SequentialAnimation {
@ -33,7 +33,6 @@ Item {
(modelSources["Account"] || []).length > 0 ||
py.startupAnyAccountsSaved
Shortcuts { id: shortcuts }
HImage {
@ -142,11 +141,6 @@ Item {
}
}
HLoader {
id: debugConsoleLoader
source: debugMode ? "DebugConsole.qml" : ""
}
HPopup {
id: fullScreenPopup
dim: false

View File

@ -41,6 +41,11 @@ function makePopup(url, parent=null, properties={}, callback=null,
}
function debug(target, callback=null) {
return Utils.makeObject("DebugConsole.qml", target, { target }, callback)
}
function isEmptyObject(obj) {
return Object.entries(obj).length === 0 && obj.constructor === Object
}