Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User can now add custom icons, path ignore regex now works on relative path to project base dir #21

Merged
merged 15 commits into from
Feb 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions src/lermitage/intellij/extra/icons/BaseIconProvider.java
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import com.intellij.ide.IconProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
@@ -17,7 +16,6 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@@ -65,10 +63,8 @@ public final Icon getIcon(@NotNull final PsiElement psiElement, final int flags)
}
final Optional<String> fullPath = getFullPath(psiDirectory);
for (final Model model : models) {
Model editedModel = getEditedModel(project, model);
if (editedModel == null) editedModel = model;
if (editedModel.getModelType() == ModelType.DIR && isModelEnabled(project, editedModel) && editedModel.check(parentName, folderName, fullPath)) {
return InMemoryIconLoader.getIcon(editedModel);
if (model.getModelType() == ModelType.DIR && isModelEnabled(project, model) && model.check(parentName, folderName, fullPath)) {
return InMemoryIconLoader.getIcon(model);
}
}
} else {
@@ -82,10 +78,8 @@ public final Icon getIcon(@NotNull final PsiElement psiElement, final int flags)
}
final Optional<String> fullPath = getFullPath(file);
for (final Model model : models) {
Model editedModel = getEditedModel(project, model);
if (editedModel == null) editedModel = model;
if (editedModel.getModelType() == ModelType.FILE && isModelEnabled(project, editedModel) && editedModel.check(parentName, fileName, fullPath)) {
return InMemoryIconLoader.getIcon(editedModel);
if (model.getModelType() == ModelType.FILE && isModelEnabled(project, model) && model.check(parentName, fileName, fullPath)) {
return InMemoryIconLoader.getIcon(model);
}
}
}
@@ -106,17 +100,6 @@ private boolean isModelEnabled(@Nullable Project project, @NotNull Model model)
return !service.getDisabledModelIds().contains(model.getId());
}

private Model getEditedModel(Project project, Model model) {
SettingsService service = getSettingsService(project);
Optional<Model> editedModel = service.getEditedModels().stream().filter(m -> m.getId().equals(model.getId())).findFirst();
return editedModel.orElse(null);
}

private List<Model> getCustomModels(Project project) {
SettingsService service = getSettingsService(project);
return service.getCustomModels();
}

private SettingsService getSettingsService(Project project) {
SettingsService service = SettingsService.getInstance(project);
if (!((SettingsProjectService) service).isOverrideIDESettings()) {
2 changes: 1 addition & 1 deletion src/lermitage/intellij/extra/icons/Model.java
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ public Model mayEnd(String... extensions) {
}

public Model end(String... extensions) {
getCurrentCondition().setExtensions(extensions);
getCurrentCondition().setEnd(extensions);
return this;
}

118 changes: 112 additions & 6 deletions src/lermitage/intellij/extra/icons/ModelCondition.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package lermitage.intellij.extra.icons;

import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.annotations.OptionTag;
import com.intellij.util.xmlb.annotations.Tag;
import org.intellij.lang.annotations.Language;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -29,6 +28,8 @@ public class ModelCondition {
private boolean checkParent = false;
@OptionTag
private boolean hasRegex = false;
@OptionTag
private boolean enabled = true;

@OptionTag
private String[] names = new String[0];
@@ -60,7 +61,7 @@ public void setMayEnd(String... extensions) {
this.extensions = extensions;
}

public void setExtensions(String... extensions) {
public void setEnd(String... extensions) {
this.end = true;
this.extensions = extensions;
}
@@ -76,9 +77,20 @@ public void setRegex(@Language("RegExp") String regex) {
}

public boolean check(String parentName, String fileName, Optional<String> fullPath) {
if (!enabled) {
return false;
}

if (checkParent) {
if (!parentNames.contains(parentName)) {
return false;
if (!(start || eq || end || mayEnd)) {
if (parentNames.contains(parentName)) {
return true; // To style all files in a subdirectory
}
}
else {
if (!parentNames.contains(parentName)) {
return false;
}
}
}

@@ -164,4 +176,98 @@ public boolean check(String parentName, String fileName, Optional<String> fullPa
}
return false;
}

public boolean hasStart() {
return start;
}

public boolean hasEq() {
return eq;
}

public boolean hasMayEnd() {
return mayEnd;
}

public boolean hasEnd() {
return end;
}

public boolean hasNoDot() {
return noDot;
}

public boolean hasCheckParent() {
return checkParent;
}

public boolean hasRegex() {
return hasRegex;
}

public boolean isEnabled() {
return enabled;
}

public boolean isValid() {
return hasRegex || checkParent || start || eq || end || mayEnd;
}

public String[] getNames() {
return names;
}

public String[] getExtensions() {
return extensions;
}

public Set<String> getParents() {
return parentNames;
}

public String getRegex() {
return regex;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String asReadableString() {
ArrayList<String> parameters = new ArrayList<>();
if (hasRegex) {
parameters.add("regex: " + this.regex);
}

if (checkParent) {
parameters.add("parent(s): " + String.join(",", this.parentNames));
}

if (start || eq) {
String names = String.join(",", this.names);
if (start) {
names = "name starts with: " + names;
if (noDot) {
names += " and does not contain a dot";
}
}
else {
names = "name equals: " + names;
}
parameters.add(names);
}

if (mayEnd || end) {
String extensions = String.join(",", this.extensions);
if (mayEnd) {
extensions = "name may end with: " + extensions;
}
else {
extensions = "name ends with: " + extensions;
}
parameters.add(extensions);
}

return StringUtil.capitalize(String.join(", ", parameters));
}
}
153 changes: 153 additions & 0 deletions src/lermitage/intellij/extra/icons/cfg/ModelConditionDialog.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="lermitage.intellij.extra.icons.cfg.ModelConditionDialog">
<grid id="27dc6" binding="dialogPanel" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="372" height="266"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c7fcc" class="javax.swing.JCheckBox" binding="regexCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Regex:"/>
</properties>
</component>
<component id="32064" class="com.intellij.ui.EditorTextField" binding="regexTextField" custom-create="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-12236470"/>
</properties>
</component>
<component id="d6b43" class="javax.swing.JCheckBox" binding="parentsCheckBox" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Parents:"/>
</properties>
</component>
<component id="36c15" class="javax.swing.JTextField" binding="parentsTextField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="64925" class="javax.swing.JCheckBox" binding="namesCheckBox" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text value="Names:"/>
</properties>
</component>
<component id="baee4" class="javax.swing.JTextField" binding="namesTextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="23608" class="javax.swing.JCheckBox" binding="extensionsCheckBox" default-binding="true">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Extensions:"/>
</properties>
</component>
<component id="a9461" class="javax.swing.JTextField" binding="extensionsTextField">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<grid id="bcc5b" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ec1a0" class="javax.swing.JRadioButton" binding="startsWithRadioButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Starts with"/>
</properties>
</component>
<component id="49101" class="javax.swing.JRadioButton" binding="equalsRadioButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<label value="Equals"/>
<selected value="false"/>
<text value="Equals"/>
</properties>
</component>
</children>
</grid>
<grid id="bbc0d" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8eeef" class="javax.swing.JRadioButton" binding="endsWithRadioButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Ends with"/>
</properties>
</component>
<component id="b4ef" class="javax.swing.JRadioButton" binding="mayEndWithRadioButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="May end with"/>
</properties>
</component>
</children>
</grid>
<component id="dcfb2" class="javax.swing.JCheckBox" binding="noDotCheckBox" default-binding="true">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalAlignment value="11"/>
<horizontalTextPosition value="4"/>
<text value="No dot"/>
<toolTipText value="Checks if file name does not contain a dot."/>
</properties>
</component>
<component id="c1def" class="com.intellij.ui.components.JBLabel" binding="separatorLabel">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentStyle value="SMALL"/>
<fontColor value="BRIGHTER"/>
<text value="Use ... as a separator for multiple values"/>
</properties>
</component>
</children>
</grid>
</form>
Loading