Skip to content

Added support for image copy path #559

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

Closed
wants to merge 7 commits into from
Closed
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
24 changes: 13 additions & 11 deletions src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

public class CopyMagentoPath extends CopyPathProvider {
public static final String PHTML_EXTENSION = "phtml";
public static final String JS_EXTENSION = "js";
public static final String CSS_EXTENSION = "css";
private final List<String> acceptedTypes
= Arrays.asList(PHTML_EXTENSION, JS_EXTENSION, CSS_EXTENSION);
public static final List<String> WEB_EXTENSIONS
= Arrays.asList("js", "css", "png", "jpg", "jpeg", "gif");
Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, isn't possible to use ImageIO::read? This should return null if the provided file cannot be read as an image. Or maybe there are some alternatives to check the file's contentType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently thinking of a way to support ONLY the Magento supported types. There's a lot more image types I missed which @DmitryFurs has described. So I'll check if the ImageIO types match the supported types, and develop a better solution. Thanks for the suggestion @eduard13 and @DmitryFurs!

public static final String SEPARATOR = "::";
private int index;

Expand Down Expand Up @@ -53,7 +51,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 && !WEB_EXTENSIONS.contains(virtualFile.getExtension())
&& !PHTML_EXTENSION.equals(virtualFile.getExtension());
}

@Nullable
Expand Down Expand Up @@ -83,19 +82,22 @@ public String getPathToElement(

if (PHTML_EXTENSION.equals(virtualFile.getExtension())) {
paths = templatePaths;
} else if (JS_EXTENSION.equals(virtualFile.getExtension())
|| CSS_EXTENSION.equals(virtualFile.getExtension())) {
} else if (WEB_EXTENSIONS.contains(virtualFile.getExtension())) {
paths = webPaths;
} else {
return fullPath.toString();
}

final int endIndex = getIndexOf(paths, fullPath, paths[++index]);
final int offset = paths[index].length();
try {
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();
}
}

private int getIndexOf(final String[] paths, final StringBuilder fullPath, final String path) {
Expand Down