Skip to content

Commit 6c4f1ed

Browse files
Merge branch '4.3.0-develop' of github.com:magento/magento2-phpstorm-plugin into 967-add-context-action-to-create-layout-xml-file
2 parents d93801f + e06a65b commit 6c4f1ed

File tree

6 files changed

+58
-27
lines changed

6 files changed

+58
-27
lines changed

src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import com.intellij.psi.PsiFile;
1616
import com.intellij.psi.PsiManager;
1717
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
18+
import java.util.ArrayList;
1819
import java.util.Arrays;
1920
import java.util.List;
21+
import javax.imageio.ImageIO;
2022
import org.jetbrains.annotations.NotNull;
2123
import org.jetbrains.annotations.Nullable;
2224

@@ -27,6 +29,8 @@ public class CopyMagentoPath extends CopyPathProvider {
2729
public static final String CSS_EXTENSION = "css";
2830
private final List<String> acceptedTypes
2931
= Arrays.asList(PHTML_EXTENSION, JS_EXTENSION, CSS_EXTENSION);
32+
private static final List<String> SUPPORTED_IMAGE_EXTENSIONS
33+
= new ArrayList<>(Arrays.asList(ImageIO.getReaderFormatNames()));
3034
public static final String SEPARATOR = "::";
3135
private int index;
3236

@@ -44,6 +48,15 @@ public class CopyMagentoPath extends CopyPathProvider {
4448
"web/"
4549
};
4650

51+
/**
52+
* Copy Magento Path actions for phtml, css, js, images extensions.
53+
*/
54+
public CopyMagentoPath() {
55+
super();
56+
57+
SUPPORTED_IMAGE_EXTENSIONS.add("svg");
58+
}
59+
4760
@Override
4861
public void update(@NotNull final AnActionEvent event) {
4962
final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
@@ -54,7 +67,8 @@ public void update(@NotNull final AnActionEvent event) {
5467

5568
private boolean isNotValidFile(final VirtualFile virtualFile) {
5669
return virtualFile != null && virtualFile.isDirectory()
57-
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension());
70+
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension())
71+
&& !SUPPORTED_IMAGE_EXTENSIONS.contains(virtualFile.getExtension());
5872
}
5973

6074
@Override
@@ -85,24 +99,23 @@ private boolean isNotValidFile(final VirtualFile virtualFile) {
8599
if (PHTML_EXTENSION.equals(virtualFile.getExtension())) {
86100
paths = templatePaths;
87101
} else if (JS_EXTENSION.equals(virtualFile.getExtension())
88-
|| CSS_EXTENSION.equals(virtualFile.getExtension())) {
102+
|| CSS_EXTENSION.equals(virtualFile.getExtension())
103+
|| SUPPORTED_IMAGE_EXTENSIONS.contains(virtualFile.getExtension())) {
89104
paths = webPaths;
90105
} else {
91106
return fullPath.toString();
92107
}
93-
int endIndex;
94108

95109
try {
96-
endIndex = getIndexOf(paths, fullPath, paths[++index]);
97-
} catch (ArrayIndexOutOfBoundsException exception) {
98-
// endIndex could not be found.
99-
return "";
100-
}
101-
final int offset = paths[index].length();
110+
final int endIndex = getIndexOf(paths, fullPath, paths[++index]);
111+
final int offset = paths[index].length();
102112

103-
fullPath.replace(0, endIndex + offset, "");
113+
fullPath.replace(0, endIndex + offset, "");
104114

105-
return moduleName + SEPARATOR + fullPath;
115+
return moduleName + SEPARATOR + fullPath;
116+
} catch (ArrayIndexOutOfBoundsException exception) {
117+
return fullPath.toString();
118+
}
106119
}
107120

108121
/**

src/com/magento/idea/magento2plugin/magento/packages/UiFormButtonTypeSettings.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,28 @@ public enum UiFormButtonTypeSettings {
1414
SAVE("Save", "save primary", "''", "[\n"
1515
+ " 'mage-init' => ['button' => ['event' => 'save']],\n"
1616
+ " 'form-role' => 'save'\n"
17-
+ " ]", 10, "Save entity button."),
18-
DELETE("Delete", "delete", "'deleteConfirm(\\''\n"
19-
+ " . __('Are you sure you want to delete this $varName?')\n"
20-
+ " . '\\', \\'' . $this->getUrl(\n'*/*/delete',\n[$varIdConst => "
21-
+ "$this->$varEntityIdAccessor]\n) . '\\')'", "[]", 20, "Delete entity button."),
17+
+ " ]", 30, "Save entity button."),
18+
DELETE(
19+
"Delete",
20+
"delete",
21+
"sprintf(\"deleteConfirm('%s', '%s')\", \n"
22+
+ "__('Are you sure you want to delete this $varName?'),\n"
23+
+ "$this->getUrl(\n'*/*/delete',\n[$varIdConst => "
24+
+ "$this->$varEntityIdAccessor]\n)\n)",
25+
"[]",
26+
20,
27+
"Delete entity button."),
2228
BACK("Back To Grid", "back",
2329
"sprintf(\"location.href = '%s';\", $this->getUrl('*/*/'))",
24-
"[]", 30, "Back to list button."),
25-
CUSTOM("Custom Button", "custom", "''", "[]", 0, "Custom button.");
30+
"[]", 10, "Back to list button."),
31+
CUSTOM(
32+
"Custom Button",
33+
"custom",
34+
"''",
35+
"[]",
36+
0,
37+
"Custom button."
38+
);
2639

2740
private final String label;
2841
private final String classes;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ private GetModuleNameByDirectoryUtil() {}
4444
final String moduleNamePath = matcher.group(0);
4545

4646
if (!moduleNamePath.isEmpty()) {
47-
return moduleNamePath.split("/")[5];
47+
final String[] moduleNamePathParts = moduleNamePath.split("/");
48+
49+
if (moduleNamePathParts.length >= 6) { //NOPMD
50+
return moduleNamePath.split("/")[5];
51+
}
4852
}
4953
}
5054

testData/actions/generation/generator/FormButtonBlockGenerator/generateBackButtonBlock/MyBackButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getButtonData(): array
2121
'back',
2222
sprintf("location.href = '%s';", $this->getUrl('*/*/')),
2323
[],
24-
30
24+
10
2525
);
2626
}
2727
}

testData/actions/generation/generator/FormButtonBlockGenerator/generateDeleteButtonBlock/DeleteBlock.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public function getButtonData(): array
2020
return $this->wrapButtonSettings(
2121
'Delete',
2222
'delete',
23-
'deleteConfirm(\''
24-
. __('Are you sure you want to delete this book?')
25-
. '\', \'' . $this->getUrl(
26-
'*/*/delete',
27-
[BookData::BOOK_ID => $this->getBookId()]
28-
) . '\')',
23+
sprintf("deleteConfirm('%s', '%s')",
24+
__('Are you sure you want to delete this book?'),
25+
$this->getUrl(
26+
'*/*/delete',
27+
[BookData::BOOK_ID => $this->getBookId()]
28+
)
29+
),
2930
[],
3031
20
3132
);

testData/actions/generation/generator/FormButtonBlockGenerator/generateSaveButtonBlock/SaveBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function getButtonData(): array
2424
'mage-init' => ['button' => ['event' => 'save']],
2525
'form-role' => 'save'
2626
],
27-
10
27+
30
2828
);
2929
}
3030
}

0 commit comments

Comments
 (0)