From 0a5cf4bc73a7d281bf7a3f6c3d4638251a223986 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 11 Feb 2022 16:47:36 +0200 Subject: [PATCH 1/3] 975: Added a new context dependent Action for the config.xml file generation --- resources/META-INF/plugin.xml | 2 + .../internal/Magento Config XML.xml.ft | 5 ++ .../internal/Magento Config XML.xml.html | 19 +++++++ .../context/xml/NewConfigXmlAction.java | 49 +++++++++++++++++++ .../magento/files/ModuleConfigXmlFile.java | 30 ++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Config XML.xml.ft create mode 100644 resources/fileTemplates/internal/Magento Config XML.xml.html create mode 100644 src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModuleConfigXmlFile.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 41b50d3ba..fb8123d96 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -63,6 +63,7 @@ + @@ -565,6 +566,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Config XML.xml.ft b/resources/fileTemplates/internal/Magento Config XML.xml.ft new file mode 100644 index 000000000..0a6d873f7 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Config XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Config XML.xml.html b/resources/fileTemplates/internal/Magento Config XML.xml.html new file mode 100644 index 000000000..8b8a0fee2 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Config XML.xml.html @@ -0,0 +1,19 @@ + + + + + + + +
+ The config.xml file is used to set default values for system configuration + (in Admin under Stores > Settings > Configuration), set in module_folder/etc/adminhtml/system.xml. +
+
+ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java new file mode 100644 index 000000000..2d9bd6afd --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java @@ -0,0 +1,49 @@ +/* + * 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.ModuleConfigXmlFile; +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 NewConfigXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 CONFIG File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 config.xml file"; + + /** + * New config.xml file generation action constructor. + */ + public NewConfigXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleConfigXmlFile()); + } + + @Override + protected boolean isVisible( + final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, + final @NotNull PsiDirectory targetDirectory, + final PsiFile targetFile + ) { + return targetDirectory.getName().equals(Package.moduleBaseAreaDir) + && 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; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleConfigXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleConfigXmlFile.java new file mode 100644 index 000000000..2726ead9c --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleConfigXmlFile.java @@ -0,0 +1,30 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.intellij.lang.xml.XMLLanguage; + +public final class ModuleConfigXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "config.xml"; + public static final String TEMPLATE = "Magento Config XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +} From 2afee117a33fc5123594b0e17cdecd6f1b267cf5 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 11 Feb 2022 17:19:36 +0200 Subject: [PATCH 2/3] 975: updated action name for generation config.xml --- .../magento2plugin/actions/context/xml/NewConfigXmlAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java index 2d9bd6afd..dfb8c6cdc 100644 --- a/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java @@ -17,7 +17,7 @@ public class NewConfigXmlAction extends AbstractContextAction { - public static final String ACTION_NAME = "Magento 2 CONFIG File"; + public static final String ACTION_NAME = "Magento 2 Config"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 config.xml file"; /** From bdd47384a00cdd4b38fc1472bf0b9f60c7252f51 Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Fri, 11 Feb 2022 17:24:29 +0200 Subject: [PATCH 3/3] 975: updated action name for generation config.xml --- .../magento2plugin/actions/context/xml/NewConfigXmlAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java index dfb8c6cdc..76cdd1060 100644 --- a/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewConfigXmlAction.java @@ -17,7 +17,7 @@ public class NewConfigXmlAction extends AbstractContextAction { - public static final String ACTION_NAME = "Magento 2 Config"; + public static final String ACTION_NAME = "Magento 2 Config File"; public static final String ACTION_DESCRIPTION = "Create a new Magento 2 config.xml file"; /**