diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index ecc57f6af..b1b8a257e 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -69,6 +69,7 @@ + @@ -577,6 +578,7 @@ + diff --git a/resources/fileTemplates/internal/Magento View XML.xml.ft b/resources/fileTemplates/internal/Magento View XML.xml.ft new file mode 100644 index 000000000..eb1b76626 --- /dev/null +++ b/resources/fileTemplates/internal/Magento View XML.xml.ft @@ -0,0 +1,5 @@ + +#parse("XML File Header.xml") + + diff --git a/resources/fileTemplates/internal/Magento View XML.xml.html b/resources/fileTemplates/internal/Magento View XML.xml.html new file mode 100644 index 000000000..74c22fae7 --- /dev/null +++ b/resources/fileTemplates/internal/Magento View XML.xml.html @@ -0,0 +1,16 @@ + + + + +

+ The properties of product images used on the storefront are stored in the view.xml configuration file. + The variable properties vars are configured for each module individually, defined by module name. +

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