7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
authorserb
Mon, 13 Aug 2012 17:43:37 +0400
changeset 13538 822dc12a21c1
parent 13418 5d3f9ceedec9
child 13540 7db2a9741c48
7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders Reviewed-by: art, anthony Contributed-by: Marco Dinacci <marco.dinacci@gmail.com>
jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java
jdk/src/macosx/native/sun/awt/CFileDialog.h
jdk/src/macosx/native/sun/awt/CFileDialog.m
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java	Fri Aug 10 10:15:52 2012 -0700
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java	Mon Aug 13 17:43:37 2012 +0400
@@ -30,12 +30,14 @@
 import java.awt.BufferCapabilities.FlipContents;
 import java.awt.event.*;
 import java.awt.image.*;
+import java.security.AccessController;
 import java.util.List;
 import java.io.*;
 
 import sun.awt.CausedFocusEvent.Cause;
 import sun.awt.AWTAccessor;
 import sun.java2d.pipe.Region;
+import sun.security.action.GetBooleanAction;
 
 class CFileDialog implements FileDialogPeer {
 
@@ -53,11 +55,14 @@
                 if (title == null) {
                     title = " ";
                 }
+                Boolean chooseDirectories = AccessController.doPrivileged(
+                        new GetBooleanAction("apple.awt.fileDialogForDirectories"));
 
                 String[] userFileNames = nativeRunFileDialog(title,
                         dialogMode,
                         target.isMultipleMode(),
                         navigateApps,
+                        chooseDirectories,
                         target.getFilenameFilter() != null,
                         target.getDirectory(),
                         target.getFile());
@@ -142,7 +147,8 @@
     }
 
     private native String[] nativeRunFileDialog(String title, int mode,
-            boolean multipleMode, boolean shouldNavigateApps, boolean hasFilenameFilter,
+            boolean multipleMode, boolean shouldNavigateApps,
+            boolean canChooseDirectories, boolean hasFilenameFilter,
             String directory, String file);
 
     @Override
--- a/jdk/src/macosx/native/sun/awt/CFileDialog.h	Fri Aug 10 10:15:52 2012 -0700
+++ b/jdk/src/macosx/native/sun/awt/CFileDialog.h	Mon Aug 13 17:43:37 2012 +0400
@@ -52,6 +52,9 @@
     // Should we navigate into apps?
     BOOL fNavigateApps;
 
+    // Can the dialog choose directories ?
+    BOOL fChooseDirectories;
+
     // Contains the absolute paths of the selected files as URLs
     NSArray *fURLs;
 }
@@ -65,6 +68,7 @@
                  mode:(jint)inMode
          multipleMode:(BOOL)inMultipleMode
        shouldNavigate:(BOOL)inNavigateApps
+ canChooseDirectories:(BOOL)inChooseDirectories
               withEnv:(JNIEnv*)env;
 
 // Invoked from the main thread
--- a/jdk/src/macosx/native/sun/awt/CFileDialog.m	Fri Aug 10 10:15:52 2012 -0700
+++ b/jdk/src/macosx/native/sun/awt/CFileDialog.m	Mon Aug 13 17:43:37 2012 +0400
@@ -43,6 +43,7 @@
                 mode:(jint)inMode
         multipleMode:(BOOL)inMultipleMode
       shouldNavigate:(BOOL)inNavigateApps
+canChooseDirectories:(BOOL)inChooseDirectories
              withEnv:(JNIEnv*)env;
 {
     if (self == [super init]) {
@@ -57,6 +58,7 @@
         fMode = inMode;
         fMultipleMode = inMultipleMode;
         fNavigateApps = inNavigateApps;
+        fChooseDirectories = inChooseDirectories;
         fPanelResult = NSCancelButton;
     }
 
@@ -109,7 +111,7 @@
             NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
             [openPanel setAllowsMultipleSelection:fMultipleMode];
             [openPanel setCanChooseFiles:YES];
-            [openPanel setCanChooseDirectories:NO];
+            [openPanel setCanChooseDirectories:fChooseDirectories];
             [openPanel setCanCreateDirectories:YES];
         }
 
@@ -182,7 +184,8 @@
 JNIEXPORT jobjectArray JNICALL
 Java_sun_lwawt_macosx_CFileDialog_nativeRunFileDialog
 (JNIEnv *env, jobject peer, jstring title, jint mode, jboolean multipleMode,
- jboolean navigateApps, jboolean hasFilter, jstring directory, jstring file)
+ jboolean navigateApps, jboolean chooseDirectories, jboolean hasFilter,
+ jstring directory, jstring file)
 {
     jobjectArray returnValue = NULL;
 
@@ -200,6 +203,7 @@
                                                                  mode:mode
                                                          multipleMode:multipleMode
                                                        shouldNavigate:navigateApps
+                                                 canChooseDirectories:chooseDirectories
                                                               withEnv:env];
 
     [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad)