1.1 Add end-of-line text color settings | 添加行末文本颜色配置
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'io.github.linwancen'
|
group 'io.github.linwancen'
|
||||||
version '1.0.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
version '1.1.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ patchPluginXml {
|
|||||||
sinceBuild = '201.1'
|
sinceBuild = '201.1'
|
||||||
untilBuild = ''
|
untilBuild = ''
|
||||||
changeNotes = """
|
changeNotes = """
|
||||||
Code optimization | 代码优化
|
1.1 Add end-of-line text color settings | 添加行末文本颜色配置
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package io.github.linwancen.plugin.comment;
|
package io.github.linwancen.plugin.comment;
|
||||||
|
|
||||||
import com.intellij.lang.java.JavaLanguage;
|
import com.intellij.lang.java.JavaLanguage;
|
||||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
|
||||||
import com.intellij.openapi.editor.Document;
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.editor.EditorLinePainter;
|
import com.intellij.openapi.editor.EditorLinePainter;
|
||||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
|
||||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
|
||||||
import com.intellij.openapi.project.DumbService;
|
import com.intellij.openapi.project.DumbService;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
@@ -15,8 +12,6 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
|
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
|
||||||
import com.intellij.psi.javadoc.PsiDocComment;
|
import com.intellij.psi.javadoc.PsiDocComment;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.ui.Gray;
|
|
||||||
import com.intellij.ui.JBColor;
|
|
||||||
import io.github.linwancen.plugin.comment.settings.AppSettingsState;
|
import io.github.linwancen.plugin.comment.settings.AppSettingsState;
|
||||||
import io.github.linwancen.plugin.comment.utils.CommentFactory;
|
import io.github.linwancen.plugin.comment.utils.CommentFactory;
|
||||||
import io.github.linwancen.plugin.comment.utils.PsiDocCommentUtils;
|
import io.github.linwancen.plugin.comment.utils.PsiDocCommentUtils;
|
||||||
@@ -25,15 +20,16 @@ import io.github.linwancen.plugin.comment.utils.SkipUtils;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class LineEnd extends EditorLinePainter {
|
public class LineEnd extends EditorLinePainter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project,
|
public @Nullable Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project,
|
||||||
@NotNull VirtualFile file, int lineNumber) {
|
@NotNull VirtualFile file, int lineNumber) {
|
||||||
if (!AppSettingsState.getInstance().showLineEndComment) {
|
AppSettingsState settings = AppSettingsState.getInstance();
|
||||||
|
if (!settings.showLineEndComment) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (DumbService.isDumb(project)) {
|
if (DumbService.isDumb(project)) {
|
||||||
@@ -46,7 +42,7 @@ public class LineEnd extends EditorLinePainter {
|
|||||||
if (comment == null) {
|
if (comment == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
LineExtensionInfo info = new LineExtensionInfo(" //" + comment, getNormalAttributes());
|
LineExtensionInfo info = new LineExtensionInfo(" //" + comment, settings.lineEndTextAttr);
|
||||||
return Collections.singletonList(info);
|
return Collections.singletonList(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,18 +166,4 @@ public class LineEnd extends EditorLinePainter {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextAttributes getNormalAttributes() {
|
|
||||||
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
|
|
||||||
TextAttributes attributes = colorsManager.getGlobalScheme()
|
|
||||||
.getAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
|
|
||||||
if (attributes == null || attributes.getForegroundColor() == null) {
|
|
||||||
JBColor jbColor = new JBColor(() -> Gray._183);
|
|
||||||
return new TextAttributes(jbColor, null, null, null, Font.ITALIC);
|
|
||||||
} else {
|
|
||||||
// Sometimes it becomes the same color as the end of the line char, so use italic to distinguish
|
|
||||||
attributes.setFontType(Font.ITALIC);
|
|
||||||
}
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,35 @@
|
|||||||
package io.github.linwancen.plugin.comment.settings;
|
package io.github.linwancen.plugin.comment.settings;
|
||||||
|
|
||||||
|
import com.intellij.ui.ColorPanel;
|
||||||
import com.intellij.ui.IdeBorderFactory;
|
import com.intellij.ui.IdeBorderFactory;
|
||||||
import com.intellij.ui.components.JBCheckBox;
|
import com.intellij.ui.components.JBCheckBox;
|
||||||
import com.intellij.util.ui.FormBuilder;
|
import com.intellij.util.ui.FormBuilder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class AppSettingsComponent {
|
public class AppSettingsComponent {
|
||||||
|
|
||||||
private final JPanel myMainPanel;
|
private final JPanel myMainPanel;
|
||||||
private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment ");
|
private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment ");
|
||||||
private final JBCheckBox showLineEndComment = new JBCheckBox("Show line end comment ");
|
private final JBCheckBox showLineEndComment = new JBCheckBox("Show line end comment ");
|
||||||
|
private final ColorPanel lineEndColor = new ColorPanel();
|
||||||
|
|
||||||
public AppSettingsComponent() {
|
public AppSettingsComponent() {
|
||||||
JPanel comment = FormBuilder.createFormBuilder()
|
JPanel comment = FormBuilder.createFormBuilder()
|
||||||
.addComponent(showTreeComment, 1)
|
.addComponent(showTreeComment, 1)
|
||||||
.addComponent(showLineEndComment, 1)
|
.addComponent(showLineEndComment, 1)
|
||||||
.addComponentFillVertically(new JPanel(), 0)
|
|
||||||
.getPanel();
|
.getPanel();
|
||||||
comment.setBorder(IdeBorderFactory.createTitledBorder("Comment"));
|
comment.setBorder(IdeBorderFactory.createTitledBorder("Comment"));
|
||||||
|
|
||||||
|
JPanel color = FormBuilder.createFormBuilder()
|
||||||
|
.addLabeledComponent(new JLabel("line end text color:"), lineEndColor)
|
||||||
|
.getPanel();
|
||||||
|
color.setBorder(IdeBorderFactory.createTitledBorder("Color"));
|
||||||
|
|
||||||
myMainPanel = FormBuilder.createFormBuilder()
|
myMainPanel = FormBuilder.createFormBuilder()
|
||||||
.addComponent(comment, 1)
|
.addComponent(comment, 1)
|
||||||
|
.addComponent(color, 1)
|
||||||
.addComponentFillVertically(new JPanel(), 0)
|
.addComponentFillVertically(new JPanel(), 0)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
@@ -49,4 +57,12 @@ public class AppSettingsComponent {
|
|||||||
public void setShowLineEndComment(boolean newStatus) {
|
public void setShowLineEndComment(boolean newStatus) {
|
||||||
showLineEndComment.setSelected(newStatus);
|
showLineEndComment.setSelected(newStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getLineEndColor() {
|
||||||
|
return lineEndColor.getSelectedColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineEndColor(Color color) {
|
||||||
|
lineEndColor.setSelectedColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package io.github.linwancen.plugin.comment.settings;
|
package io.github.linwancen.plugin.comment.settings;
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||||
import com.intellij.openapi.options.Configurable;
|
import com.intellij.openapi.options.Configurable;
|
||||||
|
import com.intellij.ui.Gray;
|
||||||
|
import com.intellij.ui.JBColor;
|
||||||
import org.jetbrains.annotations.Nls;
|
import org.jetbrains.annotations.Nls;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class AppSettingsConfigurable implements Configurable {
|
public class AppSettingsConfigurable implements Configurable {
|
||||||
|
|
||||||
@@ -33,6 +37,7 @@ public class AppSettingsConfigurable implements Configurable {
|
|||||||
AppSettingsState settings = AppSettingsState.getInstance();
|
AppSettingsState settings = AppSettingsState.getInstance();
|
||||||
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
||||||
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
|
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
|
||||||
|
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +46,15 @@ public class AppSettingsConfigurable implements Configurable {
|
|||||||
AppSettingsState settings = AppSettingsState.getInstance();
|
AppSettingsState settings = AppSettingsState.getInstance();
|
||||||
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
||||||
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
|
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
|
||||||
|
settings.lineEndTextAttr.setForegroundColor(jbColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private JBColor jbColor() {
|
||||||
|
if (EditorColorsManager.getInstance().isDarkEditor()) {
|
||||||
|
return new JBColor(new Color(98, 151, 85), mySettingsComponent.getLineEndColor());
|
||||||
|
} else {
|
||||||
|
return new JBColor(mySettingsComponent.getLineEndColor(), Gray._140);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,6 +62,7 @@ public class AppSettingsConfigurable implements Configurable {
|
|||||||
AppSettingsState settings = AppSettingsState.getInstance();
|
AppSettingsState settings = AppSettingsState.getInstance();
|
||||||
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
||||||
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
|
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
|
||||||
|
mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ import com.intellij.openapi.application.ApplicationManager;
|
|||||||
import com.intellij.openapi.components.PersistentStateComponent;
|
import com.intellij.openapi.components.PersistentStateComponent;
|
||||||
import com.intellij.openapi.components.State;
|
import com.intellij.openapi.components.State;
|
||||||
import com.intellij.openapi.components.Storage;
|
import com.intellij.openapi.components.Storage;
|
||||||
|
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||||
|
import com.intellij.ui.Gray;
|
||||||
|
import com.intellij.ui.JBColor;
|
||||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
@State(
|
@State(
|
||||||
name = "io.github.linwancen.plugin.comment.settings.AppSettingsState",
|
name = "io.github.linwancen.plugin.comment.settings.AppSettingsState",
|
||||||
storages = @Storage("ShowCommentPlugin.xml")
|
storages = @Storage("ShowCommentPlugin.xml")
|
||||||
@@ -17,6 +22,10 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
|||||||
public boolean showLineEndComment = true;
|
public boolean showLineEndComment = true;
|
||||||
public boolean showTreeComment = true;
|
public boolean showTreeComment = true;
|
||||||
|
|
||||||
|
private static final JBColor lineEndColor = new JBColor(new Color(98, 151, 85), Gray._140);
|
||||||
|
public final TextAttributes lineEndTextAttr = new TextAttributes(lineEndColor,
|
||||||
|
null, null, null, Font.ITALIC);
|
||||||
|
|
||||||
public static AppSettingsState getInstance() {
|
public static AppSettingsState getInstance() {
|
||||||
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user