Split app and global settings
This commit is contained in:
@@ -2,17 +2,20 @@ package io.github.linwancen.plugin.show.bean;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SettingsInfo {
|
||||
public final @NotNull AppSettingsState appSettings;
|
||||
public final @NotNull GlobalSettingsState globalSettings;
|
||||
public final @NotNull ProjectSettingsState projectSettings;
|
||||
public final @NotNull FuncEnum funcEnum;
|
||||
|
||||
protected SettingsInfo(@NotNull Project project, @NotNull FuncEnum funcEnum) {
|
||||
this.funcEnum = funcEnum;
|
||||
this.appSettings = AppSettingsState.getInstance();
|
||||
this.globalSettings = GlobalSettingsState.getInstance();
|
||||
this.projectSettings = ProjectSettingsState.getInstance(project);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
@NotNull String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true);
|
||||
@NotNull String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
@NotNull String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.globalSettings, lineInfo.projectSettings);
|
||||
if (filterDoc.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
|
||||
}
|
||||
// desc
|
||||
@NotNull String descDoc = descDoc(lineInfo, docElement).trim();
|
||||
@NotNull String desc = DocFilter.filterDoc(descDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
@NotNull String desc = DocFilter.filterDoc(descDoc, lineInfo.globalSettings, lineInfo.projectSettings);
|
||||
// tag
|
||||
@NotNull StringBuilder tagStrBuilder = new StringBuilder();
|
||||
@NotNull String[] names = lineInfo.tagNames();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.linwancen.plugin.show.lang.base;
|
||||
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -63,20 +64,20 @@ public class DocFilter {
|
||||
*/
|
||||
@NotNull
|
||||
public static String filterDoc(@NotNull String text,
|
||||
@NotNull AppSettingsState appSettings,
|
||||
@NotNull GlobalSettingsState globalSettingsState,
|
||||
@NotNull ProjectSettingsState projectSettings) {
|
||||
// docGetEffect first because default false
|
||||
if (projectSettings.docGetEffect && projectSettings.projectFilterEffective) {
|
||||
return filterDoc(text, projectSettings.docGet);
|
||||
} else if (appSettings.docGetEffect && projectSettings.globalFilterEffective) {
|
||||
return filterDoc(text, appSettings.docGet);
|
||||
return filterPattern(text, projectSettings.docGet);
|
||||
} else if (globalSettingsState.docGetEffect && projectSettings.globalFilterEffective) {
|
||||
return filterPattern(text, globalSettingsState.docGet);
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String filterDoc(@NotNull String text, @NotNull Pattern docGet) {
|
||||
public static String filterPattern(@NotNull String text, @NotNull Pattern docGet) {
|
||||
// if effect skip check empty
|
||||
@NotNull Matcher m = docGet.matcher(text);
|
||||
if (m.find()) {
|
||||
@@ -94,7 +95,7 @@ public class DocFilter {
|
||||
public static void addHtml(@NotNull StringBuilder sb, @NotNull String s) {
|
||||
@NotNull String deleteHtml = html2Text(s);
|
||||
if (!deleteHtml.isEmpty()) {
|
||||
sb.append(deleteHtml);
|
||||
sb.append(deleteHtml).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DocSkip {
|
||||
|
||||
public static <T extends SettingsInfo> boolean skipSign(@NotNull T settingsInfo, String text) {
|
||||
return skipText(settingsInfo, text,
|
||||
settingsInfo.appSettings.lineInclude, settingsInfo.appSettings.lineExclude,
|
||||
settingsInfo.globalSettings.lineInclude, settingsInfo.globalSettings.lineExclude,
|
||||
settingsInfo.projectSettings.lineInclude, settingsInfo.projectSettings.lineExclude);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DocSkip {
|
||||
return true;
|
||||
}
|
||||
return skipText(settingsInfo, text,
|
||||
settingsInfo.appSettings.docInclude, settingsInfo.appSettings.docExclude,
|
||||
settingsInfo.globalSettings.docInclude, settingsInfo.globalSettings.docExclude,
|
||||
settingsInfo.projectSettings.docInclude, settingsInfo.projectSettings.docExclude);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
public class AppSettingsComponent {
|
||||
|
||||
private final JPanel myMainPanel;
|
||||
private final JBCheckBox showTreeComment = new JBCheckBox(ShowBundle.message("show.tree.comment"));
|
||||
@@ -93,7 +93,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
.addSeparator()
|
||||
.addComponent(text)
|
||||
.addSeparator();
|
||||
return commonLineEndFilter(formBuilder);
|
||||
return formBuilder.getPanel();
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "// Show Comment Global";
|
||||
return "// Show Comment App";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -66,9 +66,6 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
modified |= mySettingsComponent.getSkipAnnotation() != settings.skipAnnotation;
|
||||
modified |= mySettingsComponent.getSkipAscii() != settings.skipAscii;
|
||||
modified |= mySettingsComponent.getSkipBlank() != settings.skipBlank;
|
||||
|
||||
modified = AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, modified);
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -110,8 +107,6 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
settings.skipAnnotation = mySettingsComponent.getSkipAnnotation();
|
||||
settings.skipAscii = mySettingsComponent.getSkipAscii();
|
||||
settings.skipBlank = mySettingsComponent.getSkipBlank();
|
||||
|
||||
AbstractSettingsConfigurable.apply(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,8 +147,6 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
mySettingsComponent.setSkipAnnotation(settings.skipAnnotation);
|
||||
mySettingsComponent.setSkipAscii(settings.skipAscii);
|
||||
mySettingsComponent.setSkipBlank(settings.skipBlank);
|
||||
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Locale;
|
||||
name = "io.github.linwancen.plugin.show.settings.AppSettingsState",
|
||||
storages = @Storage("ShowCommentGlobal.xml")
|
||||
)
|
||||
public class AppSettingsState extends AbstractSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
public class AppSettingsState implements PersistentStateComponent<AppSettingsState> {
|
||||
|
||||
public static final AppSettingsState DEFAULT_SETTING = new AppSettingsState();
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GlobalSettingsComponent extends AbstractSettingsComponent {
|
||||
|
||||
private final JPanel myMainPanel;
|
||||
public GlobalSettingsComponent() {
|
||||
@NotNull JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
|
||||
resetDefault.addActionListener(e -> GlobalSettingsConfigurable.reset(GlobalSettingsState.DEFAULT_SETTING, this));
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(JPanelFactory.of(resetDefault), 1)
|
||||
.addComponent(lineEndFilterPanel(), 1)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JPanel lineEndFilterPanel() {
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
.addSeparator();
|
||||
return commonLineEndFilter(formBuilder);
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GlobalSettingsConfigurable implements Configurable {
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NotNull
|
||||
private GlobalSettingsComponent mySettingsComponent;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "// Show Comment Global";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return mySettingsComponent.getPreferredFocusedComponent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
mySettingsComponent = new GlobalSettingsComponent();
|
||||
return mySettingsComponent.getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
@NotNull GlobalSettingsState settings = GlobalSettingsState.getInstance();
|
||||
return AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
@NotNull GlobalSettingsState settings = GlobalSettingsState.getInstance();
|
||||
AbstractSettingsConfigurable.apply(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
@NotNull GlobalSettingsState settings = GlobalSettingsState.getInstance();
|
||||
reset(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
static void reset(@NotNull GlobalSettingsState settings, GlobalSettingsComponent mySettingsComponent1) {
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
//noinspection ConstantConditions
|
||||
mySettingsComponent = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.github.linwancen.plugin.show.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.show.settings.GlobalSettingsState",
|
||||
storages = @Storage("ShowCommentGlobal.xml")
|
||||
)
|
||||
public class GlobalSettingsState extends AbstractSettingsState implements PersistentStateComponent<GlobalSettingsState> {
|
||||
|
||||
public static final GlobalSettingsState DEFAULT_SETTING = new GlobalSettingsState();
|
||||
|
||||
@NotNull
|
||||
public static GlobalSettingsState getInstance() {
|
||||
GlobalSettingsState service = ApplicationManager.getApplication().getService(GlobalSettingsState.class);
|
||||
if (service == null) {
|
||||
return new GlobalSettingsState();
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GlobalSettingsState getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(@NotNull GlobalSettingsState state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,14 @@ import javax.swing.*;
|
||||
public class ProjectSettingsComponent extends AbstractSettingsComponent {
|
||||
|
||||
private final JPanel myMainPanel;
|
||||
private final JBCheckBox globalFilterEffective = new JBCheckBox(ShowBundle.message("global.include.exclude.effective"));
|
||||
private final JBCheckBox projectFilterEffective = new JBCheckBox(ShowBundle.message("project.include.exclude.effective"));
|
||||
private final JBCheckBox globalFilterEffective = new JBCheckBox(ShowBundle.message("global.settings.effective"));
|
||||
private final JBCheckBox projectFilterEffective = new JBCheckBox(ShowBundle.message("project.settings.effective"));
|
||||
|
||||
public ProjectSettingsComponent() {
|
||||
@NotNull JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
|
||||
resetDefault.addActionListener(e -> ProjectSettingsConfigurable.reset(ProjectSettingsState.DEFAULT_SETTING, this));
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(JPanelFactory.of(resetDefault, globalFilterEffective, projectFilterEffective), 1)
|
||||
.addComponent(lineEndFilterPanel(), 1)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
@@ -22,8 +25,6 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent {
|
||||
@NotNull
|
||||
protected JPanel lineEndFilterPanel() {
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
.addComponent(globalFilterEffective)
|
||||
.addComponent(projectFilterEffective)
|
||||
.addSeparator();
|
||||
return commonLineEndFilter(formBuilder);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,13 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
@Override
|
||||
public void reset() {
|
||||
@NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
mySettingsComponent.setGlobalFilterEffective(settings.globalFilterEffective);
|
||||
mySettingsComponent.setProjectFilterEffective(settings.projectFilterEffective);
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent);
|
||||
reset(settings, mySettingsComponent);
|
||||
}
|
||||
|
||||
static void reset(@NotNull ProjectSettingsState settings, ProjectSettingsComponent mySettingsComponent1) {
|
||||
mySettingsComponent1.setGlobalFilterEffective(settings.globalFilterEffective);
|
||||
mySettingsComponent1.setProjectFilterEffective(settings.projectFilterEffective);
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
)
|
||||
public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent<ProjectSettingsState> {
|
||||
|
||||
public static final ProjectSettingsState DEFAULT_SETTING = new ProjectSettingsState();
|
||||
|
||||
public boolean globalFilterEffective = true;
|
||||
public boolean projectFilterEffective = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user