2 * Copyright 2000-2014 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.actionSystem;
18 import com.intellij.openapi.Disposable;
19 import com.intellij.openapi.actionSystem.ex.AnActionListener;
20 import com.intellij.openapi.application.ApplicationManager;
21 import com.intellij.openapi.components.ApplicationComponent;
22 import com.intellij.openapi.extensions.PluginId;
23 import com.intellij.openapi.util.ActionCallback;
24 import org.jetbrains.annotations.NonNls;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
30 import java.awt.event.InputEvent;
33 * A manager for actions. Used to register and unregister actions, also
34 * contains utility methods to easily fetch action by id and id by action.
38 public abstract class ActionManager implements ApplicationComponent {
41 * Fetches the instance of ActionManager implementation.
43 public static ActionManager getInstance(){
44 return ApplicationManager.getApplication().getComponent(ActionManager.class);
48 * Factory method that creates an <code>ActionPopupMenu</code> from the
49 * specified group. The specified place is associated with the created popup.
51 * @param place Determines the place that will be set for {@link AnActionEvent} passed
52 * when an action from the group is either performed or updated
53 * See {@link com.intellij.openapi.actionSystem.ActionPlaces}
55 * @param group Group from which the actions for the menu are taken.
57 * @return An instance of <code>ActionPopupMenu</code>
59 public abstract ActionPopupMenu createActionPopupMenu(@NonNls String place, @NotNull ActionGroup group);
62 * Factory method that creates an <code>ActionToolbar</code> from the
63 * specified group. The specified place is associated with the created toolbar.
65 * @param place Determines the place that will be set for {@link AnActionEvent} passed
66 * when an action from the group is either performed or updated.
67 * See {@link com.intellij.openapi.actionSystem.ActionPlaces}
69 * @param group Group from which the actions for the toolbar are taken.
71 * @param horizontal The orientation of the toolbar (true - horizontal, false - vertical)
73 * @return An instance of <code>ActionToolbar</code>
75 public abstract ActionToolbar createActionToolbar(@NonNls String place, @NotNull ActionGroup group, boolean horizontal);
78 * Returns action associated with the specified actionId.
80 * @param actionId Id of the registered action
82 * @return Action associated with the specified actionId, <code>null</code> if
83 * there is no actions associated with the specified actionId
85 * @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
87 * @see com.intellij.openapi.actionSystem.IdeActions
89 public abstract AnAction getAction(@NonNls @NotNull String actionId);
92 * Returns actionId associated with the specified action.
94 * @return id associated with the specified action, <code>null</code> if action
97 * @exception java.lang.IllegalArgumentException if <code>action</code> is <code>null</code>
99 public abstract String getId(@NotNull AnAction action);
102 * Registers the specified action with the specified id. Note that IDEA's keymaps
103 * processing deals only with registered actions.
105 * @param actionId Id to associate with the action
106 * @param action Action to register
108 public abstract void registerAction(@NonNls @NotNull String actionId, @NotNull AnAction action);
111 * Registers the specified action with the specified id.
113 * @param actionId Id to associate with the action
114 * @param action Action to register
115 * @param pluginId Identifier of the plugin owning the action. Used to show the actions in the
116 * correct place under the "Plugins" node in the "Keymap" settings pane and similar dialogs.
118 public abstract void registerAction(@NotNull String actionId, @NotNull AnAction action, @Nullable PluginId pluginId);
121 * Unregisters the action with the specified actionId.
123 * @param actionId Id of the action to be unregistered
125 public abstract void unregisterAction(@NotNull String actionId);
128 * Returns the list of all registered action IDs with the specified prefix.
130 * @return all action <code>id</code>s which have the specified prefix.
133 public abstract String[] getActionIds(@NotNull String idPrefix);
136 * Checks if the specified action ID represents an action group and not an individual action.
137 * Calling this method does not cause instantiation of a specific action class corresponding
140 * @param actionId the ID to check.
141 * @return true if the ID represents an action group, false otherwise.
144 public abstract boolean isGroup(@NotNull String actionId);
147 * Creates a panel with buttons which invoke actions from the specified action group.
149 * @param actionPlace the place where the panel will be used (see {@link ActionPlaces}).
150 * @param messageActionGroup the action group from which the toolbar is created.
151 * @return the created panel.
154 public abstract JComponent createButtonToolbar(final String actionPlace, @NotNull ActionGroup messageActionGroup);
156 public abstract AnAction getActionOrStub(@NonNls String id);
158 public abstract void addTimerListener(int delay, TimerListener listener);
160 public abstract void removeTimerListener(TimerListener listener);
162 public abstract void addTransparentTimerListener(int delay, TimerListener listener);
164 public abstract void removeTransparentTimerListener(TimerListener listener);
166 public abstract ActionCallback tryToExecute(@NotNull AnAction action, @NotNull InputEvent inputEvent, @Nullable Component contextComponent,
167 @Nullable String place, boolean now);
169 public abstract void addAnActionListener(AnActionListener listener);
170 public abstract void addAnActionListener(AnActionListener listener, Disposable parentDisposable);
172 public abstract void removeAnActionListener(AnActionListener listener);
175 public abstract KeyboardShortcut getKeyboardShortcut(@NonNls @NotNull String actionId);