mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-20 02:49:30 +08:00
Remove old dialog code
This commit is contained in:
parent
9b0f58ddf5
commit
5ce5e129cf
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 ""
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user