Search in sources :

Example 1 with LookupAdapter

use of com.intellij.codeInsight.lookup.LookupAdapter in project intellij-community by JetBrains.

the class PopupPositionManager method positionPopupInBestPosition.

public static void positionPopupInBestPosition(final JBPopup hint, @Nullable final Editor editor, @Nullable DataContext dataContext) {
    final LookupEx lookup = LookupManager.getActiveLookup(editor);
    if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) {
        new PositionAdjuster(lookup.getComponent()).adjust(hint);
        lookup.addLookupListener(new LookupAdapter() {

            @Override
            public void lookupCanceled(LookupEvent event) {
                if (hint.isVisible()) {
                    hint.cancel();
                }
            }
        });
        return;
    }
    final PositionAdjuster positionAdjuster = createPositionAdjuster();
    if (positionAdjuster != null) {
        positionAdjuster.adjust(hint);
        return;
    }
    if (editor != null && editor.getComponent().isShowing()) {
        hint.showInBestPositionFor(editor);
        return;
    }
    if (dataContext != null) {
        hint.showInBestPositionFor(dataContext);
    }
}
Also used : LookupEvent(com.intellij.codeInsight.lookup.LookupEvent) LookupEx(com.intellij.codeInsight.lookup.LookupEx) LookupAdapter(com.intellij.codeInsight.lookup.LookupAdapter)

Aggregations

LookupAdapter (com.intellij.codeInsight.lookup.LookupAdapter)1 LookupEvent (com.intellij.codeInsight.lookup.LookupEvent)1 LookupEx (com.intellij.codeInsight.lookup.LookupEx)1