Search in sources :

Example 1 with DeferredIconImpl

use of com.intellij.ui.DeferredIconImpl in project intellij-community by JetBrains.

the class NativeIconProvider method doGetIcon.

@Nullable
private Icon doGetIcon(@NotNull VirtualFile file, final int flags) {
    if (!isNativeFileType(file))
        return null;
    final Ext ext = getExtension(file, flags);
    final String filePath = file.getPath();
    Icon icon;
    synchronized (myIconCache) {
        if (!myCustomIconExtensions.contains(ext)) {
            icon = ext != null ? myIconCache.get(ext) : null;
        } else {
            icon = filePath != null ? myCustomIconCache.get(filePath) : null;
        }
    }
    if (icon != null) {
        return icon;
    }
    return new DeferredIconImpl<>(ElementBase.ICON_PLACEHOLDER.getValue(), file, false, virtualFile -> {
        final File f = new File(filePath);
        if (!f.exists()) {
            return null;
        }
        Icon icon1;
        try {
            assert SwingComponentHolder.ourFileChooser != null || !ApplicationManager.getApplication().isReadAccessAllowed();
            icon1 = getNativeIcon(f);
        } catch (Exception e) {
            return null;
        }
        if (ext != null) {
            synchronized (myIconCache) {
                if (!myCustomIconExtensions.contains(ext)) {
                    myIconCache.put(ext, icon1);
                } else if (filePath != null) {
                    myCustomIconCache.put(filePath, icon1);
                }
            }
        }
        return icon1;
    });
}
Also used : DeferredIconImpl(com.intellij.ui.DeferredIconImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DeferredIconImpl

use of com.intellij.ui.DeferredIconImpl in project intellij-plugins by JetBrains.

the class LanguageListCompletionContributor method doFillVariants.

private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
        final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
        for (LookupElement lookupElement : lookups) {
            result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
                new MyInsertHandler(parameters).handleInsert(context, item);
                lookupElement.handleInsert(context);
            }));
        }
    }
    for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
        final Language language = entry.getValue();
        final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
            final LanguageFileType fileType = language1.getAssociatedFileType();
            return fileType != null ? fileType.getIcon() : null;
        })).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
        result.addElement(lookupElementBuilder);
    }
}
Also used : Language(com.intellij.lang.Language) MarkdownElementTypes(org.intellij.plugins.markdown.lang.MarkdownElementTypes) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) MarkdownTokenTypes(org.intellij.plugins.markdown.lang.MarkdownTokenTypes) MarkdownFile(org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile) TextRange(com.intellij.openapi.util.TextRange) DeferredIconImpl(com.intellij.ui.DeferredIconImpl) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) LookupElementDecorator(com.intellij.codeInsight.lookup.LookupElementDecorator) NotNull(org.jetbrains.annotations.NotNull) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Map(java.util.Map)

Aggregations

DeferredIconImpl (com.intellij.ui.DeferredIconImpl)2 Nullable (org.jetbrains.annotations.Nullable)2 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 LookupElementDecorator (com.intellij.codeInsight.lookup.LookupElementDecorator)1 Language (com.intellij.lang.Language)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiUtilCore (com.intellij.psi.util.PsiUtilCore)1 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 MarkdownElementTypes (org.intellij.plugins.markdown.lang.MarkdownElementTypes)1 MarkdownTokenTypes (org.intellij.plugins.markdown.lang.MarkdownTokenTypes)1 MarkdownFile (org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile)1 NotNull (org.jetbrains.annotations.NotNull)1