OSStatus LLFilePickerBase::doNavSaveDialog(ESaveFilter filter, std::string const& filename, std::string const& folder) { OSStatus error = noErr; NavDialogRef navRef = NULL; NavReplyRecord navReply; memset(&navReply, 0, sizeof(navReply)); // Setup the type, creator, and extension OSType type, creator; CFStringRef extension = NULL; switch (filter) { case FFSAVE_WAV: type = 'WAVE'; creator = 'TVOD'; extension = CFSTR(".wav"); break; case FFSAVE_TGA: type = 'TPIC'; creator = 'prvw'; extension = CFSTR(".tga"); break; case FFSAVE_BMP: type = 'BMPf'; creator = 'prvw'; extension = CFSTR(".bmp"); break; case FFSAVE_JPEG: type = 'JPEG'; creator = 'prvw'; extension = CFSTR(".jpeg"); break; case FFSAVE_PNG: type = 'PNG '; creator = 'prvw'; extension = CFSTR(".png"); break; case FFSAVE_AVI: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".mov"); break; case FFSAVE_ANIM: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".xaf"); break; #ifdef _CORY_TESTING case FFSAVE_GEOMETRY: type = L'\?\?\?\?'; creator = L'\?\?\?\?'; extension = CFSTR(".slg"); break; #endif case FFSAVE_RAW: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(".raw"); break; case FFSAVE_J2C: type = '\?\?\?\?'; creator = 'prvw'; extension = CFSTR(".j2c"); break; case FFSAVE_ALL: default: type = '\?\?\?\?'; creator = '\?\?\?\?'; extension = CFSTR(""); break; } NavEventUPP eventUPP = NewNavEventUPP(NULL); //TODO: test filepicker mFolder = folder; // Create the dialog error = NavCreatePutFileDialog(&mNavOptions, type, creator, eventUPP, (void*)this, &navRef); if (error == noErr) { CFStringRef nameString = NULL; bool hasExtension = true; // Create a CFString of the initial file name if (!filename.empty()) nameString = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); else nameString = CFSTR("Untitled"); // Add the extension if one was not provided if (nameString && !CFStringHasSuffix(nameString, extension)) { CFStringRef tempString = nameString; hasExtension = false; nameString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), tempString, extension); CFRelease(tempString); } // Set the name in the dialog if (nameString) { error = NavDialogSetSaveFileName(navRef, nameString); CFRelease(nameString); } else { error = paramErr; } } //gViewerWindow->mWindow->beforeDialog(); // Run the dialog if (error == noErr) { PLS_FLUSH; error = NavDialogRun(navRef); } //gViewerWindow->mWindow->afterDialog(); if (error == noErr) error = NavDialogGetReply(navRef, &navReply); if (navRef) NavDialogDispose(navRef); if (error == noErr && navReply.validRecord) { SInt32 count = 0; // AE indexes are 1 based... error = AECountItems(&navReply.selection, &count); if (count > 0) { // Get the FSRef to the containing folder FSRef fsRef; AEKeyword theAEKeyword; DescType typeCode; Size actualSize = 0; memset(&fsRef, 0, sizeof(fsRef)); error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); if (error == noErr) { char path[PATH_MAX]; /*Flawfinder: ignore*/ char newFileName[SINGLE_FILENAME_BUFFER_SIZE]; /*Flawfinder: ignore*/ error = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX); if (error == noErr) { if (CFStringGetCString(navReply.saveFileName, newFileName, sizeof(newFileName), kCFStringEncodingUTF8)) { mFiles.push_back(std::string(path) + "/" + std::string(newFileName)); } else { error = paramErr; } } else { error = paramErr; } } } } if (eventUPP) DisposeNavEventUPP(eventUPP); return error; }
QString Q3FileDialog::macGetSaveFileName(const QString &start, const QString &filter, QString *, QWidget *parent, const char* /*name*/, const QString& caption, QString *selectedFilter) { OSErr err; QString retstr; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); static const int w = 450, h = 350; options.optionFlags |= kNavDontConfirmReplacement; options.modality = kWindowModalityAppModal; options.location.h = options.location.v = -1; QString workingDir; QString initialSelection; if (!start.isEmpty()) { Q3UrlOperator u(encodeFileName(start)); if (u.isLocalFile() && QFileInfo(u.path()).isDir()) { workingDir = start; } else { if (u.isLocalFile()) { QFileInfo fi(u.dirPath()); if (fi.exists()) { workingDir = u.dirPath(); initialSelection = u.fileName(); } } else { workingDir = u.toString(); } } if (!initialSelection.isEmpty()) options.saveFileName = CFStringCreateWithCharacters(0, (UniChar *)initialSelection.unicode(), initialSelection.length()); } if(!caption.isEmpty()) options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(), caption.length()); if(parent && parent->isVisible()) { Qt::WindowType wt = parent->window()->windowType(); if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if(options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if(options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } } else if(QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if(last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } } QList<qt_mac_filter_name*> filts = makeFiltersList(filter); qt_mac_nav_filter_type t; t.index = 0; t.filts = &filts; if(filts.count() > 1) { int i = 0; CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count()); for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) { QString rg = (*it)->description; arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length()); } options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL); } NavDialogRef dlg; if(NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(), (void *) (filts.isEmpty() ? NULL : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstr; } if (!workingDir.isEmpty()) { FSRef fsref; if (qt_mac_create_fsref(workingDir, &fsref) == noErr) { AEDesc desc; if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if(options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, __FILE__ "__modal_dlg", Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while(g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if(NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) { NavDialogDispose(dlg); return retstr; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if(!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstr; } AEKeyword keyword; DescType type; Size size; FSRef ref; err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword, &type, &ref, sizeof(ref), &size); if(err == noErr) { if(!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstr = QString::fromUtf8((const char *)str_buffer); //now filename CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8); retstr += QLatin1Char('/') + QString::fromUtf8((const char *)str_buffer); } NavDisposeReply(&ret); if(selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstr; }
OSStatus LLFilePickerBase::doNavChooseDialog(ELoadFilter filter, std::string const& folder) { OSStatus error = noErr; NavDialogRef navRef = NULL; NavReplyRecord navReply; memset(&navReply, 0, sizeof(navReply)); mLoadFilter = filter; mFolder = folder; NavEventUPP eventProc = NewNavEventUPP(doNavCallbackEvent); // NOTE: we are passing the address of a local variable here. // This is fine, because the object this call creates will exist for less than the lifetime of this function. // (It is destroyed by NavDialogDispose() below.) error = NavCreateChooseFileDialog(&mNavOptions, NULL, eventProc, NULL, navOpenFilterProc, (void*)this, &navRef); //gViewerWindow->mWindow->beforeDialog(); if (error == noErr) { PLS_FLUSH; error = NavDialogRun(navRef); } //gViewerWindow->mWindow->afterDialog(); if (error == noErr) error = NavDialogGetReply(navRef, &navReply); if (navRef) NavDialogDispose(navRef); if (error == noErr && navReply.validRecord) { SInt32 count = 0; SInt32 index; // AE indexes are 1 based... error = AECountItems(&navReply.selection, &count); for (index = 1; index <= count; index++) { FSRef fsRef; AEKeyword theAEKeyword; DescType typeCode; Size actualSize = 0; char path[MAX_PATH]; /*Flawfinder: ignore*/ memset(&fsRef, 0, sizeof(fsRef)); error = AEGetNthPtr(&navReply.selection, index, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); if (error == noErr) error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path)); if (error == noErr) mFiles.push_back(std::string(path)); } } if (eventProc) DisposeNavEventUPP(eventProc); return error; }
QStringList Q3FileDialog::macGetOpenFileNames(const QString &filter, QString *pwd, QWidget *parent, const char* /*name*/, const QString& caption, QString *selectedFilter, bool multi, bool directory) { OSErr err; QStringList retstrl; NavDialogCreationOptions options; NavGetDefaultDialogCreationOptions(&options); options.modality = kWindowModalityAppModal; options.optionFlags |= kNavDontConfirmReplacement | kNavSupportPackages; if (!multi) options.optionFlags &= ~kNavAllowMultipleFiles; if(!caption.isEmpty()) options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(), caption.length()); static const int w = 450, h = 350; options.location.h = options.location.v = -1; if(parent && parent->isVisible()) { Qt::WindowType wt = parent->window()->windowType(); if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) { options.modality = kWindowModalityWindowModal; options.parentWindow = qt_mac_window_for(parent); } else { parent = parent->window(); QString s = parent->windowTitle(); options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length()); options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2); options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2); QRect r = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber(parent)); if(options.location.h + w > r.right()) options.location.h -= (options.location.h + w) - r.right() + 10; if(options.location.v + h > r.bottom()) options.location.v -= (options.location.v + h) - r.bottom() + 10; } } else if(QWidget *p = qApp->mainWidget()) { static int last_screen = -1; int scr = QApplication::desktop()->screenNumber(p); if(last_screen != scr) { QRect r = QApplication::desktop()->screenGeometry(scr); options.location.h = (r.x() + (r.width() / 2)) - (w / 2); options.location.v = (r.y() + (r.height() / 2)) - (h / 2); } } QList<qt_mac_filter_name*> filts = makeFiltersList(filter); qt_mac_nav_filter_type t; t.index = 0; t.filts = &filts; if(filts.count() > 1) { int i = 0; CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count()); for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) { QString rg = (*it)->description; arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length()); } options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL); } NavDialogRef dlg; if(directory) { if(NavCreateChooseFolderDialog(&options, make_navProcUPP(), NULL, NULL, &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } else { if(NavCreateGetFileDialog(&options, NULL, make_navProcUPP(), NULL, make_navFilterUPP(), (void *) (filts.isEmpty() ? NULL : &t), &dlg)) { qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); return retstrl; } } if(pwd && !pwd->isEmpty()) { FSRef fsref; if(qt_mac_create_fsref(*pwd, &fsref) == noErr) { AEDesc desc; if(AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr) NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc); } } NavDialogRun(dlg); if (selectedFilter) { NavMenuItemSpec navSpec; bzero(&navSpec, sizeof(NavMenuItemSpec)); qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0); for (int i = 0; i < filts.count(); ++i) { const qt_mac_filter_name *filter = filts.at(i); if (sel_filt_name->description == filter->description && sel_filt_name->regxp == filter->regxp && sel_filt_name->filter == filter->filter) { navSpec.menuType = i; break; } } NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec); } if(options.modality == kWindowModalityWindowModal) { //simulate modality QWidget modal_widg(parent, __FILE__ "__modal_dlg", Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder); modal_widg.createWinId(); QApplicationPrivate::enterModal(&modal_widg); while(g_nav_blocking) qApp->processEvents(QEventLoop::WaitForMoreEvents); QApplicationPrivate::leaveModal(&modal_widg); } if(!(NavDialogGetUserAction(dlg) & (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) { NavDialogDispose(dlg); return retstrl; } NavReplyRecord ret; NavDialogGetReply(dlg, &ret); NavDialogDispose(dlg); long count; err = AECountItems(&(ret.selection), &count); if(!ret.validRecord || err != noErr || !count) { NavDisposeReply(&ret); return retstrl; } for(long index = 1; index <= count; index++) { FSRef ref; err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0); if(err != noErr) break; if(!str_buffer) { qAddPostRoutine(cleanup_str_buffer); str_buffer = (UInt8 *)malloc(1024); } FSRefMakePath(&ref, str_buffer, 1024); retstrl.append(QString::fromUtf8((const char *)str_buffer)); } NavDisposeReply(&ret); if(selectedFilter) *selectedFilter = filts.at(t.index)->filter; while (!filts.isEmpty()) delete filts.takeFirst(); return retstrl; }
static OSErr OpenDocEventHandler(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) { char** argv = NULL; int no; AEDesc fileListDesc = {'NULL', NULL}; long numFiles; long actualSize; long index; OSErr err; DescType actualType; AEKeyword actualKeyword; FSSpec aFile; FSRef theFile; UInt8 fullPath[MAXPATHLEN]; bool openWithWebStart = true; CFURLRef jnlpLocation = NULL; // Load up our list of file descriptors err = AEGetKeyDesc(theAppleEvent, keyDirectObject, typeAEList, &fileListDesc); if(err) { AEDisposeDesc(&fileListDesc); fprintf(stderr, "Error getting key desc\n"); return err; } // How many files do we have to deal with? err = AECountItems(&fileListDesc, &numFiles); if(err) { AEDisposeDesc(&fileListDesc); fprintf(stderr, "Error counting items\n"); return err; } // Iterate through all of the files, and try to send them through the JNLP java code. for(index = 1; index <= numFiles; index++) { err = AEGetNthPtr(&fileListDesc, index, typeFSS, &actualKeyword, &actualType, (Ptr)&aFile, sizeof(aFile), &actualSize); if(err) { AEDisposeDesc(&fileListDesc); fprintf(stderr, "Error getting file pointer\n"); return err; } // Mac stuff to turn the file representation we get into a workable pathname FSpMakeFSRef(&aFile, &theFile); FSRefMakePath(&theFile, fullPath, sizeof(fullPath)); // See if we have an application for this JNLP file. If so, use that instead. jnlpLocation = FindJnlpURLInFile(fullPath); if (jnlpLocation != NULL) { CFURLRef applicationURL = FindJNLPApplicationPackage(jnlpLocation); if (applicationURL != NULL) { OSStatus result = LSOpenCFURLRef(applicationURL, NULL); if (result == noErr) { openWithWebStart = false; } } CFRelease(jnlpLocation); } if (openWithWebStart) { // Three arguments -- app name, file to open, and null. argv = (char**)malloc(sizeof(char*) * 3); no = 0; argv[no++] = GetWebStartAppName(); argv[no++] = fullPath; argv[no] = NULL; // Call into our main app. main(no, argv); } openWithWebStart = TRUE; } QuitApplicationEventLoop(); return noErr; }
static pascal OSErr OpenFinderDoc(const AppleEvent *evt, AppleEvent *b, long c) { AEDescList docList; long count, size; short i, j; DescType retType; AEKeyword keywd; FSSpec fss; FSRef fsref; char **files, *fl; OSErr err; AEGetParamDesc(evt, keyDirectObject, typeAEList, &docList); AECountItems(&docList, &count); if (gone) files = (char **)scheme_malloc(sizeof(char *) * count); else files = (char **)malloc(sizeof(char *) * count); j = 0; for (i = 0; i < count; i++) { #ifdef OS_X err = AEGetNthPtr(&docList, i + 1, typeFSRef, &keywd, &retType, (Ptr)&fsref, sizeof(fsref), &size); #else err = errAECoercionFail; #endif if (err != noErr) { if (err == errAECoercionFail) { /* Try FSSpec: */ FSSpec spec; err = AEGetNthPtr(&docList, i + 1, typeFSS, &keywd, &retType, (Ptr)&fss, sizeof(FSSpec), &size); if (err == noErr) { fl = scheme_mac_spec_to_path(&spec); } else { fl = NULL; } } else { fl = NULL; } } else { #ifdef OS_X fl = wxFSRefToPath(fsref); #else fl = NULL; #endif } if (fl) { if (gone) files[i + j] = fl; else { /* have to malloc everything */ char *fl2; fl2 = (char *)malloc(strlen(fl)+1); memcpy(fl2, fl, strlen(fl)+1); files[i + j] = fl2; } if (!files[i + j]) --j; } else --j; } AEDisposeDesc(&docList); if (!gone) { gone = 1; Startup(files, count + j); } else { wxDrop_Runtime(files, count + j); } return 0; }
Boolean AskUserForGetFileName(char* prompt_string, short numTypes, OSType typeList[], // char* pathOfFileSelected, short maxPathLength, FSSpec *specPtr, MyCustomNavItemsData *myCustomItemsDataPtr) { OSStatus err = 0; NavDialogCreationOptions dialogOptions; NavTypeListHandle inTypeList = 0; NavEventUPP inEventProc = 0; NavPreviewUPP inPreviewProc = 0; NavObjectFilterUPP inFilterProc = 0; Ptr inClientData = (Ptr)myCustomItemsDataPtr; NavDialogRef navDialogRef = 0; NavReplyRecord replyRecord; Boolean gotReply = false; FSSpec fsSpec; char pathName[256]=""; CFStringRef windowTitleCFStrRef = 0; CFStringRef clientNameCFStrRef = 0; if(specPtr) memset(specPtr,0,sizeof(specPtr)); if(pathOfFileSelected && maxPathLength > 0) pathOfFileSelected[0] = 0; err = NavGetDefaultDialogCreationOptions(&dialogOptions); if(err) return false; // for now don't customize the dialogs, may want to do this later /*if(myCustomItemsDataPtr && myCustomItemsDataPtr->ditlResID) { inEventProc = GetMyNavEventHandlerUPP(); }*/ if(prompt_string && prompt_string[0]) { windowTitleCFStrRef = CFStringCreateWithCString(NULL, prompt_string, kCFStringEncodingMacRoman); dialogOptions.windowTitle = windowTitleCFStrRef; } // set the client name so the system can remember the last place the user looked clientNameCFStrRef = CFStringCreateWithCString(NULL, "GNOME", kCFStringEncodingMacRoman); dialogOptions.clientName = clientNameCFStrRef; //inTypeList = MyCreateNavTypeListHandle(gMySignature,numTypes,typeList); // for now allow all files to be shown, filtering is messed up on 10.6 //err = NavCreateChooseFileDialog (&dialogOptions,inTypeList,inEventProc,inPreviewProc,inFilterProc,inClientData,&navDialogRef); err = NavCreateChooseFileDialog (&dialogOptions,inTypeList,inEventProc,inPreviewProc,inFilterProc,NULL,&navDialogRef); if(err) return false; InitCursor(); err = NavDialogRun(navDialogRef); SetWatchCursor(); if(err) goto done; err = NavDialogGetReply(navDialogRef,&replyRecord); if(err) goto done; gotReply = true; err = AEGetNthPtr(&(replyRecord.selection), 1, typeFSS, NULL, NULL, &fsSpec, sizeof(fsSpec), NULL); if(err) goto done; (void)PathNameFromDirID(fsSpec.parID,fsSpec.vRefNum,pathName);//GetPathWithDelimiterFromDirID mypstrcatJM((StringPtr)pathName,fsSpec.name); my_p2cstr(pathName); if(strlen(pathName) < maxPathLength){ strcpy(pathOfFileSelected,pathName); } else { err = -1; // path is too long to return } if(!err && specPtr) *specPtr = fsSpec; done: if(inTypeList) {DisposeHandle((Handle)inTypeList); inTypeList = 0;} if(windowTitleCFStrRef) { CFRelease(windowTitleCFStrRef); windowTitleCFStrRef = 0;} if(clientNameCFStrRef) { CFRelease(clientNameCFStrRef); clientNameCFStrRef = 0;} if(gotReply) NavDisposeReply(&replyRecord); NavDialogDispose(navDialogRef); if(gotReply && !err) return true; return false; } /* end MyGetMacFile() */
Boolean AskUserForPutFileName(char* promptStr, char* defaultName, char* pathOfFileSelected, short maxPathLength, FSSpec *specPtr, MyCustomNavItemsData *myCustomItemsDataPtr) { OSStatus err = 0; NavDialogCreationOptions dialogOptions; OSType inFileType = 'TEXT'; // what will happen if we always just say TEXT and change our mind later ? (perhaps it will add .txt) ? OSType inFileCreator = kNavGenericSignature; NavEventUPP inEventProc = 0; Ptr inClientData = (Ptr)myCustomItemsDataPtr; NavDialogRef navDialogRef = 0; NavReplyRecord replyRecord; Boolean gotReply = false; FSSpec fsSpec; char pathName[256]=""; char theFileName[256]=""; CFStringRef windowTitleCFStrRef = 0; CFStringRef clientNameCFStrRef = 0; CFStringRef saveFileNameCFStrRef = 0; if(specPtr) memset(specPtr,0,sizeof(specPtr)); if(pathOfFileSelected && maxPathLength > 0) pathOfFileSelected[0] = 0; err = NavGetDefaultDialogCreationOptions(&dialogOptions); if(err) return false; // for now don't customize the dialogs, may want to do this later /*if(myCustomItemsDataPtr && myCustomItemsDataPtr->ditlResID) { inEventProc = GetMyNavEventHandlerUPP(); }*/ if(promptStr && promptStr[0]) { windowTitleCFStrRef = CFStringCreateWithCString(NULL, promptStr,kCFStringEncodingMacRoman); dialogOptions.windowTitle = windowTitleCFStrRef; } // set the client name so the system can remember the last place the user looked clientNameCFStrRef = CFStringCreateWithCString(NULL,"GNOME",kCFStringEncodingMacRoman); dialogOptions.clientName = clientNameCFStrRef; if(defaultName && defaultName[0]) { saveFileNameCFStrRef = CFStringCreateWithCString(NULL, defaultName,kCFStringEncodingMacRoman); dialogOptions.saveFileName = saveFileNameCFStrRef; } //err = NavCreatePutFileDialog(&dialogOptions,inFileType,inFileCreator,inEventProc,inClientData,&navDialogRef); err = NavCreatePutFileDialog(&dialogOptions,inFileType,inFileCreator,inEventProc,NULL,&navDialogRef); if(err) return false; InitCursor(); err = NavDialogRun(navDialogRef); SetWatchCursor(); if(err) goto done; err = NavDialogGetReply(navDialogRef,&replyRecord); if(err) goto done; gotReply = true; err = AEGetNthPtr(&(replyRecord.selection), 1, typeFSS, NULL, NULL, &fsSpec, sizeof(fsSpec), NULL); if(err) goto done; (void)PathNameFromDirID(fsSpec.parID,fsSpec.vRefNum,pathName); // GetPathWithDelimiterFromDirID mypstrcatJM((StringPtr)pathName,fsSpec.name); my_p2cstr(pathName); (void)CFStringGetCString(replyRecord.saveFileName,theFileName,256,kCFStringEncodingMacRoman); if( (strlen(pathName) + 1 + strlen(theFileName)) < maxPathLength){ strcpy(pathOfFileSelected,pathName); strcat(pathOfFileSelected,":"); strcat(pathOfFileSelected,theFileName); } else { err = -1; // path is too long to return } if(!err && specPtr) *specPtr = fsSpec; done: if(windowTitleCFStrRef) { CFRelease(windowTitleCFStrRef); windowTitleCFStrRef = 0;} if(clientNameCFStrRef) { CFRelease(clientNameCFStrRef); clientNameCFStrRef = 0;} if(saveFileNameCFStrRef) { CFRelease(saveFileNameCFStrRef); saveFileNameCFStrRef = 0;} if(gotReply) NavDisposeReply(&replyRecord); NavDialogDispose(navDialogRef); if(gotReply && !err) return true; return false; }