Skip to content

Commit

Permalink
Merge pull request #1020 from doninAtwix/414-add-action-copy-path-image
Browse files Browse the repository at this point in the history
414: Added Images support for Copy Magento Path
  • Loading branch information
bohdan-harniuk authored Mar 7, 2022
2 parents effbf30 + ab81ce1 commit e06a65b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.imageio.ImageIO;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -27,6 +29,8 @@ public class CopyMagentoPath extends CopyPathProvider {
public static final String CSS_EXTENSION = "css";
private final List<String> acceptedTypes
= Arrays.asList(PHTML_EXTENSION, JS_EXTENSION, CSS_EXTENSION);
private static final List<String> SUPPORTED_IMAGE_EXTENSIONS
= new ArrayList<>(Arrays.asList(ImageIO.getReaderFormatNames()));
public static final String SEPARATOR = "::";
private int index;

Expand All @@ -44,6 +48,15 @@ public class CopyMagentoPath extends CopyPathProvider {
"web/"
};

/**
* Copy Magento Path actions for phtml, css, js, images extensions.
*/
public CopyMagentoPath() {
super();

SUPPORTED_IMAGE_EXTENSIONS.add("svg");
}

@Override
public void update(@NotNull final AnActionEvent event) {
final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
Expand All @@ -54,7 +67,8 @@ public void update(@NotNull final AnActionEvent event) {

private boolean isNotValidFile(final VirtualFile virtualFile) {
return virtualFile != null && virtualFile.isDirectory()
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension());
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension())
&& !SUPPORTED_IMAGE_EXTENSIONS.contains(virtualFile.getExtension());
}

@Override
Expand Down Expand Up @@ -85,24 +99,23 @@ private boolean isNotValidFile(final VirtualFile virtualFile) {
if (PHTML_EXTENSION.equals(virtualFile.getExtension())) {
paths = templatePaths;
} else if (JS_EXTENSION.equals(virtualFile.getExtension())
|| CSS_EXTENSION.equals(virtualFile.getExtension())) {
|| CSS_EXTENSION.equals(virtualFile.getExtension())
|| SUPPORTED_IMAGE_EXTENSIONS.contains(virtualFile.getExtension())) {
paths = webPaths;
} else {
return fullPath.toString();
}
int endIndex;

try {
endIndex = getIndexOf(paths, fullPath, paths[++index]);
} catch (ArrayIndexOutOfBoundsException exception) {
// endIndex could not be found.
return "";
}
final int offset = paths[index].length();
final int endIndex = getIndexOf(paths, fullPath, paths[++index]);
final int offset = paths[index].length();

fullPath.replace(0, endIndex + offset, "");
fullPath.replace(0, endIndex + offset, "");

return moduleName + SEPARATOR + fullPath;
return moduleName + SEPARATOR + fullPath;
} catch (ArrayIndexOutOfBoundsException exception) {
return fullPath.toString();
}
}

/**
Expand Down

0 comments on commit e06a65b

Please sign in to comment.