project setting line count

This commit is contained in:
林万程
2023-11-16 23:33:42 +08:00
parent 1d77389b74
commit 89127e5879
18 changed files with 57 additions and 43 deletions

View File

@@ -137,7 +137,7 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
if (appendElementText(sb, element)) {
lineCount++;
}
if (DocFilter.lineCountOrLenOver(lineInfo.appSettings, sb, lineCount)) {
if (DocFilter.lineCountOrLenOver(lineInfo, sb, lineCount)) {
break;
}
}

View File

@@ -55,7 +55,7 @@ public class KotlinLangDoc extends BaseTagLangDoc<KDocSection> {
@Override
protected <T extends SettingsInfo> String descDoc(@NotNull T lineInfo, @NotNull KDocSection kDocSection) {
@NotNull String content = kDocSection.getContent();
return DocFilter.cutDoc(content, lineInfo.appSettings, false);
return DocFilter.cutDoc(content, lineInfo, false);
}
@Override
@@ -64,7 +64,7 @@ public class KotlinLangDoc extends BaseTagLangDoc<KDocSection> {
@NotNull List<KDocTag> tags = kDocSection.findTagsByName(name);
for (@NotNull KDocTag tag : tags) {
@NotNull String content = tag.getContent();
@NotNull String cutDoc = DocFilter.cutDoc(content, lineInfo.appSettings, false);
@NotNull String cutDoc = DocFilter.cutDoc(content, lineInfo, false);
tagStrBuilder.append(cutDoc);
}
}

View File

@@ -18,7 +18,6 @@ public class CopyReferenceSimple extends CopyReferenceAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("copy.class.method.or.file.line"));
}

View File

@@ -27,7 +27,6 @@ public class LineEndAdd extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("line.end.add"));
}

View File

@@ -25,7 +25,6 @@ public class LineEndCopy extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("line.end.copy"));
}

View File

@@ -20,7 +20,6 @@ public class ReloadExtDocAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("reload.ext.doc"));
}

View File

@@ -21,7 +21,6 @@ public class ResetExtDocAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("reset.ext.doc"));
}

View File

@@ -11,7 +11,7 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.lang.base.BaseTagLangDoc;
import io.github.linwancen.plugin.show.lang.base.DocFilter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,7 +56,7 @@ public class PythonLangDoc extends BaseTagLangDoc<StructuredDocString> {
return summary;
}
@NotNull String description = structuredDocString.getDescription();
return DocFilter.cutDoc(DocFilter.html2Text(description), lineInfo.appSettings, false);
return DocFilter.cutDoc(DocFilter.html2Text(description), lineInfo, false);
}
@Override
@@ -66,7 +66,7 @@ public class PythonLangDoc extends BaseTagLangDoc<StructuredDocString> {
if (structuredDocString instanceof TagBasedDocString) {
@Nullable Substring tagValue = ((TagBasedDocString) structuredDocString).getTagValue(name);
if (tagValue != null) {
@NotNull String cutDoc = DocFilter.cutDoc(tagValue.getValue(), lineInfo.appSettings, false);
@NotNull String cutDoc = DocFilter.cutDoc(tagValue.getValue(), lineInfo, false);
tagStrBuilder.append(cutDoc);
}
}

View File

@@ -182,7 +182,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
if (s == null) {
return null;
}
@NotNull String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true);
@NotNull String cutDoc = DocFilter.cutDoc(s, lineInfo, true);
@NotNull String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.globalSettings, lineInfo.projectSettings);
if (filterDoc.trim().isEmpty()) {
return null;

View File

@@ -1,5 +1,7 @@
package io.github.linwancen.plugin.show.lang.base;
import io.github.linwancen.plugin.show.bean.SettingsInfo;
import io.github.linwancen.plugin.show.settings.AbstractSettingsState;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
@@ -32,8 +34,7 @@ public class DocFilter {
* end with space
*/
@NotNull
public static String cutDoc(String text,
@NotNull AppSettingsState appSettings, boolean deletePrefix) {
public static <T extends SettingsInfo> String cutDoc(String text, @NotNull T info, boolean deletePrefix) {
String[] split = LINE_SEPARATOR_PATTERN.split(text);
int lineCount = 0;
@NotNull StringBuilder sb = new StringBuilder();
@@ -47,13 +48,24 @@ public class DocFilter {
sb.append(" ");
}
lineCount++;
if (lineCountOrLenOver(appSettings, sb, lineCount)) break;
if (lineCountOrLenOver(info, sb, lineCount)) break;
}
return sb.toString();
}
public static boolean lineCountOrLenOver(@NotNull AppSettingsState appSettings,
@NotNull StringBuilder sb, int lineCount) {
public static <T extends SettingsInfo> boolean lineCountOrLenOver(@NotNull T info,
@NotNull StringBuilder sb, int lineCount) {
if (info.projectSettings.projectFilterEffective) {
return lineCountOrLenOverInfo(info.projectSettings, sb, lineCount);
} else if (info.projectSettings.globalFilterEffective) {
return lineCountOrLenOverInfo(info.globalSettings, sb, lineCount);
} else {
return false;
}
}
private static boolean lineCountOrLenOverInfo(@NotNull AbstractSettingsState appSettings,
@NotNull StringBuilder sb, int lineCount) {
boolean countOver = appSettings.lineEndCount > 0 && lineCount >= appSettings.lineEndCount;
boolean lenOver = appSettings.lineEndLen > 0 && sb.length() >= appSettings.lineEndLen;
return countOver || lenOver;

View File

@@ -9,10 +9,11 @@ import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public abstract class AbstractSettingsComponent {
protected final JBTextField lineEndCount = new JBTextField();
private final JBTextField lineInclude = new JBTextField();
private final JBTextField lineExclude = new JBTextField();
@@ -43,21 +44,31 @@ public abstract class AbstractSettingsComponent {
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.include.regexp")), docInclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.exclude.regexp")), docExclude, 1, true)
.addSeparator();
JPanel label = JPanelFactory.of(docGetEffect, new JBLabel(ShowBundle.message("get.doc.regexp")));
@NotNull JPanel label = JPanelFactory.of(docGetEffect, new JBLabel(ShowBundle.message("get.doc.regexp")));
JPanel panel = builder
.addLabeledComponent(label, docGet, 1, true).getPanel();
panel.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("line.end.comment")));
return panel;
}
@NotNull
private JPanel treePanel() {
JPanel label = JPanelFactory.of(projectDocEffect, new JBLabel(ShowBundle.message("project.doc.regexp")));
@NotNull JPanel label = JPanelFactory.of(projectDocEffect, new JBLabel(ShowBundle.message("project.doc.regexp")));
JPanel panel = FormBuilder.createFormBuilder()
.addLabeledComponent(label, projectDoc, 1, true).getPanel();
panel.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("tree.comment")));
return panel;
}
@NotNull
public String getLineEndCount() {
return lineEndCount.getText();
}
public void setLineEndCount(@NotNull String newText) {
lineEndCount.setText(newText);
}
@NotNull
public String getLineInclude() {
return lineInclude.getText();

View File

@@ -8,6 +8,7 @@ public class AbstractSettingsConfigurable {
static boolean isModified(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component,
boolean modified) {
modified |= !component.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
modified |= !component.getLineInclude().equals(settings.getLineInclude());
modified |= !component.getLineExclude().equals(settings.getLineExclude());
modified |= !component.getDocInclude().equals(settings.getDocInclude());
@@ -20,6 +21,11 @@ public class AbstractSettingsConfigurable {
}
static void apply(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
try {
settings.lineEndCount = Integer.parseInt(component.getLineEndCount());
} catch (NumberFormatException e) {
component.setLineEndCount(String.valueOf(settings.lineEndCount));
}
settings.setLineInclude(component.getLineInclude());
settings.setLineExclude(component.getLineExclude());
settings.setDocInclude(component.getDocInclude());
@@ -31,6 +37,7 @@ public class AbstractSettingsConfigurable {
}
static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
component.setLineEndCount(String.valueOf(settings.lineEndCount));
component.setLineInclude(settings.getLineInclude());
component.setLineExclude(settings.getLineExclude());
component.setDocInclude(settings.getDocInclude());

View File

@@ -9,6 +9,8 @@ import java.util.stream.Stream;
public abstract class AbstractSettingsState {
public int lineEndCount = 2;
public int lineEndLen = 0;
@NotNull
public transient Pattern lineInclude = Pattern.compile("");
@NotNull

View File

@@ -41,13 +41,12 @@ public class AppSettingsComponent {
private final ColorPanel lineEndColor = new ColorPanel();
private final ColorPanel lineEndJsonColor = new ColorPanel();
private final JBTextField lineEndPrefix = new JBTextField();
private final JBTextField lineEndCount = new JBTextField();
public AppSettingsComponent() {
@NotNull JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
resetDefault.addActionListener(e -> AppSettingsConfigurable.reset(AppSettingsState.DEFAULT_SETTING, this));
myMainPanel = FormBuilder.createFormBuilder()
.addComponent(resetDefault, 1)
.addComponent(JPanelFactory.of(resetDefault), 1)
.addComponent(showPanel(), 1)
.addComponent(lineEndFilterPanel(), 1)
.addComponentFillVertically(new JPanel(), 0)
@@ -83,7 +82,6 @@ public class AppSettingsComponent {
@NotNull
protected JPanel lineEndFilterPanel() {
@NotNull JPanel text = JPanelFactory.of(
new JBLabel(ShowBundle.message("line.count")), lineEndCount,
new JBLabel(ShowBundle.message("text.color")), lineEndColor,
new JBLabel(ShowBundle.message("text.color.json")), lineEndJsonColor,
new JBLabel(ShowBundle.message("prefix")), lineEndPrefix);
@@ -321,13 +319,4 @@ public class AppSettingsComponent {
public void setLineEndPrefix(@NotNull String newText) {
lineEndPrefix.setText(newText);
}
@NotNull
public String getLineEndCount() {
return lineEndCount.getText();
}
public void setLineEndCount(@NotNull String newText) {
lineEndCount.setText(newText);
}
}

View File

@@ -55,7 +55,6 @@ public class AppSettingsConfigurable implements Configurable {
modified |= !mySettingsComponent.getTreeTags().equals(String.join("|", settings.treeTags));
modified |= !mySettingsComponent.getLineTags().equals(String.join("|", settings.lineTags));
modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
modified |= !settings.lineEndTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndColor());
modified |= !settings.lineEndJsonTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndJsonColor());
modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix);
@@ -92,11 +91,6 @@ public class AppSettingsConfigurable implements Configurable {
settings.treeTags = Splitter.on('|').splitToList(mySettingsComponent.getTreeTags()).toArray(new String[0]);
settings.lineTags = Splitter.on('|').splitToList(mySettingsComponent.getLineTags()).toArray(new String[0]);
try {
settings.lineEndCount = Integer.parseInt(mySettingsComponent.getLineEndCount());
} catch (NumberFormatException e) {
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
}
settings.lineEndTextAttr.setForegroundColor(mySettingsComponent.getLineEndColor());
settings.lineEndJsonTextAttr.setForegroundColor(mySettingsComponent.getLineEndJsonColor());
settings.lineEndPrefix = mySettingsComponent.getLineEndPrefix();
@@ -136,7 +130,6 @@ public class AppSettingsConfigurable implements Configurable {
mySettingsComponent.setTreeTags(String.join("|", settings.treeTags));
mySettingsComponent.setLineTags(String.join("|", settings.lineTags));
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
mySettingsComponent.setLineEndColor(settings.lineEndTextAttr.getForegroundColor());
mySettingsComponent.setLineEndJsonColor(settings.lineEndJsonTextAttr.getForegroundColor());
mySettingsComponent.setLineEndPrefix(settings.lineEndPrefix);

View File

@@ -53,8 +53,6 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
@NotNull
public String lineEndPrefix = " // ";
public int lineEndCount = 2;
public int lineEndLen = 0;
public boolean getToSet = true;
public boolean fromNew = true;
public boolean fromParam = false;

View File

@@ -1,5 +1,6 @@
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;
@@ -12,7 +13,9 @@ public class GlobalSettingsComponent extends AbstractSettingsComponent {
@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(JPanelFactory.of(resetDefault,
new JBLabel(ShowBundle.message("line.count")), lineEndCount
), 1)
.addComponent(commonPanel(), 1)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();

View File

@@ -1,6 +1,7 @@
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;
@@ -16,7 +17,10 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent {
@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(JPanelFactory.of(resetDefault,
new JBLabel(ShowBundle.message("line.count")), lineEndCount,
globalFilterEffective, projectFilterEffective
), 1)
.addComponent(commonPanel(), 1)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();