Skip to content

Commit

Permalink
feat: implement node type translation action
Browse files Browse the repository at this point in the history
  • Loading branch information
cvette committed Sep 3, 2023
1 parent 9fbb307 commit e7b070e
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 15 deletions.
59 changes: 59 additions & 0 deletions src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.vette.idea.neos;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogPanel;

Check warning on line 4 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.ui.DialogPanel;`
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.ui.components.JBLabel;

Check warning on line 7 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.ui.components.JBLabel;`
import com.intellij.ui.components.JBPanel;

Check warning on line 8 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.ui.components.JBPanel;`
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.JBUI;

Check warning on line 11 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.util.ui.JBUI;`
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

Check warning on line 15 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.awt.*;`
import java.awt.event.ActionEvent;

Check warning on line 16 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.awt.event.ActionEvent;`
import java.awt.event.ActionListener;

Check warning on line 17 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.awt.event.ActionListener;`
import java.awt.event.KeyEvent;

Check warning on line 18 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.awt.event.KeyEvent;`
import java.awt.event.KeyListener;

Check warning on line 19 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.awt.event.KeyListener;`
import java.beans.EventHandler;

Check warning on line 20 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.beans.EventHandler;`
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

Check warning on line 22 in src/main/java/de/vette/idea/neos/LocaleDialogWrapper.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.regex.PatternSyntaxException;`

public class LocaleDialogWrapper extends DialogWrapper {
JBTextField textField = new JBTextField();

Pattern pattern = Pattern.compile("^[A-Za-z]{2,4}([_-][A-Za-z]{4})?([_-]([A-Za-z]{2}|[0-9]{3}))?$");

public LocaleDialogWrapper(Project project, String title) {
super(project);
setTitle(title);
init();
}

@Override
protected @Nullable JComponent createCenterPanel() {
FormBuilder formBuilder = FormBuilder.createFormBuilder();
formBuilder.addLabeledComponent("Locale", this.textField);
return formBuilder.getPanel();
}

public String getText() {
return this.textField.getText().trim();
}

@Override
protected @Nullable ValidationInfo doValidate() {
if (!pattern.matcher(this.getText()).matches()) {
return new ValidationInfo("Test", this.textField);
}

return null;
}

@Override
public @Nullable JComponent getPreferredFocusedComponent() {
return this.textField;
}
}
6 changes: 6 additions & 0 deletions src/main/java/de/vette/idea/neos/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

Check warning on line 29 in src/main/java/de/vette/idea/neos/Settings.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.Vector;`

@State(name = "NeosPluginSettings")
public class Settings implements PersistentStateComponent<Settings> {

public boolean pluginEnabled = false;
public boolean dismissEnableNotification = false;
public boolean excludePackageSymlinks = false;

public List<String> locales = new LinkedList<>();

public static Settings getInstance(@NotNull Project project) {
return project.getService(Settings.class);
}
Expand Down
77 changes: 75 additions & 2 deletions src/main/java/de/vette/idea/neos/SettingsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@

import com.intellij.ide.actions.ShowSettingsUtilImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;

Check warning on line 23 in src/main/java/de/vette/idea/neos/SettingsForm.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.intellij.openapi.ui.DialogWrapper;`
import com.intellij.ui.AnActionButton;
import com.intellij.ui.AnActionButtonRunnable;
import com.intellij.ui.CollectionListModel;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBList;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.jetbrains.php.frameworks.PhpFrameworkConfigurable;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.function.Consumer;

Check warning on line 42 in src/main/java/de/vette/idea/neos/SettingsForm.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.function.Consumer;`

public class SettingsForm implements PhpFrameworkConfigurable {
private JCheckBox pluginEnabled;
private JCheckBox excludePackageSymlinks;
private CollectionListModel<String> locales;
private final Project project;

public SettingsForm(@NotNull final Project project) {
Expand Down Expand Up @@ -66,8 +78,17 @@ public String getHelpTopic() {
public JComponent createComponent() {
pluginEnabled = new JCheckBox("Enable plugin for this project");
excludePackageSymlinks = new JCheckBox("Exclude symlinked packages");
locales = new CollectionListModel<>();

GridLayoutManager layout = new GridLayoutManager(2,1);
JBList localeList = new JBList<String>();
localeList.setModel(this.locales);

Check warning on line 84 in src/main/java/de/vette/idea/neos/SettingsForm.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unchecked warning

Unchecked call to 'setModel(ListModel)' as a member of raw type 'javax.swing.JList'

ToolbarDecorator editableList = ToolbarDecorator.createDecorator(localeList);

Check warning on line 86 in src/main/java/de/vette/idea/neos/SettingsForm.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unchecked warning

Unchecked assignment: 'com.intellij.ui.components.JBList' to 'javax.swing.JList'
editableList.disableUpDownActions();
editableList.setPreferredSize(new Dimension(150, 100));
editableList.setAddAction(new AddAction(this.locales));

GridLayoutManager layout = new GridLayoutManager(5,1);
GridConstraints c = new GridConstraints();
c.setAnchor(GridConstraints.ANCHOR_NORTHWEST);
c.setRow(0);
Expand All @@ -77,12 +98,37 @@ public JComponent createComponent() {

c.setRow(1);
panel1.add(excludePackageSymlinks, c);

c.setRow(2);
panel1.add(new Spacer(), c);

c.setRow(3);
panel1.add(new JBLabel("Locales"), c);

c.setRow(4);
panel1.add(editableList.createPanel(), c);

return panel1;
}

@Override
public boolean isModified() {
return !pluginEnabled.isSelected() == getSettings().pluginEnabled || !excludePackageSymlinks.isSelected() == getSettings().excludePackageSymlinks;
int i = 0;

if (getSettings().locales.size() != locales.getSize()) {
return true;
}

for (String item : locales.getItems()) {
if (!item.equals(getSettings().locales.get(i))) {
return true;
}

i++;
}

return !pluginEnabled.isSelected() == getSettings().pluginEnabled
|| !excludePackageSymlinks.isSelected() == getSettings().excludePackageSymlinks;
}

@Override
Expand All @@ -93,6 +139,7 @@ public void apply() {

getSettings().pluginEnabled = pluginEnabled.isSelected();
getSettings().excludePackageSymlinks = excludePackageSymlinks.isSelected();
getSettings().locales = new ArrayList<>(locales.getItems());
}

@Override
Expand All @@ -103,6 +150,9 @@ public void reset() {
private void updateUIFromSettings() {
pluginEnabled.setSelected(getSettings().pluginEnabled);
excludePackageSymlinks.setSelected(getSettings().excludePackageSymlinks);
getSettings().locales.forEach(s -> {
locales.add(s);
});
}

private Settings getSettings() {
Expand All @@ -112,4 +162,27 @@ private Settings getSettings() {
public static void show(@NotNull Project project) {
ShowSettingsUtilImpl.showSettingsDialog(project, "Neos.SettingsForm", null);
}


class AddAction implements AnActionButtonRunnable {

CollectionListModel list;

public AddAction(CollectionListModel list) {
this.list = list;
}

@Override
public void run(AnActionButton anActionButton) {
LocaleDialogWrapper dialog = new LocaleDialogWrapper(project, "Add Locale");
if (dialog.showAndGet()) {
String text = dialog.getText();
if (text.isEmpty()) {
return;
}

this.list.add(text);

Check warning on line 184 in src/main/java/de/vette/idea/neos/SettingsForm.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unchecked warning

Unchecked call to 'add(T)' as a member of raw type 'com.intellij.ui.CollectionListModel'
}
}
}
}
Loading

0 comments on commit e7b070e

Please sign in to comment.