From f407c6acc8ee74e0df06d2c4a03fb9ac806f2db6 Mon Sep 17 00:00:00 2001 From: ddo Date: Mon, 8 Aug 2016 20:07:41 +0700 Subject: [PATCH 1/9] add #uiOpenFolder --- examples/controlgallery/main.c | 46 +++++++++++++++++++++++++++++++--- test/page5.c | 14 +++++++++++ ui.h | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/examples/controlgallery/main.c b/examples/controlgallery/main.c index c0d536c1..8c15d0c5 100644 --- a/examples/controlgallery/main.c +++ b/examples/controlgallery/main.c @@ -175,6 +175,20 @@ static void onOpenFileClicked(uiButton *b, void *data) uiFreeText(filename); } +static void onOpenFolderClicked(uiButton *b, void *data) +{ + uiEntry *entry = uiEntry(data); + char *filename; + + filename = uiOpenFolder(mainwin); + if (filename == NULL) { + uiEntrySetText(entry, "(cancelled)"); + return; + } + uiEntrySetText(entry, filename); + uiFreeText(filename); +} + static void onSaveFileClicked(uiButton *b, void *data) { uiEntry *entry = uiEntry(data); @@ -259,10 +273,10 @@ static uiControl *makeDataChoosersPage(void) 1, 0, 1, 1, 1, uiAlignFill, 0, uiAlignFill); - button = uiNewButton("Save File"); + button = uiNewButton("Open Folder"); entry = uiNewEntry(); uiEntrySetReadOnly(entry, 1); - uiButtonOnClicked(button, onSaveFileClicked, entry); + uiButtonOnClicked(button, onOpenFolderClicked, entry); uiGridAppend(grid, uiControl(button), 0, 1, 1, 1, 0, uiAlignFill, 0, uiAlignFill); @@ -270,10 +284,21 @@ static uiControl *makeDataChoosersPage(void) 1, 1, 1, 1, 1, uiAlignFill, 0, uiAlignFill); + button = uiNewButton("Save File"); + entry = uiNewEntry(); + uiEntrySetReadOnly(entry, 1); + uiButtonOnClicked(button, onSaveFileClicked, entry); + uiGridAppend(grid, uiControl(button), + 0, 2, 1, 1, + 0, uiAlignFill, 0, uiAlignFill); + uiGridAppend(grid, uiControl(entry), + 1, 2, 1, 1, + 1, uiAlignFill, 0, uiAlignFill); + msggrid = uiNewGrid(); uiGridSetPadded(msggrid, 1); uiGridAppend(grid, uiControl(msggrid), - 0, 2, 2, 1, + 0, 3, 2, 1, 0, uiAlignCenter, 0, uiAlignStart); button = uiNewButton("Message Box"); @@ -341,6 +366,19 @@ static void openClicked(uiMenuItem *item, uiWindow *w, void *data) uiFreeText(filename); } +static void openFolderClicked(uiMenuItem *item, uiWindow *w, void *data) +{ + char *filename; + + filename = uiOpenFolder(mainwin); + if (filename == NULL) { + uiMsgBoxError(mainwin, "No folder selected", "Don't be alarmed!"); + return; + } + uiMsgBox(mainwin, "Folder selected", filename); + uiFreeText(filename); +} + static void saveClicked(uiMenuItem *item, uiWindow *w, void *data) { char *filename; @@ -403,6 +441,8 @@ int main(void) menu = uiNewMenu("File"); item = uiMenuAppendItem(menu, "Open"); uiMenuItemOnClicked(item, openClicked, NULL); + item = uiMenuAppendItem(menu, "Open Folder"); + uiMenuItemOnClicked(item, openFolderClicked, NULL); item = uiMenuAppendItem(menu, "Save"); uiMenuItemOnClicked(item, saveClicked, NULL); item = uiMenuAppendQuitItem(menu); diff --git a/test/page5.c b/test/page5.c index 9bc1105a..b8741f9d 100644 --- a/test/page5.c +++ b/test/page5.c @@ -16,6 +16,19 @@ static void openFile(uiButton *b, void *data) } } +static void openFolder(uiButton *b, void *data) +{ + char *fn; + + fn = uiOpenFolder(parent); + if (fn == NULL) + uiLabelSetText(uiLabel(data), "(cancelled)"); + else { + uiLabelSetText(uiLabel(data), fn); + uiFreeText(fn); + } +} + static void saveFile(uiButton *b, void *data) { char *fn; @@ -74,6 +87,7 @@ uiBox *makePage5(uiWindow *pw) uiBoxAppend(page5, uiControl(hbox), 0); D("Open File", openFile); + D("Open Folder", openFolder); D("Save File", saveFile); title = uiNewEntry(); diff --git a/ui.h b/ui.h index 70c2f121..e8a4100f 100644 --- a/ui.h +++ b/ui.h @@ -270,6 +270,7 @@ _UI_EXTERN void uiMenuAppendSeparator(uiMenu *m); _UI_EXTERN uiMenu *uiNewMenu(const char *name); _UI_EXTERN char *uiOpenFile(uiWindow *parent); +_UI_EXTERN char *uiOpenFolder(uiWindow *parent); _UI_EXTERN char *uiSaveFile(uiWindow *parent); _UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description); _UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description); From 46af488c75ca6a81fc8c864c4fda52f821670b17 Mon Sep 17 00:00:00 2001 From: ddo Date: Mon, 8 Aug 2016 20:07:57 +0700 Subject: [PATCH 2/9] add unix#uiOpenFolder --- unix/stddialogs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unix/stddialogs.c b/unix/stddialogs.c index 93302f75..83f31408 100644 --- a/unix/stddialogs.c +++ b/unix/stddialogs.c @@ -38,6 +38,11 @@ char *uiOpenFile(uiWindow *parent) return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open"); } +char *uiOpenFolder(uiWindow *parent) +{ + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Open"); +} + char *uiSaveFile(uiWindow *parent) { return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save"); From 5796687da3484a351af4ddcd1608644363ad56f0 Mon Sep 17 00:00:00 2001 From: Ddo Date: Tue, 9 Aug 2016 03:59:36 +0700 Subject: [PATCH 3/9] add darwin#uiOpenFolder --- darwin/stddialogs.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/darwin/stddialogs.m b/darwin/stddialogs.m index 57ce9596..d4fe6993 100644 --- a/darwin/stddialogs.m +++ b/darwin/stddialogs.m @@ -46,6 +46,20 @@ char *uiOpenFile(uiWindow *parent) return runSavePanel(windowWindow(parent), o); } +char *uiOpenFolder(uiWindow *parent) +{ + NSOpenPanel *o; + + o = [NSOpenPanel openPanel]; + [o setCanChooseFiles:NO]; + [o setCanChooseDirectories:YES]; + [o setResolvesAliases:NO]; + [o setAllowsMultipleSelection:NO]; + setupSavePanel(o); + // panel is autoreleased + return runSavePanel(windowWindow(parent), o); +} + char *uiSaveFile(uiWindow *parent) { NSSavePanel *s; From d966861c0ce450b2a55f3e38ae19f67a815b2aba Mon Sep 17 00:00:00 2001 From: Ddo Date: Tue, 9 Aug 2016 04:03:55 +0700 Subject: [PATCH 4/9] add windows#uiOpenFolder --- windows/stddialogs.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/windows/stddialogs.cpp b/windows/stddialogs.cpp index 89d26bac..38f4c554 100644 --- a/windows/stddialogs.cpp +++ b/windows/stddialogs.cpp @@ -88,6 +88,18 @@ char *uiOpenFile(uiWindow *parent) return res; } +char *uiOpenFolder(uiWindow *parent) +{ + char *res; + + disableAllWindowsExcept(parent); + res = commonItemDialog(windowHWND(parent), + CLSID_FileOpenDialog, IID_IFileOpenDialog, + FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_PICKFOLDERS | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + enableAllWindowsExcept(parent); + return res; +} + char *uiSaveFile(uiWindow *parent) { char *res; From 2bcf87fbe4554a390b4b7fdb0cb0a3b7b9024424 Mon Sep 17 00:00:00 2001 From: ddo Date: Tue, 9 Aug 2016 14:14:24 +0700 Subject: [PATCH 5/9] add filename to #uiSaveFile --- examples/controlgallery/main.c | 4 ++-- test/page5.c | 2 +- ui.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/controlgallery/main.c b/examples/controlgallery/main.c index 8c15d0c5..25f87354 100644 --- a/examples/controlgallery/main.c +++ b/examples/controlgallery/main.c @@ -194,7 +194,7 @@ static void onSaveFileClicked(uiButton *b, void *data) uiEntry *entry = uiEntry(data); char *filename; - filename = uiSaveFile(mainwin); + filename = uiSaveFile(mainwin, "untitled"); if (filename == NULL) { uiEntrySetText(entry, "(cancelled)"); return; @@ -383,7 +383,7 @@ static void saveClicked(uiMenuItem *item, uiWindow *w, void *data) { char *filename; - filename = uiSaveFile(mainwin); + filename = uiSaveFile(mainwin, "untitled"); if (filename == NULL) { uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!"); return; diff --git a/test/page5.c b/test/page5.c index b8741f9d..98c955b7 100644 --- a/test/page5.c +++ b/test/page5.c @@ -33,7 +33,7 @@ static void saveFile(uiButton *b, void *data) { char *fn; - fn = uiSaveFile(parent); + fn = uiSaveFile(parent, "untitled"); if (fn == NULL) uiLabelSetText(uiLabel(data), "(cancelled)"); else { diff --git a/ui.h b/ui.h index e8a4100f..cd48cd59 100644 --- a/ui.h +++ b/ui.h @@ -271,7 +271,7 @@ _UI_EXTERN uiMenu *uiNewMenu(const char *name); _UI_EXTERN char *uiOpenFile(uiWindow *parent); _UI_EXTERN char *uiOpenFolder(uiWindow *parent); -_UI_EXTERN char *uiSaveFile(uiWindow *parent); +_UI_EXTERN char *uiSaveFile(uiWindow *parent, const char *filename); _UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description); _UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description); From 72e831b00e0b541f515deec2221e6ff1ab6c3368 Mon Sep 17 00:00:00 2001 From: ddo Date: Tue, 9 Aug 2016 14:14:50 +0700 Subject: [PATCH 6/9] add filename to unix#uiSaveFile --- unix/stddialogs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/unix/stddialogs.c b/unix/stddialogs.c index 83f31408..2d599e56 100644 --- a/unix/stddialogs.c +++ b/unix/stddialogs.c @@ -6,7 +6,7 @@ #define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w)))) -static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm) +static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, const char *defaultFilename) { GtkWidget *fcd; GtkFileChooser *fc; @@ -23,6 +23,9 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha gtk_file_chooser_set_show_hidden(fc, TRUE); gtk_file_chooser_set_do_overwrite_confirmation(fc, TRUE); gtk_file_chooser_set_create_folders(fc, TRUE); + if (defaultFilename != NULL) { + gtk_file_chooser_set_current_name(fc, defaultFilename); + } response = gtk_dialog_run(GTK_DIALOG(fcd)); if (response != GTK_RESPONSE_ACCEPT) { gtk_widget_destroy(fcd); @@ -35,17 +38,17 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha char *uiOpenFile(uiWindow *parent) { - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open"); + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", NULL); } char *uiOpenFolder(uiWindow *parent) { - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Open"); + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Open", NULL); } -char *uiSaveFile(uiWindow *parent) +char *uiSaveFile(uiWindow *parent, const char *filename) { - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save"); + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", filename); } static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons) From 58c8a61817d36632a9bd1358c6113758772fd89e Mon Sep 17 00:00:00 2001 From: ddo Date: Thu, 11 Aug 2016 17:04:08 +0700 Subject: [PATCH 7/9] add uiWindowSetTopmost --- ui.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ui.h b/ui.h index cd48cd59..28319b2c 100644 --- a/ui.h +++ b/ui.h @@ -115,6 +115,7 @@ _UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless); _UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child); _UI_EXTERN int uiWindowMargined(uiWindow *w); _UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined); +_UI_EXTERN void uiWindowSetTopmost(uiWindow *w, int topmost); _UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar); typedef struct uiButton uiButton; From 59174128928d9ea67b24f249cde333446b0202a2 Mon Sep 17 00:00:00 2001 From: ddo Date: Thu, 11 Aug 2016 17:04:54 +0700 Subject: [PATCH 8/9] add unix#uiWindowSetTopmost --- unix/window.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unix/window.c b/unix/window.c index a1d09005..b19024bf 100644 --- a/unix/window.c +++ b/unix/window.c @@ -279,6 +279,11 @@ void uiWindowSetMargined(uiWindow *w, int margined) setMargined(w->childHolderContainer, w->margined); } +void uiWindowSetTopmost(uiWindow *w, int topmost) +{ + gtk_window_set_keep_above(w->window, topmost == 1); +} + uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) { uiWindow *w; From 94bd5da38b5a7647d0f4dc489ed68f9fbeb7824a Mon Sep 17 00:00:00 2001 From: ddo Date: Thu, 11 Aug 2016 17:07:52 +0700 Subject: [PATCH 9/9] add filename to windows#uiSaveFile --- windows/stddialogs.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/windows/stddialogs.cpp b/windows/stddialogs.cpp index 38f4c554..6c6a8354 100644 --- a/windows/stddialogs.cpp +++ b/windows/stddialogs.cpp @@ -16,7 +16,7 @@ #define windowHWND(w) ((HWND) uiControlHandle(uiControl(w))) -char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd) +char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd, const char *filename) { IFileDialog *d = NULL; FILEOPENDIALOGOPTIONS opts; @@ -33,6 +33,19 @@ char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOP // always return NULL on error goto out; } + + // file name + if (filename != NULL) { + size_t size = strlen(filename) + 1; + wchar_t* filenameWchar = new wchar_t[size]; + + size_t outSize; + mbstowcs_s(&outSize, filenameWchar, size, filename, size - 1); + + LPCWSTR filenameLPCWSTR = filenameWchar; + d->SetFileName(filenameLPCWSTR); + } + hr = d->GetOptions(&opts); if (hr != S_OK) { logHRESULT(L"error getting current options", hr); @@ -83,7 +96,7 @@ char *uiOpenFile(uiWindow *parent) disableAllWindowsExcept(parent); res = commonItemDialog(windowHWND(parent), CLSID_FileOpenDialog, IID_IFileOpenDialog, - FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, NULL); enableAllWindowsExcept(parent); return res; } @@ -95,19 +108,19 @@ char *uiOpenFolder(uiWindow *parent) disableAllWindowsExcept(parent); res = commonItemDialog(windowHWND(parent), CLSID_FileOpenDialog, IID_IFileOpenDialog, - FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_PICKFOLDERS | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_PICKFOLDERS | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, NULL); enableAllWindowsExcept(parent); return res; } -char *uiSaveFile(uiWindow *parent) +char *uiSaveFile(uiWindow *parent, const char *filename) { char *res; disableAllWindowsExcept(parent); res = commonItemDialog(windowHWND(parent), CLSID_FileSaveDialog, IID_IFileSaveDialog, - FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE, filename); enableAllWindowsExcept(parent); return res; }