This commit is contained in:
林万程
2022-02-11 00:23:01 +08:00
parent 3088edd484
commit dec8cf172c
18 changed files with 820 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package io.github.linwancen.plugin.comment.settings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.util.ui.FormBuilder;
import javax.swing.*;
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 ");
public AppSettingsComponent() {
JPanel comment = FormBuilder.createFormBuilder()
.addComponent(showTreeComment, 1)
.addComponent(showLineEndComment, 1)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
comment.setBorder(IdeBorderFactory.createTitledBorder("Comment"));
myMainPanel = FormBuilder.createFormBuilder()
.addComponent(comment, 1)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
}
public JPanel getPanel() {
return myMainPanel;
}
public JComponent getPreferredFocusedComponent() {
return showTreeComment;
}
public boolean getShowTreeComment() {
return showTreeComment.isSelected();
}
public void setShowTreeComment(boolean newStatus) {
showTreeComment.setSelected(newStatus);
}
public boolean getShowLineEndComment() {
return showLineEndComment.isSelected();
}
public void setShowLineEndComment(boolean newStatus) {
showLineEndComment.setSelected(newStatus);
}
}

View File

@@ -0,0 +1,58 @@
package io.github.linwancen.plugin.comment.settings;
import com.intellij.openapi.options.Configurable;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class AppSettingsConfigurable implements Configurable {
private AppSettingsComponent mySettingsComponent;
@Nls(capitalization = Nls.Capitalization.Title)
@Override
public String getDisplayName() {
return "Show Comment.";
}
@Override
public JComponent getPreferredFocusedComponent() {
return mySettingsComponent.getPreferredFocusedComponent();
}
@Nullable
@Override
public JComponent createComponent() {
mySettingsComponent = new AppSettingsComponent();
return mySettingsComponent.getPanel();
}
@Override
public boolean isModified() {
AppSettingsState settings = AppSettingsState.getInstance();
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment;
return modified;
}
@Override
public void apply() {
AppSettingsState settings = AppSettingsState.getInstance();
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
settings.showLineEndComment = mySettingsComponent.getShowLineEndComment();
}
@Override
public void reset() {
AppSettingsState settings = AppSettingsState.getInstance();
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
mySettingsComponent.setShowLineEndComment(settings.showLineEndComment);
}
@Override
public void disposeUIResources() {
mySettingsComponent = null;
}
}

View File

@@ -0,0 +1,34 @@
package io.github.linwancen.plugin.comment.settings;
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.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@State(
name = "io.github.linwancen.plugin.comment.settings.AppSettingsState",
storages = @Storage("ShowCommentPlugin.xml")
)
public class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
public boolean showLineEndComment = true;
public boolean showTreeComment = true;
public static AppSettingsState getInstance() {
return ApplicationManager.getApplication().getService(AppSettingsState.class);
}
@Nullable
@Override
public AppSettingsState getState() {
return this;
}
@Override
public void loadState(@NotNull AppSettingsState state) {
XmlSerializerUtil.copyBean(state, this);
}
}