Skip to content

Commit a4d27e4

Browse files
author
Vitaliy Boyko
committed
added the service for defining the module dir
1 parent 058a562 commit a4d27e4

19 files changed

+483
-112
lines changed

resources/META-INF/plugin.xml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<depends optional="true" config-file="withJsGraphQl.xml">com.intellij.lang.jsgraphql</depends>
3838

3939
<actions>
40+
<!-- In editor generators -->
4041
<group id="MagentoGenerateGroup">
4142
<action id="MagentoGenerateBeforeMethodAction"
4243
class="com.magento.idea.magento2plugin.actions.generation.PluginGenerateBeforeMethodAction"
@@ -52,9 +53,16 @@
5253
description="Create Magento around plugin method."/>
5354
<add-to-group group-id="PhpGenerateGroup" anchor="last"/>
5455
</group>
56+
57+
<!-- Module file generators -->
58+
<group id="MagentoNewModuleFileGroup" class="com.magento.idea.magento2plugin.actions.groups.NewModuleFileGroup" text="Module File" popup="true">
59+
<action id="MagentoCreateABlock" class="com.magento.idea.magento2plugin.actions.generation.NewBlockAction" />
60+
<add-to-group group-id="NewGroup" anchor="last"/>
61+
</group>
62+
63+
<!-- Complex generators -->
5564
<group id="MagentoNewGroup">
5665
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
57-
<action id="MagentoCreateABlock" class="com.magento.idea.magento2plugin.actions.generation.NewBlockAction" />
5866
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewDir"/>
5967
</group>
6068
<action id="MagentoCreateAPlugin.Menu" class="com.magento.idea.magento2plugin.actions.generation.CreateAPluginAction">
@@ -63,6 +71,7 @@
6371
<action id="OverrideClassByAPreference.Menu" class="com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction">
6472
<add-to-group group-id="EditorPopupMenu"/>
6573
</action>
74+
6675
</actions>
6776

6877
<extensions defaultExtensionNs="com.intellij">
@@ -134,18 +143,7 @@
134143
<internalFileTemplate name="Magento Module Xml"/>
135144
<internalFileTemplate name="Magento Module DI Xml"/>
136145
<internalFileTemplate name="Magento Php Preference Class"/>
146+
<internalFileTemplate name="Magento Module Common Php Class"/>
137147
</extensions>
138148

139-
<application-components>
140-
<!-- Add your application components here -->
141-
</application-components>
142-
143-
<project-components>
144-
<!-- Add your project components here -->
145-
</project-components>
146-
147-
<actions>
148-
<!-- Add your actions here -->
149-
</actions>
150-
151149
</idea-plugin>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
#if (${NAMESPACE})
4+
5+
namespace ${NAMESPACE};
6+
#end
7+
#if (${USE})
8+
9+
use ${USE};
10+
#end
11+
12+
class ${NAME} #if (${EXTENDS})extends ${EXTENDS}#end #if (${IMPLEMENTS}) implements ${IMPLEMENTS}#end {
13+
14+
}

src/com/magento/idea/magento2plugin/actions/generation/NewBlockAction.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
import com.intellij.ide.IdeView;
88
import com.intellij.openapi.actionSystem.*;
99
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.util.Key;
1011
import com.intellij.psi.PsiDirectory;
12+
import com.intellij.psi.PsiElement;
13+
import com.jetbrains.php.lang.psi.PhpFile;
14+
import com.jetbrains.php.lang.psi.elements.Method;
1115
import com.magento.idea.magento2plugin.MagentoIcons;
1216
import com.magento.idea.magento2plugin.actions.generation.dialog.NewBlockDialog;
13-
import com.magento.idea.magento2plugin.actions.generation.provider.NewBlockDataProvider;
17+
import com.magento.idea.magento2plugin.actions.generation.generator.code.PluginMethodsGenerator;
18+
import com.magento.idea.magento2plugin.magento.files.RegistrationPhp;
19+
import com.magento.idea.magento2plugin.project.Settings;
1420
import org.jetbrains.annotations.NotNull;
1521

16-
/**
17-
*
18-
*/
1922
public class NewBlockAction extends AnAction {
20-
public static String ACTION_NAME = "Magento2 Block";
21-
public static String ACTION_DESCRIPTION = "Create a new Magento block";
23+
public static String ACTION_NAME = "Magento 2 Block";
24+
public static String ACTION_DESCRIPTION = "Create a new Magento 2 block";
2225

2326
NewBlockAction() {
2427
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
@@ -48,8 +51,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {
4851
return;
4952
}
5053

51-
NewBlockDataProvider.get(directory);
52-
5354
NewBlockDialog.open(project, directory);
5455
}
5556

src/com/magento/idea/magento2plugin/actions/generation/NewModuleAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import com.intellij.psi.PsiDirectory;
1515
import com.intellij.psi.PsiFile;
1616
import com.magento.idea.magento2plugin.MagentoIcons;
17-
import com.magento.idea.magento2plugin.actions.generation.dialog.NewMagentoModuleDialog;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModuleDialog;
1818
import org.jetbrains.annotations.NotNull;
1919
import org.jetbrains.annotations.Nullable;
2020

2121
public class NewModuleAction extends com.intellij.openapi.actionSystem.AnAction {
22-
public static String ACTION_NAME = "Magento2 Module";
23-
public static String ACTION_DESCRIPTION = "Create a new Magento2 module";
22+
public static String ACTION_NAME = "Magento 2 Module";
23+
public static String ACTION_DESCRIPTION = "Create a new Magento 2 module";
2424

2525
NewModuleAction() {
2626
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
@@ -41,7 +41,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
4141
}
4242

4343
public void invoke(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
44-
NewMagentoModuleDialog.open(project, initialBaseDir, file, view, editor);
44+
NewModuleDialog.open(project, initialBaseDir, file, view, editor);
4545
}
4646

4747
@Override
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.actions.generation.data;
6+
7+
import com.jetbrains.php.lang.psi.elements.PhpClass;
8+
9+
public class BlockFileData {
10+
private String blockDirectory;
11+
private String blockClassName;
12+
private String blockModule;
13+
private PhpClass targetClass;
14+
private String blockFqn;
15+
private String namespace;
16+
private boolean inheritClass;
17+
18+
public BlockFileData(
19+
String blockDirectory,
20+
String blockClassName,
21+
String blockModule,
22+
PhpClass targetClass,
23+
String blockFqn,
24+
String namespace,
25+
boolean inheritClass
26+
) {
27+
this.blockDirectory = blockDirectory;
28+
this.blockClassName = blockClassName;
29+
this.blockModule = blockModule;
30+
this.targetClass = targetClass;
31+
this.blockFqn = blockFqn;
32+
this.namespace = namespace;
33+
this.inheritClass = inheritClass;
34+
}
35+
36+
public String getBlockClassName() {
37+
return blockClassName;
38+
}
39+
40+
public String getBlockDirectory() {
41+
return blockDirectory;
42+
}
43+
44+
public String getBlockModule() {
45+
return blockModule;
46+
}
47+
48+
public PhpClass getTargetClass() {
49+
return targetClass;
50+
}
51+
52+
public String getBlockFqn() {
53+
return blockFqn;
54+
}
55+
56+
public String getNamespace() {
57+
return namespace;
58+
}
59+
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.form

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</grid>
5353
</children>
5454
</grid>
55-
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
55+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
5656
<margin top="0" left="0" bottom="0" right="0"/>
5757
<constraints>
5858
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -96,32 +96,17 @@
9696
<text value="Adminhtml"/>
9797
</properties>
9898
</component>
99-
<component id="9128b" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="moduleName" custom-create="true">
100-
<constraints>
101-
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
102-
</constraints>
103-
<properties/>
104-
</component>
105-
<component id="3e4fb" class="javax.swing.JLabel">
106-
<constraints>
107-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
108-
</constraints>
109-
<properties>
110-
<labelFor value="9128b"/>
111-
<text value="Module"/>
112-
</properties>
113-
</component>
11499
<component id="fdc52" class="javax.swing.JTextField" binding="blockParentDir">
115100
<constraints>
116-
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
101+
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
117102
<preferred-size width="150" height="-1"/>
118103
</grid>
119104
</constraints>
120105
<properties/>
121106
</component>
122107
<component id="be25f" class="javax.swing.JLabel">
123108
<constraints>
124-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
109+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
125110
</constraints>
126111
<properties>
127112
<labelFor value="fdc52"/>
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.actions.generation.dialog;
26

37
import com.intellij.openapi.project.Project;
48
import com.intellij.psi.PsiDirectory;
9+
import com.jetbrains.php.lang.psi.PhpFile;
510
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
611
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
712

813
import javax.swing.*;
914
import java.awt.*;
1015
import java.awt.event.*;
1116

12-
public class NewBlockDialog extends JDialog {
17+
public class NewBlockDialog extends AbstractDialog {
1318
private JPanel contentPanel;
1419
private JButton buttonOK;
1520
private JButton buttonCancel;
16-
1721
private JTextField blockName;
1822
private JRadioButton frontendRadioButton;
1923
private JRadioButton adminhtmlRadioButton;
2024
private JTextField blockParentDir;
21-
private FilteredComboBox moduleName;
22-
2325
private Project project;
2426

2527
public NewBlockDialog(Project project) {
2628
this.project = project;
2729

2830
setContentPane(contentPanel);
2931
setModal(true);
30-
setTitle("Create a new Magento2 block..");
32+
setTitle("Create a new Magento 2 block..");
3133
getRootPane().setDefaultButton(buttonOK);
32-
moveDialogToScreenMiddle();
34+
pushToMiddle();
3335

3436
buttonOK.addActionListener(new ActionListener() {
3537
public void actionPerformed(ActionEvent e) {
@@ -59,32 +61,22 @@ public void actionPerformed(ActionEvent e) {
5961
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
6062
}
6163

62-
/**
63-
*/
6464
public static void open(Project project, PsiDirectory directory) {
6565
NewBlockDialog dialog = new NewBlockDialog(project);
6666
dialog.pack();
6767
dialog.setVisible(true);
6868
}
6969

7070
private void onOK() {
71-
// add your code here
72-
dispose();
71+
if (!validator.validate()) {
72+
return;
73+
}
74+
generateFiles();
75+
this.setVisible(false);
7376
}
7477

75-
private void onCancel() {
78+
public void onCancel() {
7679
// add your code here if necessary
7780
dispose();
7881
}
79-
80-
private void moveDialogToScreenMiddle() {
81-
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
82-
this.setLocation(dim.width / 2 -this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
83-
}
84-
85-
private void createUIComponents() {
86-
this.moduleName = new FilteredComboBox(
87-
ModuleIndex.getInstance(this.project).getEditableModuleNames()
88-
);
89-
}
9082
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.form renamed to src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewMagentoModuleDialog">
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewModuleDialog">
33
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="10" left="10" bottom="10" right="10"/>
55
<constraints>

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMagentoModuleDialog.java renamed to src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.magento.idea.magento2plugin.actions.generation.data.ModuleComposerJsonData;
1414
import com.magento.idea.magento2plugin.actions.generation.data.ModuleRegistrationPhpData;
1515
import com.magento.idea.magento2plugin.actions.generation.data.ModuleXmlData;
16-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewMagentoModuleDialogValidator;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewModuleDialogValidator;
1717
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleComposerJsonGenerator;
1818
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleRegistrationPhpGenerator;
1919
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleXmlGenerator;
@@ -27,12 +27,11 @@
2727
import javax.swing.*;
2828
import javax.swing.event.ListSelectionEvent;
2929
import javax.swing.event.ListSelectionListener;
30-
import java.awt.*;
3130
import java.awt.event.*;
3231
import java.util.List;
3332
import java.util.Vector;
3433

35-
public class NewMagentoModuleDialog extends AbstractDialog implements ListSelectionListener {
34+
public class NewModuleDialog extends AbstractDialog implements ListSelectionListener {
3635
@NotNull
3736
private final Project project;
3837
@NotNull
@@ -45,7 +44,7 @@ public class NewMagentoModuleDialog extends AbstractDialog implements ListSelect
4544
private final Editor editor;
4645
private final DirectoryGenerator directoryGenerator;
4746
private final FileFromTemplateGenerator fileFromTemplateGenerator;
48-
private final NewMagentoModuleDialogValidator validator;
47+
private final NewModuleDialogValidator validator;
4948
private final CamelCaseToHyphen camelCaseToHyphen;
5049
private final NavigateToCreatedFile navigateToCreatedFile;
5150
private JPanel contentPane;
@@ -65,7 +64,7 @@ public class NewMagentoModuleDialog extends AbstractDialog implements ListSelect
6564
private JScrollPane moduleLicenseScrollPanel;
6665
private String detectedPackageName;
6766

68-
public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
67+
public NewModuleDialog(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
6968
this.project = project;
7069
this.initialBaseDir = initialBaseDir;
7170
this.file = file;
@@ -74,7 +73,7 @@ public NewMagentoModuleDialog(@NotNull Project project, @NotNull PsiDirectory in
7473
this.directoryGenerator = DirectoryGenerator.getInstance();
7574
this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project);
7675
this.camelCaseToHyphen = CamelCaseToHyphen.getInstance();
77-
this.validator = NewMagentoModuleDialogValidator.getInstance(this);
76+
this.validator = NewModuleDialogValidator.getInstance(this);
7877
this.navigateToCreatedFile = NavigateToCreatedFile.getInstance();
7978
detectPackageName(initialBaseDir);
8079
setContentPane(contentPane);
@@ -206,7 +205,7 @@ public List getModuleLicense() {
206205
}
207206

208207
public static void open(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
209-
NewMagentoModuleDialog dialog = new NewMagentoModuleDialog(project, initialBaseDir, file, view, editor);
208+
NewModuleDialog dialog = new NewModuleDialog(project, initialBaseDir, file, view, editor);
210209
dialog.pack();
211210
dialog.setVisible(true);
212211
}

0 commit comments

Comments
 (0)