allow events processing when old popups are open -> allow to invoke e.g. Ctrl-Q from psi popups (IDEA-93897)

This commit is contained in:
anna
2012-12-19 20:26:31 +01:00
parent 9ba893929e
commit 2e46bf4c2a
6 changed files with 46 additions and 17 deletions
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.codeInsight.lookup.*;
import com.intellij.ide.util.gotoByName.ChooseByNameBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupAdapter;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.psi.PsiElement;
@@ -34,7 +33,7 @@ import java.awt.*;
/**
* @author yole
*/
public abstract class PopupUpdateProcessor extends JBPopupAdapter {
public abstract class PopupUpdateProcessor extends PopupUpdateProcessorBase {
private final Project myProject;
@@ -43,8 +42,6 @@ public abstract class PopupUpdateProcessor extends JBPopupAdapter {
}
public abstract void updatePopup(Object lookupItemObject);
public void beforeShown(final LightweightWindowEvent windowEvent) {
final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup();
if (activeLookup != null) {
@@ -4,7 +4,8 @@ import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBList;
import com.intellij.ui.popup.PopupUpdateProcessor;
import com.intellij.ui.popup.PopupUpdateProcessorBase;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
@@ -53,6 +54,7 @@ public abstract class JBListWithHintProvider extends JBList {
});
}
@Nullable
protected abstract PsiElement getPsiElementForHint(final Object selectedValue);
public void registerHint(final JBPopup hint) {
@@ -71,7 +73,7 @@ public abstract class JBListWithHintProvider extends JBList {
public void updateHint(PsiElement element) {
if (myHint == null || !myHint.isVisible()) return;
final PopupUpdateProcessor updateProcessor = myHint.getUserData(PopupUpdateProcessor.class);
final PopupUpdateProcessorBase updateProcessor = myHint.getUserData(PopupUpdateProcessorBase.class);
if (updateProcessor != null) {
updateProcessor.updatePopup(element);
}
@@ -0,0 +1,26 @@
/*
* 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.popup;
import com.intellij.openapi.ui.popup.JBPopupAdapter;
/**
* User: anna
* Date: 12/19/12
*/
public abstract class PopupUpdateProcessorBase extends JBPopupAdapter {
public abstract void updatePopup(Object lookupItemObject);
}
@@ -118,9 +118,7 @@ public class PopupDispatcher implements AWTEventListener, KeyEventDispatcher, Id
if (ourShowingStep == null) {
return false;
}
ourShowingStep.dispatch(e);
return true;
return ourShowingStep.dispatch(e);
}
public static void setShowing(WizardPopup aBaseWizardPopup) {
@@ -331,27 +331,27 @@ public abstract class WizardPopup extends AbstractPopup implements ActionListene
return myStep;
}
public final void dispatch(KeyEvent event) {
public final boolean dispatch(KeyEvent event) {
if (event.getID() != KeyEvent.KEY_PRESSED && event.getID() != KeyEvent.KEY_RELEASED) {
return;
return false;
}
if (event.getID() == KeyEvent.KEY_PRESSED) {
final KeyStroke stroke = KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), false);
if (proceedKeyEvent(event, stroke)) return;
if (proceedKeyEvent(event, stroke)) return false;
}
if (event.getID() == KeyEvent.KEY_RELEASED) {
final KeyStroke stroke = KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), true);
proceedKeyEvent(event, stroke);
return;
return proceedKeyEvent(event, stroke);
}
myMnemonicsSearch.process(event);
mySpeedSearch.process(event);
if (event.isConsumed()) return;
if (event.isConsumed()) return true;
process(event);
return event.isConsumed();
}
private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) {
@@ -24,11 +24,12 @@ 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.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.statistics.StatisticsInfo;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.ui.JBListWithHintProvider;
import com.intellij.ui.ListScrollingUtil;
import com.intellij.ui.SeparatorWithText;
import com.intellij.ui.components.JBList;
import com.intellij.ui.popup.ClosableByLeftArrow;
import com.intellij.ui.popup.WizardPopup;
import com.intellij.util.ui.UIUtil;
@@ -474,11 +475,16 @@ public class ListPopupImpl extends WizardPopup implements ListPopup {
myIndexForShowingChild = aIndexForShowingChild;
}
private class MyList extends JBList implements DataProvider{
private class MyList extends JBListWithHintProvider implements DataProvider {
public MyList() {
super(myListModel);
}
@Override
protected PsiElement getPsiElementForHint(Object selectedValue) {
return selectedValue instanceof PsiElement ? (PsiElement)selectedValue : null;
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return new Dimension(super.getPreferredScrollableViewportSize().width, getPreferredSize().height);