Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default flag name when flag is renamed to empty string #3826

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mumtazrifai
Copy link

Fixes #3818

Right click on a flag in the browser sidebar > Rename > Delete all of the text > Hit Enter to confirm.
After doing this, Anki will go back to using the default name of the flag, including using the correct translation if the user switches languages.

anki-flags

@YukiNagat0
Copy link
Contributor

Python Style Guide suggestion:

if new_name == "" and item.item_type == SidebarItemType.FLAG:

Change the if new_name == "" to if not new_name

@dae
Copy link
Member

dae commented Feb 18, 2025

Thank you for contributing!

This could be done in a simpler way. Instead of storing a translation, simply delete the entry for that key from the dictionary, so that the default translation is used instead. This would change less code, and ensure the text remains correct when the user switches interface language.

@mumtazrifai
Copy link
Author

I already do delete the dictionary entry from the "flagLabels" config entry here:

anki/qt/aqt/flags.py

Lines 67 to 74 in 8380131

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.get_flag(flag_index).label = self.default_flag_names[flag_index]
self.mw.col.set_config("flagLabels", labels)
gui_hooks.flag_label_did_change()

When I tested it, the flag label did switch to the correct translation after I changed the language, which indicates to me that it is using the default value and not a stored value in the config.

The reason why I also store the translations in default_flag_names is to make sure that the displayed name of the flag is updated after the function is called. Though after taking another look it seems like that's unnecessary and I can just call require_refresh() to accomplish the same thing.

I hope I correctly understood what you meant! If not please clarify further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Browser: can't restore default flag names
3 participants