diff options
author | hobbs <hobbs> | 2007-10-25 21:44:21 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2007-10-25 21:44:21 (GMT) |
commit | 74c0382ad182c608bc1418a8da6bbc6a368cf801 (patch) | |
tree | 0e316eba5bf980a1124288597f60247798da5ef9 /macosx | |
parent | 4ce5204218fe597d1a9e90e874f1c716b2dcf411 (diff) | |
download | tk-74c0382ad182c608bc1418a8da6bbc6a368cf801.zip tk-74c0382ad182c608bc1418a8da6bbc6a368cf801.tar.gz tk-74c0382ad182c608bc1418a8da6bbc6a368cf801.tar.bz2 |
* doc/getOpenFile.n: TIP#242 implementation of -typevariable to
* library/tkfbox.tcl: return type of selected file in file dialogs.
* library/xmfbox.tcl: [Bug #1156388]
* macosx/tkMacOSXDialog.c:
* tests/filebox.test:
* tests/winDialog.test:
* win/tkWinDialog.c:
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXDialog.c | 97 |
1 files changed, 74 insertions, 23 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 958ae7c..a8767c3 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -10,7 +10,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.30 2007/09/11 05:24:13 das Exp $ + * RCS: @(#) $Id: tkMacOSXDialog.c,v 1.31 2007/10/25 21:44:22 hobbs Exp $ */ #include "tkMacOSXPrivate.h" @@ -38,14 +38,14 @@ * The following structures are used in the GetFileName() function. They store * information about the file dialog and the file filters. */ - -typedef struct OpenFileData { - FileFilterList fl; /* List of file filters. */ - SInt16 curType; /* The filetype currently being listed. */ - short popupItem; /* Item number of the popup in the dialog. */ - int usePopup; /* True if we show the popup menu (this is - * an open operation and the -filetypes - * option is set). */ +typedef struct _OpenFileData { + FileFilterList fl; /* List of file filters. */ + SInt16 curType; /* The filetype currently being listed. */ + short initialType; /* Type to use initially */ + short popupItem; /* Item number of the popup in the dialog. */ + short usePopup; /* True if we show the popup menu (this */ + /* is an open operation and the */ + /* -filetypes option is set). */ } OpenFileData; typedef struct NavHandlerUserData { @@ -85,7 +85,8 @@ static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd, AEDesc *initialDescPtr, char *initialFile, AEDescList *selectDescPtr, CFStringRef title, CFStringRef message, - int multiple, int isOpen, Tk_Window parent); + const char *initialType, int multiple, int isOpen, + Tk_Window parent); static int HandleInitialDirectory(Tcl_Interp *interp, char *initialFile, char *initialDir, FSRef *dirRef, AEDescList *selectDescPtr, AEDesc *dirDescPtr); @@ -261,22 +262,25 @@ Tk_GetOpenFileObjCmd( AEDesc *initialPtr = NULL; AEDescList selectDesc = {typeNull, NULL}; char *initialFile = NULL, *initialDir = NULL; + Tcl_Obj *typeVariablePtr = NULL; + const char *initialtype = NULL; static const char *openOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-multiple", "-parent", "-title", NULL + "-message", "-multiple", "-parent", "-title", "-typevariable", NULL }; enum openOptions { OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE, - OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE + OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE, OPEN_TYPEVARIABLE }; if (!fileDlgInited) { InitFileDialogs(); } TkInitFileFilters(&ofd.fl); - ofd.curType = 0; - ofd.popupItem = OPEN_POPUP_ITEM; - ofd.usePopup = 1; + ofd.curType = 0; + ofd.initialType = -1; + ofd.popupItem = OPEN_POPUP_ITEM; + ofd.usePopup = 1; for (i = 1; i < objc; i += 2) { char *choice; @@ -338,6 +342,9 @@ Tk_GetOpenFileObjCmd( title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, kCFStringEncodingUTF8, false); break; + case OPEN_TYPEVARIABLE: + typeVariablePtr = objv[i + 1]; + break; } } @@ -349,8 +356,23 @@ Tk_GetOpenFileObjCmd( if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } - result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, &selectDesc, - title, message, multiple, OPEN_FILE, parent); + + if (typeVariablePtr) { + initialtype = Tcl_GetVar(interp, Tcl_GetString(typeVariablePtr), 0); + } + result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, &selectDesc, + title, message, initialtype, multiple, OPEN_FILE, parent); + + if (typeVariablePtr) { + int i = ofd.curType; + FileFilter *filterPtr; + for (filterPtr = ofd.fl.filters; + filterPtr && i > 0; i--) { + filterPtr = filterPtr->next; + } + Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), filterPtr->name, 0); + } + end: TkFreeFileFilters(&ofd.fl); if (initialDesc.dataHandle) { @@ -401,11 +423,11 @@ Tk_GetSaveFileObjCmd( OpenFileData ofd; static const char *saveOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-parent", "-title", NULL + "-message", "-parent", "-title", "-typevariable", NULL }; enum saveOptions { SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE, - SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE + SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE, SAVE_TYPEVARIABLE }; if (!fileDlgInited) { @@ -480,7 +502,7 @@ Tk_GetSaveFileObjCmd( initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL, - title, message, false, SAVE_FILE, parent); + title, message, NULL, false, SAVE_FILE, parent); TkFreeFileFilters(&ofd.fl); end: if (initialDesc.dataHandle) { @@ -588,7 +610,7 @@ Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, title, - message, false, CHOOSE_FOLDER, parent); + message, NULL, false, CHOOSE_FOLDER, parent); TkFreeFileFilters(&ofd.fl); end: if (initialDesc.dataHandle) { @@ -737,6 +759,7 @@ NavServicesGetFile( AEDescList *selectDescPtr, CFStringRef title, CFStringRef message, + const char *initialtype, int multiple, int isOpen, Tk_Window parent) @@ -800,6 +823,9 @@ NavServicesGetFile( filterPtr = filterPtr->next, index++) { menuItemNames[index] = CFStringCreateWithCString(NULL, filterPtr->name, kCFStringEncodingUTF8); + if (initialtype && strcmp(filterPtr->name, initialtype) == 0) { + ofdPtr->initialType = index; + } } options.popupExtension = CFArrayCreate(NULL, (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL); @@ -988,8 +1014,33 @@ OpenEventProc( NavCallBackUserData callBackUD) { NavHandlerUserData *data = (NavHandlerUserData*) callBackUD; - + OpenFileData *ofd = data->ofdPtr; switch (callBackSelector) { + case kNavCBStart: + if (ofd && ofd->initialType >= 0) { + /* Select initial filter */ + int i = ofd->initialType; + FileFilter *filterPtr; + + for (filterPtr = ofd->fl.filters; + filterPtr && i > 0; i--) { + filterPtr = filterPtr->next; + } + if (filterPtr) { + NavMenuItemSpec selectItem; + OSStatus err; + selectItem.version = kNavMenuItemSpecVersion; + selectItem.menuCreator = 0; + selectItem.menuType = ofd->initialType; + selectItem.menuItemName[0] = strlen(filterPtr->name); + strncpy(&selectItem.menuItemName[1], filterPtr->name, 255); + err = NavCustomControl(callBackParams->context, kNavCtlSelectCustomType, &selectItem); + if (err != noErr) { + fprintf(stderr,"NavCustomControl kNavCtlSelectCustomType Failed, %d\n", (int)err ); + } + } + } + break; case kNavCBPopupMenuSelect: data->ofdPtr->curType = ((NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param)->menuType; @@ -1077,7 +1128,7 @@ OpenFileFilterProc( fileName[len] = '\0'; fileNamePtr = (unsigned char*) fileName; - } else if ((theItem->descriptorType = typeFSRef)) { + } else if ((theItem->descriptorType == typeFSRef)) { OSStatus err; FSRef *theRef = (FSRef *) *theItem->dataHandle; HFSUniStr255 uniFileName; |