From f6b9382f4e19df69f3b6430c2de67a56a1543516 Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Thu, 10 Sep 2009 20:13:27 +0400 Subject: [PATCH] show 'readonly' file icons in dumb mode --- .../com/intellij/ide/JavaFileIconPatcher.java | 81 +++++++------------ .../src/com/intellij/ui/LayeredIcon.java | 7 ++ .../src/com/intellij/util/IconUtil.java | 8 ++ 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java b/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java index 52048a78c5ed..89061751f46a 100644 --- a/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java +++ b/java/java-impl/src/com/intellij/ide/JavaFileIconPatcher.java @@ -9,7 +9,6 @@ import com.intellij.openapi.roots.FileIndexUtil; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClassOwner; @@ -25,62 +24,40 @@ import javax.swing.*; */ public class JavaFileIconPatcher implements FileIconPatcher { public Icon patchIcon(final Icon baseIcon, final VirtualFile file, final int flags, final Project project) { - Icon icon = baseIcon; - if (project != null) { - final boolean isUnderSource = FileIndexUtil.isJavaSourceFile(project, file); - FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(file); - if (fileType == StdFileTypes.JAVA) { - if (!isUnderSource) { - icon = Icons.JAVA_OUTSIDE_SOURCE_ICON; - } - else { - PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if (psiFile instanceof PsiClassOwner) { - PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); - if (classes.length > 0) { - // prefer icon of the class named after file - final String fileName = file.getNameWithoutExtension(); - Icon classIcon = null; - for (PsiClass aClass : classes) { - if (Comparing.strEqual(aClass.getName(), fileName)) { - classIcon = aClass.getIcon(flags); - break; - } - } - if (classIcon == null) classIcon = classes[classes.length - 1].getIcon(flags); - icon = classIcon; - } - } - } - } + if (project == null) { + return baseIcon; } - Icon excludedIcon = null; - if (project != null) { - final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - if (projectFileIndex.isInSource(file) && CompilerManager.getInstance(project).isExcludedFromCompilation(file)) { - excludedIcon = Icons.EXCLUDED_FROM_COMPILE_ICON; - } - } + Icon icon = replaceIcon(file, flags, project, baseIcon); - Icon lockedIcon = null; - if ((flags & Iconable.ICON_FLAG_READ_STATUS) != 0 && !file.isWritable()) { - lockedIcon = Icons.LOCKED_ICON; - } - - if (excludedIcon != null || lockedIcon != null) { - LayeredIcon layeredIcon = new LayeredIcon(1 + (lockedIcon != null ? 1 : 0) + (excludedIcon != null ? 1 : 0)); - int layer = 0; - layeredIcon.setIcon(icon, layer++); - if (lockedIcon != null) { - layeredIcon.setIcon(lockedIcon, layer++); - } - if (excludedIcon != null) { - layeredIcon.setIcon(excludedIcon, layer); - } - icon = layeredIcon; + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + if (fileIndex.isInSource(file) && CompilerManager.getInstance(project).isExcludedFromCompilation(file)) { + return new LayeredIcon(icon, Icons.EXCLUDED_FROM_COMPILE_ICON); } return icon; } + + private static Icon replaceIcon(VirtualFile file, int flags, Project project, Icon baseIcon) { + FileType fileType = FileTypeManager.getInstance().getFileTypeByFile(file); + if (fileType == StdFileTypes.JAVA && !FileIndexUtil.isJavaSourceFile(project, file)) { + return Icons.JAVA_OUTSIDE_SOURCE_ICON; + } + + PsiFile psiFile = PsiManager.getInstance(project).findFile(file); + if (psiFile instanceof PsiClassOwner) { + PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); + if (classes.length > 0) { + // prefer icon of the class named after file + final String fileName = file.getNameWithoutExtension(); + for (PsiClass aClass : classes) { + if (Comparing.strEqual(aClass.getName(), fileName)) { + return aClass.getIcon(flags); + } + } + return classes[classes.length - 1].getIcon(flags); + } + } + return baseIcon; + } } diff --git a/platform/platform-api/src/com/intellij/ui/LayeredIcon.java b/platform/platform-api/src/com/intellij/ui/LayeredIcon.java index b54551c5981a..9db0dedcc64e 100644 --- a/platform/platform-api/src/com/intellij/ui/LayeredIcon.java +++ b/platform/platform-api/src/com/intellij/ui/LayeredIcon.java @@ -40,6 +40,13 @@ public class LayeredIcon implements Icon { myVShifts = new int[layerCount]; } + public LayeredIcon(Icon... icons) { + this(icons.length); + for (int i = 0; i < icons.length; i++) { + setIcon(icons[i], i); + } + } + public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof LayeredIcon)) return false; diff --git a/platform/platform-api/src/com/intellij/util/IconUtil.java b/platform/platform-api/src/com/intellij/util/IconUtil.java index 3f7106ef594f..5b1bf7898b33 100644 --- a/platform/platform-api/src/com/intellij/util/IconUtil.java +++ b/platform/platform-api/src/com/intellij/util/IconUtil.java @@ -22,9 +22,11 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.Iconable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.IconDeferrer; import com.intellij.ui.RowIcon; +import com.intellij.ui.LayeredIcon; import com.intellij.util.ui.EmptyIcon; import org.jetbrains.annotations.Nullable; @@ -93,6 +95,7 @@ public class IconUtil { Icon providersIcon = getProvidersIcon(file, flags, project); Icon icon = providersIcon == null ? file.getIcon() : providersIcon; + final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); for (FileIconPatcher patcher : getPatchers()) { if (dumb && !(patcher instanceof DumbAware)) { @@ -101,6 +104,11 @@ public class IconUtil { icon = patcher.patchIcon(icon, file, flags, project); } + + if ((flags & Iconable.ICON_FLAG_READ_STATUS) != 0 && !file.isWritable()) { + return new LayeredIcon(icon, Icons.LOCKED_ICON); + } + return icon; } });