amondel2 commented on code in PR #441:
URL: 
https://github.com/apache/grails-intellij-plugin/pull/441#discussion_r4290171294


##########
plugin/src/main/java/org/apache/grails/intellij/plugin/actions/AddCustomFolderAction.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.grails.intellij.plugin.actions;
+
+import com.intellij.openapi.actionSystem.ActionUpdateThread;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiDirectory;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiManager;
+import 
org.apache.grails.intellij.plugin.config.GrailsCustomFoldersProjectService;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AddCustomFolderAction extends DumbAwareAction {
+
+  @Override
+  public void update(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
+    if (project == null) {
+      e.getPresentation().setEnabledAndVisible(false);
+      return;
+    }
+    PsiDirectory directory = getSelectedDirectory(e);
+    if (directory == null || isProjectRoot(project, directory)) {
+      e.getPresentation().setEnabledAndVisible(false);
+      return;
+    }
+
+    GrailsCustomFoldersProjectService service = 
project.getService(GrailsCustomFoldersProjectService.class);
+    if (service.getFolders().size() >= 
GrailsCustomFoldersProjectService.MAX_FOLDERS) {
+      e.getPresentation().setVisible(true);
+      e.getPresentation().setEnabled(false);
+      e.getPresentation().setDescription(
+          "Maximum of " + GrailsCustomFoldersProjectService.MAX_FOLDERS + " 
custom folders reached. Remove one first.");
+    }
+    else {
+      e.getPresentation().setEnabledAndVisible(true);
+    }
+  }
+
+  @Override
+  public @NotNull ActionUpdateThread getActionUpdateThread() {
+    return ActionUpdateThread.BGT;
+  }
+
+  @Override
+  public void actionPerformed(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
+    PsiDirectory directory = getSelectedDirectory(e);
+    if (project == null || directory == null) return;
+    if (isProjectRoot(project, directory)) return;
+
+    VirtualFile virtualFile = directory.getVirtualFile();
+    String path = VfsUtilCore.getRelativePath(virtualFile, 
project.getBaseDir(), '/');

Review Comment:
   Both sides now use the base you named.
   
   `AddCustomFolderAction` stores `VfsUtilCore.getRelativePath(file, 
application.getRoot(), '/')` with the
   application from 
`GrailsApplicationManager.getInstance(project).findApplication(dir)`, which is 
the
   same `getRoot()` the provider resolves against. `Project.getBaseDir()` no 
longer appears anywhere in
   `plugin/src/main` — a grep for it comes back empty — and the only remaining 
project-directory lookup
   in this feature is `ProjectUtil.guessProjectDir`, matching what the rest of 
the plugin already does.
   
   *Add* is offered only inside an application and is hidden for the 
application root itself, so the base



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to