From 7f268fa5b4eb862460be245c314c3ae47a912814 Mon Sep 17 00:00:00 2001 From: Martin Rykfors Date: Wed, 14 Aug 2024 12:59:00 +0200 Subject: [PATCH] Add menu choosing helper from pokey_talon (#1393) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- BREAKING_CHANGES.txt | 7 ++++++- core/homophones/homophones.py | 15 +++++++++++++++ core/homophones/homophones_open.talon | 5 +---- core/menu_choose/menu_choose.py | 14 ++++++++++++++ core/menu_choose/menu_choose.talon | 3 +++ plugin/dropdown/dropdown.talon | 3 --- 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 core/menu_choose/menu_choose.py create mode 100644 core/menu_choose/menu_choose.talon delete mode 100644 plugin/dropdown/dropdown.talon diff --git a/BREAKING_CHANGES.txt b/BREAKING_CHANGES.txt index 6c9d44c4b9..af43f37ac7 100644 --- a/BREAKING_CHANGES.txt +++ b/BREAKING_CHANGES.txt @@ -6,7 +6,12 @@ applied given the delay between changes being submitted and the time they were r and merged. --- -* 2023-06-06 Deprecate `go marks` command for VSCode. Use 'bar marks' instead. +* 2024-05-30 Deprecate 'drop down ' in favor of overridable 'choose' helper +* 2024-01-27 Deprecate '' command without a spoken prefix like `numb`. +See `numbers.talon` and `numbers_unprefixed.talon.` If in the future you want to still use +unprefixed numbers, you will need to comment out the +`tag(): user.prefixed_numbers` line in your `settings.talon` file. +* 2023-06-06 Deprecate `go ` command for VSCode. Use 'bar marks' instead. * 2023-02-04 Deprecate `murder` command for i3wm. Use 'win kill' instead. * 2022-12-11 Deprecate user.insert_with_history. Just use `user.add_phrase_to_history(text); insert(text)` instead. See #939. diff --git a/core/homophones/homophones.py b/core/homophones/homophones.py index 7ae3466836..00faee44b6 100644 --- a/core/homophones/homophones.py +++ b/core/homophones/homophones.py @@ -227,3 +227,18 @@ def homophones_get(word: str) -> [str] or None: if word in all_homophones: return all_homophones[word] return None + + +ctx_homophones_open = Context() +ctx_homophones_open.matches = """ +tag: user.homophones_open +""" + + +@ctx_homophones_open.action_class("user") +class UserActions: + def choose(number_small: int): + """Choose the nth homophone""" + result = actions.user.homophones_select(number_small) + actions.insert(result) + actions.user.homophones_hide() diff --git a/core/homophones/homophones_open.talon b/core/homophones/homophones_open.talon index 9e376e834e..2b7417e41e 100644 --- a/core/homophones/homophones_open.talon +++ b/core/homophones/homophones_open.talon @@ -1,9 +1,6 @@ tag: user.homophones_open - -choose : - result = user.homophones_select(number_small) - insert(result) - user.homophones_hide() + choose : result = user.homophones_select(number_small) insert(user.formatted_text(result, formatters)) diff --git a/core/menu_choose/menu_choose.py b/core/menu_choose/menu_choose.py new file mode 100644 index 0000000000..52bb2ebc5e --- /dev/null +++ b/core/menu_choose/menu_choose.py @@ -0,0 +1,14 @@ +from talon import Context, Module, actions + +mod = Module() + + +@mod.action_class +class Actions: + def choose(number_small: int): + """Choose the nth item""" + actions.key(f"down:{number_small-1} enter") + + def choose_up(number_small: int): + """Choose the nth item up""" + actions.key(f"up:{number_small} enter") diff --git a/core/menu_choose/menu_choose.talon b/core/menu_choose/menu_choose.talon new file mode 100644 index 0000000000..8046189f1b --- /dev/null +++ b/core/menu_choose/menu_choose.talon @@ -0,0 +1,3 @@ +# pick item from a dropdown +selector : user.choose(number_small) +selector up : user.choose_up(number_small) diff --git a/plugin/dropdown/dropdown.talon b/plugin/dropdown/dropdown.talon deleted file mode 100644 index 66a7df2b0e..0000000000 --- a/plugin/dropdown/dropdown.talon +++ /dev/null @@ -1,3 +0,0 @@ -# pick item from a dropdown -selector : key("down:{number_small-1} enter") -selector up : key("up:{number_small} enter")