Skip to content

Commit 98f2c6d

Browse files
Merge branch '4.4.0-develop' of github.com:magento/magento2-phpstorm-plugin into 406-sorting-plugin-marker
2 parents 0322702 + cc17d24 commit 98f2c6d

File tree

7 files changed

+78
-7
lines changed

7 files changed

+78
-7
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+
}

src/com/magento/idea/magento2plugin/actions/generation/OverrideTemplateInThemeAction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ protected boolean isOverrideAllowed(
4545
) {
4646
final VirtualFile virtualFile = file.getVirtualFile();
4747

48-
if (virtualFile == null || virtualFile.isDirectory()) {
48+
if (virtualFile == null
49+
|| virtualFile.isDirectory()
50+
|| virtualFile.getCanonicalPath() == null) {
4951
return false;
5052
}
5153
final String fileExtension = virtualFile.getExtension();
5254

55+
if (fileExtension == null) {
56+
return false;
57+
}
58+
5359
if (!OverridableFileType.getOverwritableFileExtensions().contains(fileExtension)) {
5460
return false;
5561
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void suggestPreferenceDirectory(final PhpClass targetClass) {
146146
if (fqnParts.length != 0) {
147147
fqnParts = ArrayUtil.remove(fqnParts, fqnParts.length - 1);
148148
}
149-
if (fqnParts[1] != null) {
149+
if (fqnParts.length > 1 && fqnParts[1] != null) {
150150
fqnParts = ArrayUtil.remove(fqnParts, 1);
151151
}
152152
if (fqnParts[0] != null) {

src/com/magento/idea/magento2plugin/indexes/ModuleIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private List<String> getNames(
121121
* @return PsiDirectory
122122
*/
123123
public @Nullable PsiDirectory getModuleDirectoryByModuleName(final String moduleName) {
124-
if (DumbService.getInstance(project).isDumb()) {
124+
if (DumbService.getInstance(project).isDumb() || moduleName == null) {
125125
return null;
126126
}
127127
final FileBasedIndex index = FileBasedIndex

src/com/magento/idea/magento2plugin/project/diagnostic/github/GitHubNewIssueBodyBuilderUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static String buildNewBugReportBody(
4242
final @NotNull String stackTrace,
4343
final int maxAllowedBodyLength
4444
) {
45-
final int maxAllowedStackTraceLength = getMaxAllowedStackTraceLength(
45+
int maxAllowedStackTraceLength = getMaxAllowedStackTraceLength(
4646
project,
4747
bugDescription,
4848
maxAllowedBodyLength
@@ -56,6 +56,9 @@ public static String buildNewBugReportBody(
5656
String encodedCutStackTrace = "";
5757

5858
while (!isFound) {
59+
if (stackTrace.length() < maxAllowedStackTraceLength) {
60+
maxAllowedStackTraceLength = stackTrace.length();
61+
}
5962
final String cutStackTrace = stackTrace.substring(0, maxAllowedStackTraceLength - step);
6063
encodedCutStackTrace = encode(cutStackTrace);
6164

src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.intellij.openapi.vfs.VfsUtil;
1111
import com.intellij.openapi.vfs.VirtualFile;
1212
import com.magento.idea.magento2plugin.magento.packages.Package;
13-
import java.io.File;
1413
import java.util.Arrays;
1514
import org.jetbrains.annotations.NotNull;
1615

@@ -29,15 +28,17 @@ public static boolean isMagentoFolderValid(final String path) {
2928
return false;
3029
}
3130
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
31+
3232
if (file != null && file.isDirectory()) {
3333
return VfsUtil.findRelativeFile(
3434
file,
35-
Package.frameworkRootComposer.split(File.separator)
35+
Package.frameworkRootComposer.split(Package.V_FILE_SEPARATOR)
3636
) != null
3737
|| VfsUtil.findRelativeFile(
3838
file,
39-
Package.frameworkRootGit.split(File.separator)) != null;
39+
Package.frameworkRootGit.split(Package.V_FILE_SEPARATOR)) != null;
4040
}
41+
4142
return false;
4243
}
4344

0 commit comments

Comments
 (0)