From 75a6140ac18a436a7c81be4cbdc8372e8157cbe7 Mon Sep 17 00:00:00 2001 From: SilinMykola Date: Wed, 14 Sep 2022 18:18:05 +0300 Subject: [PATCH 1/2] 1175 add action to generate events.xml file to menu --- resources/META-INF/plugin.xml | 1 + .../context/xml/NewEventsXmlAction.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 36b295aec..ba211873b 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -65,6 +65,7 @@ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java new file mode 100644 index 000000000..369bf7f70 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java @@ -0,0 +1,70 @@ +/* + * 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.ModuleEventsXml; +import com.magento.idea.magento2plugin.magento.packages.Areas; +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 java.util.Arrays; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class NewEventsXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Events Observer File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 events.xml file"; + + /** + * New events.xml file generation action constructor. + */ + public NewEventsXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleEventsXml()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + final PsiDirectory configDir = moduleData.getConfigDir(); + final PsiDirectory globalScopeDir = getGlobalScopeDir(targetDirectory); + + if (configDir == null || globalScopeDir == null) { + return false; + } + + final List allowedDirectories = Arrays.asList( + Package.moduleBaseAreaDir, + Areas.adminhtml.toString(), + Areas.crontab.toString(), + Areas.frontend.toString(), + Areas.graphql.toString(), + Areas.webapi_rest.toString(), + Areas.webapi_soap.toString() + ); + + return allowedDirectories.contains(targetDirectory.getName()) + && globalScopeDir.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; + } +} \ No newline at end of file From f4dbd57ec9cafd4ca0890556ae4e2af9036e7e20 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 16 Sep 2022 22:50:15 +0300 Subject: [PATCH 2/2] 1175: Minor code style fixes --- .../actions/context/xml/NewEventsXmlAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java index 369bf7f70..88ccf6359 100644 --- a/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewEventsXmlAction.java @@ -20,7 +20,7 @@ public class NewEventsXmlAction extends AbstractContextAction { - public static final String ACTION_NAME = "Magento 2 Events Observer File"; + public static final String ACTION_NAME = "Magento 2 Events File"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 events.xml file"; /** @@ -67,4 +67,4 @@ protected AttributesDefaults getProperties( ) { return defaults; } -} \ No newline at end of file +}