|
| 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