1.1 Add end-of-line text color settings | 添加行末文本颜色配置
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
package io.github.linwancen.plugin.comment.settings;
|
||||
|
||||
import com.intellij.ui.ColorPanel;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class AppSettingsComponent {
|
||||
|
||||
private final JPanel myMainPanel;
|
||||
private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment ");
|
||||
private final JBCheckBox showLineEndComment = new JBCheckBox("Show line end comment ");
|
||||
private final ColorPanel lineEndColor = new ColorPanel();
|
||||
|
||||
public AppSettingsComponent() {
|
||||
JPanel comment = FormBuilder.createFormBuilder()
|
||||
.addComponent(showTreeComment, 1)
|
||||
.addComponent(showLineEndComment, 1)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
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()
|
||||
.addComponent(comment, 1)
|
||||
.addComponent(color, 1)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
@@ -49,4 +57,12 @@ public class AppSettingsComponent {
|
||||
public void setShowLineEndComment(boolean 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;
|
||||
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
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.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@@ -33,6 +37,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
||||
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
|
||||
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -41,6 +46,15 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
||||
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
|
||||
@@ -48,6 +62,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
||||
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
|
||||
mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,10 +4,15 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@State(
|
||||
name = "io.github.linwancen.plugin.comment.settings.AppSettingsState",
|
||||
storages = @Storage("ShowCommentPlugin.xml")
|
||||
@@ -17,6 +22,10 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
public boolean showLineEndComment = 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() {
|
||||
return ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user