changeset 5249:806c0f5936f1

7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders Reviewed-by: anthony Contributed-by: Marco Dinacci <marco.dinacci@gmail.com>
author serb
date Mon, 13 Aug 2012 20:59:48 +0400
parents 043839897cd9
children 547880604844
files src/macosx/classes/sun/lwawt/macosx/CFileDialog.java src/macosx/native/sun/awt/CFileDialog.h src/macosx/native/sun/awt/CFileDialog.m
diffstat 3 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java	Thu Aug 09 20:46:39 2012 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java	Mon Aug 13 20:59:48 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/src/macosx/native/sun/awt/CFileDialog.h	Thu Aug 09 20:46:39 2012 -0700
+++ b/src/macosx/native/sun/awt/CFileDialog.h	Mon Aug 13 20:59:48 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/src/macosx/native/sun/awt/CFileDialog.m	Thu Aug 09 20:46:39 2012 -0700
+++ b/src/macosx/native/sun/awt/CFileDialog.m	Mon Aug 13 20:59:48 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)