VCS popup: do not show add if already under VCS in list [review=romeo]

This commit is contained in:
irengrig
2010-12-07 18:16:01 +03:00
parent 1873f62272
commit 0e2c8b6c28
6 changed files with 72 additions and 18 deletions
@@ -17,12 +17,13 @@
package com.intellij.ide.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.ui.EmptyIcon;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -32,6 +33,8 @@ import javax.swing.*;
public abstract class QuickSwitchSchemeAction extends AnAction implements DumbAware {
protected static final Icon ourCurrentAction = IconLoader.getIcon("/diff/currentLine.png");
protected static final Icon ourNotCurrentAction = new EmptyIcon(ourCurrentAction.getIconWidth(), ourCurrentAction.getIconHeight());
@NotNull
protected String myActionPlace = ActionPlaces.UNKNOWN;
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(PlatformDataKeys.PROJECT);
@@ -48,7 +51,7 @@ public abstract class QuickSwitchSchemeAction extends AnAction implements DumbAw
.createActionGroupPopup(QuickSwitchSchemeAction.this.getPopupTitle(e),
group,
e.getDataContext(), getAidMethod(),
true);
true, myActionPlace);
popup.showCenteredInCurrentWindow(e.getData(PlatformDataKeys.PROJECT));
}
@@ -100,6 +100,7 @@ public abstract class ActionPlaces {
public static final String REMOTE_HOST_DIALOG_POPUP = "RemoteHostDialogPopup";
public static final String TFS_TREE_POPUP = "TfsTreePopup";
public static final String ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION = "ActionPlace.VcsQuickListPopupAction";
private static final String[] ourToolbarPlaces = new String[]{EDITOR_TOOLBAR, PROJECT_VIEW_TOOLBAR, TESTTREE_VIEW_TOOLBAR, MAIN_TOOLBAR,
ANT_EXPLORER_TOOLBAR, ANT_MESSAGES_TOOLBAR, COMPILER_MESSAGES_TOOLBAR, TODO_VIEW_TOOLBAR, STRUCTURE_VIEW_TOOLBAR, USAGE_VIEW_TOOLBAR,
@@ -116,6 +117,7 @@ public abstract class ActionPlaces {
STRUCTURE_VIEW_POPUP, TODO_VIEW_POPUP, COMPILER_MESSAGES_POPUP, ANT_MESSAGES_POPUP, ANT_EXPLORER_POPUP, UPDATE_POPUP,
FILEVIEW_POPUP, CHECKOUT_POPUP, LVCS_DIRECTORY_HISTORY_POPUP, GUI_DESIGNER_EDITOR_POPUP, GUI_DESIGNER_COMPONENT_TREE_POPUP, GUI_DESIGNER_PROPERTY_INSPECTOR_POPUP,
CREATE_EJB_POPUP, CHANGES_VIEW_POPUP, REMOTE_HOST_VIEW_POPUP, REMOTE_HOST_DIALOG_POPUP, TFS_TREE_POPUP,
ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION
};
public static boolean isPopupPlace(@NotNull String place) {
@@ -161,6 +161,23 @@ public abstract class JBPopupFactory {
ActionSelectionAid selectionAidMethod,
boolean showDisabledActions);
/**
* Creates a popup allowing to choose one of the actions from the specified action group.
*
* @param title the title of the popup.
* @param actionGroup the action group from which the popup is built.
* @param dataContext the data context which provides the data for the selected action
* @param selectionAidMethod keyboard selection mode for actions in the popup.
* @param showDisabledActions if true, disabled actions are shown as disabled; if false, disabled actions are not shown
* @param actionPlace action place for ActionManager to use when creating the popup
* @return the popup instance.
*/
public abstract ListPopup createActionGroupPopup(String title,
ActionGroup actionGroup,
DataContext dataContext,
ActionSelectionAid selectionAidMethod,
boolean showDisabledActions, final @Nullable String actionPlace);
/**
* Creates a popup allowing to choose one of the actions from the specified action group.
*
@@ -114,7 +114,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
final Runnable disposeCallback,
final int maxRowCount) {
return createActionGroupPopup(title, actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, disposeCallback,
maxRowCount, null);
maxRowCount, null, null);
}
public ListPopup createActionGroupPopup(final String title,
@@ -130,18 +130,21 @@ public class PopupFactoryImpl extends JBPopupFactory {
}
private static ListPopup createActionGroupPopup(final String title,
final ActionGroup actionGroup,
DataContext dataContext,
boolean showNumbers,
boolean useAlphaAsNumbers,
boolean showDisabledActions,
boolean honorActionMnemonics,
final Runnable disposeCallback,
final int maxRowCount,
final Condition<AnAction> preselectActionCondition) {
final ActionGroup actionGroup,
DataContext dataContext,
boolean showNumbers,
boolean useAlphaAsNumbers,
boolean showDisabledActions,
boolean honorActionMnemonics,
final Runnable disposeCallback,
final int maxRowCount,
final Condition<AnAction> preselectActionCondition, @Nullable final String actionPlace) {
final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
final ActionStepBuilder builder = new ActionStepBuilder(dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics);
if (actionPlace != null) {
builder.setActionPlace(actionPlace);
}
builder.buildGroup(actionGroup);
final List<ActionItem> items = builder.getItems();
@@ -177,7 +180,8 @@ public class PopupFactoryImpl extends JBPopupFactory {
AnAction action = actionItem.getAction();
Presentation presentation = new Presentation();
presentation.setDescription(action.getTemplatePresentation().getDescription());
action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(component), ActionPlaces.UNKNOWN, presentation,
final String actualActionPlace = (actionPlace == null) ? ActionPlaces.UNKNOWN : actionPlace;
action.update(new AnActionEvent(null, DataManager.getInstance().getDataContext(component), actualActionPlace, presentation,
ActionManager.getInstance(), 0));
ActionMenu.showDescriptionInStatusBar(true, component, presentation.getDescription());
}
@@ -194,7 +198,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
final int maxRowCount,
final Condition<AnAction> preselectActionCondition) {
return createActionGroupPopup(title, actionGroup, dataContext, showNumbers, true, showDisabledActions, honorActionMnemonics,
disposeCallback, maxRowCount, preselectActionCondition);
disposeCallback, maxRowCount, preselectActionCondition, null);
}
public ListPopup createActionGroupPopup(String title,
@@ -210,6 +214,20 @@ public class PopupFactoryImpl extends JBPopupFactory {
null, -1);
}
public ListPopup createActionGroupPopup(String title,
ActionGroup actionGroup,
DataContext dataContext,
ActionSelectionAid selectionAidMethod,
boolean showDisabledActions,
@Nullable String actionPlace) {
return createActionGroupPopup(title, actionGroup, dataContext,
selectionAidMethod == ActionSelectionAid.NUMBERING || selectionAidMethod == ActionSelectionAid.ALPHA_NUMBERING,
selectionAidMethod == ActionSelectionAid.ALPHA_NUMBERING,
showDisabledActions,
selectionAidMethod == ActionSelectionAid.MNEMONICS,
null, -1, null, actionPlace);
}
public ListPopup createActionGroupPopup(String title,
ActionGroup actionGroup,
DataContext dataContext,
@@ -552,6 +570,8 @@ public class PopupFactoryImpl extends JBPopupFactory {
private Icon myEmptyIcon;
private int myMaxIconWidth = -1;
private int myMaxIconHeight = -1;
@NotNull
private String myActionPlace;
private ActionStepBuilder(final DataContext dataContext,
final boolean showNumbers,
@@ -568,6 +588,11 @@ public class PopupFactoryImpl extends JBPopupFactory {
myPrependWithSeparator = false;
mySeparatorText = null;
myHonorActionMnemonics = honorActionMnemonics;
myActionPlace = ActionPlaces.UNKNOWN;
}
public void setActionPlace(@NotNull String actionPlace) {
myActionPlace = actionPlace;
}
public List<ActionItem> getItems() {
@@ -587,7 +612,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
private void calcMaxIconSize(final ActionGroup actionGroup) {
AnAction[] actions = actionGroup.getChildren(new AnActionEvent(null, myDataContext,
ActionPlaces.UNKNOWN,
myActionPlace,
getPresentation(actionGroup),
ActionManager.getInstance(),
0));
@@ -617,7 +642,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
private void appendActionsFromGroup(final ActionGroup actionGroup) {
AnAction[] actions = actionGroup.getChildren(new AnActionEvent(null, myDataContext,
ActionPlaces.UNKNOWN,
myActionPlace,
getPresentation(actionGroup),
ActionManager.getInstance(),
0));
@@ -646,7 +671,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
private void appendAction(AnAction action) {
Presentation presentation = getPresentation(action);
AnActionEvent event = new AnActionEvent(null, myDataContext,
ActionPlaces.UNKNOWN,
myActionPlace,
presentation,
ActionManager.getInstance(),
0);
@@ -22,6 +22,9 @@ import java.util.List;
* May be customized using com.intellij.openapi.vcs.actions.VcsQuickListContentProvider extension point.
*/
public class VcsQuickListPopupAction extends QuickSwitchSchemeAction implements DumbAware {
public VcsQuickListPopupAction() {
myActionPlace = ActionPlaces.ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION;
}
protected void fillActions(@Nullable final Project project,
final DefaultActionGroup group,
@@ -22,6 +22,7 @@
*/
package com.intellij.openapi.vcs.changes.actions;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
@@ -46,7 +47,10 @@ public class ScheduleForAdditionAction extends AnAction implements DumbAware {
public void update(AnActionEvent e) {
final boolean enabled = e.getData(PlatformDataKeys.PROJECT) != null && (getUnversionedFiles(e) != null);
e.getPresentation().setEnabled(enabled);
//e.getPresentation().setVisible(enabled);
final String place = e.getPlace();
if (ActionPlaces.ACTION_PLACE_VCS_QUICK_LIST_POPUP_ACTION.equals(place) || ActionPlaces.CHANGES_VIEW_POPUP.equals(place) ) {
e.getPresentation().setVisible(enabled);
}
}
public void actionPerformed(AnActionEvent e) {