From 554f5d60138c8267a94d4c3582264617de494626 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 1 Apr 2020 08:01:13 -0400 Subject: [PATCH] Fix need to press Esc twice to exit popups/menus --- src/gui/Base/HFlickableColumnPage.qml | 2 +- src/gui/Base/HMenu.qml | 13 ++++++++++++- src/gui/Base/HPopup.qml | 13 ++++++++++++- src/gui/Base/HShortcut.qml | 5 +++++ src/gui/DebugConsole.qml | 2 +- src/gui/MainPane/MainPane.qml | 2 +- src/gui/Pages/Chat/Timeline/EventList.qml | 8 ++++---- src/gui/ShortcutBundles/FlickShortcuts.qml | 14 +++++++------- src/gui/ShortcutBundles/TabShortcuts.qml | 6 +++--- src/gui/Window.qml | 6 ++++++ 10 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/gui/Base/HFlickableColumnPage.qml b/src/gui/Base/HFlickableColumnPage.qml index 5dbc8f3b..8ce563ff 100644 --- a/src/gui/Base/HFlickableColumnPage.qml +++ b/src/gui/Base/HFlickableColumnPage.qml @@ -16,7 +16,7 @@ HPage { contentHeight: column.childrenRect.height FlickShortcuts { - enabled: ! mainUI.debugConsole.visible + active: ! mainUI.debugConsole.visible flickable: flickable } diff --git a/src/gui/Base/HMenu.qml b/src/gui/Base/HMenu.qml index 05ef0a9d..f4d0d15e 100644 --- a/src/gui/Base/HMenu.qml +++ b/src/gui/Base/HMenu.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import CppUtils 0.1 Menu { id: menu @@ -31,7 +32,15 @@ Menu { previouslyFocused = window.activeFocusItem focusOnClosed = Qt.binding(() => previouslyFocused) } - onClosed: if (focusOnClosed) focusOnClosed.forceActiveFocus() + onOpened: { + window.visibleMenus[uuid] = this + window.visibleMenusChanged() + } + onClosed: { + if (focusOnClosed) focusOnClosed.forceActiveFocus() + delete window.visibleMenus[uuid] + window.visibleMenusChanged() + } property var previouslyFocused: null @@ -40,4 +49,6 @@ Menu { // should set this to null. It will be reset to previouslyFocus when // the Menu is closed and opened again. property Item focusOnClosed: previouslyFocused + + readonly property string uuid: CppUtils.uuid() } diff --git a/src/gui/Base/HPopup.qml b/src/gui/Base/HPopup.qml index 8e87e14e..2f05b5fe 100644 --- a/src/gui/Base/HPopup.qml +++ b/src/gui/Base/HPopup.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import CppUtils 0.1 Popup { id: popup @@ -30,7 +31,15 @@ Popup { } onAboutToShow: previouslyFocused = window.activeFocusItem - onClosed: if (focusOnClosed) focusOnClosed.forceActiveFocus() + onOpened: { + window.visiblePopups[uuid] = this + window.visibleMenusChanged() + } + onClosed: { + if (focusOnClosed) focusOnClosed.forceActiveFocus() + delete window.visiblePopups[uuid] + window.visibleMenusChanged() + } property var previouslyFocused: null @@ -41,4 +50,6 @@ Popup { readonly property int maximumPreferredHeight: window.height - topMargin - bottomMargin - topInset - bottomInset + + readonly property string uuid: CppUtils.uuid() } diff --git a/src/gui/Base/HShortcut.qml b/src/gui/Base/HShortcut.qml index 1464b5c2..040db6f7 100644 --- a/src/gui/Base/HShortcut.qml +++ b/src/gui/Base/HShortcut.qml @@ -3,5 +3,10 @@ import QtQuick 2.12 Shortcut { + enabled: ! window.anyPopupOrMenu && active context: Qt.ApplicationShortcut + + + // TODO: use enabled + a Binding with restoreValue when switch to Qt 5.15 + property bool active: true } diff --git a/src/gui/DebugConsole.qml b/src/gui/DebugConsole.qml index 74f8d490..b1b6da2b 100644 --- a/src/gui/DebugConsole.qml +++ b/src/gui/DebugConsole.qml @@ -183,7 +183,7 @@ HDrawer { } FlickShortcuts { - enabled: debugConsole.visible + active: debugConsole.visible flickable: commandsView } diff --git a/src/gui/MainPane/MainPane.qml b/src/gui/MainPane/MainPane.qml index cf32c6c9..58029e5d 100644 --- a/src/gui/MainPane/MainPane.qml +++ b/src/gui/MainPane/MainPane.qml @@ -48,7 +48,7 @@ HDrawer { } HShortcut { - enabled: mainUI.accountsPresent + active: mainUI.accountsPresent sequences: window.settings.keys.toggleFocusMainPane onActivated: toggleFocus() } diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index 10d8eca6..bed5a312 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -38,20 +38,20 @@ Rectangle { } HShortcut { - enabled: eventList.currentItem + active: eventList.currentItem sequences: window.settings.keys.toggleSelectMessage onActivated: eventList.toggleCheck(eventList.currentIndex) } HShortcut { - enabled: eventList.currentItem + active: eventList.currentItem sequences: window.settings.keys.selectMessagesUntilHere onActivated: eventList.checkFromLastToHere(eventList.currentIndex) } HShortcut { - enabled: eventList.currentItem + active: eventList.currentItem sequences: window.settings.keys.debugFocusedMessage onActivated: eventList.currentItem.eventContent.debugConsoleLoader.toggle() @@ -70,7 +70,7 @@ Rectangle { } FlickShortcuts { - enabled: ! mainUI.debugConsole.visible + active: ! mainUI.debugConsole.visible flickable: eventList } diff --git a/src/gui/ShortcutBundles/FlickShortcuts.qml b/src/gui/ShortcutBundles/FlickShortcuts.qml index 58fb4796..e64ecdab 100644 --- a/src/gui/ShortcutBundles/FlickShortcuts.qml +++ b/src/gui/ShortcutBundles/FlickShortcuts.qml @@ -8,41 +8,41 @@ HQtObject { property Item flickable: parent - property bool enabled: true + property bool active: true HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollUp onActivated: utils.flickPages(flickable, -1 / 10) } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollDown onActivated: utils.flickPages(flickable, 1 / 10) } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollPageUp onActivated: utils.flickPages(flickable, -1) } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollPageDown onActivated: utils.flickPages(flickable, 1) } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollToTop onActivated: utils.flickToTop(flickable) } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.scrollToBottom onActivated: utils.flickToBottom(flickable) } diff --git a/src/gui/ShortcutBundles/TabShortcuts.qml b/src/gui/ShortcutBundles/TabShortcuts.qml index 26f924a1..ba4abaf7 100644 --- a/src/gui/ShortcutBundles/TabShortcuts.qml +++ b/src/gui/ShortcutBundles/TabShortcuts.qml @@ -8,11 +8,11 @@ HQtObject { property Item container: parent - property bool enabled: true + property bool active: true HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.previousTab onActivated: container.setCurrentIndex( utils.numberWrapAt(container.currentIndex - 1, container.count), @@ -20,7 +20,7 @@ HQtObject { } HShortcut { - enabled: root.enabled + active: root.active sequences: window.settings.keys.nextTab onActivated: container.setCurrentIndex( utils.numberWrapAt(container.currentIndex + 1, container.count), diff --git a/src/gui/Window.qml b/src/gui/Window.qml index a07941f8..6d5b3257 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -45,6 +45,12 @@ ApplicationWindow { property var hideErrorTypes: new Set() + readonly property var visibleMenus: ({}) + readonly property var visiblePopups: ({}) + readonly property bool anyPopupOrMenu: + Object.keys(window.visibleMenus).length > 0 || + Object.keys(window.visiblePopups).length > 0 + function saveState(obj) { if (! obj.saveName || ! obj.saveProperties ||