mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Use default flag name when flag is renamed to empty string (#3826)
* Add function to restore the default name of a flag
* Call function to restore default flag name if flag renamed to empty string
* Update _load_flags to use the default_flag_names dict
* Add name to contributors file
* Add trailing comma to pass tests
* Update to follow python style guide
* Update about.py
* Revert "Update _load_flags to use the default_flag_names dict"
This reverts commit caa8fea94b
.
* Use require_refresh() instead of storing default flag names
This commit is contained in:
parent
2727cf39b2
commit
e373b0ed9b
4 changed files with 18 additions and 1 deletions
|
@ -213,6 +213,7 @@ wackbyte <wackbyte@protonmail.com>
|
|||
GithubAnon0000 <GithubAnon0000@users.noreply.github.com>
|
||||
Mike Hardy <github@mikehardy.net>
|
||||
Danika_Dakika <https://github.com/Danika-Dakika>
|
||||
Mumtaz Hajjo Alrifai <mumtazrifai@protonmail.com>
|
||||
|
||||
********************
|
||||
|
||||
|
|
|
@ -214,6 +214,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
|
|||
"Gregory Abrasaldo",
|
||||
"Danika_Dakika",
|
||||
"Marcelo Vasconcelos",
|
||||
"Mumtaz Hajjo Alrifai",
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -453,7 +453,9 @@ class SidebarTreeView(QTreeView):
|
|||
|
||||
def _on_rename(self, item: SidebarItem, text: str) -> bool:
|
||||
new_name = text.replace('"', "")
|
||||
if new_name and new_name != item.name:
|
||||
if not new_name and item.item_type == SidebarItemType.FLAG:
|
||||
self.restore_default_flag_name(item)
|
||||
elif new_name and new_name != item.name:
|
||||
if item.item_type == SidebarItemType.DECK:
|
||||
self.rename_deck(item, new_name)
|
||||
elif item.item_type == SidebarItemType.SAVED_SEARCH:
|
||||
|
@ -1089,6 +1091,10 @@ class SidebarTreeView(QTreeView):
|
|||
item.name = new_name
|
||||
self.mw.flags.rename_flag(item.id, new_name)
|
||||
|
||||
def restore_default_flag_name(self, item: SidebarItem) -> None:
|
||||
self.mw.flags.restore_default_flag_name(item.id)
|
||||
item.name = self.mw.flags.get_flag(item.id).label
|
||||
|
||||
# Decks
|
||||
###########################
|
||||
|
||||
|
|
|
@ -55,6 +55,15 @@ class FlagManager:
|
|||
self.mw.col.set_config("flagLabels", labels)
|
||||
gui_hooks.flag_label_did_change()
|
||||
|
||||
def restore_default_flag_name(self, flag_index: int) -> None:
|
||||
labels = self.mw.col.get_config("flagLabels", {})
|
||||
if str(flag_index) not in labels:
|
||||
return
|
||||
del labels[str(flag_index)]
|
||||
self.mw.col.set_config("flagLabels", labels)
|
||||
self.require_refresh()
|
||||
gui_hooks.flag_label_did_change()
|
||||
|
||||
def require_refresh(self) -> None:
|
||||
"Discard cached labels."
|
||||
self._flags = []
|
||||
|
|
Loading…
Reference in a new issue