Use custom flag labels for browser actions

This commit is contained in:
RumovZ 2021-05-19 10:34:36 +02:00
parent 9816227b5c
commit 30736ddf75
3 changed files with 12 additions and 1 deletions

View File

@ -42,6 +42,7 @@ from aqt.utils import (
current_top_level_widget,
ensure_editor_saved,
getTag,
load_flags,
no_arg_trigger,
openHelp,
qtMenuShortcutWorkaround,
@ -176,6 +177,7 @@ class Browser(QMainWindow):
qconnect(
f.actionBlue_Flag.triggered, lambda: self.set_flag_of_selected_cards(4)
)
self._update_flag_labels()
qconnect(f.actionExport.triggered, self._on_export_notes)
# jumps
qconnect(f.actionPreviousCard.triggered, self.onPreviousCard)
@ -723,6 +725,10 @@ where id in %s"""
qtMenuShortcutWorkaround(self.form.menuFlag)
def _update_flag_labels(self) -> None:
for flag in load_flags(self.col):
getattr(self.form, flag[3]).setText(flag[0])
def toggle_mark_of_selected_notes(self, checked: bool) -> None:
if checked:
self.add_tags_to_selected_notes(tags=MARKED_TAG)

View File

@ -875,6 +875,7 @@ class SidebarTreeView(QTreeView):
labels[str(item.id)] = new_name
self.col.set_config("flagLabels", labels)
item.name = new_name
self.browser._update_flag_labels()
self.refresh()
# Decks

View File

@ -1026,7 +1026,7 @@ def no_arg_trigger(func: Callable) -> Callable:
return pyqtSlot()(func) # type: ignore
def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode]]:
def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode, str]]:
labels = cast(Dict[str, str], col.get_config("flagLabels", {}))
icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED)
@ -1035,21 +1035,25 @@ def load_flags(col: Collection) -> List[Tuple[str, ColoredIcon, SearchNode]]:
labels["1"] if "1" in labels else tr.actions_red_flag(),
icon.with_color(colors.FLAG1_FG),
SearchNode(flag=SearchNode.FLAG_RED),
"actionRed_Flag",
),
(
labels["2"] if "2" in labels else tr.actions_orange_flag(),
icon.with_color(colors.FLAG2_FG),
SearchNode(flag=SearchNode.FLAG_ORANGE),
"actionOrange_Flag",
),
(
labels["3"] if "3" in labels else tr.actions_green_flag(),
icon.with_color(colors.FLAG3_FG),
SearchNode(flag=SearchNode.FLAG_GREEN),
"actionGreen_Flag",
),
(
labels["4"] if "4" in labels else tr.actions_blue_flag(),
icon.with_color(colors.FLAG4_FG),
SearchNode(flag=SearchNode.FLAG_BLUE),
"actionBlue_Flag",
),
]