actionManager is not null

This commit is contained in:
Alexey Kudravtsev
2014-08-11 16:09:42 +04:00
parent fd7022c125
commit 9b1232b022
14 changed files with 59 additions and 63 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.i18n.I18nizeAction;
import com.intellij.codeInspection.i18n.JavaI18nUtil;
import com.intellij.ide.DataManager;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ex.PathManagerEx;
@@ -43,7 +44,7 @@ public class I18nizeTest extends LightCodeInsightTestCase {
configureByFile(getBasePath() + "/before"+getTestName(false)+"."+ext);
I18nizeAction action = new I18nizeAction();
DataContext dataContext = DataManager.getInstance().getDataContext(myEditor.getComponent());
AnActionEvent event = new AnActionEvent(null, dataContext, "place", action.getTemplatePresentation(), null, 0);
AnActionEvent event = new AnActionEvent(null, dataContext, "place", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
action.update(event);
@NonNls String afterFile = getBasePath() + "/after" + getTestName(false) + "." + ext;
boolean afterFileExists = new File(PathManagerEx.getTestDataPath() + afterFile).exists();
@@ -37,7 +37,7 @@ import java.util.Map;
public class AnActionEvent implements PlaceProvider<String> {
private final InputEvent myInputEvent;
private final ActionManager myActionManager;
@NotNull private final ActionManager myActionManager;
@NotNull private final DataContext myDataContext;
@NotNull private final String myPlace;
@NotNull private final Presentation myPresentation;
@@ -49,12 +49,14 @@ public class AnActionEvent implements PlaceProvider<String> {
/**
* @throws IllegalArgumentException if <code>dataContext</code> is <code>null</code> or
* <code>place</code> is <code>null</code> or <code>presentation</code> is <code>null</code>
*
* @see ActionManager#getInstance()
*/
public AnActionEvent(InputEvent inputEvent,
@NotNull DataContext dataContext,
@NotNull @NonNls String place,
@NotNull Presentation presentation,
ActionManager actionManager,
@NotNull ActionManager actionManager,
@JdkConstants.InputEventMask int modifiers) {
// TODO[vova,anton] make this constructor package local. No one is allowed to create AnActionEvents
myInputEvent = inputEvent;
@@ -69,7 +71,7 @@ public class AnActionEvent implements PlaceProvider<String> {
public static AnActionEvent createFromInputEvent(@NotNull AnAction action, InputEvent event, @NotNull String place) {
DataContext context = event == null ? DataManager.getInstance().getDataContext() : DataManager.getInstance().getDataContext(event.getComponent());
int modifiers = event == null ? 0 : event.getModifiers();
return new AnActionEvent(
AnActionEvent anActionEvent = new AnActionEvent(
event,
context,
place,
@@ -77,6 +79,8 @@ public class AnActionEvent implements PlaceProvider<String> {
ActionManager.getInstance(),
modifiers
);
anActionEvent.setInjectedContext(action.isInInjectedContext());
return anActionEvent;
}
/**
@@ -203,9 +207,11 @@ public class AnActionEvent implements PlaceProvider<String> {
return myModifiers;
}
@NotNull
public ActionManager getActionManager() {
return myActionManager;
}
public void setInjectedContext(boolean worksInInjected) {
myWorksInInjected = worksInInjected;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -53,6 +53,7 @@ public interface ViewContext extends Disposable {
ContentManager getContentManager();
@NotNull
ActionManager getActionManager();
IdeFocusManager getFocusManager();
@@ -104,7 +104,7 @@ public class DaemonListeners implements Disposable {
private final ProjectLevelVcsManager myProjectLevelVcsManager;
private final VcsDirtyScopeManager myVcsDirtyScopeManager;
private final FileStatusManager myFileStatusManager;
private final ActionManager myActionManager;
@NotNull private final ActionManager myActionManager;
private final TooltipController myTooltipController;
private boolean myEscPressed;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -43,7 +43,7 @@ import java.util.Map;
*/
public class
JBRunnerTabs extends JBTabsImpl {
public JBRunnerTabs(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
public JBRunnerTabs(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
super(project, actionManager, focusManager, parent);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -89,7 +89,7 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
private ContentManager myManager;
private final RunnerLayout myLayoutSettings;
private final ActionManager myActionManager;
@NotNull private final ActionManager myActionManager;
private final String mySessionName;
private final MyComponent myComponent = new MyComponent();
@@ -1580,6 +1580,7 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
return myManager;
}
@NotNull
@Override
public ActionManager getActionManager() {
return myActionManager;
@@ -1,6 +1,6 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -33,10 +33,10 @@ import java.util.List;
public abstract class BaseToolManager<T extends Tool> implements ExportableApplicationComponent {
private final ActionManagerEx myActionManager;
@NotNull private final ActionManagerEx myActionManager;
private final SchemesManager<ToolsGroup<T>, ToolsGroup<T>> mySchemesManager;
public BaseToolManager(ActionManagerEx actionManagerEx, SchemesManagerFactory factory) {
public BaseToolManager(@NotNull ActionManagerEx actionManagerEx, SchemesManagerFactory factory) {
myActionManager = actionManagerEx;
mySchemesManager = factory.createSchemesManager(
@@ -49,7 +49,7 @@ public class JBEditorTabs extends JBTabsImpl {
private JBEditorTabsPainter myDefaultPainter = new DefaultEditorTabsPainter();
public JBEditorTabs(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
public JBEditorTabs(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
super(project, actionManager, focusManager, parent);
}
@@ -69,7 +69,7 @@ public class JBTabsImpl extends JComponent
public static final Color MAC_AQUA_BG_COLOR = Gray._200;
final ActionManager myActionManager;
@NotNull final ActionManager myActionManager;
private final List<TabInfo> myVisibleInfos = new ArrayList<TabInfo>();
private final Map<TabInfo, Integer> myHiddenInfos = new HashMap<TabInfo, Integer>();
@@ -153,8 +153,8 @@ public class JBTabsImpl extends JComponent
private JBTabsPosition myPosition = JBTabsPosition.top;
private final TabsBorder myBorder = new TabsBorder(this);
private BaseNavigationAction myNextAction;
private BaseNavigationAction myPrevAction;
private final BaseNavigationAction myNextAction;
private final BaseNavigationAction myPrevAction;
private boolean myTabDraggingEnabled;
private DragHelper myDragHelper;
@@ -186,7 +186,7 @@ public class JBTabsImpl extends JComponent
this(project, ActionManager.getInstance(), focusManager, parent);
}
public JBTabsImpl(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
public JBTabsImpl(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
myProject = project;
myActionManager = actionManager;
myFocusManager = focusManager != null ? focusManager : IdeFocusManager.getGlobalInstance();
@@ -198,13 +198,11 @@ public class JBTabsImpl extends JComponent
myNavigationActions = new DefaultActionGroup();
if (myActionManager != null) {
myNextAction = new SelectNextAction(this, myActionManager);
myPrevAction = new SelectPreviousAction(this, myActionManager);
myNextAction = new SelectNextAction(this, myActionManager);
myPrevAction = new SelectPreviousAction(this, myActionManager);
myNavigationActions.add(myNextAction);
myNavigationActions.add(myPrevAction);
}
myNavigationActions.add(myNextAction);
myNavigationActions.add(myPrevAction);
setUiDecorator(null);
@@ -452,14 +450,14 @@ public class JBTabsImpl extends JComponent
}
private void addTimerUpdate() {
if (myActionManager != null && !myListenerAdded) {
if (!myListenerAdded) {
myActionManager.addTimerListener(500, this);
myListenerAdded = true;
}
}
private void removeTimerUpdate() {
if (myActionManager != null && myListenerAdded) {
if (myListenerAdded) {
myActionManager.removeTimerListener(this);
myListenerAdded = false;
}
@@ -1408,7 +1406,7 @@ public class JBTabsImpl extends JComponent
final ActionGroup group = info.getGroup();
final JComponent side = info.getSideComponent();
if (group != null && myTabs.myActionManager != null) {
if (group != null) {
final String place = info.getPlace();
ActionToolbar toolbar =
myTabs.myActionManager.createActionToolbar(place != null ? place : ActionPlaces.UNKNOWN, group, myTabs.myHorizontalSide);
@@ -2755,8 +2753,7 @@ public class JBTabsImpl extends JComponent
}
private static boolean isChanged(Object oldObject, Object newObject) {
if (oldObject == null && newObject == null) return false;
return oldObject != null && !oldObject.equals(newObject) || newObject != null && !newObject.equals(oldObject);
return !Comparing.equal(oldObject, newObject);
}
@Override
@@ -2794,12 +2791,11 @@ public class JBTabsImpl extends JComponent
}
private abstract static class BaseNavigationAction extends AnAction {
private final ShadowAction myShadow;
private final ActionManager myActionManager;
@NotNull private final ActionManager myActionManager;
private final JBTabsImpl myTabs;
protected BaseNavigationAction(final String copyFromID, JBTabsImpl tabs, ActionManager mgr) {
protected BaseNavigationAction(@NotNull String copyFromID, @NotNull JBTabsImpl tabs, @NotNull ActionManager mgr) {
myActionManager = mgr;
myTabs = tabs;
myShadow = new ShadowAction(this, myActionManager.getAction(copyFromID), tabs);
@@ -2867,7 +2863,7 @@ public class JBTabsImpl extends JComponent
private static class SelectNextAction extends BaseNavigationAction {
private SelectNextAction(JBTabsImpl tabs, ActionManager mgr) {
private SelectNextAction(JBTabsImpl tabs, @NotNull ActionManager mgr) {
super(IdeActions.ACTION_NEXT_TAB, tabs, mgr);
}
@@ -2883,7 +2879,7 @@ public class JBTabsImpl extends JComponent
}
private static class SelectPreviousAction extends BaseNavigationAction {
private SelectPreviousAction(JBTabsImpl tabs, ActionManager mgr) {
private SelectPreviousAction(JBTabsImpl tabs, @NotNull ActionManager mgr) {
super(IdeActions.ACTION_PREVIOUS_TAB, tabs, mgr);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -107,7 +107,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
private final ActionButtonLook myButtonLook = null;
private final ActionButtonLook myMinimalButtonLook = new InplaceActionButtonLook();
private final DataManager myDataManager;
protected final ActionManagerEx myActionManager;
@NotNull protected final ActionManagerEx myActionManager;
private Rectangle myAutoPopupRec;
@@ -135,7 +135,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
@NotNull final ActionGroup actionGroup,
final boolean horizontal,
DataManager dataManager,
ActionManagerEx actionManager,
@NotNull ActionManagerEx actionManager,
KeymapManagerEx keymapManager) {
this(place, actionGroup, horizontal, false, dataManager, actionManager, keymapManager, false);
}
@@ -144,7 +144,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
final boolean horizontal,
final boolean decorateButtons,
DataManager dataManager,
ActionManagerEx actionManager,
@NotNull ActionManagerEx actionManager,
KeymapManagerEx keymapManager) {
this(place, actionGroup, horizontal, decorateButtons, dataManager, actionManager, keymapManager, false);
}
@@ -154,7 +154,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
final boolean horizontal,
final boolean decorateButtons,
DataManager dataManager,
ActionManagerEx actionManager,
@NotNull ActionManagerEx actionManager,
KeymapManagerEx keymapManager,
boolean updateActionsNow) {
super(null);
@@ -1185,7 +1185,7 @@ public class ActionToolbarImpl extends JPanel implements ActionToolbar {
final ActionGroup actionGroup,
final boolean horizontal,
final DataManager dataManager,
final ActionManagerEx actionManager,
@NotNull ActionManagerEx actionManager,
final KeymapManagerEx keymapManager,
JComponent parent) {
super(place, actionGroup, horizontal, false, dataManager, actionManager, keymapManager, true);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -20,11 +20,7 @@ import com.intellij.history.integration.TestVirtualFile;
import com.intellij.history.integration.ui.actions.LocalHistoryAction;
import com.intellij.history.integration.ui.actions.ShowHistoryAction;
import com.intellij.history.integration.ui.actions.ShowSelectionHistoryAction;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
@@ -135,6 +131,6 @@ public class LocalHistoryActionsTest extends LocalHistoryUITestCase {
return null;
}
};
return new AnActionEvent(null, dc, "", a.getTemplatePresentation(), null, -1);
return new AnActionEvent(null, dc, "", a.getTemplatePresentation(), ActionManager.getInstance(), -1);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* 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.
@@ -16,6 +16,7 @@
package com.intellij.ui.tabs.impl;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
@@ -46,7 +47,7 @@ public class JBTabsDemo {
final JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout(0, 0));
final int[] count = new int[1];
final JBTabsImpl tabs = new JBTabsImpl(null, null, null, Disposer.newDisposable());
final JBTabsImpl tabs = new JBTabsImpl(null, ActionManager.getInstance(), null, Disposer.newDisposable());
tabs.setTestMode(true);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -17,10 +17,7 @@ package org.jetbrains.idea;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.ide.startup.impl.StartupManagerImpl;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.PluginPathManager;
@@ -506,7 +503,7 @@ public abstract class SvnTestCase extends AbstractJunitVcsTestCase {
}
return null;
}
}, "test", new Presentation(), null, 0));
}, "test", new Presentation(), ActionManager.getInstance(), 0));
final ChangeListManager clManager = ChangeListManager.getInstance(project);
clManager.ensureUpToDate(false);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -15,10 +15,7 @@
*/
package org.jetbrains.idea.svn;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.VcsException;
@@ -144,7 +141,7 @@ public class SvnAnnotationIsClosedTest extends Svn17TestCase {
}
return null;
}
}, "test", new Presentation(), null, 0));
}, "test", new Presentation(), ActionManager.getInstance(), 0));
myChangeListManager.ensureUpToDate(false);
myChangeListManager.ensureUpToDate(false); // wait for after-events like annotations recalculation
@@ -191,7 +188,7 @@ public class SvnAnnotationIsClosedTest extends Svn17TestCase {
}
return null;
}
}, "test", new Presentation(), null, 0));
}, "test", new Presentation(), ActionManager.getInstance(), 0));
myChangeListManager.ensureUpToDate(false);
myChangeListManager.ensureUpToDate(false); // wait for after-events like annotations recalculation