rename prefix to path-prefix

This commit is contained in:
Marcel Haßlinger 2021-09-19 22:00:26 +02:00
parent e7479b17b9
commit 3f09556d1d
6 changed files with 35 additions and 32 deletions

View File

@ -26,8 +26,8 @@ public class SettingsDialog {
private TextFieldWithBrowseButton pathText; private TextFieldWithBrowseButton pathText;
private JBTextField filePatternText; private JBTextField filePatternText;
private JBTextField previewText; private JBTextField previewLocaleText;
private JBTextField prefixText; private JBTextField pathPrefixText;
private JBCheckBox codeAssistanceCheckbox; private JBCheckBox codeAssistanceCheckbox;
public SettingsDialog(Project project) { public SettingsDialog(Project project) {
@ -38,24 +38,25 @@ public class SettingsDialog {
String localesPath = SettingsService.getInstance(project).getState().getLocalesPath(); String localesPath = SettingsService.getInstance(project).getState().getLocalesPath();
String filePattern = SettingsService.getInstance(project).getState().getFilePattern(); String filePattern = SettingsService.getInstance(project).getState().getFilePattern();
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale(); String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
String prefixLocale = SettingsService.getInstance(project).getState().getPrefix(); String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();
boolean codeAssistance = SettingsService.getInstance(project).getState().isCodeAssistance(); boolean codeAssistance = SettingsService.getInstance(project).getState().isCodeAssistance();
if(prepare(localesPath, filePattern, previewLocale, prefixLocale, codeAssistance).show() == DialogWrapper.OK_EXIT_CODE) { // Save changes if(prepare(localesPath, filePattern, previewLocale, pathPrefix, codeAssistance).show() == DialogWrapper.OK_EXIT_CODE) { // Save changes
SettingsService.getInstance(project).getState().setLocalesPath(pathText.getText()); SettingsService.getInstance(project).getState().setLocalesPath(pathText.getText());
SettingsService.getInstance(project).getState().setFilePattern(filePatternText.getText()); SettingsService.getInstance(project).getState().setFilePattern(filePatternText.getText());
SettingsService.getInstance(project).getState().setPreviewLocale(previewText.getText()); SettingsService.getInstance(project).getState().setPreviewLocale(previewLocaleText.getText());
SettingsService.getInstance(project).getState().setCodeAssistance(codeAssistanceCheckbox.isSelected()); SettingsService.getInstance(project).getState().setCodeAssistance(codeAssistanceCheckbox.isSelected());
SettingsService.getInstance(project).getState().setPrefix(prefixText.getText()); SettingsService.getInstance(project).getState().setPathPrefix(pathPrefixText.getText());
// Reload instance // Reload instance
DataStore.getInstance(project).reloadFromDisk(); DataStore.getInstance(project).reloadFromDisk();
} }
} }
private DialogBuilder prepare(String localesPath, String filePattern, String previewLocale, String prefixLocale, boolean codeAssistance) { private DialogBuilder prepare(String localesPath, String filePattern, String previewLocale, String pathPrefix, boolean codeAssistance) {
JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2)); JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2));
/* path */
JBLabel pathLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.text")); JBLabel pathLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.text"));
pathText = new TextFieldWithBrowseButton(new JTextField(localesPath)); pathText = new TextFieldWithBrowseButton(new JTextField(localesPath));
@ -66,28 +67,32 @@ public class SettingsDialog {
rootPanel.add(pathLabel); rootPanel.add(pathLabel);
rootPanel.add(pathText); rootPanel.add(pathText);
/* file pattern */
JBLabel filePatternLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.file-pattern")); JBLabel filePatternLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.file-pattern"));
filePatternText = new JBTextField(filePattern); filePatternText = new JBTextField(filePattern);
rootPanel.add(filePatternLabel); rootPanel.add(filePatternLabel);
rootPanel.add(filePatternText); rootPanel.add(filePatternText);
/* preview locale */
JBLabel previewLocaleLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.preview"));
previewLocaleText = new JBTextField(previewLocale);
previewLocaleLabel.setLabelFor(previewLocaleText);
JBLabel previewLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.preview")); rootPanel.add(previewLocaleLabel);
previewText = new JBTextField(previewLocale); rootPanel.add(previewLocaleText);
previewLabel.setLabelFor(previewText);
rootPanel.add(previewLabel); /* path prefix */
rootPanel.add(previewText); JBLabel pathPrefixLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.prefix"));
pathPrefixText = new JBTextField(pathPrefix);
rootPanel.add(pathPrefixLabel);
rootPanel.add(pathPrefixText);
/* code assistance */
codeAssistanceCheckbox = new JBCheckBox(ResourceBundle.getBundle("messages").getString("settings.editor.assistance")); codeAssistanceCheckbox = new JBCheckBox(ResourceBundle.getBundle("messages").getString("settings.editor.assistance"));
codeAssistanceCheckbox.setSelected(codeAssistance); codeAssistanceCheckbox.setSelected(codeAssistance);
JBLabel prefixLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.prefix"));
prefixText = new JBTextField(prefixLocale);
rootPanel.add(prefixLabel);
rootPanel.add(prefixText);
rootPanel.add(codeAssistanceCheckbox); rootPanel.add(codeAssistanceCheckbox);
DialogBuilder builder = new DialogBuilder(); DialogBuilder builder = new DialogBuilder();

View File

@ -28,13 +28,13 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
} }
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale(); String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
String prefix = SettingsService.getInstance(project).getState().getPrefix(); String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();
String path = result.getPrefixMatcher().getPrefix(); String path = result.getPrefixMatcher().getPrefix();
DataStore instance = DataStore.getInstance(project); DataStore instance = DataStore.getInstance(project);
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
collect(map, instance.getTranslations().getNodes(), null, previewLocale, prefix); collect(map, instance.getTranslations().getNodes(), null, previewLocale, pathPrefix);
Map<String, String> containedPath = new HashMap<>(); Map<String, String> containedPath = new HashMap<>();
StringBuilder prefixedKey = new StringBuilder(); StringBuilder prefixedKey = new StringBuilder();
int maxPrefixLookUpLength = 5; int maxPrefixLookUpLength = 5;
@ -55,16 +55,16 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
}); });
} }
private void collect(Map<String, String> map, LocalizedNode node, String path, String locale, String prefix) { private void collect(Map<String, String> map, LocalizedNode node, String path, String locale, String pathPrefix) {
if (node.isLeaf() && !node.getKey().equals(LocalizedNode.ROOT_KEY)) { if (node.isLeaf() && !node.getKey().equals(LocalizedNode.ROOT_KEY)) {
String value = node.getValue().get(locale); String value = node.getValue().get(locale);
map.put(path, value); map.put(path, value);
if (prefix != null && !prefix.isEmpty()) { if (pathPrefix != null && !pathPrefix.isEmpty()) {
map.put(prefix + "." + path, value); map.put(pathPrefix + "." + path, value);
} }
} else { } else {
for (LocalizedNode child : node.getChildren()) { for (LocalizedNode child : node.getChildren()) {
collect(map, child, path == null || path.isEmpty() ? child.getKey() : path + "." + child.getKey(), locale, prefix); collect(map, child, path == null || path.isEmpty() ? child.getKey() : path + "." + child.getKey(), locale, pathPrefix);
} }
} }
} }

View File

@ -2,7 +2,6 @@ package de.marhali.easyi18n.editor.generic;
import com.intellij.codeInsight.completion.CompletionContributor; import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionType; import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.lang.*;
import com.intellij.patterns.*; import com.intellij.patterns.*;
import com.intellij.psi.*; import com.intellij.psi.*;
import com.intellij.psi.xml.*; import com.intellij.psi.xml.*;

View File

@ -16,7 +16,7 @@ public class SettingsState {
private String localesPath; private String localesPath;
private String filePattern; private String filePattern;
private String previewLocale; private String previewLocale;
private String prefix; private String pathPrefix;
private Boolean codeAssistance; private Boolean codeAssistance;
public SettingsState() {} public SettingsState() {}
@ -53,11 +53,11 @@ public class SettingsState {
this.codeAssistance = codeAssistance; this.codeAssistance = codeAssistance;
} }
public void setPrefix(String prefix) { public void setPathPrefix(String pathPrefix) {
this.prefix = prefix; this.pathPrefix = pathPrefix;
} }
public String getPrefix() { public String getPathPrefix() {
return prefix; return pathPrefix;
} }
} }

View File

@ -4,7 +4,6 @@ import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State; import com.intellij.openapi.components.State;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.util.xmlb.XmlSerializerUtil;
import de.marhali.easyi18n.model.SettingsState; import de.marhali.easyi18n.model.SettingsState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -14,6 +14,6 @@ translation.locales=Locales
settings.path.title=Locales Directory settings.path.title=Locales Directory
settings.path.text=Locales directory settings.path.text=Locales directory
settings.path.file-pattern=Translation file pattern settings.path.file-pattern=Translation file pattern
settings.path.prefix=Path prefix
settings.preview=Preview locale settings.preview=Preview locale
settings.editor.assistance=I18n key completion and annotation inside editor settings.editor.assistance=I18n key completion and annotation inside editor
settings.path.prefix=Prefix