From 23336f7c76572fa3de2c6d514bc0e3c910d6a171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Wed, 5 Mar 2025 11:22:15 +0100 Subject: [PATCH] basic_action_system.md: note about reusable logic --- topics/basics/basic_action_system.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/topics/basics/basic_action_system.md b/topics/basics/basic_action_system.md index d2499d1d4..903eee15a 100644 --- a/topics/basics/basic_action_system.md +++ b/topics/basics/basic_action_system.md @@ -141,6 +141,12 @@ An example of enabling a menu action based on whether a project is open is demon When the user selects an enabled action, be it from a menu or toolbar, the action's `AnAction.actionPerformed()` method is called. This method contains the code executed to perform the action, and it is here that the real work gets done. +> Reusable logic must *not* be exposed in the `AnAction` implementation via `static` methods (Java) or `companion object` (Kotlin). +> +> Instead, introduce dedicated methods in utility classes or [](plugin_services.md). +> +{title="Reusable Logic" style="warning"} + By using the `AnActionEvent` methods and `CommonDataKeys`, objects such as the `Project`, `Editor`, `PsiFile`, and other information is available. For example, the `actionPerformed()` method can modify, remove, or add PSI elements to a file open in the editor.