Skip to content

Commit e21494d

Browse files
author
makzef
committed
1111: Add context dependent action for generation of README.md
1 parent 431a2e4 commit e21494d

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<action id="MagentoCreateWebapiFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWebapiXmlAction"/>
7878
<action id="MagentoCreateWidgetFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewWidgetXmlAction"/>
7979
<action id="MagentoCreateLayoutFile" class="com.magento.idea.magento2plugin.actions.context.xml.NewLayoutXmlAction"/>
80+
<action id="MagentoCreateReadmeFile" class="com.magento.idea.magento2plugin.actions.context.md.NewReadmeMdAction"/>
8081
<!-- Context dependent actions -->
8182
<separator/>
8283
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewXml"/>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.md;
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.indexes.ModuleIndex;
13+
import com.magento.idea.magento2plugin.magento.files.ModuleReadmeMdFile;
14+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
15+
import com.magento.idea.magento2plugin.magento.packages.Package;
16+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
17+
import org.jetbrains.annotations.NotNull;
18+
19+
public class NewReadmeMdAction extends AbstractContextAction {
20+
21+
public static final String ACTION_NAME = "Magento 2 README File";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 README file";
23+
24+
public NewReadmeMdAction() {
25+
super(ACTION_NAME, ACTION_DESCRIPTION, new ModuleReadmeMdFile());
26+
}
27+
28+
@Override
29+
protected boolean isVisible(
30+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
31+
final PsiDirectory targetDirectory,
32+
final PsiFile targetFile
33+
) {
34+
final PsiDirectory moduleDirectory = new ModuleIndex(targetDirectory.getProject())
35+
.getModuleDirectoryByModuleName(moduleData.getName());
36+
final String magentoModuleName = moduleData.getName().split(Package.vendorModuleNameSeparator)[1];
37+
38+
return targetDirectory.getName().equals(magentoModuleName)
39+
&& targetDirectory.equals(moduleDirectory)
40+
&& moduleData.getType().equals(ComponentType.module);
41+
}
42+
43+
@Override
44+
protected AttributesDefaults getProperties(
45+
final @NotNull AttributesDefaults defaults,
46+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
47+
final PsiDirectory targetDirectory,
48+
final PsiFile targetFile
49+
) {
50+
final String[] templateData = moduleData.getName().split(Package.vendorModuleNameSeparator);
51+
defaults.addPredefined("PACKAGE", templateData[0]);
52+
defaults.addPredefined("MODULE_NAME", templateData[1]);
53+
54+
return defaults;
55+
}
56+
}

0 commit comments

Comments
 (0)