qt: keep list of recently used wallets in sync across windows
this also removes alpha-sort of the wallet list in favor of placing most recently opened on top
This commit is contained in:
@@ -497,6 +497,7 @@ class Daemon(Logger):
|
|||||||
wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config)
|
wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config)
|
||||||
wallet.start_network(self.network)
|
wallet.start_network(self.network)
|
||||||
self.add_wallet(wallet)
|
self.add_wallet(wallet)
|
||||||
|
self.update_recently_opened_wallets(path)
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -542,6 +543,7 @@ class Daemon(Logger):
|
|||||||
self.stop_wallet(path)
|
self.stop_wallet(path)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
self.update_recently_opened_wallets(path, remove=True)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -704,3 +706,14 @@ class Daemon(Logger):
|
|||||||
self._check_password_for_directory(
|
self._check_password_for_directory(
|
||||||
old_password=old_password, new_password=new_password, wallet_dir=wallet_dir)
|
old_password=old_password, new_password=new_password, wallet_dir=wallet_dir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def update_recently_opened_wallets(self, wallet_path, *, remove: bool = False):
|
||||||
|
recent = self.config.RECENTLY_OPEN_WALLET_FILES or []
|
||||||
|
if wallet_path in recent:
|
||||||
|
recent.remove(wallet_path)
|
||||||
|
if not remove:
|
||||||
|
recent.insert(0, wallet_path)
|
||||||
|
recent = [path for path in recent if os.path.exists(path)]
|
||||||
|
recent = recent[:5]
|
||||||
|
self.config.RECENTLY_OPEN_WALLET_FILES = recent
|
||||||
|
util.trigger_callback('recently_opened_wallets_update')
|
||||||
|
|||||||
@@ -506,6 +506,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
def on_event_proxy_set(self, *args):
|
def on_event_proxy_set(self, *args):
|
||||||
self.tor_button.setVisible(False)
|
self.tor_button.setVisible(False)
|
||||||
|
|
||||||
|
@qt_event_listener
|
||||||
|
def on_event_recently_opened_wallets_update(self, *args):
|
||||||
|
self.update_recently_opened_menu()
|
||||||
|
|
||||||
def close_wallet(self):
|
def close_wallet(self):
|
||||||
if self.wallet:
|
if self.wallet:
|
||||||
self.logger.info(f'close_wallet {self.wallet.storage.path}')
|
self.logger.info(f'close_wallet {self.wallet.storage.path}')
|
||||||
@@ -513,7 +517,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def load_wallet(self, wallet: Abstract_Wallet):
|
def load_wallet(self, wallet: Abstract_Wallet):
|
||||||
self.update_recently_visited(wallet.storage.path)
|
self.update_recently_opened_menu()
|
||||||
if wallet.has_lightning():
|
if wallet.has_lightning():
|
||||||
util.trigger_callback('channels_updated', wallet)
|
util.trigger_callback('channels_updated', wallet)
|
||||||
self.need_update.set()
|
self.need_update.set()
|
||||||
@@ -658,24 +662,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
|||||||
self.show_message(msg, title=_("Wallet backup created"))
|
self.show_message(msg, title=_("Wallet backup created"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update_recently_visited(self, filename):
|
def update_recently_opened_menu(self):
|
||||||
recent = self.config.RECENTLY_OPEN_WALLET_FILES or []
|
recent = self.config.RECENTLY_OPEN_WALLET_FILES
|
||||||
try:
|
|
||||||
sorted(recent)
|
|
||||||
except Exception:
|
|
||||||
recent = []
|
|
||||||
if filename in recent:
|
|
||||||
recent.remove(filename)
|
|
||||||
recent.insert(0, filename)
|
|
||||||
recent = [path for path in recent if os.path.exists(path)]
|
|
||||||
recent = recent[:5]
|
|
||||||
self.config.RECENTLY_OPEN_WALLET_FILES = recent
|
|
||||||
self.recently_visited_menu.clear()
|
self.recently_visited_menu.clear()
|
||||||
for i, k in enumerate(sorted(recent)):
|
for i, k in enumerate(recent):
|
||||||
b = os.path.basename(k)
|
b = os.path.basename(k)
|
||||||
|
|
||||||
def loader(k):
|
def loader(k):
|
||||||
return lambda: self.gui_object.new_window(k)
|
return lambda: self.gui_object.new_window(k)
|
||||||
self.recently_visited_menu.addAction(b, loader(k)).setShortcut(QKeySequence("Ctrl+%d"%(i+1)))
|
self.recently_visited_menu.addAction(b, loader(k)).setShortcut(QKeySequence("Ctrl+%d" % (i+1)))
|
||||||
self.recently_visited_menu.setEnabled(bool(len(recent)))
|
self.recently_visited_menu.setEnabled(bool(len(recent)))
|
||||||
|
|
||||||
def get_wallet_folder(self):
|
def get_wallet_folder(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user