Skip to content

Commit 2a7841e

Browse files
author
Vitaliy
authored
Merge pull request #52 from magento/plugin-39-add-new-module
MVP implementation of the New Magento 2 Module action
2 parents fbcdac1 + c3a1c7a commit 2a7841e

21 files changed

+860
-0
lines changed

resources/META-INF/plugin.xml

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
description="Create Magento around plugin method."/>
5454
<add-to-group group-id="PhpGenerateGroup" anchor="last"/>
5555
</group>
56+
<group id="MagentoNewGroup">
57+
<action id="Magento2NewModule" class="com.magento.idea.magento2plugin.actions.generation.NewModuleAction"/>
58+
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewDir"/>
59+
</group>
5660

5761
</actions>
5862

@@ -104,6 +108,10 @@
104108
groupName="Magento" enabledByDefault="true" level="ERROR"
105109
implementationClass="com.magento.idea.magento2plugin.inspections.php.PluginInspection"/>
106110
<libraryRoot id=".phpstorm.meta.php" path=".phpstorm.meta.php/" runtime="false"/>
111+
112+
<internalFileTemplate name="Magento Module Composer"/>
113+
<internalFileTemplate name="Magento Module Registration Php"/>
114+
<internalFileTemplate name="Magento Module Xml"/>
107115
</extensions>
108116

109117
<application-components>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "${COMPOSER_PACKAGE_NAME}",
3+
"version": "${MODULE_VERSION}",
4+
"description": "${MODULE_DESCRIPTION}",
5+
"type": "magento2-module",
6+
#if (${DEPENDENCIES}) "require": {
7+
${DEPENDENCIES} }, #end
8+
#if (${LICENSE}) ${LICENSE}, #end
9+
"autoload": {
10+
"files": [
11+
"registration.php"
12+
],
13+
"psr-4": {
14+
"${PACKAGE}\\\\${MODULE_NAME}\\": ""
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
use Magento\Framework\Component\ComponentRegistrar;
5+
6+
ComponentRegistrar::register(ComponentRegistrar::MODULE, '${PACKAGE}_${MODULE_NAME}', __DIR__);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
#if (${SEQUENCES})
4+
<module name="${PACKAGE}_${MODULE_NAME}">
5+
${SEQUENCES}
6+
</module>
7+
#else
8+
<module name="${PACKAGE}_${MODULE_NAME}" />
9+
#end
10+
</config>
File renamed without changes.

src/com/magento/idea/magento2plugin/MagentoIcons.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
*/
1414
public class MagentoIcons {
1515
public static final Icon WEB_API = IconLoader.getIcon("icons/webapi.png");
16+
public static final Icon MODULE = IconLoader.getIcon("/icons/module.png");
1617
}
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.AnActionEvent;
9+
import com.intellij.openapi.actionSystem.CommonDataKeys;
10+
import com.intellij.openapi.actionSystem.DataContext;
11+
import com.intellij.openapi.actionSystem.LangDataKeys;
12+
import com.intellij.openapi.editor.Editor;
13+
import com.intellij.openapi.project.Project;
14+
import com.intellij.psi.PsiDirectory;
15+
import com.intellij.psi.PsiFile;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewMagentoModuleDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.annotations.Nullable;
20+
21+
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";
24+
25+
NewModuleAction() {
26+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
27+
}
28+
@Override
29+
public void actionPerformed(@NotNull AnActionEvent e) {
30+
DataContext dataContext = e.getDataContext();
31+
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
32+
if (view != null) {
33+
Project project = CommonDataKeys.PROJECT.getData(dataContext);
34+
if (project != null) {
35+
PsiDirectory initialBaseDir = view.getOrChooseDirectory();
36+
if (initialBaseDir != null) {
37+
this.invoke(project, initialBaseDir, this.getFile(dataContext), view, CommonDataKeys.EDITOR.getData(dataContext));
38+
}
39+
}
40+
}
41+
}
42+
43+
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);
45+
}
46+
47+
@Override
48+
public boolean isDumbAware() {
49+
return false;
50+
}
51+
52+
@NotNull
53+
private String getActionName() {
54+
return this.getTemplatePresentation().getText();
55+
}
56+
57+
public PsiFile getFile(DataContext dataContext) {
58+
return CommonDataKeys.PSI_FILE.getData(dataContext);
59+
}
60+
}
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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.NewMagentoModuleDialog">
3+
<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">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="462" height="297"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
15+
</constraints>
16+
<properties/>
17+
<border type="none"/>
18+
<children>
19+
<hspacer id="98af6">
20+
<constraints>
21+
<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"/>
22+
</constraints>
23+
</hspacer>
24+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
25+
<margin top="0" left="0" bottom="0" right="0"/>
26+
<constraints>
27+
<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"/>
28+
</constraints>
29+
<properties/>
30+
<border type="none"/>
31+
<children>
32+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
33+
<constraints>
34+
<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"/>
35+
</constraints>
36+
<properties>
37+
<text value="OK"/>
38+
</properties>
39+
</component>
40+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
41+
<constraints>
42+
<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"/>
43+
</constraints>
44+
<properties>
45+
<text value="Cancel"/>
46+
</properties>
47+
</component>
48+
</children>
49+
</grid>
50+
</children>
51+
</grid>
52+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
53+
<margin top="0" left="0" bottom="0" right="0"/>
54+
<constraints>
55+
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
56+
</constraints>
57+
<properties/>
58+
<border type="none"/>
59+
<children>
60+
<component id="ad3ba" class="javax.swing.JTextField" binding="packageName" default-binding="true">
61+
<constraints>
62+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
63+
<preferred-size width="150" height="-1"/>
64+
</grid>
65+
</constraints>
66+
<properties/>
67+
<clientProperties>
68+
<html.disable class="java.lang.Boolean" value="true"/>
69+
</clientProperties>
70+
</component>
71+
<component id="3fe2b" class="javax.swing.JLabel" binding="packageNameLabel">
72+
<constraints>
73+
<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"/>
74+
</constraints>
75+
<properties>
76+
<text value="Package Name"/>
77+
</properties>
78+
</component>
79+
<component id="e4858" class="javax.swing.JTextField" binding="moduleName">
80+
<constraints>
81+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
82+
<preferred-size width="150" height="-1"/>
83+
</grid>
84+
</constraints>
85+
<properties/>
86+
<clientProperties>
87+
<html.disable class="java.lang.Boolean" value="true"/>
88+
</clientProperties>
89+
</component>
90+
<component id="22b5e" class="javax.swing.JLabel" binding="moduleNameLabel">
91+
<constraints>
92+
<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"/>
93+
</constraints>
94+
<properties>
95+
<text value="Module Name"/>
96+
</properties>
97+
</component>
98+
<component id="423dc" class="javax.swing.JTextField" binding="moduleVersion">
99+
<constraints>
100+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
101+
<preferred-size width="150" height="-1"/>
102+
</grid>
103+
</constraints>
104+
<properties>
105+
<text value="1.0.0"/>
106+
</properties>
107+
<clientProperties>
108+
<html.disable class="java.lang.Boolean" value="true"/>
109+
</clientProperties>
110+
</component>
111+
<component id="2af8d" class="javax.swing.JLabel" binding="moduleVersionLabel">
112+
<constraints>
113+
<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"/>
114+
</constraints>
115+
<properties>
116+
<text value="Module Version"/>
117+
</properties>
118+
</component>
119+
</children>
120+
</grid>
121+
<component id="4c5ac" class="javax.swing.JTextArea" binding="moduleDescription">
122+
<constraints>
123+
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
124+
<preferred-size width="150" height="50"/>
125+
</grid>
126+
</constraints>
127+
<properties>
128+
<text value="N/A"/>
129+
<toolTipText value="Module Description"/>
130+
</properties>
131+
<clientProperties>
132+
<html.disable class="java.lang.Boolean" value="true"/>
133+
</clientProperties>
134+
</component>
135+
<component id="ec98d" class="javax.swing.JLabel" binding="moduleDescriptionLabel">
136+
<constraints>
137+
<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"/>
138+
</constraints>
139+
<properties>
140+
<text value="Module Description"/>
141+
</properties>
142+
</component>
143+
</children>
144+
</grid>
145+
</form>

0 commit comments

Comments
 (0)