diff --git a/src/config.json b/src/config.json index 88a9e66..0405c17 100755 --- a/src/config.json +++ b/src/config.json @@ -68,6 +68,7 @@ "modify_deck": true, "modify_field": true, "modify_flag": true, + "modify_flag__show_explanations": true, "modify_is": true, "modify_is__show_explanations": true, "modify_note": true, diff --git a/src/config.schema.json b/src/config.schema.json index 02097ab..09ab6eb 100644 --- a/src/config.schema.json +++ b/src/config.schema.json @@ -314,6 +314,11 @@ "default": true, "description": "" }, + "modify_flag__show_explanations": { + "type": "boolean", + "default": true, + "description": "" + }, "modify_is": { "type": "boolean", "default": true, diff --git a/src/config_update.py b/src/config_update.py index cfe9ab6..9946c35 100644 --- a/src/config_update.py +++ b/src/config_update.py @@ -67,6 +67,10 @@ def get_default_conf_for_this_addon(addon_folder_name): "modify_deck": ["open filter dialog after typing these search operators", "modify_deck"], "modify_field": ["open filter dialog after typing these search operators", "modify_field"], "modify_flag": ["open filter dialog after typing these search operators", "modify_flag"], + "modify_flag__show_explanations": [ + "open filter dialog after typing these search operators", + "modify_flag__show_explanations", + ], "modify_is": ["open filter dialog after typing these search operators", "modify_is"], "modify_is__show_explanations": [ "open filter dialog after typing these search operators", diff --git a/src/helpers.py b/src/helpers.py index 80fb64d..e0e8116 100755 --- a/src/helpers.py +++ b/src/helpers.py @@ -55,6 +55,34 @@ def is_values_with_explanations(): "is:learn -is:review (cards that are in learning for the first time)": "is:learn -is:review", } +def flag_values(): + return [ + "flag:1", + "flag:2", + "flag:3", + "flag:4", + "flag:5", + "flag:6", + "flag:7", + "flag:0", + "-flag:0", + "-flag:1", + ] + + +def flag_values_with_explanations(): + return { + "red flag": "flag:1", + "orange flag": "flag:2", + "green flag": "flag:3", + "blue flag": "flag:4", + "pink flag": "flag:5", + "turquoise flag": "flag:6", + "purple flag": "flag:7", + "no flags": "flag:0", + "any flag": "-flag:0", + "no red flags": "-flag:1", + } def props(): all_version_texts = { diff --git a/src/onTextChange.py b/src/onTextChange.py index 4bdd485..2e2bf17 100755 --- a/src/onTextChange.py +++ b/src/onTextChange.py @@ -637,20 +637,13 @@ def onSearchEditTextChange( if matches_search_operator(before, "flag:") and ( gc(["open filter dialog after typing these search operators", "modify_flag"]) or from_button ): + expl = gc(["open filter dialog after typing these search operators", "modify_flag__show_explanations"]) prefixed_with_minus = True if minus_precedes_search_operator(before, "flag:") else False vals = { - "remove_from_end_of_before": -1 if prefixed_with_minus else 0, + "remove_from_end_of_before": (0 if expl else -5) - (1 if prefixed_with_minus else 0), "insert_space_at_pos_in_before": -5, - "dict_for_dialog": "flags", - "values_for_filter_dialog": { - "red": "1", - "orange": "2", - "green": "3", - "blue": "4", - "pink": "5", - "turquoise": "6", - "purple": "7", - }, + "dict_for_dialog": "flags_with_explanations" if expl else False, + "values_for_filter_dialog": flag_values_with_explanations() if expl else flag_values(), "surround_with_quotes": False, "infotext": False, "windowtitle": "Anki: Search by Flag", @@ -893,7 +886,16 @@ def fieldnames_modelname_dict(): ) # triggering a search makes no sense here: the user needs to fill in the search term for prop: ############ generate sel_list - if vals["dict_for_dialog"] == "flags": + if vals["dict_for_dialog"] == "flags_with_explanations": + already_in_line = befmod[:-5] # substract flag: + new_text = already_in_line + ("-" if is_exclusion else "") + d.sel_value_from_dict + after + new_pos = len(already_in_line + ("-" if is_exclusion else "") + d.sel_value_from_dict) + return ( + new_text, + new_pos, + False, + ) # triggering a search makes no sense here: the user needs to fill in the search term for is: + elif vals["dict_for_dialog"] == "flags": sel_list = [d.sel_value_from_dict] if just_returned_input_line_content: