From d553d7d893bf1f403e85215a9db5d76e94e2b674 Mon Sep 17 00:00:00 2001 From: William Kariampuzha <86256217+wzkariampuzha@users.noreply.github.com> Date: Sun, 18 May 2025 06:55:37 -0500 Subject: [PATCH 1/4] Update onTextChange.py added the no tags filter tag:0 It would be great if the search box also had "any flags" filter which is -flag:0 --- src/onTextChange.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/onTextChange.py b/src/onTextChange.py index 4bdd485..b9c1e0e 100755 --- a/src/onTextChange.py +++ b/src/onTextChange.py @@ -650,6 +650,7 @@ def onSearchEditTextChange( "pink": "5", "turquoise": "6", "purple": "7", + "no flags": "0", }, "surround_with_quotes": False, "infotext": False, From 4d0d46ab018e23223e3928def9b510287d23b555 Mon Sep 17 00:00:00 2001 From: William Kariampuzha <86256217+wzkariampuzha@users.noreply.github.com> Date: Sun, 18 May 2025 07:31:18 -0500 Subject: [PATCH 2/4] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 6bd921b..76bfd9a 100755 --- a/README.md +++ b/README.md @@ -1,3 +1 @@ -Add-on for Anki, see [Ankiweb](https://ankiweb.net/shared/info/1052724801). - -for the license see on top of `src/__init__.py`. +To add the "any flags" and "no red flags" you need to create a new flag_values() function in helpers (see [here](https://github.com/wzkariampuzha/anki__BetterSearch/blob/d553d7d893bf1f403e85215a9db5d76e94e2b674/src/helpers.py#L31C1-L38C21)) then you need to trace the is: functions all the way back and copy them. From 292fce79ea2a7096a129f0d95d8fb208afe6a5d0 Mon Sep 17 00:00:00 2001 From: William Kariampuzha Date: Sun, 18 May 2025 11:47:18 -0500 Subject: [PATCH 3/4] first attempt at editing the flag search feature --- README.md | 4 +++- notes.md | 1 + src/config.json | 1 + src/config.schema.json | 5 +++++ src/config_update.py | 4 ++++ src/helpers.py | 28 ++++++++++++++++++++++++++++ src/onTextChange.py | 27 ++++++++++++++------------- 7 files changed, 56 insertions(+), 14 deletions(-) create mode 100755 notes.md diff --git a/README.md b/README.md index 76bfd9a..6bd921b 100755 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -To add the "any flags" and "no red flags" you need to create a new flag_values() function in helpers (see [here](https://github.com/wzkariampuzha/anki__BetterSearch/blob/d553d7d893bf1f403e85215a9db5d76e94e2b674/src/helpers.py#L31C1-L38C21)) then you need to trace the is: functions all the way back and copy them. +Add-on for Anki, see [Ankiweb](https://ankiweb.net/shared/info/1052724801). + +for the license see on top of `src/__init__.py`. diff --git a/notes.md b/notes.md new file mode 100755 index 0000000..76bfd9a --- /dev/null +++ b/notes.md @@ -0,0 +1 @@ +To add the "any flags" and "no red flags" you need to create a new flag_values() function in helpers (see [here](https://github.com/wzkariampuzha/anki__BetterSearch/blob/d553d7d893bf1f403e85215a9db5d76e94e2b674/src/helpers.py#L31C1-L38C21)) then you need to trace the is: functions all the way back and copy them. 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 b9c1e0e..2e2bf17 100755 --- a/src/onTextChange.py +++ b/src/onTextChange.py @@ -637,21 +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", - "no flags": "0", - }, + "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", @@ -894,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: From f99e989975efe782ebf28051ecafc0e57623202d Mon Sep 17 00:00:00 2001 From: William Kariampuzha Date: Sun, 18 May 2025 12:11:42 -0500 Subject: [PATCH 4/4] removed temp notes --- notes.md | 1 - 1 file changed, 1 deletion(-) delete mode 100755 notes.md diff --git a/notes.md b/notes.md deleted file mode 100755 index 76bfd9a..0000000 --- a/notes.md +++ /dev/null @@ -1 +0,0 @@ -To add the "any flags" and "no red flags" you need to create a new flag_values() function in helpers (see [here](https://github.com/wzkariampuzha/anki__BetterSearch/blob/d553d7d893bf1f403e85215a9db5d76e94e2b674/src/helpers.py#L31C1-L38C21)) then you need to trace the is: functions all the way back and copy them.