diff --git a/redo/test/page5.c b/redo/test/page5.c index a703f523..761c0e2a 100644 --- a/redo/test/page5.c +++ b/redo/test/page5.c @@ -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 *page5; @@ -34,6 +47,7 @@ uiBox *makePage5(void) uiBoxAppend(page5, uiControl(hbox), 0); D("Open File", openFile); + D("Save File", saveFile); return page5; } diff --git a/redo/ui.idl b/redo/ui.idl index 74fde141..3abe76c6 100644 --- a/redo/ui.idl +++ b/redo/ui.idl @@ -206,5 +206,6 @@ interface MenuItem { }; func OpenFile(void) *char; +func SaveFile(void) *char; }; diff --git a/redo/windows/stddialogs.c b/redo/windows/stddialogs.c index e1ed95a5..88c6e540 100644 --- a/redo/windows/stddialogs.c +++ b/redo/windows/stddialogs.c @@ -39,3 +39,38 @@ char *uiOpenFile(void) endDialogHelper(dialogHelper); 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); +}