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