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
|
// 22 may 2015
|
||||||
#include "uipriv_windows.h"
|
#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
|
char *commonItemDialog(REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
|
||||||
#define NFILENAME 4096
|
|
||||||
|
|
||||||
// TODO not in MinGW-w64?
|
|
||||||
// TODO IFileSaveDialog only?
|
|
||||||
#define FOS_SUPPORTSTREAMABLEITEMS 0x80000000
|
|
||||||
|
|
||||||
char *uiOpenFile(void)
|
|
||||||
{
|
{
|
||||||
IFileOpenDialog *d;
|
IFileDialog *d;
|
||||||
FILEOPENDIALOGOPTIONS opts;
|
FILEOPENDIALOGOPTIONS opts;
|
||||||
HWND dialogHelper;
|
HWND dialogHelper;
|
||||||
IShellItem *result;
|
IShellItem *result;
|
||||||
|
@ -20,71 +13,51 @@ char *uiOpenFile(void)
|
||||||
char *name;
|
char *name;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
hr = CoCreateInstance(&CLSID_FileOpenDialog,
|
hr = CoCreateInstance(clsid,
|
||||||
NULL, CLSCTX_INPROC_SERVER,
|
NULL, CLSCTX_INPROC_SERVER,
|
||||||
&IID_IFileOpenDialog, (LPVOID *) (&d));
|
iid, (LPVOID *) (&d));
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error creating common item dialog in uiOpenFile()", hr);
|
logHRESULT("error creating common item dialog in commonItemDialog()", hr);
|
||||||
hr = IFileOpenDialog_GetOptions(d, &opts);
|
hr = IFileDialog_GetOptions(d, &opts);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error getting current options in uiOpenFile()", hr);
|
logHRESULT("error getting current options in commonItemDialog()", hr);
|
||||||
opts |= FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE;
|
opts |= optsadd;
|
||||||
hr = IFileOpenDialog_SetOptions(d, opts);
|
hr = IFileDialog_SetOptions(d, opts);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error setting options in uiOpenFile()", hr);
|
logHRESULT("error setting options in commonItemDialog()", hr);
|
||||||
dialogHelper = beginDialogHelper();
|
dialogHelper = beginDialogHelper();
|
||||||
hr = IFileOpenDialog_Show(d, dialogHelper);
|
hr = IFileDialog_Show(d, dialogHelper);
|
||||||
endDialogHelper(dialogHelper);
|
endDialogHelper(dialogHelper);
|
||||||
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
|
||||||
IFileOpenDialog_Release(d);
|
IFileDialog_Release(d);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error showing dialog in uiOpenFile()", hr);
|
logHRESULT("error showing dialog in commonItemDialog()", hr);
|
||||||
hr = IFileOpenDialog_GetResult(d, &result);
|
hr = IFileDialog_GetResult(d, &result);
|
||||||
if (hr != S_OK)
|
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);
|
hr = IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &wname);
|
||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
logHRESULT("error getting filename in uiOpenFile()", hr);
|
logHRESULT("error getting filename in commonItemDialog()", hr);
|
||||||
name = toUTF8(wname);
|
name = toUTF8(wname);
|
||||||
CoTaskMemFree(wname);
|
CoTaskMemFree(wname);
|
||||||
IShellItem_Release(result);
|
IShellItem_Release(result);
|
||||||
IFileOpenDialog_Release(d);
|
IFileDialog_Release(d);
|
||||||
return name;
|
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)
|
char *uiSaveFile(void)
|
||||||
{
|
{
|
||||||
WCHAR wfilename[NFILENAME];
|
return commonItemDialog(&CLSID_FileSaveDialog, &IID_IFileSaveDialog,
|
||||||
OPENFILENAMEW ofn;
|
// TODO strip FOS_NOREADONLYRETURN?
|
||||||
HWND dialogHelper;
|
FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO MinGW-w64 3.x doesn't support task dialogs
|
// TODO MinGW-w64 3.x doesn't support task dialogs
|
||||||
|
|
Loading…
Reference in New Issue