Converted the save file dialog to the Common Item Dialog system and resolved a few TODOs.
This commit is contained in:
parent
a8ddd7f94f
commit
afb7c773fe
|
@ -1,18 +1,11 @@
|
|||
// 22 may 2015
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
// TODO when making Vista-only, use common item dialog
|
||||
// note: FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use
|
||||
|
||||
// this should be reasonable
|
||||
#define NFILENAME 4096
|
||||
|
||||
// TODO not in MinGW-w64?
|
||||
// TODO IFileSaveDialog only?
|
||||
#define FOS_SUPPORTSTREAMABLEITEMS 0x80000000
|
||||
|
||||
char *uiOpenFile(void)
|
||||
char *commonItemDialog(REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
||||
{
|
||||
IFileOpenDialog *d;
|
||||
IFileDialog *d;
|
||||
FILEOPENDIALOGOPTIONS opts;
|
||||
HWND dialogHelper;
|
||||
IShellItem *result;
|
||||
|
@ -20,71 +13,51 @@ char *uiOpenFile(void)
|
|||
char *name;
|
||||
HRESULT hr;
|
||||
|
||||
hr = CoCreateInstance(&CLSID_FileOpenDialog,
|
||||
hr = CoCreateInstance(clsid,
|
||||
NULL, CLSCTX_INPROC_SERVER,
|
||||
&IID_IFileOpenDialog, (LPVOID *) (&d));
|
||||
iid, (LPVOID *) (&d));
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error creating common item dialog in uiOpenFile()", hr);
|
||||
hr = IFileOpenDialog_GetOptions(d, &opts);
|
||||
logHRESULT("error creating common item dialog in commonItemDialog()", hr);
|
||||
hr = IFileDialog_GetOptions(d, &opts);
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error getting current options in uiOpenFile()", hr);
|
||||
opts |= FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE;
|
||||
hr = IFileOpenDialog_SetOptions(d, opts);
|
||||
logHRESULT("error getting current options in commonItemDialog()", hr);
|
||||
opts |= optsadd;
|
||||
hr = IFileDialog_SetOptions(d, opts);
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error setting options in uiOpenFile()", hr);
|
||||
logHRESULT("error setting options in commonItemDialog()", hr);
|
||||
dialogHelper = beginDialogHelper();
|
||||
hr = IFileOpenDialog_Show(d, dialogHelper);
|
||||
hr = IFileDialog_Show(d, dialogHelper);
|
||||
endDialogHelper(dialogHelper);
|
||||
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||
IFileOpenDialog_Release(d);
|
||||
IFileDialog_Release(d);
|
||||
return NULL;
|
||||
}
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error showing dialog in uiOpenFile()", hr);
|
||||
hr = IFileOpenDialog_GetResult(d, &result);
|
||||
logHRESULT("error showing dialog in commonItemDialog()", hr);
|
||||
hr = IFileDialog_GetResult(d, &result);
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error getting dialog result in uiOpenFile()", hr);
|
||||
logHRESULT("error getting dialog result in commonItemDialog()", hr);
|
||||
hr = IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &wname);
|
||||
if (hr != S_OK)
|
||||
logHRESULT("error getting filename in uiOpenFile()", hr);
|
||||
logHRESULT("error getting filename in commonItemDialog()", hr);
|
||||
name = toUTF8(wname);
|
||||
CoTaskMemFree(wname);
|
||||
IShellItem_Release(result);
|
||||
IFileOpenDialog_Release(d);
|
||||
IFileDialog_Release(d);
|
||||
return name;
|
||||
}
|
||||
|
||||
char *uiOpenFile(void)
|
||||
{
|
||||
return commonItemDialog(&CLSID_FileOpenDialog, &IID_IFileOpenDialog,
|
||||
FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||
}
|
||||
|
||||
char *uiSaveFile(void)
|
||||
{
|
||||
WCHAR wfilename[NFILENAME];
|
||||
OPENFILENAMEW ofn;
|
||||
HWND dialogHelper;
|
||||
DWORD err;
|
||||
|
||||
dialogHelper = beginDialogHelper();
|
||||
wfilename[0] = L'\0'; // required by GetOpenFileName() to indicate no previous filename
|
||||
ZeroMemory(&ofn, sizeof (OPENFILENAMEW));
|
||||
ofn.lStructSize = sizeof (OPENFILENAMEW);
|
||||
ofn.hwndOwner = dialogHelper;
|
||||
ofn.hInstance = hInstance;
|
||||
ofn.lpstrFilter = NULL; // no filters
|
||||
ofn.lpstrFile = wfilename;
|
||||
ofn.nMaxFile = NFILENAME; // seems to include null terminator according to docs
|
||||
ofn.lpstrInitialDir = NULL; // let system decide
|
||||
ofn.lpstrTitle = NULL; // let system decide
|
||||
// TODO OFN_PATHMUSTEXIST?
|
||||
ofn.Flags = OFN_EXPLORER | OFN_FORCESHOWHIDDEN | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT | OFN_SHAREAWARE;
|
||||
if (GetSaveFileNameW(&ofn) == FALSE) {
|
||||
err = CommDlgExtendedError();
|
||||
if (err != 0)
|
||||
// TODO
|
||||
complain("error running open file dialog", err);
|
||||
// otherwise user cancelled
|
||||
endDialogHelper(dialogHelper);
|
||||
return NULL;
|
||||
}
|
||||
endDialogHelper(dialogHelper);
|
||||
return toUTF8(wfilename);
|
||||
return commonItemDialog(&CLSID_FileSaveDialog, &IID_IFileSaveDialog,
|
||||
// TODO strip FOS_NOREADONLYRETURN?
|
||||
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||
}
|
||||
|
||||
// TODO MinGW-w64 3.x doesn't support task dialogs
|
||||
|
|
Loading…
Reference in New Issue