Skip to content

Commit 13d4b77

Browse files
authored
Merge pull request #111 from shuzijun/gradle
1.Add editor menu. 2.Add Bash SQL support. 3.Add English description(leetcode-cn.com). 4.Add timer. 5.Repair notification scope.
2 parents cb655f5 + b1cf09f commit 13d4b77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1363
-421
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
- **Configuration path**: `File` -> `settings`->`tools`->`leetcode plugin`
3737
- **`URL options`**: `leetcode.com`OR`leetcode-cn.com`
38-
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`
38+
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
3939
- **`LoginName`**: Login Username
4040
- **`Password`**: Login password
4141
- **`Temp File Path`**: Temporary file storage catalogue
@@ -80,3 +80,7 @@
8080
- **`Testcase`**:Customize test cases
8181
- **`favorite`**:Add or remove favorite
8282
- **`Clear cache`**:Clean up the current question
83+
- **`Timer`**:Timer, when it is turned on, it will prompt the problem solving time in the status bar in the lower right corner
84+
85+
- **Editor Menu(Right-click on Editor to appear)**:
86+
Function as above

README_ZH.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131

3232
- **配置路径**: `File` -> `settings`->`tools`->`leetcode plugin`
3333
- **`URL可选项`**: `leetcode.com``leetcode-cn.com`
34-
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`
34+
- **`Code Type`**: `Java`,`Python`,`C++`,`Python3`,`C`,`C#`,`JavaScript`,`Ruby`,`Swift`,`Go` ,`Scala`,`Kotlin`,`Rust`,`PHP`,`Bash`,`SQL`
3535
- **`LoginName`**: 登录用户名
3636
- **`Password`**: 登录密码
3737
- **`Temp File Path`**: 临时文件存放目录
3838
- **`proxy(HTTP Proxy)`**: 使用http代理,配置路径:`File` -> `settings`->`Appearance & Behavior`->`System Settings`->`HTTP Proxy`
3939
- **`Custom code template`**: 自定义代码生成模板 ([详细介绍](https://github.com/shuzijun/leetcode-editor/blob/master/doc/CustomCode_ZH.md))([示例](https://github.com/shuzijun/leetcode-question))
40-
- **`LevelColour`**: 自定义题目难度颜色,重启后生效
40+
- **`LevelColour`**: 自定义题目难度颜色,重启后生效
41+
- **`English Content`**: 题目显示英文描述
4142

4243
### 窗口(主窗口右下角![icon](https://raw.githubusercontent.com/shuzijun/leetcode-editor/master/doc/LeetCodeIcon.png))
4344

@@ -76,6 +77,10 @@
7677
- **`Testcase`**:自定义测试用例
7778
- **`favorite`**:添加或移除收藏
7879
- **`Clear cache`**:清理当前题目
80+
- **`Timer`**:计时器,开启后在右下角状态栏提示解题时间
81+
82+
- **Editor菜单(在Editor上右击出现)**:
83+
功能同上
7984

8085
### 常见问题
8186
[常见问题](https://github.com/shuzijun/leetcode-editor/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)

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/actions/AbstractAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class AbstractAction extends AnAction {
2020
public void actionPerformed(AnActionEvent anActionEvent) {
2121
Config config = PersistentConfig.getInstance().getInitConfig();
2222
if (config == null) {
23-
MessageUtils.showWarnMsg("warning", PropertiesUtils.getInfo("config.first"));
23+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("warning", PropertiesUtils.getInfo("config.first"));
2424
ShowSettingsUtil.getInstance().showSettingsDialog(anActionEvent.getProject(), SettingConfigurable.DISPLAY_NAME);
2525
return;
2626
} else if (StringUtils.isBlank(config.getId())) {
@@ -29,13 +29,12 @@ public void actionPerformed(AnActionEvent anActionEvent) {
2929
}
3030

3131
try {
32-
MTAUtils.click(anActionEvent.getActionManager().getId(this),config);
33-
UpdateUtils.examine(config);
34-
}catch (Exception e){
32+
MTAUtils.click(anActionEvent.getActionManager().getId(this), config);
33+
UpdateUtils.examine(config, anActionEvent.getProject());
34+
} catch (Exception e) {
3535
}
3636

3737

38-
3938
actionPerformed(anActionEvent, config);
4039
}
4140

src/main/java/com/shuzijun/leetcode/plugin/actions/ClearAllAction.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,35 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
3030

3131
File file = new File(filePath);
3232
if (!file.exists() || !file.isDirectory()) {
33-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("clear.success"));
33+
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("clear.success"));
3434
return;
3535
}
3636

3737
try {
38-
String[] tempList = file.list();
39-
File temp = null;
40-
for (int i = 0; i < tempList.length; i++) {
41-
if (filePath.endsWith(File.separator)) {
42-
temp = new File(filePath + tempList[i]);
43-
} else {
44-
temp = new File(filePath + File.separator + tempList[i]);
45-
}
46-
if (temp.isFile()) {
47-
temp.delete();
48-
}
49-
}
50-
51-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("clear.success"));
38+
delFile(file);
39+
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("clear.success"));
5240
} catch (Exception ee) {
5341
LogUtils.LOG.error("清理文件错误", ee);
54-
MessageUtils.showErrorMsg("error", PropertiesUtils.getInfo("clear.failed"));
42+
MessageUtils.getInstance(anActionEvent.getProject()).showErrorMsg("error", PropertiesUtils.getInfo("clear.failed"));
5543
}
5644
}
5745

5846
}
5947

48+
public void delFile(File file) {
49+
if (!file.exists()) {
50+
return;
51+
}
52+
53+
if (file.isDirectory()) {
54+
File[] files = file.listFiles();
55+
for (File f : files) {
56+
delFile(f);
57+
}
58+
}
59+
file.delete();
60+
}
61+
6062
private class ClearAllWarningPanel extends DialogWrapper {
6163

6264
private JPanel jpanel;

src/main/java/com/shuzijun/leetcode/plugin/actions/ClearOneAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class ClearOneAction extends AbstractAction {
2323
public void actionPerformed(AnActionEvent anActionEvent, Config config) {
2424

2525
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
26-
Question question = ViewManager.getTreeQuestion(tree);
26+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
2727
if (question == null) {
2828
return;
2929
}
3030

3131
String codeType = config.getCodeType();
3232
CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType);
3333
if (codeTypeEnum == null) {
34-
MessageUtils.showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
34+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("config.code"));
3535
return;
3636
}
3737

@@ -41,7 +41,7 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
4141
if (file.exists()) {
4242
file.delete();
4343
}
44-
MessageUtils.showInfoMsg(question.getFormTitle(), PropertiesUtils.getInfo("clear.success"));
44+
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg(question.getFormTitle(), PropertiesUtils.getInfo("clear.success"));
4545

4646
}
4747
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.shuzijun.leetcode.plugin.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent;
4+
import com.intellij.openapi.actionSystem.DefaultActionGroup;
5+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
6+
import com.intellij.openapi.vfs.VirtualFile;
7+
import com.shuzijun.leetcode.plugin.model.LeetcodeEditor;
8+
import com.shuzijun.leetcode.plugin.setting.ProjectConfig;
9+
10+
/**
11+
* @author shuzijun
12+
*/
13+
public class EditorMenuActionGroup extends DefaultActionGroup {
14+
15+
@Override
16+
public void update(AnActionEvent e) {
17+
VirtualFile vf = e.getData(PlatformDataKeys.VIRTUAL_FILE);
18+
LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(e.getProject()).getEditor(vf.getPath());
19+
boolean menuAllowed = false;
20+
if (leetcodeEditor != null) {
21+
menuAllowed = true;
22+
}
23+
e.getPresentation().setEnabledAndVisible(menuAllowed);
24+
}
25+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public FavoriteAction(@Nullable String text, Tag tag) {
2828
public boolean isSelected(AnActionEvent anActionEvent) {
2929

3030
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
31-
Question question = ViewManager.getTreeQuestion(tree);
31+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
3232
if (question == null) {
3333
return false;
3434
}
@@ -38,14 +38,14 @@ public boolean isSelected(AnActionEvent anActionEvent) {
3838
@Override
3939
public void setSelected(AnActionEvent anActionEvent, boolean b) {
4040
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
41-
Question question = ViewManager.getTreeQuestion(tree);
41+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
4242
if (question == null) {
4343
return;
4444
}
4545
if (b) {
46-
FavoriteManager.addQuestionToFavorite(tag, question);
47-
}else {
48-
FavoriteManager.removeQuestionFromFavorite(tag, question);
46+
FavoriteManager.addQuestionToFavorite(tag, question, anActionEvent.getProject());
47+
} else {
48+
FavoriteManager.removeQuestionFromFavorite(tag, question, anActionEvent.getProject());
4949
}
5050

5151
}

src/main/java/com/shuzijun/leetcode/plugin/actions/LoginAction.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,46 @@ public void perform(AnActionEvent anActionEvent, Config config) {
3030
CloseableHttpResponse response = HttpClientUtils.executeGet(httpget);
3131
httpget.abort();
3232
if (response == null) {
33-
MessageUtils.showWarnMsg("warning", PropertiesUtils.getInfo("request.failed"));
33+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("warning", PropertiesUtils.getInfo("request.failed"));
3434
return;
3535
}
3636
if (response.getStatusLine().getStatusCode() != 200) {
37-
ViewManager.loadServiceData(tree);
38-
MessageUtils.showWarnMsg("warning", PropertiesUtils.getInfo("request.failed"));
37+
ViewManager.loadServiceData(tree, anActionEvent.getProject());
38+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("warning", PropertiesUtils.getInfo("request.failed"));
3939
return;
4040
}
4141
} else {
4242
if (HttpClientUtils.isLogin()) {
43-
MessageUtils.showWarnMsg("info", PropertiesUtils.getInfo("login.exist"));
43+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("login.exist"));
4444
return;
4545
}
4646
}
4747

4848
if (StringUtils.isBlank(config.getLoginName())) {
49-
MessageUtils.showWarnMsg("info", PropertiesUtils.getInfo("config.user"));
49+
MessageUtils.getInstance(anActionEvent.getProject()).showWarnMsg("info", PropertiesUtils.getInfo("config.user"));
5050
return;
5151
}
5252

5353
if (StringUtils.isNotBlank(config.getCookie(config.getUrl() + config.getLoginName()))) {
5454
List<BasicClientCookie> cookieList = CookieUtils.toCookie(config.getCookie(config.getUrl() + config.getLoginName()));
5555
HttpClientUtils.setCookie(cookieList);
5656
if (HttpClientUtils.isLogin()) {
57-
MessageUtils.showInfoMsg("login", PropertiesUtils.getInfo("login.success"));
58-
ViewManager.loadServiceData(tree);
57+
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("login", PropertiesUtils.getInfo("login.success"));
58+
ViewManager.loadServiceData(tree, anActionEvent.getProject());
5959
return;
6060
} else {
6161
config.addCookie(config.getUrl() + config.getLoginName(), null);
6262
PersistentConfig.getInstance().setInitConfig(config);
6363
}
6464
}
6565

66-
LoginFrame loginFrame = new LoginFrame(anActionEvent.getProject(), tree);
66+
6767
if (URLUtils.leetcodecn.equals(URLUtils.getLeetcodeHost())) {
68-
if (!loginFrame.ajaxLogin(config)) {
68+
if (!LoginFrame.httpLogin.ajaxLogin(config, tree, anActionEvent.getProject())) {
6969
ApplicationManager.getApplication().invokeLater(new Runnable() {
7070
@Override
7171
public void run() {
72+
LoginFrame loginFrame = new LoginFrame(anActionEvent.getProject(), tree);
7273
loginFrame.loadComponent();
7374
loginFrame.show();
7475
}
@@ -78,6 +79,7 @@ public void run() {
7879
ApplicationManager.getApplication().invokeLater(new Runnable() {
7980
@Override
8081
public void run() {
82+
LoginFrame loginFrame = new LoginFrame(anActionEvent.getProject(), tree);
8183
loginFrame.loadComponent();
8284
loginFrame.show();
8385
}

src/main/java/com/shuzijun/leetcode/plugin/actions/LogoutAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public void perform(AnActionEvent anActionEvent, Config config) {
2020
CloseableHttpResponse response = HttpClientUtils.executeGet(httpget);
2121
httpget.abort();
2222
HttpClientUtils.resetHttpclient();
23-
MessageUtils.showInfoMsg("info", PropertiesUtils.getInfo("login.out"));
23+
MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("login.out"));
2424
}
2525
}

src/main/java/com/shuzijun/leetcode/plugin/actions/OpenAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class OpenAction extends AbstractAction {
1919
@Override
2020
public void actionPerformed(AnActionEvent anActionEvent, Config config) {
2121
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
22-
Question question = ViewManager.getTreeQuestion(tree);
22+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
2323
if (question == null) {
2424
return;
2525
}

src/main/java/com/shuzijun/leetcode/plugin/actions/OpenContentAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class OpenContentAction extends AbstractAction {
2020
@Override
2121
public void actionPerformed(AnActionEvent anActionEvent, Config config) {
2222
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
23-
Question question = ViewManager.getTreeQuestion(tree);
23+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
2424
if (question == null) {
2525
return;
2626
}

src/main/java/com/shuzijun/leetcode/plugin/actions/OpenInWebAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class OpenInWebAction extends AbstractAction {
1818
@Override public void actionPerformed(AnActionEvent anActionEvent, Config config) {
1919
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
20-
Question question = ViewManager.getTreeQuestion(tree);
20+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
2121
if (question == null) {
2222
return;
2323
}

src/main/java/com/shuzijun/leetcode/plugin/actions/RefreshAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class RefreshAction extends AbstractAsynAction {
1616
public void perform(AnActionEvent anActionEvent, Config config) {
1717

1818
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
19-
ViewManager.loadServiceData(tree);
19+
ViewManager.loadServiceData(tree, anActionEvent.getProject());
2020

2121
}
2222

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.shuzijun.leetcode.plugin.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent;
4+
import com.intellij.openapi.wm.WindowManager;
5+
import com.shuzijun.leetcode.plugin.model.Config;
6+
import com.shuzijun.leetcode.plugin.timer.TimerBarWidget;
7+
8+
/**
9+
* @author shuzijun
10+
*/
11+
public class ResetTimeAction extends AbstractAsynAction {
12+
@Override
13+
public void perform(AnActionEvent anActionEvent, Config config) {
14+
TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID);
15+
timerBarWidget.reset();
16+
}
17+
}

src/main/java/com/shuzijun/leetcode/plugin/actions/RunCodeAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class RunCodeAction extends AbstractAsynAction {
1717
@Override
1818
public void perform(AnActionEvent anActionEvent, Config config) {
1919
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
20-
Question question = ViewManager.getTreeQuestion(tree);
20+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
2121
if (question == null) {
2222
return;
2323
}
24-
CodeManager.RuncodeCode(question);
24+
CodeManager.RuncodeCode(question, anActionEvent.getProject());
2525
}
2626
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.shuzijun.leetcode.plugin.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent;
4+
import com.intellij.openapi.wm.WindowManager;
5+
import com.shuzijun.leetcode.plugin.manager.ViewManager;
6+
import com.shuzijun.leetcode.plugin.model.Config;
7+
import com.shuzijun.leetcode.plugin.model.Question;
8+
import com.shuzijun.leetcode.plugin.timer.TimerBarWidget;
9+
import com.shuzijun.leetcode.plugin.utils.DataKeys;
10+
import com.shuzijun.leetcode.plugin.window.WindowFactory;
11+
12+
import javax.swing.*;
13+
14+
/**
15+
* @author shuzijun
16+
*/
17+
public class StartTimeAction extends AbstractAsynAction {
18+
@Override
19+
public void perform(AnActionEvent anActionEvent, Config config) {
20+
JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE);
21+
Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject());
22+
if (question == null) {
23+
return;
24+
}
25+
TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID);
26+
timerBarWidget.startTimer(question.getTitle());
27+
}
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.shuzijun.leetcode.plugin.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent;
4+
import com.intellij.openapi.wm.WindowManager;
5+
import com.shuzijun.leetcode.plugin.model.Config;
6+
import com.shuzijun.leetcode.plugin.timer.TimerBarWidget;
7+
8+
/**
9+
* @author shuzijun
10+
*/
11+
public class StopTimeAction extends AbstractAsynAction {
12+
@Override
13+
public void perform(AnActionEvent anActionEvent, Config config) {
14+
TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID);
15+
timerBarWidget.stopTimer();
16+
}
17+
}

0 commit comments

Comments
 (0)