diff --git a/electrum/gui/qml/components/Wallets.qml b/electrum/gui/qml/components/Wallets.qml index e98e82c1475..e03b619bc76 100644 --- a/electrum/gui/qml/components/Wallets.qml +++ b/electrum/gui/qml/components/Wallets.qml @@ -37,6 +37,38 @@ Pane { text: qsTr('Wallets') } + TextField { + id: searchEdit + Layout.fillWidth: true + Layout.leftMargin: constants.paddingLarge + Layout.rightMargin: constants.paddingLarge + + placeholderText: qsTr('search') + inputMethodHints: Qt.ImhNoPredictiveText + EnterKey.type: Qt.EnterKeyDone + onAccepted: { + // load a wallet (e.g. a hidden wallet not shown in the list) when + // the search text exactly matches an available wallet name + var path = Daemon.availableWallets.pathForName(text) + if (path && !Daemon.loading) { + if (!Daemon.currentWallet || Daemon.currentWallet.name != text) { + Daemon.loadWallet(path) + } else { + app.stack.pop() + } + } + } + + Image { + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.rightMargin: constants.paddingMedium + source: Qt.resolvedUrl('../../icons/zoom.png') + sourceSize.width: constants.iconSizeMedium + sourceSize.height: constants.iconSizeMedium + } + } + Frame { id: detailsFrame Layout.fillWidth: true @@ -52,9 +84,14 @@ Pane { model: Daemon.availableWallets delegate: ItemDelegate { + property bool matchesSearch: searchEdit.text.length === 0 + || model.name.toLowerCase().indexOf(searchEdit.text.toLowerCase()) !== -1 + property bool hiddenWallet: model.name.startsWith('.') && !model.active width: ListView.view.width - height: row.height - + height: visible ? row.height : 0 + // visible: searchEdit.text.length === 0 + // || model.name.toLowerCase().indexOf(searchEdit.text.toLowerCase()) !== -1 + visible: matchesSearch && !hiddenWallet onClicked: { if (!Daemon.currentWallet || Daemon.currentWallet.name != model.name) { if (!Daemon.loading) // wallet load in progress @@ -118,6 +155,8 @@ Pane { ButtonContainer { Layout.fillWidth: true + visible: !searchEdit.text + FlatButton { Layout.fillWidth: true text: qsTr('Create Wallet') diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 3b3ea756253..679bf5aa411 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -72,7 +72,7 @@ def reload(self): wallet_folder = os.path.dirname(self.daemon.config.get_wallet_path()) with os.scandir(wallet_folder) as it: for i in it: - if i.is_file() and not i.name.startswith('.'): + if i.is_file(): available.append(i.path) for path in sorted(available): wallet = self.daemon.get_wallet(path) @@ -109,6 +109,13 @@ def wallet_name_exists(self, name): return True return False + @pyqtSlot(str, result=str) + def pathForName(self, name): + for wallet_name, wallet_path in self._wallets: + if name == wallet_name: + return wallet_path + return '' + @pyqtSlot(str) def updateWallet(self, path): i = 0 @@ -325,8 +332,10 @@ def isValidWalletName(self, wallet_name: str) -> bool: for forbidden_char in ("/", "\\", ): if forbidden_char in wallet_name: return False - if wallet_name.startswith('.'): # not shown in wallet list - # TODO: allow wallets starting with '.' as hidden wallets, opened e.g. through wallet creation wizard + # note: wallet names starting with '.' are allowed as hidden wallets; they are not shown + # in the wallet list unless active (see Wallets.qml) but can be created via the wizard. + # disallow double '..*' filenames though. + if wallet_name.startswith('..'): return False if os.path.basename(wallet_name) != wallet_name: # '/foo/bar/' returns 'bar' return False