mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
source roots editors: obtain icons for content tree from extension
This commit is contained in:
+18
-3
@@ -28,16 +28,21 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class ContentEntryTreeCellRenderer extends NodeRenderer {
|
||||
protected final ContentEntryTreeEditor myTreeEditor;
|
||||
private final List<ModuleSourceRootEditHandler<?>> myEditHandlers;
|
||||
|
||||
public ContentEntryTreeCellRenderer(@NotNull final ContentEntryTreeEditor treeEditor) {
|
||||
public ContentEntryTreeCellRenderer(@NotNull final ContentEntryTreeEditor treeEditor, List<ModuleSourceRootEditHandler<?>> editHandlers) {
|
||||
myTreeEditor = treeEditor;
|
||||
myEditHandlers = editHandlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +91,7 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer {
|
||||
final SourceFolder[] sourceFolders = entry.getSourceFolders();
|
||||
for (SourceFolder sourceFolder : sourceFolders) {
|
||||
if (file.equals(sourceFolder.getFile())) {
|
||||
return IconSet.getSourceRootIcon(sourceFolder.isTestSource());
|
||||
return IconSet.getSourceRootIcon(sourceFolder.getRootType(), myEditHandlers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +103,20 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer {
|
||||
if (currentRoot != null && VfsUtilCore.isAncestor(sourcePath, currentRoot, false)) {
|
||||
continue;
|
||||
}
|
||||
icon = IconSet.getSourceFolderIcon(sourceFolder.isTestSource());
|
||||
icon = getSourceFolderIcon(sourceFolder.getRootType());
|
||||
currentRoot = sourcePath;
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Icon getSourceFolderIcon(JpsModuleSourceRootType<?> type) {
|
||||
for (ModuleSourceRootEditHandler<?> handler : myEditHandlers) {
|
||||
if (handler.getRootType().equals(type)) {
|
||||
return handler.getFolderUnderRootIcon();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -111,8 +111,12 @@ public class ContentEntryTreeEditor {
|
||||
setupExcludedAction();
|
||||
}
|
||||
|
||||
protected List<ModuleSourceRootEditHandler<?>> getEditHandlers() {
|
||||
return myEditHandlers;
|
||||
}
|
||||
|
||||
protected TreeCellRenderer getContentEntryCellRenderer() {
|
||||
return new ContentEntryTreeCellRenderer(this);
|
||||
return new ContentEntryTreeCellRenderer(this, myEditHandlers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
package com.intellij.openapi.roots.ui.configuration;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -31,7 +34,13 @@ public class IconSet {
|
||||
return isTestSource ? AllIcons.Modules.TestRoot : AllIcons.Modules.SourceRoot;
|
||||
}
|
||||
|
||||
public static Icon getSourceFolderIcon(boolean isTestSource) {
|
||||
return isTestSource ? AllIcons.Modules.TestSourceFolder : AllIcons.Modules.SourceFolder;
|
||||
@Nullable
|
||||
public static Icon getSourceRootIcon(JpsModuleSourceRootType<?> type, List<ModuleSourceRootEditHandler<?>> handlers) {
|
||||
for (ModuleSourceRootEditHandler<?> handler : handlers) {
|
||||
if (handler.getRootType().equals(type)) {
|
||||
return handler.getRootIcon();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.ui.DarculaColors;
|
||||
import com.intellij.ui.JBColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -56,6 +57,12 @@ public class JavaModuleSourceRootEditHandler extends JavaSourceRootEditHandlerBa
|
||||
return AllIcons.Modules.SourceRoot;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getFolderUnderRootIcon() {
|
||||
return AllIcons.Modules.SourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomShortcutSet getMarkRootShortcutSet() {
|
||||
return new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
|
||||
|
||||
+7
@@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.CustomShortcutSet;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -55,6 +56,12 @@ public class JavaTestSourceRootEditHandler extends JavaSourceRootEditHandlerBase
|
||||
return AllIcons.Modules.TestRoot;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getFolderUnderRootIcon() {
|
||||
return AllIcons.Modules.TestSourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomShortcutSet getMarkRootShortcutSet() {
|
||||
return new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK));
|
||||
|
||||
+4
-1
@@ -47,6 +47,9 @@ public abstract class ModuleSourceRootEditHandler<P extends JpsElement> {
|
||||
@NotNull
|
||||
public abstract Icon getRootIcon();
|
||||
|
||||
@Nullable
|
||||
public abstract Icon getFolderUnderRootIcon();
|
||||
|
||||
@Nullable
|
||||
public abstract CustomShortcutSet getMarkRootShortcutSet();
|
||||
|
||||
@@ -56,10 +59,10 @@ public abstract class ModuleSourceRootEditHandler<P extends JpsElement> {
|
||||
@NotNull
|
||||
public abstract Color getRootsGroupColor();
|
||||
|
||||
|
||||
@NotNull
|
||||
public abstract String getUnmarkRootActionName();
|
||||
|
||||
|
||||
@NotNull
|
||||
public abstract P createDefaultProperties();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user