Skip to content

874: enhanced new models dialog UX #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
873: Code refactoring
  • Loading branch information
bohdan-harniuk committed Dec 21, 2021
commit 3b0b1914ec95a7265d33c80e96e941d9bc43d5b8
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;

@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
public class NewEmailTemplateAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Email Template";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";

Expand All @@ -36,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewEmailTemplateDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.magento.idea.magento2plugin.magento.packages.Areas;
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -36,15 +34,18 @@
import javax.swing.KeyStroke;

public class NewEmailTemplateDialog extends AbstractDialog {
private final String moduleName;
private final Project project;
private final NewEmailTemplateDialogValidator validator;

private static final String EMAIL_TEMPLATE_ID = "id";
private static final String LABEL = "label";
private static final String FILENAME = "file name";

private final String moduleName;
private final Project project;
private final NewEmailTemplateDialogValidator validator;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, EMAIL_TEMPLATE_ID})
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
Expand All @@ -58,6 +59,7 @@ public class NewEmailTemplateDialog extends AbstractDialog {
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
message = {IdentifierRule.MESSAGE, FILENAME})
private JTextField fileName;

private FilteredComboBox area;
private FilteredComboBox templateType;
private JTextField subject;
Expand All @@ -83,18 +85,16 @@ public NewEmailTemplateDialog(final Project project, final PsiDirectory director
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(final WindowEvent windowEvent) {
onCancel();
}
});

// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(
new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
onCancel();
}
},
actionEvent -> onCancel(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);
Expand Down Expand Up @@ -230,11 +230,6 @@ private void generateFile() {
xmlGenerator.generate(NewEmailTemplateAction.ACTION_NAME, true);
}

protected void onCancel() {
// add your code here if necessary
dispose();
}

@SuppressWarnings({"PMD.UnusedPrivateMethod"})
private void createUIComponents() {
this.area = new FilteredComboBox(getAreaList());
Expand Down