Skip to content

Commit 5a49f00

Browse files
author
Roman Glushko
committed
📦 #58 Inited block generation action and dialog
1 parent 77fa261 commit 5a49f00

File tree

9 files changed

+391
-8
lines changed

9 files changed

+391
-8
lines changed

‎resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
title="CHANGELOG.md"
2222
>here</a>
2323
]]>
24-
2524
</change-notes>
2625

2726
<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
@@ -55,6 +54,7 @@
5554
</group>
5655
<group id="MagentoNewGroup">
5756
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
57+
<action id="MagentoCreateABlock" class="com.magento.idea.magento2plugin.actions.generation.NewBlockAction" />
5858
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewDir"/>
5959
</group>
6060
<action id="MagentoCreateAPlugin.Menu" class="com.magento.idea.magento2plugin.actions.generation.CreateAPluginAction">
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.actions.generation;
6+
7+
import com.intellij.ide.IdeView;
8+
import com.intellij.openapi.actionSystem.*;
9+
import com.intellij.openapi.project.Project;
10+
import com.intellij.psi.PsiDirectory;
11+
import com.magento.idea.magento2plugin.MagentoIcons;
12+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewBlockDialog;
13+
import com.magento.idea.magento2plugin.actions.generation.provider.NewBlockDataProvider;
14+
import org.jetbrains.annotations.NotNull;
15+
16+
/**
17+
*
18+
*/
19+
public class NewBlockAction extends AnAction {
20+
public static String ACTION_NAME = "Magento2 Block";
21+
public static String ACTION_DESCRIPTION = "Create a new Magento block";
22+
23+
NewBlockAction() {
24+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
25+
}
26+
27+
/**
28+
* Triggers when new item is clicked
29+
*/
30+
@Override
31+
public void actionPerformed(@NotNull AnActionEvent e) {
32+
DataContext dataContext = e.getDataContext();
33+
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
34+
35+
if (view == null) {
36+
return;
37+
}
38+
39+
Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
41+
if (project == null) {
42+
return;
43+
}
44+
45+
PsiDirectory directory = view.getOrChooseDirectory();
46+
47+
if (directory == null) {
48+
return;
49+
}
50+
51+
NewBlockDataProvider.get(directory);
52+
53+
NewBlockDialog.open(project, directory);
54+
}
55+
56+
@Override
57+
public boolean isDumbAware() {
58+
return false;
59+
}
60+
}
61+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import org.jetbrains.annotations.Nullable;
2020

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

2525
NewModuleAction() {
2626
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.magento.idea.magento2plugin.actions.generation.data;
2+
3+
/**
4+
* NewBlockData contains suggested information about new block
5+
*/
6+
public class NewBlockData {
7+
private String name;
8+
private String area;
9+
private String module;
10+
private String parentDirectory;
11+
12+
public NewBlockData(String name, String area, String module, String parentDirectory) {
13+
this.name = name;
14+
this.area = area;
15+
this.module = module;
16+
this.parentDirectory = parentDirectory;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
public String getArea() {
28+
return area;
29+
}
30+
31+
public void setArea(String area) {
32+
this.area = area;
33+
}
34+
35+
public String getModule() {
36+
return module;
37+
}
38+
39+
public void setModule(String module) {
40+
this.module = module;
41+
}
42+
43+
public String getParentDirectory() {
44+
return parentDirectory;
45+
}
46+
47+
public void setParentDirectory(String parentDirectory) {
48+
this.parentDirectory = parentDirectory;
49+
}
50+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?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.NewBlockDialog">
3+
<grid id="cbd77" binding="contentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="419" height="297"/>
7+
</constraints>
8+
<properties>
9+
<name value="New Magento2 Block.."/>
10+
<toolTipText value="New Magento2 Block.."/>
11+
</properties>
12+
<border type="none"/>
13+
<children>
14+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
15+
<margin top="0" left="0" bottom="0" right="0"/>
16+
<constraints>
17+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
18+
</constraints>
19+
<properties/>
20+
<border type="none"/>
21+
<children>
22+
<hspacer id="98af6">
23+
<constraints>
24+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
25+
</constraints>
26+
</hspacer>
27+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
28+
<margin top="0" left="0" bottom="0" right="0"/>
29+
<constraints>
30+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
31+
</constraints>
32+
<properties/>
33+
<border type="none"/>
34+
<children>
35+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
36+
<constraints>
37+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
38+
</constraints>
39+
<properties>
40+
<text value="OK"/>
41+
</properties>
42+
</component>
43+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
44+
<constraints>
45+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
46+
</constraints>
47+
<properties>
48+
<text value="Cancel"/>
49+
</properties>
50+
</component>
51+
</children>
52+
</grid>
53+
</children>
54+
</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">
56+
<margin top="0" left="0" bottom="0" right="0"/>
57+
<constraints>
58+
<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"/>
59+
</constraints>
60+
<properties/>
61+
<border type="none"/>
62+
<children>
63+
<component id="726dd" class="javax.swing.JLabel">
64+
<constraints>
65+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
66+
<preferred-size width="113" height="16"/>
67+
</grid>
68+
</constraints>
69+
<properties>
70+
<labelFor value="2d9cc"/>
71+
<text value="Block Name"/>
72+
</properties>
73+
</component>
74+
<component id="2d9cc" class="javax.swing.JTextField" binding="blockName">
75+
<constraints>
76+
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
77+
<preferred-size width="150" height="-1"/>
78+
</grid>
79+
</constraints>
80+
<properties/>
81+
</component>
82+
<component id="e6153" class="javax.swing.JRadioButton" binding="frontendRadioButton" default-binding="true">
83+
<constraints>
84+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
85+
</constraints>
86+
<properties>
87+
<selected value="true"/>
88+
<text value="Frontend"/>
89+
</properties>
90+
</component>
91+
<component id="3fb02" class="javax.swing.JRadioButton" binding="adminhtmlRadioButton" default-binding="true">
92+
<constraints>
93+
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
94+
</constraints>
95+
<properties>
96+
<text value="Adminhtml"/>
97+
</properties>
98+
</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>
114+
<component id="fdc52" class="javax.swing.JTextField" binding="blockParentDir">
115+
<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">
117+
<preferred-size width="150" height="-1"/>
118+
</grid>
119+
</constraints>
120+
<properties/>
121+
</component>
122+
<component id="be25f" class="javax.swing.JLabel">
123+
<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"/>
125+
</constraints>
126+
<properties>
127+
<labelFor value="fdc52"/>
128+
<text value="Block Directory"/>
129+
</properties>
130+
</component>
131+
<component id="e81ed" class="javax.swing.JLabel">
132+
<constraints>
133+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
134+
<preferred-size width="113" height="16"/>
135+
</grid>
136+
</constraints>
137+
<properties>
138+
<text value="Block Area"/>
139+
</properties>
140+
</component>
141+
</children>
142+
</grid>
143+
</children>
144+
</grid>
145+
<buttonGroups>
146+
<group name="blockArea">
147+
<member id="3fb02"/>
148+
<member id="e6153"/>
149+
</group>
150+
</buttonGroups>
151+
</form>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.magento.idea.magento2plugin.actions.generation.dialog;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.psi.PsiDirectory;
5+
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
6+
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
7+
8+
import javax.swing.*;
9+
import java.awt.*;
10+
import java.awt.event.*;
11+
12+
public class NewBlockDialog extends JDialog {
13+
private JPanel contentPanel;
14+
private JButton buttonOK;
15+
private JButton buttonCancel;
16+
17+
private JTextField blockName;
18+
private JRadioButton frontendRadioButton;
19+
private JRadioButton adminhtmlRadioButton;
20+
private JTextField blockParentDir;
21+
private FilteredComboBox moduleName;
22+
23+
private Project project;
24+
25+
public NewBlockDialog(Project project) {
26+
this.project = project;
27+
28+
setContentPane(contentPanel);
29+
setModal(true);
30+
setTitle("Create a new Magento2 block..");
31+
getRootPane().setDefaultButton(buttonOK);
32+
moveDialogToScreenMiddle();
33+
34+
buttonOK.addActionListener(new ActionListener() {
35+
public void actionPerformed(ActionEvent e) {
36+
onOK();
37+
}
38+
});
39+
40+
buttonCancel.addActionListener(new ActionListener() {
41+
public void actionPerformed(ActionEvent e) {
42+
onCancel();
43+
}
44+
});
45+
46+
// call onCancel() when cross is clicked
47+
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
48+
addWindowListener(new WindowAdapter() {
49+
public void windowClosing(WindowEvent e) {
50+
onCancel();
51+
}
52+
});
53+
54+
// call onCancel() on ESCAPE
55+
contentPanel.registerKeyboardAction(new ActionListener() {
56+
public void actionPerformed(ActionEvent e) {
57+
onCancel();
58+
}
59+
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
60+
}
61+
62+
/**
63+
*/
64+
public static void open(Project project, PsiDirectory directory) {
65+
NewBlockDialog dialog = new NewBlockDialog(project);
66+
dialog.pack();
67+
dialog.setVisible(true);
68+
}
69+
70+
private void onOK() {
71+
// add your code here
72+
dispose();
73+
}
74+
75+
private void onCancel() {
76+
// add your code here if necessary
77+
dispose();
78+
}
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+
}
90+
}

0 commit comments

Comments
 (0)