diff --git a/src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java b/src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java index 1e88d84f4..ac79aebbe 100644 --- a/src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java +++ b/src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java @@ -15,13 +15,20 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.util.Arrays; +import java.util.List; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class CopyMagentoPath extends CopyPathProvider { - public static final String PHTML = "phtml"; - public static final String PHTML_SEPARATOR = "::"; + public static final String PHTML_EXTENSION = "phtml"; + public static final String JS_EXTENSION = "js"; + public static final String CSS_EXTENSION = "css"; + private final List acceptedTypes + = Arrays.asList(PHTML_EXTENSION, JS_EXTENSION, CSS_EXTENSION); + public static final String SEPARATOR = "::"; private int index; + private final String[] templatePaths = { "view/frontend/templates/", "view/adminhtml/templates/", @@ -29,15 +36,26 @@ public class CopyMagentoPath extends CopyPathProvider { "templates/" }; + private final String[] webPaths = { + "view/frontend/web/", + "view/adminhtml/web/", + "view/base/web/", + "web/" + }; + @Override public void update(@NotNull final AnActionEvent event) { final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE); - if (virtualFile != null && virtualFile.isDirectory() - || virtualFile != null && !PHTML.equals(virtualFile.getExtension())) { + if (isNotValidFile(virtualFile)) { event.getPresentation().setVisible(false); } } + private boolean isNotValidFile(final VirtualFile virtualFile) { + return virtualFile != null && virtualFile.isDirectory() + || virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension()); + } + @Nullable @Override public String getPathToElement( @@ -59,27 +77,30 @@ public String getPathToElement( return null; } final StringBuilder fullPath = new StringBuilder(virtualFile.getPath()); - final StringBuilder magentoPath - = new StringBuilder(moduleName); - String path = fullPath.toString(); - if (PHTML.equals(virtualFile.getExtension())) { - index = -1; - final int endIndex = getIndexOf(fullPath, templatePaths[++index]); - final int offset = templatePaths[index].length(); + index = -1; + String[] paths; - fullPath.replace(0, endIndex + offset, ""); - magentoPath.append(PHTML_SEPARATOR); - magentoPath.append(fullPath); - path = magentoPath.toString(); + if (PHTML_EXTENSION.equals(virtualFile.getExtension())) { + paths = templatePaths; + } else if (JS_EXTENSION.equals(virtualFile.getExtension()) + || CSS_EXTENSION.equals(virtualFile.getExtension())) { + paths = webPaths; + } else { + return fullPath.toString(); } - return path; + final int endIndex = getIndexOf(paths, fullPath, paths[++index]); + final int offset = paths[index].length(); + + fullPath.replace(0, endIndex + offset, ""); + + return moduleName + SEPARATOR + fullPath; } - private int getIndexOf(final StringBuilder fullPath, final String path) { + private int getIndexOf(final String[] paths, final StringBuilder fullPath, final String path) { return fullPath.lastIndexOf(path) == -1 - ? getIndexOf(fullPath, templatePaths[++index]) + ? getIndexOf(paths, fullPath, paths[++index]) : fullPath.lastIndexOf(path); } }