diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 998d4b8cf..e041502a3 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -73,6 +73,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Cron Tab XML.xml.ft b/resources/fileTemplates/internal/Magento Cron Tab XML.xml.ft index 36fe2288e..332d258ec 100644 --- a/resources/fileTemplates/internal/Magento Cron Tab XML.xml.ft +++ b/resources/fileTemplates/internal/Magento Cron Tab XML.xml.ft @@ -1,4 +1,5 @@ #parse("XML File Header.xml") - + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewCrontabXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewCrontabXmlAction.java new file mode 100644 index 000000000..a4fdc03e9 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewCrontabXmlAction.java @@ -0,0 +1,57 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.context.xml; + +import com.intellij.ide.fileTemplates.actions.AttributesDefaults; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.context.AbstractContextAction; +import com.magento.idea.magento2plugin.magento.files.CrontabXmlTemplate; +import com.magento.idea.magento2plugin.magento.packages.ComponentType; +import com.magento.idea.magento2plugin.magento.packages.Package; +import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; +import org.jetbrains.annotations.NotNull; + +public class NewCrontabXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Crontab File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 crontab.xml file"; + + /** + * New crontab.xml file generation action constructor. + */ + public NewCrontabXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new CrontabXmlTemplate()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory configDir = moduleData.getConfigDir(); + + if (configDir == null) { + return false; + } + + return targetDirectory.getName().equals(Package.moduleBaseAreaDir) + && targetDirectory.equals(configDir) + && moduleData.getType().equals(ComponentType.module); + } + + + @Override + protected AttributesDefaults getProperties( + final @NotNull AttributesDefaults defaults, + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + return defaults; + } +}