IDEA-128713 (option to prevent file chooser from peeking inside non-user directories)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 6 Nov 2014 19:22:12 +0000 (20:22 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 6 Nov 2014 19:22:12 +0000 (20:22 +0100)
bin/idea.properties
platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java

index be34798ed34ea5f4582cc2a5a9ea42855f3f8ff5..a9cd05389fd5f7c87c02a6eb2582c59c5440b89a 100644 (file)
@@ -99,4 +99,11 @@ sun.java2d.pmoffscreen=false
 # Maximum size (kilobytes) IDEA will load for showing past file contents -
 # in Show Diff or when calculating Digest Diff
 #---------------------------------------------------------------------
-#idea.max.vcs.loaded.size.kb=20480
\ No newline at end of file
+#idea.max.vcs.loaded.size.kb=20480
+
+#---------------------------------------------------------------------
+# IDEA file chooser peeks inside directories to detect whether they contain a valid project
+# (to mark such directories with a corresponding icon).
+# Uncommenting the option prevents this behavior outside of user home directory.
+#---------------------------------------------------------------------
+#idea.chooser.lookup.for.project.dirs=false
index b462fcbc11ad316ea6e5f352722e4ed54c39d0db..b5cecc22216904fba5c5b9f58a481e25e1dfd371 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.projectImport.ProjectOpenProcessor;
+import com.intellij.util.SystemProperties;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -34,6 +35,7 @@ import javax.swing.*;
  */
 public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor {
   private static final Icon ourProjectIcon = IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
+  private static final boolean ourCanInspectDirs = SystemProperties.getBooleanProperty("idea.chooser.lookup.for.project.dirs", true);
 
   public OpenProjectFileChooserDescriptor(boolean chooseFiles) {
     super(chooseFiles, true, chooseFiles, chooseFiles, false, false);
@@ -64,15 +66,14 @@ public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor {
   }
 
   private static boolean canInspectDirectory(VirtualFile file) {
-    if (file.getParent() == null) return false;
-
     VirtualFile home = VfsUtil.getUserHomeDir();
-    if (home == null) return false;  // unnatural situation
-    VirtualFile homes = home.getParent();
-    if (homes == null) return false;  // another one
-    if (homes.equals(file.getParent()) || VfsUtilCore.isAncestor(file, homes, false)) return false;
-
-    return true;
+    if (home == null || VfsUtilCore.isAncestor(file, home, false)) {
+      return false;
+    }
+    if (ourCanInspectDirs || VfsUtilCore.isAncestor(home, file, true)) {
+      return true;
+    }
+    return false;
   }
 
   private static Icon getImporterIcon(VirtualFile file) {