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

Diff of /emacs/src/gtkutil.c

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

revision 1.26.2.10 by miles, Fri Oct 29 02:05:11 2004 UTC revision 1.26.2.11 by miles, Thu Nov 4 13:12:30 2004 UTC
# Line 1118  create_dialog (wv, select_cb, deactivate Line 1118  create_dialog (wv, select_cb, deactivate
1118  }  }
1119    
1120    
1121    
1122    /***********************************************************************
1123                          File dialog functions
1124     ***********************************************************************/
1125  enum  enum
1126  {  {
1127    XG_FILE_NOT_DONE,    XG_FILE_NOT_DONE,
# Line 1126  enum Line 1130  enum
1130    XG_FILE_DESTROYED,    XG_FILE_DESTROYED,
1131  };  };
1132    
1133    #ifdef HAVE_GTK_FILE_BOTH
1134    static int use_old_gtk_file_dialog;
1135    #endif
1136    
1137    
1138    #ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
1139    /* Read a file name from the user using a file chooser dialog.
1140       F is the current frame.
1141       PROMPT is a prompt to show to the user.  May not be NULL.
1142       DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
1143       If MUSTMATCH_P is non-zero, the returned file name must be an existing
1144       file.
1145    
1146       Returns a file name or NULL if no file was selected.
1147       The returned string must be freed by the caller.  */
1148    
1149    static char *
1150    xg_get_file_with_chooser (f, prompt, default_filename, mustmatch_p, only_dir_p)
1151         FRAME_PTR f;
1152         char *prompt;
1153         char *default_filename;
1154         int mustmatch_p, only_dir_p;
1155    {
1156      GtkWidget *filewin;
1157      GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f));
1158    
1159      char *fn = 0;
1160      GtkFileChooserAction action = (mustmatch_p ?
1161                                     GTK_FILE_CHOOSER_ACTION_OPEN :
1162                                     GTK_FILE_CHOOSER_ACTION_SAVE);
1163    
1164      if (only_dir_p)
1165        action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
1166    
1167      filewin = gtk_file_chooser_dialog_new (prompt, gwin, action,
1168                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1169                                             (mustmatch_p || only_dir_p ?
1170                                              GTK_STOCK_OPEN : GTK_STOCK_OK),
1171                                             GTK_RESPONSE_OK,
1172                                             NULL);
1173    
1174      xg_set_screen (filewin, f);
1175      gtk_widget_set_name (filewin, "emacs-filedialog");
1176      gtk_window_set_transient_for (GTK_WINDOW (filewin), gwin);
1177      gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
1178    
1179    
1180      if (default_filename)
1181        gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin),
1182                                       default_filename);
1183    
1184      gtk_widget_show (filewin);
1185    
1186      if (gtk_dialog_run (GTK_DIALOG (filewin)) == GTK_RESPONSE_OK)
1187        fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filewin));
1188    
1189      gtk_widget_destroy (filewin);
1190    
1191      return fn;
1192    }
1193    #endif /* HAVE_GTK_FILE_CHOOSER_DIALOG_NEW */
1194    
1195    #ifdef HAVE_GTK_FILE_SELECTION_NEW
1196  /* Callback function invoked when the Ok button is pressed in  /* Callback function invoked when the Ok button is pressed in
1197     a file dialog.     a file dialog.
1198     W is the file dialog widget,     W is the file dialog widget,
# Line 1167  xg_file_sel_destroy (w, arg) Line 1234  xg_file_sel_destroy (w, arg)
1234    *(int*)arg = XG_FILE_DESTROYED;    *(int*)arg = XG_FILE_DESTROYED;
1235  }  }
1236    
1237  /* Read a file name from the user using a file dialog.  /* Read a file name from the user using a file selection dialog.
1238     F is the current frame.     F is the current frame.
1239     PROMPT is a prompt to show to the user.  May not be NULL.     PROMPT is a prompt to show to the user.  May not be NULL.
1240     DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.     DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
# Line 1177  xg_file_sel_destroy (w, arg) Line 1244  xg_file_sel_destroy (w, arg)
1244     Returns a file name or NULL if no file was selected.     Returns a file name or NULL if no file was selected.
1245     The returned string must be freed by the caller.  */     The returned string must be freed by the caller.  */
1246    
1247  char *  static char *
1248  xg_get_file_name (f, prompt, default_filename, mustmatch_p)  xg_get_file_with_selection (f, prompt, default_filename,
1249                                mustmatch_p, only_dir_p)
1250       FRAME_PTR f;       FRAME_PTR f;
1251       char *prompt;       char *prompt;
1252       char *default_filename;       char *default_filename;
1253       int mustmatch_p;       int mustmatch_p, only_dir_p;
1254  {  {
1255    GtkWidget *filewin;    GtkWidget *filewin;
1256    GtkFileSelection *filesel;    GtkFileSelection *filesel;
# Line 1193  xg_get_file_name (f, prompt, default_fil Line 1261  xg_get_file_name (f, prompt, default_fil
1261    filesel = GTK_FILE_SELECTION (filewin);    filesel = GTK_FILE_SELECTION (filewin);
1262    
1263    xg_set_screen (filewin, f);    xg_set_screen (filewin, f);
   
1264    gtk_widget_set_name (filewin, "emacs-filedialog");    gtk_widget_set_name (filewin, "emacs-filedialog");
   
1265    gtk_window_set_transient_for (GTK_WINDOW (filewin),    gtk_window_set_transient_for (GTK_WINDOW (filewin),
1266                                  GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));                                  GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1267    gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);    gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
# Line 1237  xg_get_file_name (f, prompt, default_fil Line 1303  xg_get_file_name (f, prompt, default_fil
1303    
1304    return fn;    return fn;
1305  }  }
1306    #endif /* HAVE_GTK_FILE_SELECTION_NEW */
1307    
1308    /* Read a file name from the user using a file dialog, either the old
1309       file selection dialog, or the new file chooser dialog.  Which to use
1310       depends on what the GTK version used has, and what the value of
1311       gtk-use-old-file-dialog.
1312       F is the current frame.
1313       PROMPT is a prompt to show to the user.  May not be NULL.
1314       DEFAULT_FILENAME is a default selection to be displayed.  May be NULL.
1315       If MUSTMATCH_P is non-zero, the returned file name must be an existing
1316       file.
1317    
1318       Returns a file name or NULL if no file was selected.
1319       The returned string must be freed by the caller.  */
1320    
1321    char *
1322    xg_get_file_name (f, prompt, default_filename, mustmatch_p, only_dir_p)
1323         FRAME_PTR f;
1324         char *prompt;
1325         char *default_filename;
1326         int mustmatch_p, only_dir_p;
1327    {
1328    #ifdef HAVE_GTK_FILE_BOTH
1329      if (use_old_gtk_file_dialog)
1330        return xg_get_file_with_selection (f, prompt, default_filename,
1331                                           mustmatch_p, only_dir_p);
1332      return xg_get_file_with_chooser (f, prompt, default_filename,
1333                                       mustmatch_p, only_dir_p);
1334    
1335    #else /* not HAVE_GTK_FILE_BOTH */
1336    
1337    #ifdef HAVE_GTK_FILE_SELECTION_DIALOG_NEW
1338      return xg_get_file_with_selection (f, prompt, default_filename,
1339                                         mustmatch_p, only_dir_p);
1340    #endif
1341    #ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
1342      return xg_get_file_with_chooser (f, prompt, default_filename,
1343                                       mustmatch_p, only_dir_p);
1344    #endif
1345    
1346    #endif /* HAVE_GTK_FILE_BOTH */
1347      return 0;
1348    }
1349    
1350    
1351  /***********************************************************************  /***********************************************************************
# Line 3429  xg_initialize () Line 3538  xg_initialize ()
3538                                      "gtk-key-theme-name",                                      "gtk-key-theme-name",
3539                                      "Emacs",                                      "Emacs",
3540                                      EMACS_CLASS);                                      EMACS_CLASS);
3541    
3542    #ifdef HAVE_GTK_FILE_BOTH
3543      DEFVAR_BOOL ("use-old-gtk-file-dialog", &use_old_gtk_file_dialog,
3544        doc: /* *Non-nil means that the old GTK file selection dialog is used.
3545                If nil the new GTK file chooser is used instead.  To turn off
3546                all file dialogs set the variable `use-file-dialog'.  */);
3547      use_old_gtk_file_dialog = 0;
3548    #endif
3549  }  }
3550    
3551  #endif /* USE_GTK */  #endif /* USE_GTK */

Legend:
Removed from v.1.26.2.10  
changed lines
  Added in v.1.26.2.11

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