From 4602366b9cc07573d537de19379369c47debf26c Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 1 Apr 2020 05:37:44 -0400 Subject: [PATCH] debugConsole: add toggle() conveniance function --- TODO.md | 2 -- src/gui/DebugConsole.qml | 14 +++++++++++++- src/gui/Pages/Chat/Timeline/EventDelegate.qml | 7 ++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 9d053ae6..9e15ca46 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,5 @@ # TODO -- Fix escape to unselect events - ## Refactoring - Rewrite account settings using `HTabbedContainer` diff --git a/src/gui/DebugConsole.qml b/src/gui/DebugConsole.qml index ff555fb1..004f4820 100644 --- a/src/gui/DebugConsole.qml +++ b/src/gui/DebugConsole.qml @@ -73,6 +73,18 @@ HDrawer { readonly property alias commandsView: commandsView + function toggle(targetItem=mainUI, js="", addToHistory=false) { + if (debugConsole.visible) { + debugConsole.visible = false + return + } + + debugConsole.visible = true + debugConsole.target = targetItem + if (js) debugConsole.runJS(js, addToHistory) + } + + function runJS(input, addToHistory=true) { if (addToHistory && history.slice(-1)[0] !== input) { history.push(input) @@ -119,7 +131,7 @@ HDrawer { HShortcut { sequences: settings.keys.toggleDebugConsole - onActivated: debugConsole.visible = ! debugConsole.visible + onActivated: debugConsole.toggle() } HColumnLayout { diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index a81776bd..fdbc562c 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -221,11 +221,8 @@ HColumnLayout { HMenuItem { icon.name: "debug" text: qsTr("Debug this event") - onTriggered: { - mainUI.debugConsole.visible = true - mainUI.debugConsole.target = eventContent - mainUI.debugConsole.runJS("t.parent.json()", false) - } + onTriggered: + mainUI.debugConsole.toggle(eventContent, "t.parent.json()") } HMenuItemPopupSpawner {