/[emacs]/emacs/src/w32fns.c
ViewVC logotype

Diff of /emacs/src/w32fns.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.173 by jasonr, Wed May 22 19:35:48 2002 UTC revision 1.174 by jasonr, Sat Jun 22 19:49:44 2002 UTC
# Line 52  Boston, MA 02111-1307, USA.  */ Line 52  Boston, MA 02111-1307, USA.  */
52  #include <shellapi.h>  #include <shellapi.h>
53  #include <ctype.h>  #include <ctype.h>
54    
55    #include <dlgs.h>
56    #define FILE_NAME_TEXT_FIELD edt1
57    
58  extern void free_frame_menubar ();  extern void free_frame_menubar ();
59  extern void x_compute_fringe_widths P_ ((struct frame *, int));  extern void x_compute_fringe_widths P_ ((struct frame *, int));
60  extern double atof ();  extern double atof ();
# Line 14244  Value is t if tooltip was open, nil othe Line 14247  Value is t if tooltip was open, nil othe
14247  /***********************************************************************  /***********************************************************************
14248                          File selection dialog                          File selection dialog
14249   ***********************************************************************/   ***********************************************************************/
   
14250  extern Lisp_Object Qfile_name_history;  extern Lisp_Object Qfile_name_history;
14251    
14252    /* Callback for altering the behaviour of the Open File dialog.
14253       Makes the Filename text field contain "Current Directory" and be
14254       read-only when "Directories" is selected in the filter.  This
14255       allows us to work around the fact that the standard Open File
14256       dialog does not support directories.  */
14257    UINT CALLBACK
14258    file_dialog_callback (hwnd, msg, wParam, lParam)
14259         HWND hwnd;
14260         UINT msg;
14261         WPARAM wParam;
14262         LPARAM lParam;
14263    {
14264      if (msg == WM_NOTIFY)
14265        {
14266          OFNOTIFY * notify = (OFNOTIFY *)lParam;
14267          /* Detect when the Filter dropdown is changed.  */
14268          if (notify->hdr.code == CDN_TYPECHANGE)
14269            {
14270              HWND dialog = GetParent (hwnd);
14271              HWND edit_control = GetDlgItem (dialog, FILE_NAME_TEXT_FIELD);
14272    
14273              /* Directories is in index 2.  */
14274              if (notify->lpOFN->nFilterIndex == 2)
14275                {
14276                  CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD,
14277                                                   "Current Directory");
14278                  EnableWindow (edit_control, FALSE);
14279                }
14280              else
14281                {
14282                  CommDlg_OpenSave_SetControlText (dialog, FILE_NAME_TEXT_FIELD,
14283                                                   "");
14284                  EnableWindow (edit_control, TRUE);
14285                }
14286            }
14287        }
14288      return 0;
14289    }
14290    
14291  DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0,  DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0,
14292         doc: /* Read file name, prompting with PROMPT in directory DIR.         doc: /* Read file name, prompting with PROMPT in directory DIR.
14293  Use a file selection dialog.  Use a file selection dialog.
# Line 14261  specified.  Ensure that file exists if M Line 14302  specified.  Ensure that file exists if M
14302    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
14303    char filename[MAX_PATH + 1];    char filename[MAX_PATH + 1];
14304    char init_dir[MAX_PATH + 1];    char init_dir[MAX_PATH + 1];
   int use_dialog_p = 1;  
14305    
14306    GCPRO5 (prompt, dir, default_filename, mustmatch, file);    GCPRO5 (prompt, dir, default_filename, mustmatch, file);
14307    CHECK_STRING (prompt);    CHECK_STRING (prompt);
# Line 14287  specified.  Ensure that file exists if M Line 14327  specified.  Ensure that file exists if M
14327        else        else
14328          {          {
14329            file_name_only++;            file_name_only++;
   
           /* If default_file_name is a directory, don't use the open  
              file dialog, as it does not support selecting  
              directories. */  
           if (!(*file_name_only))  
             use_dialog_p = 0;  
14330          }          }
14331    
14332        strncpy (filename, file_name_only, MAX_PATH);        strncpy (filename, file_name_only, MAX_PATH);
# Line 14301  specified.  Ensure that file exists if M Line 14335  specified.  Ensure that file exists if M
14335    else    else
14336      filename[0] = '\0';      filename[0] = '\0';
14337    
14338    if (use_dialog_p)    {
14339      {      OPENFILENAME file_details;
       OPENFILENAME file_details;  
14340    
14341        /* Prevent redisplay.  */      /* Prevent redisplay.  */
14342        specbind (Qinhibit_redisplay, Qt);      specbind (Qinhibit_redisplay, Qt);
14343        BLOCK_INPUT;      BLOCK_INPUT;
14344    
14345        bzero (&file_details, sizeof (file_details));      bzero (&file_details, sizeof (file_details));
14346        file_details.lStructSize = sizeof (file_details);      file_details.lStructSize = sizeof (file_details);
14347        file_details.hwndOwner = FRAME_W32_WINDOW (f);      file_details.hwndOwner = FRAME_W32_WINDOW (f);
14348        /* Undocumented Bug in Common File Dialog:      /* Undocumented Bug in Common File Dialog:
14349           If a filter is not specified, shell links are not resolved.  */         If a filter is not specified, shell links are not resolved.  */
14350        file_details.lpstrFilter = "ALL Files (*.*)\0*.*\0\0";      file_details.lpstrFilter = "All Files (*.*)\0*.*\0Directories\0*|*\0\0";
14351        file_details.lpstrFile = filename;      file_details.lpstrFile = filename;
14352        file_details.nMaxFile = sizeof (filename);      file_details.nMaxFile = sizeof (filename);
14353        file_details.lpstrInitialDir = init_dir;      file_details.lpstrInitialDir = init_dir;
14354        file_details.lpstrTitle = XSTRING (prompt)->data;      file_details.lpstrTitle = XSTRING (prompt)->data;
14355        file_details.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR;      file_details.Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR
14356                              | OFN_EXPLORER | OFN_ENABLEHOOK);
14357        if (!NILP (mustmatch))
14358          file_details.Flags |= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
14359    
14360        if (!NILP (mustmatch))      file_details.lpfnHook = (LPOFNHOOKPROC) file_dialog_callback;
         file_details.Flags |= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;  
14361    
14362        if (GetOpenFileName (&file_details))      if (GetOpenFileName (&file_details))
14363          {        {
14364            dostounix_filename (filename);          dostounix_filename (filename);
14365            file = DECODE_FILE(build_string (filename));          if (file_details.nFilterIndex == 2)
14366          }            {
14367        else              /* "Folder Only" selected - strip dummy file name.  */
14368          file = Qnil;              char * last = strrchr (filename, '/');
14369                *last = '\0';
14370              }
14371    
14372        UNBLOCK_INPUT;          file = DECODE_FILE(build_string (filename));
14373        file = unbind_to (count, file);        }
14374      }      /* User cancelled the dialog without making a selection.  */
14375    /* Open File dialog will not allow folders to be selected, so resort      else if (!CommDlgExtendedError ())
14376       to minibuffer completing reads for directories. */        file = Qnil;
14377    else      /* An error occurred, fallback on reading from the mini-buffer.  */
14378      file = Fcompleting_read (prompt, intern ("read-file-name-internal"),      else
14379                               dir, mustmatch, dir, Qfile_name_history,        file = Fcompleting_read (prompt, intern ("read-file-name-internal"),
14380                               default_filename, Qnil);                                 dir, mustmatch, dir, Qfile_name_history,
14381                                   default_filename, Qnil);
14382    
14383        UNBLOCK_INPUT;
14384        file = unbind_to (count, file);
14385      }
14386    
14387    UNGCPRO;    UNGCPRO;
14388    

Legend:
Removed from v.1.173  
changed lines
  Added in v.1.174

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26