Skip to content

Commit 9a47c12

Browse files
committed
Plugin Constant
1 parent 67d6308 commit 9a47c12

22 files changed

+114
-50
lines changed

src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.openapi.actionSystem.AnActionEvent;
88
import com.shuzijun.leetcode.plugin.manager.ViewManager;
99
import com.shuzijun.leetcode.plugin.model.Constant;
10+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1011
import com.shuzijun.leetcode.plugin.model.Tag;
1112
import com.shuzijun.leetcode.plugin.utils.DataKeys;
1213
import icons.LeetCodeEditorIcons;
@@ -54,7 +55,7 @@ public AnAction[] getChildren(AnActionEvent anActionEvent) {
5455

5556
if (tags != null && !tags.isEmpty()) {
5657
for (Tag tag : tags) {
57-
if ("leetcode.find.Category".equals(id)) {
58+
if (PluginConstant.LEETCODE_FIND_CATEGORY.equals(id)) {
5859
anActionList.add(new FindTagAction(tag.getName(), tag, true));
5960
}else {
6061
anActionList.add(new FindTagAction(tag.getName(), tag));
@@ -68,15 +69,15 @@ public AnAction[] getChildren(AnActionEvent anActionEvent) {
6869

6970
private List<Tag> getTags(String id) {
7071
List<Tag> tags = null;
71-
if ("leetcode.find.Difficulty".equals(id)) {
72+
if (PluginConstant.LEETCODE_FIND_DIFFICULTY.equals(id)) {
7273
tags = ViewManager.getFilter(Constant.FIND_TYPE_DIFFICULTY);
73-
} else if ("leetcode.find.Status".equals(id)) {
74+
} else if (PluginConstant.LEETCODE_FIND_STATUS.equals(id)) {
7475
tags = ViewManager.getFilter(Constant.FIND_TYPE_STATUS);
75-
} else if ("leetcode.find.Lists".equals(id)) {
76+
} else if (PluginConstant.LEETCODE_FIND_LISTS.equals(id)) {
7677
tags = ViewManager.getFilter(Constant.FIND_TYPE_LISTS);
77-
} else if ("leetcode.find.Tags".equals(id)) {
78+
} else if (PluginConstant.LEETCODE_FIND_TAGS.equals(id)) {
7879
tags = ViewManager.getFilter(Constant.FIND_TYPE_TAGS);
79-
} else if ("leetcode.find.Category".equals(id)) {
80+
} else if (PluginConstant.LEETCODE_FIND_CATEGORY.equals(id)) {
8081
tags = ViewManager.getFilter(Constant.FIND_TYPE_CATEGORY);
8182
}
8283

src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.intellij.openapi.progress.ProgressManager;
77
import com.intellij.openapi.progress.Task;
88
import com.shuzijun.leetcode.plugin.manager.ViewManager;
9+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
910
import com.shuzijun.leetcode.plugin.model.Tag;
1011
import com.shuzijun.leetcode.plugin.utils.DataKeys;
1112
import com.shuzijun.leetcode.plugin.window.WindowFactory;
@@ -47,7 +48,7 @@ public void setSelected(AnActionEvent anActionEvent, boolean b) {
4748
return;
4849
}
4950
if (againLoad) {
50-
ProgressManager.getInstance().run(new Task.Backgroundable(anActionEvent.getProject(), "leetcode.editor." + tag.getName(), false) {
51+
ProgressManager.getInstance().run(new Task.Backgroundable(anActionEvent.getProject(), PluginConstant.PLUGIN_NAME+ "." + tag.getName(), false) {
5152
@Override
5253
public void run(@NotNull ProgressIndicator progressIndicator) {
5354
if (b) {

src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/SortAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.shuzijun.leetcode.plugin.manager.ViewManager;
77
import com.shuzijun.leetcode.plugin.model.Config;
88
import com.shuzijun.leetcode.plugin.model.Constant;
9+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
910
import com.shuzijun.leetcode.plugin.model.Sort;
1011
import com.shuzijun.leetcode.plugin.utils.DataKeys;
1112
import com.shuzijun.leetcode.plugin.window.WindowFactory;
@@ -62,6 +63,6 @@ private Sort getSort(AnActionEvent anActionEvent) {
6263
}
6364

6465
private String getKey(AnActionEvent anActionEvent){
65-
return anActionEvent.getActionManager().getId(this).replace("leetcode.sort.","");
66+
return anActionEvent.getActionManager().getId(this).replace(PluginConstant.LEETCODE_SORT_PREFIX,"");
6667
}
6768
}

src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.openapi.progress.Task;
88
import com.shuzijun.leetcode.plugin.manager.FavoriteManager;
99
import com.shuzijun.leetcode.plugin.manager.ViewManager;
10+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1011
import com.shuzijun.leetcode.plugin.model.Question;
1112
import com.shuzijun.leetcode.plugin.model.Tag;
1213
import com.shuzijun.leetcode.plugin.utils.DataKeys;
@@ -47,7 +48,7 @@ public void setSelected(AnActionEvent anActionEvent, boolean b) {
4748
return;
4849
}
4950

50-
ProgressManager.getInstance().run(new Task.Backgroundable(anActionEvent.getProject(),"leetcode.editor.favorite",false) {
51+
ProgressManager.getInstance().run(new Task.Backgroundable(anActionEvent.getProject(), PluginConstant.PLUGIN_NAME + ".favorite",false) {
5152
@Override
5253
public void run(@NotNull ProgressIndicator progressIndicator) {
5354
if (b) {

src/main/java/com/shuzijun/leetcode/plugin/listener/TreeMouseListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.openapi.project.Project;
99
import com.intellij.ui.treeStructure.SimpleTree;
1010
import com.shuzijun.leetcode.plugin.manager.CodeManager;
11+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1112
import com.shuzijun.leetcode.plugin.model.Question;
1213
import org.jetbrains.annotations.NotNull;
1314

@@ -43,12 +44,12 @@ public void mouseClicked(MouseEvent e) {
4344
if (question.isLeaf()) {
4445
if (e.getButton() == 3) { //鼠标右键
4546
final ActionManager actionManager = ActionManager.getInstance();
46-
final ActionGroup actionGroup = (ActionGroup) actionManager.getAction("leetcode.NavigatorActionsMenu");
47+
final ActionGroup actionGroup = (ActionGroup) actionManager.getAction(PluginConstant.LEETCODE_NAVIGATOR_ACTIONS_MENU);
4748
if (actionGroup != null) {
4849
actionManager.createActionPopupMenu("", actionGroup).getComponent().show(e.getComponent(), e.getX(), e.getY());
4950
}
5051
} else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
51-
ProgressManager.getInstance().run(new Task.Backgroundable(project,"leetcode.editor.openCode",false) {
52+
ProgressManager.getInstance().run(new Task.Backgroundable(project,PluginConstant.LEETCODE_EDITOR_OPEN_CODE,false) {
5253
@Override
5354
public void run(@NotNull ProgressIndicator progressIndicator) {
5455
CodeManager.openCode(question, project);

src/main/java/com/shuzijun/leetcode/plugin/listener/TreeWillListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.wm.ToolWindow;
1010
import com.shuzijun.leetcode.plugin.manager.ExploreManager;
1111
import com.shuzijun.leetcode.plugin.model.Constant;
12+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
1213
import com.shuzijun.leetcode.plugin.model.Question;
1314
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
1415
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
@@ -50,7 +51,7 @@ public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
5051
MessageUtils.showMsg(toolWindow.getContentManager().getComponent(), MessageType.INFO, "info", "no permissions");
5152
throw new ExpandVetoException(event);
5253
}
53-
ProgressManager.getInstance().run(new Task.Backgroundable(project,"leetcode.editor.tree",false) {
54+
ProgressManager.getInstance().run(new Task.Backgroundable(project, PluginConstant.LEETCODE_EDITOR_TREE,false) {
5455
@Override
5556
public void run(@NotNull ProgressIndicator progressIndicator) {
5657
loadData(question,node,selPath,tree,toolWindow);

src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.intellij.openapi.progress.ProgressManager;
88
import com.intellij.openapi.progress.Task;
99
import com.intellij.openapi.project.Project;
10-
import com.shuzijun.leetcode.plugin.model.CodeTypeEnum;
11-
import com.shuzijun.leetcode.plugin.model.Config;
12-
import com.shuzijun.leetcode.plugin.model.Constant;
13-
import com.shuzijun.leetcode.plugin.model.Question;
10+
import com.shuzijun.leetcode.plugin.model.*;
1411
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
1512
import com.shuzijun.leetcode.plugin.utils.*;
1613
import org.apache.commons.lang.StringUtils;
@@ -322,7 +319,7 @@ private static class SubmitCheckTask extends Task.Backgroundable {
322319
private Project project;
323320

324321
public SubmitCheckTask(JSONObject returnObj, CodeTypeEnum codeTypeEnum, Question question, Project project) {
325-
super(project,"leetcode.editor.submitCheckTask",true);
322+
super(project,PluginConstant.PLUGIN_NAME + ".submitCheckTask",true);
326323
this.returnObj = returnObj;
327324
this.codeTypeEnum = codeTypeEnum;
328325
this.question = question;
@@ -413,7 +410,7 @@ private static class RunCodeCheckTask extends Task.Backgroundable {
413410
private String input;
414411

415412
public RunCodeCheckTask(JSONObject returnObj, Project project, String input) {
416-
super(project,"leetcode.editor.runCodeCheckTask",true);
413+
super(project, PluginConstant.PLUGIN_NAME+".runCodeCheckTask",true);
417414
this.returnObj = returnObj;
418415
this.project = project;
419416
this.input = input;

src/main/java/com/shuzijun/leetcode/plugin/model/Constant.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
*/
88
public class Constant {
99

10-
public static final String PLUGIN_ID = "leetcode-editor";
11-
/**
12-
* 通知分组
13-
*/
14-
public static final String NOTIFICATION_GROUP = "leetcode editor";
15-
1610
/**
1711
* 题目难度
1812
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.shuzijun.leetcode.plugin.model;
2+
3+
/**
4+
* 插件常量
5+
*
6+
* @author shuzijun
7+
*/
8+
public class PluginConstant {
9+
public static final String WEB_ID = "12132";
10+
public static final String PLUGIN_ID = "leetcode-editor";
11+
public static final String PLUGIN_NAME = "leetcode.editor";
12+
13+
/**
14+
* 通知分组
15+
*/
16+
public static final String NOTIFICATION_GROUP = "leetcode editor";
17+
public static final String TOOL_WINDOW_ID = "leetcode";
18+
19+
/**
20+
* 配置id
21+
*/
22+
public static final String APPLICATION_CONFIGURABLE_ID = "leetcode.id";
23+
24+
/**
25+
* 配置名称
26+
*/
27+
public static final String APPLICATION_CONFIGURABLE_DISPLAY_NAME = "leetcode plugin";
28+
29+
30+
public static final String ACTION_PREFIX = "leetcode";
31+
public static final String ACTION_SUFFIX = "";
32+
33+
public static final String LEETCODE_FIND_CATEGORY = ACTION_PREFIX + ".find.Category";
34+
public static final String LEETCODE_FIND_DIFFICULTY = ACTION_PREFIX + ".find.Difficulty";
35+
public static final String LEETCODE_FIND_STATUS = ACTION_PREFIX + ".find.Status";
36+
public static final String LEETCODE_FIND_LISTS = ACTION_PREFIX + ".find.Lists";
37+
public static final String LEETCODE_FIND_TAGS = ACTION_PREFIX + ".find.Tags";
38+
39+
public static final String LEETCODE_SORT_PREFIX = ACTION_PREFIX + ".sort.";
40+
41+
public static final String LEETCODE_EDITOR_FAVORITE = ACTION_PREFIX + ".editor.favorite";
42+
43+
public static final String LEETCODE_NAVIGATOR_ACTIONS_MENU =ACTION_PREFIX + ".NavigatorActionsMenu";
44+
45+
public static final String LEETCODE_EDITOR_OPEN_CODE = ACTION_PREFIX + ".editor.openCode";
46+
47+
public static final String LEETCODE_EDITOR_TREE = ACTION_PREFIX + ".editor.tree";
48+
49+
public static final String LEETCODE_TIMER_BAR_WIDGET = ACTION_PREFIX + ".TimerBarWidget";
50+
51+
public static final String LEETCODE_NAVIGATOR_ACTIONS_TOOLBAR =ACTION_PREFIX + ".NavigatorActionsToolbar";
52+
public static final String LEETCODE_FIND_TOOLBAR = ACTION_PREFIX + ".find.Toolbar";
53+
54+
public static final String LEETCODE_FIND_SORT_TOOLBAR = ACTION_PREFIX + ".find.SortToolbar";
55+
56+
}

src/main/java/com/shuzijun/leetcode/plugin/setting/PersistentConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.intellij.openapi.components.*;
66
import com.intellij.util.xmlb.XmlSerializerUtil;
77
import com.shuzijun.leetcode.plugin.model.Config;
8+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
89
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
910
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
1011
import org.jetbrains.annotations.NotNull;
@@ -17,7 +18,7 @@
1718
/**
1819
* @author shuzijun
1920
*/
20-
@State(name = "PersistentConfig", storages = {@Storage(value = "leetcode-config.xml", roamingType = RoamingType.DISABLED)})
21+
@State(name = "PersistentConfig" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"-config.xml", roamingType = RoamingType.DISABLED)})
2122
public class PersistentConfig implements PersistentStateComponent<PersistentConfig> {
2223

2324
public static String PATH = "leetcode" + File.separator + "editor";
@@ -69,7 +70,7 @@ public String getTempFilePath() {
6970
public void savePassword(String password) {
7071
try {
7172
PasswordSafe.getInstance().storePassword
72-
(null, this.getClass(), "leetcode-editor", password != null ? password : "");
73+
(null, this.getClass(), PluginConstant.PLUGIN_ID, password != null ? password : "");
7374
} catch (PasswordSafeException exception) {
7475
MessageUtils.showAllWarnMsg("warning", "Failed to save password");
7576
}
@@ -78,7 +79,7 @@ public void savePassword(String password) {
7879
public String getPassword() {
7980
if (getConfig().getVersion() != null) {
8081
try {
81-
return PasswordSafe.getInstance().getPassword(null, this.getClass(), "leetcode-editor");
82+
return PasswordSafe.getInstance().getPassword(null, this.getClass(), PluginConstant.PLUGIN_ID);
8283
} catch (PasswordSafeException exception) {
8384
MessageUtils.showAllWarnMsg("warning", "Password acquisition failed");
8485
return null;

0 commit comments

Comments
 (0)