Skip to content

414: Added Images support for Copy Magento Path #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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