emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r112058: * nsfns.m (ns_filename_from_


From: Jan D.
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112058: * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New
Date: Sat, 16 Mar 2013 14:52:12 +0100
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 112058
fixes bug: http://debbugs.gnu.org/13932
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Sat 2013-03-16 14:52:12 +0100
message:
  * 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.
modified:
  src/ChangeLog
  src/nsfns.m
  src/nsterm.h
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-03-15 20:03:31 +0000
+++ b/src/ChangeLog     2013-03-16 13:52:12 +0000
@@ -1,3 +1,17 @@
+2013-03-16  Jan Djärv  <address@hidden>
+
+       * 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  <address@hidden>
 
        * coding.c (decode_coding_gap): Fix typo caught by static checking.

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2013-03-07 03:01:17 +0000
+++ b/src/nsfns.m       2013-03-16 13:52:12 +0000
@@ -261,6 +261,29 @@
   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 @@
    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 @@
       [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 @@
     }
   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 @@
   [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 @@
 - (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 @@
   [super cancel: sender];
   [NSApp stop: self];
 }
+
 #endif
+- (NSString *) getFilename
+{
+  return ns_filename_from_panel (self);
+}
+- (NSString *) getDirectory
+{
+  return ns_directory_from_panel (self);
+}
+
 @end
 
 

=== modified file 'src/nsterm.h'
--- a/src/nsterm.h      2013-02-05 12:16:35 +0000
+++ b/src/nsterm.h      2013-03-16 13:52:12 +0000
@@ -267,10 +267,14 @@
 @interface EmacsSavePanel : NSSavePanel
 {
 }
+- (NSString *) getFilename;
+- (NSString *) getDirectory;
 @end
 @interface EmacsOpenPanel : NSOpenPanel
 {
 }
+- (NSString *) getFilename;
+- (NSString *) getDirectory;
 @end
 
 @interface EmacsFileDelegate : NSObject


reply via email to

[Prev in Thread] Current Thread [Next in Thread]