+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.
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)
Lisp_Object init, Lisp_Object dir_only_p)
{
static id fileDelegate = nil;
- int ret;
+ BOOL ret;
id panel;
Lisp_Object fname;
[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) && \
}
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 ();
[NSApp stop: self];
}
#endif
+- (NSString *) getFilename
+{
+ return ns_filename_from_panel (self);
+}
+- (NSString *) getDirectory
+{
+ return ns_directory_from_panel (self);
+}
@end
- (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];
}
[super cancel: sender];
[NSApp stop: self];
}
+
#endif
+- (NSString *) getFilename
+{
+ return ns_filename_from_panel (self);
+}
+- (NSString *) getDirectory
+{
+ return ns_directory_from_panel (self);
+}
+
@end