9
9
import com .intellij .openapi .vfs .VirtualFile ;
10
10
import com .intellij .psi .PsiFile ;
11
11
import com .magento .idea .magento2plugin .project .Settings ;
12
+ import java .util .ArrayList ;
12
13
import java .util .List ;
13
14
14
15
public final class IsFileInEditableModuleUtil {
@@ -29,37 +30,33 @@ public static boolean execute(final PsiFile file) {
29
30
}
30
31
31
32
/**
32
- * Validates if a given virtual file is located within editable paths defined by Magento project structure .
33
+ * Validates if a given virtual file is located within editable paths.
33
34
*
34
35
* @param project the current project containing the virtual file
35
36
* @param virtualFile the file to check against editable module directories
36
37
* @return true if the file is in an editable module directory, false otherwise
37
38
*/
38
39
public static boolean execute (final Project project , final VirtualFile virtualFile ) {
39
- final Settings settings = Settings .getInstance (project );
40
- List <String > magentoToFolders = settings .getMagentoFolders ();
41
- final String magentoPathUrl = MagentoPathUrlUtil .execute (project );
42
- if (magentoPathUrl != null ) {
43
- if (magentoToFolders == null ) {
44
- magentoToFolders = List .of (
45
- magentoPathUrl
46
- );
47
- } else {
48
- magentoToFolders .add (
49
- magentoPathUrl
50
- );
51
- }
40
+ final String magentoRootPath = MagentoPathUrlUtil .execute (project );
41
+ if (magentoRootPath == null ) {
42
+ return false ;
52
43
}
53
44
45
+ final Settings settings = Settings .getInstance (project );
46
+ List <String > editablePaths = settings .getMagentoFolders ();
47
+ if (editablePaths == null ) {
48
+ editablePaths = new ArrayList <>();
49
+ }
54
50
55
-
56
- if (magentoToFolders == null ) {
57
- return false ;
51
+ editablePaths .add (magentoRootPath );
52
+ final String magentoDesignPath = MagentoPathUrlUtil .getDesignPath (project );
53
+ if (magentoDesignPath != null ) {
54
+ editablePaths .add (magentoDesignPath );
58
55
}
59
56
60
- final String filePath = virtualFile .getUrl ();
61
- for (final String editablePath : magentoToFolders ) {
62
- if (normalizeUrl (filePath ).startsWith (normalizeUrl (editablePath ))) {
57
+ final String currentFilePath = virtualFile .getUrl ();
58
+ for (final String editablePath : editablePaths ) {
59
+ if (normalizeUrl (currentFilePath ).startsWith (normalizeUrl (editablePath ))) {
63
60
return true ;
64
61
}
65
62
}
0 commit comments