From c6b40735aa4abe8a48613aa698d2e25aad2654bb Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 27 Oct 2011 12:18:33 +0200 Subject: [PATCH] provide refactoring quick list (IDEA-75821) --- .../RefactoringQuickListPopupAction.java | 72 +++++++++++++++++++ .../ide/actions/QuickSwitchSchemeAction.java | 4 ++ .../openapi/actionSystem/IdeActions.java | 1 + .../src/idea/Keymap_Default.xml | 3 + .../src/idea/LangActions.xml | 9 ++- resources/src/idea/JavaActions.xml | 9 +-- 6 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java new file mode 100644 index 000000000000..83a37309085c --- /dev/null +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/RefactoringQuickListPopupAction.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2011 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.refactoring.actions; + +import com.intellij.ide.actions.QuickSwitchSchemeAction; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.popup.ListPopup; +import org.jetbrains.annotations.Nullable; + +public class RefactoringQuickListPopupAction extends QuickSwitchSchemeAction { + + protected void fillActions(@Nullable final Project project, + final DefaultActionGroup group, + final DataContext dataContext) { + if (project == null) { + return; + } + + final ActionManager actionManager = ActionManager.getInstance(); + final AnAction action = actionManager.getAction(IdeActions.GROUP_REFACTOR); + if (action instanceof DefaultActionGroup) { + final AnAction[] children = ((DefaultActionGroup)action).getChildren(null); + for (AnAction child : children) { + if (child instanceof Separator) { + group.add(child); + } + else if (child instanceof BaseRefactoringAction && ((BaseRefactoringAction)child).getHandler(dataContext) != null) { + final Presentation presentation = new Presentation(); + final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, presentation, actionManager, 0); + child.update(event); + if (presentation.isEnabled() && presentation.isVisible()) { + group.add(child); + } + } + } + } + } + + + @Override + protected void showPopup(AnActionEvent e, ListPopup popup) { + final Editor editor = e.getData(PlatformDataKeys.EDITOR); + if (editor != null) { + popup.showInBestPositionFor(editor); + } else { + super.showPopup(e, popup); + } + } + + protected boolean isEnabled() { + return true; + } + + protected String getPopupTitle(AnActionEvent e) { + return "Refactor This"; + } +} diff --git a/platform/platform-api/src/com/intellij/ide/actions/QuickSwitchSchemeAction.java b/platform/platform-api/src/com/intellij/ide/actions/QuickSwitchSchemeAction.java index a31db04d1086..c3143fbe55ca 100644 --- a/platform/platform-api/src/com/intellij/ide/actions/QuickSwitchSchemeAction.java +++ b/platform/platform-api/src/com/intellij/ide/actions/QuickSwitchSchemeAction.java @@ -63,6 +63,10 @@ public abstract class QuickSwitchSchemeAction extends AnAction implements DumbAw e.getDataContext(), getAidMethod(), true, myActionPlace); + showPopup(e, popup); + } + + protected void showPopup(AnActionEvent e, ListPopup popup) { popup.showCenteredInCurrentWindow(e.getData(PlatformDataKeys.PROJECT)); } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java index d19bcce5e8cc..a8a50c2884e7 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java @@ -252,4 +252,5 @@ public interface IdeActions { String ACTION_UNDO = "$Undo"; String ACTION_REDO = "$Redo"; + String GROUP_REFACTOR = "RefactoringMenu"; } diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index e4ca0f809134..3d9732ced32a 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -934,5 +934,8 @@ + + + diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index bcabc7822d58..fa1c63e7bd39 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -250,6 +250,9 @@ + @@ -258,21 +261,21 @@ - - + + - + diff --git a/resources/src/idea/JavaActions.xml b/resources/src/idea/JavaActions.xml index 46a184c19c13..f76529a259ca 100644 --- a/resources/src/idea/JavaActions.xml +++ b/resources/src/idea/JavaActions.xml @@ -59,9 +59,10 @@ - + - + + @@ -83,10 +84,6 @@ - - - -