Skip to content

Commit 6c4970e

Browse files
committed
qml: close console autocomplete when changing tabs
1 parent 25e0566 commit 6c4970e

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

qml/controls/NavigationBar2.qml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,40 @@ import QtQuick.Controls 2.15
77
import QtQuick.Layouts 1.15
88

99
Pane {
10+
id: root
11+
1012
property alias leftItem: left_section.contentItem
1113
property alias centerItem: center_section.contentItem
1214
property alias rightItem: right_section.contentItem
1315
property var navigationStack: null
16+
// Optional tab group supplied by a containing view. This lets content
17+
// pages close transient UI when the user leaves their tab.
18+
property var tabGroup: null
19+
property var currentTab: null
1420
property bool showBackButton: navigationStack ? navigationStack.canGoBack : false
1521
property string backButtonObjectName: ""
1622
property string backButtonText: qsTr("Back")
1723

1824
signal backClicked
25+
signal tabChanged(var previousTab, var currentTab)
26+
27+
onTabGroupChanged: {
28+
currentTab = tabGroup ? tabGroup.checkedButton : null
29+
}
30+
31+
Connections {
32+
target: root.tabGroup
33+
34+
function onCheckedButtonChanged() {
35+
const nextTab = root.tabGroup.checkedButton
36+
if (!nextTab || nextTab === root.currentTab) {
37+
return
38+
}
39+
const previousTab = root.currentTab
40+
root.currentTab = nextTab
41+
root.tabChanged(previousTab, nextTab)
42+
}
43+
}
1944

2045
background: null
2146
padding: 4

qml/pages/node/CommandConsole.qml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ Page {
2929
property bool searchMode: false
3030
property string commandDraft: ""
3131
property string searchDraft: ""
32+
// DesktopWallets supplies its navigation bar so this persistent
33+
// StackLayout child can dismiss overlay-based transient UI on tab changes.
34+
property var navigationBar: null
35+
property var navigationTab: null
36+
37+
Connections {
38+
target: root.navigationBar
39+
40+
function onTabChanged(previousTab, currentTab) {
41+
if (previousTab === root.navigationTab) {
42+
autocompletePopup.close()
43+
}
44+
}
45+
}
3246

3347
function _pushPalette() {
3448
rpcConsoleModel.requestColor = consoleRequestColor

qml/pages/wallet/DesktopWallets.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Page {
106106

107107
header: NavigationBar2 {
108108
id: navBar
109+
tabGroup: navigationTabs
109110
leftItem: WalletBadge {
110111
objectName: "walletBadge"
111112
implicitWidth: 175
@@ -346,6 +347,8 @@ Page {
346347
}
347348
CommandConsole {
348349
showHeader: false
350+
navigationBar: navBar
351+
navigationTab: consoleTabButton
349352
walletName: walletController.isWalletLoaded && walletController.selectedWallet
350353
? walletController.selectedWallet.name
351354
: ""

test/qml/tst_desktopwallets.qml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ TestCase {
9797
compare(tabs[3].iconSize, 30)
9898
}
9999

100+
function test_console_autocomplete_closes_when_switching_tabs() {
101+
const page = createDesktopWallets()
102+
const consoleTab = findChild(page, "consoleTabButton")
103+
const activityTab = findChild(page, "activityTabButton")
104+
const popup = findChild(page, "consoleAutocompletePopup")
105+
106+
verify(consoleTab !== null)
107+
verify(activityTab !== null)
108+
verify(popup !== null)
109+
110+
consoleTab.checked = true
111+
tryCompare(consoleTab, "checked", true)
112+
popup.open()
113+
tryCompare(popup, "visible", true)
114+
115+
activityTab.checked = true
116+
tryCompare(activityTab, "checked", true)
117+
tryCompare(popup, "visible", false)
118+
}
119+
100120
function test_receive_options_view_address_history_opens_settings_address_stack() {
101121
const page = createDesktopWallets()
102122
const receiveTab = findChild(page, "receiveTabButton")

0 commit comments

Comments
 (0)