Split app and global settings
This commit is contained in:
@@ -5,6 +5,7 @@ plugins {
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.10.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
description "Show comment at the Project View Tree, line End, JSON, other"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -139,8 +139,13 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
<applicationConfigurable parentId="tools"
|
||||
instance="io.github.linwancen.plugin.show.settings.AppSettingsConfigurable"
|
||||
id="io.github.linwancen.plugin.show.settings.AppSettingsConfigurable"
|
||||
displayName="// Show Comment Global"/>
|
||||
displayName="// Show Comment App"/>
|
||||
<applicationService serviceImplementation="io.github.linwancen.plugin.show.settings.AppSettingsState"/>
|
||||
<applicationConfigurable parentId="io.github.linwancen.plugin.show.settings.AppSettingsConfigurable"
|
||||
instance="io.github.linwancen.plugin.show.settings.GlobalSettingsConfigurable"
|
||||
id="io.github.linwancen.plugin.show.settings.GlobalSettingsComponent"
|
||||
displayName="// Show Comment Global"/>
|
||||
<applicationService serviceImplementation="io.github.linwancen.plugin.show.settings.GlobalSettingsState"/>
|
||||
<projectConfigurable parentId="io.github.linwancen.plugin.show.settings.AppSettingsConfigurable"
|
||||
instance="io.github.linwancen.plugin.show.settings.ProjectSettingsConfigurable"
|
||||
id="io.github.linwancen.plugin.show.settings.ProjectSettingsConfigurable"
|
||||
|
||||
@@ -27,8 +27,8 @@ comment.include.regexp=comment include Regexp:
|
||||
comment.exclude.regexp=comment exclude Regexp:
|
||||
get.doc.regexp=get doc Regexp, last () when had, default is first sentence .+?(?:[\u3002\r\n]|. ) :
|
||||
|
||||
global.include.exclude.effective=Global Include Exclude Effective
|
||||
project.include.exclude.effective=Project Include Exclude Effective
|
||||
global.settings.effective=Global Settings Effective
|
||||
project.settings.effective=Project Settings Effective
|
||||
|
||||
reload.ext.doc=\uD83D\uDD04 // Reload External Comment
|
||||
reset.ext.doc=\uD83C\uDD91 // Clear External Comment
|
||||
|
||||
@@ -27,8 +27,8 @@ comment.include.regexp=\u6CE8\u91CA \u5305\u542B \u6B63\u5219\uFF1A
|
||||
comment.exclude.regexp=\u6CE8\u91CA \u6392\u9664 \u6B63\u5219\uFF1A
|
||||
get.doc.regexp=\u6CE8\u91CA\u63D0\u53D6\u6B63\u5219\uFF0C\u82E5\u6709 () \u5219\u53D6\u6700\u540E\u4E00\u4E2A\uFF0C\u9ED8\u8BA4\u6B63\u5219\u662F\u7B2C\u4E00\u53E5 .+?(?:[\u3002\r\n]|. ) :
|
||||
|
||||
global.include.exclude.effective=\u5168\u5C40\u5305\u542B\u6392\u9664\u751F\u6548
|
||||
project.include.exclude.effective=\u9879\u76EE\u5305\u542B\u6392\u9664\u751F\u6548
|
||||
global.settings.effective=\u5168\u5C40\u914D\u7F6E\u751F\u6548
|
||||
project.settings.effective=\u9879\u76EE\u914D\u7F6E\u751F\u6548
|
||||
|
||||
reload.ext.doc=\uD83D\uDD04 // \u91CD\u65B0\u8BFB\u53D6\u5916\u90E8\u6CE8\u91CA
|
||||
reset.ext.doc=\uD83C\uDD91 // \u6E05\u7406\u5916\u90E8\u6CE8\u91CA
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.linwancen.plugin.show.lang.base;
|
||||
|
||||
import io.github.linwancen.plugin.show.lang.base.DocFilter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -32,7 +31,7 @@ class DocFilterTest {
|
||||
};
|
||||
|
||||
/**
|
||||
* @see DocFilter#filterDoc
|
||||
* @see DocFilter#filterPattern
|
||||
*/
|
||||
@Test
|
||||
void testGetDoc() {
|
||||
@@ -40,7 +39,7 @@ class DocFilterTest {
|
||||
Pattern p = PATTERNS[pi];
|
||||
for (int si = 0; si < STRS.length; si++) {
|
||||
String s = STRS[si];
|
||||
@Nullable String doc = DocFilter.filterDoc(s, p);
|
||||
@Nullable String doc = DocFilter.filterPattern(s, p);
|
||||
String pattern = p.pattern();
|
||||
System.out.println("(" + s + ", " + pattern + "): " + doc);
|
||||
if (pi < 2) {
|
||||
|
||||
Reference in New Issue
Block a user