Search in sources :

Example 11 with LookupImpl

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

the class CodeInsightTestFixtureImpl method assertPreferredCompletionItems.

@Override
public void assertPreferredCompletionItems(final int selected, @NotNull final String... expected) {
    final LookupImpl lookup = getLookup();
    assertNotNull("No lookup is shown", lookup);
    final JList list = lookup.getList();
    List<String> strings = getLookupElementStrings();
    assertNotNull(strings);
    final List<String> actual = strings.subList(0, Math.min(expected.length, strings.size()));
    if (!actual.equals(Arrays.asList(expected))) {
        UsefulTestCase.assertOrderedEquals(DumpLookupElementWeights.getLookupElementWeights(lookup, false), expected);
    }
    if (selected != list.getSelectedIndex()) {
        //noinspection UseOfSystemOutOrSystemErr
        System.out.println(DumpLookupElementWeights.getLookupElementWeights(lookup, false));
    }
    assertEquals(selected, list.getSelectedIndex());
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 12 with LookupImpl

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

the class InplaceRefactoring method restoreOldCaretPositionAndSelection.

private void restoreOldCaretPositionAndSelection(final int offset) {
    //move to old offset
    Runnable runnable = () -> {
        myEditor.getCaretModel().moveToOffset(restoreCaretOffset(offset));
        restoreSelection();
    };
    final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
    if (lookup != null && lookup.getLookupStart() <= (restoreCaretOffset(offset))) {
        lookup.setFocusDegree(LookupImpl.FocusDegree.UNFOCUSED);
        lookup.performGuardedChange(runnable);
    } else {
        runnable.run();
    }
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl)

Example 13 with LookupImpl

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

the class CodeCompletionHandlerBase method obtainLookup.

@NotNull
private LookupImpl obtainLookup(Editor editor, Project project) {
    CompletionAssertions.checkEditorValid(editor);
    LookupImpl existing = (LookupImpl) LookupManager.getActiveLookup(editor);
    if (existing != null && existing.isCompletion()) {
        existing.markReused();
        if (!autopopup) {
            existing.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
        }
        return existing;
    }
    LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
    if (editor.isOneLineMode()) {
        lookup.setCancelOnClickOutside(true);
        lookup.setCancelOnOtherWindowOpen(true);
    }
    lookup.setFocusDegree(autopopup ? LookupImpl.FocusDegree.UNFOCUSED : LookupImpl.FocusDegree.FOCUSED);
    return lookup;
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with LookupImpl

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

the class ListTemplatesHandler method showTemplatesLookup.

public static void showTemplatesLookup(final Project project, final Editor editor, Map<TemplateImpl, String> template2Argument) {
    final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
    for (TemplateImpl template : template2Argument.keySet()) {
        String prefix = computePrefix(template, template2Argument.get(template));
        lookup.addItem(createTemplateElement(template), new PlainPrefixMatcher(prefix));
    }
    showLookup(lookup, template2Argument);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher)

Example 15 with LookupImpl

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

the class ConsoleExecuteAction method update.

@Override
public final void update(@NotNull AnActionEvent e) {
    EditorEx editor = myConsoleView.getConsoleEditor();
    boolean enabled = !editor.isRendererMode() && isEnabled() && (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence()));
    if (enabled) {
        Lookup lookup = LookupManager.getActiveLookup(editor);
        // we should check getCurrentItem() also - fast typing could produce outdated lookup, such lookup reports isCompletion() true
        enabled = lookup == null || !lookup.isCompletion() || lookup.getCurrentItem() == null || (lookup instanceof LookupImpl && ((LookupImpl) lookup).getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED);
    }
    e.getPresentation().setEnabled(enabled);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Lookup(com.intellij.codeInsight.lookup.Lookup)

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