From 12f9c38da5e819cafa64ac22b8701d92ec94a13b Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Wed, 16 Feb 2022 15:05:55 +0200 Subject: [PATCH] 991: Added fieldset.xml file in context generation. --- resources/META-INF/plugin.xml | 2 + .../internal/Magento Fieldset XML.xml.ft | 5 ++ .../internal/Magento Fieldset XML.xml.html | 20 +++++++ .../context/xml/NewFieldsetXmlAction.java | 57 +++++++++++++++++++ .../magento/files/ModuleFieldsetXmlFile.java | 30 ++++++++++ 5 files changed, 114 insertions(+) create mode 100644 resources/fileTemplates/internal/Magento Fieldset XML.xml.ft create mode 100644 resources/fileTemplates/internal/Magento Fieldset XML.xml.html create mode 100644 src/com/magento/idea/magento2plugin/actions/context/xml/NewFieldsetXmlAction.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/ModuleFieldsetXmlFile.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index b1b8a257e..ce3f6db59 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -70,6 +70,7 @@ + @@ -579,6 +580,7 @@ + diff --git a/resources/fileTemplates/internal/Magento Fieldset XML.xml.ft b/resources/fileTemplates/internal/Magento Fieldset XML.xml.ft new file mode 100644 index 000000000..fd3170f89 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Fieldset XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento Fieldset XML.xml.html b/resources/fileTemplates/internal/Magento Fieldset XML.xml.html new file mode 100644 index 000000000..d8310cf85 --- /dev/null +++ b/resources/fileTemplates/internal/Magento Fieldset XML.xml.html @@ -0,0 +1,20 @@ + + + + +

+ The fieldset.xml file configures which the copy fields from quote to order. + The fieldset.xml file is located under etc/fieldset.xml in a given Magento 2 extension. +

+

+ Read more about fieldset.xml in the + DevDocs. +

+
+ + diff --git a/src/com/magento/idea/magento2plugin/actions/context/xml/NewFieldsetXmlAction.java b/src/com/magento/idea/magento2plugin/actions/context/xml/NewFieldsetXmlAction.java new file mode 100644 index 000000000..1fd806dc8 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/context/xml/NewFieldsetXmlAction.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.ModuleFieldsetXmlFile; +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 NewFieldsetXmlAction extends AbstractContextAction { + + public static final String ACTION_NAME = "Magento 2 Fieldset File"; + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 fieldset.xml file"; + + /** + * New fieldset.xml file generation action constructor. + */ + public NewFieldsetXmlAction() { + super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleFieldsetXmlFile()); + } + + @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; + } +} diff --git a/src/com/magento/idea/magento2plugin/magento/files/ModuleFieldsetXmlFile.java b/src/com/magento/idea/magento2plugin/magento/files/ModuleFieldsetXmlFile.java new file mode 100644 index 000000000..d94af2f99 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/ModuleFieldsetXmlFile.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 ModuleFieldsetXmlFile implements ModuleFileInterface { + + public static final String FILE_NAME = "fieldset.xml"; + public static final String TEMPLATE = "Magento Fieldset XML"; + + @Override + public String getFileName() { + return FILE_NAME; + } + + @Override + public String getTemplate() { + return TEMPLATE; + } + + @Override + public Language getLanguage() { + return XMLLanguage.INSTANCE; + } +}