diff --git a/v2/internal/ffenestri/ffenestri.h b/v2/internal/ffenestri/ffenestri.h index 139d5d3fb..c7f13ff0f 100644 --- a/v2/internal/ffenestri/ffenestri.h +++ b/v2/internal/ffenestri/ffenestri.h @@ -29,5 +29,5 @@ 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, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolveAliases, int treatPackagesAsDirectories); +extern void OpenDialog(void *appPointer, char *callbackID, char *title, char *filter, char *defaultDir, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolveAliases, int treatPackagesAsDirectories); #endif diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index 5770157e7..1ecc01e48 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -125,6 +125,7 @@ func (c *Client) OpenDialog(dialogOptions *options.OpenDialog, callbackID string c.app.string2CString(callbackID), c.app.string2CString(dialogOptions.Title), c.app.string2CString(dialogOptions.Filter), + c.app.string2CString(dialogOptions.DefaultDirectory), c.app.bool2Cint(dialogOptions.AllowFiles), c.app.bool2Cint(dialogOptions.AllowDirectories), c.app.bool2Cint(dialogOptions.AllowMultiple), diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 1d10ebe74..ad72e08a5 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -13,6 +13,7 @@ #define s(str) sel_registerName(str) #define u(str) sel_getUid(str) #define str(input) msg(c("NSString"), s("stringWithUTF8String:"), input) +#define url(input) msg(c("NSURL"), s("fileURLWithPath:"), str(input)) #define GET_FRAME(receiver) ((CGRect(*)(id, SEL))objc_msgSend_stret)(receiver, s("frame")); @@ -416,7 +417,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, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolveAliases, int treatPackagesAsDirectories) { +void OpenDialog(struct Application *app, char *callbackID, char *title, char *filter, char *defaultDir, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolveAliases, int treatPackagesAsDirectories) { Debug("OpenDialog Called with callback id: %s", callbackID); // Create an open panel @@ -439,6 +440,16 @@ void OpenDialog(struct Application *app, char *callbackID, char *title, char *fi msg(dialog, s("setAllowsOtherFileTypes:"), YES); } + // Default Directory + if( defaultDir != NULL && strlen(defaultDir) > 0 ) { + msg(dialog, s("setDirectoryURL:"), url(defaultDir)); + } + + // Default Filename + // if( defaultFilename != NULL && strlen(defaultFilename) > 0 ) { + // msg(dialog, s("setNameFieldStringValue:"), str(defaultFilename)); + // } + // Setup Options msg(dialog, s("setCanChooseFiles:"), allowFiles); msg(dialog, s("setCanChooseDirectories:"), allowDirs); diff --git a/v2/pkg/options/dialog.go b/v2/pkg/options/dialog.go index 3637b1303..8f7234ba1 100644 --- a/v2/pkg/options/dialog.go +++ b/v2/pkg/options/dialog.go @@ -2,6 +2,8 @@ package options // OpenDialog contains the options for the OpenDialog runtime method type OpenDialog struct { + DefaultDirectory string + DefaultFilename string Title string Filter string AllowFiles bool diff --git a/v2/test/runtime/runtime.go b/v2/test/runtime/runtime.go index ed24fc3e9..f0db9b88c 100644 --- a/v2/test/runtime/runtime.go +++ b/v2/test/runtime/runtime.go @@ -111,8 +111,10 @@ func (r *RuntimeTest) OpenDialogMultiple(title string, filter string) []string { } // OpenDialogAllOptions will call the Runtime.Dialog.OpenDialog method allowing multiple selection -func (r *RuntimeTest) OpenDialogAllOptions(filter string) []string { +func (r *RuntimeTest) OpenDialogAllOptions(filter string, defaultDir string, defaultFilename string) []string { dialogOptions := &options.OpenDialog{ + DefaultDirectory: defaultDir, + DefaultFilename: defaultFilename, Filter: filter, AllowFiles: true, AllowDirectories: true,