Skip to content

Commit 9bdd689

Browse files
Merge pull request #1133 from makzef/1111-context-action-readme-generation
1111: Add context dependent action for generation of README.md
2 parents ecfe9ab + bfeec98 commit 9bdd689

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
if (!moduleData.getType().equals(ComponentType.module)) {
35+
return false;
36+
}
37+
final PsiDirectory moduleDirectory = new ModuleIndex(targetDirectory.getProject())
38+
.getModuleDirectoryByModuleName(moduleData.getName());
39+
final String magentoModuleName = moduleData
40+
.getName()
41+
.split(Package.vendorModuleNameSeparator)[1];
42+
43+
return targetDirectory.getName().equals(magentoModuleName)
44+
&& targetDirectory.equals(moduleDirectory);
45+
}
46+
47+
@Override
48+
protected AttributesDefaults getProperties(
49+
final @NotNull AttributesDefaults defaults,
50+
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData,
51+
final PsiDirectory targetDirectory,
52+
final PsiFile targetFile
53+
) {
54+
final String[] templateData = moduleData.getName().split(Package.vendorModuleNameSeparator);
55+
defaults.addPredefined("PACKAGE", templateData[0]);
56+
defaults.addPredefined("MODULE_NAME", templateData[1]);
57+
58+
return defaults;
59+
}
60+
}

0 commit comments

Comments
 (0)