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;
});
}
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);
}
}
Aggregations