mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ActionUtil.getActions
This commit is contained in:
@@ -28,7 +28,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -145,7 +144,8 @@ public abstract class AnAction implements PossiblyDumbAware {
|
||||
public final void registerCustomShortcutSet(@NotNull ShortcutSet shortcutSet, @Nullable JComponent component){
|
||||
myShortcutSet = shortcutSet;
|
||||
if (component != null){
|
||||
@SuppressWarnings("unchecked") List<AnAction> actionList = (ArrayList<AnAction>)component.getClientProperty(ourClientProperty);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<AnAction> actionList = (List<AnAction>)component.getClientProperty(ourClientProperty);
|
||||
if (actionList == null){
|
||||
actionList = new SmartList<AnAction>();
|
||||
component.putClientProperty(ourClientProperty, actionList);
|
||||
@@ -172,7 +172,8 @@ public abstract class AnAction implements PossiblyDumbAware {
|
||||
|
||||
public final void unregisterCustomShortcutSet(JComponent component){
|
||||
if (component != null){
|
||||
@SuppressWarnings("unchecked") ArrayList<AnAction> actionList = (ArrayList<AnAction>)component.getClientProperty(ourClientProperty);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<AnAction> actionList = (List<AnAction>)component.getClientProperty(ourClientProperty);
|
||||
if (actionList != null){
|
||||
actionList.remove(this);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package com.intellij.openapi.actionSystem;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class purpose is to reserve action-id in a plugin.xml so the action appears in Keymap.
|
||||
@@ -74,13 +74,8 @@ public final class EmptyAction extends AnAction {
|
||||
}
|
||||
|
||||
public static void registerActionShortcuts(JComponent component, final JComponent fromComponent) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<AnAction> actionList =
|
||||
(ArrayList<AnAction>)fromComponent.getClientProperty(ourClientProperty);
|
||||
if (actionList != null) {
|
||||
for (AnAction anAction : actionList) {
|
||||
anAction.registerCustomShortcutSet(anAction.getShortcutSet(), component);
|
||||
}
|
||||
for (AnAction anAction : ActionUtil.getActions(fromComponent)) {
|
||||
anAction.registerCustomShortcutSet(anAction.getShortcutSet(), component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionUtil {
|
||||
@@ -166,5 +168,10 @@ public class ActionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<AnAction> getActions(@NotNull JComponent component) {
|
||||
Object property = component.getClientProperty(AnAction.ourClientProperty);
|
||||
//noinspection unchecked
|
||||
return property == null ? Collections.<AnAction>emptyList() : (List<AnAction>)property;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -651,8 +651,8 @@ public final class IdeKeyEventDispatcher implements Disposable {
|
||||
if (!(component instanceof JComponent)) {
|
||||
continue;
|
||||
}
|
||||
ArrayList listOfActions = (ArrayList)((JComponent)component).getClientProperty(AnAction.ourClientProperty);
|
||||
if (listOfActions == null) {
|
||||
List<AnAction> listOfActions = ActionUtil.getActions((JComponent)component);
|
||||
if (listOfActions.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (Object listOfAction : listOfActions) {
|
||||
|
||||
+9
-13
@@ -19,6 +19,7 @@ import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.impl.PresentationFactory;
|
||||
import com.intellij.openapi.keymap.Keymap;
|
||||
import com.intellij.openapi.keymap.KeymapManager;
|
||||
@@ -78,21 +79,16 @@ public final class IdeMouseEventDispatcher {
|
||||
|
||||
// here we try to find "local" shortcuts
|
||||
if (component instanceof JComponent) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<AnAction> listOfActions = (ArrayList<AnAction>)((JComponent)component).getClientProperty(AnAction.ourClientProperty);
|
||||
if (listOfActions != null) {
|
||||
for (AnAction action : listOfActions) {
|
||||
final Shortcut[] shortcuts = action.getShortcutSet().getShortcuts();
|
||||
for (Shortcut shortcut : shortcuts) {
|
||||
if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) {
|
||||
myActions.add(action);
|
||||
}
|
||||
for (AnAction action : ActionUtil.getActions((JComponent)component)) {
|
||||
for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) {
|
||||
if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) {
|
||||
myActions.add(action);
|
||||
}
|
||||
}
|
||||
// once we've found a proper local shortcut(s), we exit
|
||||
if (! myActions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// once we've found a proper local shortcut(s), we exit
|
||||
if (!myActions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.openapi.vcs.ex;
|
||||
import com.intellij.codeInsight.hint.EditorFragmentComponent;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.diff.DiffColors;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -165,9 +166,6 @@ public class LineStatusTrackerDrawing {
|
||||
group.add(new ShowLineStatusRangeDiffAction(tracker, range, editor));
|
||||
group.add(new CopyLineStatusRangeAction(tracker, range));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<AnAction> actionList = (List<AnAction>)editorComponent.getClientProperty(AnAction.ourClientProperty);
|
||||
|
||||
final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true).getComponent();
|
||||
|
||||
final Color background = ((EditorEx)editor).getBackgroundColor();
|
||||
@@ -218,6 +216,7 @@ public class LineStatusTrackerDrawing {
|
||||
EditorFactory.getInstance().releaseEditor(uEditor);
|
||||
}
|
||||
|
||||
final List<AnAction> actionList = ActionUtil.getActions(editorComponent);
|
||||
final LightweightHint lightweightHint = new LightweightHint(component);
|
||||
HintListener closeListener = new HintListener() {
|
||||
public void hintHidden(final EventObject event) {
|
||||
|
||||
Reference in New Issue
Block a user