summaryrefslogtreecommitdiff
path: root/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/ActionManager.java
blob: ee850c3fe060994a11bfcea69e652d9aae000eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.actionSystem;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ex.AnActionListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.ProjectType;
import com.intellij.openapi.util.ActionCallback;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;

/**
 * A manager for actions. Used to register and unregister actions, also
 * contains utility methods to easily fetch action by id and id by action.
 *
 * @see AnAction
 */
public abstract class ActionManager implements ApplicationComponent {

  /**
   * Fetches the instance of ActionManager implementation.
   */
  public static ActionManager getInstance(){
    return ApplicationManager.getApplication().getComponent(ActionManager.class);
  }

  /**
   * Factory method that creates an <code>ActionPopupMenu</code> from the
   * specified group. The specified place is associated with the created popup.
   *
   * @param place Determines the place that will be set for {@link AnActionEvent} passed
   *  when an action from the group is either performed or updated
   *  See {@link com.intellij.openapi.actionSystem.ActionPlaces}
   *
   * @param group Group from which the actions for the menu are taken.
   *
   * @return An instance of <code>ActionPopupMenu</code>
   */
  public abstract ActionPopupMenu createActionPopupMenu(@NonNls String place, @NotNull ActionGroup group);

  /**
   * Factory method that creates an <code>ActionToolbar</code> from the
   * specified group. The specified place is associated with the created toolbar.
   *
   * @param place Determines the place that will be set for {@link AnActionEvent} passed
   *  when an action from the group is either performed or updated.
   *  See {@link com.intellij.openapi.actionSystem.ActionPlaces}
   *
   * @param group Group from which the actions for the toolbar are taken.
   *
   * @param horizontal The orientation of the toolbar (true - horizontal, false - vertical)
   *
   * @return An instance of <code>ActionToolbar</code>
   */
  public abstract ActionToolbar createActionToolbar(@NonNls String place, @NotNull ActionGroup group, boolean horizontal);

  /**
   * Returns action associated with the specified actionId.
   *
   * @param actionId Id of the registered action
   *
   * @return Action associated with the specified actionId, <code>null</code> if
   *  there is no actions associated with the specified actionId
   *
   * @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
   *
   * @see com.intellij.openapi.actionSystem.IdeActions
   */
  public abstract AnAction getAction(@NonNls @NotNull String actionId);

  /**
   * Returns action associated with the specified actionId.
   *
   * @param actionId Id of the registered action
   *
   * @return Action associated with the specified actionId, <code>null</code> if
   *  there is no actions associated with the specified actionId
   *
   * @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
   *
   * @see com.intellij.openapi.actionSystem.IdeActions
   */
  public abstract AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType);

  /**
   * Returns actionId associated with the specified action.
   *
   * @return id associated with the specified action, <code>null</code> if action
   *  is not registered
   *
   * @exception java.lang.IllegalArgumentException if <code>action</code> is <code>null</code>
   */
  public abstract String getId(@NotNull AnAction action);

  /**
   * Registers the specified action with the specified id. Note that IDEA's keymaps
   * processing deals only with registered actions.
   *
   * @param actionId Id to associate with the action
   * @param action Action to register
   */
  public abstract void registerAction(@NonNls @NotNull String actionId, @NotNull AnAction action);

  /**
   * Registers the specified action with the specified id.
   *
   * @param actionId Id to associate with the action
   * @param action   Action to register
   * @param pluginId Identifier of the plugin owning the action. Used to show the actions in the
   *                 correct place under the "Plugins" node in the "Keymap" settings pane and similar dialogs.
   */
  public abstract void registerAction(@NotNull String actionId, @NotNull AnAction action, @Nullable PluginId pluginId);

  /**
   * Unregisters the action with the specified actionId.
   *
   * @param actionId Id of the action to be unregistered
   */
  public abstract void unregisterAction(@NotNull String actionId);

  /**
   * Returns the list of all registered action IDs with the specified prefix.
   *
   * @return all action <code>id</code>s which have the specified prefix.
   * @since 5.1
   */
  public abstract String[] getActionIds(@NotNull String idPrefix);

  /**
   * Checks if the specified action ID represents an action group and not an individual action.
   * Calling this method does not cause instantiation of a specific action class corresponding
   * to the action ID.
   *
   * @param actionId the ID to check.
   * @return true if the ID represents an action group, false otherwise.
   * @since 5.1
   */
  public abstract boolean isGroup(@NotNull String actionId);

  /**
   * Creates a panel with buttons which invoke actions from the specified action group.
   *
   * @param actionPlace        the place where the panel will be used (see {@link ActionPlaces}).
   * @param messageActionGroup the action group from which the toolbar is created.
   * @return the created panel.
   * @since 5.1
   */
  public abstract JComponent createButtonToolbar(final String actionPlace, @NotNull ActionGroup messageActionGroup);

  public abstract AnAction getActionOrStub(@NonNls String id);

  public abstract void addTimerListener(int delay, TimerListener listener);

  public abstract void removeTimerListener(TimerListener listener);

  public abstract void addTransparentTimerListener(int delay, TimerListener listener);

  public abstract void removeTransparentTimerListener(TimerListener listener);

  public abstract ActionCallback tryToExecute(@NotNull AnAction action, @NotNull InputEvent inputEvent, @Nullable Component contextComponent,
                                              @Nullable String place, boolean now);

  public abstract void addAnActionListener(AnActionListener listener);
  public abstract void addAnActionListener(AnActionListener listener, Disposable parentDisposable);

  public abstract void removeAnActionListener(AnActionListener listener);

  @Nullable
  public abstract KeyboardShortcut getKeyboardShortcut(@NonNls @NotNull String actionId);
}