diff --git a/ftl/core/errors.ftl b/ftl/core/errors.ftl index 5f5ea6eb5..8e549ecb1 100644 --- a/ftl/core/errors.ftl +++ b/ftl/core/errors.ftl @@ -1,3 +1,5 @@ +errors-invalid-deck-name = Invalid deck name: { $reason } errors-invalid-input-empty = Invalid input. errors-invalid-input-details = Invalid input: { $details } errors-parse-number-fail = A number was invalid or out of range. +errors-reason-filtered-parent = Filtered decks cannot be parent decks. diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index cd446fec9..05836f8dd 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -21,8 +21,8 @@ from aqt.utils import ( getOnlyText, openLink, shortcut, + show_rename_deck_error, showInfo, - showWarning, tr, ) @@ -272,8 +272,8 @@ class DeckBrowser: try: self.mw.col.decks.rename(deck, newName) gui_hooks.sidebar_should_refresh_decks() - except DeckRenameError as e: - showWarning(e.description) + except DeckRenameError as err: + show_rename_deck_error(err) return self.show() diff --git a/qt/aqt/dyndeckconf.py b/qt/aqt/dyndeckconf.py index 8c88df964..6f47480b7 100644 --- a/qt/aqt/dyndeckconf.py +++ b/qt/aqt/dyndeckconf.py @@ -19,6 +19,7 @@ from aqt.utils import ( restoreGeom, saveGeom, show_invalid_search_error, + show_rename_deck_error, showWarning, tr, ) @@ -244,7 +245,7 @@ class DeckConf(QDialog): except InvalidInput as err: show_invalid_search_error(err) except DeckRenameError as err: - showWarning(err.description) + show_rename_deck_error(err) else: if not self.mw.col.sched.rebuild_filtered_deck(self.deck["id"]): if askUser(tr(TR.DECKS_THE_PROVIDED_SEARCH_DID_NOT_MATCH)): diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 41856e3c7..db90c0846 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -23,8 +23,8 @@ from aqt.utils import ( askUser, getOnlyText, show_invalid_search_error, + show_rename_deck_error, showInfo, - showWarning, tr, ) @@ -993,8 +993,8 @@ class SidebarTreeView(QTreeView): self.mw.checkpoint(tr(TR.ACTIONS_RENAME_DECK)) try: self.mw.col.decks.rename(deck, new_name) - except DeckRenameError as e: - showWarning(e.description) + except DeckRenameError as err: + show_rename_deck_error(err) return self.refresh() self.mw.deckBrowser.refresh() diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 8d94aa5c7..5d57bbf0a 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -36,7 +36,7 @@ from PyQt5.QtWidgets import ( import anki import aqt from anki import Collection -from anki.errors import InvalidInput +from anki.errors import DeckRenameError, InvalidInput from anki.lang import TR # pylint: disable=unused-import from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild from aqt.qt import * @@ -146,6 +146,14 @@ def show_invalid_search_error(err: Exception) -> None: showWarning(text) +def show_rename_deck_error(err: DeckRenameError) -> None: + if err.description == "deck was filtered": + reason = tr(TR.ERRORS_REASON_FILTERED_PARENT) + else: + reason = "unknown reason." + showWarning(tr(TR.ERRORS_INVALID_DECK_NAME, reason=reason)) + + def showInfo( text: str, parent: Union[Literal[False], QDialog] = False,