Skip to content

Commit

Permalink
1.3.4:
Browse files Browse the repository at this point in the history
 - 新增方法跳转到视图
 - 增加Class文件显示
 - fix bugs
  • Loading branch information
ZhangYuanSheng1217 committed Apr 28, 2021
1 parent cf93b73 commit d089e4c
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 31 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ publishPlugin {
}

group 'cn.cloud.auto.restful.tool'
version '1.3.3-fix'
version '1.3.4'
patchPluginXml {
changeNotes """
<ul>
<li>fix some bugs</li>
<li>Add method navigation to view</li>
<li>Add Class file display</li>
<li>fix bugs</li>
</ul>
"""
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.restful.tool.actions.copy;

import com.github.restful.tool.utils.Bundle;
import com.github.restful.tool.view.icon.Icons;
import com.github.restful.tool.view.window.RestfulToolWindowFactory;
import com.github.restful.tool.view.window.frame.RightToolWindow;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author ZhangYuanSheng
* @version 1.0
*/
public class NavigationServiceTreeAction extends AnAction implements CopyOption {

private RightToolWindow toolWindow;

public NavigationServiceTreeAction() {
getTemplatePresentation().setText(Bundle.getString("action.NavigateToView.text"));
getTemplatePresentation().setIcon(Icons.Plugin);
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
PsiMethod psiMethod = getPsiMethod(e);
if (psiMethod == null) {
return;
}
if (getToolWindow(e.getProject()) == null) {
return;
}
toolWindow.navigationToView(psiMethod);
}

private RightToolWindow getToolWindow(@Nullable Project project) {
if (toolWindow != null) {
return toolWindow;
}
return (toolWindow = RestfulToolWindowFactory.getToolWindow(project, true));
}
}
72 changes: 72 additions & 0 deletions src/main/java/com/github/restful/tool/beans/ClassTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright (C), 2018-2020, ZhangYuanSheng
FileName: ModuleTree
Author: ZhangYuanSheng
Date: 2020/8/25 16:48
Description:
History:
<author> <time> <version> <desc>
作者姓名 修改时间 版本号 描述
*/
package com.github.restful.tool.beans;

import com.intellij.icons.AllIcons;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
* @author ZhangYuanSheng
* @version 1.0
*/
public class ClassTree {

private final PsiClass psiClass;

/**
* 图标
*/
private final Icon icon;

public ClassTree(@NotNull PsiClass psiClass) {
this.psiClass = psiClass;
this.icon = AllIcons.FileTypes.Java;
}

public ClassTree(@NotNull PsiClass psiClass, Icon icon) {
this.psiClass = psiClass;
this.icon = icon;
}

public NavigatablePsiElement getPsiClass() {
return psiClass;
}

public Icon getIcon() {
return icon;
}

public String getQualifiedName() {
return psiClass.getQualifiedName();
}

public String getName() {
return psiClass.getName();
}

public String getSimpleName() {
String[] split = getQualifiedName().split("\\.");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < split.length - 1; i++) {
sb.append(split[i].charAt(0)).append(".");
}
return sb.append(split[split.length - 1]).toString();
}

@Override
public String toString() {
return getSimpleName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public static class SystemOptionForm extends OptionForm {
false
);

public static final SettingKey<Boolean> SHOW_CLASS_SERVICE_TREE = SettingKey.createCheckBox(
Bundle.getString("setting.system.ShowClassServiceTreeByDefault"),
true
);

public SystemOptionForm() {
super(Bundle.getString("setting.system"), 0);
}
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/com/github/restful/tool/utils/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;

import java.util.Locale;
import java.util.ResourceBundle;

/**
* @author ZhangYuanSheng
* @version 1.0
Expand All @@ -26,20 +29,9 @@ public class Bundle extends AbstractBundle {

@NonNls
public static final String BUNDLE = "messages.RestfulToolBundle";
@NonNls
public static final String BUNDLE_ZH = "messages.RestfulToolBundleZh";

@NotNull
private static final Bundle INSTANCE;

static {
final String chineseLanguagePlugin = "com.intellij.zh";
if (PluginManager.isPluginInstalled(PluginId.getId(chineseLanguagePlugin))) {
INSTANCE = new Bundle(BUNDLE_ZH);
} else {
INSTANCE = new Bundle(BUNDLE);
}
}
private static final Bundle INSTANCE = new Bundle(BUNDLE);

private Bundle(@NonNls String resource) {
super(resource);
Expand All @@ -56,4 +48,16 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, O
public static String getString(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return message(key, params);
}

@Override
protected ResourceBundle findBundle(@NotNull @NonNls String pathToBundle,
@NotNull ClassLoader loader,
@NotNull ResourceBundle.Control control) {
final String chineseLanguagePlugin = "com.intellij.zh";
if (!PluginManager.isPluginInstalled(PluginId.getId(chineseLanguagePlugin))) {
// 未安装 IDE中文语言包 插件则使用默认
return ResourceBundle.getBundle(pathToBundle, Locale.ROOT, loader, control);
}
return ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader, control);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/github/restful/tool/view/icon/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public class Icons {

public static Icon Plugin = load("/META-INF/pluginIcon.svg");

@NotNull
public static Icon load(@NotNull String path) {
return IconManager.getInstance().getIcon(path, Icons.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,55 @@ public class RestfulToolWindowFactory implements ToolWindowFactory {
*/
@Nullable
public static RightToolWindow getToolWindow(@Nullable Project project) {
return getToolWindow(project, null);
}

/**
* 获取RestfulTool的toolWindow窗口内容
*
* @param project auto
* @return RightToolWindow
*/
@Nullable
public static RightToolWindow getToolWindow(@Nullable Project project, Boolean show) {
if (project == null) {
return null;
}
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
if (toolWindow == null) {
return null;
ToolWindow toolWindow = getWindow(project);
if (show != null && show) {
showWindow(project, null);
}
for (Component component : toolWindow.getComponent().getComponents()) {
if (component instanceof RightToolWindow) {
return ((RightToolWindow) component);
if (toolWindow != null) {
for (Component component : toolWindow.getComponent().getComponents()) {
if (component instanceof RightToolWindow) {
return ((RightToolWindow) component);
}
}
}
return null;
}

@Nullable
public static ToolWindow getWindow(@NotNull Project project) {
return ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
}

public static void showWindow(@NotNull Project project, @Nullable Runnable onShow) {
ToolWindow window = getWindow(project);
if (window == null) {
return;
}
window.show(onShow);
}

public static void hideWindow(@NotNull Project project, @Nullable Runnable onShow) {
ToolWindow window = getWindow(project);
if (window == null) {
return;
}
window.hide(onShow);
}

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ToolWindowService.getInstance(project).init(toolWindow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
*/
package com.github.restful.tool.view.window;

import com.github.restful.tool.beans.ClassTree;
import com.github.restful.tool.beans.ModuleTree;
import com.github.restful.tool.beans.Request;
import com.github.restful.tool.view.window.frame.ServiceTree;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -41,6 +43,12 @@ public void customizeCellRenderer(
ServiceTree.RequestNode node = (ServiceTree.RequestNode) value;
Request data = node.getData();
setMethodTypeAndPath(data, selected);
} else if (value instanceof ServiceTree.ControllerNode) {
ServiceTree.ControllerNode node = (ServiceTree.ControllerNode) value;
ClassTree data = node.getData();
setIcon(data.getIcon());
append(data.getName());
append(" - " + data.getQualifiedName(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
} else if (value instanceof ServiceTree.TreeNode<?>) {
ServiceTree.TreeNode<?> node = (ServiceTree.TreeNode<?>) value;
append(node.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiMethod;
import com.intellij.ui.JBSplitter;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -114,4 +115,8 @@ public void refreshRequestTree() {
// 清除扫描的pom文件缓存
PomUtil.clearCaches();
}

public void navigationToView(@NotNull PsiMethod psiMethod) {
RestfulToolWindowFactory.showWindow(project, () -> serviceTree.navigationToTree(psiMethod));
}
}
Loading

0 comments on commit d089e4c

Please sign in to comment.