From: Jan Djärv Date: Sat, 16 Mar 2013 13:52:12 +0000 (+0100) Subject: * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~561 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8f2906f551da4a06c0097887e8ad61b8144baeac;p=emacs.git * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New functions. (Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose directories. If filename is nil, get directory name. Use getFilename and getDirectory. (getFilename, getDirectory): New methods for EmacsSavePanel and EmacsOpenPanel. (ok:): In EmacsOpenPanel, if we can't choose directories, just return. * nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename and getDirectory. Fixes: debbugs:13932 --- diff --git a/src/ChangeLog b/src/ChangeLog index 288996fffb2..d924772abad 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2013-03-16 Jan Djärv + + * nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename + and getDirectory. + + * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New + functions. + (Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose + directories. If filename is nil, get directory name (Bug#13932). + Use getFilename and getDirectory. + (getFilename, getDirectory): New methods for EmacsSavePanel and + EmacsOpenPanel. + (ok:): In EmacsOpenPanel, if we can't choose directories, just return. + 2013-03-15 Paul Eggert * coding.c (decode_coding_gap): Fix typo caught by static checking. diff --git a/src/nsfns.m b/src/nsfns.m index e4dde5fb894..ef18acaa045 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -261,6 +261,29 @@ ns_display_info_for_name (Lisp_Object name) return dpyinfo; } +static NSString * +ns_filename_from_panel (NSSavePanel *panel) +{ +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + NSURL *url = [panel URL]; + NSString *str = [url path]; + return str; +#else + return [panel filename]; +#endif +} + +static NSString * +ns_directory_from_panel (NSSavePanel *panel) +{ +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + NSURL *url = [panel directoryURL]; + NSString *str = [url path]; + return str; +#else + return [panel directory]; +#endif +} static Lisp_Object interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) @@ -1471,7 +1494,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) Lisp_Object init, Lisp_Object dir_only_p) { static id fileDelegate = nil; - int ret; + BOOL ret; id panel; Lisp_Object fname; @@ -1508,6 +1531,13 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) [panel setCanChooseDirectories: YES]; [panel setCanChooseFiles: NO]; } + else + { + /* This is not quite what the documentation says, but it is compatible + with the Gtk+ code. Also, the menu entry says "Open File...". */ + [panel setCanChooseDirectories: NO]; + [panel setCanChooseFiles: YES]; + } block_input (); #if defined (NS_IMPL_COCOA) && \ @@ -1528,15 +1558,19 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) } else { - [panel setCanChooseDirectories: YES]; ret = [panel runModalForDirectory: dirS file: initS types: nil]; } #endif ret = (ret == NSOKButton) || panelOK; - if (ret) - fname = build_string ([[panel filename] UTF8String]); + if (ret) + { + NSString *str = [panel getFilename]; + if (! str) str = [panel getDirectory]; + if (! str) ret = NO; + else fname = build_string ([str UTF8String]); + } [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; unblock_input (); @@ -2603,6 +2637,14 @@ Value is t if tooltip was open, nil otherwise. */) [NSApp stop: self]; } #endif +- (NSString *) getFilename +{ + return ns_filename_from_panel (self); +} +- (NSString *) getDirectory +{ + return ns_directory_from_panel (self); +} @end @@ -2616,6 +2658,12 @@ Value is t if tooltip was open, nil otherwise. */) - (void) ok: (id)sender { [super ok: sender]; + + // If not choosing directories, and Open is pressed on a directory, return. + if (! [self canChooseDirectories] && [self getDirectory] && + ! [self getFilename]) + return; + panelOK = 1; [NSApp stop: self]; } @@ -2624,7 +2672,17 @@ Value is t if tooltip was open, nil otherwise. */) [super cancel: sender]; [NSApp stop: self]; } + #endif +- (NSString *) getFilename +{ + return ns_filename_from_panel (self); +} +- (NSString *) getDirectory +{ + return ns_directory_from_panel (self); +} + @end diff --git a/src/nsterm.h b/src/nsterm.h index 41dbaf3c0f7..6bd04b96684 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -267,10 +267,14 @@ along with GNU Emacs. If not, see . */ @interface EmacsSavePanel : NSSavePanel { } +- (NSString *) getFilename; +- (NSString *) getDirectory; @end @interface EmacsOpenPanel : NSOpenPanel { } +- (NSString *) getFilename; +- (NSString *) getDirectory; @end @interface EmacsFileDelegate : NSObject