From 66273cebf33ea9cfcd266c39cefcf4dd06403643 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 17 Oct 2016 19:42:10 +0300 Subject: [PATCH] ui: remove SwitchManager * it is a dead code * even while disabled, it registers actions and sets their shortcuts in runtime (making impossible removing these shortcuts in Keymap) --- .../ui/switcher/ApplySwitchAction.java | 65 --- .../ui/switcher/QuickAccessSettings.java | 172 ------- .../ui/switcher/QuickActionManager.java | 125 ----- .../intellij/ui/switcher/SwitchManager.java | 198 ------- .../ui/switcher/SwitchingSession.java | 484 ------------------ .../wm/impl/ToolWindowManagerImpl.java | 52 +- .../ui/switcher/QuickAccessConfigurable.java | 335 ------------ .../intellij/ui/switcher/SwitchAction.java | 105 ---- .../switcher/SwitchManagerAppComponent.java | 70 --- .../src/META-INF/PlatformExtensions.xml | 3 - .../src/componentSets/UICore.xml | 12 - .../src/idea/PlatformActions.xml | 9 - .../util/resources/misc/registry.properties | 5 - 13 files changed, 48 insertions(+), 1587 deletions(-) delete mode 100644 platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java delete mode 100644 platform/platform-api/src/com/intellij/ui/switcher/QuickAccessSettings.java delete mode 100644 platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java delete mode 100644 platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java delete mode 100644 platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java delete mode 100644 platform/platform-impl/src/com/intellij/ui/switcher/QuickAccessConfigurable.java delete mode 100644 platform/platform-impl/src/com/intellij/ui/switcher/SwitchAction.java delete mode 100644 platform/platform-impl/src/com/intellij/ui/switcher/SwitchManagerAppComponent.java diff --git a/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java b/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java deleted file mode 100644 index f9ab352448b1..000000000000 --- a/platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2000-2010 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.ui.switcher; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.project.Project; - -import java.util.List; - -public class ApplySwitchAction extends AnAction { - - @Override - public void update(AnActionEvent e) { - Project project = getEventProject(e); - if (project == null) { - e.getPresentation().setEnabled(false); - return; - } - - SwitchManager mgr = SwitchManager.getInstance(project); - - boolean switchActionActive = mgr != null && mgr.isSessionActive(); - if (switchActionActive && mgr.isSelectionWasMoved()) { - e.getPresentation().setEnabled(true); - } else { - QuickActionProvider quickActionProvider = QuickActionProvider.KEY.getData(e.getDataContext()); - if (quickActionProvider == null) { - e.getPresentation().setEnabled(false); - } else { - List actions = quickActionProvider.getActions(true); - e.getPresentation().setEnabled(actions != null && !actions.isEmpty()); - } - } - } - - - @Override - public void actionPerformed(AnActionEvent e) { - Project project = getEventProject(e); - - SwitchManager switchManager = SwitchManager.getInstance(project); - if (switchManager.canApplySwitch()) { - switchManager.applySwitch(); - } else { - switchManager.disposeCurrentSession(false); - QuickActionManager.getInstance(project).showQuickActions(); - } - - } -} diff --git a/platform/platform-api/src/com/intellij/ui/switcher/QuickAccessSettings.java b/platform/platform-api/src/com/intellij/ui/switcher/QuickAccessSettings.java deleted file mode 100644 index 0f0d975cc07f..000000000000 --- a/platform/platform-api/src/com/intellij/ui/switcher/QuickAccessSettings.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2000-2015 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.ui.switcher; - -import com.intellij.openapi.actionSystem.KeyboardShortcut; -import com.intellij.openapi.actionSystem.Shortcut; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.keymap.Keymap; -import com.intellij.openapi.keymap.KeymapManager; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.util.registry.RegistryValue; -import com.intellij.openapi.util.registry.RegistryValueListener; -import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; -import org.intellij.lang.annotations.JdkConstants; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.util.Set; - -public class QuickAccessSettings { - private final Set myModifierVks = new THashSet<>(); - @NonNls public static final String SWITCH_UP = "SwitchUp"; - @NonNls public static final String SWITCH_DOWN = "SwitchDown"; - @NonNls public static final String SWITCH_LEFT = "SwitchLeft"; - @NonNls public static final String SWITCH_RIGHT = "SwitchRight"; - @NonNls public static final String SWITCH_APPLY = "SwitchApply"; - private RegistryValue myModifiersValue; - - public QuickAccessSettings() { - myModifiersValue = Registry.get("actionSystem.quickAccessModifiers"); - myModifiersValue.addListener(new RegistryValueListener.Adapter() { - @Override - public void afterValueChanged(RegistryValue value) { - applyModifiersFromRegistry(); - } - }, ApplicationManager.getApplication()); - - applyModifiersFromRegistry(); - } - - Keymap getKeymap() { - return KeymapManager.getInstance().getActiveKeymap(); - } - - void saveModifiersToRegistry(Set codeTexts) { - StringBuilder value = new StringBuilder(); - for (String each : codeTexts) { - if (value.length() > 0) { - value.append(" "); - } - value.append(each); - } - myModifiersValue.setValue(value.toString()); - } - - private void applyModifiersFromRegistry() { - Application app = ApplicationManager.getApplication(); - if (app != null && app.isUnitTestMode()) { - return; - } - - Set vksSet = new THashSet<>(); - ContainerUtil.addAll(vksSet, getModifierRegistryValue().split(" ")); - myModifierVks.clear(); - int mask = getModifierMask(vksSet); - myModifierVks.addAll(getModifiersVKs(mask)); - - reassignActionShortcut(SWITCH_UP, mask, KeyEvent.VK_UP); - reassignActionShortcut(SWITCH_DOWN, mask, KeyEvent.VK_DOWN); - reassignActionShortcut(SWITCH_LEFT, mask, KeyEvent.VK_LEFT); - reassignActionShortcut(SWITCH_RIGHT, mask, KeyEvent.VK_RIGHT); - reassignActionShortcut(SWITCH_APPLY, mask, KeyEvent.VK_ENTER); - } - - @NotNull - private String getModifierRegistryValue() { - String value = myModifiersValue.asString().trim(); - if (value.length() > 0) { - return value; - } - return SystemInfo.isMac ? "control alt" : "shift alt"; - } - - private void reassignActionShortcut(String actionId, @JdkConstants.InputEventMask int modifiers, int actionCode) { - removeShortcuts(actionId); - if (modifiers > 0) { - getKeymap().addShortcut(actionId, new KeyboardShortcut(KeyStroke.getKeyStroke(actionCode, modifiers), null)); - } - } - - private void removeShortcuts(String actionId) { - Shortcut[] shortcuts = getKeymap().getShortcuts(actionId); - for (Shortcut each : shortcuts) { - if (each instanceof KeyboardShortcut) { - getKeymap().removeShortcut(actionId, each); - } - } - } - - @JdkConstants.InputEventMask - int getModifierMask(Set codeTexts) { - int mask = 0; - for (String each : codeTexts) { - if ("control".equals(each)) { - mask |= InputEvent.CTRL_MASK; - } - else if ("shift".equals(each)) { - mask |= InputEvent.SHIFT_MASK; - } - else if ("alt".equals(each)) { - mask |= InputEvent.ALT_MASK; - } - else if ("meta".equals(each)) { - mask |= InputEvent.META_MASK; - } - } - - return mask; - } - - @NotNull - public static Set getModifiersVKs(int mask) { - Set codes = new THashSet<>(); - if ((mask & InputEvent.SHIFT_MASK) > 0) { - codes.add(KeyEvent.VK_SHIFT); - } - if ((mask & InputEvent.CTRL_MASK) > 0) { - codes.add(KeyEvent.VK_CONTROL); - } - - if ((mask & InputEvent.META_MASK) > 0) { - codes.add(KeyEvent.VK_META); - } - - if ((mask & InputEvent.ALT_MASK) > 0) { - codes.add(KeyEvent.VK_ALT); - } - - return codes; - } - - public static QuickAccessSettings getInstance() { - return ApplicationManager.getApplication().getComponent(QuickAccessSettings.class); - } - - public boolean isEnabled() { - return Registry.is("actionSystem.quickAccessEnabled"); - } - - public Set getModiferCodes() { - return myModifierVks; - } -} diff --git a/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java b/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java deleted file mode 100644 index 42c1538f7cc5..000000000000 --- a/platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2000-2016 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.ui.switcher; - -import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.util.Consumer; -import org.jetbrains.annotations.NotNull; - -import java.awt.*; -import java.util.List; - -public class QuickActionManager implements ProjectComponent { - - private SwitchProvider myActiveProvider; - - public void projectOpened() { - } - - public void projectClosed() { - } - - @NotNull - public String getComponentName() { - return "QuickActionsManager"; - } - - public void initComponent() { - } - - public void disposeComponent() { - } - - public static QuickActionManager getInstance(Project project) { - return project != null ? project.getComponent(QuickActionManager.class) : null; - } - - public void showQuickActions() { - if (isActive()) return; - - showActionsPopup(); - } - - private void showActionsPopup() { - DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer() { - public void consume(DataContext context) { - QuickActionProvider provider = QuickActionProvider.KEY.getData(context); - if (provider == null) return; - - List actions = provider.getActions(true); - if (actions != null && actions.size() > 0) { - DefaultActionGroup group = new DefaultActionGroup(); - for (AnAction each : actions) { - group.add(each); - } - - boolean firstParent = true; - Component eachParent = provider.getComponent().getParent(); - while (eachParent != null) { - if (eachParent instanceof QuickActionProvider) { - QuickActionProvider eachProvider = (QuickActionProvider)eachParent; - if (firstParent) { - group.addSeparator(); - firstParent = false; - } - List eachActionList = eachProvider.getActions(false); - if (eachActionList.size() > 0) { - group.add(new Group(eachActionList, eachProvider.getName())); - } - if (eachProvider.isCycleRoot()) break; - - } - eachParent = eachParent.getParent(); - } - - JBPopupFactory.getInstance() - .createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.ALPHA_NUMBERING, true, - () -> myActiveProvider = null, -1).showInBestPositionFor(context); - } - } - }); - - } - - private class Group extends DefaultActionGroup implements DumbAware { - private String myTitle; - - private Group(List actions, String title) { - setPopup(true); - for (AnAction each : actions) { - add(each); - } - myTitle = title; - } - - @Override - public void update(AnActionEvent e) { - e.getPresentation().setText(myTitle); - } - } - - public boolean isActive() { - return myActiveProvider != null; - } -} diff --git a/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java b/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java deleted file mode 100644 index 0eba55b00ffa..000000000000 --- a/platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2000-2015 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.ui.switcher; - -import com.intellij.ide.DataManager; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.util.Alarm; -import com.intellij.util.Consumer; -import gnu.trove.THashSet; -import org.intellij.lang.annotations.JdkConstants; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.awt.*; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.util.Set; - -public class SwitchManager { - private final Project myProject; - private final QuickAccessSettings myQa; - - private SwitchingSession mySession; - - private boolean myWaitingForAutoInitSession; - private final Alarm myInitSessionAlarm = new Alarm(); - private KeyEvent myAutoInitSessionEvent; - - private final Set myFadingAway = new THashSet<>(); - - public SwitchManager(@NotNull Project project, QuickAccessSettings quickAccess) { - myProject = project; - myQa = quickAccess; - } - - /** - * internal use only - */ - public boolean dispatchKeyEvent(@NotNull KeyEvent e) { - if (isSessionActive()) { - return false; - } - - if (e.getID() != KeyEvent.KEY_PRESSED) { - if (myWaitingForAutoInitSession) { - cancelWaitingForAutoInit(); - } - return false; - } - - if (myQa.getModiferCodes().contains(e.getKeyCode())) { - if (areAllModifiersPressed(e.getModifiers(), myQa.getModiferCodes())) { - myWaitingForAutoInitSession = true; - myAutoInitSessionEvent = e; - Runnable initRunnable = () -> IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(() -> { - if (myWaitingForAutoInitSession) { - tryToInitSessionFromFocus(null, false); - } - }); - if (myFadingAway.isEmpty()) { - myInitSessionAlarm.addRequest(initRunnable, Registry.intValue("actionSystem.keyGestureHoldTime")); - } - else { - initRunnable.run(); - } - } - } - else if (myWaitingForAutoInitSession) { - cancelWaitingForAutoInit(); - } - - return false; - } - - private ActionCallback tryToInitSessionFromFocus(@Nullable SwitchTarget preselected, boolean showSpots) { - if (isSessionActive()) { - return ActionCallback.REJECTED; - } - - Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - SwitchProvider provider = SwitchProvider.KEY.getData(DataManager.getInstance().getDataContext(owner)); - if (provider != null) { - return initSession(new SwitchingSession(this, provider, myAutoInitSessionEvent, preselected, showSpots)); - } - - return ActionCallback.REJECTED; - } - - private void cancelWaitingForAutoInit() { - myWaitingForAutoInitSession = false; - myInitSessionAlarm.cancelAllRequests(); - } - - public static boolean areAllModifiersPressed(@JdkConstants.InputEventMask int modifiers, Set modifierCodes) { - int mask = 0; - for (Integer each : modifierCodes) { - if (each == KeyEvent.VK_SHIFT) { - mask |= InputEvent.SHIFT_MASK; - } - - if (each == KeyEvent.VK_CONTROL) { - mask |= InputEvent.CTRL_MASK; - } - - if (each == KeyEvent.VK_META) { - mask |= InputEvent.META_MASK; - } - - if (each == KeyEvent.VK_ALT) { - mask |= InputEvent.ALT_MASK; - } - } - - return (modifiers ^ mask) == 0; - } - - public static SwitchManager getInstance(Project project) { - return project != null ? ServiceManager.getService(project, SwitchManager.class) : null; - } - - public SwitchingSession getSession() { - return mySession; - } - - public ActionCallback initSession(SwitchingSession session) { - cancelWaitingForAutoInit(); - - disposeCurrentSession(false); - mySession = session; - return ActionCallback.DONE; - } - - public void disposeCurrentSession(boolean fadeAway) { - if (mySession != null) { - mySession.setFadeaway(fadeAway); - Disposer.dispose(mySession); - mySession = null; - } - } - - public boolean isSessionActive() { - return mySession != null && !mySession.isFinished(); - } - - public ActionCallback applySwitch() { - final ActionCallback result = new ActionCallback(); - if (isSessionActive()) { - final boolean showSpots = mySession.isShowspots(); - mySession.finish(false).doWhenDone(new Consumer() { - @Override - public void consume(final SwitchTarget switchTarget) { - mySession = null; - IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown( - () -> tryToInitSessionFromFocus(switchTarget, showSpots).doWhenProcessed(result.createSetDoneRunnable())); - } - }); - } - else { - result.setDone(); - } - - return result; - } - - public boolean canApplySwitch() { - return isSessionActive() && mySession.isSelectionWasMoved(); - } - - public boolean isSelectionWasMoved() { - return isSessionActive() && mySession.isSelectionWasMoved(); - } - - public void addFadingAway(SwitchingSession session) { - myFadingAway.add(session); - } - - public void removeFadingAway(SwitchingSession session) { - myFadingAway.remove(session); - } -} diff --git a/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java b/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java deleted file mode 100644 index 00574f7b1fa0..000000000000 --- a/platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright 2000-2012 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.ui.switcher; - -import com.intellij.openapi.Disposable; -import com.intellij.openapi.ui.AbstractPainter; -import com.intellij.openapi.ui.GraphicsConfig; -import com.intellij.openapi.util.AsyncResult; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.openapi.wm.IdeGlassPane; -import com.intellij.openapi.wm.IdeGlassPaneUtil; -import com.intellij.ui.ColorUtil; -import com.intellij.ui.awt.RelativeRectangle; -import com.intellij.util.Alarm; -import org.jetbrains.annotations.Nullable; - -import java.awt.*; -import java.awt.event.KeyEvent; -import java.awt.geom.Area; -import java.awt.geom.RoundRectangle2D; -import java.awt.image.BufferedImage; -import java.util.*; -import java.util.List; - -import static java.lang.Math.abs; -import static java.lang.Math.sqrt; - -public class SwitchingSession implements KeyEventDispatcher, Disposable { - - private SwitchProvider myProvider; - private KeyEvent myInitialEvent; - private boolean myFinished; - private LinkedHashSet myTargets = new LinkedHashSet<>(); - private IdeGlassPane myGlassPane; - - private Component myRootComponent; - - private SwitchTarget mySelection; - private SwitchTarget myStartSelection; - - private boolean mySelectionWasMoved; - - private Alarm myAlarm = new Alarm(); - private Runnable myAutoApplyRunnable = new Runnable() { - public void run() { - if (myManager.canApplySwitch()) { - myManager.applySwitch(); - } - } - }; - private SwitchManager myManager; - private Spotlight mySpotlight; - - private boolean myShowspots; - private Alarm myShowspotsAlarm; - private Runnable myShowspotsRunnable = new Runnable() { - public void run() { - if (!myShowspots) { - setShowspots(true); - } - } - }; - - private boolean myFadingAway; - private Disposable myPainterDisposable = Disposer.newDisposable(); - - public SwitchingSession(SwitchManager mgr, SwitchProvider provider, KeyEvent e, @Nullable SwitchTarget preselected, boolean showSpots) { - myManager = mgr; - myProvider = provider; - myInitialEvent = e; - - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); - - - myTargets.addAll(myProvider.getTargets(true, true)); - - Component eachParent = myProvider.getComponent(); - eachParent = eachParent.getParent(); - while (eachParent != null) { - if (eachParent instanceof SwitchProvider) { - SwitchProvider eachProvider = (SwitchProvider)eachParent; - myTargets.addAll(eachProvider.getTargets(true, false)); - if (eachProvider.isCycleRoot()) { - break; - } - } - - eachParent = eachParent.getParent(); - } - - - - if (myTargets.size() == 0) { - Disposer.dispose(this); - return; - } - - - mySelection = myProvider.getCurrentTarget(); - if (myTargets.contains(preselected)) { - mySelection = preselected; - } - - myStartSelection = mySelection; - - myGlassPane = IdeGlassPaneUtil.find(myProvider.getComponent()); - myRootComponent = myProvider.getComponent().getRootPane(); - mySpotlight = new Spotlight(myRootComponent); - myGlassPane.addPainter(myRootComponent, mySpotlight, myPainterDisposable); - - myShowspotsAlarm = new Alarm(this); - restartShowspotsAlarm(); - - myShowspots = showSpots; - mySpotlight.setNeedsRepaint(true); - } - - public void setFadeaway(boolean fadeAway) { - myFadingAway = fadeAway; - } - - - private class Spotlight extends AbstractPainter { - - private Component myRoot; - - private Area myArea; - - private BufferedImage myBackground; - - private Spotlight(Component root) { - myRoot = root; - } - - @Override - public boolean needsRepaint() { - return true; - } - - @Override - public void executePaint(Component component, Graphics2D g) { - int inset = -1; - int selectedInset = -8; - - Set shapes = new HashSet<>(); - Area selected = null; - - boolean hasIntersections = false; - - Rectangle clip = g.getClipBounds(); - myArea = new Area(clip); - - for (SwitchTarget each : myTargets) { - RelativeRectangle eachSimpleRec = each.getRectangle(); - if (eachSimpleRec == null) continue; - - boolean isSelected = each.equals(mySelection); - - Rectangle eachBaseRec = eachSimpleRec.getRectangleOn(myRoot); - Rectangle eachShape; - if (isSelected) { - eachShape = new Rectangle(eachBaseRec.x + selectedInset, - eachBaseRec.y + selectedInset, - eachBaseRec.width - selectedInset -selectedInset, - eachBaseRec.height - selectedInset -selectedInset); - } else { - eachShape = new Rectangle(eachBaseRec.x + inset, - eachBaseRec.y + inset, - eachBaseRec.width - inset -inset, - eachBaseRec.height - inset -inset); - } - - if (!hasIntersections) { - hasIntersections = clip.contains(eachShape) || clip.intersects(eachShape); - } - - Area eachArea = new Area(new RoundRectangle2D.Double(eachShape.x, eachShape.y, eachShape.width, eachShape.height, 6, 6)); - shapes.add(eachArea); - if (isSelected) { - selected = eachArea; - } - } - - - Color fillColor = new Color(0f, 0f, 0f, 0.25f); - if (!hasIntersections && myShowspots) { - g.setColor(fillColor); - g.fillRect(clip.x, clip.y, clip.width, clip.height); - return; - } - - for (Area each : shapes) { - myArea.subtract(each); - if (each != selected) { - each.subtract(selected); - } - } - - GraphicsConfig cfg = new GraphicsConfig(g); - cfg.setAntialiasing(true); - - if (myShowspots) { - g.setColor(fillColor); - g.fill(myArea); - - g.setColor(Color.lightGray); - for (Shape each : shapes) { - if (each != selected) { - g.draw(each); - } - } - } - - if (selected != null) { - Color bg = Color.darkGray; - g.setColor(ColorUtil.toAlpha(bg, 180)); - g.setStroke(new BasicStroke(3)); - g.draw(selected); - } - - cfg.restore(); - } - } - - public boolean dispatchKeyEvent(KeyEvent e) { - if (myFadingAway) { - _dispose(); - } else { - KeyEvent event = myInitialEvent; - if (event == null || ((e.getModifiers() & event.getModifiers()) == 0)) { - finish(!isSelectionWasMoved()); - return false; - } - } - - return false; - } - - private SwitchTarget getSelection() { - return mySelection; - } - - public boolean isSelectionWasMoved() { - return mySelectionWasMoved; - } - - private enum Direction { - up, down, left, right - } - - public void up() { - setSelection(getNextTarget(Direction.up)); - } - - public void down() { - setSelection(getNextTarget(Direction.down)); - } - - public void left() { - setSelection(getNextTarget(Direction.left)); - } - - public void right() { - setSelection(getNextTarget(Direction.right)); - } - - private void setSelection(SwitchTarget target) { - if (target == null) return; - - mySelection = target; - - mySelectionWasMoved |= !mySelection.equals(myStartSelection); - - mySpotlight.setNeedsRepaint(true); - - myAlarm.cancelAllRequests(); - myAlarm.addRequest(myAutoApplyRunnable, Registry.intValue("actionSystem.autoSelectTimeout")); - - restartShowspotsAlarm(); - } - - private SwitchTarget getNextTarget(Direction direction) { - if (myTargets.size() == 1) { - return getSelection(); - } - - List points = new ArrayList<>(); - Point selected = null; - Map target2Point = new HashMap<>(); - for (SwitchTarget each : myTargets) { - RelativeRectangle rectangle = each.getRectangle(); - if (rectangle == null) continue; - Rectangle eachRec = rectangle.getRectangleOn(myRootComponent); - Point eachPoint = null; - switch (direction) { - case up: - eachPoint = new Point(eachRec.x + eachRec.width / 2, eachRec.y + eachRec.height); - break; - case down: - eachPoint = new Point(eachRec.x + eachRec.width /2, eachRec.y); - break; - case left: - eachPoint = new Point(eachRec.x + eachRec.width, eachRec.y + eachRec.height / 2); - break; - case right: - eachPoint = new Point(eachRec.x, eachRec.y + eachRec.height / 2); - break; - } - - if (each.equals(mySelection)) { - switch (direction) { - case up: - selected = new Point(eachRec.x + eachRec.width / 2, eachRec.y); - break; - case down: - selected = new Point(eachRec.x + eachRec.width / 2, eachRec.y + eachRec.height); - break; - case left: - selected = new Point(eachRec.x, eachRec.y + eachRec.height / 2); - break; - case right: - selected = new Point(eachRec.x + eachRec.width, eachRec.y + eachRec.height / 2); - break; - } - points.add(selected); - target2Point.put(each, selected); - } - else { - points.add(eachPoint); - target2Point.put(each, eachPoint); - } - } - - TreeMap distance = new TreeMap<>(); - for (SwitchTarget eachTarget : myTargets) { - Point eachPoint = target2Point.get(eachTarget); - if (eachPoint == null || selected == null) continue; - if (selected == eachPoint) continue; - - double eachDistance = sqrt(abs(eachPoint.getX() - selected.getX())) + sqrt(abs(eachPoint.getY() - selected.getY())); - distance.put((int)eachDistance, eachTarget); - } - - - Integer[] distancesArray = distance.keySet().toArray(new Integer[distance.size()]); - for (Integer eachDistance : distancesArray) { - SwitchTarget eachTarget = distance.get(eachDistance); - Point eachPoint = target2Point.get(eachTarget); - if (eachPoint == null || selected == null) continue; - switch (direction) { - case up: - if (eachPoint.y <= selected.y) { - return eachTarget; - } - break; - case down: - if (eachPoint.y >= selected.y) { - return eachTarget; - } - break; - case left: - if (eachPoint.x <= selected.x) { - return eachTarget; - } - break; - case right: - if (eachPoint.x >= selected.x) { - return eachTarget; - } - break; - } - } - - for (int i = distancesArray.length - 1; i >= 0; i--) { - SwitchTarget eachTarget = distance.get(distancesArray[i]); - Point eachPoint = target2Point.get(eachTarget); - if (eachPoint == null || selected == null) continue; - switch (direction) { - case up: - if (eachPoint.y >= selected.y) { - return eachTarget; - } - break; - case down: - if (eachPoint.y <= selected.y) { - return eachTarget; - } - break; - case left: - if (eachPoint.x >= selected.x) { - return eachTarget; - } - break; - case right: - if (eachPoint.x <= selected.x) { - return eachTarget; - } - break; - } - } - - - if (myTargets.size() == 0) return null; - - List all = Arrays.asList(myTargets.toArray(new SwitchTarget[myTargets.size()])); - int index = all.indexOf(getSelection()); - if (index + 1 < myTargets.size()) { - return all.get(index + 1); - } - else { - return all.get(0); - } - } - - public void dispose() { - myFinished = true; - - if (myFadingAway) { - myManager.addFadingAway(this); - myAlarm.addRequest(() -> _dispose(), Registry.intValue("actionSystem.keyGestureDblClickTime")); - } else { - _dispose(); - } - } - - private void _dispose() { - myFadingAway = false; - myManager.removeFadingAway(this); - Disposer.dispose(myPainterDisposable); - KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this); - } - - public AsyncResult finish(final boolean fadeAway) { - myAlarm.cancelAllRequests(); - - final AsyncResult result = new AsyncResult<>(); - final SwitchTarget selection = getSelection(); - if (selection != null) { - selection.switchTo(true).doWhenDone(() -> { - myManager.disposeCurrentSession(fadeAway); - result.setDone(selection); - }).notifyWhenRejected(result); - } else { - Disposer.dispose(this); - result.setDone(); - } - - return result; - } - - public boolean isFinished() { - return myFinished; - } - - public void setShowspots(boolean showspots) { - if (myShowspots != showspots) { - myShowspots = showspots; - mySpotlight.setNeedsRepaint(true); - } - } - - public boolean isShowspots() { - return myShowspots; - } - - private void restartShowspotsAlarm() { - myShowspotsAlarm.cancelAllRequests(); - myShowspotsAlarm.addRequest(myShowspotsRunnable, Registry.intValue("actionSystem.quickAccessShowSpotsTime")); - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index 2ef6de9cbb90..320e38aa2bff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -56,14 +56,14 @@ import com.intellij.openapi.wm.impl.commands.*; import com.intellij.ui.BalloonImpl; import com.intellij.ui.ColorUtil; import com.intellij.ui.awt.RelativePoint; -import com.intellij.ui.switcher.QuickAccessSettings; -import com.intellij.ui.switcher.SwitchManager; import com.intellij.util.*; import com.intellij.util.containers.HashMap; import com.intellij.util.ui.EdtInvocationManager; import com.intellij.util.ui.PositionTracker; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.UiNotifyConnector; +import gnu.trove.THashSet; +import org.intellij.lang.annotations.JdkConstants; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -264,7 +264,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements int mouseMask = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK; if ((e.getModifiersEx() & mouseMask) == 0) { - if (SwitchManager.areAllModifiersPressed(modifiers, vks) || !pressed) { + if (areAllModifiersPressed(modifiers, vks) || !pressed) { processState(pressed); } else { @@ -277,6 +277,29 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements return false; } + private static boolean areAllModifiersPressed(@JdkConstants.InputEventMask int modifiers, Set modifierCodes) { + int mask = 0; + for (Integer each : modifierCodes) { + if (each == KeyEvent.VK_SHIFT) { + mask |= InputEvent.SHIFT_MASK; + } + + if (each == KeyEvent.VK_CONTROL) { + mask |= InputEvent.CTRL_MASK; + } + + if (each == KeyEvent.VK_META) { + mask |= InputEvent.META_MASK; + } + + if (each == KeyEvent.VK_ALT) { + mask |= InputEvent.ALT_MASK; + } + } + + return (modifiers ^ mask) == 0; + } + @NotNull private static Set getActivateToolWindowVKs() { if (ApplicationManager.getApplication() == null) return new HashSet<>(); @@ -293,7 +316,28 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } } } - return QuickAccessSettings.getModifiersVKs(baseModifiers); + return getModifiersVKs(baseModifiers); + } + + @NotNull + private static Set getModifiersVKs(int mask) { + Set codes = new THashSet<>(); + if ((mask & InputEvent.SHIFT_MASK) > 0) { + codes.add(KeyEvent.VK_SHIFT); + } + if ((mask & InputEvent.CTRL_MASK) > 0) { + codes.add(KeyEvent.VK_CONTROL); + } + + if ((mask & InputEvent.META_MASK) > 0) { + codes.add(KeyEvent.VK_META); + } + + if ((mask & InputEvent.ALT_MASK) > 0) { + codes.add(KeyEvent.VK_ALT); + } + + return codes; } private void resetHoldState() { diff --git a/platform/platform-impl/src/com/intellij/ui/switcher/QuickAccessConfigurable.java b/platform/platform-impl/src/com/intellij/ui/switcher/QuickAccessConfigurable.java deleted file mode 100644 index c74e5b8fb459..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/switcher/QuickAccessConfigurable.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright 2000-2016 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.ui.switcher; - -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.KeyboardShortcut; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SearchableConfigurable; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.ui.DocumentAdapter; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.SeparatorWithText; -import com.intellij.ui.components.panels.VerticalBox; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyEvent; -import java.text.NumberFormat; -import java.util.*; - -/** -* @author nik -*/ -public class QuickAccessConfigurable extends JPanel implements SearchableConfigurable { - private Set myModifiers = new HashSet<>(); - private boolean myQaEnabled; - private int myDelay; - private JCheckBox myEnabled; - private ModifierBox myCtrl; - private ModifierBox myAlt; - private ModifierBox myShift; - private ModifierBox myMeta; - private JPanel myConflicts; - private JFormattedTextField myHoldTime; - private QuickAccessSettings myQuickAccessSettings; - - public QuickAccessConfigurable(QuickAccessSettings quickAccessSettings) { - myQuickAccessSettings = quickAccessSettings; - JPanel north = new JPanel(new BorderLayout()); - VerticalBox box = new VerticalBox(); - north.add(box, BorderLayout.NORTH); - - setLayout(new BorderLayout()); - add(north, BorderLayout.WEST); - - myEnabled = new JCheckBox("Enable Quick Access"); - myEnabled.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - myQaEnabled = myEnabled.isSelected(); - processEnabled(); - } - }); - box.add(myEnabled); - - VerticalBox kbConfig = new VerticalBox(); - - JPanel modifiers = new JPanel(new FlowLayout(FlowLayout.CENTER)) { - @Override - public Dimension getPreferredSize() { - Dimension size = super.getPreferredSize(); - size.width *= 1.5; - return size; - } - }; - myCtrl = new ModifierBox("control", KeyEvent.getKeyModifiersText(KeyEvent.CTRL_MASK)); - myAlt = new ModifierBox("alt", KeyEvent.getKeyModifiersText(KeyEvent.ALT_MASK)); - myShift = new ModifierBox("shift", KeyEvent.getKeyModifiersText(KeyEvent.SHIFT_MASK)); - myMeta = new ModifierBox("meta", KeyEvent.getKeyModifiersText(KeyEvent.META_MASK)); - - modifiers.add(new JLabel("Modifiers:")); - modifiers.add(myCtrl); - modifiers.add(myAlt); - modifiers.add(myShift); - if (SystemInfo.isMac) { - modifiers.add(myMeta); - } - - JPanel hold = new JPanel(new FlowLayout(FlowLayout.CENTER)); - hold.add(new JLabel("Hold time:")); - myHoldTime = new JFormattedTextField(NumberFormat.getIntegerInstance()); - myHoldTime.setColumns(5); - myHoldTime.setHorizontalAlignment(JTextField.RIGHT); - myHoldTime.getDocument().addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(DocumentEvent e) { - String txt = myHoldTime.getText(); - if (txt != null) { - try { - Integer value = Integer.valueOf(txt); - myDelay = value.intValue(); - } - catch (NumberFormatException e1) { - } - } - } - }); - hold.add(myHoldTime); - hold.add(new JLabel("ms")); - - kbConfig.add(modifiers); - kbConfig.add(hold); - - kbConfig.setBorder(IdeBorderFactory.createTitledBorder("Keyboard Configuration", true)); - - box.add(kbConfig); - - myConflicts = new JPanel(); - - box.add(myConflicts); - - updateConflicts(); - } - - private Set getModifierTexts() { - HashSet result = new HashSet<>(); - - for (Integer each : myQuickAccessSettings.getModiferCodes()) { - if (each == KeyEvent.VK_SHIFT) { - result.add("shift"); - } - else if (each == KeyEvent.VK_CONTROL) { - result.add("control"); - } - else if (each == KeyEvent.VK_ALT) { - result.add("alt"); - } - else if (each == KeyEvent.VK_META) { - result.add("meta"); - } - } - - return result; - } - - private void updateConflicts() { - myConflicts.removeAll(); - myConflicts.setBorder(null); - - if (!myQaEnabled) { - return; - } - - if (myModifiers.size() == 0) { - myConflicts.setLayout(new BorderLayout()); - myConflicts.add(getSmallLabel("Without assigning modifier keys Quick Access will not function"), BorderLayout.NORTH); - return; - } - - myConflicts.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(0, 4, 0, 4); - - boolean hasConflicts = printConflict(c, KeyEvent.VK_UP, QuickAccessSettings.SWITCH_UP); - hasConflicts |= printConflict(c, KeyEvent.VK_DOWN, QuickAccessSettings.SWITCH_DOWN); - hasConflicts |= printConflict(c, KeyEvent.VK_LEFT, QuickAccessSettings.SWITCH_LEFT); - hasConflicts |= printConflict(c, KeyEvent.VK_RIGHT, QuickAccessSettings.SWITCH_RIGHT); - hasConflicts |= printConflict(c, KeyEvent.VK_ENTER, QuickAccessSettings.SWITCH_APPLY); - - if (hasConflicts) { - myConflicts.setBorder(IdeBorderFactory.createTitledBorder("Conflicts", true)); - c.gridx = 0; - c.gridy++; - c.gridwidth = 2; - myConflicts.add(new SeparatorWithText(), c); - - c.gridx = 0; - c.gridy++; - myConflicts.add(getSmallLabel("These conflicting actions may be not what you use a lot"), c); - } - } - - private static JLabel getSmallLabel(final String text) { - JLabel message = new JLabel(text, null, JLabel.CENTER); - message.setFont(message.getFont().deriveFont(message.getFont().getStyle(), message.getFont().getSize() - 2)); - return message; - } - - private boolean printConflict(GridBagConstraints c, int actionKey, String actionId) { - boolean hasConflicts = false; - - int mask = myQuickAccessSettings.getModifierMask(myModifiers); - - KeyboardShortcut sc = new KeyboardShortcut(KeyStroke.getKeyStroke(actionKey, mask), null); - - Map> conflictMap = myQuickAccessSettings.getKeymap().getConflicts(actionId, sc); - if (conflictMap.size() > 0) { - hasConflicts = true; - - JLabel scText = new JLabel(sc.toString()); - c.gridy++; - c.gridx = 0; - myConflicts.add(scText, c); - - Iterator actions = conflictMap.keySet().iterator(); - while (actions.hasNext()) { - String each = actions.next(); - AnAction eachAnAction = ActionManager.getInstance().getAction(each); - if (eachAnAction != null) { - String text = eachAnAction.getTemplatePresentation().getText(); - JLabel eachAction = new JLabel(text != null && text.length() > 0 ? text : each); - c.gridx = 1; - myConflicts.add(eachAction, c); - c.gridy++; - } - } - } - - c.gridx = 0; - c.gridwidth = 2; - c.gridy++; - - myConflicts.add(new SeparatorWithText(), c); - c.gridwidth = 1; - - return hasConflicts; - - } - - @Nls - public String getDisplayName() { - return "Quick Access"; - } - - public String getHelpTopic() { - return null; - } - - public JComponent createComponent() { - return this; - } - - @NotNull - public String getId() { - return "QuickAccess"; - } - - public boolean isModified() { - return !myModifiers.equals(getModifierTexts()) - || myQuickAccessSettings.isEnabled() != myEnabled.isSelected() - || getHoldTime() != myDelay; - } - - public void apply() throws ConfigurationException { - Registry.get("actionSystem.quickAccessEnabled").setValue(myEnabled.isSelected()); - myQuickAccessSettings.saveModifiersToRegistry(myModifiers); - Registry.get("actionSystem.keyGestureHoldTime").setValue(myDelay); - } - - public void reset() { - int delay = getHoldTime(); - myQaEnabled = myQuickAccessSettings.isEnabled(); - myModifiers.clear(); - myModifiers.addAll(getModifierTexts()); - myDelay = delay; - - myEnabled.setSelected(myQaEnabled); - myCtrl.readMask(); - myAlt.readMask(); - myShift.readMask(); - myMeta.readMask(); - - myHoldTime.setText(String.valueOf(delay)); - - processEnabled(); - - updateConflicts(); - } - - private static int getHoldTime() { - return Registry.intValue("actionSystem.keyGestureHoldTime"); - } - - public void disposeUIResources() { - } - - private void processEnabled() { - for (Component component : UIUtil.uiTraverser(this)) { - if (component != myEnabled) { - component.setEnabled(myQaEnabled); - } - } - } - - private class ModifierBox extends JCheckBox { - - private String myModifierText; - - private ModifierBox(String modifierText, String text) { - setText(text); - myModifierText = modifierText; - addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - applyMask(); - updateConflicts(); - } - }); - } - - private void applyMask() { - if (isSelected()) { - myModifiers.add(myModifierText); - } - else { - myModifiers.remove(myModifierText); - } - } - - public boolean readMask() { - boolean selected = myModifiers.contains(myModifierText); - setSelected(selected); - return selected; - } - } -} diff --git a/platform/platform-impl/src/com/intellij/ui/switcher/SwitchAction.java b/platform/platform-impl/src/com/intellij/ui/switcher/SwitchAction.java deleted file mode 100644 index 32192f6b67c0..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/switcher/SwitchAction.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2000-2016 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.ui.switcher; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; - -import java.awt.event.KeyEvent; - -public abstract class SwitchAction extends AnAction implements DumbAware { - - protected SwitchAction() { - setEnabledInModalContext(true); - } - - @Override - public void update(AnActionEvent e) { - if (!getSettings().isEnabled()) { - e.getPresentation().setEnabled(false); - return; - } - - SwitchingSession session = getSession(e); - e.getPresentation().setEnabled(session != null && !session.isFinished() || getProvider(e) != null); - } - - @Override - public void actionPerformed(AnActionEvent e) { - SwitchingSession session = getSession(e); - if (session == null || session.isFinished()) { - SwitchProvider provider = getProvider(e); - session = new SwitchingSession(getManager(e), provider, (KeyEvent)e.getInputEvent(), null, false); - initSession(e, session); - } - - move(session); - } - - protected static QuickAccessSettings getSettings() { - return QuickAccessSettings.getInstance(); - } - - private static SwitchProvider getProvider(AnActionEvent e) { - return e.getData(SwitchProvider.KEY); - } - - private static SwitchingSession getSession(AnActionEvent e) { - return getManager(e).getSession(); - } - - private static SwitchManager getManager(AnActionEvent e) { - Project project = e.getProject(); - return SwitchManager.getInstance(project); - } - - private static void initSession(AnActionEvent e, SwitchingSession session) { - getManager(e).initSession(session); - } - - protected abstract void move(SwitchingSession session); - - public static class Up extends SwitchAction { - @Override - protected void move(SwitchingSession session) { - session.up(); - } - } - - public static class Down extends SwitchAction { - @Override - protected void move(SwitchingSession session) { - session.down(); - } - } - - public static class Left extends SwitchAction { - @Override - protected void move(SwitchingSession session) { - session.left(); - } - } - - public static class Right extends SwitchAction { - @Override - protected void move(SwitchingSession session) { - session.right(); - } - } - -} diff --git a/platform/platform-impl/src/com/intellij/ui/switcher/SwitchManagerAppComponent.java b/platform/platform-impl/src/com/intellij/ui/switcher/SwitchManagerAppComponent.java deleted file mode 100644 index b9c4b4a96057..000000000000 --- a/platform/platform-impl/src/com/intellij/ui/switcher/SwitchManagerAppComponent.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2015 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.ui.switcher; - -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.ex.AnActionListener; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.IdeFrame; -import com.intellij.util.ui.UIUtil; -import gnu.trove.THashSet; -import org.jetbrains.annotations.NotNull; - -import java.awt.*; -import java.awt.event.KeyEvent; -import java.util.Set; - -final class SwitchManagerAppComponent extends AnActionListener.Adapter implements KeyEventDispatcher { - private final Set switchActions = new THashSet<>(); - - public SwitchManagerAppComponent(@NotNull ActionManager actionManager) { - switchActions.add(actionManager.getAction(QuickAccessSettings.SWITCH_UP)); - switchActions.add(actionManager.getAction(QuickAccessSettings.SWITCH_DOWN)); - switchActions.add(actionManager.getAction(QuickAccessSettings.SWITCH_LEFT)); - switchActions.add(actionManager.getAction(QuickAccessSettings.SWITCH_RIGHT)); - switchActions.add(actionManager.getAction(QuickAccessSettings.SWITCH_APPLY)); - - actionManager.addAnActionListener(this); - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); - } - - @Override - public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { - Project project = event.getProject(); - if (project != null && !project.isDisposed() && !project.isDefault() && !switchActions.contains(action)) { - SwitchManager.getInstance(project).disposeCurrentSession(false); - } - } - - @Override - public boolean dispatchKeyEvent(@NotNull KeyEvent e) { - if (!QuickAccessSettings.getInstance().isEnabled()) { - return false; - } - - Component frame = UIUtil.findUltimateParent(e.getComponent()); - if (frame instanceof IdeFrame) { - Project project = ((IdeFrame)frame).getProject(); - if (project != null && !project.isDefault()) { - return SwitchManager.getInstance(project).dispatchKeyEvent(e); - } - } - return false; - } -} diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 8f0116eb6614..2a2b6067ffc0 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -305,7 +305,6 @@ - @@ -335,8 +334,6 @@ - - diff --git a/platform/platform-resources/src/componentSets/UICore.xml b/platform/platform-resources/src/componentSets/UICore.xml index f33369dcebc8..9c5ab055c517 100644 --- a/platform/platform-resources/src/componentSets/UICore.xml +++ b/platform/platform-resources/src/componentSets/UICore.xml @@ -45,22 +45,10 @@ com.intellij.ide.MacOSApplicationProvider - - com.intellij.ui.switcher.QuickAccessSettings - com.intellij.openapi.updateSettings.impl.UpdateCheckerComponent - - com.intellij.ui.switcher.SwitchManagerAppComponent - - - - - com.intellij.ui.switcher.QuickActionManager - - diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 50fba845c9b5..81f55d0afab1 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -15,15 +15,6 @@ --> - - - - - - - - - diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 0622aced242b..28f5e4fe5d00 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -30,11 +30,6 @@ actionSystem.noContextComponentWhileFocusTransfer=true actionSystem.secondKeystrokeTimeout=2000 actionSystem.secondKeystrokeAutoPopupEnabled=false actionSystem.secondKeystrokePopupTimeout=500 -actionSystem.keyGestureHoldTime=400 -actionSystem.autoSelectTimeout=1000 -actionSystem.quickAccessEnabled=false -actionSystem.quickAccessModifiers= -actionSystem.quickAccessShowSpotsTime=1500 actionSystem.win.suppressAlt=true actionSystem.win.suppressAlt.new=true