generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LiLittleCat/develop
Develop
- Loading branch information
Showing
9 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/main/java/com/codelabware/intellij/view/editor/Editor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/codelabware/intellij/window/CodeLabwareToolWindowFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plugin.name=Code Labware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plugin.name=Code Labware |
This file was deleted.
Oops, something went wrong.