[md] "register actions" rewritten accordingly to review

This commit is contained in:
Anna Bulenkova 2015-01-20 13:26:33 +01:00
parent 7cd3b817e3
commit e80017689d

View File

@ -10,7 +10,8 @@ or be bound to UI element and could be invoked on demand. These UI elements incl
**TODO - links to source** **TODO - links to source**
#Working with custom actions. #Working with custom actions.
An action is technically a class, derived from the [AnAction] (https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java) class. An action is technically a class, derived from the [AnAction] (https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java)
class.
To update the state of the action, the method AnAction.update() is periodically called by IDEA. To update the state of the action, the method AnAction.update() is periodically called by IDEA.
The object of type [AnActionEvent] (https://github.com/JetBrains/intellij-community/blob/ff16ce78a1e0ddb6e67fd1dbc6e6a597e20d483a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java) The object of type [AnActionEvent] (https://github.com/JetBrains/intellij-community/blob/ff16ce78a1e0ddb6e67fd1dbc6e6a597e20d483a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java)
passed to this method carries the information about the current context for the action, passed to this method carries the information about the current context for the action,
@ -18,14 +19,14 @@ and in particular, the specific presentation which needs to be updated.
##Creating actions. ##Creating actions.
To create a new we need to extend To create a new we need to extend
[AnAction] () [AnAction] (https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java)
class class:
public class SimpleAction extends AnAction { public class SimpleAction extends AnAction {
} }
The only method of an inheritor of The only method of an inheritor of
[AnAction] () [AnAction] (https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java)
which needs to be overridden is ```public void actionPerformed(AnActionEvent anActionEvent);``` which needs to be overridden is ```public void actionPerformed(AnActionEvent anActionEvent);```
, and it should contain a part of code to be executed after the action has been invoked. , and it should contain a part of code to be executed after the action has been invoked.
@ -60,49 +61,44 @@ file will look like this:
</action> </action>
</actions> </actions>
------------ Full list of action's attributes can also be set manually in
[plugin.xml]()
configuration file like the following code sample shows:
Under construction <actions>
TODO: rewrite accordingly to the guidelines/review <!-- Add your actions here -->
<!-- The <action> element defines an action to register.
<actions> The mandatory "id" attribute specifies an unique identifier for the action.
<!-- The <action> element defines an action to register. The mandatory "class" attribute specifies the full-qualified name of the class implementing the action.
The mandatory "id" attribute specifies an unique identifier for the action. The mandatory "text" attribute specifies the text of the action (tooltip for toolbar button or text for menu item).
The mandatory "class" attribute specifies the full-qualified name of the class implementing the action. The optional "use-shortcut-of" attribute specifies the ID of the action whose keyboard shortcut this action will use.
The mandatory "text" attribute specifies the text of the action (tooltip for toolbar button or text for menu item). The optional "description" attribute specifies the text which is displayed in the status bar when the action is focused.
The optional "use-shortcut-of" attribute specifies the ID of the action whose keyboard shortcut this action will use. The optional "icon" attribute specifies the icon which is displayed on the toolbar button or next to the menu item. -->
The optional "description" attribute specifies the text which is displayed in the status bar when the action is focused. <action id="org.jetbrains.tutorials.actions.SimpleAction" class="org.jetbrains.tutorials.actions.SimpleAction"
The optional "icon" attribute specifies the icon which is displayed on the toolbar button or next to the menu item. --> text="Simple Action" description="IntelliJ Action System Demo">
<!-- The <keyboard-shortcut> node specifies the keyboard shortcut for the action. An action can have several keyboard shortcuts.
<action id="PluginSample.DummyAction" class="SimpleAction" text="Dummy Action" description="Illustrates how to plug an action in"> The mandatory "first-keystroke" attribute specifies the first keystroke of the action. The key strokes are specified according to the regular Swing rules.
The optional "second-keystroke" attribute specifies the second keystroke of the action.
<!-- The <keyboard-shortcut> node specifies the keyboard shortcut for the action. An action can have several keyboard shortcuts. The mandatory "keymap" attribute specifies the keymap for which the action is active. IDs of the standard keymaps are defined as
The mandatory "first-keystroke" attribute specifies the first keystroke of the action. The key strokes are specified according to the regular Swing rules. constants in the com.intellij.openapi.keymap.KeymapManager class. -->
The optional "second-keystroke" attribute specifies the second keystroke of the action. <keyboard-shortcut first-keystroke="control alt A" second-keystroke="C" keymap="$default"/>
The mandatory "keymap" attribute specifies the keymap for which the action is active. IDs of the standard keymaps are defined as <!-- The <mouse-shortcut> node specifies the mouse shortcut for the action. An action can have several mouse shortcuts.
constants in the com.intellij.openapi.keymap.KeymapManager class. --> The mandatory "keystroke" attribute specifies the clicks and modifiers for the action. It is defined as a sequence of words separated by spaces:
<keyboard-shortcut first-keystroke="control alt A" second-keystroke="C" keymap="$default"/> "button1", "button2", "button3" for the mouse buttons; "shift", "control", "meta", "alt", "altGraph" for the modifier keys;
"doubleClick" if the action is activated by a double-click of the button.
<!-- The <mouse-shortcut> node specifies the mouse shortcut for the action. An action can have several mouse shortcuts. The mandatory "keymap" attribute specifies the keymap for which the action is active. IDs of the standard keymaps are defined as
The mandatory "keystroke" attribute specifies the clicks and modifiers for the action. It is defined as a sequence of words separated by spaces: constants in the com.intellij.openapi.keymap.KeymapManager class. -->
"button1", "button2", "button3" for the mouse buttons; "shift", "control", "meta", "alt", "altGraph" for the modifier keys; <mouse-shortcut keystroke="control button3 doubleClick" keymap="$default"/>
"doubleClick" if the action is activated by a double-click of the button. <!-- The <add-to-group> node specifies that the action should be added to an existing group. An action can be added to several groups.
The mandatory "keymap" attribute specifies the keymap for which the action is active. IDs of the standard keymaps are defined as The mandatory "group-id" attribute specifies the ID of the group to which the action is added.
constants in the com.intellij.openapi.keymap.KeymapManager class. --> The group must be implemented by an instance of the DefaultActionGroup class.
<mouse-shortcut keystroke="control button3 doubleClick" keymap="$default"/> The mandatory "anchor" attribute specifies the position of the action in the group relative to other actions. It can have the values
"first", "last", "before" and "after".
<!-- The <add-to-group> node specifies that the action should be added to an existing group. An action can be added to several groups. The "relative-to-action" attribute is mandatory if the anchor is set to "before" and "after", and specifies the action before or after which
The mandatory "group-id" attribute specifies the ID of the group to which the action is added. the current action is inserted. -->
The group must be implemented by an instance of the DefaultActionGroup class. <add-to-group group-id="ToolsMenu" anchor="first"/>
The mandatory "anchor" attribute specifies the position of the action in the group relative to other actions. It can have the values </action>
"first", "last", "before" and "after". </actions>
The "relative-to-action" attribute is mandatory if the anchor is set to "before" and "after", and specifies the action before or after which
the current action is inserted. -->
<add-to-group group-id="ToolsMenu" anchor="after"/>
</action>
</actions>
[Link to source code] (https://github.com/JetBrains/intellij-sdk/blob/master/code_samples/plugin_sample/META-INF/plugin.xml)
----------- -----------