Skip to content

Commit 906a192

Browse files
committed
Added JS support for Copy Magento Path
1 parent bd7d510 commit 906a192

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,42 @@
1818
import org.jetbrains.annotations.NotNull;
1919
import org.jetbrains.annotations.Nullable;
2020

21+
import java.util.Arrays;
22+
import java.util.List;
23+
2124
public class CopyMagentoPath extends CopyPathProvider {
2225
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 = "::";
2429
private int index;
30+
2531
private final String[] templatePaths = {
2632
"view/frontend/templates/",
2733
"view/adminhtml/templates/",
2834
"view/base/templates/",
2935
"templates/"
3036
};
3137

38+
private final String[] jsPaths = {
39+
"view/frontend/web/",
40+
"view/adminhtml/web/",
41+
"view/base/web/"
42+
};
43+
3244
@Override
3345
public void update(@NotNull final AnActionEvent event) {
3446
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)) {
3748
event.getPresentation().setVisible(false);
3849
}
3950
}
4051

52+
private boolean isNotValidFile(VirtualFile virtualFile) {
53+
return virtualFile != null && virtualFile.isDirectory()
54+
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension());
55+
}
56+
4157
@Nullable
4258
@Override
4359
public String getPathToElement(
@@ -65,21 +81,30 @@ public String getPathToElement(
6581

6682
if (PHTML.equals(virtualFile.getExtension())) {
6783
index = -1;
68-
final int endIndex = getIndexOf(fullPath, templatePaths[++index]);
84+
final int endIndex = getIndexOf(fullPath, templatePaths[++index], templatePaths);
6985
final int offset = templatePaths[index].length();
7086

7187
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);
7398
magentoPath.append(fullPath);
7499
path = magentoPath.toString();
75100
}
76101

77102
return path;
78103
}
79104

80-
private int getIndexOf(final StringBuilder fullPath, final String path) {
105+
private int getIndexOf(final StringBuilder fullPath, final String path, final String[] paths) {
81106
return fullPath.lastIndexOf(path) == -1
82-
? getIndexOf(fullPath, templatePaths[++index])
107+
? getIndexOf(fullPath, paths[++index], paths)
83108
: fullPath.lastIndexOf(path);
84109
}
85110
}

0 commit comments

Comments
 (0)