Search in sources :

Example 6 with LookupImpl

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

the class FinalListener method perform.

public void perform(final boolean generateFinal, final String modifier, final PsiVariable variable) {
    final Document document = myEditor.getDocument();
    LOG.assertTrue(variable != null);
    final PsiModifierList modifierList = variable.getModifierList();
    LOG.assertTrue(modifierList != null);
    final int textOffset = modifierList.getTextOffset();
    final Runnable runnable = () -> {
        if (generateFinal) {
            final PsiTypeElement typeElement = variable.getTypeElement();
            final int typeOffset = typeElement != null ? typeElement.getTextOffset() : textOffset;
            document.insertString(typeOffset, modifier + " ");
        } else {
            final int idx = modifierList.getText().indexOf(modifier);
            document.deleteString(textOffset + idx, textOffset + idx + modifier.length() + 1);
        }
    };
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    if (lookup != null) {
        lookup.performGuardedChange(runnable);
    } else {
        runnable.run();
    }
    PsiDocumentManager.getInstance(variable.getProject()).commitDocument(document);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) Document(com.intellij.openapi.editor.Document)

Example 7 with LookupImpl

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

the class JsonSchemaCrossReferencesTest method checkCompletion.

private void checkCompletion(String... strings) {
    assertStringItems(strings);
    LookupImpl lookup = getActiveLookup();
    if (lookup != null)
        lookup.hide();
    JsonSchemaService.Impl.get(getProject()).reset();
    doHighlighting();
    complete();
    assertStringItems(strings);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 8 with LookupImpl

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

the class TreeInplaceEditor method eventDispatched.

@Override
public void eventDispatched(AWTEvent event) {
    if (!isShown()) {
        return;
    }
    MouseEvent mouseEvent = (MouseEvent) event;
    if (mouseEvent.getClickCount() == 0 && !(event instanceof MouseWheelEvent)) {
        return;
    }
    final int id = mouseEvent.getID();
    if (id != MouseEvent.MOUSE_PRESSED && id != MouseEvent.MOUSE_RELEASED && id != MouseEvent.MOUSE_CLICKED && id != MouseEvent.MOUSE_WHEEL) {
        return;
    }
    final Component sourceComponent = mouseEvent.getComponent();
    final Point originalPoint = mouseEvent.getPoint();
    final Editor editor = getEditor();
    if (editor == null)
        return;
    Project project = editor.getProject();
    LookupImpl activeLookup = project != null ? (LookupImpl) LookupManager.getInstance(project).getActiveLookup() : null;
    if (activeLookup != null) {
        final Point lookupPoint = SwingUtilities.convertPoint(sourceComponent, originalPoint, activeLookup.getComponent());
        if (activeLookup.getComponent().getBounds().contains(lookupPoint)) {
            //mouse click inside lookup
            return;
        } else {
            //hide popup on mouse position changed
            activeLookup.hide();
        }
    }
    // do not cancel editing if we click in editor popup
    final List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(myInplaceEditorComponent);
    for (JBPopup popup : popups) {
        if (SwingUtilities.isDescendingFrom(sourceComponent, popup.getContent())) {
            return;
        }
    }
    final Point point = SwingUtilities.convertPoint(sourceComponent, originalPoint, myInplaceEditorComponent);
    if (myInplaceEditorComponent.contains(point)) {
        return;
    }
    final Component componentAtPoint = SwingUtilities.getDeepestComponentAt(sourceComponent, originalPoint.x, originalPoint.y);
    for (Component comp = componentAtPoint; comp != null; comp = comp.getParent()) {
        if (comp instanceof ComboPopup) {
            if (id != MouseEvent.MOUSE_WHEEL) {
                doPopupOKAction();
            }
            return;
        }
    }
    if (id != MouseEvent.MOUSE_RELEASED) {
        // do not cancel on release outside of the component
        cancelEditing();
    }
}
Also used : Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) ComboPopup(javax.swing.plaf.basic.ComboPopup) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 9 with LookupImpl

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

the class LightFixtureCompletionTestCase method selectItem.

protected void selectItem(@NotNull LookupElement item, final char completionChar) {
    final LookupImpl lookup = getLookup();
    lookup.setCurrentItem(item);
    if (LookupEvent.isSpecialCompletionChar(completionChar)) {
        lookup.finishLookup(completionChar);
    } else {
        type(completionChar);
    }
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 10 with LookupImpl

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

the class CompletionTestCase method complete.

protected void complete(final int time) {
    new CodeCompletionHandlerBase(myType).invokeCompletion(myProject, InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, getFile()), time);
    LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    myItems = lookup == null ? null : lookup.getItems().toArray(new LookupElement[lookup.getItems().size()]);
    myPrefix = lookup == null ? "" : lookup.itemPattern(lookup.getItems().get(0));
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Aggregations

LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)39 ListTemplatesAction (com.intellij.codeInsight.template.impl.actions.ListTemplatesAction)5 Document (com.intellij.openapi.editor.Document)5 Editor (com.intellij.openapi.editor.Editor)5 Project (com.intellij.openapi.project.Project)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)2 LookupEx (com.intellij.codeInsight.lookup.LookupEx)2 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)1 CommandAdapter (com.intellij.openapi.command.CommandAdapter)1 CommandEvent (com.intellij.openapi.command.CommandEvent)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocCommandGroupId (com.intellij.openapi.editor.actionSystem.DocCommandGroupId)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1