trigger an action button passively or on certain instigator Follow
i have a plugin that does an action through a button click event, if i want to trigger the same action through multiple instigators, is it possible?
for example if i want to trigger the action every 3 seconds or when the user writes a complete statement (a statement ending with semicolon), not only when the button is clicked, is it possible to trigger the same action if one of multiple events has occured?
if yes, how to trigger the action in both ways i mentioned above and where can i search for all the possible ways?
Please sign in to leave a comment.
I assume that you implemented your action as AnAction.
You can use ActionManager.getInstance().getAction("actionId") to find an action by ID and invoke its actionPerformed() directly, or use ActionManager.tryToExecute(), especially if you want to trigger it periodically (see https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000784304-How-to-schedule-AnActionEvent-actions- for more details).
Regarding the events that trigger actions, it's up to your use case, there is no limited list of the contexts an action can be triggered.
it worked out, but this method creates a new thread everytime i press the action button which is inefficient..
so focus with me for a minute:
- I have this Action class which is pinned in EditorPopupMenu:
- I have overridden ActionPerformed and created a local field:
- I inserted the following statement right after initializing runnable:
apparently everytime i click the action button, EdtExecutorService creates a new thread, but what i want is no matter how many times i press the action button, only 1 thread executes.
- i tried to put use this method with a boolean flag that indicates that i have already pressed the button
but it does not kill the thread, it remains running.
so in a nut shell, i want to know how to kill a task that is executed using (EdtExecutorServices).
i also want to know other thing: my original goal was to execute an action everytime the editor gets i new Complete syntax sentance (a line of code ends with semicolon), what kind of listener should i use?