Merge remote-tracking branch 'origin/master'

This commit is contained in:
Yann Cébron
2013-07-24 17:55:29 +02:00
4 changed files with 39 additions and 12 deletions
@@ -0,0 +1,9 @@
package com.intellij.openapi.ui.popup;
import org.intellij.lang.annotations.MagicConstant;
import java.awt.event.InputEvent;
public interface ListPopupStepEx<T> extends ListPopupStep<T> {
PopupStep onChosen(T selectedValue, boolean finalChoice, @MagicConstant(flagsFromClass = InputEvent.class) int eventModifiers);
}
@@ -21,33 +21,39 @@ import com.intellij.openapi.ui.popup.SpeedSearchFilter;
import com.intellij.util.ui.UIUtil;
public abstract class BaseStep<T> implements PopupStep<T>, SpeedSearchFilter<T>, MnemonicNavigationFilter<T> {
private Runnable myFinalRunnable;
@Override
public boolean isSpeedSearchEnabled() {
return false;
}
@Override
public boolean isAutoSelectionEnabled() {
return true;
}
@Override
public SpeedSearchFilter<T> getSpeedSearchFilter() {
return this;
}
@Override
public boolean canBeHidden(T value) {
return true;
}
@Override
public String getIndexedString(T value) {
return getTextFor(value);
}
@Override
public boolean isMnemonicsNavigationEnabled() {
return false;
}
@Override
public int getMnemonicPos(T value) {
final String text = getTextFor(value);
int i = text.indexOf("&");
@@ -57,10 +63,12 @@ public abstract class BaseStep<T> implements PopupStep<T>, SpeedSearchFilter<T>,
return i;
}
@Override
public MnemonicNavigationFilter<T> getMnemonicNavigationFilter() {
return this;
}
@Override
public Runnable getFinalRunnable() {
return myFinalRunnable;
}
@@ -69,4 +77,4 @@ public abstract class BaseStep<T> implements PopupStep<T>, SpeedSearchFilter<T>,
myFinalRunnable = runnable;
return FINAL_CHOICE;
}
}
}
@@ -621,7 +621,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
public boolean isEnabled() { return myIsEnabled; }
}
private static class ActionPopupStep implements ListPopupStep<ActionItem>, MnemonicNavigationFilter<ActionItem>, SpeedSearchFilter<ActionItem> {
private static class ActionPopupStep implements ListPopupStepEx<ActionItem>, MnemonicNavigationFilter<ActionItem>, SpeedSearchFilter<ActionItem> {
private final List<ActionItem> myItems;
private final String myTitle;
private final Component myContext;
@@ -711,6 +711,11 @@ public class PopupFactoryImpl extends JBPopupFactory {
@Override
public PopupStep onChosen(final ActionItem actionChoice, final boolean finalChoice) {
return onChosen(actionChoice, finalChoice, 0);
}
@Override
public PopupStep onChosen(ActionItem actionChoice, boolean finalChoice, final int eventModifiers) {
if (!actionChoice.isEnabled()) return FINAL_CHOICE;
final AnAction action = actionChoice.getAction();
DataManager mgr = DataManager.getInstance();
@@ -725,7 +730,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
myFinalRunnable = new Runnable() {
@Override
public void run() {
action.actionPerformed(new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), ActionManager.getInstance(), 0));
action.actionPerformed(new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, action.getTemplatePresentation().clone(), ActionManager.getInstance(), eventModifiers));
}
};
return FINAL_CHOICE;
@@ -19,10 +19,7 @@ import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeEventQueue;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.ui.popup.ListPopupStep;
import com.intellij.openapi.ui.popup.MultiSelectionListPopupStep;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.statistics.StatisticsInfo;
@@ -34,6 +31,7 @@ import com.intellij.ui.popup.ClosableByLeftArrow;
import com.intellij.ui.popup.WizardPopup;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
@@ -327,7 +325,7 @@ public class ListPopupImpl extends WizardPopup implements ListPopup {
_handleSelect(handleFinalChoices, e);
}
private boolean _handleSelect(final boolean handleFinalChoices, InputEvent e) {
private boolean _handleSelect(final boolean handleFinalChoices, @Nullable InputEvent e) {
if (myList.getSelectedIndex() == -1) return false;
if (getSpeedSearch().isHoldingFilter() && myList.getModel().getSize() == 0) return false;
@@ -356,9 +354,16 @@ public class ListPopupImpl extends WizardPopup implements ListPopup {
valuesSelected(selectedValues);
final PopupStep nextStep = listStep instanceof MultiSelectionListPopupStep<?>
? ((MultiSelectionListPopupStep<Object>)listStep).onChosen(Arrays.asList(selectedValues), handleFinalChoices)
: listStep.onChosen(selectedValues[0], handleFinalChoices);
final PopupStep nextStep;
if (listStep instanceof MultiSelectionListPopupStep<?>) {
nextStep = ((MultiSelectionListPopupStep<Object>)listStep).onChosen(Arrays.asList(selectedValues), handleFinalChoices);
}
else if (e != null && listStep instanceof ListPopupStepEx<?>) {
nextStep = ((ListPopupStepEx<Object>)listStep).onChosen(selectedValues[0], handleFinalChoices, e.getModifiers());
}
else {
nextStep = listStep.onChosen(selectedValues[0], handleFinalChoices);
}
return handleNextStep(nextStep, selectedValues.length == 1 ? selectedValues[0] : null, e);
}