From 5ce5e129cf239063273f0ea7bff51a56e10e1709 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 26 Sep 2020 16:16:25 +1000 Subject: [PATCH] Remove old dialog code --- lib/interfaces/renderer.go | 4 +- lib/renderer/webview.go | 20 +----- lib/renderer/webview/webview.go | 2 +- runtime/dialog.go | 11 +--- v2/internal/ffenestri/ffenestri.h | 2 - v2/internal/ffenestri/ffenestri_client.go | 38 ----------- v2/internal/ffenestri/ffenestri_darwin.c | 18 ----- .../messagedispatcher/dispatchclient.go | 2 - v2/internal/runtime/goruntime/dialog.go | 66 ------------------- v2/internal/webserver/websockets.go | 14 +--- v2/test/runtime/runtime.go | 10 --- 11 files changed, 8 insertions(+), 179 deletions(-) diff --git a/lib/interfaces/renderer.go b/lib/interfaces/renderer.go index 88744da5a..97c4959f1 100644 --- a/lib/interfaces/renderer.go +++ b/lib/interfaces/renderer.go @@ -17,9 +17,7 @@ type Renderer interface { NotifyEvent(eventData *messages.EventData) error // Dialog Runtime - SelectFile(title string, filter string) string - OpenDialog() []string - SelectSaveFile(title string, filter string) string + OpenDialog(title string, filter string) []string // Window Runtime SetColour(string) error diff --git a/lib/renderer/webview.go b/lib/renderer/webview.go index 36c4396ea..7b47b492e 100644 --- a/lib/renderer/webview.go +++ b/lib/renderer/webview.go @@ -265,7 +265,7 @@ func (w *WebView) SelectFile(title string, filter string) string { // OpenDialog opens a dialog that allows the user to select a directory func (w *WebView) OpenDialog() []string { - var result string + var result []string // We need to run this on the main thread, however Dispatch is // non-blocking so we launch this in a goroutine and wait for // dispatch to finish before returning the result @@ -281,24 +281,6 @@ func (w *WebView) OpenDialog() []string { return result } -// SelectSaveFile opens a dialog that allows the user to select a file to save -func (w *WebView) SelectSaveFile(title string, filter string) string { - var result string - // We need to run this on the main thread, however Dispatch is - // non-blocking so we launch this in a goroutine and wait for - // dispatch to finish before returning the result - var wg sync.WaitGroup - wg.Add(1) - go func() { - w.window.Dispatch(func() { - result = w.window.Dialog(wv.DialogTypeSave, 0, title, "", filter) - wg.Done() - }) - }() - wg.Wait() - return result -} - // callback sends a callback to the frontend func (w *WebView) callback(data string) error { callbackCMD := fmt.Sprintf("window.wails._.Callback('%s');", data) diff --git a/lib/renderer/webview/webview.go b/lib/renderer/webview/webview.go index f8ac2b706..c6eadfd73 100755 --- a/lib/renderer/webview/webview.go +++ b/lib/renderer/webview/webview.go @@ -186,7 +186,7 @@ type WebView interface { // Dialog() opens a system dialog of the given type and title. String // argument can be provided for certain dialogs, such as alert boxes. For // alert boxes argument is a message inside the dialog box. - Dialog(dlgType DialogType, flags int, title string, arg string, filter string) string + Dialog(dlgType DialogType, flags int, title string, arg string, filter string) []string // Terminate() breaks the main UI loop. This method must be called from the main thread // only. See Dispatch() for more details. Terminate() diff --git a/runtime/dialog.go b/runtime/dialog.go index a5f42cac7..440b9cdb8 100644 --- a/runtime/dialog.go +++ b/runtime/dialog.go @@ -32,13 +32,8 @@ func (r *Dialog) SelectFile(params ...string) string { } // OpenDialog prompts the user to select a directory -func (r *Dialog) OpenDialog() []string { - return r.renderer.OpenDialog() -} - -// SelectSaveFile prompts the user to select a file for saving -func (r *Dialog) SelectSaveFile(params ...string) string { - title := "Select Save" +func (r *Dialog) OpenDialog(params ...string) []string { + title := "Select File" filter := "" if len(params) > 0 { title = params[0] @@ -46,5 +41,5 @@ func (r *Dialog) SelectSaveFile(params ...string) string { if len(params) > 1 { filter = strings.Replace(params[1], " ", "", -1) } - return r.renderer.SelectSaveFile(title, filter) + return r.renderer.OpenDialog(title, filter) } diff --git a/v2/internal/ffenestri/ffenestri.h b/v2/internal/ffenestri/ffenestri.h index fff6da947..684b22f2e 100644 --- a/v2/internal/ffenestri/ffenestri.h +++ b/v2/internal/ffenestri/ffenestri.h @@ -29,8 +29,6 @@ extern void Fullscreen(void *app); extern void UnFullscreen(void *app); extern void ToggleFullscreen(void *app); extern void DisableFrame(void *app); -extern char *SaveFileDialog(void *appPointer, char *title, char *filter); extern char *OpenDialog(void *appPointer, char *title, char *filter); -extern char *OpenDirectoryDialog(void *appPointer, char *title, char *filter); #endif diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index da1a81b98..98a3ea23a 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -122,44 +122,6 @@ func (c *Client) WindowSetColour(colour int) { C.SetColour(c.app.app, r, g, b, a) } -// // OpenFileDialog will open a file dialog with the given title -// func (c *Client) OpenFileDialog(title string, filter string) []string { -// var result []string - -// cstring := C.OpenFileDialog(c.app.app, c.app.string2CString(title), c.app.string2CString(filter)) -// if cstring == nil { -// return result -// } - -// json := C.GoString(cstring) -// // Free the C string that was allocated by the dialog -// C.free(unsafe.Pointer(cstring)) - -// // Unmarshal the json -// err := json.Unmarshal([]byte(json), &result) -// if err != nil { -// // ??? -// log.Fatal(err) -// } - -// fmt.Printf("result = %+v\n", result) - -// return result -// } - -// // SaveFileDialog will open a save file dialog with the given title -// func (c *Client) SaveFileDialog(title string, filter string) string { - -// cstring := C.SaveFileDialog(c.app.app, c.app.string2CString(title), c.app.string2CString(filter)) -// var result string -// if cstring != nil { -// result = C.GoString(cstring) -// // Free the C string that was allocated by the dialog -// C.free(unsafe.Pointer(cstring)) -// } -// return result -// } - // OpenDialog will open a dialog with the given title and filter func (c *Client) OpenDialog(title string, filter string) []string { diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 218f91f71..6354d30c3 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -414,14 +414,6 @@ char* OpenFileDialog(struct Application *app, char *title, char *filter) { return filename; } -// SaveFileDialog opens a dialog to select a file -// NOTE: The result is a string that will need to be freed! -char* SaveFileDialog(void *appPointer, char *title, char *filter) { - Debug("SaveFileDialog Called"); - char *filename = concat("","BogusSaveFilename"); - return filename; -} - // OpenDialog opens a dialog to select files/directories // NOTE: The result is a string that will need to be freed! char* OpenDialog(void *appPointer, char *title, char *filter) { @@ -512,16 +504,6 @@ char* OpenFileDialogOnMainThread(void *app, char *title) { return "OpenFileDialogOnMainThread result"; } -char* SaveFileDialogOnMainThread(void *app, char *title) { - Debug("SaveFileDialogOnMainThread Called"); - return "SaveFileDialogOnMainThread result"; -} - -char* OpenDirectoryDialogOnMainThread(void *app, char *title) { - Debug("OpenDirectoryDialogOnMainThread Called"); - return "OpenDirectoryDialogOnMainThread result"; -} - // // Sets the icon to the XPM stored in icon // void setIcon( struct Application *app) { // GdkPixbuf *appIcon = gdk_pixbuf_new_from_xpm_data ((const char**)icon); diff --git a/v2/internal/messagedispatcher/dispatchclient.go b/v2/internal/messagedispatcher/dispatchclient.go index 0f7854bcd..4f6ae8860 100644 --- a/v2/internal/messagedispatcher/dispatchclient.go +++ b/v2/internal/messagedispatcher/dispatchclient.go @@ -13,9 +13,7 @@ type Client interface { Quit() NotifyEvent(message string) CallResult(message string) - // SaveFileDialog(title string, filter string) []string OpenDialog(title string, filter string) []string - // OpenDirectoryDialog(title string, filter string) string WindowSetTitle(title string) WindowShow() WindowHide() diff --git a/v2/internal/runtime/goruntime/dialog.go b/v2/internal/runtime/goruntime/dialog.go index 20d017c8e..75b23fc6f 100644 --- a/v2/internal/runtime/goruntime/dialog.go +++ b/v2/internal/runtime/goruntime/dialog.go @@ -9,8 +9,6 @@ import ( // Dialog defines all Dialog related operations type Dialog interface { - SaveFile(params ...string) string - SelectFile(params ...string) string OpenDialog(params ...string) []string } @@ -43,70 +41,6 @@ func (r *dialog) processTitleAndFilter(params ...string) (string, string) { return title, filter } -// SelectFile prompts the user to select a file -func (r *dialog) SelectFile(params ...string) string { - - // Extract title + filter - title, filter := r.processTitleAndFilter(params...) - - // Create unique dialog callback - uniqueCallback := crypto.RandomID() - - // Subscribe to the respose channel - responseTopic := "dialog:fileselected:" + uniqueCallback - dialogResponseChannel, err := r.bus.Subscribe(responseTopic) - if err != nil { - fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error()) - } - - // Publish dialog request - message := "dialog:select:file:" + title - if filter != "" { - message += ":" + filter - } - r.bus.Publish(message, responseTopic) - - // Wait for result - result := <-dialogResponseChannel - - // Delete subscription to response topic - r.bus.UnSubscribe(responseTopic) - - return result.Data().(string) -} - -// SaveFile prompts the user to select a file to save to -func (r *dialog) SaveFile(params ...string) string { - - // Extract title + filter - title, filter := r.processTitleAndFilter(params...) - - // Create unique dialog callback - uniqueCallback := crypto.RandomID() - - // Subscribe to the respose channel - responseTopic := "dialog:filesaveselected:" + uniqueCallback - dialogResponseChannel, err := r.bus.Subscribe(responseTopic) - if err != nil { - fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error()) - } - - // Publish dialog request - message := "dialog:select:filesave:" + title - if filter != "" { - message += ":" + filter - } - r.bus.Publish(message, responseTopic) - - // Wait for result - result := <-dialogResponseChannel - - // Delete subscription to response topic - r.bus.UnSubscribe(responseTopic) - - return result.Data().(string) -} - // OpenDialog prompts the user to select a file func (r *dialog) OpenDialog(params ...string) []string { diff --git a/v2/internal/webserver/websockets.go b/v2/internal/webserver/websockets.go index bb221a2b2..0fdc207ad 100644 --- a/v2/internal/webserver/websockets.go +++ b/v2/internal/webserver/websockets.go @@ -34,18 +34,8 @@ func (wc *WebClient) CallResult(message string) { wc.SendMessage("R" + message) } -// SaveFileDialog is a noop in the webclient -func (wc *WebClient) SaveFileDialog(title string) string { - return "" -} - -// OpenFileDialog is a noop in the webclient -func (wc *WebClient) OpenFileDialog(title string) string { - return "" -} - -// OpenDirectoryDialog is a noop in the webclient -func (wc *WebClient) OpenDirectoryDialog(title string) string { +// OpenDialog is a noop in the webclient +func (wc *WebClient) OpenDialog(title string) string { return "" } diff --git a/v2/test/runtime/runtime.go b/v2/test/runtime/runtime.go index bfc40d16d..9062e41a8 100644 --- a/v2/test/runtime/runtime.go +++ b/v2/test/runtime/runtime.go @@ -66,16 +66,6 @@ func (r *RuntimeTest) SetColour(colour int) { r.runtime.Window.SetColour(colour) } -// SelectFile will call the Runtime.Dialog.OpenFile method -func (r *RuntimeTest) SelectFile(title string, filter string) string { - return r.runtime.Dialog.SelectFile(title, filter) -} - -// SaveFile will call the Runtime.Dialog.SaveFile method -func (r *RuntimeTest) SaveFile(title string, filter string) string { - return r.runtime.Dialog.SaveFile(title, filter) -} - // OpenDialog will call the Runtime.Dialog.OpenDirectory method func (r *RuntimeTest) OpenDialog(title string, filter string) []string { return r.runtime.Dialog.OpenDialog(title, filter)