jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m
author anashaty
Tue, 20 Jan 2015 19:26:14 +0300
changeset 28990 2656e19f0cd6
parent 26751 70bac69b37c9
permissions -rw-r--r--
8068283: Mac OS Incompatibility between JDK 6 and 8 regarding input method handling Reviewed-by: ant, kizune
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
23611
72d34c61dc4a 8034211: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CFileDialog.m
serb
parents: 20452
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import <sys/stat.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import "CFileDialog.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
#import "java_awt_FileDialog.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
#import "sun_lwawt_macosx_CFileDialog.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
@implementation CFileDialog
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
- (id)initWithFilter:(jboolean)inHasFilter
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
          fileDialog:(jobject)inDialog
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
               title:(NSString *)inTitle
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
           directory:(NSString *)inPath
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
                file:(NSString *)inFile
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
                mode:(jint)inMode
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
    44
        multipleMode:(BOOL)inMultipleMode
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
      shouldNavigate:(BOOL)inNavigateApps
13538
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
    46
canChooseDirectories:(BOOL)inChooseDirectories
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
             withEnv:(JNIEnv*)env;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
    if (self == [super init]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
        fHasFileFilter = inHasFilter;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
        fFileDialog = JNFNewGlobalRef(env, inDialog);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
        fDirectory = inPath;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
        [fDirectory retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
        fFile = inFile;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
        [fFile retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
        fTitle = inTitle;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
        [fTitle retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
        fMode = inMode;
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
    59
        fMultipleMode = inMultipleMode;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
        fNavigateApps = inNavigateApps;
13538
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
    61
        fChooseDirectories = inChooseDirectories;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
        fPanelResult = NSCancelButton;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
-(void) disposer {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    if (fFileDialog != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
        JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
        JNFDeleteGlobalRef(env, fFileDialog);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
        fFileDialog = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
-(void) dealloc {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    [fDirectory release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    fDirectory = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    [fFile release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    fFile = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    [fTitle release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    fTitle = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
    86
    [fURLs release];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
    87
    fURLs = nil;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
- (void)safeSaveOrLoad {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    NSSavePanel *thePanel = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
20452
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
    95
    /* 
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
    96
     * 8013553: turns off extension hiding for the native file dialog.
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
    97
     * This way is used because setExtensionHidden(NO) doesn't work
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
    98
     * as expected.
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
    99
     */
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
   100
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
   101
    [defaults setBool:NO forKey:@"NSNavLastUserSetHideExtensionButtonState"];
6e4dba882546 8013553: [macosx] java.awt.FileDialog removes file extensions
bagiras
parents: 20430
diff changeset
   102
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    if (fMode == java_awt_FileDialog_SAVE) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
        thePanel = [NSSavePanel savePanel];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
        [thePanel setAllowsOtherFileTypes:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
        thePanel = [NSOpenPanel openPanel];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    if (thePanel != nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        [thePanel setTitle:fTitle];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
        if (fNavigateApps) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
            [thePanel setTreatsFilePackagesAsDirectories:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
        if (fMode == java_awt_FileDialog_LOAD) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
            NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   119
            [openPanel setAllowsMultipleSelection:fMultipleMode];
20430
8cc1a2344d8f 8025503: [macosx] FileDialog allows file selection with apple.awt.fileDialogForDirectories = true
pchelko
parents: 13538
diff changeset
   120
            [openPanel setCanChooseFiles:!fChooseDirectories];
13538
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
   121
            [openPanel setCanChooseDirectories:fChooseDirectories];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
            [openPanel setCanCreateDirectories:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        [thePanel setDelegate:self];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        fPanelResult = [thePanel runModalForDirectory:fDirectory file:fFile];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        [thePanel setDelegate:nil];
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   128
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   129
        if ([self userClickedOK]) {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   130
            if (fMode == java_awt_FileDialog_LOAD) {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   131
                NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   132
                fURLs = [openPanel URLs];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   133
            } else {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   134
                fURLs = [NSArray arrayWithObject:[thePanel URL]];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   135
            }
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   136
            [fURLs retain];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   137
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    [self disposer];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
- (BOOL) askFilenameFilter:(NSString *)filename {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
    JNIEnv *env = [ThreadUtilities getJNIEnv];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    jstring jString = JNFNormalizedJavaStringForPath(env, filename);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    static JNF_CLASS_CACHE(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
    static JNF_MEMBER_CACHE(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    BOOL returnValue = JNFCallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    (*env)->DeleteLocalRef(env, jString);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    return returnValue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
    if (!fHasFileFilter) return YES; // no filter, no problem!
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    // check if it's not a normal file
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    NSNumber *isFile = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    if ([url getResourceValue:&isFile forKey:NSURLIsRegularFileKey error:nil]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        if (![isFile boolValue]) return YES; // always show directories and non-file entities (browsing servers/mounts, etc)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    // if in directory-browsing mode, don't offer files
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    if ((fMode != java_awt_FileDialog_LOAD) && (fMode != java_awt_FileDialog_SAVE)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
        return NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    // ask the file filter up in Java
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23611
diff changeset
   170
    NSString* filePath = (NSString*)CFURLCopyFileSystemPath((CFURLRef)url, kCFURLPOSIXPathStyle);
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23611
diff changeset
   171
    BOOL shouldEnableFile = [self askFilenameFilter:filePath];
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23611
diff changeset
   172
    [filePath release];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    return shouldEnableFile;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
- (BOOL) userClickedOK {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
    return fPanelResult == NSOKButton;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   180
- (NSArray *)URLs {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   181
    return [[fURLs retain] autorelease];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
 * Class:     sun_lwawt_macosx_CFileDialog
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
 * Method:    nativeRunFileDialog
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
 * Signature: (Ljava/lang/String;ILjava/io/FilenameFilter;
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   189
 *             Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
 */
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   191
JNIEXPORT jobjectArray JNICALL
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
Java_sun_lwawt_macosx_CFileDialog_nativeRunFileDialog
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   193
(JNIEnv *env, jobject peer, jstring title, jint mode, jboolean multipleMode,
13538
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
   194
 jboolean navigateApps, jboolean chooseDirectories, jboolean hasFilter,
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
   195
 jstring directory, jstring file)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
{
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   197
    jobjectArray returnValue = NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    NSString *dialogTitle = JNFJavaToNSString(env, title);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    if ([dialogTitle length] == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
        dialogTitle = @" ";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    CFileDialog *dialogDelegate = [[CFileDialog alloc] initWithFilter:hasFilter
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
                                                           fileDialog:peer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
                                                                title:dialogTitle
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
                                                            directory:JNFJavaToNSString(env, directory)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
                                                                 file:JNFJavaToNSString(env, file)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
                                                                 mode:mode
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   211
                                                         multipleMode:multipleMode
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
                                                       shouldNavigate:navigateApps
13538
822dc12a21c1 7161437: [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
serb
parents: 12653
diff changeset
   213
                                                 canChooseDirectories:chooseDirectories
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
                                                              withEnv:env];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
    [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
                                 on:dialogDelegate
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
                         withObject:nil
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
                      waitUntilDone:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    if ([dialogDelegate userClickedOK]) {
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   222
        NSArray *urls = [dialogDelegate URLs];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   223
        jsize count = [urls count];
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   224
23611
72d34c61dc4a 8034211: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CFileDialog.m
serb
parents: 20452
diff changeset
   225
        static JNF_CLASS_CACHE(jc_String, "java/lang/String");
72d34c61dc4a 8034211: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CFileDialog.m
serb
parents: 20452
diff changeset
   226
        returnValue = JNFNewObjectArray(env, &jc_String, count);
12653
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   227
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   228
        [urls enumerateObjectsUsingBlock:^(id url, NSUInteger index, BOOL *stop) {
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   229
            jstring filename = JNFNormalizedJavaStringForPath(env, [url path]);
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   230
            (*env)->SetObjectArrayElement(env, returnValue, index, filename);
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   231
            (*env)->DeleteLocalRef(env, filename);
07d5ca30e79e 7124337: [macosx] FileDialog fails to select multiple files
dcherepanov
parents: 12047
diff changeset
   232
        }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    [dialogDelegate release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
    return returnValue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
}