Added a save file dialog.
This commit is contained in:
parent
ded1bf05de
commit
13a4e3f4e5
|
@ -14,6 +14,19 @@ static void openFile(uiButton *b, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void saveFile(uiButton *b, void *data)
|
||||||
|
{
|
||||||
|
char *fn;
|
||||||
|
|
||||||
|
fn = uiSaveFile();
|
||||||
|
if (fn == NULL)
|
||||||
|
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||||
|
else {
|
||||||
|
uiLabelSetText(uiLabel(data), fn);
|
||||||
|
uiFreeText(fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uiBox *makePage5(void)
|
uiBox *makePage5(void)
|
||||||
{
|
{
|
||||||
uiBox *page5;
|
uiBox *page5;
|
||||||
|
@ -34,6 +47,7 @@ uiBox *makePage5(void)
|
||||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||||
|
|
||||||
D("Open File", openFile);
|
D("Open File", openFile);
|
||||||
|
D("Save File", saveFile);
|
||||||
|
|
||||||
return page5;
|
return page5;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,5 +206,6 @@ interface MenuItem {
|
||||||
};
|
};
|
||||||
|
|
||||||
func OpenFile(void) *char;
|
func OpenFile(void) *char;
|
||||||
|
func SaveFile(void) *char;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,3 +39,38 @@ char *uiOpenFile(void)
|
||||||
endDialogHelper(dialogHelper);
|
endDialogHelper(dialogHelper);
|
||||||
return toUTF8(wfilename);
|
return toUTF8(wfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_SHAREAWARE?
|
||||||
|
// better question: TODO keep networking?
|
||||||
|
// TODO OFN_PATHMUSTEXIST?
|
||||||
|
ofn.Flags = OFN_EXPLORER | OFN_FORCESHOWHIDDEN | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_NOCHANGEDIR | OFN_NODEREFERENCELINKS | OFN_NOTESTFILECREATE | OFN_OVERWRITEPROMPT;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue