aboutsummaryrefslogtreecommitdiffstats
path: root/src/gtkutil.c
diff options
context:
space:
mode:
authorKaroly Lorentey2004-11-06 17:52:02 +0000
committerKaroly Lorentey2004-11-06 17:52:02 +0000
commit65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb (patch)
tree853cf391ca1abda4f4ccd6fe8e7bb43f7c86ee08 /src/gtkutil.c
parente0bc17abe6979d607e8de4684dddb96e53c60065 (diff)
parent392cf16dd0ee9358f8af0cd0d8048b822456bbeb (diff)
downloademacs-65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb.tar.gz
emacs-65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb.zip
Merged in changes from CVS trunk.
Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-653 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-654 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-655 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-656 Update from CVS: lisp/man.el (Man-xref-normal-file): Fix help-echo. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-657 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-658 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-659 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-660 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-661 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-662 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-663 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-664 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-665 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-666 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-667 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-668 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-669 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-670 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-671 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-64 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-65 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-66 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-67 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-68 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-264
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r--src/gtkutil.c137
1 files changed, 131 insertions, 6 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index dc091c1a09b..f5f05709e48 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,85 @@ enum
1126 XG_FILE_DESTROYED, 1130 XG_FILE_DESTROYED,
1127}; 1131};
1128 1132
1133#ifdef HAVE_GTK_FILE_BOTH
1134int 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_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 {
1182 Lisp_Object file;
1183 struct gcpro gcpro1;
1184 GCPRO1 (file);
1185
1186 /* File chooser does not understand ~/... in the file name. It must be
1187 an absolute name starting with /. */
1188 if (default_filename[0] != '/')
1189 {
1190 file = Fexpand_file_name (build_string (default_filename), Qnil);
1191 default_filename = SDATA (file);
1192 }
1193
1194 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewin),
1195 default_filename);
1196
1197 UNGCPRO;
1198 }
1199
1200 gtk_widget_show (filewin);
1201
1202 if (gtk_dialog_run (GTK_DIALOG (filewin)) == GTK_RESPONSE_OK)
1203 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filewin));
1204
1205 gtk_widget_destroy (filewin);
1206
1207 return fn;
1208}
1209#endif /* HAVE_GTK_FILE_CHOOSER_DIALOG_NEW */
1210
1211#ifdef HAVE_GTK_FILE_SELECTION_NEW
1129/* Callback function invoked when the Ok button is pressed in 1212/* Callback function invoked when the Ok button is pressed in
1130 a file dialog. 1213 a file dialog.
1131 W is the file dialog widget, 1214 W is the file dialog widget,
@@ -1167,7 +1250,7 @@ xg_file_sel_destroy (w, arg)
1167 *(int*)arg = XG_FILE_DESTROYED; 1250 *(int*)arg = XG_FILE_DESTROYED;
1168} 1251}
1169 1252
1170/* Read a file name from the user using a file dialog. 1253/* Read a file name from the user using a file selection dialog.
1171 F is the current frame. 1254 F is the current frame.
1172 PROMPT is a prompt to show to the user. May not be NULL. 1255 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. 1256 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
@@ -1177,12 +1260,13 @@ xg_file_sel_destroy (w, arg)
1177 Returns a file name or NULL if no file was selected. 1260 Returns a file name or NULL if no file was selected.
1178 The returned string must be freed by the caller. */ 1261 The returned string must be freed by the caller. */
1179 1262
1180char * 1263static char *
1181xg_get_file_name (f, prompt, default_filename, mustmatch_p) 1264xg_get_file_with_selection (f, prompt, default_filename,
1265 mustmatch_p, only_dir_p)
1182 FRAME_PTR f; 1266 FRAME_PTR f;
1183 char *prompt; 1267 char *prompt;
1184 char *default_filename; 1268 char *default_filename;
1185 int mustmatch_p; 1269 int mustmatch_p, only_dir_p;
1186{ 1270{
1187 GtkWidget *filewin; 1271 GtkWidget *filewin;
1188 GtkFileSelection *filesel; 1272 GtkFileSelection *filesel;
@@ -1193,9 +1277,7 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p)
1193 filesel = GTK_FILE_SELECTION (filewin); 1277 filesel = GTK_FILE_SELECTION (filewin);
1194 1278
1195 xg_set_screen (filewin, f); 1279 xg_set_screen (filewin, f);
1196
1197 gtk_widget_set_name (filewin, "emacs-filedialog"); 1280 gtk_widget_set_name (filewin, "emacs-filedialog");
1198
1199 gtk_window_set_transient_for (GTK_WINDOW (filewin), 1281 gtk_window_set_transient_for (GTK_WINDOW (filewin),
1200 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 1282 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1201 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE); 1283 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
@@ -1237,6 +1319,49 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p)
1237 1319
1238 return fn; 1320 return fn;
1239} 1321}
1322#endif /* HAVE_GTK_FILE_SELECTION_NEW */
1323
1324/* Read a file name from the user using a file dialog, either the old
1325 file selection dialog, or the new file chooser dialog. Which to use
1326 depends on what the GTK version used has, and what the value of
1327 gtk-use-old-file-dialog.
1328 F is the current frame.
1329 PROMPT is a prompt to show to the user. May not be NULL.
1330 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1331 If MUSTMATCH_P is non-zero, the returned file name must be an existing
1332 file.
1333
1334 Returns a file name or NULL if no file was selected.
1335 The returned string must be freed by the caller. */
1336
1337char *
1338xg_get_file_name (f, prompt, default_filename, mustmatch_p, only_dir_p)
1339 FRAME_PTR f;
1340 char *prompt;
1341 char *default_filename;
1342 int mustmatch_p, only_dir_p;
1343{
1344#ifdef HAVE_GTK_FILE_BOTH
1345 if (use_old_gtk_file_dialog)
1346 return xg_get_file_with_selection (f, prompt, default_filename,
1347 mustmatch_p, only_dir_p);
1348 return xg_get_file_with_chooser (f, prompt, default_filename,
1349 mustmatch_p, only_dir_p);
1350
1351#else /* not HAVE_GTK_FILE_BOTH */
1352
1353#ifdef HAVE_GTK_FILE_SELECTION_DIALOG_NEW
1354 return xg_get_file_with_selection (f, prompt, default_filename,
1355 mustmatch_p, only_dir_p);
1356#endif
1357#ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
1358 return xg_get_file_with_chooser (f, prompt, default_filename,
1359 mustmatch_p, only_dir_p);
1360#endif
1361
1362#endif /* HAVE_GTK_FILE_BOTH */
1363 return 0;
1364}
1240 1365
1241 1366
1242/*********************************************************************** 1367/***********************************************************************