From: Jan Djärv Date: Sun, 30 Sep 2012 13:43:47 +0000 (+0200) Subject: Support file name dialog on NS. X-Git-Tag: emacs-24.2.90~243^2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d7e642cc001a237dda8511f99b284e1a22865024;p=emacs.git Support file name dialog on NS. * 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. --- diff --git a/etc/ChangeLog b/etc/ChangeLog index 2c1e3758ea0..099d7ca044f 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog @@ -1,6 +1,7 @@ 2012-09-30 Jan Djärv * NEWS: The NS port supports fullscreen. + Mention that the file dialog is used on NS. 2012-09-17 Glenn Morris diff --git a/etc/NEWS b/etc/NEWS index e6f09d83f43..2791a25e051 100644 --- 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. * Editing Changes in Emacs 24.3 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 255b8924784..5d1a7eea095 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2012-09-30 Jan Djärv + + * term/ns-win.el (x-file-dialog): New function. + 2012-09-30 Juanma Barranquero * ido.el (ido-max-directory-size): Default to nil; the current diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index 06b67475c1d..c229ec14dd5 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -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) diff --git a/src/ChangeLog b/src/ChangeLog index 6aaa6bc88f8..119651e0651 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2012-09-30 Jan Djärv + * 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. diff --git a/src/fileio.c b/src/fileio.c index 9d8a0dc8b45..9ce9e7b8395 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -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 diff --git a/src/nsfns.m b/src/nsfns.m index c96ec99ed2e..1efadf0cb98 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -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; diff --git a/src/w32fns.c b/src/w32fns.c index 808e19d0b66..d7b45e263b3 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -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) diff --git a/src/xfns.c b/src/xfns.c index 928e6367743..d497cffe3df 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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)