diff --git a/v2/internal/ffenestri/ffenestri.h b/v2/internal/ffenestri/ffenestri.h index 384218975..490bf9fb3 100644 --- a/v2/internal/ffenestri/ffenestri.h +++ b/v2/internal/ffenestri/ffenestri.h @@ -29,6 +29,6 @@ extern void Fullscreen(void *app); extern void UnFullscreen(void *app); extern void ToggleFullscreen(void *app); extern void DisableFrame(void *app); -extern void OpenDialog(void *appPointer, char *callbackID, char *title, char *filter); +extern void OpenDialog(void *appPointer, char *callbackID, char *title, char *filter, int allowFiles, int allowDirs ); #endif diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index 3297a491d..97e6eb00e 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -121,5 +121,11 @@ func (c *Client) WindowSetColour(colour int) { // OpenDialog will open a dialog with the given title and filter func (c *Client) OpenDialog(dialogOptions *options.OpenDialog, callbackID string) { - C.OpenDialog(c.app.app, c.app.string2CString(callbackID), c.app.string2CString(dialogOptions.Title), c.app.string2CString(dialogOptions.Filter)) + C.OpenDialog(c.app.app, + c.app.string2CString(callbackID), + c.app.string2CString(dialogOptions.Title), + c.app.string2CString(dialogOptions.Filter), + c.app.bool2Cint(dialogOptions.AllowFiles), + c.app.bool2Cint(dialogOptions.AllowDirectories), + ) } diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 2224e3959..5e40d8b9f 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -416,7 +416,7 @@ char* OpenFileDialog(struct Application *app, char *title, char *filter) { // OpenDialog opens a dialog to select files/directories // NOTE: The result is a string that will need to be freed! -void OpenDialog(struct Application *app, char* callbackID, char *title, char *filter) { +void OpenDialog(struct Application *app, char* callbackID, char *title, char *filter, int allowFiles, int allowDirs) { Debug("OpenDialog Called with callback id: %s", callbackID); // Create an open panel @@ -428,6 +428,9 @@ void OpenDialog(struct Application *app, char* callbackID, char *title, char *fi // No filters: [dialog setAllowsOtherFileTypes:YES]; // TODO: Other options + msg(dialog, s("setCanChooseFiles:"), allowFiles); + msg(dialog, s("setCanChooseDirectories:"), allowDirs); + msg(dialog, s("beginSheetModalForWindow:completionHandler:"), app->mainWindow, ^(id result) { JsonNode *response = json_mkarray(); @@ -451,7 +454,7 @@ void OpenDialog(struct Application *app, char* callbackID, char *title, char *fi free((void*)callback); free((void*)header); app->sendMessageToBackend(responseMessage); - free(responseMessage); + free((void*)responseMessage); }); msg( c("NSApp"), s("runModalForWindow:"), app->mainWindow); diff --git a/v2/test/runtime/runtime.go b/v2/test/runtime/runtime.go index ed4d972ef..faf7edfec 100644 --- a/v2/test/runtime/runtime.go +++ b/v2/test/runtime/runtime.go @@ -67,11 +67,33 @@ func (r *RuntimeTest) SetColour(colour int) { r.runtime.Window.SetColour(colour) } -// OpenDialog will call the Runtime.Dialog.OpenDirectory method +// OpenFileDialog will call the Runtime.Dialog.OpenDialog method requesting File selection +func (r *RuntimeTest) OpenFileDialog(title string, filter string) []string { + dialogOptions := &options.OpenDialog{ + Title: title, + Filter: filter, + AllowFiles: true, + } + return r.runtime.Dialog.Open(dialogOptions) +} + +// OpenDirectoryDialog will call the Runtime.Dialog.OpenDialog method requesting File selection +func (r *RuntimeTest) OpenDirectoryDialog(title string, filter string) []string { + dialogOptions := &options.OpenDialog{ + Title: title, + Filter: filter, + AllowDirectories: true, + } + return r.runtime.Dialog.Open(dialogOptions) +} + +// OpenDialog will call the Runtime.Dialog.OpenDialog method requesting both Files and Directories func (r *RuntimeTest) OpenDialog(title string, filter string) []string { dialogOptions := &options.OpenDialog{ - Title: title, - Filter: filter, + Title: title, + Filter: filter, + AllowDirectories: true, + AllowFiles: true, } return r.runtime.Dialog.Open(dialogOptions) }