Skip to content

Commit

Permalink
Merge pull request #212 from marhali/next
Browse files Browse the repository at this point in the history
Next (4.4.0)
  • Loading branch information
marhali authored Dec 16, 2022
2 parents dbd0470 + fd47de4 commit 0797eb9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 55 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# easy-i18n Changelog

## [Unreleased]
### Added
- Support of path variables for the locales directory configuration @SIMULATAN

### Changed
- Restructure form actions to improve user experience

## [4.3.1]
### Fixed
### Fixed
- Support for all 2022.3 builds (223.*)

## [4.3.0]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = de.marhali.easyi18n
pluginName = easy-i18n
# SemVer format -> https://semver.org
pluginVersion = 4.3.1
pluginVersion = 4.4.0

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/de/marhali/easyi18n/dialog/AddDialog.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.marhali.easyi18n.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper;

import de.marhali.easyi18n.model.action.TranslationCreate;
Expand All @@ -14,8 +13,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
* Dialog to create a new translation with all associated locale values.
* Supports optional prefill technique for translation key or locale value.
Expand All @@ -35,6 +32,8 @@ public AddDialog(@NotNull Project project, @Nullable KeyPath prefillKey, @Nullab
? new TranslationValue(ProjectSettingsService.get(project).getState().getPreviewLocale(), prefillLocale)
: null)
);

setTitle(bundle.getString("action.add"));
}

/**
Expand All @@ -45,18 +44,6 @@ public AddDialog(@NotNull Project project) {
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
protected @Nullable TranslationUpdate handleExit(int exitCode) {
if(exitCode == DialogWrapper.OK_EXIT_CODE) {
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/de/marhali/easyi18n/dialog/EditDialog.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.marhali.easyi18n.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper;

import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor;
Expand All @@ -27,18 +26,13 @@ public class EditDialog extends TranslationDialog {
*/
public EditDialog(@NotNull Project project, @NotNull Translation origin) {
super(project, origin);

setTitle(bundle.getString("action.edit"));
}

@Override
protected @NotNull DialogBuilder configure(@NotNull JComponent centerPanel) {
DialogBuilder builder = new DialogBuilder();
builder.setTitle(bundle.getString("action.edit"));
builder.removeAllActions();
builder.addCancelAction();
builder.addActionDescriptor(new DeleteActionDescriptor());
builder.addOkAction();
builder.setCenterPanel(centerPanel);
return builder;
protected Action @NotNull [] createLeftSideActions() {
return new Action[]{ new DeleteActionDescriptor(this) };
}

@Override
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/de/marhali/easyi18n/dialog/TranslationDialog.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.marhali.easyi18n.dialog;

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.JBTextField;
import com.intellij.util.Consumer;
Expand All @@ -28,7 +28,7 @@
* Base for add and edit translation dialogs.
* @author marhali
*/
abstract class TranslationDialog {
abstract class TranslationDialog extends DialogWrapper {

protected static final ResourceBundle bundle = ResourceBundle.getBundle("messages");

Expand All @@ -48,6 +48,8 @@ abstract class TranslationDialog {
* @param origin Prefill translation
*/
protected TranslationDialog(@NotNull Project project, @NotNull Translation origin) {
super(project);

this.project = project;
this.settings = ProjectSettingsService.get(project).getState();
this.converter = new KeyPathConverter(settings);
Expand Down Expand Up @@ -75,14 +77,6 @@ public void registerCallback(Consumer<TranslationUpdate> 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
* @param exitCode See {@link com.intellij.openapi.ui.DialogWrapper} for exit codes
Expand All @@ -95,7 +89,10 @@ public void registerCallback(Consumer<TranslationUpdate> callback) {
* Internally, the {@link #handleExit(int)} method will be called to determine finalization logic.
*/
public void showAndHandle() {
int exitCode = createDialog().show();
init();
show();

int exitCode = getExitCode();
TranslationUpdate update = handleExit(exitCode);

if(update != null) {
Expand All @@ -120,15 +117,16 @@ public void showAndHandle() {
return new Translation(key, value);
}

private DialogBuilder createDialog() {
@Override
protected @Nullable JComponent createCenterPanel() {
JPanel panel = FormBuilder.createFormBuilder()
.addLabeledComponent(bundle.getString("translation.key"), keyField, true)
.addComponent(createLocalesPanel(), 12)
.getPanel();

panel.setMinimumSize(new Dimension(200, 150));

return configure(panel);
return panel;
}

private JComponent createLocalesPanel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.marhali.easyi18n.dialog.descriptor;

import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.event.ActionEvent;
Expand All @@ -12,26 +12,19 @@
* Action can be monitored using the exit code for the opened dialog. See EXIT_CODE.
* @author marhali
*/
public class DeleteActionDescriptor extends AbstractAction implements DialogBuilder.ActionDescriptor {
public class DeleteActionDescriptor extends AbstractAction {

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"));
this.dialog = dialog;
}

@Override
public void actionPerformed(ActionEvent e) {
if(dialogWrapper != null) {
dialogWrapper.close(EXIT_CODE, false);
}
}

@Override
public Action getAction(DialogWrapper dialogWrapper) {
this.dialogWrapper = dialogWrapper;
return this;
dialog.close(EXIT_CODE, false);
}
}
4 changes: 3 additions & 1 deletion src/main/java/de/marhali/easyi18n/io/IOHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.marhali.easyi18n.io;

import com.intellij.codeInsight.actions.ReformatCodeProcessor;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -57,7 +58,8 @@ public IOHandler(@NotNull Project project, @NotNull ProjectSettings settings) th
* @throws IOException Could not read translation data
*/
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()) {
throw new EmptyLocalesDirException("Locales path must not be empty");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ settings.preset.tooltip=Choose a configuration template that best fits your proj
settings.resource.title=Resource Configuration
settings.resource.path.window=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.folder.items=Single Directory;Modularized: Locale / Namespace;Modularized: Namespace / Locale
settings.resource.folder.tooltip=What is the folder structure of your translation files?
Expand Down

0 comments on commit 0797eb9

Please sign in to comment.