public abstract class AnAction extends java.lang.Object implements PossiblyDumbAware
actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent)
and optionally to override update(com.intellij.openapi.actionSystem.AnActionEvent)
. By overriding the
update(com.intellij.openapi.actionSystem.AnActionEvent)
method you can dynamically change action's presentation
depending on the place (for more information on places see ActionPlaces
.
The same action can have various presentations.
public class MyAction extends AnAction { public MyAction() { // ... } public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); if (e.getPlace().equals(ActionPlaces.MAIN_MENU)) { presentation.setText("My Menu item name"); } else if (e.getPlace().equals(ActionPlaces.MAIN_TOOLBAR)) { presentation.setText("My Toolbar item name"); } } public void actionPerformed(AnActionEvent e) { ... } }
AnActionEvent
,
Presentation
,
ActionPlaces
,
DumbAwareAction
Modifier and Type | Class and Description |
---|---|
static interface |
AnAction.TransparentUpdate |
Modifier and Type | Field and Description |
---|---|
static Key<java.util.List<AnAction>> |
ACTIONS_KEY |
static AnAction[] |
EMPTY_ARRAY |
Constructor and Description |
---|
AnAction()
Creates a new action with its text, description and icon set to
null . |
AnAction(javax.swing.Icon icon)
Creates a new action with
icon provided. |
AnAction(java.lang.String text)
Creates a new action with the specified text.
|
AnAction(java.lang.String text,
java.lang.String description,
javax.swing.Icon icon)
Constructs a new action with the specified text, description and icon.
|
AnAction(java.util.function.Supplier<java.lang.String> dynamicText)
Creates a new action with the specified text.
|
AnAction(java.util.function.Supplier<java.lang.String> dynamicText,
javax.swing.Icon icon)
Constructs a new action with the specified dynamicText, dynamicDescription and icon.
|
AnAction(java.util.function.Supplier<java.lang.String> dynamicText,
java.util.function.Supplier<java.lang.String> dynamicDescription,
javax.swing.Icon icon)
Constructs a new action with the specified dynamicText, dynamicDescription and icon.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
actionPerformed(AnActionEvent e)
Implement this method to provide your action handler.
|
void |
addTextOverride(java.lang.String place,
java.lang.String text) |
void |
applyTextOverride(AnActionEvent e) |
void |
beforeActionPerformedUpdate(AnActionEvent e)
Same as
update(AnActionEvent) but is calls immediately before actionPerformed() as final check guard. |
void |
copyFrom(AnAction sourceAction)
Copies template presentation and shortcuts set from
sourceAction . |
void |
copyShortcutFrom(AnAction sourceAction) |
boolean |
displayTextInToolbar()
Override with true returned if your action has to display its text along with the icon when placed in the toolbar
|
static Project |
getEventProject(AnActionEvent e) |
ShortcutSet |
getShortcutSet()
Returns the shortcut set associated with this action.
|
Presentation |
getTemplatePresentation()
Returns a template presentation that will be used
as a template for created presentations.
|
java.lang.String |
getTemplateText()
Returns default action text.
|
boolean |
isDefaultIcon()
Returns true if the action has an internal, not user-customized icon.
|
boolean |
isEnabledInModalContext() |
boolean |
isInInjectedContext() |
boolean |
isTransparentUpdate() |
void |
registerCustomShortcutSet(int keyCode,
int modifiers,
javax.swing.JComponent component) |
void |
registerCustomShortcutSet(javax.swing.JComponent component,
Disposable parentDisposable) |
void |
registerCustomShortcutSet(ShortcutSet shortcutSet,
javax.swing.JComponent component)
Registers a set of shortcuts that will be processed when the specified component
is the ancestor of focused component.
|
void |
registerCustomShortcutSet(ShortcutSet shortcutSet,
javax.swing.JComponent component,
Disposable parentDisposable) |
void |
setDefaultIcon(boolean isDefaultIconSet)
Sets the flag indicating whether the action has an internal or a user-customized icon.
|
protected void |
setEnabledInModalContext(boolean enabledInModalContext) |
void |
setInjectedContext(boolean worksInInjected)
Enables automatic detection of injected fragments in editor.
|
protected void |
setShortcutSet(ShortcutSet shortcutSet) |
boolean |
startInTransaction()
Deprecated.
unused
|
java.lang.String |
toString() |
void |
unregisterCustomShortcutSet(javax.swing.JComponent component) |
void |
update(AnActionEvent e)
Updates the state of the action.
|
boolean |
useSmallerFontForTextInToolbar()
Override with true returned if your action displays text in a smaller font (same as toolbar combobox font) when placed in the toolbar
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isDumbAware
public static final AnAction[] EMPTY_ARRAY
public AnAction()
null
.public AnAction(javax.swing.Icon icon)
icon
provided. Its text, description set to null
.icon
- Default icon to appear in toolbars and menus (Note some platform don't have icons in menu).public AnAction(java.lang.String text)
null
.text
- Serves as a tooltip when the presentation is a button and the name of the
menu item when the presentation is a menu item.public AnAction(java.util.function.Supplier<java.lang.String> dynamicText)
null
.dynamicText
- Serves as a tooltip when the presentation is a button and the name of the
menu item when the presentation is a menu item.
Use it if you need to localize action text.public AnAction(java.lang.String text, java.lang.String description, javax.swing.Icon icon)
text
- Serves as a tooltip when the presentation is a button and the name of the
menu item when the presentation is a menu itemdescription
- Describes current action, this description will appear on
the status bar when presentation has focusicon
- Action's iconpublic AnAction(java.util.function.Supplier<java.lang.String> dynamicText, javax.swing.Icon icon)
dynamicText
- Serves as a tooltip when the presentation is a button and the name of the
menu item when the presentation is a menu item. Use it if you need to localize action text.icon
- Action's iconpublic AnAction(java.util.function.Supplier<java.lang.String> dynamicText, java.util.function.Supplier<java.lang.String> dynamicDescription, javax.swing.Icon icon)
dynamicText
- Serves as a tooltip when the presentation is a button and the name of the
menu item when the presentation is a menu item. Use it if you need to localize action text.dynamicDescription
- Describes current action, this dynamicDescription will appear on
the status bar when presentation has focus. Use it if you need to localize description.icon
- Action's iconpublic final ShortcutSet getShortcutSet()
public final void registerCustomShortcutSet(ShortcutSet shortcutSet, javax.swing.JComponent component)
shortcutSet
- the shortcuts for the action.component
- the component for which the shortcuts will be active.public final void registerCustomShortcutSet(int keyCode, int modifiers, javax.swing.JComponent component)
public final void registerCustomShortcutSet(ShortcutSet shortcutSet, javax.swing.JComponent component, Disposable parentDisposable)
public final void registerCustomShortcutSet(javax.swing.JComponent component, Disposable parentDisposable)
public final void unregisterCustomShortcutSet(javax.swing.JComponent component)
public final void copyFrom(AnAction sourceAction)
sourceAction
.
Consider using ActionUtil.copyFrom(AnAction, String)
instead.public final void copyShortcutFrom(AnAction sourceAction)
public final boolean isEnabledInModalContext()
protected final void setEnabledInModalContext(boolean enabledInModalContext)
public boolean displayTextInToolbar()
public boolean useSmallerFontForTextInToolbar()
public void update(AnActionEvent e)
actionPerformed(AnActionEvent)
method and notify
the user that action cannot be executed if it's the case.
If the action is added to a toolbar, its "update" can be called twice a second, but only if there was
any user activity or a focus transfer. If your action's availability is changed
in absence of any of these events, please call ActivityTracker.getInstance().inc()
to notify
action subsystem to update all toolbar actions when your subsystem's determines that its actions' visibility might be affected.e
- Carries information on the invocation place and data availablepublic void beforeActionPerformedUpdate(AnActionEvent e)
update(AnActionEvent)
but is calls immediately before actionPerformed() as final check guard.
Default implementation delegates to update(AnActionEvent)
.e
- Carries information on the invocation place and data availablepublic final Presentation getTemplatePresentation()
public abstract void actionPerformed(AnActionEvent e)
e
- Carries information on the invocation placeprotected void setShortcutSet(ShortcutSet shortcutSet)
public void setDefaultIcon(boolean isDefaultIconSet)
isDefaultIconSet
- true if the icon is internal, false if the icon is customized by the user.public boolean isDefaultIcon()
public void setInjectedContext(boolean worksInInjected)
public boolean isInInjectedContext()
public boolean isTransparentUpdate()
@Deprecated public boolean startInTransaction()
public void addTextOverride(java.lang.String place, java.lang.String text)
public void applyTextOverride(AnActionEvent e)
public static Project getEventProject(AnActionEvent e)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getTemplateText()