activate new configuration service
This commit is contained in:
parent
1161e324e3
commit
31ad2e3464
@ -7,10 +7,10 @@ import com.intellij.openapi.vfs.*;
|
||||
|
||||
import de.marhali.easyi18n.exception.EmptyLocalesDirException;
|
||||
import de.marhali.easyi18n.io.IOHandler;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.service.FileChangeListener;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import de.marhali.easyi18n.util.NotificationHelper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -48,18 +48,18 @@ public class DataStore {
|
||||
* @param successResult Consumer will inform if operation was successful
|
||||
*/
|
||||
public void loadFromPersistenceLayer(@NotNull Consumer<Boolean> successResult) {
|
||||
SettingsState settings = SettingsService.getInstance(this.project).getState();
|
||||
ProjectSettings settings = ProjectSettingsService.get(project).getState();
|
||||
|
||||
ApplicationManager.getApplication().saveAll(); // Save opened files (required if new locales were added)
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
try {
|
||||
this.data = new IOHandler(settings).read();
|
||||
this.changeListener.updateLocalesPath(settings.getLocalesPath());
|
||||
this.changeListener.updateLocalesPath(settings.getLocalesDirectory());
|
||||
successResult.accept(true);
|
||||
|
||||
} catch (Exception ex) {
|
||||
this.data = new TranslationData(settings.isSortKeys());
|
||||
this.data = new TranslationData(settings.isSorting());
|
||||
successResult.accept(false);
|
||||
|
||||
if(ex instanceof EmptyLocalesDirException) {
|
||||
@ -76,7 +76,7 @@ public class DataStore {
|
||||
* @param successResult Consumer will inform if operation was successful
|
||||
*/
|
||||
public void saveToPersistenceLayer(@NotNull Consumer<Boolean> successResult) {
|
||||
SettingsState settings = SettingsService.getInstance(this.project).getState();
|
||||
ProjectSettings settings = ProjectSettingsService.get(project).getState();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
try {
|
||||
|
@ -1,174 +0,0 @@
|
||||
package de.marhali.easyi18n.dialog;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.DialogBuilder;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBPanel;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.io.parser.ArrayMapper;
|
||||
import de.marhali.easyi18n.model.FolderStrategyType;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Plugin configuration dialog.
|
||||
* @author marhali
|
||||
*/
|
||||
@Deprecated
|
||||
public class SettingsDialog {
|
||||
|
||||
private final Project project;
|
||||
|
||||
private TextFieldWithBrowseButton pathText;
|
||||
private ComboBox<String> folderStrategyComboBox;
|
||||
private ComboBox<String> parserStrategyComboBox;
|
||||
private JBTextField filePatternText;
|
||||
private JBTextField previewLocaleText;
|
||||
private JBTextField pathPrefixText;
|
||||
private JBCheckBox sortKeysCheckbox;
|
||||
private JBCheckBox nestedKeysCheckbox;
|
||||
private JBCheckBox codeAssistanceCheckbox;
|
||||
|
||||
public SettingsDialog(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public void showAndHandle() {
|
||||
SettingsState state = SettingsService.getInstance(project).getState();
|
||||
|
||||
if(prepare(state).show() == DialogWrapper.OK_EXIT_CODE) { // Save changes
|
||||
state.setLocalesPath(pathText.getText());
|
||||
state.setFolderStrategy(FolderStrategyType.fromIndex(folderStrategyComboBox.getSelectedIndex()));
|
||||
state.setParserStrategy(ParserStrategyType.fromIndex(parserStrategyComboBox.getSelectedIndex()));
|
||||
state.setFilePattern(filePatternText.getText());
|
||||
state.setPreviewLocale(previewLocaleText.getText());
|
||||
state.setPathPrefix(pathPrefixText.getText());
|
||||
state.setSortKeys(sortKeysCheckbox.isSelected());
|
||||
state.setNestedKeys(nestedKeysCheckbox.isSelected());
|
||||
state.setCodeAssistance(codeAssistanceCheckbox.isSelected());
|
||||
|
||||
// Reload instance
|
||||
InstanceManager manager = InstanceManager.get(project);
|
||||
manager.store().loadFromPersistenceLayer((success) ->
|
||||
manager.bus().propagate().onUpdateData(manager.store().getData()));
|
||||
}
|
||||
}
|
||||
|
||||
private DialogBuilder prepare(SettingsState state) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("messages");
|
||||
JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2));
|
||||
|
||||
/* path */
|
||||
JBLabel pathLabel = new JBLabel(bundle.getString("settings.path.text"));
|
||||
pathText = new TextFieldWithBrowseButton(new JTextField(state.getLocalesPath()));
|
||||
|
||||
pathLabel.setLabelFor(pathText);
|
||||
pathText.addBrowseFolderListener(bundle.getString("settings.path.title"), null, project, new FileChooserDescriptor(
|
||||
false, true, false, false, false, false));
|
||||
|
||||
rootPanel.add(pathLabel);
|
||||
rootPanel.add(pathText);
|
||||
|
||||
JBLabel strategyLabel = new JBLabel(bundle.getString("settings.strategy.title"));
|
||||
rootPanel.add(strategyLabel);
|
||||
|
||||
JPanel strategyPanel = new JBPanel<>(new GridBagLayout());
|
||||
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"));
|
||||
parserStrategyComboBox.addItemListener(handleParserChange());
|
||||
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 */
|
||||
JBLabel previewLocaleLabel = new JBLabel(bundle.getString("settings.preview"));
|
||||
previewLocaleText = new JBTextField(state.getPreviewLocale());
|
||||
previewLocaleLabel.setLabelFor(previewLocaleText);
|
||||
|
||||
rootPanel.add(previewLocaleLabel);
|
||||
rootPanel.add(previewLocaleText);
|
||||
|
||||
/* path prefix */
|
||||
JBLabel pathPrefixLabel = new JBLabel(bundle.getString("settings.path.prefix"));
|
||||
pathPrefixText = new JBTextField(state.getPathPrefix());
|
||||
|
||||
rootPanel.add(pathPrefixLabel);
|
||||
rootPanel.add(pathPrefixText);
|
||||
|
||||
/* sort keys */
|
||||
sortKeysCheckbox = new JBCheckBox(bundle.getString("settings.keys.sort"));
|
||||
sortKeysCheckbox.setSelected(state.isSortKeys());
|
||||
|
||||
rootPanel.add(sortKeysCheckbox);
|
||||
|
||||
/* nested keys */
|
||||
nestedKeysCheckbox = new JBCheckBox(bundle.getString("settings.keys.nested"));
|
||||
nestedKeysCheckbox.setSelected(state.isNestedKeys());
|
||||
|
||||
rootPanel.add(nestedKeysCheckbox);
|
||||
|
||||
/* code assistance */
|
||||
codeAssistanceCheckbox = new JBCheckBox(bundle.getString("settings.editor.assistance"));
|
||||
codeAssistanceCheckbox.setSelected(state.isCodeAssistance());
|
||||
|
||||
rootPanel.add(codeAssistanceCheckbox);
|
||||
|
||||
DialogBuilder builder = new DialogBuilder();
|
||||
builder.setTitle(bundle.getString("action.settings"));
|
||||
builder.removeAllActions();
|
||||
builder.addCancelAction();
|
||||
builder.addOkAction();
|
||||
builder.setCenterPanel(rootPanel);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ItemListener handleParserChange() {
|
||||
return e -> {
|
||||
if(e.getStateChange() == ItemEvent.SELECTED) {
|
||||
// Automatically suggest file pattern option on parser change
|
||||
ParserStrategyType newStrategy = ParserStrategyType.fromIndex(parserStrategyComboBox.getSelectedIndex());
|
||||
filePatternText.setText(newStrategy.getExampleFilePattern());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -7,10 +7,10 @@ import com.intellij.openapi.project.Project;
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.model.KeyPath;
|
||||
import de.marhali.easyi18n.model.KeyPathConverter;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationNode;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -27,12 +27,14 @@ public class KeyAnnotator {
|
||||
*/
|
||||
protected void annotate(@NotNull String key, @NotNull Project project, @NotNull AnnotationHolder holder) {
|
||||
// Do not annotate keys if service is disabled
|
||||
if(!SettingsService.getInstance(project).getState().isCodeAssistance()) {
|
||||
if(!ProjectSettingsService.get(project).getState().isAssistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SettingsState state = SettingsService.getInstance(project).getState();
|
||||
String pathPrefix = state.getPathPrefix();
|
||||
ProjectSettings state = ProjectSettingsService.get(project).getState();
|
||||
//String pathPrefix = state.getPathPrefix();
|
||||
// TODO: Path prefix removal
|
||||
String pathPrefix = "";
|
||||
String previewLocale = state.getPreviewLocale();
|
||||
|
||||
KeyPathConverter converter = new KeyPathConverter(project);
|
||||
|
@ -10,8 +10,8 @@ import de.marhali.easyi18n.DataStore;
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.model.KeyPath;
|
||||
import de.marhali.easyi18n.model.Translation;
|
||||
import de.marhali.easyi18n.service.*;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
@ -29,14 +29,16 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
|
||||
Project project = parameters.getOriginalFile().getProject();
|
||||
|
||||
// Do not annotate keys if service is disabled
|
||||
if(!SettingsService.getInstance(project).getState().isCodeAssistance()) {
|
||||
if(!ProjectSettingsService.get(project).getState().isAssistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DataStore store = InstanceManager.get(project).store();
|
||||
|
||||
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
|
||||
String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();
|
||||
String previewLocale = ProjectSettingsService.get(project).getState().getPreviewLocale();
|
||||
//String pathPrefix = ProjectSettingsService.get(project).getState().getPathPrefix();
|
||||
// TODO: Path prefix removal
|
||||
String pathPrefix = "";
|
||||
|
||||
if(pathPrefix.length() > 0 && !pathPrefix.endsWith(KeyPath.DELIMITER)) {
|
||||
pathPrefix += KeyPath.DELIMITER;
|
||||
|
@ -13,7 +13,7 @@ import de.marhali.easyi18n.DataStore;
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.model.KeyPathConverter;
|
||||
import de.marhali.easyi18n.model.Translation;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -33,7 +33,7 @@ public class GenericFoldingBuilder extends FoldingBuilderEx {
|
||||
Collection<PsiLiteralValue> literalValues = PsiTreeUtil.findChildrenOfType(root, PsiLiteralValue.class);
|
||||
List<FoldingDescriptor> descriptors = new ArrayList<>();
|
||||
|
||||
if(!SettingsService.getInstance(root.getProject()).getState().isCodeAssistance()) {
|
||||
if(!ProjectSettingsService.get(root.getProject()).getState().isAssistance()) {
|
||||
return FoldingDescriptor.EMPTY;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public class GenericFoldingBuilder extends FoldingBuilderEx {
|
||||
return null;
|
||||
}
|
||||
|
||||
String previewLocale = SettingsService.getInstance(literalValue.getProject()).getState().getPreviewLocale();
|
||||
String previewLocale = ProjectSettingsService.get(literalValue.getProject()).getState().getPreviewLocale();
|
||||
|
||||
return translation.get(previewLocale);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import com.intellij.util.ProcessingContext;
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.editor.KeyReference;
|
||||
import de.marhali.easyi18n.model.KeyPathConverter;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -35,7 +35,7 @@ public class GenericKeyReferenceContributor extends PsiReferenceContributor {
|
||||
}
|
||||
|
||||
// Do not reference keys if service is disabled
|
||||
if(!SettingsService.getInstance(element.getProject()).getState().isCodeAssistance()) {
|
||||
if(!ProjectSettingsService.get(element.getProject()).getState().isAssistance()) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ import com.intellij.util.ProcessingContext;
|
||||
import de.marhali.easyi18n.InstanceManager;
|
||||
import de.marhali.easyi18n.editor.KeyReference;
|
||||
import de.marhali.easyi18n.model.KeyPathConverter;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry;
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression;
|
||||
@ -42,7 +42,7 @@ public class KotlinKeyReferenceContributor extends PsiReferenceContributor {
|
||||
}
|
||||
|
||||
// Do not reference keys if service is disabled
|
||||
if(!SettingsService.getInstance(element.getProject()).getState().isCodeAssistance()) {
|
||||
if(!ProjectSettingsService.get(element.getProject()).getState().isAssistance()) {
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.model.*;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@ -21,23 +22,23 @@ import java.util.List;
|
||||
*/
|
||||
public class IOHandler {
|
||||
|
||||
private final @NotNull SettingsState settings;
|
||||
private final @NotNull ProjectSettings settings;
|
||||
|
||||
private final @NotNull FolderStrategy folderStrategy;
|
||||
|
||||
private final @NotNull ParserStrategyType parserStrategyType;
|
||||
private final @NotNull ParserStrategy parserStrategy;
|
||||
|
||||
public IOHandler(@NotNull SettingsState settings) throws Exception {
|
||||
public IOHandler(@NotNull ProjectSettings settings) throws Exception {
|
||||
|
||||
this.settings = settings;
|
||||
|
||||
this.folderStrategy = settings.getFolderStrategy().getStrategy()
|
||||
.getDeclaredConstructor(SettingsState.class).newInstance(settings);
|
||||
.getDeclaredConstructor(ProjectSettings.class).newInstance(settings);
|
||||
|
||||
this.parserStrategyType = settings.getParserStrategy();
|
||||
this.parserStrategy = parserStrategyType.getStrategy()
|
||||
.getDeclaredConstructor(SettingsState.class).newInstance(settings);
|
||||
.getDeclaredConstructor(ProjectSettings.class).newInstance(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +48,7 @@ public class IOHandler {
|
||||
* @throws IOException Could not read translation data
|
||||
*/
|
||||
public @NotNull TranslationData read() throws IOException {
|
||||
String localesPath = this.settings.getLocalesPath();
|
||||
String localesPath = this.settings.getLocalesDirectory();
|
||||
|
||||
if(localesPath == null || localesPath.isEmpty()) {
|
||||
throw new EmptyLocalesDirException("Locales path must not be empty");
|
||||
@ -59,7 +60,7 @@ public class IOHandler {
|
||||
throw new IllegalArgumentException("Specified locales path is invalid (" + localesPath + ")");
|
||||
}
|
||||
|
||||
TranslationData data = new TranslationData(this.settings.isSortKeys());
|
||||
TranslationData data = new TranslationData(this.settings.isSorting());
|
||||
List<TranslationFile> translationFiles = this.folderStrategy.analyzeFolderStructure(localesDirectory);
|
||||
|
||||
for(TranslationFile file : translationFiles) {
|
||||
@ -80,7 +81,7 @@ public class IOHandler {
|
||||
* @throws IOException Write action failed
|
||||
*/
|
||||
public void write(@NotNull TranslationData data) throws IOException {
|
||||
String localesPath = this.settings.getLocalesPath();
|
||||
String localesPath = this.settings.getLocalesDirectory();
|
||||
|
||||
if(localesPath == null || localesPath.isEmpty()) {
|
||||
throw new EmptyLocalesDirException("Locales path must not be empty");
|
||||
|
@ -4,10 +4,10 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -22,9 +22,9 @@ import java.util.Objects;
|
||||
*/
|
||||
public abstract class FolderStrategy {
|
||||
|
||||
protected final @NotNull SettingsState settings;
|
||||
protected final @NotNull ProjectSettings settings;
|
||||
|
||||
public FolderStrategy(@NotNull SettingsState settings) {
|
||||
public FolderStrategy(@NotNull ProjectSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ package de.marhali.easyi18n.io.folder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -20,7 +20,7 @@ import java.util.List;
|
||||
*/
|
||||
public class ModularLocaleFolderStrategy extends FolderStrategy {
|
||||
|
||||
public ModularLocaleFolderStrategy(@NotNull SettingsState settings) {
|
||||
public ModularLocaleFolderStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ package de.marhali.easyi18n.io.folder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -20,7 +20,7 @@ import java.util.List;
|
||||
*/
|
||||
public class ModularNamespaceFolderStrategy extends FolderStrategy {
|
||||
|
||||
public ModularNamespaceFolderStrategy(@NotNull SettingsState settings) {
|
||||
public ModularNamespaceFolderStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ package de.marhali.easyi18n.io.folder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -22,7 +22,7 @@ import java.util.List;
|
||||
*/
|
||||
public class SingleFolderStrategy extends FolderStrategy {
|
||||
|
||||
public SingleFolderStrategy(@NotNull SettingsState settings) {
|
||||
public SingleFolderStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package de.marhali.easyi18n.io.parser;
|
||||
|
||||
import de.marhali.easyi18n.model.*;
|
||||
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -12,9 +13,9 @@ import java.util.Objects;
|
||||
*/
|
||||
public abstract class ParserStrategy {
|
||||
|
||||
protected final @NotNull SettingsState settings;
|
||||
protected final @NotNull ProjectSettings settings;
|
||||
|
||||
public ParserStrategy(@NotNull SettingsState settings) {
|
||||
public ParserStrategy(@NotNull ProjectSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@ -48,7 +49,7 @@ public abstract class ParserStrategy {
|
||||
TranslationNode moduleNode = data.getNode(KeyPath.of(moduleName));
|
||||
|
||||
if(moduleNode == null) {
|
||||
moduleNode = new TranslationNode(this.settings.isSortKeys());
|
||||
moduleNode = new TranslationNode(this.settings.isSorting());
|
||||
data.getRootNode().setChildren(moduleName, moduleNode);
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,15 @@ package de.marhali.easyi18n.io.parser.json;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.model.*;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.Objects;
|
||||
@ -23,7 +24,7 @@ public class JsonParserStrategy extends ParserStrategy {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
|
||||
public JsonParserStrategy(@NotNull SettingsState settings) {
|
||||
public JsonParserStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ package de.marhali.easyi18n.io.parser.json5;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.model.TranslationNode;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import de.marhali.json5.Json5;
|
||||
import de.marhali.json5.Json5Element;
|
||||
import de.marhali.json5.Json5Object;
|
||||
@ -26,7 +26,7 @@ public class Json5ParserStrategy extends ParserStrategy {
|
||||
private static final Json5 JSON5 = Json5.builder(builder ->
|
||||
builder.allowInvalidSurrogate().trailingComma().indentFactor(4).build());
|
||||
|
||||
public Json5ParserStrategy(@NotNull SettingsState settings) {
|
||||
public Json5ParserStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ package de.marhali.easyi18n.io.parser.properties;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.model.TranslationNode;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -20,7 +20,7 @@ import java.io.StringWriter;
|
||||
*/
|
||||
public class PropertiesParserStrategy extends ParserStrategy {
|
||||
|
||||
public PropertiesParserStrategy(@NotNull SettingsState settings) {
|
||||
public PropertiesParserStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
|
||||
TranslationData targetData = new TranslationData(data.getLocales(), targetNode);
|
||||
|
||||
try(Reader reader = new InputStreamReader(vf.getInputStream(), vf.getCharset())) {
|
||||
SortableProperties input = new SortableProperties(this.settings.isSortKeys());
|
||||
SortableProperties input = new SortableProperties(this.settings.isSorting());
|
||||
input.load(reader);
|
||||
PropertiesMapper.read(file.getLocale(), input, targetData);
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
|
||||
TranslationNode targetNode = super.getTargetNode(data, file);
|
||||
TranslationData targetData = new TranslationData(data.getLocales(), targetNode);
|
||||
|
||||
SortableProperties output = new SortableProperties(this.settings.isSortKeys());
|
||||
SortableProperties output = new SortableProperties(this.settings.isSorting());
|
||||
PropertiesMapper.write(file.getLocale(), output, targetData);
|
||||
|
||||
try(StringWriter writer = new StringWriter()) {
|
||||
|
@ -3,10 +3,10 @@ package de.marhali.easyi18n.io.parser.yaml;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategy;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.model.TranslationData;
|
||||
import de.marhali.easyi18n.model.TranslationFile;
|
||||
import de.marhali.easyi18n.model.TranslationNode;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -22,7 +22,7 @@ import java.io.Reader;
|
||||
*/
|
||||
public class YamlParserStrategy extends ParserStrategy {
|
||||
|
||||
public YamlParserStrategy(@NotNull SettingsState settings) {
|
||||
public YamlParserStrategy(@NotNull ProjectSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package de.marhali.easyi18n.model;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -22,7 +22,7 @@ public class KeyPathConverter {
|
||||
}
|
||||
|
||||
public KeyPathConverter(@NotNull Project project) {
|
||||
this(SettingsService.getInstance(project).getState().isNestedKeys());
|
||||
this(ProjectSettingsService.get(project).getState().isNestedKeys());
|
||||
}
|
||||
|
||||
public @NotNull String concat(@NotNull KeyPath path) {
|
||||
|
@ -1,106 +0,0 @@
|
||||
package de.marhali.easyi18n.model;
|
||||
|
||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents the persistent settings which can be configured.
|
||||
* @author marhali
|
||||
*/
|
||||
@Deprecated
|
||||
public class SettingsState {
|
||||
|
||||
public static final String DEFAULT_PREVIEW_LOCALE = "en";
|
||||
public static final FolderStrategyType DEFAULT_FOLDER_STRATEGY = FolderStrategyType.SINGLE;
|
||||
public static final ParserStrategyType DEFAULT_PARSER_STRATEGY = ParserStrategyType.JSON;
|
||||
public static final String DEFAULT_FILE_PATTERN = "*.*";
|
||||
public static final String DEFAULT_PATH_PREFIX = "";
|
||||
public static final boolean DEFAULT_SORT_KEYS = true;
|
||||
public static final boolean DEFAULT_NESTED_KEYS = true;
|
||||
public static final boolean DEFAULT_CODE_ASSISTANCE = true;
|
||||
|
||||
private String localesPath;
|
||||
private FolderStrategyType folderStrategy;
|
||||
private ParserStrategyType parserStrategy;
|
||||
private String filePattern;
|
||||
private String previewLocale;
|
||||
private String pathPrefix;
|
||||
private Boolean sortKeys;
|
||||
private Boolean nestedKeys;
|
||||
private Boolean codeAssistance;
|
||||
|
||||
public SettingsState() {}
|
||||
|
||||
public @Nullable String getLocalesPath() {
|
||||
return localesPath;
|
||||
}
|
||||
|
||||
public void setLocalesPath(String localesPath) {
|
||||
this.localesPath = localesPath;
|
||||
}
|
||||
|
||||
public @NotNull FolderStrategyType getFolderStrategy() {
|
||||
return folderStrategy != null ? folderStrategy : DEFAULT_FOLDER_STRATEGY;
|
||||
}
|
||||
|
||||
public void setFolderStrategy(FolderStrategyType folderStrategy) {
|
||||
this.folderStrategy = folderStrategy;
|
||||
}
|
||||
|
||||
public @NotNull ParserStrategyType getParserStrategy() {
|
||||
return parserStrategy != null ? parserStrategy : DEFAULT_PARSER_STRATEGY;
|
||||
}
|
||||
|
||||
public void setParserStrategy(ParserStrategyType parserStrategy) {
|
||||
this.parserStrategy = parserStrategy;
|
||||
}
|
||||
|
||||
public @NotNull String getFilePattern() {
|
||||
return filePattern != null ? filePattern : DEFAULT_FILE_PATTERN;
|
||||
}
|
||||
|
||||
public void setFilePattern(String filePattern) {
|
||||
this.filePattern = filePattern;
|
||||
}
|
||||
|
||||
public @NotNull String getPreviewLocale() {
|
||||
return previewLocale != null ? previewLocale : DEFAULT_PREVIEW_LOCALE;
|
||||
}
|
||||
|
||||
public void setPreviewLocale(String previewLocale) {
|
||||
this.previewLocale = previewLocale;
|
||||
}
|
||||
|
||||
public @NotNull String getPathPrefix() {
|
||||
return pathPrefix != null ? pathPrefix : DEFAULT_PATH_PREFIX;
|
||||
}
|
||||
|
||||
public void setPathPrefix(String pathPrefix) {
|
||||
this.pathPrefix = pathPrefix;
|
||||
}
|
||||
|
||||
public boolean isSortKeys() {
|
||||
return sortKeys == null ? DEFAULT_SORT_KEYS : sortKeys;
|
||||
}
|
||||
|
||||
public void setSortKeys(boolean sortKeys) {
|
||||
this.sortKeys = sortKeys;
|
||||
}
|
||||
|
||||
public boolean isNestedKeys() {
|
||||
return nestedKeys == null ? DEFAULT_NESTED_KEYS : nestedKeys;
|
||||
}
|
||||
|
||||
public void setNestedKeys(boolean nestedKeys) {
|
||||
this.nestedKeys = nestedKeys;
|
||||
}
|
||||
|
||||
public boolean isCodeAssistance() {
|
||||
return codeAssistance == null ? DEFAULT_CODE_ASSISTANCE : codeAssistance;
|
||||
}
|
||||
|
||||
public void setCodeAssistance(boolean codeAssistance) {
|
||||
this.codeAssistance = codeAssistance;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package de.marhali.easyi18n.service;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Persistent settings storage at project level.
|
||||
* @author marhali
|
||||
*/
|
||||
@State(name = "EasyI18nSettings")
|
||||
@Deprecated
|
||||
public class SettingsService implements PersistentStateComponent<SettingsState> {
|
||||
|
||||
public static SettingsService getInstance(Project project) {
|
||||
return project.getService(SettingsService.class);
|
||||
}
|
||||
|
||||
private SettingsState state;
|
||||
|
||||
public SettingsService() {
|
||||
this.state = new SettingsState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SettingsState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(SettingsState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(@NotNull SettingsState state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ import de.marhali.easyi18n.dialog.EditDialog;
|
||||
import de.marhali.easyi18n.listener.DeleteKeyListener;
|
||||
import de.marhali.easyi18n.listener.PopupClickListener;
|
||||
import de.marhali.easyi18n.renderer.TreeRenderer;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||
import de.marhali.easyi18n.tabs.mapper.TreeModelMapper;
|
||||
import de.marhali.easyi18n.util.TreeUtil;
|
||||
|
||||
@ -80,7 +80,7 @@ public class TreeView implements BusListener {
|
||||
|
||||
@Override
|
||||
public void onUpdateData(@NotNull TranslationData data) {
|
||||
tree.setModel(this.currentMapper = new TreeModelMapper(data, SettingsService.getInstance(project).getState()));
|
||||
tree.setModel(this.currentMapper = new TreeModelMapper(data, ProjectSettingsService.get(project).getState()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ import com.intellij.ui.JBColor;
|
||||
import de.marhali.easyi18n.model.*;
|
||||
import de.marhali.easyi18n.model.bus.FilterMissingTranslationsListener;
|
||||
import de.marhali.easyi18n.model.bus.SearchQueryListener;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import de.marhali.easyi18n.util.UiUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -24,9 +25,9 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
|
||||
|
||||
private final TranslationData data;
|
||||
private final KeyPathConverter converter;
|
||||
private final SettingsState state;
|
||||
private final ProjectSettings state;
|
||||
|
||||
public TreeModelMapper(TranslationData data, SettingsState state) {
|
||||
public TreeModelMapper(TranslationData data, ProjectSettings state) {
|
||||
super(null);
|
||||
|
||||
this.data = data;
|
||||
@ -41,7 +42,7 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
|
||||
@Override
|
||||
public void onSearchQuery(@Nullable String query) {
|
||||
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
|
||||
TranslationData shadow = new TranslationData(this.state.isSortKeys());
|
||||
TranslationData shadow = new TranslationData(this.state.isSorting());
|
||||
|
||||
if(query == null) { // Reset
|
||||
this.generateNodes(rootNode, this.data.getRootNode());
|
||||
@ -75,7 +76,7 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList
|
||||
@Override
|
||||
public void onFilterMissingTranslations(boolean filter) {
|
||||
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
|
||||
TranslationData shadow = new TranslationData(this.state.isSortKeys());
|
||||
TranslationData shadow = new TranslationData(this.state.isSorting());
|
||||
|
||||
if(!filter) { // Reset
|
||||
this.generateNodes(rootNode, this.data.getRootNode());
|
||||
|
@ -5,7 +5,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import de.marhali.easyi18n.action.SettingsAction;
|
||||
import de.marhali.easyi18n.io.IOHandler;
|
||||
import de.marhali.easyi18n.model.SettingsState;
|
||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
@ -17,11 +17,11 @@ import java.util.ResourceBundle;
|
||||
*/
|
||||
public class NotificationHelper {
|
||||
|
||||
public static void createIOError(@NotNull SettingsState state, Exception ex) {
|
||||
public static void createIOError(@NotNull ProjectSettings state, Exception ex) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("messages");
|
||||
|
||||
String message = MessageFormat.format(bundle.getString("error.io"),
|
||||
state.getFolderStrategy(), state.getParserStrategy(), state.getFilePattern(), state.getLocalesPath());
|
||||
state.getFolderStrategy(), state.getParserStrategy(), state.getFilePattern(), state.getLocalesDirectory());
|
||||
|
||||
Logger.getInstance(IOHandler.class).error(message, ex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user