* 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
This commit is contained in:
Jan Djärv 2013-03-16 14:52:12 +01:00
parent 3f53a2bd1a
commit 8f2906f551
3 changed files with 80 additions and 4 deletions

View file

@ -1,3 +1,17 @@
2013-03-16 Jan Djärv <jan.h.d@swipnet.se>
* 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 <eggert@cs.ucla.edu>
* coding.c (decode_coding_gap): Fix typo caught by static checking.

View file

@ -261,6 +261,29 @@ Updated by Christian Limpach (chris@nice.ch)
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 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
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 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
[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 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
}
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 @@ - (void) cancel: (id)sender
[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 @@ @implementation EmacsOpenPanel
- (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 @@ - (void) cancel: (id)sender
[super cancel: sender];
[NSApp stop: self];
}
#endif
- (NSString *) getFilename
{
return ns_filename_from_panel (self);
}
- (NSString *) getDirectory
{
return ns_directory_from_panel (self);
}
@end

View file

@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
@interface EmacsSavePanel : NSSavePanel
{
}
- (NSString *) getFilename;
- (NSString *) getDirectory;
@end
@interface EmacsOpenPanel : NSOpenPanel
{
}
- (NSString *) getFilename;
- (NSString *) getDirectory;
@end
@interface EmacsFileDelegate : NSObject