add new configuration options for enhanced io system
This commit is contained in:
parent
d2bd18e322
commit
5f16d14524
@ -2,15 +2,20 @@ package de.marhali.easyi18n.dialog;
|
|||||||
|
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.ui.ComboBox;
|
||||||
import com.intellij.openapi.ui.DialogBuilder;
|
import com.intellij.openapi.ui.DialogBuilder;
|
||||||
import com.intellij.openapi.ui.DialogWrapper;
|
import com.intellij.openapi.ui.DialogWrapper;
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
import com.intellij.ui.components.JBCheckBox;
|
import com.intellij.ui.components.JBCheckBox;
|
||||||
import com.intellij.ui.components.JBLabel;
|
import com.intellij.ui.components.JBLabel;
|
||||||
|
import com.intellij.ui.components.JBPanel;
|
||||||
import com.intellij.ui.components.JBTextField;
|
import com.intellij.ui.components.JBTextField;
|
||||||
|
|
||||||
import de.marhali.easyi18n.InstanceManager;
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
|
import de.marhali.easyi18n.io.ArrayMapper;
|
||||||
|
import de.marhali.easyi18n.model.FolderStrategy;
|
||||||
import de.marhali.easyi18n.model.SettingsState;
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
|
import de.marhali.easyi18n.model.bus.ParserStrategy;
|
||||||
import de.marhali.easyi18n.service.SettingsService;
|
import de.marhali.easyi18n.service.SettingsService;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -26,6 +31,8 @@ public class SettingsDialog {
|
|||||||
private final Project project;
|
private final Project project;
|
||||||
|
|
||||||
private TextFieldWithBrowseButton pathText;
|
private TextFieldWithBrowseButton pathText;
|
||||||
|
private ComboBox<String> folderStrategyComboBox;
|
||||||
|
private ComboBox<String> parserStrategyComboBox;
|
||||||
private JBTextField filePatternText;
|
private JBTextField filePatternText;
|
||||||
private JBTextField previewLocaleText;
|
private JBTextField previewLocaleText;
|
||||||
private JBTextField pathPrefixText;
|
private JBTextField pathPrefixText;
|
||||||
@ -42,6 +49,8 @@ public class SettingsDialog {
|
|||||||
|
|
||||||
if(prepare(state).show() == DialogWrapper.OK_EXIT_CODE) { // Save changes
|
if(prepare(state).show() == DialogWrapper.OK_EXIT_CODE) { // Save changes
|
||||||
state.setLocalesPath(pathText.getText());
|
state.setLocalesPath(pathText.getText());
|
||||||
|
state.setFolderStrategy(FolderStrategy.fromIndex(folderStrategyComboBox.getSelectedIndex()));
|
||||||
|
state.setParserStrategy(ParserStrategy.fromIndex(parserStrategyComboBox.getSelectedIndex()));
|
||||||
state.setFilePattern(filePatternText.getText());
|
state.setFilePattern(filePatternText.getText());
|
||||||
state.setPreviewLocale(previewLocaleText.getText());
|
state.setPreviewLocale(previewLocaleText.getText());
|
||||||
state.setPathPrefix(pathPrefixText.getText());
|
state.setPathPrefix(pathPrefixText.getText());
|
||||||
@ -57,29 +66,57 @@ public class SettingsDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DialogBuilder prepare(SettingsState state) {
|
private DialogBuilder prepare(SettingsState state) {
|
||||||
|
ResourceBundle bundle = ResourceBundle.getBundle("messages");
|
||||||
JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2));
|
JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2));
|
||||||
|
|
||||||
/* path */
|
/* path */
|
||||||
JBLabel pathLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.text"));
|
JBLabel pathLabel = new JBLabel(bundle.getString("settings.path.text"));
|
||||||
pathText = new TextFieldWithBrowseButton(new JTextField(state.getLocalesPath()));
|
pathText = new TextFieldWithBrowseButton(new JTextField(state.getLocalesPath()));
|
||||||
|
|
||||||
pathLabel.setLabelFor(pathText);
|
pathLabel.setLabelFor(pathText);
|
||||||
pathText.addBrowseFolderListener(ResourceBundle.getBundle("messages").getString("settings.path.title"), null, project, new FileChooserDescriptor(
|
pathText.addBrowseFolderListener(bundle.getString("settings.path.title"), null, project, new FileChooserDescriptor(
|
||||||
false, true, false, false, false, false));
|
false, true, false, false, false, false));
|
||||||
|
|
||||||
rootPanel.add(pathLabel);
|
rootPanel.add(pathLabel);
|
||||||
rootPanel.add(pathText);
|
rootPanel.add(pathText);
|
||||||
|
|
||||||
/* file pattern */
|
JBLabel strategyLabel = new JBLabel(bundle.getString("settings.strategy.title"));
|
||||||
JBLabel filePatternLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.file-pattern"));
|
rootPanel.add(strategyLabel);
|
||||||
filePatternText = new JBTextField(state.getFilePattern());
|
|
||||||
filePatternText.setToolTipText(ResourceBundle.getBundle("messages").getString("settings.path.file-pattern-tooltip"));
|
|
||||||
|
|
||||||
rootPanel.add(filePatternLabel);
|
JPanel strategyPanel = new JBPanel<>(new GridBagLayout());
|
||||||
rootPanel.add(filePatternText);
|
rootPanel.add(strategyPanel);
|
||||||
|
GridBagConstraints constraints = new GridBagConstraints();
|
||||||
|
|
||||||
|
/* folder strategy */
|
||||||
|
folderStrategyComboBox = new ComboBox<>(bundle.getString("settings.strategy.folder").split(ArrayMapper.SPLITERATOR_REGEX));
|
||||||
|
folderStrategyComboBox.setSelectedIndex(state.getFolderStrategy().toIndex());
|
||||||
|
folderStrategyComboBox.setToolTipText(bundle.getString("settings.strategy.folder.tooltip"));
|
||||||
|
folderStrategyComboBox.setMinimumAndPreferredWidth(256);
|
||||||
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
constraints.gridx = 0;
|
||||||
|
constraints.gridy = 0;
|
||||||
|
strategyPanel.add(folderStrategyComboBox, constraints);
|
||||||
|
|
||||||
|
/* parser strategy */
|
||||||
|
parserStrategyComboBox = new ComboBox<>(bundle.getString("settings.strategy.parser").split(ArrayMapper.SPLITERATOR_REGEX));
|
||||||
|
parserStrategyComboBox.setSelectedIndex(state.getParserStrategy().toIndex());
|
||||||
|
parserStrategyComboBox.setToolTipText(bundle.getString("settings.strategy.parser.tooltip"));
|
||||||
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
constraints.gridx = 1;
|
||||||
|
constraints.gridy = 0;
|
||||||
|
strategyPanel.add(parserStrategyComboBox, constraints);
|
||||||
|
|
||||||
|
/* file pattern strategy */
|
||||||
|
filePatternText = new JBTextField(state.getFilePattern());
|
||||||
|
filePatternText.setToolTipText(bundle.getString("settings.strategy.file-pattern.tooltip"));
|
||||||
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
constraints.gridx = 2;
|
||||||
|
constraints.gridy = 0;
|
||||||
|
constraints.weightx = 1;
|
||||||
|
strategyPanel.add(filePatternText, constraints);
|
||||||
|
|
||||||
/* preview locale */
|
/* preview locale */
|
||||||
JBLabel previewLocaleLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.preview"));
|
JBLabel previewLocaleLabel = new JBLabel(bundle.getString("settings.preview"));
|
||||||
previewLocaleText = new JBTextField(state.getPreviewLocale());
|
previewLocaleText = new JBTextField(state.getPreviewLocale());
|
||||||
previewLocaleLabel.setLabelFor(previewLocaleText);
|
previewLocaleLabel.setLabelFor(previewLocaleText);
|
||||||
|
|
||||||
@ -87,32 +124,32 @@ public class SettingsDialog {
|
|||||||
rootPanel.add(previewLocaleText);
|
rootPanel.add(previewLocaleText);
|
||||||
|
|
||||||
/* path prefix */
|
/* path prefix */
|
||||||
JBLabel pathPrefixLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.prefix"));
|
JBLabel pathPrefixLabel = new JBLabel(bundle.getString("settings.path.prefix"));
|
||||||
pathPrefixText = new JBTextField(state.getPathPrefix());
|
pathPrefixText = new JBTextField(state.getPathPrefix());
|
||||||
|
|
||||||
rootPanel.add(pathPrefixLabel);
|
rootPanel.add(pathPrefixLabel);
|
||||||
rootPanel.add(pathPrefixText);
|
rootPanel.add(pathPrefixText);
|
||||||
|
|
||||||
/* sort keys */
|
/* sort keys */
|
||||||
sortKeysCheckbox = new JBCheckBox(ResourceBundle.getBundle("messages").getString("settings.keys.sort"));
|
sortKeysCheckbox = new JBCheckBox(bundle.getString("settings.keys.sort"));
|
||||||
sortKeysCheckbox.setSelected(state.isSortKeys());
|
sortKeysCheckbox.setSelected(state.isSortKeys());
|
||||||
|
|
||||||
rootPanel.add(sortKeysCheckbox);
|
rootPanel.add(sortKeysCheckbox);
|
||||||
|
|
||||||
/* nested keys */
|
/* nested keys */
|
||||||
nestedKeysCheckbox = new JBCheckBox(ResourceBundle.getBundle("messages").getString("settings.keys.nested"));
|
nestedKeysCheckbox = new JBCheckBox(bundle.getString("settings.keys.nested"));
|
||||||
nestedKeysCheckbox.setSelected(state.isNestedKeys());
|
nestedKeysCheckbox.setSelected(state.isNestedKeys());
|
||||||
|
|
||||||
rootPanel.add(nestedKeysCheckbox);
|
rootPanel.add(nestedKeysCheckbox);
|
||||||
|
|
||||||
/* code assistance */
|
/* code assistance */
|
||||||
codeAssistanceCheckbox = new JBCheckBox(ResourceBundle.getBundle("messages").getString("settings.editor.assistance"));
|
codeAssistanceCheckbox = new JBCheckBox(bundle.getString("settings.editor.assistance"));
|
||||||
codeAssistanceCheckbox.setSelected(state.isCodeAssistance());
|
codeAssistanceCheckbox.setSelected(state.isCodeAssistance());
|
||||||
|
|
||||||
rootPanel.add(codeAssistanceCheckbox);
|
rootPanel.add(codeAssistanceCheckbox);
|
||||||
|
|
||||||
DialogBuilder builder = new DialogBuilder();
|
DialogBuilder builder = new DialogBuilder();
|
||||||
builder.setTitle(ResourceBundle.getBundle("messages").getString("action.settings"));
|
builder.setTitle(bundle.getString("action.settings"));
|
||||||
builder.removeAllActions();
|
builder.removeAllActions();
|
||||||
builder.addCancelAction();
|
builder.addCancelAction();
|
||||||
builder.addOkAction();
|
builder.addOkAction();
|
||||||
|
@ -22,7 +22,7 @@ public abstract class ArrayMapper {
|
|||||||
static final String SUFFIX = "]";
|
static final String SUFFIX = "]";
|
||||||
static final char DELIMITER = ';';
|
static final char DELIMITER = ';';
|
||||||
|
|
||||||
static final String SPLITERATOR_REGEX =
|
public static final String SPLITERATOR_REGEX =
|
||||||
MessageFormat.format("(?<!\\\\){0}", Pattern.quote(String.valueOf(DELIMITER)));
|
MessageFormat.format("(?<!\\\\){0}", Pattern.quote(String.valueOf(DELIMITER)));
|
||||||
|
|
||||||
protected static <T> String read(Iterator<T> elements, Function<T, String> stringFactory) {
|
protected static <T> String read(Iterator<T> elements, Function<T, String> stringFactory) {
|
||||||
|
29
src/main/java/de/marhali/easyi18n/model/FolderStrategy.java
Normal file
29
src/main/java/de/marhali/easyi18n/model/FolderStrategy.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package de.marhali.easyi18n.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents all supported folder strategies.
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public enum FolderStrategy {
|
||||||
|
SINGLE,
|
||||||
|
MODULARIZED_LOCALE,
|
||||||
|
MODULARIZED_NAMESPACE;
|
||||||
|
|
||||||
|
public int toIndex() {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for(FolderStrategy strategy : values()) {
|
||||||
|
if(strategy == this) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FolderStrategy fromIndex(int index) {
|
||||||
|
return values()[index];
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.bus.ParserStrategy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -10,6 +11,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
public class SettingsState {
|
public class SettingsState {
|
||||||
|
|
||||||
public static final String DEFAULT_PREVIEW_LOCALE = "en";
|
public static final String DEFAULT_PREVIEW_LOCALE = "en";
|
||||||
|
public static final FolderStrategy DEFAULT_FOLDER_STRATEGY = FolderStrategy.SINGLE;
|
||||||
|
public static final ParserStrategy DEFAULT_PARSER_STRATEGY = ParserStrategy.JSON;
|
||||||
public static final String DEFAULT_FILE_PATTERN = "*.*";
|
public static final String DEFAULT_FILE_PATTERN = "*.*";
|
||||||
public static final String DEFAULT_PATH_PREFIX = "";
|
public static final String DEFAULT_PATH_PREFIX = "";
|
||||||
public static final boolean DEFAULT_SORT_KEYS = true;
|
public static final boolean DEFAULT_SORT_KEYS = true;
|
||||||
@ -17,6 +20,8 @@ public class SettingsState {
|
|||||||
public static final boolean DEFAULT_CODE_ASSISTANCE = true;
|
public static final boolean DEFAULT_CODE_ASSISTANCE = true;
|
||||||
|
|
||||||
private String localesPath;
|
private String localesPath;
|
||||||
|
private FolderStrategy folderStrategy;
|
||||||
|
private ParserStrategy parserStrategy;
|
||||||
private String filePattern;
|
private String filePattern;
|
||||||
private String previewLocale;
|
private String previewLocale;
|
||||||
private String pathPrefix;
|
private String pathPrefix;
|
||||||
@ -34,6 +39,22 @@ public class SettingsState {
|
|||||||
this.localesPath = localesPath;
|
this.localesPath = localesPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull FolderStrategy getFolderStrategy() {
|
||||||
|
return folderStrategy != null ? folderStrategy : DEFAULT_FOLDER_STRATEGY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFolderStrategy(FolderStrategy folderStrategy) {
|
||||||
|
this.folderStrategy = folderStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ParserStrategy getParserStrategy() {
|
||||||
|
return parserStrategy != null ? parserStrategy : DEFAULT_PARSER_STRATEGY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParserStrategy(ParserStrategy parserStrategy) {
|
||||||
|
this.parserStrategy = parserStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull String getFilePattern() {
|
public @NotNull String getFilePattern() {
|
||||||
return filePattern != null ? filePattern : DEFAULT_FILE_PATTERN;
|
return filePattern != null ? filePattern : DEFAULT_FILE_PATTERN;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package de.marhali.easyi18n.model.bus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents all supported file parser strategies.
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public enum ParserStrategy {
|
||||||
|
JSON,
|
||||||
|
YAML,
|
||||||
|
PROPERTIES;
|
||||||
|
|
||||||
|
public int toIndex() {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for(ParserStrategy strategy : values()) {
|
||||||
|
if(strategy == this) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ParserStrategy fromIndex(int index) {
|
||||||
|
return values()[index];
|
||||||
|
}
|
||||||
|
}
|
@ -14,10 +14,14 @@ translation.key=Key
|
|||||||
translation.locales=Locales
|
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 wildcard matcher
|
settings.strategy.title=Specify your translation file structure
|
||||||
settings.path.file-pattern-tooltip=Defines a wildcard matcher to filter relevant translation files. For example *.json, *.???.
|
settings.strategy.folder=Single Directory;Modularized: Locale / Namespace;Modularized: Namespace / Locale
|
||||||
settings.path.prefix=Path prefix
|
settings.strategy.folder.tooltip=What is the folder structure of your translation files?
|
||||||
|
settings.strategy.parser=JSON;YAML;Properties
|
||||||
|
settings.strategy.parser.tooltip=Which file parser should be used to process your translation files?
|
||||||
|
settings.strategy.file-pattern.tooltip=Defines a wildcard matcher to filter relevant translation files. For example *.json, *.???.
|
||||||
settings.preview=Preview locale
|
settings.preview=Preview locale
|
||||||
|
settings.path.prefix=Path prefix
|
||||||
settings.keys.sort=Sort translation keys alphabetically
|
settings.keys.sort=Sort translation keys alphabetically
|
||||||
settings.keys.nested=Escape delimiter character within a section layer.
|
settings.keys.nested=Escape delimiter character within a section layer.
|
||||||
settings.editor.assistance=I18n key completion, annotation and reference inside editor
|
settings.editor.assistance=I18n key completion, annotation and reference inside editor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user