mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
show 'readonly' file icons in dumb mode
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user