Skip to content

Commit

Permalink
Merge pull request #1 from LiLittleCat/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LiLittleCat authored Feb 27, 2023
2 parents 2961a41 + 0ada087 commit be97aae
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.8.0"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.12.0"
id("org.jetbrains.intellij") version "1.13.0"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "2.0.0"
// Gradle Qodana Plugin
Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ kotlin.stdlib.default.dependency = false
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
# suppress inspection "UnusedProperty"
org.gradle.unsafe.configuration-cache = true


systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.codelabware.intellij;
package com.codelabware.intellij.message;

import com.intellij.DynamicBundle;
import org.jetbrains.annotations.Nls;
Expand All @@ -12,12 +12,12 @@
* @author <a href="https://github.com/LiLittleCat">LiLittleCat</a>
* @since 0.0.1
*/
public class MyBundle extends DynamicBundle {
public class CodeLabwareBundle extends DynamicBundle {
@NonNls
private static final String BUNDLE = "messages.MyBundle";
private static final MyBundle INSTANCE = new MyBundle();
private static final String BUNDLE = "messages.CodeLabwareBundle";
private static final CodeLabwareBundle INSTANCE = new CodeLabwareBundle();

private MyBundle() {
private CodeLabwareBundle() {
super(BUNDLE);
}

Expand Down
118 changes: 118 additions & 0 deletions src/main/java/com/codelabware/intellij/view/editor/Editor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.codelabware.intellij.view.editor;

import com.codelabware.intellij.message.CodeLabwareBundle;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.json.JsonFileType;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.ui.EditorTextField;
import com.intellij.util.LocalTimeCounter;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.border.Border;

/**
* @author <a href="https://github.com/LiLittleCat">LiLittleCat</a>
* @since 2023/2/26
*/
public class Editor extends EditorTextField {
public static final FileType TEXT_FILE_TYPE = FileTypes.PLAIN_TEXT;
public static final FileType JSON_FILE_TYPE = JsonFileType.INSTANCE;
public static final FileType HTML_FILE_TYPE = HtmlFileType.INSTANCE;
public static final FileType XML_FILE_TYPE = XmlFileType.INSTANCE;

public Editor(Project project) {
this(project, TEXT_FILE_TYPE);
}

public Editor(Project project, FileType fileType) {
super(null, project, fileType, false, false);
}

public static void setupTextFieldEditor(@NotNull EditorEx editor) {
EditorSettings settings = editor.getSettings();
settings.setFoldingOutlineShown(true);
settings.setLineNumbersShown(true);
settings.setIndentGuidesShown(true);
editor.setHorizontalScrollbarVisible(true);
editor.setVerticalScrollbarVisible(true);
}

public void setText(@Nullable final String text, @NotNull final FileType fileType) {
super.setFileType(fileType);
Document document = createDocument(text, fileType);
setDocument(document);
PsiFile psiFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
if (psiFile != null) {
WriteCommandAction.runWriteCommandAction(
getProject(),
() -> {
CodeStyleManager.getInstance(getProject()).reformat(psiFile);
}
);
}
}

@Override
public void setFileType(@NotNull FileType fileType) {
setNewDocumentAndFileType(fileType, createDocument(getText(), fileType));
}

@Override
protected Document createDocument() {
return createDocument(null, getFileType());
}

private void initOneLineMode(@NotNull final EditorEx editor) {
editor.setOneLineMode(false);
editor.setColorsScheme(editor.createBoundColorSchemeDelegate(null));
editor.getSettings().setCaretRowShown(false);
}

@Override
protected EditorEx createEditor() {
EditorEx editor = super.createEditor();
initOneLineMode(editor);
setupTextFieldEditor(editor);
return editor;
}

@Override
public void repaint(long tm, int x, int y, int width, int height) {
super.repaint(tm, x, y, width, height);
if (getEditor() instanceof EditorEx) {
initOneLineMode(((EditorEx) getEditor()));
}
}

@Override
public void setBorder(Border border) {
super.setBorder(JBUI.Borders.empty());
}

public Document createDocument(@Nullable final String text, @NotNull final FileType fileType) {
final PsiFileFactory factory = PsiFileFactory.getInstance(getProject());
final long stamp = LocalTimeCounter.currentTime();
final PsiFile psiFile = factory.createFileFromText(
CodeLabwareBundle.message("plugin.name"),
fileType,
text == null ? "" : text,
stamp,
true,
false
);
return PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.codelabware.intellij.window;

import com.codelabware.intellij.message.CodeLabwareBundle;
import com.codelabware.intellij.view.editor.Editor;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.EditorComboBox;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
* @author <a href="https://github.com/LiLittleCat">LiLittleCat</a>
* @since 2023/2/26
*/
public class CodeLabwareToolWindowFactory implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ContentManager contentManager = toolWindow.getContentManager();


// Content labelContent = contentManager.getFactory().createContent(new Editor(project, Editor.JSON_FILE_TYPE), CodeLabwareBundle.message("plugin.name"), false);
Content labelContent = contentManager.getFactory().createContent(new EditorTextField(project, Editor.JSON_FILE_TYPE), CodeLabwareBundle.message("plugin.name"), false);
Content labelContent1 = contentManager.getFactory().createContent(new EditorComboBox("test"), CodeLabwareBundle.message("plugin.name"), false);
contentManager.addContent(labelContent);
contentManager.addContent(labelContent1);
// // add actions to tool window
// List<AnAction> anActionList = new ArrayList<>();
// anActionList.add(new SettingsAction("Settings"));
// anActionList.add(new RefreshAction("Refresh"));
// toolWindow.setTitleActions(anActionList);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<add-to-group group-id="EditorPopupMenu" anchor="first"/>
</action>
</actions>
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Sample Calendar" secondary="true" icon="AllIcons.General.Modified" anchor="right"
factoryClass="com.codelabware.intellij.window.CodeLabwareToolWindowFactory"/>
</extensions>
</idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/messages/CodeLabwareBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plugin.name=Code Labware
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plugin.name=Code Labware
3 changes: 0 additions & 3 deletions src/main/resources/messages/MyBundle.properties

This file was deleted.

0 comments on commit be97aae

Please sign in to comment.