From f0f1979293c9ba406c7e7f794bbc63bb320085bd Mon Sep 17 00:00:00 2001 From: Sergey Baranov Date: Fri, 25 Sep 2009 16:18:35 +0400 Subject: [PATCH] cache ico/exe native icons by file path --- .../impl/NativeFileIconProvider.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/NativeFileIconProvider.java b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/NativeFileIconProvider.java index 368686a9c938..da968b61cca6 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/NativeFileIconProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/NativeFileIconProvider.java @@ -20,24 +20,33 @@ import java.util.*; public class NativeFileIconProvider implements FileIconProvider { private JFileChooser myFileChooser = new JFileChooser(); private final Map myIconCache = new HashMap(); - // on Windows .exe and .ico files provide their own icons which can differ for each file, don't cache them - private final Set myNoCacheExtensions = SystemInfo.isWindows ? new HashSet(Arrays.asList("exe", "ico")) : new HashSet(); + // on Windows .exe and .ico files provide their own icons which can differ for each file, cache them by full file path + private final Set myCustomIconExtensions = + SystemInfo.isWindows ? new HashSet(Arrays.asList("exe", "ico")) : new HashSet(); + private final Map myCustomIconCache = new HashMap(); public Icon getIcon(VirtualFile file, int flags, @Nullable Project project) { if (!(file.getFileType() instanceof NativeFileType) && !(file.getFileType() instanceof UnknownFileType)) { return null; } final String ext = file.getExtension(); + final String filePath = file.getPath(); + Icon icon; synchronized (myIconCache) { - icon = ext != null && !myNoCacheExtensions.contains(ext) ? myIconCache.get(ext) : null; + 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(file.getFileType().getIcon(), file, false, new Function() { public Icon fun(VirtualFile virtualFile) { - final File f = new File(virtualFile.getPath()); + final File f = new File(filePath); if (!f.exists()) { return null; } @@ -50,7 +59,12 @@ public class NativeFileIconProvider implements FileIconProvider { } if (ext != null) { synchronized (myIconCache) { - myIconCache.put(ext, icon); + if (!myCustomIconExtensions.contains(ext)) { + myIconCache.put(ext, icon); + } + else if (filePath != null) { + myCustomIconCache.put(filePath, icon); + } } } return icon;