Commit 8f2906f5 authored by Jan Djärv's avatar Jan Djärv
Browse files

* 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
parent 3f53a2bd
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> 2013-03-15 Paul Eggert <eggert@cs.ucla.edu>
   
* coding.c (decode_coding_gap): Fix typo caught by static checking. * coding.c (decode_coding_gap): Fix typo caught by static checking.
......
...@@ -261,6 +261,29 @@ Updated by Christian Limpach (chris@nice.ch) ...@@ -261,6 +261,29 @@ Updated by Christian Limpach (chris@nice.ch)
return dpyinfo; 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 static Lisp_Object
interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) 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 ...@@ -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) Lisp_Object init, Lisp_Object dir_only_p)
{ {
static id fileDelegate = nil; static id fileDelegate = nil;
int ret; BOOL ret;
id panel; id panel;
Lisp_Object fname; Lisp_Object fname;
...@@ -1508,6 +1531,13 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side ...@@ -1508,6 +1531,13 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
[panel setCanChooseDirectories: YES]; [panel setCanChooseDirectories: YES];
[panel setCanChooseFiles: NO]; [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 (); block_input ();
#if defined (NS_IMPL_COCOA) && \ #if defined (NS_IMPL_COCOA) && \
...@@ -1528,15 +1558,19 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side ...@@ -1528,15 +1558,19 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
} }
else else
{ {
[panel setCanChooseDirectories: YES];
ret = [panel runModalForDirectory: dirS file: initS types: nil]; ret = [panel runModalForDirectory: dirS file: initS types: nil];
} }
#endif #endif
ret = (ret == NSOKButton) || panelOK; ret = (ret == NSOKButton) || panelOK;
if (ret) if (ret)
fname = build_string ([[panel filename] UTF8String]); {
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]; [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
unblock_input (); unblock_input ();
...@@ -2603,6 +2637,14 @@ - (void) cancel: (id)sender ...@@ -2603,6 +2637,14 @@ - (void) cancel: (id)sender
[NSApp stop: self]; [NSApp stop: self];
} }
#endif #endif
- (NSString *) getFilename
{
return ns_filename_from_panel (self);
}
- (NSString *) getDirectory
{
return ns_directory_from_panel (self);
}
@end @end
...@@ -2616,6 +2658,12 @@ @implementation EmacsOpenPanel ...@@ -2616,6 +2658,12 @@ @implementation EmacsOpenPanel
- (void) ok: (id)sender - (void) ok: (id)sender
{ {
[super ok: 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; panelOK = 1;
[NSApp stop: self]; [NSApp stop: self];
} }
...@@ -2624,7 +2672,17 @@ - (void) cancel: (id)sender ...@@ -2624,7 +2672,17 @@ - (void) cancel: (id)sender
[super cancel: sender]; [super cancel: sender];
[NSApp stop: self]; [NSApp stop: self];
} }
#endif #endif
- (NSString *) getFilename
{
return ns_filename_from_panel (self);
}
- (NSString *) getDirectory
{
return ns_directory_from_panel (self);
}
@end @end
......
...@@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ ...@@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
@interface EmacsSavePanel : NSSavePanel @interface EmacsSavePanel : NSSavePanel
{ {
} }
- (NSString *) getFilename;
- (NSString *) getDirectory;
@end @end
@interface EmacsOpenPanel : NSOpenPanel @interface EmacsOpenPanel : NSOpenPanel
{ {
} }
- (NSString *) getFilename;
- (NSString *) getDirectory;
@end @end
@interface EmacsFileDelegate : NSObject @interface EmacsFileDelegate : NSObject
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment