diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenInWebAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenInWebAction.java deleted file mode 100644 index 120819ed..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenInWebAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.ide.BrowserUtil; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.manager.ViewManager; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.utils.DataKeys; -import com.shuzijun.leetcode.plugin.utils.URLUtils; -import com.shuzijun.leetcode.plugin.window.WindowFactory; - -import javax.swing.*; - -/** - * @author zzdcon - */ -public class OpenInWebAction extends AbstractAction { - @Override public void actionPerformed(AnActionEvent anActionEvent, Config config) { - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if (question == null) { - return; - } - BrowserUtil.browse(URLUtils.getLeetcodeProblems()+question.getTitleSlug()); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/ResetTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/ResetTimeAction.java deleted file mode 100644 index 359fb427..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/ResetTimeAction.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; - -/** - * @author shuzijun - */ -public class ResetTimeAction extends AbstractTimeAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.reset(); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/RunCodeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/RunCodeAction.java deleted file mode 100644 index 5e5c1499..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/RunCodeAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.utils.DataKeys; -import com.shuzijun.leetcode.plugin.window.WindowFactory; - -import javax.swing.*; - -/** - * @author shuzijun - */ -public class RunCodeAction extends AbstractAsynAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config) { - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if (question == null) { - return; - } - CodeManager.RuncodeCode(question, anActionEvent.getProject()); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/StartTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/StartTimeAction.java deleted file mode 100644 index 5ff4dd3a..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/StartTimeAction.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; - -/** - * @author shuzijun - */ -public class StartTimeAction extends AbstractTimeAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.reset(); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/StopTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/StopTimeAction.java deleted file mode 100644 index 96fd12fa..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/StopTimeAction.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; - -/** - * @author shuzijun - */ -public class StopTimeAction extends AbstractTimeAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.reset(); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/SubmitAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/SubmitAction.java deleted file mode 100644 index a91f0312..00000000 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/SubmitAction.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.shuzijun.leetcode.plugin.actions; - -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; -import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.utils.DataKeys; -import com.shuzijun.leetcode.plugin.window.WindowFactory; - -import javax.swing.*; - -/** - * @author shuzijun - */ -public class SubmitAction extends AbstractAsynAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config) { - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if(question == null){ - return; - } - - CodeManager.SubmitCode(question,anActionEvent.getProject()); - } -} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java similarity index 60% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractTimeAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java index e470ef85..888ecb3e 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/AbstractTimeAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAction.java @@ -1,25 +1,24 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.wm.WindowManager; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; import com.shuzijun.leetcode.plugin.utils.MessageUtils; import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; /** * @author shuzijun */ -public abstract class AbstractTimeAction extends AbstractAsynAction { +abstract class AbstractEditAction extends AbstractAction { @Override - public void perform(AnActionEvent anActionEvent, Config config) { + public void actionPerformed(AnActionEvent anActionEvent, Config config) { VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); if (leetcodeEditor == null) { @@ -30,13 +29,10 @@ public void perform(AnActionEvent anActionEvent, Config config) { MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); return; } - TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); - if (timerBarWidget != null) { - perform(anActionEvent, config, timerBarWidget, question); - } else { - //For possible reasons, the IDE version is not supported - } + + actionPerformed(anActionEvent, config, question); + } - public abstract void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question); + public abstract void actionPerformed(AnActionEvent anActionEvent, Config config, Question question); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAsynAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAsynAction.java new file mode 100644 index 00000000..a6b66039 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/AbstractEditAsynAction.java @@ -0,0 +1,24 @@ +package com.shuzijun.leetcode.plugin.actions.editor; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; + +/** + * @author shuzijun + */ +public abstract class AbstractEditAsynAction extends AbstractEditAction { + + @Override + public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + perform(anActionEvent, config, question); + } + }); + } + + public abstract void perform(AnActionEvent anActionEvent, Config config, Question question); +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/EditorMenuActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java similarity index 94% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/EditorMenuActionGroup.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java index 17b1b2aa..41f584be 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/EditorMenuActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/EditorMenuActionGroup.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenContentAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenContentAction.java index 65014907..a33986b1 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenContentAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenContentAction.java @@ -1,40 +1,19 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.utils.MessageUtils; -import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; /** * @author shuzijun */ -public class OpenContentAction extends AbstractAction { +public class OpenContentAction extends AbstractEditAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - final Editor editor = anActionEvent.getData(CommonDataKeys.EDITOR); - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { Project project = anActionEvent.getProject(); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenInWebAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenInWebAction.java index 956cb467..bd9cbc05 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenInWebAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenInWebAction.java @@ -2,34 +2,17 @@ import com.intellij.ide.BrowserUtil; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAction; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.utils.MessageUtils; -import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; import com.shuzijun.leetcode.plugin.utils.URLUtils; /** * @author zzdcon */ -public class OpenInWebAction extends AbstractAction { +public class OpenInWebAction extends AbstractEditAction { + @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { BrowserUtil.browse(URLUtils.getLeetcodeProblems() + question.getTitleSlug()); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/ResetTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/ResetTimeAction.java index 468fe169..b2860374 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/ResetTimeAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/ResetTimeAction.java @@ -1,7 +1,7 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.actions.AbstractTimeAction; +import com.intellij.openapi.wm.WindowManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; @@ -9,9 +9,15 @@ /** * @author shuzijun */ -public class ResetTimeAction extends AbstractTimeAction { +public class ResetTimeAction extends AbstractEditAsynAction { + @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.reset(); + public void perform(AnActionEvent anActionEvent, Config config, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.reset(); + } else { + //For possible reasons, the IDE version is not supported + } } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/RunCodeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/RunCodeAction.java index e483a3d2..fb6d83ff 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/RunCodeAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/RunCodeAction.java @@ -1,34 +1,17 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAsynAction; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.utils.MessageUtils; -import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; /** * @author shuzijun */ -public class RunCodeAction extends AbstractAsynAction { +public class RunCodeAction extends AbstractEditAsynAction { + @Override - public void perform(AnActionEvent anActionEvent, Config config) { - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } - CodeManager.RuncodeCode(question,anActionEvent.getProject()); + public void perform(AnActionEvent anActionEvent, Config config, Question question) { + CodeManager.RuncodeCode(question, anActionEvent.getProject()); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StartTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StartTimeAction.java index 793c0157..5b57e20f 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StartTimeAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StartTimeAction.java @@ -1,7 +1,7 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.actions.AbstractTimeAction; +import com.intellij.openapi.wm.WindowManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; @@ -9,9 +9,15 @@ /** * @author shuzijun */ -public class StartTimeAction extends AbstractTimeAction { +public class StartTimeAction extends AbstractEditAsynAction { + @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.startTimer(question.getTitle()); + public void perform(AnActionEvent anActionEvent, Config config, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.startTimer(question.getTitle()); + } else { + //For possible reasons, the IDE version is not supported + } } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StopTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StopTimeAction.java index 16cee06b..ba2d7369 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StopTimeAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/StopTimeAction.java @@ -1,7 +1,7 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.actions.AbstractTimeAction; +import com.intellij.openapi.wm.WindowManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; @@ -9,9 +9,15 @@ /** * @author shuzijun */ -public class StopTimeAction extends AbstractTimeAction { +public class StopTimeAction extends AbstractEditAsynAction { + @Override - public void perform(AnActionEvent anActionEvent, Config config, TimerBarWidget timerBarWidget, Question question) { - timerBarWidget.stopTimer(); + public void perform(AnActionEvent anActionEvent, Config config, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.stopTimer(); + } else { + //For possible reasons, the IDE version is not supported + } } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmissionsAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmissionsAction.java index 31bcf91a..6d2b4717 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmissionsAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmissionsAction.java @@ -1,18 +1,10 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.SubmissionManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.model.Submission; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.utils.MessageUtils; -import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; import com.shuzijun.leetcode.plugin.window.SubmissionsPanel; import java.util.List; @@ -20,19 +12,10 @@ /** * @author shuzijun */ -public class SubmissionsAction extends AbstractAction { +public class SubmissionsAction extends AbstractEditAction { + @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { List submissionList = SubmissionManager.getSubmissionService(question, anActionEvent.getProject()); if (submissionList == null || submissionList.isEmpty()) { return; @@ -45,5 +28,4 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) { SubmissionManager.openSubmission(submissionList.get(dialog.getSelectedRow()), question, anActionEvent.getProject()); } } - } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmitAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmitAction.java index 50fc87c7..4b376c7b 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmitAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/SubmitAction.java @@ -1,35 +1,17 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAsynAction; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; -import com.shuzijun.leetcode.plugin.utils.MessageUtils; -import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; /** * @author shuzijun */ -public class SubmitAction extends AbstractAsynAction { - @Override - public void perform(AnActionEvent anActionEvent, Config config) { - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } +public class SubmitAction extends AbstractEditAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, Question question) { CodeManager.SubmitCode(question, anActionEvent.getProject()); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/TestcaseAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/TestcaseAction.java index 7db3a282..daa2f37a 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/TestcaseAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/TestcaseAction.java @@ -1,17 +1,11 @@ package com.shuzijun.leetcode.plugin.actions.editor; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.vfs.VirtualFile; -import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.CodeTypeEnum; import com.shuzijun.leetcode.plugin.model.Config; -import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.setting.PersistentConfig; -import com.shuzijun.leetcode.plugin.setting.ProjectConfig; import com.shuzijun.leetcode.plugin.utils.MessageUtils; import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; import com.shuzijun.leetcode.plugin.window.TestcasePanel; @@ -20,20 +14,9 @@ /** * @author shuzijun */ -public class TestcaseAction extends AbstractAction { +public class TestcaseAction extends AbstractEditAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - - VirtualFile vf = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(anActionEvent.getProject()).getEditor(vf.getPath()); - if (leetcodeEditor == null) { - return; - } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); - if (question == null) { - MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg("info", PropertiesUtils.getInfo("tree.null")); - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { if (StringUtils.isBlank(question.getTestCase())) { String codeType = PersistentConfig.getInstance().getInitConfig().getCodeType(); CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType); @@ -57,5 +40,4 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) { } } - } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/ClearAllAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ClearAllAction.java similarity index 95% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/ClearAllAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ClearAllAction.java index 568180e9..f76dac5d 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/ClearAllAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ClearAllAction.java @@ -1,9 +1,10 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.components.JBPanel; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.setting.PersistentConfig; import com.shuzijun.leetcode.plugin.utils.LogUtils; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/CollapseAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/CollapseAction.java similarity index 86% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/CollapseAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/CollapseAction.java index 41c4c24a..0d30bfaa 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/CollapseAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/CollapseAction.java @@ -1,6 +1,7 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.window.WindowFactory; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/ConfigAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ConfigAction.java similarity index 90% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/ConfigAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ConfigAction.java index 4e5a252c..424839ac 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/ConfigAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/ConfigAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java similarity index 95% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FindAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java index 8b1b67ec..094072d2 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java similarity index 97% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FindActionGroup.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java index 5151639c..f1c142dc 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindActionGroup.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.google.common.collect.Lists; import com.intellij.icons.AllIcons; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindClearAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindClearAction.java similarity index 86% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FindClearAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindClearAction.java index d939c222..0aebc489 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindClearAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindClearAction.java @@ -1,7 +1,8 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.utils.DataKeys; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindConfigAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindConfigAction.java similarity index 94% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FindConfigAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindConfigAction.java index 7556c648..2027a9e2 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindConfigAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindConfigAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindTagAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java similarity index 95% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FindTagAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java index e9368456..0ca72f91 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FindTagAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/FindTagAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/HelpAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/HelpAction.java similarity index 87% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/HelpAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/HelpAction.java index e91b4328..a149770a 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/HelpAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/HelpAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.ide.BrowserUtil; import com.intellij.openapi.actionSystem.AnAction; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/LoginAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LoginAction.java similarity index 97% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/LoginAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LoginAction.java index 751187e1..cf926719 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/LoginAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LoginAction.java @@ -1,7 +1,8 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; +import com.shuzijun.leetcode.plugin.actions.AbstractAsynAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.setting.PersistentConfig; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/LogoutAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LogoutAction.java similarity index 88% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/LogoutAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LogoutAction.java index aa10b1db..0c1d8716 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/LogoutAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/LogoutAction.java @@ -1,6 +1,7 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.actions.AbstractAsynAction; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.utils.HttpClientUtils; import com.shuzijun.leetcode.plugin.utils.MessageUtils; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/PickAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/PickAction.java similarity index 88% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/PickAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/PickAction.java index 6cbc2e4f..b2f34d64 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/PickAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/PickAction.java @@ -1,7 +1,8 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.ui.components.JBScrollPane; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.utils.DataKeys; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/RefreshAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/RefreshAction.java similarity index 85% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/RefreshAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/RefreshAction.java index 5ff9fef6..20356ef1 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/RefreshAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/toolbar/RefreshAction.java @@ -1,6 +1,7 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.toolbar; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.actions.AbstractAsynAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.utils.DataKeys; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAction.java similarity index 57% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/OpenAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAction.java index 3d8af098..8f92a872 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAction.java @@ -1,9 +1,7 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.shuzijun.leetcode.plugin.manager.CodeManager; +import com.shuzijun.leetcode.plugin.actions.AbstractAction; import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; @@ -15,21 +13,19 @@ /** * @author shuzijun */ -public class OpenAction extends AbstractAction { - @Override +public abstract class AbstractTreeAction extends AbstractAction { + public void actionPerformed(AnActionEvent anActionEvent, Config config) { JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); + if (tree == null) { + return; + } Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); if (question == null) { return; } - Project project = anActionEvent.getProject(); - - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - CodeManager.openCode(question, project); - } - }); + actionPerformed(anActionEvent, config, tree, question); } + + public abstract void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAsynAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAsynAction.java new file mode 100644 index 00000000..cd87b6d3 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/AbstractTreeAsynAction.java @@ -0,0 +1,26 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public abstract class AbstractTreeAsynAction extends AbstractTreeAction { + + @Override + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + perform(anActionEvent, config, tree, question); + } + }); + } + + public abstract void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question); +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/ClearOneAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ClearOneAction.java similarity index 70% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/ClearOneAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ClearOneAction.java index dba59bb0..b9c0d000 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/ClearOneAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ClearOneAction.java @@ -1,16 +1,13 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.CodeTypeEnum; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.setting.PersistentConfig; -import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.utils.MessageUtils; import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; import com.shuzijun.leetcode.plugin.utils.VelocityUtils; -import com.shuzijun.leetcode.plugin.window.WindowFactory; import javax.swing.*; import java.io.File; @@ -18,15 +15,9 @@ /** * @author shuzijun */ -public class ClearOneAction extends AbstractAction { +public class ClearOneAction extends AbstractTreeAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if (question == null) { - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { String codeType = config.getCodeType(); CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType); @@ -44,4 +35,5 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) { MessageUtils.getInstance(anActionEvent.getProject()).showInfoMsg(question.getFormTitle(), PropertiesUtils.getInfo("clear.success")); } + } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java similarity index 97% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java index f10ff84b..76f48d85 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteAction.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteActionGroup.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java similarity index 95% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteActionGroup.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java index 9449c8bf..5defd477 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/FavoriteActionGroup.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/FavoriteActionGroup.java @@ -1,4 +1,4 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.google.common.collect.Lists; import com.intellij.openapi.actionSystem.ActionGroup; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenAction.java new file mode 100644 index 00000000..ed285a7e --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenAction.java @@ -0,0 +1,27 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.shuzijun.leetcode.plugin.manager.CodeManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class OpenAction extends AbstractTreeAction { + @Override + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + Project project = anActionEvent.getProject(); + + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + CodeManager.openCode(question, project); + } + }); + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenContentAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java similarity index 56% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/OpenContentAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java index af11747c..718c6b87 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/OpenContentAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java @@ -1,29 +1,21 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; -import com.shuzijun.leetcode.plugin.utils.DataKeys; -import com.shuzijun.leetcode.plugin.window.WindowFactory; import javax.swing.*; /** * @author shuzijun */ -public class OpenContentAction extends AbstractAction { +public class OpenContentAction extends AbstractTreeAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if (question == null) { - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { Project project = anActionEvent.getProject(); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenInWebAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenInWebAction.java new file mode 100644 index 00000000..c0a16ac0 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenInWebAction.java @@ -0,0 +1,20 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; +import com.shuzijun.leetcode.plugin.utils.URLUtils; + +import javax.swing.*; + +/** + * @author zzdcon + */ +public class OpenInWebAction extends AbstractTreeAction { + @Override + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + + BrowserUtil.browse(URLUtils.getLeetcodeProblems() + question.getTitleSlug()); + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ResetTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ResetTimeAction.java new file mode 100644 index 00000000..61c786b3 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/ResetTimeAction.java @@ -0,0 +1,24 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.wm.WindowManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; +import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class ResetTimeAction extends AbstractTreeAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.reset(); + } else { + //For possible reasons, the IDE version is not supported + } + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/RunCodeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/RunCodeAction.java new file mode 100644 index 00000000..4b05b823 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/RunCodeAction.java @@ -0,0 +1,18 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.manager.CodeManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class RunCodeAction extends AbstractTreeAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + CodeManager.RuncodeCode(question, anActionEvent.getProject()); + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StartTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StartTimeAction.java new file mode 100644 index 00000000..317b4413 --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StartTimeAction.java @@ -0,0 +1,24 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.wm.WindowManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; +import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class StartTimeAction extends AbstractTreeAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.startTimer(question.getTitle()); + } else { + //For possible reasons, the IDE version is not supported + } + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StopTimeAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StopTimeAction.java new file mode 100644 index 00000000..d52703da --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/StopTimeAction.java @@ -0,0 +1,24 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.wm.WindowManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; +import com.shuzijun.leetcode.plugin.timer.TimerBarWidget; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class StopTimeAction extends AbstractTreeAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + TimerBarWidget timerBarWidget = (TimerBarWidget) WindowManager.getInstance().getStatusBar(anActionEvent.getProject()).getWidget(TimerBarWidget.ID); + if (timerBarWidget != null) { + timerBarWidget.stopTimer(); + } else { + //For possible reasons, the IDE version is not supported + } + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/SubmissionsAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmissionsAction.java similarity index 64% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/SubmissionsAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmissionsAction.java index 9c348dae..79916e07 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/SubmissionsAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmissionsAction.java @@ -1,14 +1,11 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; import com.shuzijun.leetcode.plugin.manager.SubmissionManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.model.Submission; -import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.window.SubmissionsPanel; -import com.shuzijun.leetcode.plugin.window.WindowFactory; import javax.swing.*; import java.util.List; @@ -16,15 +13,11 @@ /** * @author shuzijun */ -public class SubmissionsAction extends AbstractAction { +public class SubmissionsAction extends AbstractTreeAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if(question == null){ - return; - } - List submissionList = SubmissionManager.getSubmissionService(question,anActionEvent.getProject()); + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + + List submissionList = SubmissionManager.getSubmissionService(question, anActionEvent.getProject()); if (submissionList == null || submissionList.isEmpty()) { return; } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmitAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmitAction.java new file mode 100644 index 00000000..118d8b9b --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/SubmitAction.java @@ -0,0 +1,18 @@ +package com.shuzijun.leetcode.plugin.actions.tree; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.shuzijun.leetcode.plugin.manager.CodeManager; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.Question; + +import javax.swing.*; + +/** + * @author shuzijun + */ +public class SubmitAction extends AbstractTreeAsynAction { + @Override + public void perform(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { + CodeManager.SubmitCode(question, anActionEvent.getProject()); + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/TestcaseAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/TestcaseAction.java similarity index 75% rename from src/main/java/com/shuzijun/leetcode/plugin/actions/TestcaseAction.java rename to src/main/java/com/shuzijun/leetcode/plugin/actions/tree/TestcaseAction.java index 70781207..cd3f5d6a 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/TestcaseAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/TestcaseAction.java @@ -1,17 +1,14 @@ -package com.shuzijun.leetcode.plugin.actions; +package com.shuzijun.leetcode.plugin.actions.tree; import com.intellij.openapi.actionSystem.AnActionEvent; import com.shuzijun.leetcode.plugin.manager.CodeManager; -import com.shuzijun.leetcode.plugin.manager.ViewManager; import com.shuzijun.leetcode.plugin.model.CodeTypeEnum; import com.shuzijun.leetcode.plugin.model.Config; import com.shuzijun.leetcode.plugin.model.Question; import com.shuzijun.leetcode.plugin.setting.PersistentConfig; -import com.shuzijun.leetcode.plugin.utils.DataKeys; import com.shuzijun.leetcode.plugin.utils.MessageUtils; import com.shuzijun.leetcode.plugin.utils.PropertiesUtils; import com.shuzijun.leetcode.plugin.window.TestcasePanel; -import com.shuzijun.leetcode.plugin.window.WindowFactory; import org.apache.commons.lang.StringUtils; import javax.swing.*; @@ -19,15 +16,9 @@ /** * @author shuzijun */ -public class TestcaseAction extends AbstractAction { +public class TestcaseAction extends AbstractTreeAction { @Override - public void actionPerformed(AnActionEvent anActionEvent, Config config) { - - JTree tree = WindowFactory.getDataContext(anActionEvent.getProject()).getData(DataKeys.LEETCODE_PROJECTS_TREE); - Question question = ViewManager.getTreeQuestion(tree, anActionEvent.getProject()); - if (question == null) { - return; - } + public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { if (StringUtils.isBlank(question.getTestCase())) { String codeType = PersistentConfig.getInstance().getInitConfig().getCodeType(); CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType); diff --git a/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java b/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java index fb9902a8..832f7e75 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java @@ -244,6 +244,7 @@ public void apply() { config.setCustomFileName(fileNameEditor.getDocument().getText()); config.setCustomTemplate(templateEditor.getDocument().getText()); config.setLevelColour(LevelColourField.getText()); + config.setEnglishContent(englishContentBox.isSelected()); File file = new File(config.getFilePath() + File.separator + PersistentConfig.PATH + File.separator); if (!file.exists()) { file.mkdirs(); diff --git a/src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java b/src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java index b4c5b339..e6ac27da 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java @@ -76,7 +76,7 @@ public static String getLeetcodeVerify() { } public static String getDescContent() { - if ("leetcode.com".equals(getLeetcodeHost()) && !PersistentConfig.getInstance().getConfig().getEnglishContent()) { + if ("leetcode.com".equals(getLeetcodeHost()) || PersistentConfig.getInstance().getConfig().getEnglishContent()) { return "content"; } else { return "translatedContent"; diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c213800a..0992d233 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -337,62 +337,62 @@ - - - - - - - - - - - - - - - - - @@ -421,19 +421,19 @@ - - - @@ -442,29 +442,29 @@ - - - - - - - - -