|
1 |
| -from talon import Module, actions, app |
| 1 | +from talon import Module, actions |
2 | 2 |
|
3 |
| -from ..csv_overrides import init_csv_and_watch_changes |
4 | 3 | from ..targets.target_types import CursorlessTarget, ImplicitDestination
|
5 |
| -from .actions_callback import callback_action_defaults, callback_action_map |
6 |
| -from .actions_simple import ( |
7 |
| - no_wait_actions, |
8 |
| - no_wait_actions_post_sleep, |
9 |
| - simple_action_defaults, |
10 |
| -) |
11 | 4 | from .bring_move import BringMoveTargets
|
| 5 | +from .call import cursorless_call_action |
12 | 6 | from .execute_command import cursorless_execute_command_action
|
| 7 | +from .homophones import cursorless_homophones_action |
13 | 8 |
|
14 | 9 | mod = Module()
|
15 | 10 |
|
16 | 11 |
|
17 |
| -mod.list("cursorless_experimental_action", "Experimental actions") |
| 12 | +mod.list( |
| 13 | + "cursorless_simple_action", |
| 14 | + desc="Cursorless internal: simple actions", |
| 15 | +) |
| 16 | + |
| 17 | +mod.list( |
| 18 | + "cursorless_callback_action", |
| 19 | + desc="Cursorless internal: actions implemented via a callback function", |
| 20 | +) |
| 21 | + |
| 22 | +mod.list( |
| 23 | + "cursorless_custom_action", |
| 24 | + desc="Cursorless internal: user-defined custom actions", |
| 25 | +) |
| 26 | + |
| 27 | +mod.list( |
| 28 | + "cursorless_experimental_action", |
| 29 | + desc="Cursorless internal: experimental actions", |
| 30 | +) |
| 31 | + |
| 32 | +ACTION_LIST_NAMES = [ |
| 33 | + "simple_action", |
| 34 | + "callback_action", |
| 35 | + "paste_action", |
| 36 | + "bring_move_action", |
| 37 | + "swap_action", |
| 38 | + "wrap_action", |
| 39 | + "insert_snippet_action", |
| 40 | + "reformat_action", |
| 41 | + "experimental_action", |
| 42 | +] |
| 43 | + |
| 44 | +callback_actions = { |
| 45 | + "callAsFunction": cursorless_call_action, |
| 46 | + "findInDocument": actions.user.private_cursorless_find, |
| 47 | + "nextHomophone": cursorless_homophones_action, |
| 48 | +} |
| 49 | + |
| 50 | +# Don't wait for these actions to finish, usually because they hang on some kind of user interaction |
| 51 | +no_wait_actions = [ |
| 52 | + "generateSnippet", |
| 53 | + "rename", |
| 54 | +] |
| 55 | + |
| 56 | +# These are actions that we don't wait for, but still want to have a post action sleep |
| 57 | +no_wait_actions_post_sleep = { |
| 58 | + "rename": 0.3, |
| 59 | +} |
18 | 60 |
|
19 | 61 |
|
20 | 62 | @mod.capture(
|
@@ -42,8 +84,8 @@ def cursorless_action_or_ide_command(m) -> dict:
|
42 | 84 | class Actions:
|
43 | 85 | def cursorless_command(action_name: str, target: CursorlessTarget):
|
44 | 86 | """Perform cursorless command on target"""
|
45 |
| - if action_name in callback_action_map: |
46 |
| - callback_action_map[action_name](target) |
| 87 | + if action_name in callback_actions: |
| 88 | + callback_actions[action_name](target) |
47 | 89 | elif action_name in ["replaceWithTarget", "moveToTarget"]:
|
48 | 90 | actions.user.cursorless_bring_move(
|
49 | 91 | action_name, BringMoveTargets(target, ImplicitDestination())
|
@@ -79,33 +121,3 @@ def private_cursorless_action_or_ide_command(
|
79 | 121 | actions.user.cursorless_command(value, target)
|
80 | 122 | elif type == "ide_command":
|
81 | 123 | actions.user.cursorless_ide_command(value, target)
|
82 |
| - |
83 |
| - |
84 |
| -default_values = { |
85 |
| - "simple_action": simple_action_defaults, |
86 |
| - "callback_action": callback_action_defaults, |
87 |
| - "paste_action": {"paste": "pasteFromClipboard"}, |
88 |
| - "bring_move_action": {"bring": "replaceWithTarget", "move": "moveToTarget"}, |
89 |
| - "swap_action": {"swap": "swapTargets"}, |
90 |
| - "wrap_action": {"wrap": "wrapWithPairedDelimiter", "repack": "rewrap"}, |
91 |
| - "insert_snippet_action": {"snippet": "insertSnippet"}, |
92 |
| - "reformat_action": {"format": "applyFormatter"}, |
93 |
| -} |
94 |
| - |
95 |
| - |
96 |
| -ACTION_LIST_NAMES = list(default_values.keys()) + ["experimental_action"] |
97 |
| - |
98 |
| - |
99 |
| -def on_ready() -> None: |
100 |
| - init_csv_and_watch_changes("actions", default_values) |
101 |
| - init_csv_and_watch_changes( |
102 |
| - "experimental/experimental_actions", |
103 |
| - { |
104 |
| - "experimental_action": { |
105 |
| - "-from": "experimental.setInstanceReference", |
106 |
| - } |
107 |
| - }, |
108 |
| - ) |
109 |
| - |
110 |
| - |
111 |
| -app.register("ready", on_ready) |
|
0 commit comments