Skip to content

Commit ab81ce1

Browse files
committed
414: Added Images support for Copy Magento Path
1 parent effbf30 commit ab81ce1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
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
/**

0 commit comments

Comments
 (0)