You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/action_system/working_with_custom_actions.md
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,12 @@ public class SimplePopDialogAction extends AnAction {
23
23
}
24
24
```
25
25
26
+
**Note** the `SimplePopDialogAction` does not have class fields of any kind. This is because an instance of `AnAction` class
27
+
exists for the entire lifetime of the application. If `AnAction` class uses a field to store data which has a shorter
28
+
lifetime, and doesn't clear this data promptly, the data will be leaked. For example, any `AnAction` data that exists
29
+
only within the context of a `Project` will cause the `Project` to be kept in memory after the user has closed it.
30
+
31
+
26
32
### 1.2. Overriding actionPerformed()
27
33
28
34
The [AnAction](upsource:///platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java)
@@ -103,14 +109,23 @@ In order to make the action do something we need to add code to the `SimplePopDi
103
109
The following code gets information from the `anActionEvent` input parameter and constructs a simple message dialog.
104
110
A generic icon, and the `description` and `text` attributes from the invoking menu action are displayed.
105
111
112
+
For demonstration purposes the `AnActionEvent.getData()` method tests if a [Navigatable](upsource:///platform/core-api/src/com/intellij/pom/Navigatable.java)
113
+
object is available, meaning e.g. an element has been selected in the editor. If so, information about
114
+
the selected element is opportunistically added to the dialog.
0 commit comments