mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[cidr] native icons for project view folders (blue) for mac & aqua laf & cidr exclusively :)
This commit is contained in:
+18
-4
@@ -41,8 +41,10 @@ import com.intellij.psi.impl.file.PsiDirectoryFactory;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.ui.RowIcon;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -117,14 +119,26 @@ public class PsiDirectoryNode extends BasePsiNode<PsiDirectory> implements Navig
|
||||
|
||||
private void setupIcon(PresentationData data, PsiDirectory psiDirectory) {
|
||||
final VirtualFile virtualFile = psiDirectory.getVirtualFile();
|
||||
for (final IconProvider provider : Extensions.getExtensions(IconProvider.EXTENSION_POINT_NAME)) {
|
||||
final Icon openIcon = provider.getIcon(psiDirectory, Iconable.ICON_FLAG_OPEN);
|
||||
if (PlatformUtils.isCidr()) {
|
||||
final Icon openIcon = IconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_OPEN, myProject);
|
||||
if (openIcon != null) {
|
||||
final Icon closedIcon = provider.getIcon(psiDirectory, Iconable.ICON_FLAG_CLOSED);
|
||||
final Icon closedIcon = IconUtil.getIcon(virtualFile, Iconable.ICON_FLAG_CLOSED, myProject);
|
||||
if (closedIcon != null) {
|
||||
data.setOpenIcon(patchIcon(openIcon, virtualFile));
|
||||
data.setClosedIcon(patchIcon(closedIcon, virtualFile));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (final IconProvider provider : Extensions.getExtensions(IconProvider.EXTENSION_POINT_NAME)) {
|
||||
final Icon openIcon = provider.getIcon(psiDirectory, Iconable.ICON_FLAG_OPEN);
|
||||
if (openIcon != null) {
|
||||
final Icon closedIcon = provider.getIcon(psiDirectory, Iconable.ICON_FLAG_CLOSED);
|
||||
if (closedIcon != null) {
|
||||
data.setOpenIcon(patchIcon(openIcon, virtualFile));
|
||||
data.setClosedIcon(patchIcon(closedIcon, virtualFile));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+32
-4
@@ -19,10 +19,12 @@ package com.intellij.openapi.fileTypes.impl;
|
||||
import com.intellij.ide.FileIconProvider;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.impl.ElementBase;
|
||||
import com.intellij.ui.DeferredIconImpl;
|
||||
import com.intellij.ui.mac.foundation.Foundation;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.update.ComparableObject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -43,10 +45,15 @@ public class NativeFileIconProvider implements FileIconProvider {
|
||||
|
||||
private static final Ext NO_EXT = new Ext(null);
|
||||
|
||||
public Icon getIcon(VirtualFile file, int flags, @Nullable Project project) {
|
||||
private static final Ext OPEN_DIR = new Ext(null, Iconable.ICON_FLAG_OPEN);
|
||||
private static final Ext CLOSED_DIR = new Ext(null, Iconable.ICON_FLAG_CLOSED);
|
||||
|
||||
private static final Icon DIR_OPEN_ICON = UIManager.getDefaults().getIcon( "Tree.openIcon" );
|
||||
|
||||
public Icon getIcon(VirtualFile file, final int flags, @Nullable Project project) {
|
||||
if (!isNativeFileType(file)) return null;
|
||||
|
||||
final Ext ext = file.getExtension() != null ? new Ext(file.getExtension()) : NO_EXT;
|
||||
final Ext ext = getExtension(file, flags);
|
||||
final String filePath = file.getPath();
|
||||
|
||||
Icon icon;
|
||||
@@ -70,7 +77,13 @@ public class NativeFileIconProvider implements FileIconProvider {
|
||||
Icon icon;
|
||||
try { // VM will ensure lock to init -static final field--, note we should have no read access here, to avoid deadlock with EDT needed to init component
|
||||
assert SwingComponentHolder.ourFileChooser != null || !ApplicationManager.getApplication().isReadAccessAllowed();
|
||||
icon = SwingComponentHolder.ourFileChooser.getIcon(f);
|
||||
|
||||
if (SystemInfo.isMac && virtualFile.isDirectory() && (flags & Iconable.ICON_FLAG_OPEN) == Iconable.ICON_FLAG_OPEN) {
|
||||
icon = Foundation.isPackageAtPath(f) ? SwingComponentHolder.ourFileChooser.getIcon(f) : DIR_OPEN_ICON;
|
||||
}
|
||||
else {
|
||||
icon = SwingComponentHolder.ourFileChooser.getIcon(f);
|
||||
}
|
||||
}
|
||||
catch (Exception e) { // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4854174
|
||||
return null;
|
||||
@@ -90,6 +103,18 @@ public class NativeFileIconProvider implements FileIconProvider {
|
||||
});
|
||||
}
|
||||
|
||||
private static Ext getExtension(final VirtualFile file, final int flags) {
|
||||
if (file.isDirectory()) {
|
||||
if (file.getExtension() == null) {
|
||||
return flags == Iconable.ICON_FLAG_OPEN ? OPEN_DIR : CLOSED_DIR;
|
||||
} else {
|
||||
return new Ext(file.getExtension(), flags);
|
||||
}
|
||||
}
|
||||
|
||||
return file.getExtension() != null ? new Ext(file.getExtension()) : NO_EXT;
|
||||
}
|
||||
|
||||
static class SwingComponentHolder {
|
||||
private static final JFileChooser ourFileChooser = new JFileChooser();
|
||||
}
|
||||
@@ -99,13 +124,16 @@ public class NativeFileIconProvider implements FileIconProvider {
|
||||
}
|
||||
|
||||
private static class Ext extends ComparableObject.Impl {
|
||||
|
||||
private final Object[] myText;
|
||||
|
||||
private Ext(@Nullable String text) {
|
||||
myText = new Object[] {text};
|
||||
}
|
||||
|
||||
private Ext(@Nullable String text, final int flags) {
|
||||
myText = new Object[] {text, flags};
|
||||
}
|
||||
|
||||
public Object[] getEqualityObjects() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user