Skip to content

Commit 6b26919

Browse files
committed
feat: add window icon
1 parent d1ed390 commit 6b26919

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

src/main/java/io/github/linyimin/plugin/compile/MybatisPojoCompile.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import com.intellij.openapi.compiler.CompilerManager;
66
import com.intellij.openapi.project.Project;
77
import com.intellij.openapi.roots.OrderEnumerator;
8+
import com.intellij.openapi.roots.ProjectRootManager;
89
import com.intellij.openapi.ui.Messages;
910
import com.intellij.openapi.util.io.FileUtil;
11+
import com.intellij.openapi.vfs.VirtualFile;
1012
import com.intellij.util.lang.UrlClassLoader;
1113
import io.github.linyimin.plugin.dom.Constant;
1214
import io.github.linyimin.plugin.utils.JavaUtils;
@@ -18,6 +20,7 @@
1820
import java.net.URL;
1921
import java.util.*;
2022
import java.util.stream.Collectors;
23+
import java.util.stream.Stream;
2124

2225

2326
/**
@@ -58,8 +61,8 @@ public static void setClassLoader(Project project) {
5861
changeLoaderUrls(preDependencies, dependencies);
5962
} else {
6063
createProjectLoader(urls);
61-
preDependencies = dependencies;
6264
}
65+
preDependencies = dependencies;
6366
}
6467

6568
private static List<String> getProjectDependencies(Project project) {
@@ -76,15 +79,25 @@ private static List<String> getProjectDependencies(Project project) {
7679
.stream()
7780
.filter(path -> path.contains(Constant.MYBATIS_LOGGING_LOG4J)
7881
|| path.contains(Constant.MYBATIS_LOGGING_SLF4J)
79-
|| path.contains(project.getName())
80-
).collect(Collectors.toList());
82+
|| isProjectModule(project, path))
83+
.collect(Collectors.toList());
8184

8285

8386
list.addAll(mapperDependencies);
8487

8588
return list;
8689
}
8790

91+
private static boolean isProjectModule(Project project, String path) {
92+
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentRootsFromAllModules();
93+
Set<String> moduleNames = Stream.of(vFiles).map(VirtualFile::getName).collect(Collectors.toSet());
94+
95+
moduleNames.add(project.getName());
96+
moduleNames.add(project.getBasePath());
97+
98+
return moduleNames.stream().anyMatch(path::contains);
99+
}
100+
88101
private static void createProjectLoader(List<URL> urls) {
89102
classLoader = UrlClassLoader.build().urls(urls).parent(ClassLoader.getSystemClassLoader()).get();
90103
attachPluginParentLoader(classLoader);
@@ -99,14 +112,12 @@ private static void attachPluginParentLoader(UrlClassLoader classLoader) {
99112

100113
try {
101114
field = pluginClassLoaderClass.getDeclaredField(Constant.PLUGIN_CLASS_LOADER_PARENTS);
102-
} catch (NoSuchFieldException e) {
103-
e.printStackTrace();
115+
} catch (NoSuchFieldException ignored) {
104116
}
105117

106118
try {
107119
field = pluginClassLoaderClass.getDeclaredField(Constant.PLUGIN_CLASS_LOADER_MY_PARENTS);
108-
} catch (NoSuchFieldException e) {
109-
e.printStackTrace();
120+
} catch (NoSuchFieldException ignored) {
110121
}
111122

112123
if (Objects.isNull(field)) {

src/main/java/io/github/linyimin/plugin/view/MyTextField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public MyTextField(Project myProject, Language language, LanguageFileType fileTy
4343
@Override
4444
public void setText(@Nullable String text) {
4545
super.setFileType(fileType);
46-
ReadAction.nonBlocking(() -> {
46+
ReadAction.run(() -> {
4747
Document document = createDocument(text, language, myProject, new SimpleDocumentCreator());
4848
setDocument(document);
4949
PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
@@ -55,7 +55,7 @@ public void setText(@Nullable String text) {
5555
}
5656
);
5757
}
58-
}).executeSynchronously();
58+
});
5959
}
6060

6161
private void setUpEditor(EditorEx editor) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<projectService serviceImplementation="io.github.linyimin.plugin.service.MybatisSqlStateComponent" order="first" />
3030
<projectService serviceImplementation="io.github.linyimin.plugin.service.SqlParamGenerateService" order="first" />
3131

32-
<toolWindow id="mybatis-sql-viewer" doNotActivateOnStart="true" factoryClass="io.github.linyimin.plugin.window.MybatisSqlViewerToolWindowFactory" anchor="right" secondary="false" />
32+
<toolWindow id="mybatis-sql-viewer" icon="/mybatis-sql-viewer.svg" doNotActivateOnStart="true" factoryClass="io.github.linyimin.plugin.window.MybatisSqlViewerToolWindowFactory" anchor="right" secondary="false" />
3333
</extensions>
3434

3535
<actions>
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)