aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Tamm2004-08-26 18:28:44 +0000
committerSteven Tamm2004-08-26 18:28:44 +0000
commit6eb3ee72e0d9a53835288bbd6b53dafddea714d6 (patch)
tree9501eabab98c3adf4b18d28049a60125c1e84ccf
parent0e48150a65b1645e0a9ea1c678dc79b782043e28 (diff)
downloademacs-6eb3ee72e0d9a53835288bbd6b53dafddea714d6.tar.gz
emacs-6eb3ee72e0d9a53835288bbd6b53dafddea714d6.zip
fileio.c (Fread_file_name): Call x_file_dialog on carbon on
tool-bar/menu click macfns.c (Fx_file_dialog): Implemented using NavServices
-rw-r--r--src/ChangeLog6
-rw-r--r--src/fileio.c2
-rw-r--r--src/macfns.c216
3 files changed, 150 insertions, 74 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d49514b2fc0..fa1922c6255 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12004-08-26 Steven Tamm <steventamm@mac.com>
2
3 * fileio.c (Fread_file_name): Call x_file_dialog on carbon on
4 tool-bar/menu click
5 * macfns.c (Fx_file_dialog): Implemented using NavServices
6
12004-08-24 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 72004-08-24 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 8
3 * xterm.c (x_catch_errors_unwind): Do not XSync if display has closed. 9 * xterm.c (x_catch_errors_unwind): Do not XSync if display has closed.
diff --git a/src/fileio.c b/src/fileio.c
index 5acfee7c02c..b9299910186 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6304,7 +6304,7 @@ and `read-file-name-function'. */)
6304 6304
6305 GCPRO2 (insdef, default_filename); 6305 GCPRO2 (insdef, default_filename);
6306 6306
6307#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) 6307#if defined (USE_MOTIF) || defined (HAVE_NTGUI) || defined (USE_GTK) || defined(TARGET_API_MAC_CARBON)
6308 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 6308 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
6309 && use_dialog_box 6309 && use_dialog_box
6310 && use_file_dialog 6310 && use_file_dialog
diff --git a/src/macfns.c b/src/macfns.c
index ec014e772e3..fbade05ea17 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -4192,19 +4192,27 @@ Value is t if tooltip was open, nil otherwise. */)
4192 4192
4193 4193
4194 4194
4195#ifdef TARGET_API_MAC_CARBON
4195/*********************************************************************** 4196/***********************************************************************
4196 File selection dialog 4197 File selection dialog
4197 ***********************************************************************/ 4198 ***********************************************************************/
4198 4199
4199#if 0 /* MAC_TODO: can standard file dialog */ 4200/**
4201 There is a relatively standard way to do this using applescript to run
4202 a (choose file) method. However, this doesn't do "the right thing"
4203 by working only if the find-file occurred during a menu or toolbar
4204 click. So we must do the file dialog by hand, using the navigation
4205 manager. This also has more flexibility in determining the default
4206 directory and whether or not we are going to choose a file.
4207 **/
4208
4200extern Lisp_Object Qfile_name_history; 4209extern Lisp_Object Qfile_name_history;
4201 4210
4202DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0, 4211DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 4, 0,
4203 doc: /* Read file name, prompting with PROMPT in directory DIR. 4212 doc: /* Read file name, prompting with PROMPT in directory DIR.
4204Use a file selection dialog. 4213Use a file selection dialog.
4205Select DEFAULT-FILENAME in the dialog's file selection box, if 4214Select DEFAULT-FILENAME in the dialog's file selection box, if
4206specified. Don't let the user enter a file name in the file 4215specified. Ensure that file exists if MUSTMATCH is non-nil. */)
4207selection dialog's entry field, if MUSTMATCH is non-nil. */)
4208 (prompt, dir, default_filename, mustmatch) 4216 (prompt, dir, default_filename, mustmatch)
4209 Lisp_Object prompt, dir, default_filename, mustmatch; 4217 Lisp_Object prompt, dir, default_filename, mustmatch;
4210{ 4218{
@@ -4212,9 +4220,8 @@ selection dialog's entry field, if MUSTMATCH is non-nil. */)
4212 Lisp_Object file = Qnil; 4220 Lisp_Object file = Qnil;
4213 int count = SPECPDL_INDEX (); 4221 int count = SPECPDL_INDEX ();
4214 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 4222 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
4215 char filename[MAX_PATH + 1]; 4223 char filename[1001];
4216 char init_dir[MAX_PATH + 1]; 4224 int default_filter_index = 1; /* 1: All Files, 2: Directories only */
4217 int use_dialog_p = 1;
4218 4225
4219 GCPRO5 (prompt, dir, default_filename, mustmatch, file); 4226 GCPRO5 (prompt, dir, default_filename, mustmatch, file);
4220 CHECK_STRING (prompt); 4227 CHECK_STRING (prompt);
@@ -4223,87 +4230,150 @@ selection dialog's entry field, if MUSTMATCH is non-nil. */)
4223 /* Create the dialog with PROMPT as title, using DIR as initial 4230 /* Create the dialog with PROMPT as title, using DIR as initial
4224 directory and using "*" as pattern. */ 4231 directory and using "*" as pattern. */
4225 dir = Fexpand_file_name (dir, Qnil); 4232 dir = Fexpand_file_name (dir, Qnil);
4226 strncpy (init_dir, SDATA (dir), MAX_PATH);
4227 init_dir[MAX_PATH] = '\0';
4228 unixtodos_filename (init_dir);
4229
4230 if (STRINGP (default_filename))
4231 {
4232 char *file_name_only;
4233 char *full_path_name = SDATA (default_filename);
4234
4235 unixtodos_filename (full_path_name);
4236
4237 file_name_only = strrchr (full_path_name, '\\');
4238 if (!file_name_only)
4239 file_name_only = full_path_name;
4240 else
4241 {
4242 file_name_only++;
4243
4244 /* If default_file_name is a directory, don't use the open
4245 file dialog, as it does not support selecting
4246 directories. */
4247 if (!(*file_name_only))
4248 use_dialog_p = 0;
4249 }
4250
4251 strncpy (filename, file_name_only, MAX_PATH);
4252 filename[MAX_PATH] = '\0';
4253 }
4254 else
4255 filename[0] = '\0';
4256 4233
4257 if (use_dialog_p) 4234 {
4258 { 4235 OSStatus status;
4259 OPENFILENAME file_details; 4236 NavDialogCreationOptions options;
4260 char *filename_file; 4237 NavDialogRef dialogRef;
4238 NavTypeListHandle fileTypes = NULL;
4239 NavUserAction userAction;
4240 CFStringRef message=NULL, client=NULL, saveName = NULL;
4241
4242 /* No need for a callback function because we are modal */
4243 NavGetDefaultDialogCreationOptions(&options);
4244 options.modality = kWindowModalityAppModal;
4245 options.location.h = options.location.v = -1;
4246 options.optionFlags = kNavDefaultNavDlogOptions;
4247 options.optionFlags |= kNavAllFilesInPopup; /* All files allowed */
4248 options.optionFlags |= kNavSelectAllReadableItem;
4249 if (!NILP(prompt))
4250 {
4251 message = CFStringCreateWithCStringNoCopy(NULL, SDATA(prompt),
4252 kCFStringEncodingUTF8,
4253 kCFAllocatorNull);
4254 options.message = message;
4255 }
4256 /* Don't set the application, let it use default.
4257 client = CFStringCreateWithCStringNoCopy(NULL, "Emacs",
4258 kCFStringEncodingMacRoman, NULL);
4259 options.clientName = client;
4260 */
4261
4262 /* Do Dired hack copied from w32fns.c */
4263 if (!NILP(prompt) && strncmp (SDATA(prompt), "Dired", 5) == 0)
4264 status = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL,
4265 &dialogRef);
4266 else if (NILP (mustmatch))
4267 {
4268 /* This is a save dialog */
4269 if (!NILP(default_filename))
4270 {
4271 saveName = CFStringCreateWithCString(NULL, SDATA(default_filename),
4272 kCFStringEncodingUTF8);
4273 options.saveFileName = saveName;
4274 options.optionFlags |= kNavSelectDefaultLocation;
4275 }
4276 /* MAC_TODO: Find a better way to determine if this is a save
4277 or load dialog than comparing dir with default_filename */
4278 if (EQ(dir, default_filename))
4279 {
4280 status = NavCreateChooseFileDialog(&options, fileTypes,
4281 NULL, NULL, NULL, NULL,
4282 &dialogRef);
4283 }
4284 else {
4285 status = NavCreatePutFileDialog(&options,
4286 'TEXT', kNavGenericSignature,
4287 NULL, NULL, &dialogRef);
4288 }
4289 }
4290 else
4291 {
4292 /* This is an open dialog*/
4293 status = NavCreateChooseFileDialog(&options, fileTypes,
4294 NULL, NULL, NULL, NULL,
4295 &dialogRef);
4296 }
4297
4298 /* Set the default location and continue*/
4299 if (status == noErr) {
4300 if (!NILP(dir)) {
4301 FSRef defLoc;
4302 AEDesc defLocAed;
4303 status = FSPathMakeRef(SDATA(dir), &defLoc, NULL);
4304 if (status == noErr)
4305 {
4306 AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed);
4307 NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed);
4308 }
4309 AEDisposeDesc(&defLocAed);
4310 }
4261 4311
4262 /* Prevent redisplay. */
4263 specbind (Qinhibit_redisplay, Qt);
4264 BLOCK_INPUT; 4312 BLOCK_INPUT;
4313 status = NavDialogRun(dialogRef);
4314 UNBLOCK_INPUT;
4315 }
4265 4316
4266 bzero (&file_details, sizeof (file_details)); 4317 if (saveName) CFRelease(saveName);
4267 file_details.lStructSize = sizeof (file_details); 4318 if (client) CFRelease(client);
4268 file_details.hwndOwner = FRAME_W32_WINDOW (f); 4319 if (message) CFRelease(message);
4269 file_details.lpstrFile = filename;
4270 file_details.nMaxFile = sizeof (filename);
4271 file_details.lpstrInitialDir = init_dir;
4272 file_details.lpstrTitle = SDATA (prompt);
4273 file_details.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
4274
4275 if (!NILP (mustmatch))
4276 file_details.Flags |= OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
4277 4320
4278 if (GetOpenFileName (&file_details)) 4321 if (status == noErr) {
4279 { 4322 userAction = NavDialogGetUserAction(dialogRef);
4280 dostounix_filename (filename); 4323 switch (userAction)
4281 file = build_string (filename); 4324 {
4282 } 4325 case kNavUserActionNone:
4283 else 4326 case kNavUserActionCancel:
4284 file = Qnil; 4327 NavDialogDispose(dialogRef);
4285 4328 Fsignal (Qquit, Qnil); /* Treat cancel like C-g */
4286 UNBLOCK_INPUT; 4329 return;
4287 file = unbind_to (count, file); 4330 case kNavUserActionOpen:
4331 case kNavUserActionChoose:
4332 case kNavUserActionSaveAs:
4333 {
4334 NavReplyRecord reply;
4335 AEDesc aed;
4336 FSRef fsRef;
4337 status = NavDialogGetReply(dialogRef, &reply);
4338 AECoerceDesc(&reply.selection, typeFSRef, &aed);
4339 AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef));
4340 FSRefMakePath(&fsRef, (UInt8 *) filename, 1000);
4341 AEDisposeDesc(&aed);
4342 if (reply.saveFileName)
4343 {
4344 /* If it was a saved file, we need to add the file name */
4345 int len = strlen(filename);
4346 if (len && filename[len-1] != '/')
4347 filename[len++] = '/';
4348 CFStringGetCString(reply.saveFileName, filename+len,
4349 1000-len, kCFStringEncodingUTF8);
4350 }
4351 file = DECODE_FILE(build_string (filename));
4352 NavDisposeReply(&reply);
4353 }
4354 break;
4355 }
4356 NavDialogDispose(dialogRef);
4288 } 4357 }
4289 /* Open File dialog will not allow folders to be selected, so resort 4358 else {
4290 to minibuffer completing reads for directories. */ 4359 /* Fall back on minibuffer if there was a problem */
4291 else 4360 file = Fcompleting_read (prompt, intern ("read-file-name-internal"),
4292 file = Fcompleting_read (prompt, intern ("read-file-name-internal"), 4361 dir, mustmatch, dir, Qfile_name_history,
4293 dir, mustmatch, dir, Qfile_name_history, 4362 default_filename, Qnil);
4294 default_filename, Qnil); 4363 }
4364 }
4295 4365
4296 UNGCPRO; 4366 UNGCPRO;
4297 4367
4298 /* Make "Cancel" equivalent to C-g. */ 4368 /* Make "Cancel" equivalent to C-g. */
4299 if (NILP (file)) 4369 if (NILP (file))
4300 Fsignal (Qquit, Qnil); 4370 Fsignal (Qquit, Qnil);
4301 4371
4302 return unbind_to (count, file); 4372 return unbind_to (count, file);
4303} 4373}
4304#endif /* MAC_TODO */
4305 4374
4306 4375
4376#endif
4307 4377
4308/*********************************************************************** 4378/***********************************************************************
4309 Initialization 4379 Initialization
@@ -4507,7 +4577,7 @@ Chinese, Japanese, and Korean. */);
4507 last_show_tip_args = Qnil; 4577 last_show_tip_args = Qnil;
4508 staticpro (&last_show_tip_args); 4578 staticpro (&last_show_tip_args);
4509 4579
4510#if 0 /* MAC_TODO */ 4580#if TARGET_API_MAC_CARBON
4511 defsubr (&Sx_file_dialog); 4581 defsubr (&Sx_file_dialog);
4512#endif 4582#endif
4513} 4583}