feat: Move NamingConvention to presets package
Moved `NamingConvention` from the settings package to a new settings.presets package. This involved modifying various import statements across the application and updating methods that utilised this enum. Increased the `KeyCaseFormater` minimum and preferred width to 200 for better UI rendering.
This commit is contained in:
parent
4c737e25fa
commit
340ab134e5
@ -1,6 +1,5 @@
|
|||||||
package de.marhali.easyi18n.action;
|
package de.marhali.easyi18n.action;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||||
@ -11,7 +10,7 @@ import com.intellij.openapi.project.Project;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.dialog.AddDialog;
|
import de.marhali.easyi18n.dialog.AddDialog;
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||||
import de.marhali.easyi18n.util.DocumentUtil;
|
import de.marhali.easyi18n.util.DocumentUtil;
|
||||||
|
|
||||||
@ -79,10 +78,16 @@ class LocalizeItAction extends AnAction {
|
|||||||
*/
|
*/
|
||||||
private String buildReplacement(String flavorTemplate, String key, DocumentUtil documentUtil) {
|
private String buildReplacement(String flavorTemplate, String key, DocumentUtil documentUtil) {
|
||||||
if (documentUtil.isVue() || documentUtil.isJsOrTs()) return flavorTemplate + "('" + key + "')";
|
if (documentUtil.isVue() || documentUtil.isJsOrTs()) return flavorTemplate + "('" + key + "')";
|
||||||
|
|
||||||
return flavorTemplate + "(\"" + key + "\")";
|
return flavorTemplate + "(\"" + key + "\")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a given key to the specified naming convention.
|
||||||
|
*
|
||||||
|
* @param key the key to convert
|
||||||
|
* @param project the project where the key is being converted
|
||||||
|
* @return the converted key
|
||||||
|
*/
|
||||||
private String convertKeyToNamingCase(String key, Project project) {
|
private String convertKeyToNamingCase(String key, Project project) {
|
||||||
return NamingConvention.convertKeyToConvention(key, ProjectSettingsService.get(project).getState().getCaseFormat());
|
return NamingConvention.convertKeyToConvention(key, ProjectSettingsService.get(project).getState().getCaseFormat());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.intellij.ide.BrowserUtil;
|
import com.intellij.ide.BrowserUtil;
|
||||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
@ -14,6 +13,7 @@ import com.intellij.util.ui.FormBuilder;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ArrayMapper;
|
import de.marhali.easyi18n.io.parser.ArrayMapper;
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.presets.Preset;
|
import de.marhali.easyi18n.settings.presets.Preset;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -233,7 +233,7 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
|||||||
private JComponent constructKeyCaseFormater() {
|
private JComponent constructKeyCaseFormater() {
|
||||||
KeyCaseFormater = new ComboBox<>(NamingConvention.getEnumNames());
|
KeyCaseFormater = new ComboBox<>(NamingConvention.getEnumNames());
|
||||||
KeyCaseFormater.setToolTipText(bundle.getString("settings.experimental.key-naming-format.tooltip"));
|
KeyCaseFormater.setToolTipText(bundle.getString("settings.experimental.key-naming-format.tooltip"));
|
||||||
KeyCaseFormater.setMinimumAndPreferredWidth(120);
|
KeyCaseFormater.setMinimumAndPreferredWidth(200);
|
||||||
return KeyCaseFormater;
|
return KeyCaseFormater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.intellij.openapi.ui.ComboBox;
|
import com.intellij.openapi.ui.ComboBox;
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.presets.Preset;
|
import de.marhali.easyi18n.settings.presets.Preset;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory for state management for the project settings component.
|
* Mandatory for state management for the project settings component.
|
||||||
@ -72,7 +71,7 @@ public class ProjectSettingsComponentState {
|
|||||||
|
|
||||||
state.setFlavorTemplate(flavorTemplate.getText());
|
state.setFlavorTemplate(flavorTemplate.getText());
|
||||||
|
|
||||||
state.setCaseFormat(NamingConvention.fromSelector(KeyCaseFormater.getSelectedItem().toString()));
|
state.setCaseFormat(NamingConvention.fromString(KeyCaseFormater.getSelectedItem().toString()));
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.intellij.util.xmlb.annotations.Property;
|
import com.intellij.util.xmlb.annotations.Property;
|
||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.settings.presets.DefaultPreset;
|
import de.marhali.easyi18n.settings.presets.DefaultPreset;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package de.marhali.easyi18n.settings.presets;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings.presets;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing different naming conventions.
|
||||||
|
* Provides utility methods to convert keys to the specified convention.
|
||||||
|
*/
|
||||||
public enum NamingConvention {
|
public enum NamingConvention {
|
||||||
CAMEL_CASE("Camel Case"),
|
CAMEL_CASE("Camel Case"),
|
||||||
CAMEL_CASE_UPPERCASE("Camel Case Uppercase"),
|
CAMEL_CASE_UPPERCASE("Camel Case (Uppercase)"),
|
||||||
SNAKE_CASE("Snake Case"),
|
SNAKE_CASE("Snake Case"),
|
||||||
SNAKE_CASE_UPPERCASE("Snake Case Uppercase");
|
SNAKE_CASE_UPPERCASE("Snake Case (Uppercase)");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@ -16,6 +20,11 @@ public enum NamingConvention {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the name of the current instance of the class.
|
||||||
|
*
|
||||||
|
* @return the name of the current instance
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
@ -25,17 +34,38 @@ public enum NamingConvention {
|
|||||||
return super.name().toLowerCase();
|
return super.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public NamingConvention fromSelector(String name) {
|
/**
|
||||||
String formated = name.replace(" ", "_");
|
* Converts a string representation of a naming convention to the corresponding NamingConvention enum value.
|
||||||
return valueOf(formated.toUpperCase());
|
*
|
||||||
|
* @param name the string representation of the naming convention
|
||||||
|
* @return the corresponding NamingConvention enum value
|
||||||
|
*/
|
||||||
|
static public NamingConvention fromString(String name) {
|
||||||
|
for (NamingConvention value : NamingConvention.values()) {
|
||||||
|
if (value.getName().equals(name))
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return NamingConvention.CAMEL_CASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of strings representing the names of the enum values in the {@link NamingConvention} enum.
|
||||||
|
*
|
||||||
|
* @return an array of strings representing the enum names
|
||||||
|
*/
|
||||||
static public String[] getEnumNames() {
|
static public String[] getEnumNames() {
|
||||||
return Arrays.stream(NamingConvention.values())
|
return Arrays.stream(NamingConvention.values())
|
||||||
.map(NamingConvention::getName)
|
.map(NamingConvention::getName)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a given key to the specified naming convention.
|
||||||
|
*
|
||||||
|
* @param key the key to convert
|
||||||
|
* @param convention the naming convention to convert the key to
|
||||||
|
* @return the converted key
|
||||||
|
*/
|
||||||
static public String convertKeyToConvention(String key, NamingConvention convention) {
|
static public String convertKeyToConvention(String key, NamingConvention convention) {
|
||||||
String newKey = key.toLowerCase();
|
String newKey = key.toLowerCase();
|
||||||
newKey = newKey.replaceAll("\\s+", "_");
|
newKey = newKey.replaceAll("\\s+", "_");
|
||||||
@ -1,9 +1,7 @@
|
|||||||
package de.marhali.easyi18n.settings.presets;
|
package de.marhali.easyi18n.settings.presets;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package de.marhali.easyi18n.settings.presets;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|||||||
@ -64,7 +64,6 @@ settings.experimental.flavor-template =I18n flavor template
|
|||||||
settings.experimental.flavor-template-tooltip = Specify how to replace strings with i18n representation.
|
settings.experimental.flavor-template-tooltip = Specify how to replace strings with i18n representation.
|
||||||
settings.experimental.key-naming-format.title=Key format of extracted translation
|
settings.experimental.key-naming-format.title=Key format of extracted translation
|
||||||
settings.experimental.key-naming-format.tooltip=Choose Naming Convention for the keys of extracted translation
|
settings.experimental.key-naming-format.tooltip=Choose Naming Convention for the keys of extracted translation
|
||||||
settings.experimental.key-naming-format.items=Camel Case;Snake Case
|
|
||||||
|
|
||||||
error.io=An error occurred while processing translation files. \n\
|
error.io=An error occurred while processing translation files. \n\
|
||||||
Config: {0} => {1} ({2}) \n\
|
Config: {0} => {1} ({2}) \n\
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package de.marhali.easyi18n;
|
|||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import de.marhali.easyi18n.io.parser.properties.PropertiesMapper;
|
|||||||
import de.marhali.easyi18n.io.parser.properties.SortableProperties;
|
import de.marhali.easyi18n.io.parser.properties.SortableProperties;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.settings.NamingConvention;
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.intellij.testFramework.fixtures.BasePlatformTestCase;
|
|||||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||||
|
|
||||||
import de.marhali.easyi18n.settings.presets.DefaultPreset;
|
import de.marhali.easyi18n.settings.presets.DefaultPreset;
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the project settings service itself.
|
* Tests for the project settings service itself.
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package de.marhali.easyi18n.settings;
|
package de.marhali.easyi18n.settings;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.settings.presets.NamingConvention;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user