Skip to content

Commit 0fea3d2

Browse files
committed
1.0.1: Added logs in Project-view
Signed-off-by: Cybrosis <[email protected]>
1 parent 4741383 commit 0fea3d2

File tree

7 files changed

+221
-7
lines changed

7 files changed

+221
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ will be recognized as log emitters:\
3232

3333
* Comment/uncomment log entry
3434

35+
* \[NEW!\] Logs in Project-view are grouped\
36+
![Project view screenshot](images/project_view.png)
37+
3538
Changelog
3639
------------
40+
* 1.0.1 Added logs in Project-view
3741
* 1.0 Initial release

images/project_view.png

11.8 KB
Loading

src/main/java/com/cybrosis/catdea/icons/CatdeaIcons.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
*/
2626
public class CatdeaIcons {
2727
public static final Icon FILE_TYPE = IconLoader.getIcon("/icons/file.svg");
28+
public static final Icon FOLDER = IconLoader.getIcon("/icons/folder.svg");
2829

29-
public final static class Gutter {
30-
public static final Icon ICON = IconLoader.getIcon("icons/gutter.svg");
31-
public static final Icon NONE = IconLoader.getIcon("icons/gutter_none.svg");
30+
public final static class Gutter {
31+
public static final Icon ICON = IconLoader.getIcon("icons/gutter.svg");
32+
public static final Icon NONE = IconLoader.getIcon("icons/gutter_none.svg");
3233

33-
public static Icon getIcon(boolean isNone) {
34-
return isNone ? NONE : ICON;
35-
}
34+
public static Icon getIcon(boolean isNone) {
35+
return isNone ? NONE : ICON;
3636
}
3737
}
38+
}
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* Copyright 2019 Cybrosis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.cybrosis.catdea.navigator;
18+
19+
import com.android.tools.idea.navigator.AndroidProjectViewPane;
20+
import com.cybrosis.catdea.CatdeaService;
21+
import com.cybrosis.catdea.files.CatdeaFileType;
22+
import com.cybrosis.catdea.icons.CatdeaIcons;
23+
import com.cybrosis.catdea.lang.psi.PsiCatdeaFile;
24+
import com.intellij.ide.projectView.PresentationData;
25+
import com.intellij.ide.projectView.ProjectViewNode;
26+
import com.intellij.ide.projectView.TreeStructureProvider;
27+
import com.intellij.ide.projectView.ViewSettings;
28+
import com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase;
29+
import com.intellij.ide.projectView.impl.ProjectTreeStructure;
30+
import com.intellij.ide.projectView.impl.ProjectViewPane;
31+
import com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode;
32+
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
33+
import com.intellij.ide.util.treeView.AbstractTreeNode;
34+
import com.intellij.openapi.project.Project;
35+
import com.intellij.openapi.vfs.VirtualFile;
36+
import com.intellij.psi.PsiFile;
37+
import com.intellij.psi.PsiManager;
38+
import com.intellij.psi.search.FileTypeIndex;
39+
import com.intellij.psi.search.GlobalSearchScope;
40+
import org.jetbrains.annotations.NotNull;
41+
42+
import javax.swing.*;
43+
import java.util.ArrayList;
44+
import java.util.Collection;
45+
import java.util.Collections;
46+
import java.util.List;
47+
48+
public class CatdeaProjectViewPane extends ProjectViewPane {
49+
public static final String ID = "CatdeaLogs";
50+
51+
public class CatdeaStructureProvider implements TreeStructureProvider {
52+
@NotNull
53+
@Override
54+
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
55+
@NotNull Collection<AbstractTreeNode> children,
56+
ViewSettings settings) {
57+
if (parent instanceof RootNode) return children;
58+
59+
final Project project = parent.getProject();
60+
if (project == null) return children;
61+
62+
final List<AbstractTreeNode> result = new ArrayList<>(children);
63+
64+
if (parent instanceof ProjectViewProjectNode && CatdeaService.getInstance(myProject).available()) {
65+
result.add(new RootNode(project, settings));
66+
return result;
67+
}
68+
69+
result.removeIf(child -> {
70+
return child instanceof PsiFileNode &&
71+
((PsiFileNode) child).getValue() instanceof PsiCatdeaFile;
72+
});
73+
74+
return result;
75+
}
76+
}
77+
78+
private class RootNode extends ProjectViewNode<String> {
79+
RootNode(Project project, ViewSettings viewSettings) {
80+
super(project, "Logs", viewSettings);
81+
}
82+
83+
@Override
84+
public boolean contains(@NotNull VirtualFile file) {
85+
return file.getFileType() instanceof CatdeaFileType;
86+
}
87+
88+
@NotNull
89+
@Override
90+
public Collection<? extends AbstractTreeNode> getChildren() {
91+
final List<AbstractTreeNode> result = new ArrayList<>();
92+
93+
final PsiManager psiManager = PsiManager.getInstance(myProject);
94+
95+
FileTypeIndex.processFiles(
96+
CatdeaFileType.INSTANCE,
97+
file -> {
98+
final PsiFile psiFile = psiManager.findFile(file);
99+
if (psiFile != null) {
100+
result.add(new Node(getProject(), psiFile, getSettings()));
101+
}
102+
return true;
103+
},
104+
GlobalSearchScope.projectScope(myProject)
105+
);
106+
107+
return result;
108+
}
109+
110+
@Override
111+
protected void update(@NotNull PresentationData presentation) {
112+
presentation.setPresentableText(CatdeaProjectViewPane.this.getTitle());
113+
presentation.setIcon(CatdeaProjectViewPane.this.getIcon());
114+
}
115+
}
116+
117+
private static class Node extends PsiFileNode {
118+
Node(Project project, @NotNull PsiFile psiFile, ViewSettings viewSettings) {
119+
super(project, psiFile, viewSettings);
120+
}
121+
122+
@Override
123+
public boolean contains(@NotNull VirtualFile file) {
124+
return false;
125+
}
126+
127+
@Override
128+
public Collection<AbstractTreeNode> getChildrenImpl() {
129+
return Collections.emptyList();
130+
}
131+
132+
@Override
133+
public void update(@NotNull PresentationData presentation) {
134+
presentation.setPresentableText(getValue().getName());
135+
presentation.setIcon(CatdeaIcons.FILE_TYPE);
136+
}
137+
}
138+
139+
140+
public CatdeaProjectViewPane(@NotNull Project project) {
141+
super(project);
142+
}
143+
144+
@NotNull
145+
@Override
146+
public String getTitle() {
147+
return "Catdea Logs";
148+
}
149+
150+
@NotNull
151+
@Override
152+
public Icon getIcon() {
153+
return CatdeaIcons.FOLDER;
154+
}
155+
156+
@NotNull
157+
@Override
158+
public String getId() {
159+
return ID;
160+
}
161+
162+
@SuppressWarnings("DanglingJavadoc")
163+
@Override
164+
public int getWeight() {
165+
/** @see AndroidProjectViewPane#getWeight() */
166+
return 141;
167+
}
168+
169+
@NotNull
170+
@Override
171+
protected ProjectAbstractTreeStructureBase createStructure() {
172+
return new ProjectTreeStructure(myProject, ID) {
173+
@Override
174+
protected AbstractTreeNode createRoot(@NotNull Project project, @NotNull ViewSettings settings) {
175+
return new RootNode(project, settings);
176+
}
177+
};
178+
}
179+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>com.cybrosis.catdea</id>
33
<name>Catdea</name>
4-
<version>1.0</version>
4+
<version>1.0.1</version>
55
<vendor email="[email protected]" url="https://github.com/Cybr0sis/Catdea">Cybrosis</vendor>
66

77
<description><![CDATA[
@@ -12,6 +12,7 @@
1212
]]></description>
1313

1414
<change-notes><![CDATA[
15+
<p>1.0.1: Added logs in Project-view</p>
1516
<p>1.0: Initial release</p>
1617
<ul>
1718
<li>Log files support</li>
@@ -84,6 +85,13 @@
8485

8586
<projectSdkSetupValidator
8687
implementation="com.cybrosis.catdea.validators.CatdeaSdkSetupValidator"/>
88+
89+
<projectViewPane
90+
implementation="com.cybrosis.catdea.navigator.CatdeaProjectViewPane"/>
91+
92+
<treeStructureProvider
93+
order="last"
94+
implementation="com.cybrosis.catdea.navigator.CatdeaProjectViewPane$CatdeaStructureProvider"/>
8795
</extensions>
8896

8997
</idea-plugin>

src/main/resources/icons/folder.svg

Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)