Fix need to press Esc twice to exit popups/menus
This commit is contained in:
@@ -16,7 +16,7 @@ HPage {
|
||||
contentHeight: column.childrenRect.height
|
||||
|
||||
FlickShortcuts {
|
||||
enabled: ! mainUI.debugConsole.visible
|
||||
active: ! mainUI.debugConsole.visible
|
||||
flickable: flickable
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
}
|
||||
|
@@ -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()
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user