Skip to content

Commit 428e6ec

Browse files
Merge pull request #1189 from SilinMykola/1175-add-action-to-generate-events-xml-file
1175: Add action to generate events.xml file through the context menu
2 parents d845379 + f4dbd57 commit 428e6ec

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
6666
<action id="MagentoCreateDiFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewDiXmlAction"/>
6767
<action id="MagentoCreateEmailTemplatesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEmailTemplatesXmlAction"/>
68+
<action id="MagentoCreateEventsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEventsXmlAction"/>
6869
<action id="MagentoCreateExtensionAttributesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewExtensionAttributesXmlAction"/>
6970
<action id="MagentoCreateFieldsetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewFieldsetXmlAction"/>
7071
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.context.xml;
7+
8+
import com.intellij.ide.fileTemplates.actions.AttributesDefaults;
9+
import com.intellij.psi.PsiDirectory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.context.AbstractContextAction;
12+
import com.magento.idea.magento2plugin.magento.files.ModuleEventsXml;
13+
import com.magento.idea.magento2plugin.magento.packages.Areas;
14+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
15+
import com.magento.idea.magento2plugin.magento.packages.Package;
16+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
17+
import java.util.Arrays;
18+
import java.util.List;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
public class NewEventsXmlAction extends AbstractContextAction {
22+
23+
public static final String ACTION_NAME = "Magento 2 Events File";
24+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 events.xml file";
25+
26+
/**
27+
* New events.xml file generation action constructor.
28+
*/
29+
public NewEventsXmlAction() {
30+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleEventsXml());
31+
}
32+
33+
@Override
34+
protected boolean isVisible(
35+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
36+
final PsiDirectory targetDirectory,
37+
final PsiFile targetFile
38+
) {
39+
final PsiDirectory configDir = moduleData.getConfigDir();
40+
final PsiDirectory globalScopeDir = getGlobalScopeDir(targetDirectory);
41+
42+
if (configDir == null || globalScopeDir == null) {
43+
return false;
44+
}
45+
46+
final List<String> allowedDirectories = Arrays.asList(
47+
Package.moduleBaseAreaDir,
48+
Areas.adminhtml.toString(),
49+
Areas.crontab.toString(),
50+
Areas.frontend.toString(),
51+
Areas.graphql.toString(),
52+
Areas.webapi_rest.toString(),
53+
Areas.webapi_soap.toString()
54+
);
55+
56+
return allowedDirectories.contains(targetDirectory.getName())
57+
&& globalScopeDir.equals(configDir)
58+
&& moduleData.getType().equals(ComponentType.module);
59+
}
60+
61+
@Override
62+
protected AttributesDefaults getProperties(
63+
final @NotNull AttributesDefaults defaults,
64+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
65+
final PsiDirectory targetDirectory,
66+
final PsiFile targetFile
67+
) {
68+
return defaults;
69+
}
70+
}

0 commit comments

Comments
 (0)