Merge pull request #212 from marhali/next

Next (4.4.0)
This commit is contained in:
Marcel 2022-12-16 18:03:09 +01:00 committed by GitHub
commit 0797eb94ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 55 deletions

View File

@ -3,6 +3,11 @@
# easy-i18n Changelog # easy-i18n Changelog
## [Unreleased] ## [Unreleased]
### Added
- Support of path variables for the locales directory configuration @SIMULATAN
### Changed
- Restructure form actions to improve user experience
## [4.3.1] ## [4.3.1]
### Fixed ### Fixed

View File

@ -4,7 +4,7 @@
pluginGroup = de.marhali.easyi18n pluginGroup = de.marhali.easyi18n
pluginName = easy-i18n pluginName = easy-i18n
# SemVer format -> https://semver.org # SemVer format -> https://semver.org
pluginVersion = 4.3.1 pluginVersion = 4.4.0
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions. # for insight into build numbers and IntelliJ Platform versions.

View File

@ -1,7 +1,6 @@
package de.marhali.easyi18n.dialog; package de.marhali.easyi18n.dialog;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.DialogWrapper;
import de.marhali.easyi18n.model.action.TranslationCreate; import de.marhali.easyi18n.model.action.TranslationCreate;
@ -14,8 +13,6 @@ import de.marhali.easyi18n.settings.ProjectSettingsService;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/** /**
* Dialog to create a new translation with all associated locale values. * Dialog to create a new translation with all associated locale values.
* Supports optional prefill technique for translation key or locale value. * Supports optional prefill technique for translation key or locale value.
@ -35,6 +32,8 @@ public class AddDialog extends TranslationDialog {
? new TranslationValue(ProjectSettingsService.get(project).getState().getPreviewLocale(), prefillLocale) ? new TranslationValue(ProjectSettingsService.get(project).getState().getPreviewLocale(), prefillLocale)
: null) : null)
); );
setTitle(bundle.getString("action.add"));
} }
/** /**
@ -45,18 +44,6 @@ public class AddDialog extends TranslationDialog {
this(project, new KeyPath(), ""); this(project, new KeyPath(), "");
} }
@Override
protected @NotNull DialogBuilder configure(@NotNull JComponent centerPanel) {
DialogBuilder builder = new DialogBuilder();
builder.setTitle(bundle.getString("action.add"));
builder.removeAllActions();
builder.addOkAction();
builder.addCancelAction();
builder.setCenterPanel(centerPanel);
return builder;
}
@Override @Override
protected @Nullable TranslationUpdate handleExit(int exitCode) { protected @Nullable TranslationUpdate handleExit(int exitCode) {
if(exitCode == DialogWrapper.OK_EXIT_CODE) { if(exitCode == DialogWrapper.OK_EXIT_CODE) {

View File

@ -1,7 +1,6 @@
package de.marhali.easyi18n.dialog; package de.marhali.easyi18n.dialog;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.DialogWrapper;
import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor; import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor;
@ -27,18 +26,13 @@ public class EditDialog extends TranslationDialog {
*/ */
public EditDialog(@NotNull Project project, @NotNull Translation origin) { public EditDialog(@NotNull Project project, @NotNull Translation origin) {
super(project, origin); super(project, origin);
setTitle(bundle.getString("action.edit"));
} }
@Override @Override
protected @NotNull DialogBuilder configure(@NotNull JComponent centerPanel) { protected Action @NotNull [] createLeftSideActions() {
DialogBuilder builder = new DialogBuilder(); return new Action[]{ new DeleteActionDescriptor(this) };
builder.setTitle(bundle.getString("action.edit"));
builder.removeAllActions();
builder.addCancelAction();
builder.addActionDescriptor(new DeleteActionDescriptor());
builder.addOkAction();
builder.setCenterPanel(centerPanel);
return builder;
} }
@Override @Override

View File

@ -1,7 +1,7 @@
package de.marhali.easyi18n.dialog; package de.marhali.easyi18n.dialog;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder; import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField; import com.intellij.ui.components.JBTextField;
import com.intellij.util.Consumer; import com.intellij.util.Consumer;
@ -28,7 +28,7 @@ import java.util.*;
* Base for add and edit translation dialogs. * Base for add and edit translation dialogs.
* @author marhali * @author marhali
*/ */
abstract class TranslationDialog { abstract class TranslationDialog extends DialogWrapper {
protected static final ResourceBundle bundle = ResourceBundle.getBundle("messages"); protected static final ResourceBundle bundle = ResourceBundle.getBundle("messages");
@ -48,6 +48,8 @@ abstract class TranslationDialog {
* @param origin Prefill translation * @param origin Prefill translation
*/ */
protected TranslationDialog(@NotNull Project project, @NotNull Translation origin) { protected TranslationDialog(@NotNull Project project, @NotNull Translation origin) {
super(project);
this.project = project; this.project = project;
this.settings = ProjectSettingsService.get(project).getState(); this.settings = ProjectSettingsService.get(project).getState();
this.converter = new KeyPathConverter(settings); this.converter = new KeyPathConverter(settings);
@ -75,14 +77,6 @@ abstract class TranslationDialog {
callbacks.add(callback); callbacks.add(callback);
} }
/**
* Implementation needs to configure the dialog. E.g. title, actions, ...
* The implementation needs to set the provided centerPanel as the view panel.
* @param centerPanel GUI to set on the dialog builder
* @return configured dialog builder
*/
protected abstract @NotNull DialogBuilder configure(@NotNull JComponent centerPanel);
/** /**
* Implementation needs to handle exit * Implementation needs to handle exit
* @param exitCode See {@link com.intellij.openapi.ui.DialogWrapper} for exit codes * @param exitCode See {@link com.intellij.openapi.ui.DialogWrapper} for exit codes
@ -95,7 +89,10 @@ abstract class TranslationDialog {
* Internally, the {@link #handleExit(int)} method will be called to determine finalization logic. * Internally, the {@link #handleExit(int)} method will be called to determine finalization logic.
*/ */
public void showAndHandle() { public void showAndHandle() {
int exitCode = createDialog().show(); init();
show();
int exitCode = getExitCode();
TranslationUpdate update = handleExit(exitCode); TranslationUpdate update = handleExit(exitCode);
if(update != null) { if(update != null) {
@ -120,7 +117,8 @@ abstract class TranslationDialog {
return new Translation(key, value); return new Translation(key, value);
} }
private DialogBuilder createDialog() { @Override
protected @Nullable JComponent createCenterPanel() {
JPanel panel = FormBuilder.createFormBuilder() JPanel panel = FormBuilder.createFormBuilder()
.addLabeledComponent(bundle.getString("translation.key"), keyField, true) .addLabeledComponent(bundle.getString("translation.key"), keyField, true)
.addComponent(createLocalesPanel(), 12) .addComponent(createLocalesPanel(), 12)
@ -128,7 +126,7 @@ abstract class TranslationDialog {
panel.setMinimumSize(new Dimension(200, 150)); panel.setMinimumSize(new Dimension(200, 150));
return configure(panel); return panel;
} }
private JComponent createLocalesPanel() { private JComponent createLocalesPanel() {

View File

@ -1,7 +1,7 @@
package de.marhali.easyi18n.dialog.descriptor; package de.marhali.easyi18n.dialog.descriptor;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NotNull;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -12,26 +12,19 @@ import java.util.ResourceBundle;
* Action can be monitored using the exit code for the opened dialog. See EXIT_CODE. * Action can be monitored using the exit code for the opened dialog. See EXIT_CODE.
* @author marhali * @author marhali
*/ */
public class DeleteActionDescriptor extends AbstractAction implements DialogBuilder.ActionDescriptor { public class DeleteActionDescriptor extends AbstractAction {
public static final int EXIT_CODE = 10; public static final int EXIT_CODE = 10;
private DialogWrapper dialogWrapper; private final DialogWrapper dialog;
public DeleteActionDescriptor() { public DeleteActionDescriptor(@NotNull DialogWrapper dialog) {
super(ResourceBundle.getBundle("messages").getString("action.delete")); super(ResourceBundle.getBundle("messages").getString("action.delete"));
this.dialog = dialog;
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(dialogWrapper != null) { dialog.close(EXIT_CODE, false);
dialogWrapper.close(EXIT_CODE, false);
}
}
@Override
public Action getAction(DialogWrapper dialogWrapper) {
this.dialogWrapper = dialogWrapper;
return this;
} }
} }

View File

@ -1,6 +1,7 @@
package de.marhali.easyi18n.io; package de.marhali.easyi18n.io;
import com.intellij.codeInsight.actions.ReformatCodeProcessor; import com.intellij.codeInsight.actions.ReformatCodeProcessor;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
@ -57,7 +58,8 @@ public class IOHandler {
* @throws IOException Could not read translation data * @throws IOException Could not read translation data
*/ */
public @NotNull TranslationData read() throws IOException { public @NotNull TranslationData read() throws IOException {
String localesPath = this.settings.getLocalesDirectory(); String localesPath = PathMacroManager.getInstance(project)
.expandPath(this.settings.getLocalesDirectory());
if(localesPath == null || localesPath.isEmpty()) { if(localesPath == null || localesPath.isEmpty()) {
throw new EmptyLocalesDirException("Locales path must not be empty"); throw new EmptyLocalesDirException("Locales path must not be empty");

View File

@ -25,7 +25,7 @@ settings.preset.tooltip=Choose a configuration template that best fits your proj
settings.resource.title=Resource Configuration settings.resource.title=Resource Configuration
settings.resource.path.window=Locales Directory settings.resource.path.window=Locales Directory
settings.resource.path.title=Locales directory settings.resource.path.title=Locales directory
settings.resource.path.tooltip=Define the folder which contains all translation files. For nested folders, use the top folder. settings.resource.path.tooltip=Choose the folder which contains all translation files. Path variables like $PROJECT_DIR$ are supported.
settings.resource.strategy=File structure settings.resource.strategy=File structure
settings.resource.folder.items=Single Directory;Modularized: Locale / Namespace;Modularized: Namespace / Locale settings.resource.folder.items=Single Directory;Modularized: Locale / Namespace;Modularized: Namespace / Locale
settings.resource.folder.tooltip=What is the folder structure of your translation files? settings.resource.folder.tooltip=What is the folder structure of your translation files?