Support file name dialog on NS.
authorJan Djärv <jan.h.d@swipnet.se>
Sun, 30 Sep 2012 13:43:47 +0000 (15:43 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Sun, 30 Sep 2012 13:43:47 +0000 (15:43 +0200)
* etc/NEWS: Mention that the file dialog is used on NS.

* lisp/term/ns-win.el (x-file-dialog): New function.

* src/fileio.c (Fnext_read_file_uses_dialog_p): Add HAVE_NS.

* src/nsfns.m (ns_frame_parm_handlers): Add x_set_fullscreen.

* src/nsfns.m (Fns_read_file_name): Add argument DIR_ONLY_P.
Initialize panel name field if OSX >= 10.6.

* src/w32fns.c (Fx_file_dialog): Update comment.

* src/xfns.c (Fx_file_dialog): Update comment.

etc/ChangeLog
etc/NEWS
lisp/ChangeLog
lisp/term/ns-win.el
src/ChangeLog
src/fileio.c
src/nsfns.m
src/w32fns.c
src/xfns.c

index 2c1e375..099d7ca 100644 (file)
@@ -1,6 +1,7 @@
 2012-09-30  Jan Djärv  <jan.h.d@swipnet.se>
 
        * NEWS: The NS port supports fullscreen.
+       Mention that the file dialog is used on NS.
 
 2012-09-17  Glenn Morris  <rgm@gnu.org>
 
index e6f09d8..2791a25 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -187,8 +187,11 @@ The PCL-CVS commands are still available via the keyboard.
 ---
 *** New input method `vietnamese-vni'.
 
-** The NS port supports fullscreen.
-
+** NextStep/OSX port changes.
+---
+*** Fullscreen and frame parameter fullscreen is supported.
+---
+*** A file dialog is used when open/saved is done from the menu/toolbar.
 \f
 * Editing Changes in Emacs 24.3
 
index 255b892..5d1a7ee 100644 (file)
@@ -1,3 +1,7 @@
+2012-09-30  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * term/ns-win.el (x-file-dialog): New function.
+
 2012-09-30  Juanma Barranquero  <lekktu@gmail.com>
 
        * ido.el (ido-max-directory-size): Default to nil; the current
index 06b6747..c229ec1 100644 (file)
@@ -452,6 +452,17 @@ Lines are highlighted according to `ns-input-line'."
 
 ;;;; File handling.
 
+(defun x-file-dialog (prompt dir default_filename mustmatch only_dir_p)
+"Read file name, prompting with PROMPT in directory DIR.
+Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
+selection box, if specified.  If MUSTMATCH is non-nil, the returned file
+or directory must exist.
+
+This function is only defined on NS, MS Windows, and X Windows with the
+Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
+Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories."
+  (ns-read-file-name prompt dir mustmatch default_filename only_dir_p))
+
 (defun ns-open-file-using-panel ()
   "Pop up open-file panel, and load the result in a buffer."
   (interactive)
index 6aaa6bc..119651e 100644 (file)
@@ -1,5 +1,14 @@
 2012-09-30  Jan Djärv  <jan.h.d@swipnet.se>
 
+       * xfns.c (Fx_file_dialog): Update comment.
+
+       * w32fns.c (Fx_file_dialog): Update comment.
+
+       * nsfns.m (Fns_read_file_name): Add argument DIR_ONLY_P.
+       Initialize panel name field if OSX >= 10.6.
+
+       * fileio.c (Fnext_read_file_uses_dialog_p): Add HAVE_NS.
+
        * nsfns.m (ns_frame_parm_handlers): Add x_set_fullscreen.
 
        * nsterm.m (NEW_STYLE_FS): New define.
index 9d8a0dc..9ce9e7b 100644 (file)
@@ -5520,7 +5520,8 @@ The return value is only relevant for a call to `read-file-name' that happens
 before any other event (mouse or keypress) is handled.  */)
   (void)
 {
-#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK)
+#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) \
+  || defined (HAVE_NS)
   if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
       && use_dialog_box
       && use_file_dialog
index c96ec99..1efadf0 100644 (file)
@@ -1467,13 +1467,15 @@ DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
 }
 
 
-DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 4, 0,
+DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
        doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
 Optional arg DIR, if non-nil, supplies a default directory.
 Optional arg MUSTMATCH, if non-nil, means the returned file or
 directory must exist.
-Optional arg INIT, if non-nil, provides a default file name to use.  */)
-     (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch, Lisp_Object init)
+Optional arg INIT, if non-nil, provides a default file name to use.
+Optional arg DIR_ONLY_P, if non-nil, means choose only directories.  */)
+  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object mustmatch,
+   Lisp_Object init, Lisp_Object dir_only_p)
 {
   static id fileDelegate = nil;
   int ret;
@@ -1498,21 +1500,36 @@ Optional arg INIT, if non-nil, provides a default file name to use.  */)
   if ([dirS characterAtIndex: 0] == '~')
     dirS = [dirS stringByExpandingTildeInPath];
 
-  panel = NILP (mustmatch) ?
+  panel = NILP (mustmatch) && NILP (dir_only_p) ?
     (id)[EmacsSavePanel savePanel] : (id)[EmacsOpenPanel openPanel];
 
   [panel setTitle: promptS];
 
-  /* Puma (10.1) does not have */
-  if ([panel respondsToSelector: @selector (setAllowsOtherFileTypes:)])
-    [panel setAllowsOtherFileTypes: YES];
-
+  [panel setAllowsOtherFileTypes: YES];
   [panel setTreatsFilePackagesAsDirectories: YES];
   [panel setDelegate: fileDelegate];
 
   panelOK = 0;
+  if (! NILP (dir_only_p)) 
+    {
+      [panel setCanChooseDirectories: YES];
+      [panel setCanChooseFiles: NO];
+    }
+  
   block_input ();
-  if (NILP (mustmatch))
+#if defined (NS_IMPL_COCOA) && \
+  MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+  if (! NILP (mustmatch) || ! NILP (dir_only_p))
+    [panel setAllowedFileTypes: nil];
+  if (dirS) [panel setDirectoryURL: [NSURL fileURLWithPath: dirS]];
+  if (initS && NILP (Ffile_directory_p (init)))
+    [panel setNameFieldStringValue: [initS lastPathComponent]];
+  else
+    [panel setNameFieldStringValue: @""];
+    
+  ret = [panel runModal];
+#else
+  if (NILP (mustmatch) && NILP (dir_only_p))
     {
       ret = [panel runModalForDirectory: dirS file: initS];
     }
@@ -1521,6 +1538,7 @@ Optional arg INIT, if non-nil, provides a default file name to use.  */)
       [panel setCanChooseDirectories: YES];
       ret = [panel runModalForDirectory: dirS file: initS types: nil];
     }
+#endif
 
   ret = (ret == NSOKButton) || panelOK;
 
index 808e19d..d7b45e2 100644 (file)
@@ -5945,7 +5945,7 @@ Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
 selection box, if specified.  If MUSTMATCH is non-nil, the returned file
 or directory must exist.
 
-This function is only defined on MS Windows, and X Windows with the
+This function is only defined on NS, MS Windows, and X Windows with the
 Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.  */)
   (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
index 928e636..d497cff 100644 (file)
@@ -5344,7 +5344,7 @@ Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
 selection box, if specified.  If MUSTMATCH is non-nil, the returned file
 or directory must exist.
 
-This function is only defined on MS Windows, and X Windows with the
+This function is only defined on NS, MS Windows, and X Windows with the
 Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.  */)
   (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
@@ -5517,7 +5517,7 @@ Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
 selection box, if specified.  If MUSTMATCH is non-nil, the returned file
 or directory must exist.
 
-This function is only defined on MS Windows, and X Windows with the
+This function is only defined on NS, MS Windows, and X Windows with the
 Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.  */)
   (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)