Skip to content

Commit a43d273

Browse files
committed
989: Added view.xml file in context generation.
1 parent ae866bc commit a43d273

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<action id="MagentoCreateWidgetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWidgetXmlAction"/>
7070
<action id="MagentoCreateMviewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewMviewXmlAction"/>
7171
<action id="MagentoCreateIndexerFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewIndexerXmlAction"/>
72+
<action id="MagentoCreateViewFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewViewXmlAction"/>
7273
<!-- Context dependent actions -->
7374
<separator/>
7475
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
@@ -577,6 +578,7 @@
577578
<internalFileTemplate name="Magento Widget XML"/>
578579
<internalFileTemplate name="Magento Mview XML"/>
579580
<internalFileTemplate name="Magento Indexer XML"/>
581+
<internalFileTemplate name="Magento View XML"/>
580582

581583
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
582584

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
#parse("XML File Header.xml")
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/view.xsd">
5+
</config>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
The properties of product images used on the storefront are stored in the view.xml configuration file.
12+
The variable properties vars are configured for each module individually, defined by module name.
13+
</p>
14+
</font>
15+
</body>
16+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.ModuleViewXmlFile;
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 NewViewXmlAction extends AbstractContextAction {
19+
20+
public static final String ACTION_NAME = "Magento 2 View File";
21+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 view.xml file";
22+
23+
/**
24+
* New view.xml file generation action constructor.
25+
*/
26+
public NewViewXmlAction() {
27+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleViewXmlFile());
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.magento.files;
7+
8+
import com.intellij.lang.Language;
9+
import com.intellij.lang.xml.XMLLanguage;
10+
11+
public final class ModuleViewXmlFile implements ModuleFileInterface {
12+
13+
public static final String FILE_NAME = "view.xml";
14+
public static final String TEMPLATE = "Magento View XML";
15+
16+
@Override
17+
public String getFileName() {
18+
return FILE_NAME;
19+
}
20+
21+
@Override
22+
public String getTemplate() {
23+
return TEMPLATE;
24+
}
25+
26+
@Override
27+
public Language getLanguage() {
28+
return XMLLanguage.INSTANCE;
29+
}
30+
}

0 commit comments

Comments
 (0)