Skip to content

Commit b2a0e6d

Browse files
committed
Increase editor configuration
1 parent 1512537 commit b2a0e6d

File tree

5 files changed

+142
-25
lines changed

5 files changed

+142
-25
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.shuzijun.leetcode'
8-
version "6.0" + (project.build_env.isEmpty() ? "" : "-") + project.build_env
8+
version "6.1" + (project.build_env.isEmpty() ? "" : "-") + project.build_env
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import com.intellij.openapi.project.Project;
88
import com.intellij.openapi.vfs.LocalFileSystem;
99
import com.intellij.openapi.vfs.VirtualFile;
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;
12+
import com.shuzijun.leetcode.plugin.setting.ProjectConfig;
1513
import com.shuzijun.leetcode.plugin.utils.*;
1614
import org.apache.commons.lang.StringUtils;
1715
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -54,6 +52,8 @@ public static void openCode(Question question, Project project) {
5452
VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
5553
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vf);
5654
FileEditorManager.getInstance(project).openTextEditor(descriptor, false);
55+
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getDefEditor(vf.getPath());
56+
leetcodeEditor.setQuestionId(question.getQuestionId());
5757
} else {
5858

5959
if (getQuestion(question, codeTypeEnum)) {
@@ -63,6 +63,8 @@ public static void openCode(Question question, Project project) {
6363
VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
6464
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vf);
6565
FileEditorManager.getInstance(project).openTextEditor(descriptor, false);
66+
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getDefEditor(vf.getPath());
67+
leetcodeEditor.setQuestionId(question.getQuestionId());
6668
}
6769
}
6870
}
@@ -179,7 +181,7 @@ public static void SubmitCode(Question question) {
179181
JSONObject returnObj = JSONObject.parseObject(body);
180182
cachedThreadPool.execute(new SubmitCheckTask(returnObj, codeTypeEnum, question));
181183
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("request.pending"));
182-
}else if(response != null && response.getStatusLine().getStatusCode() == 429){
184+
} else if (response != null && response.getStatusLine().getStatusCode() == 429) {
183185
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("request.pending"));
184186
} else {
185187
LogUtils.LOG.error("提交失败:url:" + post.getURI().getPath() + ";param:" + arg.toJSONString() + ";body:" + EntityUtils.toString(response.getEntity(), "UTF-8"));
@@ -386,8 +388,8 @@ public void run() {
386388
String input = jsonObject.getString("input");
387389
String output = jsonObject.getString("code_output");
388390
String expected = jsonObject.getString("expected_output");
389-
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"),"\n\t\t");
390-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.failed", input, output, expected,outputs));
391+
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"), "\n\t\t");
392+
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.failed", input, output, expected, outputs));
391393

392394
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.failed", input, output, expected));
393395
if (!"ac".equals(question.getStatus())) {
@@ -396,8 +398,8 @@ public void run() {
396398
}
397399
}
398400
} else {
399-
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"),"\n\t\t");
400-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.run.failed", buildErrorMsg(jsonObject),outputs));
401+
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"), "\n\t\t");
402+
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.run.failed", buildErrorMsg(jsonObject), outputs));
401403
if (!"ac".equals(question.getStatus())) {
402404
question.setStatus("notac");
403405
ViewManager.updateStatus();
@@ -446,7 +448,7 @@ public RunCodeCheckTask(JSONObject returnObj) {
446448
@Override
447449
public void run() {
448450
String key = returnObj.getString("interpret_expected_id");
449-
if(StringUtils.isBlank(key)){
451+
if (StringUtils.isBlank(key)) {
450452
key = returnObj.getString("interpret_id");
451453
}
452454
for (int i = 0; i < 50; i++) {
@@ -471,11 +473,11 @@ public void run() {
471473
} else if (jsonObject.getJSONArray("expected_code_answer") != null && !jsonObject.getJSONArray("expected_code_answer").isEmpty()) {
472474
expected = jsonObject.getJSONArray("expected_code_answer").getString(0);
473475
}
474-
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"),"\n\t\t");
475-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("test.success", input, output, expected,outputs));
476+
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"), "\n\t\t");
477+
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("test.success", input, output, expected, outputs));
476478
} else {
477-
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"),"\n\t\t");
478-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.run.failed", buildErrorMsg(jsonObject),outputs));
479+
String outputs = StringUtils.join(jsonObject.getJSONArray("code_output"), "\n\t\t");
480+
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("submit.run.failed", buildErrorMsg(jsonObject), outputs));
479481
}
480482
return;
481483
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.shuzijun.leetcode.plugin.model;
2+
3+
/**
4+
* @author shuzijun
5+
*/
6+
public class LeetcodeEditor {
7+
8+
private Integer version = 1;
9+
10+
/**
11+
* file path
12+
*/
13+
private String path;
14+
15+
/**
16+
* questionId
17+
*/
18+
private String questionId;
19+
20+
public Integer getVersion() {
21+
return version;
22+
}
23+
24+
public void setVersion(Integer version) {
25+
this.version = version;
26+
}
27+
28+
public String getPath() {
29+
return path;
30+
}
31+
32+
public void setPath(String path) {
33+
this.path = path;
34+
}
35+
36+
public String getQuestionId() {
37+
return questionId;
38+
}
39+
40+
public void setQuestionId(String questionId) {
41+
this.questionId = questionId;
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.shuzijun.leetcode.plugin.setting;
2+
3+
import com.intellij.openapi.components.*;
4+
import com.intellij.openapi.project.Project;
5+
import com.intellij.util.xmlb.annotations.MapAnnotation;
6+
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
/**
14+
* @author shuzijun
15+
*/
16+
@State(name = "LeetcodeEditor", storages = {@Storage(value = "leetcode/editor.xml")})
17+
public class ProjectConfig implements ProjectComponent, PersistentStateComponent<ProjectConfig.InnerState> {
18+
19+
public ProjectConfig(Project project) {
20+
21+
}
22+
23+
@Nullable
24+
public static ProjectConfig getInstance(Project project) {
25+
// return project.getComponent(ProjectConfig.class);
26+
return ServiceManager.getService(project, ProjectConfig.class);
27+
}
28+
29+
private InnerState innerState = new InnerState();
30+
31+
@Nullable
32+
@Override
33+
public ProjectConfig.InnerState getState() {
34+
return innerState;
35+
}
36+
37+
@Override
38+
public void loadState(@NotNull ProjectConfig.InnerState innerState) {
39+
this.innerState = innerState;
40+
}
41+
42+
43+
public LeetcodeEditor getDefEditor(String path) {
44+
LeetcodeEditor leetcodeEditor = innerState.projectConfig.get(path);
45+
if (leetcodeEditor == null) {
46+
leetcodeEditor = new LeetcodeEditor();
47+
leetcodeEditor.setPath(path);
48+
innerState.projectConfig.put(path, leetcodeEditor);
49+
}
50+
return leetcodeEditor;
51+
}
52+
53+
public LeetcodeEditor getEditor(String path) {
54+
return innerState.projectConfig.get(path);
55+
}
56+
57+
public static class InnerState {
58+
@NotNull
59+
@MapAnnotation
60+
public Map<String, LeetcodeEditor> projectConfig;
61+
62+
InnerState() {
63+
projectConfig = new HashMap<>();
64+
}
65+
}
66+
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>leetcode-editor</id>
33
<name>leetcode editor</name>
4-
<version>6.0</version>
4+
<version>6.1</version>
55
<vendor email="shuzijun0109@gmail.com" url="https://github.com/shuzijun/idea-leetcode-plugin">shuzijun</vendor>
66

77
<description><![CDATA[
@@ -297,12 +297,14 @@
297297
</application-components>
298298

299299
<extensions defaultExtensionNs="com.intellij">
300-
<!-- <postStartupActivity implementation = "com.shuzijun.leetcode.plugin.listener.RegisterPluginInstallerStateListener"></postStartupActivity>-->
300+
<!-- <postStartupActivity implementation = "com.shuzijun.leetcode.plugin.listener.RegisterPluginInstallerStateListener"></postStartupActivity>-->
301301
<errorHandler implementation="com.shuzijun.leetcode.plugin.listener.ErrorReportHandler"/>
302302
<toolWindow id="leetcode" secondary="true" icon="/image/LeetCodeIcon.png" anchor="right"
303303
factoryClass="com.shuzijun.leetcode.plugin.window.WindowFactory"/>
304304
<applicationService serviceInterface="com.shuzijun.leetcode.plugin.setting.PersistentConfig"
305305
serviceImplementation="com.shuzijun.leetcode.plugin.setting.PersistentConfig"/>
306+
<projectService serviceInterface="com.shuzijun.leetcode.plugin.setting.ProjectConfig"
307+
serviceImplementation="com.shuzijun.leetcode.plugin.setting.ProjectConfig"/>
306308
<applicationConfigurable groupId="tools" displayName="leetcode plugin" id="leetcode.id"
307309
instance="com.shuzijun.leetcode.plugin.setting.SettingConfigurable"/>
308310
</extensions>
@@ -327,11 +329,11 @@
327329
text="Clear cache" description="Clear cache" icon="AllIcons.Process.StopHovered">
328330
</action>
329331
<action id="leetcode.CollapseAction" class="com.shuzijun.leetcode.plugin.actions.CollapseAction"
330-
text="Collapse All" description="Collapse All" icon="AllIcons.Actions.Collapseall">
332+
text="Collapse All" description="Collapse All" icon="AllIcons.Actions.Collapseall">
331333
</action>
332334

333335
<action id="leetcode.HelpAction" class="com.shuzijun.leetcode.plugin.actions.HelpAction"
334-
text="Help" description="Help" icon="AllIcons.Actions.Help">
336+
text="Help" description="Help" icon="AllIcons.Actions.Help">
335337
</action>
336338

337339
<action id="leetcode.OpenAction" class="com.shuzijun.leetcode.plugin.actions.OpenAction"
@@ -394,26 +396,30 @@
394396
<reference id="leetcode.TestcaseAction"/>
395397
<separator/>
396398
<group id="leetcode.FavoriteGroup" class="com.shuzijun.leetcode.plugin.actions.FavoriteActionGroup"
397-
popup="true" text="Favorite" description="Favorite" icon="AllIcons.Actions.Menu_open">
399+
popup="true" text="Favorite" description="Favorite" icon="AllIcons.Actions.Menu_open">
398400
</group>
399401
<reference id="leetcode.ClearOneAction"/>
400402
</group>
401403

402404
<group id="leetcode.find.Toolbar" popup="true" text="Status" description="Status">
403-
<group id="leetcode.find.Difficulty" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true" text="Difficulty" description="Difficulty">
405+
<group id="leetcode.find.Difficulty" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup"
406+
popup="true" text="Difficulty" description="Difficulty">
404407
</group>
405-
<group id="leetcode.find.Status" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true" text="Status" description="Status">
408+
<group id="leetcode.find.Status" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true"
409+
text="Status" description="Status">
406410
</group>
407-
<group id="leetcode.find.Lists" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true" text="Lists" description="Lists">
411+
<group id="leetcode.find.Lists" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true"
412+
text="Lists" description="Lists">
408413
</group>
409-
<group id="leetcode.find.Tags" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true" text="Tags" description="Tags">
414+
<group id="leetcode.find.Tags" class="com.shuzijun.leetcode.plugin.actions.FindActionGroup" popup="true"
415+
text="Tags" description="Tags">
410416
</group>
411417
<separator/>
412418
<action id="leetcode.find.Clear" class="com.shuzijun.leetcode.plugin.actions.FindClearAction"
413419
text="Clear find" description="Clear find " icon="AllIcons.Process.StopHovered">
414420
</action>
415421
<action id="leetcode.find.Config" class="com.shuzijun.leetcode.plugin.actions.FindConfigAction"
416-
text="" description="find intersection" >
422+
text="" description="find intersection">
417423
</action>
418424
</group>
419425

0 commit comments

Comments
 (0)