Skip to content

Commit 3f1a674

Browse files
Merge pull request #1001 from doninAtwix/994-new-context-crontab-xml-file-action
994: Added crontab.xml file in context generation.
2 parents 7869627 + 04aabfa commit 3f1a674

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<action id="MagentoCreateFieldsetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewFieldsetXmlAction"/>
7474
<action id="MagentoCreateSectionsFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewSectionsXmlAction"/>
7575
<action id="MagentoCreateEmailTemplatesFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewEmailTemplatesXmlAction"/>
76+
<action id="MagentoCreateCrontabFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewCrontabXmlAction"/>
7677
<!-- Context dependent actions -->
7778
<separator/>
7879
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0"?>
22
#parse("XML File Header.xml")
3-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
45
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.CrontabXmlTemplate;
13+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
14+
import com.magento.idea.magento2plugin.magento.packages.Package;
15+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class NewCrontabXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 Crontab File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 crontab.xml file";
22+
23+
/**
24+
* New crontab.xml file generation action constructor.
25+
*/
26+
public NewCrontabXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new CrontabXmlTemplate());
28+
}
29+
30+
@Override
31+
protected boolean isVisible(
32+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
33+
final @NotNull PsiDirectory targetDirectory,
34+
final PsiFile targetFile
35+
) {
36+
final PsiDirectory configDir = moduleData.getConfigDir();
37+
38+
if (configDir == null) {
39+
return false;
40+
}
41+
42+
return targetDirectory.getName().equals(Package.moduleBaseAreaDir)
43+
&& targetDirectory.equals(configDir)
44+
&& moduleData.getType().equals(ComponentType.module);
45+
}
46+
47+
48+
@Override
49+
protected AttributesDefaults getProperties(
50+
final @NotNull AttributesDefaults defaults,
51+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
52+
final PsiDirectory targetDirectory,
53+
final PsiFile targetFile
54+
) {
55+
return defaults;
56+
}
57+
}

0 commit comments

Comments
 (0)