emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/src/gtkutil.c [lexbind]


From: Miles Bader
Subject: [Emacs-diffs] Changes to emacs/src/gtkutil.c [lexbind]
Date: Thu, 04 Nov 2004 08:29:03 -0500

Index: emacs/src/gtkutil.c
diff -c emacs/src/gtkutil.c:1.26.2.10 emacs/src/gtkutil.c:1.26.2.11
*** emacs/src/gtkutil.c:1.26.2.10       Fri Oct 29 02:05:11 2004
--- emacs/src/gtkutil.c Thu Nov  4 13:12:30 2004
***************
*** 1118,1123 ****
--- 1118,1127 ----
  }
  
  
+ 
+ /***********************************************************************
+                       File dialog functions
+  ***********************************************************************/
  enum
  {
    XG_FILE_NOT_DONE,
***************
*** 1126,1131 ****
--- 1130,1198 ----
    XG_FILE_DESTROYED,
  };
  
+ #ifdef HAVE_GTK_FILE_BOTH
+ static int use_old_gtk_file_dialog;
+ #endif
+ 
+ 
+ #ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
+ /* Read a file name from the user using a file chooser dialog.
+    F is the current frame.
+    PROMPT is a prompt to show to the user.  May not be NULL.
+    DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
+    If MUSTMATCH_P is non-zero, the returned file name must be an existing
+    file.
+ 
+    Returns a file name or NULL if no file was selected.
+    The returned string must be freed by the caller.  */
+ 
+ static char *
+ xg_get_file_with_chooser (f, prompt, default_filename, mustmatch_p, 
only_dir_p)
+      FRAME_PTR f;
+      char *prompt;
+      char *default_filename;
+      int mustmatch_p, only_dir_p;
+ {
+   GtkWidget *filewin;
+   GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f));
+ 
+   char *fn = 0;
+   GtkFileChooserAction action = (mustmatch_p ?
+                                  GTK_FILE_CHOOSER_ACTION_OPEN :
+                                  GTK_FILE_CHOOSER_ACTION_SAVE);
+ 
+   if (only_dir_p)
+     action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+ 
+   filewin = gtk_file_chooser_dialog_new (prompt, gwin, action,
+                                          GTK_STOCK_CANCEL, 
GTK_RESPONSE_CANCEL,
+                                          (mustmatch_p || only_dir_p ?
+                                           GTK_STOCK_OPEN : GTK_STOCK_OK),
+                                          GTK_RESPONSE_OK,
+                                          NULL);
+ 
+   xg_set_screen (filewin, f);
+   gtk_widget_set_name (filewin, "emacs-filedialog");
+   gtk_window_set_transient_for (GTK_WINDOW (filewin), gwin);
+   gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
+ 
+ 
+   if (default_filename)
+     gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin),
+                                    default_filename);
+ 
+   gtk_widget_show (filewin);
+ 
+   if (gtk_dialog_run (GTK_DIALOG (filewin)) == GTK_RESPONSE_OK)
+     fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filewin));
+ 
+   gtk_widget_destroy (filewin);
+ 
+   return fn;
+ }
+ #endif /* HAVE_GTK_FILE_CHOOSER_DIALOG_NEW */
+ 
+ #ifdef HAVE_GTK_FILE_SELECTION_NEW
  /* Callback function invoked when the Ok button is pressed in
     a file dialog.
     W is the file dialog widget,
***************
*** 1167,1173 ****
    *(int*)arg = XG_FILE_DESTROYED;
  }
  
! /* Read a file name from the user using a file dialog.
     F is the current frame.
     PROMPT is a prompt to show to the user.  May not be NULL.
     DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
--- 1234,1240 ----
    *(int*)arg = XG_FILE_DESTROYED;
  }
  
! /* Read a file name from the user using a file selection dialog.
     F is the current frame.
     PROMPT is a prompt to show to the user.  May not be NULL.
     DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
***************
*** 1177,1188 ****
     Returns a file name or NULL if no file was selected.
     The returned string must be freed by the caller.  */
  
! char *
! xg_get_file_name (f, prompt, default_filename, mustmatch_p)
       FRAME_PTR f;
       char *prompt;
       char *default_filename;
!      int mustmatch_p;
  {
    GtkWidget *filewin;
    GtkFileSelection *filesel;
--- 1244,1256 ----
     Returns a file name or NULL if no file was selected.
     The returned string must be freed by the caller.  */
  
! static char *
! xg_get_file_with_selection (f, prompt, default_filename,
!                             mustmatch_p, only_dir_p)
       FRAME_PTR f;
       char *prompt;
       char *default_filename;
!      int mustmatch_p, only_dir_p;
  {
    GtkWidget *filewin;
    GtkFileSelection *filesel;
***************
*** 1193,1201 ****
    filesel = GTK_FILE_SELECTION (filewin);
  
    xg_set_screen (filewin, f);
- 
    gtk_widget_set_name (filewin, "emacs-filedialog");
- 
    gtk_window_set_transient_for (GTK_WINDOW (filewin),
                                  GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
    gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
--- 1261,1267 ----
***************
*** 1237,1242 ****
--- 1303,1351 ----
  
    return fn;
  }
+ #endif /* HAVE_GTK_FILE_SELECTION_NEW */
+ 
+ /* Read a file name from the user using a file dialog, either the old
+    file selection dialog, or the new file chooser dialog.  Which to use
+    depends on what the GTK version used has, and what the value of
+    gtk-use-old-file-dialog.
+    F is the current frame.
+    PROMPT is a prompt to show to the user.  May not be NULL.
+    DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
+    If MUSTMATCH_P is non-zero, the returned file name must be an existing
+    file.
+ 
+    Returns a file name or NULL if no file was selected.
+    The returned string must be freed by the caller.  */
+ 
+ char *
+ xg_get_file_name (f, prompt, default_filename, mustmatch_p, only_dir_p)
+      FRAME_PTR f;
+      char *prompt;
+      char *default_filename;
+      int mustmatch_p, only_dir_p;
+ {
+ #ifdef HAVE_GTK_FILE_BOTH
+   if (use_old_gtk_file_dialog)
+     return xg_get_file_with_selection (f, prompt, default_filename,
+                                        mustmatch_p, only_dir_p);
+   return xg_get_file_with_chooser (f, prompt, default_filename,
+                                    mustmatch_p, only_dir_p);
+ 
+ #else /* not HAVE_GTK_FILE_BOTH */
+ 
+ #ifdef HAVE_GTK_FILE_SELECTION_DIALOG_NEW
+   return xg_get_file_with_selection (f, prompt, default_filename,
+                                      mustmatch_p, only_dir_p);
+ #endif
+ #ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
+   return xg_get_file_with_chooser (f, prompt, default_filename,
+                                    mustmatch_p, only_dir_p);
+ #endif
+ 
+ #endif /* HAVE_GTK_FILE_BOTH */
+   return 0;
+ }
  
  
  /***********************************************************************
***************
*** 3429,3434 ****
--- 3538,3551 ----
                                      "gtk-key-theme-name",
                                      "Emacs",
                                      EMACS_CLASS);
+ 
+ #ifdef HAVE_GTK_FILE_BOTH
+   DEFVAR_BOOL ("use-old-gtk-file-dialog", &use_old_gtk_file_dialog,
+     doc: /* *Non-nil means that the old GTK file selection dialog is used.
+             If nil the new GTK file chooser is used instead.  To turn off
+             all file dialogs set the variable `use-file-dialog'.  */);
+   use_old_gtk_file_dialog = 0;
+ #endif
  }
  
  #endif /* USE_GTK */




reply via email to

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