5106 |
} |
} |
5107 |
|
|
5108 |
|
|
5109 |
DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, |
DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
5110 |
doc: /* Read file name, prompting with PROMPT in directory DIR. |
doc: /* Read file name, prompting with PROMPT in directory DIR. |
5111 |
Use a file selection dialog. |
Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5112 |
Select DEFAULT-FILENAME in the dialog's file selection box, if |
selection box, if specified. If MUSTMATCH is non-nil, the returned file |
5113 |
specified. Don't let the user enter a file name in the file |
or directory must exist. ONLY-DIR-P is ignored." */) |
5114 |
selection dialog's entry field, if MUSTMATCH is non-nil. */) |
(prompt, dir, default_filename, mustmatch, only_dir_p) |
5115 |
(prompt, dir, default_filename, mustmatch) |
Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; |
|
Lisp_Object prompt, dir, default_filename, mustmatch; |
|
5116 |
{ |
{ |
5117 |
int result; |
int result; |
5118 |
struct frame *f = SELECTED_FRAME (); |
struct frame *f = SELECTED_FRAME (); |
5119 |
Lisp_Object file = Qnil; |
Lisp_Object file = Qnil; |
5120 |
Widget dialog, text, list, help; |
Widget dialog, text, help; |
5121 |
Arg al[10]; |
Arg al[10]; |
5122 |
int ac = 0; |
int ac = 0; |
5123 |
extern XtAppContext Xt_app_con; |
extern XtAppContext Xt_app_con; |
5124 |
XmString dir_xmstring, pattern_xmstring; |
XmString dir_xmstring, pattern_xmstring; |
5125 |
int count = SPECPDL_INDEX (); |
int count = SPECPDL_INDEX (); |
5126 |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
5127 |
|
|
5128 |
GCPRO5 (prompt, dir, default_filename, mustmatch, file); |
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
5129 |
CHECK_STRING (prompt); |
CHECK_STRING (prompt); |
5130 |
CHECK_STRING (dir); |
CHECK_STRING (dir); |
5131 |
|
|
5158 |
XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, |
XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, |
5159 |
(XtPointer) &result); |
(XtPointer) &result); |
5160 |
|
|
5161 |
/* Disable the help button since we can't display help. */ |
/* Remove the help button since we can't display help. */ |
5162 |
help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); |
help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); |
5163 |
XtSetSensitive (help, False); |
XtUnmanageChild (help); |
5164 |
|
|
5165 |
/* Mark OK button as default. */ |
/* Mark OK button as default. */ |
5166 |
XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), |
XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), |
5182 |
/* Manage the dialog, so that list boxes get filled. */ |
/* Manage the dialog, so that list boxes get filled. */ |
5183 |
XtManageChild (dialog); |
XtManageChild (dialog); |
5184 |
|
|
|
/* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME |
|
|
must include the path for this to work. */ |
|
|
list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST); |
|
5185 |
if (STRINGP (default_filename)) |
if (STRINGP (default_filename)) |
5186 |
{ |
{ |
5187 |
XmString default_xmstring; |
XmString default_xmstring; |
5188 |
int item_pos; |
Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); |
5189 |
|
Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST); |
5190 |
|
|
5191 |
default_xmstring |
XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext); |
5192 |
= XmStringCreateLocalized (SDATA (default_filename)); |
XmTextFieldReplace (wtext, 0, last_pos, |
5193 |
|
(SDATA (Ffile_name_nondirectory (default_filename)))); |
5194 |
|
|
5195 |
|
/* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME |
5196 |
|
must include the path for this to work. */ |
5197 |
|
|
5198 |
|
default_xmstring = XmStringCreateLocalized (SDATA (default_filename)); |
5199 |
|
|
5200 |
|
if (XmListItemExists (list, default_xmstring)) |
5201 |
|
{ |
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 |
|
|
|
if (!XmListItemExists (list, default_xmstring)) |
|
|
{ |
|
|
/* Add a new item if DEFAULT_FILENAME is not in the list. */ |
|
|
XmListAddItem (list, default_xmstring, 0); |
|
|
item_pos = 0; |
|
|
} |
|
|
else |
|
|
item_pos = XmListItemPos (list, default_xmstring); |
|
5208 |
XmStringFree (default_xmstring); |
XmStringFree (default_xmstring); |
|
|
|
|
/* Select the item and scroll it into view. */ |
|
|
XmListSelectPos (list, item_pos, True); |
|
|
XmListSetPos (list, item_pos); |
|
5209 |
} |
} |
5210 |
|
|
5211 |
/* Process events until the user presses Cancel or OK. */ |
/* Process events until the user presses Cancel or OK. */ |
5249 |
|
|
5250 |
#ifdef USE_GTK |
#ifdef USE_GTK |
5251 |
|
|
5252 |
DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, |
DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
5253 |
"Read file name, prompting with PROMPT in directory DIR.\n\ |
doc: /* Read file name, prompting with PROMPT in directory DIR. |
5254 |
Use a file selection dialog.\n\ |
Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5255 |
Select DEFAULT-FILENAME in the dialog's file selection box, if\n\ |
selection box, if specified. If MUSTMATCH is non-nil, the returned file |
5256 |
specified. Don't let the user enter a file name in the file\n\ |
or directory must exist. If ONLY-DIR-P is non-nil, the user can only select |
5257 |
selection dialog's entry field, if MUSTMATCH is non-nil.") |
directories. */) |
5258 |
(prompt, dir, default_filename, mustmatch) |
(prompt, dir, default_filename, mustmatch, only_dir_p) |
5259 |
Lisp_Object prompt, dir, default_filename, mustmatch; |
Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; |
5260 |
{ |
{ |
5261 |
FRAME_PTR f = SELECTED_FRAME (); |
FRAME_PTR f = SELECTED_FRAME (); |
5262 |
char *fn; |
char *fn; |
5263 |
Lisp_Object file = Qnil; |
Lisp_Object file = Qnil; |
5264 |
int count = specpdl_ptr - specpdl; |
int count = specpdl_ptr - specpdl; |
5265 |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
5266 |
char *cdef_file; |
char *cdef_file; |
5267 |
|
|
5268 |
GCPRO5 (prompt, dir, default_filename, mustmatch, file); |
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
5269 |
CHECK_STRING (prompt); |
CHECK_STRING (prompt); |
5270 |
CHECK_STRING (dir); |
CHECK_STRING (dir); |
5271 |
|
|
5279 |
else |
else |
5280 |
cdef_file = SDATA (dir); |
cdef_file = SDATA (dir); |
5281 |
|
|
5282 |
fn = xg_get_file_name (f, SDATA (prompt), cdef_file, ! NILP (mustmatch)); |
fn = xg_get_file_name (f, SDATA (prompt), cdef_file, |
5283 |
|
! NILP (mustmatch), |
5284 |
|
! NILP (only_dir_p)); |
5285 |
|
|
5286 |
if (fn) |
if (fn) |
5287 |
{ |
{ |