Skip to content

Commit 8c56b83

Browse files
authored
Merge pull request #367 from shuzijun/gradle
Optimization view
2 parents 0324e04 + cb2d140 commit 8c56b83

Some content is hidden

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

45 files changed

+2042
-191
lines changed

.github/FUNDING.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://shuzijun.cn/donate.html']

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
</p>
2525

2626
### Installation([help](https://www.jetbrains.com/help/idea/2019.2/managing-plugins.html))
27-
- **Install via plug-in library** https://plugins.jetbrains.com/plugin/12132-leetcode-editor
28-
- **Install by downloading the file** https://github.com/shuzijun/leetcode-editor/releases
27+
- **Install via plug-in library** [leetcode-editor](https://plugins.jetbrains.com/plugin/12132-leetcode-editor)
28+
- **Install by downloading the file** [releases](https://github.com/shuzijun/leetcode-editor/releases)
29+
- **If you are willing to donate to this project, you can choose the pro version** [leetcode-editor-pro](https://plugins.jetbrains.com/plugin/17166-leetcode-editor-pro)
2930

3031
### Configuration (configuration for first installation)
3132

README_ZH.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
</p>
2525

2626
### 安装
27-
- **通过插件库安装** https://plugins.jetbrains.com/plugin/12132-leetcode-editor
28-
- **下载文件安装** https://github.com/shuzijun/leetcode-editor/releases
27+
- **通过插件库安装** [leetcode-editor](https://plugins.jetbrains.com/plugin/12132-leetcode-editor)
28+
- **下载文件安装** [releases](https://github.com/shuzijun/leetcode-editor/releases)
29+
- **如果您想捐助此项目,可以选择pro版本** [leetcode-editor-pro](https://plugins.jetbrains.com/plugin/17166-leetcode-editor-pro)
2930

3031
### 配置(第一次安装需要先配置)
3132

build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
}
2323
api 'org.scilab.forge:jlatexmath:1.0.7'
2424
api 'org.apache.commons:commons-lang3:3.9'
25+
api 'com.vladsch.flexmark:flexmark:0.62.2'
26+
api 'com.vladsch.flexmark:flexmark-ext-attributes:0.62.2'
2527
//api fileTree(dir: 'src/main/resources/lib', include: ['*.jar'])
2628

2729
}
@@ -37,7 +39,10 @@ intellij {
3739
ideaDependencyCachePath = "$gradle.gradleUserHomeDir/caches/modules-2/files-2.1/com.jetbrains.intellij.idea"
3840
/* localPath project.idea_local_path
3941
alternativeIdePath project.idea_local_path*/
40-
plugins = project.intellij_plugins.split(",").toList()
42+
/*plugins = project.intellij_plugins.split(",").toList()*/
43+
runIde {
44+
jvmArgs = ["-Dfile.encoding=utf-8"]
45+
}
4146
/* prepareSandbox {
4247
from("src/main/natives" + (project.build_env.isEmpty() ? "" : "-") + project.build_env) { into(getPluginName() + '/natives') }
4348
}*/

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
plugin_version = 2021.1.0
1+
plugin_version = 7.0
22
idea_local_path =
33
# '' | windows | mac | linux
44
build_env =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.shuzijun.leetcode.plugin.actions.toolbar;
2+
3+
import com.intellij.ide.BrowserUtil;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
7+
8+
/**
9+
* @author shuzijun
10+
*/
11+
public class DonateAction extends AnAction {
12+
@Override
13+
public void actionPerformed(AnActionEvent anActionEvent) {
14+
BrowserUtil.browse("https://shuzijun.cn/donate.html");
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.shuzijun.leetcode.plugin.editor;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.project.ProjectManager;
5+
import io.netty.buffer.Unpooled;
6+
import io.netty.channel.ChannelHandlerContext;
7+
import io.netty.handler.codec.http.*;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.io.Responses;
10+
11+
import java.io.IOException;
12+
import java.net.URLDecoder;
13+
import java.nio.charset.StandardCharsets;
14+
import java.util.List;
15+
import java.util.Map;
16+
17+
/**
18+
* @author shuzijun
19+
*/
20+
public abstract class BaseController {
21+
22+
// every time the plugin starts up, assume resources could have been modified
23+
protected static final long LAST_MODIFIED = System.currentTimeMillis();
24+
25+
public final void process(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
26+
FullHttpResponse response;
27+
try {
28+
if (request.method() == HttpMethod.POST) {
29+
response = post(urlDecoder, request, context);
30+
} else if (request.method() == HttpMethod.GET) {
31+
response = get(urlDecoder, request, context);
32+
} else {
33+
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
34+
}
35+
} catch (Throwable t) {
36+
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(t.getMessage().getBytes(StandardCharsets.UTF_8)));
37+
}
38+
Responses.send(response, context.channel(), request);
39+
if (response.content() != Unpooled.EMPTY_BUFFER) {
40+
try {
41+
response.release();
42+
} catch (Exception ignore) {
43+
}
44+
}
45+
}
46+
47+
public FullHttpResponse get(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
48+
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
49+
}
50+
51+
public FullHttpResponse post(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
52+
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
53+
}
54+
55+
public abstract String getControllerPath();
56+
57+
protected String getResourceName(QueryStringDecoder urlDecoder) {
58+
return urlDecoder.path().substring(PreviewStaticServer.PREFIX.length() + getControllerPath().length());
59+
}
60+
61+
protected String getParameter(@NotNull QueryStringDecoder urlDecoder, @NotNull String parameter) {
62+
List<String> parameters = urlDecoder.parameters().get(parameter);
63+
if (parameters == null || parameters.size() != 1) {
64+
return null;
65+
}
66+
return URLDecoder.decode(parameters.get(0), StandardCharsets.UTF_8);
67+
}
68+
69+
protected FullHttpResponse fillHtmlResponse(String content) {
70+
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(StandardCharsets.UTF_8)));
71+
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain;charset=UTF-8");
72+
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "max-age=5, private, must-revalidate");
73+
response.headers().set("Referrer-Policy", "no-referrer");
74+
return response;
75+
}
76+
77+
protected FullHttpResponse fillJsonResponse(String content) {
78+
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(StandardCharsets.UTF_8)));
79+
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
80+
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "max-age=5, private, must-revalidate");
81+
response.headers().set("Referrer-Policy", "no-referrer");
82+
return response;
83+
}
84+
85+
public void addRoute(Map<String, BaseController> route) {
86+
route.put(PreviewStaticServer.PREFIX + getControllerPath(), this);
87+
}
88+
89+
protected Project getProject(String projectNameParameter, String projectUrlParameter) {
90+
Project project = null;
91+
for (Project p : ProjectManager.getInstance().getOpenProjects()) {
92+
if ((projectNameParameter != null && projectNameParameter.equals(p.getName()))
93+
|| (projectUrlParameter != null && projectUrlParameter.equals(p.getPresentableUrl()))) {
94+
project = p;
95+
break;
96+
}
97+
}
98+
99+
return project;
100+
}
101+
102+
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.shuzijun.leetcode.plugin.editor;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.vfs.VirtualFile;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
/**
8+
* @author shuzijun
9+
*/
10+
public class ContentProvider extends LCVProvider{
11+
12+
@Override
13+
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
14+
return true;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.shuzijun.leetcode.plugin.editor;
2+
3+
import com.intellij.openapi.fileTypes.LanguageFileType;
4+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
5+
import icons.LeetCodeEditorIcons;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
8+
9+
import javax.swing.*;
10+
11+
public class LCVFileType extends LanguageFileType {
12+
public static final LCVFileType INSTANCE = new LCVFileType();
13+
14+
private LCVFileType() {
15+
super(LCVLanguage.INSTANCE);
16+
}
17+
18+
@NotNull
19+
@Override
20+
public String getName() {
21+
return PluginConstant.LEETCODE_EDITOR_VIEW+"Doc";
22+
}
23+
24+
@NotNull
25+
@Override
26+
public String getDescription() {
27+
return PluginConstant.LEETCODE_EDITOR_VIEW;
28+
}
29+
30+
@NotNull
31+
@Override
32+
public String getDefaultExtension() {
33+
return PluginConstant.LEETCODE_EDITOR_VIEW;
34+
}
35+
36+
@Nullable
37+
@Override
38+
public Icon getIcon() {
39+
return LeetCodeEditorIcons.LCV;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.shuzijun.leetcode.plugin.editor;
2+
3+
import com.intellij.lang.Language;
4+
import com.shuzijun.leetcode.plugin.model.PluginConstant;
5+
6+
public class LCVLanguage extends Language {
7+
8+
public static final String LANGUAGE_NAME = PluginConstant.LEETCODE_EDITOR_VIEW+"Doc";
9+
10+
public static final LCVLanguage INSTANCE = new LCVLanguage();
11+
12+
protected LCVLanguage() {
13+
super(LANGUAGE_NAME);
14+
}
15+
}

0 commit comments

Comments
 (0)