void chooseFileNative( char *title, char *path, int openingFile, char *okMsg, char *cancelMsg ) { if( openingFile ) { GetOpenFileFromUser( title, path, okMsg, cancelMsg ); } else { GetSaveFileFromUser( title, path, okMsg, cancelMsg ); } SetThemeCursor( 0 ); }
std::string getFile(){ return GetOpenFileFromUser(DO_LOAD); };
// OS specific results here. "" = cancel or something bad like can't load, can't save, etc... ofFileDialogResult ofFileLoadDialog(string windowTitle, bool bFolderSelection){ ofFileDialogResult results; //---------------------------------------------------------------------------------------- //------------------------------------------------------------------------------ OSX //---------------------------------------------------------------------------------------- #ifdef TARGET_OSX CFURLRef cfUrl = GetOpenFileFromUser(bFolderSelection); CFStringRef cfString = NULL; if ( cfUrl != NULL ){ cfString = CFURLCopyFileSystemPath( cfUrl, kCFURLPOSIXPathStyle ); CFRelease( cfUrl ); // copy from a CFString into a local c string (http://www.carbondev.com/site/?page=CStrings+) const int kBufferSize = MAXPATHLEN; char fileUrl[kBufferSize]; Boolean bool1 = CFStringGetCString(cfString,fileUrl,kBufferSize,kCFStringEncodingMacRoman); //char fileName[kBufferSize]; //Boolean bool2 = CFStringGetCString(reply.saveFileName,fileName,kBufferSize,kCFStringEncodingMacRoman); // append strings together results.filePath = fileUrl; } #endif //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //------------------------------------------------------------------------------ windoze //---------------------------------------------------------------------------------------- #ifdef TARGET_WIN32 // TODO pc file choose dialog is now mega broken, please fix! if (bFolderSelection == false){ wchar_t szFileName[MAX_PATH] = L""; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); HWND hwnd = WindowFromDC(wglGetCurrentDC()); ofn.hwndOwner = hwnd; ofn.lpstrFilter = _T("All Files (*.*)\0*.*\0"); ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = 0; if(GetOpenFileName(&ofn)) { results.filePath = convertWideToNarrow(szFileName); // TODO: name conversion, please!! } } else { BROWSEINFO bi; wchar_t wideCharacterBuffer[MAX_PATH]; LPITEMIDLIST pidl; LPMALLOC lpMalloc; // Get a pointer to the shell memory allocator if(SHGetMalloc(&lpMalloc) != S_OK){ //TODO: deal with some sort of error here? } bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = wideCharacterBuffer; bi.lpszTitle = _T("Select Directory"); bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; if(pidl = SHBrowseForFolder(&bi)){ // Copy the path directory to the buffer if(SHGetPathFromIDList(pidl,wideCharacterBuffer)){ results.filePath = convertWideToNarrow(wideCharacterBuffer); } lpMalloc->Free(pidl); } lpMalloc->Release(); } //---------------------------------------------------------------------------------------- //------------------------------------------------------------------------------ windoze //---------------------------------------------------------------------------------------- #endif //---------------------------------------------------------------------------------------- //------------------------------------------------------------------------------ linux //---------------------------------------------------------------------------------------- #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) if(bFolderSelection) results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,windowTitle); else results.filePath = gtkFileDialog(GTK_FILE_CHOOSER_ACTION_OPEN,windowTitle); #endif //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- if( results.filePath.length() > 0 ){ results.bSuccess = true; results.fileName = ofFileUtils::getFilenameFromPath(results.filePath); } return results; }
std::string putFile(){ return GetOpenFileFromUser(DO_SAVE); };