From 7b482de72771d7e25c6945801dff739c0fe9840e Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 19 Sep 2019 16:47:35 -0400 Subject: [PATCH] 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. --- src/qml/Chat/Timeline/EventDelegate.qml | 6 ++---- src/qml/DebugConsole.qml | 6 ++++-- src/qml/Shortcuts.qml | 13 ++++++++++--- src/qml/UI.qml | 8 +------- src/qml/utils.js | 5 +++++ 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/qml/Chat/Timeline/EventDelegate.qml b/src/qml/Chat/Timeline/EventDelegate.qml index 66574d61..46e57c1e 100644 --- a/src/qml/Chat/Timeline/EventDelegate.qml +++ b/src/qml/Chat/Timeline/EventDelegate.qml @@ -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()") }) } } } diff --git a/src/qml/DebugConsole.qml b/src/qml/DebugConsole.qml index 39a71618..49bd4302 100644 --- a/src/qml/DebugConsole.qml +++ b/src/qml/DebugConsole.qml @@ -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, }) diff --git a/src/qml/Shortcuts.qml b/src/qml/Shortcuts.qml index e688ee48..ea106016 100644 --- a/src/qml/Shortcuts.qml +++ b/src/qml/Shortcuts.qml @@ -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) diff --git a/src/qml/UI.qml b/src/qml/UI.qml index 6e425869..70d11883 100644 --- a/src/qml/UI.qml +++ b/src/qml/UI.qml @@ -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 diff --git a/src/qml/utils.js b/src/qml/utils.js index 47add7ae..5410d6fc 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -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 }