public class AnActionEvent extends java.lang.Object implements PlaceProvider<java.lang.String>
AnAction
.Constructor and Description |
---|
AnActionEvent(java.awt.event.InputEvent inputEvent,
DataContext dataContext,
java.lang.String place,
Presentation presentation,
ActionManager actionManager,
int modifiers) |
AnActionEvent(java.awt.event.InputEvent inputEvent,
DataContext dataContext,
java.lang.String place,
Presentation presentation,
ActionManager actionManager,
int modifiers,
boolean isContextMenuAction,
boolean isActionToolbar) |
Modifier and Type | Method and Description |
---|---|
void |
accept(AnActionEventVisitor visitor) |
static AnActionEvent |
createFromAnAction(AnAction action,
java.awt.event.InputEvent event,
java.lang.String place,
DataContext dataContext) |
static AnActionEvent |
createFromDataContext(java.lang.String place,
Presentation presentation,
DataContext dataContext) |
static AnActionEvent |
createFromInputEvent(AnAction action,
java.awt.event.InputEvent event,
java.lang.String place)
|
static AnActionEvent |
createFromInputEvent(java.awt.event.InputEvent event,
java.lang.String place,
Presentation presentation,
DataContext dataContext) |
static AnActionEvent |
createFromInputEvent(java.awt.event.InputEvent event,
java.lang.String place,
Presentation presentation,
DataContext dataContext,
boolean isContextMenuAction,
boolean isToolbarAction) |
ActionManager |
getActionManager() |
<T> T |
getData(DataKey<T> key) |
DataContext |
getDataContext()
Returns the context which allows to retrieve information about the state of IDE related to
the action invocation (active editor, selection and so on).
|
static DataContext |
getInjectedDataContext(DataContext context) |
java.awt.event.InputEvent |
getInputEvent()
Returns the
InputEvent which causes invocation of the action. |
int |
getModifiers()
Returns the modifier keys held down during this action event.
|
java.lang.String |
getPlace()
Returns the identifier of the place in the IDE user interface from where the action is invoked
or updated.
|
Presentation |
getPresentation()
Returns the presentation which represents the action in the place from where it is invoked
or updated.
|
Project |
getProject() |
<T> T |
getRequiredData(DataKey<T> key)
Returns not null data by a data key.
|
static java.lang.String |
injectedId(java.lang.String dataId) |
boolean |
isFromActionToolbar() |
boolean |
isFromContextMenu()
Deprecated.
This method returns
true for both main menu and context menu invocations. Use ActionPlaces.isPopupPlace(String)
instead to get results only from context menus. |
boolean |
isInInjectedContext() |
void |
setInjectedContext(boolean worksInInjected) |
static java.lang.String |
uninjectedId(java.lang.String dataId) |
public AnActionEvent(java.awt.event.InputEvent inputEvent, DataContext dataContext, java.lang.String place, Presentation presentation, ActionManager actionManager, int modifiers)
java.lang.IllegalArgumentException
- if dataContext
is null
or
place
is null
or presentation
is null
ActionManager.getInstance()
public AnActionEvent(java.awt.event.InputEvent inputEvent, DataContext dataContext, java.lang.String place, Presentation presentation, ActionManager actionManager, int modifiers, boolean isContextMenuAction, boolean isActionToolbar)
java.lang.IllegalArgumentException
- if dataContext
is null
or
place
is null
or presentation
is null
ActionManager.getInstance()
@Deprecated public static AnActionEvent createFromInputEvent(AnAction action, java.awt.event.InputEvent event, java.lang.String place)
public static AnActionEvent createFromAnAction(AnAction action, java.awt.event.InputEvent event, java.lang.String place, DataContext dataContext)
public static AnActionEvent createFromDataContext(java.lang.String place, Presentation presentation, DataContext dataContext)
public static AnActionEvent createFromInputEvent(java.awt.event.InputEvent event, java.lang.String place, Presentation presentation, DataContext dataContext)
public static AnActionEvent createFromInputEvent(java.awt.event.InputEvent event, java.lang.String place, Presentation presentation, DataContext dataContext, boolean isContextMenuAction, boolean isToolbarAction)
public java.awt.event.InputEvent getInputEvent()
InputEvent
which causes invocation of the action. It might be
KeyEvent
, MouseEvent
.InputEvent
instance.public Project getProject()
public static java.lang.String injectedId(java.lang.String dataId)
public static java.lang.String uninjectedId(java.lang.String dataId)
public static DataContext getInjectedDataContext(DataContext context)
public DataContext getDataContext()
public <T> T getData(DataKey<T> key)
public <T> T getRequiredData(DataKey<T> key)
null
in AnAction#update
method.
public class MyAction extends AnAction { public void update(AnActionEvent e) { // perform action if and only if EDITOR != null boolean enabled = e.getData(CommonDataKeys.EDITOR) != null; e.getPresentation.setEnabled(enabled); } public void actionPerformed(AnActionEvent e) { // if we're here then EDITOR != null Document doc = e.getRequiredData(CommonDataKeys.EDITOR).getDocument(); doSomething(doc); } }
public java.lang.String getPlace()
getPlace
in interface PlaceProvider<java.lang.String>
ActionPlaces
public boolean isFromActionToolbar()
@Deprecated public boolean isFromContextMenu()
true
for both main menu and context menu invocations. Use ActionPlaces.isPopupPlace(String)
instead to get results only from context menus.public Presentation getPresentation()
public int getModifiers()
public ActionManager getActionManager()
public void setInjectedContext(boolean worksInInjected)
public boolean isInInjectedContext()
public void accept(AnActionEventVisitor visitor)