|
|
@ -21,6 +21,9 @@ |
|
|
|
* IN THE SOFTWARE. |
|
|
|
*/ |
|
|
|
|
|
|
|
// This code has been modified by Macoy Madson. My changes will remain under the same license as
|
|
|
|
// above. It has been modified to support opening DIALOG_DIR on Windows.
|
|
|
|
|
|
|
|
/* A portable library to create open and save dialogs on linux, osx and
|
|
|
|
* windows. |
|
|
|
* |
|
|
@ -150,41 +153,88 @@ const char *noc_file_dialog_open(int flags, |
|
|
|
|
|
|
|
#include <windows.h> |
|
|
|
#include <commdlg.h> |
|
|
|
#include <shlobj_core.h> |
|
|
|
|
|
|
|
const char *noc_file_dialog_open(int flags, |
|
|
|
const char *filters, |
|
|
|
const char *default_path, |
|
|
|
const char *default_name) |
|
|
|
static int CALLBACK BrowseCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) |
|
|
|
{ |
|
|
|
OPENFILENAME ofn; // common dialog box structure
|
|
|
|
char szFile[260]; // buffer for file name
|
|
|
|
int ret; |
|
|
|
if(uMsg == BFFM_INITIALIZED) |
|
|
|
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); |
|
|
|
|
|
|
|
// init default file name
|
|
|
|
if (default_name) |
|
|
|
strncpy(szFile, default_name, sizeof(szFile) - 1); |
|
|
|
else |
|
|
|
szFile[0] = '\0'; |
|
|
|
|
|
|
|
ZeroMemory(&ofn, sizeof(ofn)); |
|
|
|
ofn.lStructSize = sizeof(ofn); |
|
|
|
ofn.lpstrFile = szFile; |
|
|
|
ofn.nMaxFile = sizeof(szFile); |
|
|
|
ofn.lpstrFilter = filters; |
|
|
|
ofn.nFilterIndex = 1; |
|
|
|
ofn.lpstrFileTitle = NULL; |
|
|
|
ofn.nMaxFileTitle = 0; |
|
|
|
ofn.lpstrInitialDir = (LPSTR)default_path; |
|
|
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; |
|
|
|
|
|
|
|
if (flags & NOC_FILE_DIALOG_OPEN) |
|
|
|
ret = GetOpenFileName(&ofn); |
|
|
|
else |
|
|
|
ret = GetSaveFileName(&ofn); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
free(g_noc_file_dialog_ret); |
|
|
|
g_noc_file_dialog_ret = ret ? strdup(szFile) : NULL; |
|
|
|
return g_noc_file_dialog_ret; |
|
|
|
const char* noc_file_dialog_open(int flags, const char* filters, const char* default_path, |
|
|
|
const char* default_name) |
|
|
|
{ |
|
|
|
// Open Directory
|
|
|
|
if (flags & NOC_FILE_DIALOG_DIR) |
|
|
|
{ |
|
|
|
char path[1024] = {0}; |
|
|
|
|
|
|
|
BROWSEINFO bi = {0}; |
|
|
|
bi.lpszTitle = ("Browse for folder to index"); |
|
|
|
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; |
|
|
|
bi.lpfn = BrowseCallback; |
|
|
|
bi.lParam = (LPARAM)default_path; |
|
|
|
|
|
|
|
LPITEMIDLIST pidl = SHBrowseForFolder(&bi); |
|
|
|
|
|
|
|
if (pidl != 0) |
|
|
|
{ |
|
|
|
SHGetPathFromIDList(pidl, path); |
|
|
|
|
|
|
|
IMalloc* imalloc = NULL; |
|
|
|
if (SUCCEEDED(SHGetMalloc(&imalloc))) |
|
|
|
{ |
|
|
|
imalloc->Free(pidl); |
|
|
|
imalloc->Release(); |
|
|
|
} |
|
|
|
|
|
|
|
free(g_noc_file_dialog_ret); |
|
|
|
g_noc_file_dialog_ret = NULL; |
|
|
|
g_noc_file_dialog_ret = path ? strdup(path) : NULL; |
|
|
|
|
|
|
|
return g_noc_file_dialog_ret; |
|
|
|
} |
|
|
|
|
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
// Open File and Save File
|
|
|
|
{ |
|
|
|
char szFile[1024]; |
|
|
|
|
|
|
|
// init default file name
|
|
|
|
if (default_name) |
|
|
|
strncpy(szFile, default_name, sizeof(szFile) - 1); |
|
|
|
else |
|
|
|
szFile[0] = '\0'; |
|
|
|
|
|
|
|
OPENFILENAME ofn; // common dialog box structure
|
|
|
|
int ret; |
|
|
|
|
|
|
|
ZeroMemory(&ofn, sizeof(ofn)); |
|
|
|
ofn.lStructSize = sizeof(ofn); |
|
|
|
ofn.lpstrFile = szFile; |
|
|
|
ofn.nMaxFile = sizeof(szFile); |
|
|
|
ofn.lpstrFilter = filters; |
|
|
|
ofn.nFilterIndex = 1; |
|
|
|
ofn.lpstrFileTitle = NULL; |
|
|
|
ofn.nMaxFileTitle = 0; |
|
|
|
ofn.lpstrInitialDir = (LPSTR)default_path; |
|
|
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; |
|
|
|
|
|
|
|
if (flags & NOC_FILE_DIALOG_OPEN) |
|
|
|
{ |
|
|
|
ret = GetOpenFileName(&ofn); |
|
|
|
} |
|
|
|
else |
|
|
|
ret = GetSaveFileName(&ofn); |
|
|
|
|
|
|
|
free(g_noc_file_dialog_ret); |
|
|
|
g_noc_file_dialog_ret = ret ? strdup(szFile) : NULL; |
|
|
|
return g_noc_file_dialog_ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|