From 2fa6889f4c599bda43fd66dbc9d1c04870413e59 Mon Sep 17 00:00:00 2001 From: hobbs Date: Tue, 23 Aug 2005 22:08:26 +0000 Subject: * macosx/tkMacOSXDialog.c: make dialogs ignore -initialfile "" and -initialdir "" instead of error. --- ChangeLog | 5 +++ macosx/tkMacOSXDialog.c | 90 ++++++++++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1a14c4..d2ae4d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-08-23 Jeff Hobbs + + * macosx/tkMacOSXDialog.c: make dialogs ignore -initialfile "" and + -initialdir "" instead of error. + 2005-08-23 Mo DeJong * win/tkWin32Dll.c (DllMain): Replace old asm SEH diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index d94b945..bc7b3c8 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.6 2005/08/22 11:55:15 das Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.4.2.7 2005/08/23 22:08:27 hobbs Exp $ */ #include @@ -87,7 +87,7 @@ static int HandleInitialDirectory (Tcl_Interp *interp, char *initialFile, char *initialDir, FSRef *dirRef, AEDescList *selectDescPtr, - AEDesc *dirDescPtr); + AEDesc *dirDescPtr); /* * Have we initialized the file dialog subsystem @@ -273,15 +273,15 @@ Tk_GetOpenFileObjCmd( AEDescList selectDesc = {typeNull, NULL}; char *initialFile = NULL, *initialDir = NULL; static CONST char *openOptionStrings[] = { - "-defaultextension", "-filetypes", - "-initialdir", "-initialfile", + "-defaultextension", "-filetypes", + "-initialdir", "-initialfile", "-message", "-multiple", - "-parent", "-title", NULL + "-parent", "-title", NULL }; enum openOptions { - OPEN_DEFAULT, OPEN_FILETYPES, + OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE, - OPEN_MESSAGE, OPEN_MULTIPLE, + OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE }; @@ -289,14 +289,14 @@ Tk_GetOpenFileObjCmd( InitFileDialogs(); } - result = TCL_ERROR; - parent = (Tk_Window) clientData; + result = TCL_ERROR; + parent = (Tk_Window) clientData; multiple = false; title = NULL; - message = NULL; + message = NULL; TkInitFileFilters(&ofd.fl); - + ofd.curType = 0; ofd.popupItem = OPEN_POPUP_ITEM; ofd.usePopup = 1; @@ -331,10 +331,14 @@ Tk_GetOpenFileObjCmd( } break; case OPEN_INITDIR: - initialDir = Tcl_GetStringFromObj(objv[i + 1], NULL); + initialDir = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + /* empty strings should be like no selection given */ + if (choiceLen == 0) { initialDir = NULL; } break; case OPEN_INITFILE: initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL); + /* empty strings should be like no selection given */ + if (choiceLen == 0) { initialFile = NULL; } break; case OPEN_MESSAGE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); @@ -374,8 +378,7 @@ Tk_GetOpenFileObjCmd( initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, - NULL, &selectDesc, - title, message, multiple, OPEN_FILE); + NULL, &selectDesc, title, message, multiple, OPEN_FILE); end: TkFreeFileFilters(&ofd.fl); @@ -434,11 +437,11 @@ Tk_GetSaveFileObjCmd( if (!fileDlgInited) { InitFileDialogs(); } - - result = TCL_ERROR; - parent = (Tk_Window) clientData; + + result = TCL_ERROR; + parent = (Tk_Window) clientData; title = NULL; - message = NULL; + message = NULL; for (i = 1; i < objc; i += 2) { char *choice; @@ -462,15 +465,19 @@ Tk_GetSaveFileObjCmd( /* Currently unimplemented - what would we do here anyway? */ break; case SAVE_INITDIR: - choice = Tcl_GetStringFromObj(objv[i + 1], NULL); - if (HandleInitialDirectory(interp, NULL, choice, &dirRef, - NULL, &initialDesc) != TCL_OK) { - result = TCL_ERROR; - goto end; - } + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + /* empty strings should be like no selection given */ + if (choiceLen && + HandleInitialDirectory(interp, NULL, choice, &dirRef, + NULL, &initialDesc) != TCL_OK) { + result = TCL_ERROR; + goto end; + } break; case SAVE_INITFILE: - initialFile = Tcl_GetStringFromObj(objv[i + 1], NULL); + initialFile = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + /* empty strings should be like no selection given */ + if (choiceLen == 0) { initialFile = NULL; } break; case SAVE_MESSAGE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); @@ -492,7 +499,7 @@ Tk_GetSaveFileObjCmd( break; } } - + TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; @@ -503,7 +510,7 @@ Tk_GetSaveFileObjCmd( title, message, false, SAVE_FILE); end: - + AEDisposeDesc(&initialDesc); if (title != NULL) { CFRelease(title); @@ -511,7 +518,7 @@ Tk_GetSaveFileObjCmd( if (message != NULL) { CFRelease(message); } - + return result; } @@ -549,14 +556,13 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) CFStringRef message, title; OpenFileData ofd; static CONST char *chooseOptionStrings[] = { - "-initialdir", "-message", "-mustexist", "-parent", "-title", NULL + "-initialdir", "-message", "-mustexist", "-parent", "-title", NULL }; enum chooseOptions { - CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, - CHOOSE_PARENT, CHOOSE_TITLE + CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, + CHOOSE_PARENT, CHOOSE_TITLE }; - - + if (!NavServicesAvailable()) { return TCL_ERROR; } @@ -564,10 +570,10 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) if (!fileDlgInited) { InitFileDialogs(); } - result = TCL_ERROR; - parent = (Tk_Window) clientData; + result = TCL_ERROR; + parent = (Tk_Window) clientData; title = NULL; - message = NULL; + message = NULL; for (i = 1; i < objc; i += 2) { char *choice; @@ -586,9 +592,10 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) } switch (index) { case CHOOSE_INITDIR: - choice = Tcl_GetStringFromObj(objv[i + 1], NULL); - if (HandleInitialDirectory(interp, NULL, choice, &dirRef, - NULL, &initialDesc) != TCL_OK) { + choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); + if (choiceLen && + HandleInitialDirectory(interp, NULL, choice, &dirRef, + NULL, &initialDesc) != TCL_OK) { result = TCL_ERROR; goto end; } @@ -613,11 +620,10 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) break; } } - + TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; - if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } @@ -658,7 +664,7 @@ HandleInitialDirectory ( } err = FSPathMakeRef((unsigned char*) dirName, - dirRef, &isDirectory); + dirRef, &isDirectory); if (err != noErr) { Tcl_AppendResult(interp, "bad directory \"", -- cgit v0.12