|
18 | 18 | import org.jetbrains.annotations.NotNull;
|
19 | 19 | import org.jetbrains.annotations.Nullable;
|
20 | 20 |
|
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.List; |
| 23 | + |
21 | 24 | public class CopyMagentoPath extends CopyPathProvider {
|
22 | 25 | public static final String PHTML = "phtml";
|
23 |
| - public static final String PHTML_SEPARATOR = "::"; |
| 26 | + public static final String JS = "js"; |
| 27 | + private final List<String> acceptedTypes = Arrays.asList(PHTML, JS); |
| 28 | + public static final String SEPARATOR = "::"; |
24 | 29 | private int index;
|
| 30 | + |
25 | 31 | private final String[] templatePaths = {
|
26 | 32 | "view/frontend/templates/",
|
27 | 33 | "view/adminhtml/templates/",
|
28 | 34 | "view/base/templates/",
|
29 | 35 | "templates/"
|
30 | 36 | };
|
31 | 37 |
|
| 38 | + private final String[] jsPaths = { |
| 39 | + "view/frontend/web/", |
| 40 | + "view/adminhtml/web/", |
| 41 | + "view/base/web/" |
| 42 | + }; |
| 43 | + |
32 | 44 | @Override
|
33 | 45 | public void update(@NotNull final AnActionEvent event) {
|
34 | 46 | final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
|
35 |
| - if (virtualFile != null && virtualFile.isDirectory() |
36 |
| - || virtualFile != null && !PHTML.equals(virtualFile.getExtension())) { |
| 47 | + if (isNotValidFile(virtualFile)) { |
37 | 48 | event.getPresentation().setVisible(false);
|
38 | 49 | }
|
39 | 50 | }
|
40 | 51 |
|
| 52 | + private boolean isNotValidFile(VirtualFile virtualFile) { |
| 53 | + return virtualFile != null && virtualFile.isDirectory() |
| 54 | + || virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension()); |
| 55 | + } |
| 56 | + |
41 | 57 | @Nullable
|
42 | 58 | @Override
|
43 | 59 | public String getPathToElement(
|
@@ -65,21 +81,30 @@ public String getPathToElement(
|
65 | 81 |
|
66 | 82 | if (PHTML.equals(virtualFile.getExtension())) {
|
67 | 83 | index = -1;
|
68 |
| - final int endIndex = getIndexOf(fullPath, templatePaths[++index]); |
| 84 | + final int endIndex = getIndexOf(fullPath, templatePaths[++index], templatePaths); |
69 | 85 | final int offset = templatePaths[index].length();
|
70 | 86 |
|
71 | 87 | fullPath.replace(0, endIndex + offset, "");
|
72 |
| - magentoPath.append(PHTML_SEPARATOR); |
| 88 | + magentoPath.append(SEPARATOR); |
| 89 | + magentoPath.append(fullPath); |
| 90 | + path = magentoPath.toString(); |
| 91 | + } else if (JS.equals(virtualFile.getExtension())) { |
| 92 | + index = -1; |
| 93 | + final int endIndex = getIndexOf(fullPath, jsPaths[++index], jsPaths); |
| 94 | + final int offset = jsPaths[index].length(); |
| 95 | + |
| 96 | + fullPath.replace(0, endIndex + offset, ""); |
| 97 | + magentoPath.append(SEPARATOR); |
73 | 98 | magentoPath.append(fullPath);
|
74 | 99 | path = magentoPath.toString();
|
75 | 100 | }
|
76 | 101 |
|
77 | 102 | return path;
|
78 | 103 | }
|
79 | 104 |
|
80 |
| - private int getIndexOf(final StringBuilder fullPath, final String path) { |
| 105 | + private int getIndexOf(final StringBuilder fullPath, final String path, final String[] paths) { |
81 | 106 | return fullPath.lastIndexOf(path) == -1
|
82 |
| - ? getIndexOf(fullPath, templatePaths[++index]) |
| 107 | + ? getIndexOf(fullPath, paths[++index], paths) |
83 | 108 | : fullPath.lastIndexOf(path);
|
84 | 109 | }
|
85 | 110 | }
|
0 commit comments