Skip to content

Optimization view #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://shuzijun.cn/donate.html']
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
</p>

### Installation([help](https://www.jetbrains.com/help/idea/2019.2/managing-plugins.html))
- **Install via plug-in library** https://plugins.jetbrains.com/plugin/12132-leetcode-editor
- **Install by downloading the file** https://github.com/shuzijun/leetcode-editor/releases
- **Install via plug-in library** [leetcode-editor](https://plugins.jetbrains.com/plugin/12132-leetcode-editor)
- **Install by downloading the file** [releases](https://github.com/shuzijun/leetcode-editor/releases)
- **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)

### Configuration (configuration for first installation)

Expand Down
5 changes: 3 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
</p>

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

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

Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
}
api 'org.scilab.forge:jlatexmath:1.0.7'
api 'org.apache.commons:commons-lang3:3.9'
api 'com.vladsch.flexmark:flexmark:0.62.2'
api 'com.vladsch.flexmark:flexmark-ext-attributes:0.62.2'
//api fileTree(dir: 'src/main/resources/lib', include: ['*.jar'])

}
Expand All @@ -37,7 +39,10 @@ intellij {
ideaDependencyCachePath = "$gradle.gradleUserHomeDir/caches/modules-2/files-2.1/com.jetbrains.intellij.idea"
/* localPath project.idea_local_path
alternativeIdePath project.idea_local_path*/
plugins = project.intellij_plugins.split(",").toList()
/*plugins = project.intellij_plugins.split(",").toList()*/
runIde {
jvmArgs = ["-Dfile.encoding=utf-8"]
}
/* prepareSandbox {
from("src/main/natives" + (project.build_env.isEmpty() ? "" : "-") + project.build_env) { into(getPluginName() + '/natives') }
}*/
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugin_version = 2021.1.0
plugin_version = 7.0
idea_local_path =
# '' | windows | mac | linux
build_env =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.shuzijun.leetcode.plugin.actions.toolbar;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;


/**
* @author shuzijun
*/
public class DonateAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
BrowserUtil.browse("https://shuzijun.cn/donate.html");
}

}
103 changes: 103 additions & 0 deletions src/main/java/com/shuzijun/leetcode/plugin/editor/BaseController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.shuzijun.leetcode.plugin.editor;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.io.Responses;

import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

/**
* @author shuzijun
*/
public abstract class BaseController {

// every time the plugin starts up, assume resources could have been modified
protected static final long LAST_MODIFIED = System.currentTimeMillis();

public final void process(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
FullHttpResponse response;
try {
if (request.method() == HttpMethod.POST) {
response = post(urlDecoder, request, context);
} else if (request.method() == HttpMethod.GET) {
response = get(urlDecoder, request, context);
} else {
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
}
} catch (Throwable t) {
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(t.getMessage().getBytes(StandardCharsets.UTF_8)));
}
Responses.send(response, context.channel(), request);
if (response.content() != Unpooled.EMPTY_BUFFER) {
try {
response.release();
} catch (Exception ignore) {
}
}
}

public FullHttpResponse get(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
}

public FullHttpResponse post(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
}

public abstract String getControllerPath();

protected String getResourceName(QueryStringDecoder urlDecoder) {
return urlDecoder.path().substring(PreviewStaticServer.PREFIX.length() + getControllerPath().length());
}

protected String getParameter(@NotNull QueryStringDecoder urlDecoder, @NotNull String parameter) {
List<String> parameters = urlDecoder.parameters().get(parameter);
if (parameters == null || parameters.size() != 1) {
return null;
}
return URLDecoder.decode(parameters.get(0), StandardCharsets.UTF_8);
}

protected FullHttpResponse fillHtmlResponse(String content) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(StandardCharsets.UTF_8)));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain;charset=UTF-8");
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "max-age=5, private, must-revalidate");
response.headers().set("Referrer-Policy", "no-referrer");
return response;
}

protected FullHttpResponse fillJsonResponse(String content) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.getBytes(StandardCharsets.UTF_8)));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "max-age=5, private, must-revalidate");
response.headers().set("Referrer-Policy", "no-referrer");
return response;
}

public void addRoute(Map<String, BaseController> route) {
route.put(PreviewStaticServer.PREFIX + getControllerPath(), this);
}

protected Project getProject(String projectNameParameter, String projectUrlParameter) {
Project project = null;
for (Project p : ProjectManager.getInstance().getOpenProjects()) {
if ((projectNameParameter != null && projectNameParameter.equals(p.getName()))
|| (projectUrlParameter != null && projectUrlParameter.equals(p.getPresentableUrl()))) {
project = p;
break;
}
}

return project;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.shuzijun.leetcode.plugin.editor;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

/**
* @author shuzijun
*/
public class ContentProvider extends LCVProvider{

@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
return true;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/shuzijun/leetcode/plugin/editor/LCVFileType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.shuzijun.leetcode.plugin.editor;

import com.intellij.openapi.fileTypes.LanguageFileType;
import com.shuzijun.leetcode.plugin.model.PluginConstant;
import icons.LeetCodeEditorIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class LCVFileType extends LanguageFileType {
public static final LCVFileType INSTANCE = new LCVFileType();

private LCVFileType() {
super(LCVLanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return PluginConstant.LEETCODE_EDITOR_VIEW+"Doc";
}

@NotNull
@Override
public String getDescription() {
return PluginConstant.LEETCODE_EDITOR_VIEW;
}

@NotNull
@Override
public String getDefaultExtension() {
return PluginConstant.LEETCODE_EDITOR_VIEW;
}

@Nullable
@Override
public Icon getIcon() {
return LeetCodeEditorIcons.LCV;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/shuzijun/leetcode/plugin/editor/LCVLanguage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.shuzijun.leetcode.plugin.editor;

import com.intellij.lang.Language;
import com.shuzijun.leetcode.plugin.model.PluginConstant;

public class LCVLanguage extends Language {

public static final String LANGUAGE_NAME = PluginConstant.LEETCODE_EDITOR_VIEW+"Doc";

public static final LCVLanguage INSTANCE = new LCVLanguage();

protected LCVLanguage() {
super(LANGUAGE_NAME);
}
}
Loading