aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog31
-rw-r--r--src/fileio.c3
-rw-r--r--src/gtkutil.c129
-rw-r--r--src/gtkutil.h3
-rw-r--r--src/lisp.h2
-rw-r--r--src/macfns.c38
-rw-r--r--src/w32fns.c18
-rw-r--r--src/xfns.c83
8 files changed, 228 insertions, 79 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 18704954db0..68794ed6cef 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,36 @@
12004-11-02 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 12004-11-02 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 2
3 * fileio.c (Fread_file_name): Pass Qt as fifth parameter to
4 Fx_file_dialog if only directories should be read.
5
6 * lisp.h: Fx_file_dialog takes 5 parameters.
7
8 * xfns.c (Fx_file_dialog): Both Motif and GTK version: Add
9 parameter only_dir_p.
10 In Motif version, don't put DEFAULT_FILENAME in filter part of the
11 dialog, just text field part. Do not add DEFAULT_FILENAME
12 to list of files if it isn't there.
13 In GTK version, pass only_dir_p parameter to xg_get_file_name.
14
15 * macfns.c (Fx_file_dialog): Add parameter only_dir_p. Check
16 only_dir_p instead of comparing prompt to "Dired". When using
17 a save dialog, add option kNavDontConfirmReplacement, change title
18 to "Enter name", change text for save button to "Ok".
19
20 * w32fns.c (Fx_file_dialog): Add parameter only_dir_p. Check
21 only_dir_p instead of comparing prompt to "Dired".
22
23 * gtkutil.c (xg_get_file_with_chooser)
24 (xg_get_file_with_selection): New functions, only defined ifdef
25 HAVE_GTK_FILE_CHOOSER_DIALOG_NEW and HAVE_GTK_FILE_SELECTION_NEW
26 respectively.
27 (xg_get_file_name): Add parameter only_dir_p.
28 Call xg_get_file_with_chooser or xg_get_file_with_selection
29 depending on HAVE_GTK_FILE* and the value of use_old_gtk_file_dialog.
30 (xg_initialize): New DEFVAR_BOOL use_old_gtk_file_dialog.
31
32 * gtkutil.h (xg_get_file_name): Add parameter only_dir_p.
33
3 * config.in: Rebuild (added HAVE_GTK_FILE_*). 34 * config.in: Rebuild (added HAVE_GTK_FILE_*).
4 35
52004-11-01 Kim F. Storm <storm@cua.dk> 362004-11-01 Kim F. Storm <storm@cua.dk>
diff --git a/src/fileio.c b/src/fileio.c
index c10969378bc..68ca97cf57f 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6321,7 +6321,8 @@ and `read-file-name-function'. */)
6321 } 6321 }
6322 if (!NILP(default_filename)) 6322 if (!NILP(default_filename))
6323 default_filename = Fexpand_file_name (default_filename, dir); 6323 default_filename = Fexpand_file_name (default_filename, dir);
6324 val = Fx_file_dialog (prompt, dir, default_filename, mustmatch); 6324 val = Fx_file_dialog (prompt, dir, default_filename, mustmatch,
6325 EQ (predicate, Qfile_directory_p) ? Qt : Qnil);
6325 add_to_history = 1; 6326 add_to_history = 1;
6326 } 6327 }
6327 else 6328 else
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 */
diff --git a/src/gtkutil.h b/src/gtkutil.h
index c0055f361cc..b2e2c5f2fff 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -132,7 +132,8 @@ extern void free_widget_value P_ ((widget_value *));
132extern char *xg_get_file_name P_ ((FRAME_PTR f, 132extern char *xg_get_file_name P_ ((FRAME_PTR f,
133 char *prompt, 133 char *prompt,
134 char *default_filename, 134 char *default_filename,
135 int mustmatch_p)); 135 int mustmatch_p,
136 int only_dir_p));
136 137
137extern GtkWidget *xg_create_widget P_ ((char *type, 138extern GtkWidget *xg_create_widget P_ ((char *type,
138 char *name, 139 char *name,
diff --git a/src/lisp.h b/src/lisp.h
index 49d6fa9219d..daf23a05f54 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3121,7 +3121,7 @@ extern void syms_of_xfns P_ ((void));
3121#ifdef HAVE_WINDOW_SYSTEM 3121#ifdef HAVE_WINDOW_SYSTEM
3122/* Defined in xfns.c, w32fns.c, or macfns.c */ 3122/* Defined in xfns.c, w32fns.c, or macfns.c */
3123EXFUN (Fxw_display_color_p, 1); 3123EXFUN (Fxw_display_color_p, 1);
3124EXFUN (Fx_file_dialog, 4); 3124EXFUN (Fx_file_dialog, 5);
3125#endif /* HAVE_WINDOW_SYSTEM */ 3125#endif /* HAVE_WINDOW_SYSTEM */
3126 3126
3127/* Defined in xsmfns.c */ 3127/* Defined in xsmfns.c */
diff --git a/src/macfns.c b/src/macfns.c
index 88f975a65c8..401c7011fea 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -4216,22 +4216,23 @@ Value is t if tooltip was open, nil otherwise. */)
4216 4216
4217extern Lisp_Object Qfile_name_history; 4217extern Lisp_Object Qfile_name_history;
4218 4218
4219DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, 4219DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
4220 doc: /* Read file name, prompting with PROMPT in directory DIR. 4220 doc: /* Read file name, prompting with PROMPT in directory DIR.
4221Use a file selection dialog. 4221Use a file selection dialog.
4222Select DEFAULT-FILENAME in the dialog's file selection box, if 4222Select DEFAULT-FILENAME in the dialog's file selection box, if
4223specified. Ensure that file exists if MUSTMATCH is non-nil. */) 4223specified. Ensure that file exists if MUSTMATCH is non-nil.
4224 (prompt, dir, default_filename, mustmatch) 4224If ONLY-DIR-P is non-nil, the user can only select directories. */)
4225 Lisp_Object prompt, dir, default_filename, mustmatch; 4225 (prompt, dir, default_filename, mustmatch, only_dir_p)
4226 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
4226{ 4227{
4227 struct frame *f = SELECTED_FRAME (); 4228 struct frame *f = SELECTED_FRAME ();
4228 Lisp_Object file = Qnil; 4229 Lisp_Object file = Qnil;
4229 int count = SPECPDL_INDEX (); 4230 int count = SPECPDL_INDEX ();
4230 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 4231 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
4231 char filename[1001]; 4232 char filename[1001];
4232 int default_filter_index = 1; /* 1: All Files, 2: Directories only */ 4233 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
4233 4234
4234 GCPRO5 (prompt, dir, default_filename, mustmatch, file); 4235 GCPRO6 (prompt, dir, default_filename, mustmatch, file, only_dir_p);
4235 CHECK_STRING (prompt); 4236 CHECK_STRING (prompt);
4236 CHECK_STRING (dir); 4237 CHECK_STRING (dir);
4237 4238
@@ -4245,7 +4246,8 @@ specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4245 NavDialogRef dialogRef; 4246 NavDialogRef dialogRef;
4246 NavTypeListHandle fileTypes = NULL; 4247 NavTypeListHandle fileTypes = NULL;
4247 NavUserAction userAction; 4248 NavUserAction userAction;
4248 CFStringRef message=NULL, client=NULL, saveName = NULL; 4249 CFStringRef message=NULL, client=NULL, saveName = NULL, ok = NULL;
4250 CFStringRef title = NULL;
4249 4251
4250 BLOCK_INPUT; 4252 BLOCK_INPUT;
4251 /* No need for a callback function because we are modal */ 4253 /* No need for a callback function because we are modal */
@@ -4268,13 +4270,19 @@ specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4268 options.clientName = client; 4270 options.clientName = client;
4269 */ 4271 */
4270 4272
4271 /* Do Dired hack copied from w32fns.c */ 4273 if (!NILP (only_dir_p))
4272 if (!NILP(prompt) && strncmp (SDATA(prompt), "Dired", 5) == 0)
4273 status = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL, 4274 status = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL,
4274 &dialogRef); 4275 &dialogRef);
4275 else if (NILP (mustmatch)) 4276 else if (NILP (mustmatch))
4276 { 4277 {
4277 /* This is a save dialog */ 4278 /* This is a save dialog */
4279 ok = CFStringCreateWithCString (NULL, "Ok", kCFStringEncodingUTF8);
4280 title = CFStringCreateWithCString (NULL, "Enter name",
4281 kCFStringEncodingUTF8);
4282 options.optionFlags |= kNavDontConfirmReplacement;
4283 options.actionButtonLabel = ok;
4284 options.windowTitle = title;
4285
4278 if (!NILP(default_filename)) 4286 if (!NILP(default_filename))
4279 { 4287 {
4280 saveName = CFStringCreateWithCString(NULL, SDATA(default_filename), 4288 saveName = CFStringCreateWithCString(NULL, SDATA(default_filename),
@@ -4282,20 +4290,10 @@ specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4282 options.saveFileName = saveName; 4290 options.saveFileName = saveName;
4283 options.optionFlags |= kNavSelectDefaultLocation; 4291 options.optionFlags |= kNavSelectDefaultLocation;
4284 } 4292 }
4285 /* MAC_TODO: Find a better way to determine if this is a save
4286 or load dialog than comparing dir with default_filename */
4287 if (EQ(dir, default_filename))
4288 {
4289 status = NavCreateChooseFileDialog(&options, fileTypes,
4290 NULL, NULL, NULL, NULL,
4291 &dialogRef);
4292 }
4293 else {
4294 status = NavCreatePutFileDialog(&options, 4293 status = NavCreatePutFileDialog(&options,
4295 'TEXT', kNavGenericSignature, 4294 'TEXT', kNavGenericSignature,
4296 NULL, NULL, &dialogRef); 4295 NULL, NULL, &dialogRef);
4297 } 4296 }
4298 }
4299 else 4297 else
4300 { 4298 {
4301 /* This is an open dialog*/ 4299 /* This is an open dialog*/
@@ -4324,6 +4322,8 @@ specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4324 if (saveName) CFRelease(saveName); 4322 if (saveName) CFRelease(saveName);
4325 if (client) CFRelease(client); 4323 if (client) CFRelease(client);
4326 if (message) CFRelease(message); 4324 if (message) CFRelease(message);
4325 if (ok) CFRelease(ok);
4326 if (title) CFRelease(title);
4327 4327
4328 if (status == noErr) { 4328 if (status == noErr) {
4329 userAction = NavDialogGetUserAction(dialogRef); 4329 userAction = NavDialogGetUserAction(dialogRef);
diff --git a/src/w32fns.c b/src/w32fns.c
index 38faa7c3199..41bd6a9b9f9 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -7742,23 +7742,24 @@ file_dialog_callback (hwnd, msg, wParam, lParam)
7742 return 0; 7742 return 0;
7743} 7743}
7744 7744
7745DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, 7745DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
7746 doc: /* Read file name, prompting with PROMPT in directory DIR. 7746 doc: /* Read file name, prompting with PROMPT in directory DIR.
7747Use a file selection dialog. 7747Use a file selection dialog.
7748Select DEFAULT-FILENAME in the dialog's file selection box, if 7748Select DEFAULT-FILENAME in the dialog's file selection box, if
7749specified. Ensure that file exists if MUSTMATCH is non-nil. */) 7749specified. Ensure that file exists if MUSTMATCH is non-nil.
7750 (prompt, dir, default_filename, mustmatch) 7750If ONLY-DIR-P is non-nil, the user can only select directories. */)
7751 Lisp_Object prompt, dir, default_filename, mustmatch; 7751 (prompt, dir, default_filename, mustmatch, only_dir_p)
7752 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
7752{ 7753{
7753 struct frame *f = SELECTED_FRAME (); 7754 struct frame *f = SELECTED_FRAME ();
7754 Lisp_Object file = Qnil; 7755 Lisp_Object file = Qnil;
7755 int count = SPECPDL_INDEX (); 7756 int count = SPECPDL_INDEX ();
7756 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 7757 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
7757 char filename[MAX_PATH + 1]; 7758 char filename[MAX_PATH + 1];
7758 char init_dir[MAX_PATH + 1]; 7759 char init_dir[MAX_PATH + 1];
7759 int default_filter_index = 1; /* 1: All Files, 2: Directories only */ 7760 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
7760 7761
7761 GCPRO5 (prompt, dir, default_filename, mustmatch, file); 7762 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
7762 CHECK_STRING (prompt); 7763 CHECK_STRING (prompt);
7763 CHECK_STRING (dir); 7764 CHECK_STRING (dir);
7764 7765
@@ -7806,10 +7807,7 @@ specified. Ensure that file exists if MUSTMATCH is non-nil. */)
7806 file_details.lpstrInitialDir = init_dir; 7807 file_details.lpstrInitialDir = init_dir;
7807 file_details.lpstrTitle = SDATA (prompt); 7808 file_details.lpstrTitle = SDATA (prompt);
7808 7809
7809 /* If prompt starts with Dired, default to directories only. */ 7810 if (! NILP (only_dir_p))
7810 /* A bit hacky, but there doesn't seem to be a better way to
7811 DTRT for dired. */
7812 if (strncmp (file_details.lpstrTitle, "Dired", 5) == 0)
7813 default_filter_index = 2; 7811 default_filter_index = 2;
7814 7812
7815 file_details.nFilterIndex = default_filter_index; 7813 file_details.nFilterIndex = default_filter_index;
diff --git a/src/xfns.c b/src/xfns.c
index 01d528e2790..2cf8a59ca52 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -5106,27 +5106,26 @@ file_dialog_unmap_cb (widget, client_data, call_data)
5106} 5106}
5107 5107
5108 5108
5109DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, 5109DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5110 doc: /* Read file name, prompting with PROMPT in directory DIR. 5110 doc: /* Read file name, prompting with PROMPT in directory DIR.
5111Use a file selection dialog. 5111Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5112Select DEFAULT-FILENAME in the dialog's file selection box, if 5112selection box, if specified. If MUSTMATCH is non-nil, the returned file
5113specified. Don't let the user enter a file name in the file 5113or directory must exist. ONLY-DIR-P is ignored." */)
5114selection dialog's entry field, if MUSTMATCH is non-nil. */) 5114 (prompt, dir, default_filename, mustmatch, only_dir_p)
5115 (prompt, dir, default_filename, mustmatch) 5115 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
5116 Lisp_Object prompt, dir, default_filename, mustmatch;
5117{ 5116{
5118 int result; 5117 int result;
5119 struct frame *f = SELECTED_FRAME (); 5118 struct frame *f = SELECTED_FRAME ();
5120 Lisp_Object file = Qnil; 5119 Lisp_Object file = Qnil;
5121 Widget dialog, text, list, help; 5120 Widget dialog, text, help;
5122 Arg al[10]; 5121 Arg al[10];
5123 int ac = 0; 5122 int ac = 0;
5124 extern XtAppContext Xt_app_con; 5123 extern XtAppContext Xt_app_con;
5125 XmString dir_xmstring, pattern_xmstring; 5124 XmString dir_xmstring, pattern_xmstring;
5126 int count = SPECPDL_INDEX (); 5125 int count = SPECPDL_INDEX ();
5127 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 5126 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5128 5127
5129 GCPRO5 (prompt, dir, default_filename, mustmatch, file); 5128 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5130 CHECK_STRING (prompt); 5129 CHECK_STRING (prompt);
5131 CHECK_STRING (dir); 5130 CHECK_STRING (dir);
5132 5131
@@ -5159,9 +5158,9 @@ selection dialog's entry field, if MUSTMATCH is non-nil. */)
5159 XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, 5158 XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb,
5160 (XtPointer) &result); 5159 (XtPointer) &result);
5161 5160
5162 /* Disable the help button since we can't display help. */ 5161 /* Remove the help button since we can't display help. */
5163 help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); 5162 help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON);
5164 XtSetSensitive (help, False); 5163 XtUnmanageChild (help);
5165 5164
5166 /* Mark OK button as default. */ 5165 /* Mark OK button as default. */
5167 XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), 5166 XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON),
@@ -5183,30 +5182,30 @@ selection dialog's entry field, if MUSTMATCH is non-nil. */)
5183 /* Manage the dialog, so that list boxes get filled. */ 5182 /* Manage the dialog, so that list boxes get filled. */
5184 XtManageChild (dialog); 5183 XtManageChild (dialog);
5185 5184
5186 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5187 must include the path for this to work. */
5188 list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST);
5189 if (STRINGP (default_filename)) 5185 if (STRINGP (default_filename))
5190 { 5186 {
5191 XmString default_xmstring; 5187 XmString default_xmstring;
5192 int item_pos; 5188 Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
5189 Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST);
5193 5190
5194 default_xmstring 5191 XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext);
5195 = XmStringCreateLocalized (SDATA (default_filename)); 5192 XmTextFieldReplace (wtext, 0, last_pos,
5193 (SDATA (Ffile_name_nondirectory (default_filename))));
5196 5194
5197 if (!XmListItemExists (list, default_xmstring)) 5195 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5198 { 5196 must include the path for this to work. */
5199 /* Add a new item if DEFAULT_FILENAME is not in the list. */ 5197
5200 XmListAddItem (list, default_xmstring, 0); 5198 default_xmstring = XmStringCreateLocalized (SDATA (default_filename));
5201 item_pos = 0;
5202 }
5203 else
5204 item_pos = XmListItemPos (list, default_xmstring);
5205 XmStringFree (default_xmstring);
5206 5199
5207 /* Select the item and scroll it into view. */ 5200 if (XmListItemExists (list, default_xmstring))
5208 XmListSelectPos (list, item_pos, True); 5201 {
5209 XmListSetPos (list, item_pos); 5202 int item_pos = XmListItemPos (list, default_xmstring);
5203 /* Select the item and scroll it into view. */
5204 XmListSelectPos (list, item_pos, True);
5205 XmListSetPos (list, item_pos);
5206 }
5207
5208 XmStringFree (default_xmstring);
5210 } 5209 }
5211 5210
5212 /* Process events until the user presses Cancel or OK. */ 5211 /* Process events until the user presses Cancel or OK. */
@@ -5250,23 +5249,23 @@ selection dialog's entry field, if MUSTMATCH is non-nil. */)
5250 5249
5251#ifdef USE_GTK 5250#ifdef USE_GTK
5252 5251
5253DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, 5252DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5254 "Read file name, prompting with PROMPT in directory DIR.\n\ 5253 doc: /* Read file name, prompting with PROMPT in directory DIR.
5255Use a file selection dialog.\n\ 5254Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5256Select DEFAULT-FILENAME in the dialog's file selection box, if\n\ 5255selection box, if specified. If MUSTMATCH is non-nil, the returned file
5257specified. Don't let the user enter a file name in the file\n\ 5256or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5258selection dialog's entry field, if MUSTMATCH is non-nil.") 5257directories. */)
5259 (prompt, dir, default_filename, mustmatch) 5258 (prompt, dir, default_filename, mustmatch, only_dir_p)
5260 Lisp_Object prompt, dir, default_filename, mustmatch; 5259 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
5261{ 5260{
5262 FRAME_PTR f = SELECTED_FRAME (); 5261 FRAME_PTR f = SELECTED_FRAME ();
5263 char *fn; 5262 char *fn;
5264 Lisp_Object file = Qnil; 5263 Lisp_Object file = Qnil;
5265 int count = specpdl_ptr - specpdl; 5264 int count = specpdl_ptr - specpdl;
5266 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 5265 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5267 char *cdef_file; 5266 char *cdef_file;
5268 5267
5269 GCPRO5 (prompt, dir, default_filename, mustmatch, file); 5268 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5270 CHECK_STRING (prompt); 5269 CHECK_STRING (prompt);
5271 CHECK_STRING (dir); 5270 CHECK_STRING (dir);
5272 5271
@@ -5280,7 +5279,9 @@ selection dialog's entry field, if MUSTMATCH is non-nil.")
5280 else 5279 else
5281 cdef_file = SDATA (dir); 5280 cdef_file = SDATA (dir);
5282 5281
5283 fn = xg_get_file_name (f, SDATA (prompt), cdef_file, ! NILP (mustmatch)); 5282 fn = xg_get_file_name (f, SDATA (prompt), cdef_file,
5283 ! NILP (mustmatch),
5284 ! NILP (only_dir_p));
5284 5285
5285 if (fn) 5286 if (fn)
5286 { 5287 {