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 .ArrayList ;
18
19
import java .util .Arrays ;
19
20
import java .util .List ;
21
+ import javax .imageio .ImageIO ;
20
22
import org .jetbrains .annotations .NotNull ;
21
23
import org .jetbrains .annotations .Nullable ;
22
24
@@ -27,6 +29,8 @@ public class CopyMagentoPath extends CopyPathProvider {
27
29
public static final String CSS_EXTENSION = "css" ;
28
30
private final List <String > acceptedTypes
29
31
= Arrays .asList (PHTML_EXTENSION , JS_EXTENSION , CSS_EXTENSION );
32
+ private static final List <String > SUPPORTED_IMAGE_EXTENSIONS
33
+ = new ArrayList <>(Arrays .asList (ImageIO .getReaderFormatNames ()));
30
34
public static final String SEPARATOR = "::" ;
31
35
private int index ;
32
36
@@ -44,6 +48,15 @@ public class CopyMagentoPath extends CopyPathProvider {
44
48
"web/"
45
49
};
46
50
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
+
47
60
@ Override
48
61
public void update (@ NotNull final AnActionEvent event ) {
49
62
final VirtualFile virtualFile = event .getData (PlatformDataKeys .VIRTUAL_FILE );
@@ -54,7 +67,8 @@ public void update(@NotNull final AnActionEvent event) {
54
67
55
68
private boolean isNotValidFile (final VirtualFile virtualFile ) {
56
69
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 ());
58
72
}
59
73
60
74
@ Override
@@ -85,24 +99,23 @@ private boolean isNotValidFile(final VirtualFile virtualFile) {
85
99
if (PHTML_EXTENSION .equals (virtualFile .getExtension ())) {
86
100
paths = templatePaths ;
87
101
} 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 ())) {
89
104
paths = webPaths ;
90
105
} else {
91
106
return fullPath .toString ();
92
107
}
93
- int endIndex ;
94
108
95
109
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 ();
102
112
103
- fullPath .replace (0 , endIndex + offset , "" );
113
+ fullPath .replace (0 , endIndex + offset , "" );
104
114
105
- return moduleName + SEPARATOR + fullPath ;
115
+ return moduleName + SEPARATOR + fullPath ;
116
+ } catch (ArrayIndexOutOfBoundsException exception ) {
117
+ return fullPath .toString ();
118
+ }
106
119
}
107
120
108
121
/**
0 commit comments