aboutsummaryrefslogtreecommitdiffstats
path: root/src/gtkutil.c
diff options
context:
space:
mode:
authorJan Djärv2004-11-02 08:21:16 +0000
committerJan Djärv2004-11-02 08:21:16 +0000
commitf9d64bb358607b8bb771c5d61eccaea2859d3e5f (patch)
treec94b0355ad29207ff09e565c5b613901380ac14c /src/gtkutil.c
parent46bfc73bed2e2b6b3cdfff43f82c6705fb89355c (diff)
downloademacs-f9d64bb358607b8bb771c5d61eccaea2859d3e5f.tar.gz
emacs-f9d64bb358607b8bb771c5d61eccaea2859d3e5f.zip
* fileio.c (Fread_file_name): Pass Qt as fifth parameter to
Fx_file_dialog if only directories should be read. * lisp.h: Fx_file_dialog takes 5 parameters. * xfns.c (Fx_file_dialog): Both Motif and GTK version: Add parameter only_dir_p. In Motif version, don't put DEFAULT_FILENAME in filter part of the dialog, just text field part. Do not add DEFAULT_FILENAME to list of files if it isn't there. In GTK version, pass only_dir_p parameter to xg_get_file_name. * macfns.c (Fx_file_dialog): Add parameter only_dir_p. Check only_dir_p instead of comparing prompt to "Dired". When using a save dialog, add option kNavDontConfirmReplacement, change title to "Enter name", change text for save button to "Ok". * w32fns.c (Fx_file_dialog): Add parameter only_dir_p. Check only_dir_p instead of comparing prompt to "Dired". * gtkutil.c (xg_get_file_with_chooser) (xg_get_file_with_selection): New functions, only defined ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW and HAVE_GTK_FILE_SELECTION_NEW respectively. (xg_get_file_name): Add parameter only_dir_p. Call xg_get_file_with_chooser or xg_get_file_with_selection depending on HAVE_GTK_FILE* and the value of use_old_gtk_file_dialog. (xg_initialize): New DEFVAR_BOOL use_old_gtk_file_dialog. * gtkutil.h (xg_get_file_name): Add parameter only_dir_p.
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r--src/gtkutil.c129
1 files changed, 123 insertions, 6 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index dc091c1a09b..ac4f1af56f9 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1118,6 +1118,10 @@ create_dialog (wv, select_cb, deactivate_cb)
1118} 1118}
1119 1119
1120 1120
1121
1122/***********************************************************************
1123 File dialog functions
1124 ***********************************************************************/
1121enum 1125enum
1122{ 1126{
1123 XG_FILE_NOT_DONE, 1127 XG_FILE_NOT_DONE,
@@ -1126,6 +1130,69 @@ enum
1126 XG_FILE_DESTROYED, 1130 XG_FILE_DESTROYED,
1127}; 1131};
1128 1132
1133#ifdef HAVE_GTK_FILE_BOTH
1134static 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
1149static char *
1150xg_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_SAVE),
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
1129/* Callback function invoked when the Ok button is pressed in 1196/* Callback function invoked when the Ok button is pressed in
1130 a file dialog. 1197 a file dialog.
1131 W is the file dialog widget, 1198 W is the file dialog widget,
@@ -1167,7 +1234,7 @@ xg_file_sel_destroy (w, arg)
1167 *(int*)arg = XG_FILE_DESTROYED; 1234 *(int*)arg = XG_FILE_DESTROYED;
1168} 1235}
1169 1236
1170/* Read a file name from the user using a file dialog. 1237/* Read a file name from the user using a file selection dialog.
1171 F is the current frame. 1238 F is the current frame.
1172 PROMPT is a prompt to show to the user. May not be NULL. 1239 PROMPT is a prompt to show to the user. May not be NULL.
1173 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1240 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
@@ -1177,12 +1244,13 @@ xg_file_sel_destroy (w, arg)
1177 Returns a file name or NULL if no file was selected. 1244 Returns a file name or NULL if no file was selected.
1178 The returned string must be freed by the caller. */ 1245 The returned string must be freed by the caller. */
1179 1246
1180char * 1247static char *
1181xg_get_file_name (f, prompt, default_filename, mustmatch_p) 1248xg_get_file_with_selection (f, prompt, default_filename,
1249 mustmatch_p, only_dir_p)
1182 FRAME_PTR f; 1250 FRAME_PTR f;
1183 char *prompt; 1251 char *prompt;
1184 char *default_filename; 1252 char *default_filename;
1185 int mustmatch_p; 1253 int mustmatch_p, only_dir_p;
1186{ 1254{
1187 GtkWidget *filewin; 1255 GtkWidget *filewin;
1188 GtkFileSelection *filesel; 1256 GtkFileSelection *filesel;
@@ -1193,9 +1261,7 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p)
1193 filesel = GTK_FILE_SELECTION (filewin); 1261 filesel = GTK_FILE_SELECTION (filewin);
1194 1262
1195 xg_set_screen (filewin, f); 1263 xg_set_screen (filewin, f);
1196
1197 gtk_widget_set_name (filewin, "emacs-filedialog"); 1264 gtk_widget_set_name (filewin, "emacs-filedialog");
1198
1199 gtk_window_set_transient_for (GTK_WINDOW (filewin), 1265 gtk_window_set_transient_for (GTK_WINDOW (filewin),
1200 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 1266 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1201 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE); 1267 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
@@ -1237,6 +1303,49 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p)
1237 1303
1238 return fn; 1304 return fn;
1239} 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
1321char *
1322xg_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}
1240 1349
1241 1350
1242/*********************************************************************** 1351/***********************************************************************
@@ -3429,6 +3538,14 @@ xg_initialize ()
3429 "gtk-key-theme-name", 3538 "gtk-key-theme-name",
3430 "Emacs", 3539 "Emacs",
3431 EMACS_CLASS); 3540 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
3432} 3549}
3433 3550
3434#endif /* USE_GTK */ 3551#endif /* USE_GTK */