From a8b86ac83963b7a10824bf9c09a4c121b3ae5bc6 Mon Sep 17 00:00:00 2001 From: Tobias Predel Date: Tue, 28 Feb 2023 03:09:40 +0100 Subject: [PATCH] Set deck to current deck when clicked on table row (#2383) When a user clicks on the table row in the deck list (neither click on the deck link nor on the options menu) while the shift key is pressed, then set the deck in that table row as the current deck. This gives the user some quick feedback and enables the user to easily create subdecks (as it automatically fills the add deck dialog with the deck name of the selected deck) and to create notes belonging to the selected deck. --- CONTRIBUTORS | 1 + qt/aqt/deckbrowser.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7762c12e6..b89c4be40 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -111,6 +111,7 @@ Stefan Kangas Fabricio Duarte Mani Kaben Nanlohy +Tobias Predel ******************** diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index 3bcb82025..c12e3a9bf 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -118,6 +118,10 @@ class DeckBrowser: self._confirm_upgrade() elif cmd == "v2upgradeinfo": openLink("https://faqs.ankiweb.net/the-anki-2.1-scheduler.html") + elif cmd == "select": + set_current_deck( + parent=self.mw, deck_id=DeckId(int(arg)) + ).run_in_background() return False def set_current_deck(self, deck_id: DeckId) -> None: @@ -210,7 +214,14 @@ class DeckBrowser: else: klass = "deck" - buf = "" % (klass, node.deck_id) + buf = ( + "" + % ( + klass, + node.deck_id, + node.deck_id, + ) + ) # deck link if node.children: collapse = ( @@ -346,7 +357,9 @@ class DeckBrowser: openLink(f"{aqt.appShared}decks/") def _on_create(self) -> None: - if op := add_deck_dialog(parent=self.mw): + if op := add_deck_dialog( + parent=self.mw, default_text=self.mw.col.decks.current()["name"] + ): op.run_in_background() ######################################################################