diff --git a/build.gradle b/build.gradle index 5735e127..9af7f48c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,46 +1,46 @@ plugins { - id 'java' - id 'org.jetbrains.intellij' version '0.4.16' + id 'java-library' + id 'org.jetbrains.intellij' version '1.0' id "de.undercouch.download" version "4.0.2" } group 'com.shuzijun.leetcode' -version (System.getenv('LD_VERSION')==null ? "6.9":System.getenv('LD_VERSION')) + (project.build_env.isEmpty() ? "" : "-") + project.build_env +version (System.getenv('LD_VERSION')==null ? project.plugin_version :System.getenv('LD_VERSION')) + (project.build_env.isEmpty() ? "" : "-") + project.build_env -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 11 +targetCompatibility = 11 repositories { mavenCentral() } dependencies { - compile 'com.alibaba:fastjson:1.2.47' - compile 'org.jsoup:jsoup:1.11.3' - compile('io.sentry:sentry:1.7.9') { + api 'com.alibaba:fastjson:1.2.47' + api 'org.jsoup:jsoup:1.11.3' + api('io.sentry:sentry:1.7.9') { exclude module: 'slf4j-api' } - compile 'org.scilab.forge:jlatexmath:1.0.7' - compile 'org.apache.commons:commons-lang3:3.9' - //compile fileTree(dir: 'src/main/resources/lib', include: ['*.jar']) + api 'org.scilab.forge:jlatexmath:1.0.7' + api 'org.apache.commons:commons-lang3:3.9' + //api fileTree(dir: 'src/main/resources/lib', include: ['*.jar']) } // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - pluginName 'leetcode-editor' - version '2020.2' - type 'IU' - downloadSources false - updateSinceUntilBuild false - buildSearchableOptions.enabled(false) - /* updateSinceUntilBuild false - localPath project.idea_local_path + pluginName = 'leetcode-editor' + version = project.intellij_version + type = 'IU' + downloadSources = true + updateSinceUntilBuild = false + buildSearchableOptions.enabled = false + ideaDependencyCachePath = "$gradle.gradleUserHomeDir/caches/modules-2/files-2.1/com.jetbrains.intellij.idea" + /* localPath project.idea_local_path alternativeIdePath project.idea_local_path*/ - - prepareSandbox { + plugins = project.intellij_plugins.split(",").toList() +/* prepareSandbox { from("src/main/natives" + (project.build_env.isEmpty() ? "" : "-") + project.build_env) { into(getPluginName() + '/natives') } - } + }*/ } diff --git a/gradle.properties b/gradle.properties index 8ed1f1eb..85189b0c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ +plugin_version = 2021.1.0 idea_local_path = # '' | windows | mac | linux build_env = jcef_version = v6.0-jcef-beta.1 - +intellij_version = 2021.1 +intellij_plugins = org.intellij.plugins.markdown:211.6693.44 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cb..7454180f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5028f28f..69a97150 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index af6708ff..744e882e 100644 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -56,7 +72,7 @@ case "`uname`" in Darwin* ) darwin=true ;; - MINGW* ) + MSYS* | MINGW* ) msys=true ;; NONSTOP* ) @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 6d57edc7..107acd32 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell 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 38c5a1f1..a90d51be 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 @@ -14,7 +14,7 @@ public class OpenContentAction extends AbstractEditAction { @Override public void actionPerformed(AnActionEvent anActionEvent, Config config, Question question) { Project project = anActionEvent.getProject(); - CodeManager.openContent(question, project); + CodeManager.openContent(question, project, true); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java index 097d37d2..0cd5ce0a 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/editor/OpenSolutionAction.java @@ -30,7 +30,7 @@ public void update(@NotNull AnActionEvent anActionEvent) { if (leetcodeEditor == null) { return; } - Question question = ViewManager.getQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); + Question question = ViewManager.getDumbQuestionById(leetcodeEditor.getQuestionId(), anActionEvent.getProject()); if (question == null) { anActionEvent.getPresentation().setEnabled(false); return; diff --git a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java index d4dc3be2..72ff6ac1 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/actions/tree/OpenContentAction.java @@ -16,6 +16,6 @@ public class OpenContentAction extends AbstractTreeAction { @Override public void actionPerformed(AnActionEvent anActionEvent, Config config, JTree tree, Question question) { Project project = anActionEvent.getProject(); - CodeManager.openContent(question, project); + CodeManager.openContent(question, project, true); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorProvider.java b/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorProvider.java new file mode 100644 index 00000000..4ff01b2b --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorProvider.java @@ -0,0 +1,70 @@ +package com.shuzijun.leetcode.plugin.editor; + +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorProvider; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.shuzijun.leetcode.plugin.model.Config; +import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; +import com.shuzijun.leetcode.plugin.setting.PersistentConfig; +import com.shuzijun.leetcode.plugin.setting.ProjectConfig; +import org.apache.commons.lang3.StringUtils; +import org.intellij.plugins.markdown.ui.preview.MarkdownPreviewFileEditorProvider; +import org.intellij.plugins.markdown.ui.split.SplitTextEditorProvider; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +/** + * @author shuzijun + */ +public class QuestionEditorProvider extends SplitTextEditorProvider { + + + + public QuestionEditorProvider() { + super(new PsiAwareTextEditorProvider(), new MarkdownPreviewFileEditorProvider()); + } + + @Override + public boolean accept(@NotNull Project project, @NotNull VirtualFile file) { + Config config = PersistentConfig.getInstance().getInitConfig(); + if(config == null || !config.getQuestionEditor()){ + return false; + } + LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getEditor(file.getPath()); + if(leetcodeEditor == null || StringUtils.isBlank(leetcodeEditor.getContentPath())){ + return false; + } + + return this.myFirstProvider.accept(project, file); + } + @Override + public Builder createEditorAsync(@NotNull Project project, @NotNull VirtualFile file) { + LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getEditor(file.getPath()); + + final Builder firstBuilder = getBuilderFromEditorProvider(this.myFirstProvider, project, file); + + VirtualFile contentVf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(leetcodeEditor.getContentPath())); + final Builder secondBuilder = getBuilderFromEditorProvider(this.mySecondProvider, project, contentVf); + return new Builder() { + public FileEditor build() { + return createSplitEditor(firstBuilder.build(), secondBuilder.build()); + } + }; + } + + @Override + protected FileEditor createSplitEditor(@NotNull FileEditor firstEditor, @NotNull FileEditor secondEditor) { + + //if (firstEditor instanceof TextEditor && secondEditor instanceof MarkdownSplitEditor) { + return new QuestionEditorWithPreview((TextEditor)firstEditor, secondEditor); + //} else { + // throw new IllegalArgumentException("Main editor should be TextEditor"); + //} + } + + +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorWithPreview.java b/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorWithPreview.java new file mode 100644 index 00000000..d410b79f --- /dev/null +++ b/src/main/java/com/shuzijun/leetcode/plugin/editor/QuestionEditorWithPreview.java @@ -0,0 +1,40 @@ +package com.shuzijun.leetcode.plugin.editor; + +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileEditor; +import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.fileEditor.TextEditorWithPreview; +import com.intellij.openapi.util.Key; +import com.shuzijun.leetcode.plugin.model.PluginConstant; +import org.intellij.plugins.markdown.ui.preview.MarkdownPreviewFileEditor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Method; + +/** + * @author shuzijun + */ +public class QuestionEditorWithPreview extends TextEditorWithPreview { + public static final Key PARENT_SPLIT_EDITOR_KEY = Key.create("Question Split"); + + public QuestionEditorWithPreview(@NotNull TextEditor editor, @NotNull FileEditor preview) { + super(editor, preview, "Question "+ Layout.SHOW_EDITOR_AND_PREVIEW.getName() ,Layout.SHOW_EDITOR_AND_PREVIEW); + editor.putUserData(PARENT_SPLIT_EDITOR_KEY, this); + preview.putUserData(PARENT_SPLIT_EDITOR_KEY, this); + if(preview instanceof MarkdownPreviewFileEditor){ + try { + Method setMainEditor = preview.getClass().getMethod("setMainEditor", Editor.class); + setMainEditor.invoke(preview,editor.getEditor()); + }catch (Throwable ignore){ + } + } + } + + @Nullable + protected ActionGroup createLeftToolbarActionGroup() { + return (ActionGroup) ActionManager.getInstance().getAction(PluginConstant.LEETCODE_EDITOR_GROUP); + } +} diff --git a/src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java b/src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java index f8a554ad..47264215 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java @@ -15,6 +15,7 @@ import java.io.File; import java.math.BigDecimal; +import java.util.function.BiConsumer; /** * @author shuzijun @@ -34,23 +35,28 @@ public static void openCode(Question question, Project project) { return; } + if(config.getQuestionEditor()) { + openContent(question, project, false); + } + String filePath = PersistentConfig.getInstance().getTempFilePath() + VelocityUtils.convert(config.getCustomFileName(), question) + codeTypeEnum.getSuffix(); File file = new File(filePath); + BiConsumer fillPath = (e, s) -> e.setPath(s); if (file.exists()) { - FileUtils.openFileEditorAndSaveState(file,project,question); + FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true); } else { if (getQuestion(question, codeTypeEnum, project)) { question.setContent(CommentUtils.createComment(question.getContent(), codeTypeEnum)); FileUtils.saveFile(file, VelocityUtils.convert(config.getCustomTemplate(), question)); - FileUtils.openFileEditorAndSaveState(file,project,question); + FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,true); } } } - public static void openContent(Question question, Project project) { + public static void openContent(Question question, Project project,boolean isOpen) { Config config = PersistentConfig.getInstance().getInitConfig(); String codeType = config.getCodeType(); CodeTypeEnum codeTypeEnum = CodeTypeEnum.getCodeTypeEnum(codeType); @@ -66,12 +72,13 @@ public static void openContent(Question question, Project project) { String filePath = PersistentConfig.getInstance().getTempFilePath() + Constant.DOC_CONTENT + VelocityUtils.convert(config.getCustomFileName(), question) + ".md"; File file = new File(filePath); + BiConsumer fillPath = (e, s) -> e.setContentPath(s); if (file.exists()) { - FileUtils.openFileEditor(file,project); + FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen); } else { if (getQuestion(question, codeTypeEnum, project)) { FileUtils.saveFile(file, question.getContent()); - FileUtils.openFileEditor(file,project); + FileUtils.openFileEditorAndSaveState(file,project,question,fillPath,isOpen); } } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java b/src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java index 8db7907b..966f0494 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java @@ -270,6 +270,12 @@ public void run() { } return question.get(id); } + public static Question getDumbQuestionById(String id, Project project) { + if (question.isEmpty()) { + return null; + } + return question.get(id); + } private static void addChild(DefaultMutableTreeNode rootNode, List Lists, Map questionMap) { if (!Lists.isEmpty()) { diff --git a/src/main/java/com/shuzijun/leetcode/plugin/model/Config.java b/src/main/java/com/shuzijun/leetcode/plugin/model/Config.java index 7072e6f1..35c24c7e 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/model/Config.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/model/Config.java @@ -90,6 +90,11 @@ public class Config { */ private Boolean jcef = false; + /** + * question Split Editor + */ + private Boolean questionEditor = true; + private List favoriteList; public String getId() { @@ -308,6 +313,14 @@ public void setJcef(Boolean jcef) { this.jcef = jcef; } + public Boolean getQuestionEditor() { + return questionEditor; + } + + public void setQuestionEditor(Boolean questionEditor) { + this.questionEditor = questionEditor; + } + public boolean isModified(Config config){ if(config ==null){ return false; @@ -328,6 +341,8 @@ public boolean isModified(Config config){ return false; if (jcef != null ? !jcef.equals(config.jcef) : config.jcef != null) return false; + if (questionEditor != null ? !questionEditor.equals(config.questionEditor) : config.questionEditor != null) + return false; return levelColour != null ? levelColour.equals(config.levelColour) : config.levelColour == null; } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/model/LeetcodeEditor.java b/src/main/java/com/shuzijun/leetcode/plugin/model/LeetcodeEditor.java index f496dc95..125fcd21 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/model/LeetcodeEditor.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/model/LeetcodeEditor.java @@ -17,6 +17,12 @@ public class LeetcodeEditor { */ private String questionId; + + /** + * content file path + */ + private String contentPath; + public Integer getVersion() { return version; } @@ -40,4 +46,13 @@ public String getQuestionId() { public void setQuestionId(String questionId) { this.questionId = questionId; } + + public String getContentPath() { + return contentPath; + } + + public void setContentPath(String contentPath) { + this.contentPath = contentPath; + } + } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/model/PluginConstant.java b/src/main/java/com/shuzijun/leetcode/plugin/model/PluginConstant.java index d71cb3a4..b7a2d9d4 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/model/PluginConstant.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/model/PluginConstant.java @@ -53,4 +53,7 @@ public class PluginConstant { public static final String LEETCODE_FIND_SORT_TOOLBAR = ACTION_PREFIX + ".find.SortToolbar"; + public static final String LEETCODE_EDITOR_GROUP = ACTION_PREFIX + ".editor.group"; + + } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java b/src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java index c504d05c..e1505412 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/setting/ProjectConfig.java @@ -5,6 +5,7 @@ import com.intellij.util.xmlb.annotations.MapAnnotation; import com.shuzijun.leetcode.plugin.model.LeetcodeEditor; import com.shuzijun.leetcode.plugin.model.PluginConstant; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,6 +18,8 @@ @State(name = "LeetcodeEditor" + PluginConstant.ACTION_SUFFIX, storages = {@Storage(value = PluginConstant.ACTION_PREFIX+"/editor.xml")}) public class ProjectConfig implements ProjectComponent, PersistentStateComponent { + public Map idProjectConfig = new HashMap<>(); + public ProjectConfig(Project project) { } @@ -37,19 +40,29 @@ public ProjectConfig.InnerState getState() { @Override public void loadState(@NotNull ProjectConfig.InnerState innerState) { this.innerState = innerState; + idProjectConfig.clear(); + this.innerState.projectConfig.forEach((s, leetcodeEditor) -> { + idProjectConfig.put(leetcodeEditor.getQuestionId(),leetcodeEditor); + }); } - public LeetcodeEditor getDefEditor(String path) { - LeetcodeEditor leetcodeEditor = innerState.projectConfig.get(path); + public LeetcodeEditor getDefEditor(String questionId) { + LeetcodeEditor leetcodeEditor = idProjectConfig.get(questionId); if (leetcodeEditor == null) { leetcodeEditor = new LeetcodeEditor(); - leetcodeEditor.setPath(path); - innerState.projectConfig.put(path, leetcodeEditor); + idProjectConfig.put(questionId,leetcodeEditor); } return leetcodeEditor; } + public void addLeetcodeEditor(LeetcodeEditor leetcodeEditor) { + idProjectConfig.put(leetcodeEditor.getQuestionId(), leetcodeEditor); + if(StringUtils.isNotBlank(leetcodeEditor.getPath())) { + innerState.projectConfig.put(leetcodeEditor.getPath(), leetcodeEditor); + } + } + public LeetcodeEditor getEditor(String path) { return innerState.projectConfig.get(path); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.form b/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.form index 021575a5..d3b4a901 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.form +++ b/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.form @@ -1,342 +1,323 @@
- - + + - + + + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 77f93967..8be20688 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/setting/SettingUI.java @@ -38,6 +38,7 @@ */ public class SettingUI { private JPanel mainPanel; + private JCheckBox questionEditorCheckBox; private JComboBox webComboBox; private JComboBox codeComboBox; private JBTextField userNameField; @@ -123,7 +124,7 @@ public void mouseClicked(MouseEvent e) { //允许单逻辑行折叠 settings.setAllowSingleLogicalLineFolding(false); //滚动 - settings.setAnimatedScrolling(false); + settings.setAnimatedScrolling(true); //底部附加 settings.setAdditionalPageAtBottom(false); //代码自动折叠 @@ -184,6 +185,7 @@ private void loadSetting() { hardLabel.setForeground(colors[2]); jcefCheckBox.setSelected(config.getJcef()); + questionEditorCheckBox.setSelected(config.getQuestionEditor()); } else { Color[] colors = new Config().getFormatLevelColour(); easyLabel.setForeground(colors[0]); @@ -251,6 +253,7 @@ public void process(Config config) { config.setFormatLevelColour(easyLabel.getForeground(), mediumLabel.getForeground(), hardLabel.getForeground()); config.setEnglishContent(englishContentBox.isSelected()); config.setJcef(jcefCheckBox.isSelected()); + config.setQuestionEditor(questionEditorCheckBox.isSelected()); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/utils/FileUtils.java b/src/main/java/com/shuzijun/leetcode/plugin/utils/FileUtils.java index 239dbd54..4c7ee953 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/utils/FileUtils.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/utils/FileUtils.java @@ -25,6 +25,7 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiConsumer; /** * @author shuzijun @@ -263,13 +264,18 @@ public static void openFileEditor(File file, Project project) { }); } - public static void openFileEditorAndSaveState(File file, Project project, Question question) { + + public static void openFileEditorAndSaveState(File file, Project project, Question question, BiConsumer consumer,boolean isOpen) { ApplicationManager.getApplication().invokeAndWait(() -> { VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); - OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vf); - FileEditorManager.getInstance(project).openTextEditor(descriptor, false); - LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getDefEditor(vf.getPath()); + LeetcodeEditor leetcodeEditor = ProjectConfig.getInstance(project).getDefEditor(question.getQuestionId()); leetcodeEditor.setQuestionId(question.getQuestionId()); + consumer.accept(leetcodeEditor,vf.getPath()); + ProjectConfig.getInstance(project).addLeetcodeEditor(leetcodeEditor); + if(isOpen) { + OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vf); + FileEditorManager.getInstance(project).openTextEditor(descriptor, false); + } }); } diff --git a/src/main/java/com/shuzijun/leetcode/plugin/window/NavigatorPanel.java b/src/main/java/com/shuzijun/leetcode/plugin/window/NavigatorPanel.java index fe531d42..442a7d51 100644 --- a/src/main/java/com/shuzijun/leetcode/plugin/window/NavigatorPanel.java +++ b/src/main/java/com/shuzijun/leetcode/plugin/window/NavigatorPanel.java @@ -127,11 +127,11 @@ protected void paintComponent(Graphics g) { queryField.addKeyListener(new QueryKeyListener(queryField, contentScrollPanel, toolWindow)); queryPanel.add(queryField); - findToolbar = actionManager.createActionToolbar("", + findToolbar = actionManager.createActionToolbar(PluginConstant.LEETCODE_FIND_TOOLBAR, (DefaultActionGroup) actionManager.getAction(PluginConstant.LEETCODE_FIND_TOOLBAR), true); findToolbar.setTargetComponent(tree); - actionSortToolbar = actionManager.createActionToolbar("", + actionSortToolbar = actionManager.createActionToolbar(PluginConstant.LEETCODE_FIND_SORT_TOOLBAR, (DefaultActionGroup) actionManager.getAction(PluginConstant.LEETCODE_FIND_SORT_TOOLBAR), true); actionSortToolbar.setTargetComponent(tree); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a49b67d0..6c675b24 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -392,6 +392,7 @@ on how to target different products --> com.intellij.modules.lang + org.intellij.plugins.markdown         @@ -426,6 +427,7 @@ + @@ -569,10 +571,7 @@ - - - + @@ -614,6 +613,11 @@ text="Reset" description="Reset Time(editor)"> + + + + @@ -644,7 +648,6 @@ class="com.shuzijun.leetcode.plugin.actions.toolbar.SortAction" text="Frequency" description="Sort By Frequency" icon="LeetCodeEditorIcons.SORT_ASC"/> - diff --git a/src/main/resources/icons/LeetCode.png b/src/main/resources/icons/LeetCode.png index bd89b79f..0c1def93 100644 Binary files a/src/main/resources/icons/LeetCode.png and b/src/main/resources/icons/LeetCode.png differ diff --git a/src/main/resources/icons/LeetCode.svg b/src/main/resources/icons/LeetCode.svg index 5bee3351..a53589d7 100644 --- a/src/main/resources/icons/LeetCode.svg +++ b/src/main/resources/icons/LeetCode.svg @@ -1,6 +1,6 @@ - + preserveAspectRatio="xMidYMid meet" width="13" height="13"> + - +