From 8065e73ef870c3b3842c44b6702f4d6999586eb9 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 1 Feb 2021 19:10:05 +0100 Subject: [PATCH] Add cross links for second dyndeck filter --- ftl/core/browsing.ftl | 1 + qt/aqt/browser.py | 7 ++++ qt/aqt/dyndeckconf.py | 51 +++++++++++++++++++++-------- qt/aqt/forms/browser.ui | 9 +++++ qt/aqt/forms/dyndconf.ui | 71 ++++++++++++++++++++++------------------ 5 files changed, 94 insertions(+), 45 deletions(-) diff --git a/ftl/core/browsing.ftl b/ftl/core/browsing.ftl index 2b87a92dc..8ce372e8f 100644 --- a/ftl/core/browsing.ftl +++ b/ftl/core/browsing.ftl @@ -25,6 +25,7 @@ browsing-clear-unused = Clear Unused browsing-clear-unused-tags = Clear Unused Tags browsing-created = Created browsing-create-filtered-deck = Create Filtered Deck... +browsing-create-filtered-deck_2 = Create Filtered Deck (2nd Filter)... browsing-ctrlandshiftande = Ctrl+Shift+E browsing-current-deck = Current Deck browsing-current-note-type = Current note type: diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index ef665e7fb..7454e54d6 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -482,6 +482,9 @@ class Browser(QMainWindow): if not isMac: f.actionClose.setVisible(False) qconnect(f.actionCreateFilteredDeck.triggered, self.createFilteredDeck) + qconnect(f.actionCreateFilteredDeck2.triggered, self.createFilteredDeck2) + if self.mw.col.schedVer() == 1: + f.menuEdit.removeAction(f.actionCreateFilteredDeck2) # notes qconnect(f.actionAdd.triggered, self.mw.onAddCard) qconnect(f.actionAdd_Tags.triggered, lambda: self.addTags()) @@ -1194,6 +1197,10 @@ where id in %s""" search = self.form.searchEdit.lineEdit().text() aqt.dialogs.open("DynDeckConfDialog", self.mw, search=search) + def createFilteredDeck2(self): + search = self.form.searchEdit.lineEdit().text() + aqt.dialogs.open("DynDeckConfDialog", self.mw, search_2=search) + # Preview ###################################################################### diff --git a/qt/aqt/dyndeckconf.py b/qt/aqt/dyndeckconf.py index 4e54bd0da..31ce27817 100644 --- a/qt/aqt/dyndeckconf.py +++ b/qt/aqt/dyndeckconf.py @@ -29,7 +29,11 @@ class DeckConf(QDialog): """Dialogue to modify and build a filtered deck.""" def __init__( - self, mw: AnkiQt, search: Optional[str] = None, deck: Optional[Deck] = None + self, + mw: AnkiQt, + search: Optional[str] = None, + search_2: Optional[str] = None, + deck: Optional[Deck] = None, ): """If 'deck' is an existing filtered deck, load and modify its settings. Otherwise, build a new one and derive settings from the current deck. @@ -60,10 +64,10 @@ class DeckConf(QDialog): self.new_dyn_deck() self.loadConf() self.set_default_searches(self.old_deck["name"]) - if search is not None: - self.form.search.setText(search) + self.set_custom_searches(search, search_2) qconnect(self.form.search_button.clicked, self.on_search_button) + qconnect(self.form.search_button_2.clicked, self.on_search_button_2) color = theme_manager.str_color("link") self.setStyleSheet( f"""QPushButton[flat=true] {{ text-align: left; color: {color}; padding: 0; border: 0 }} @@ -78,8 +82,6 @@ class DeckConf(QDialog): without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck["name"])) ) self.form.buttonBox.addButton(label, QDialogButtonBox.AcceptRole) - self.form.search.setFocus() - self.form.search.selectAll() if self.mw.col.schedVer() == 1: self.form.secondFilter.setVisible(False) restoreGeom(self, "dyndeckconf") @@ -87,12 +89,13 @@ class DeckConf(QDialog): self.show() def reopen( - self, _mw: AnkiQt, search: Optional[str] = None, _deck: Optional[Deck] = None + self, + _mw: AnkiQt, + search: Optional[str] = None, + search_2: Optional[str] = None, + _deck: Optional[Deck] = None, ): - if search is not None: - self.form.search.setText(search) - self.form.search.setFocus() - self.form.search.selectAll() + self.set_custom_searches(search, search_2) def new_dyn_deck(self): suffix: int = 1 @@ -118,6 +121,20 @@ class DeckConf(QDialog): ) ) + def set_custom_searches( + self, search: Optional[str], search_2: Optional[str] + ) -> None: + if search is not None: + self.form.search.setText(search) + self.form.search.setFocus() + self.form.search.selectAll() + if search_2 is not None: + self.form.secondFilter.setChecked(True) + self.form.filter2group.setVisible(True) + self.form.search_2.setText(search_2) + self.form.search_2.setFocus() + self.form.search_2.selectAll() + def initialSetup(self): import anki.consts as cs @@ -126,12 +143,18 @@ class DeckConf(QDialog): qconnect(self.form.resched.stateChanged, self._onReschedToggled) - def on_search_button(self): + def on_search_button(self) -> None: + self._on_search_button(self.form.search) + + def on_search_button_2(self) -> None: + self._on_search_button(self.form.search_2) + + def _on_search_button(self, line: QLineEdit) -> None: try: - search = self.mw.col.build_search_string(self.form.search.text()) + search = self.mw.col.build_search_string(line.text()) except InvalidInput as err: - self.form.search.setFocus() - self.form.search.selectAll() + line.setFocus() + line.selectAll() show_invalid_search_error(err) else: aqt.dialogs.open("Browser", self.mw, search=(search,)) diff --git a/qt/aqt/forms/browser.ui b/qt/aqt/forms/browser.ui index 9a9d02cbe..72d24f97c 100644 --- a/qt/aqt/forms/browser.ui +++ b/qt/aqt/forms/browser.ui @@ -232,6 +232,7 @@ + @@ -593,6 +594,14 @@ Ctrl+G + + + BROWSING_CREATE_FILTERED_DECK_2 + + + Ctrl+Shift+G + + diff --git a/qt/aqt/forms/dyndconf.ui b/qt/aqt/forms/dyndconf.ui index 85d9c4b30..7491d0731 100644 --- a/qt/aqt/forms/dyndconf.ui +++ b/qt/aqt/forms/dyndconf.ui @@ -20,22 +20,6 @@ ACTIONS_FILTER - - - - SEARCH_VIEW_IN_BROWSER - - - ACTIONS_SEARCH - - - false - - - true - - - @@ -43,12 +27,8 @@ - - - - DECKS_CARDS_SELECTED_BY - - + + @@ -69,8 +49,28 @@ - - + + + + DECKS_CARDS_SELECTED_BY + + + + + + + SEARCH_VIEW_IN_BROWSER + + + ACTIONS_SEARCH + + + false + + + true + + @@ -94,13 +94,6 @@ - - - - ACTIONS_SEARCH - - - @@ -124,6 +117,22 @@ + + + + SEARCH_VIEW_IN_BROWSER + + + ACTIONS_SEARCH + + + false + + + true + + +