Search in sources :

Example 1 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project intellij-plugins by JetBrains.

the class FlexCompletionTest method commonFlex3NamespaceInFlex4Context.

private void commonFlex3NamespaceInFlex4Context(final String namespaceToSelect, final String... otherExpectedNamespaces) throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".mxml");
    complete();
    final String[] expectedNamespaces = ArrayUtil.mergeArrays(new String[] { namespaceToSelect }, otherExpectedNamespaces);
    assertEquals(expectedNamespaces.length, myItems.length);
    final String[] namespaces = new String[myItems.length];
    LookupElement selectedElement = null;
    for (int i = 0; i < myItems.length; i++) {
        final LookupElement lookupElement = myItems[i];
        final LookupElementPresentation presentation = new LookupElementPresentation();
        lookupElement.renderElement(presentation);
        assertEquals("Accordion", presentation.getItemText());
        final String namespace = presentation.getTypeText();
        namespaces[i] = namespace;
        if (namespace.equals(namespaceToSelect)) {
            selectedElement = lookupElement;
        }
    }
    assertSameElements(namespaces, expectedNamespaces);
    assertNotNull(selectedElement);
    selectItem(selectedElement, Lookup.REPLACE_SELECT_CHAR);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.mxml");
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 2 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project android by JetBrains.

the class AndroidLayoutDomTest method doTestTagNameIcons.

private void doTestTagNameIcons(String fileName) throws IOException {
    VirtualFile file = copyFileToProject(fileName);
    myFixture.configureFromExistingVirtualFile(file);
    LookupElement[] elements = myFixture.complete(CompletionType.BASIC);
    Set<String> elementsToCheck = new HashSet<>(Arrays.asList("view", "include", "requestFocus", "fragment", "Button"));
    for (LookupElement element : elements) {
        String s = element.getLookupString();
        Object obj = element.getObject();
        if (elementsToCheck.contains(s)) {
            LookupElementPresentation presentation = new LookupElementPresentation();
            element.renderElement(presentation);
            assertNotNull("no icon for element: " + element, presentation.getIcon());
            if ("Button".equals(s)) {
                assertInstanceOf(obj, PsiClass.class);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement) HashSet(com.intellij.util.containers.HashSet)

Example 3 with LookupElementPresentation

use of com.intellij.codeInsight.lookup.LookupElementPresentation in project android by JetBrains.

the class AndroidLayoutDomTest method testDeprecatedAttributeNamesCompletion.

// Deprecated attributes should be crossed out in the completion
// This test specifically checks for "android:editable" attribute on TextView
public void testDeprecatedAttributeNamesCompletion() throws Throwable {
    myFixture.configureFromExistingVirtualFile(copyFileToProject("text_view_editable.xml"));
    myFixture.complete(CompletionType.BASIC);
    // LookupElement that corresponds to "android:editable" attribute
    LookupElement editableElement = null;
    for (LookupElement element : myFixture.getLookupElements()) {
        if ("android:editable".equals(element.getLookupString())) {
            editableElement = element;
        }
    }
    assertEquals("android:editable", editableElement.getLookupString());
    LookupElementPresentation presentation = new LookupElementPresentation();
    editableElement.renderElement(presentation);
    assertTrue(presentation.isStrikeout());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 4 with LookupElementPresentation

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

the class LookupCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(final JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
    boolean nonFocusedSelection = isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
    if (!myLookup.isFocused()) {
        isSelected = false;
    }
    myIsSelected = isSelected;
    final LookupElement item = (LookupElement) value;
    final Color foreground = getForegroundColor(isSelected);
    final Color background = nonFocusedSelection ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR : isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;
    int allowedWidth = list.getWidth() - calcSpacing(myNameComponent, myEmptyIcon) - calcSpacing(myTailComponent, null) - calcSpacing(myTypeLabel, null);
    FontMetrics normalMetrics = getRealFontMetrics(item, false);
    FontMetrics boldMetrics = getRealFontMetrics(item, true);
    final LookupElementPresentation presentation = new RealLookupElementPresentation(isSelected ? getMaxWidth() : allowedWidth, normalMetrics, boldMetrics, myLookup);
    AccessToken token = ReadAction.start();
    try {
        if (item.isValid()) {
            try {
                item.renderElement(presentation);
            } catch (ProcessCanceledException e) {
                LOG.info(e);
                presentation.setItemTextForeground(JBColor.RED);
                presentation.setItemText("Error occurred, see the log in Help | Show Log");
            } catch (Exception | Error e) {
                LOG.error(e);
            }
        } else {
            presentation.setItemTextForeground(JBColor.RED);
            presentation.setItemText("Invalid");
        }
    } finally {
        token.finish();
    }
    myNameComponent.clear();
    myNameComponent.setBackground(background);
    allowedWidth -= setItemTextLabel(item, new JBColor(isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(), presentation.getItemTextForeground()), isSelected, presentation, allowedWidth);
    Font font = myLookup.getCustomFont(item, false);
    if (font == null) {
        font = myNormalFont;
    }
    myTailComponent.setFont(font);
    myTypeLabel.setFont(font);
    myNameComponent.setIcon(augmentIcon(myLookup.getEditor(), presentation.getIcon(), myEmptyIcon));
    myTypeLabel.clear();
    if (allowedWidth > 0) {
        allowedWidth -= setTypeTextLabel(item, background, foreground, presentation, isSelected ? getMaxWidth() : allowedWidth, isSelected, nonFocusedSelection, normalMetrics);
    }
    myTailComponent.clear();
    myTailComponent.setBackground(background);
    if (isSelected || allowedWidth >= 0) {
        setTailTextLabel(isSelected, presentation, foreground, isSelected ? getMaxWidth() : allowedWidth, nonFocusedSelection, normalMetrics);
    }
    if (mySelected.containsKey(index)) {
        if (!isSelected && mySelected.get(index)) {
            myPanel.setUpdateExtender(true);
        }
    }
    mySelected.put(index, isSelected);
    final double w = myNameComponent.getPreferredSize().getWidth() + myTailComponent.getPreferredSize().getWidth() + myTypeLabel.getPreferredSize().getWidth();
    boolean useBoxLayout = isSelected && w > list.getWidth() && ((JBList) list).getExpandableItemsHandler().isEnabled();
    if (useBoxLayout != myPanel.getLayout() instanceof BoxLayout) {
        myPanel.removeAll();
        if (useBoxLayout) {
            myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
            myPanel.add(myNameComponent);
            myPanel.add(myTailComponent);
            myPanel.add(myTypeLabel);
        } else {
            myPanel.setLayout(new BorderLayout());
            myPanel.add(myNameComponent, BorderLayout.WEST);
            myPanel.add(myTailComponent, BorderLayout.CENTER);
            myPanel.add(myTypeLabel, BorderLayout.EAST);
        }
    }
    AccessibleContextUtil.setCombinedName(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    AccessibleContextUtil.setCombinedDescription(myPanel, myNameComponent, "", myTailComponent, " - ", myTypeLabel);
    return myPanel;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) AccessToken(com.intellij.openapi.application.AccessToken) JBList(com.intellij.ui.components.JBList) RealLookupElementPresentation(com.intellij.codeInsight.lookup.RealLookupElementPresentation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with LookupElementPresentation

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

the class SecondSmartTypeCompletionTest method testEmptyMapPresentation.

public void testEmptyMapPresentation() {
    configure();
    LookupElementPresentation presentation = new LookupElementPresentation();
    myItems[0].renderElement(presentation);
    assertEquals("Collections.<String, S...>emptyMap", presentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation)

Aggregations

LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)20 LookupElement (com.intellij.codeInsight.lookup.LookupElement)12 LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)2 RealLookupElementPresentation (com.intellij.codeInsight.lookup.RealLookupElementPresentation)2 SingleLineEmmetFilter (com.intellij.codeInsight.template.emmet.filters.SingleLineEmmetFilter)1 XmlZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.XmlZenCodingGenerator)1 ZenCodingGenerator (com.intellij.codeInsight.template.emmet.generators.ZenCodingGenerator)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)1 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Editor (com.intellij.openapi.editor.Editor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 JBList (com.intellij.ui.components.JBList)1 ThrowableRunnable (com.intellij.util.ThrowableRunnable)1 HashSet (com.intellij.util.containers.HashSet)1 Nullable (javax.annotation.Nullable)1