mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-21 03:19:31 +08:00
Revert changes to v1
This commit is contained in:
parent
3b851e9a22
commit
02fd4ec477
@ -17,7 +17,9 @@ type Renderer interface {
|
||||
NotifyEvent(eventData *messages.EventData) error
|
||||
|
||||
// Dialog Runtime
|
||||
OpenDialog(title string, filter string) []string
|
||||
SelectFile(title string, filter string) string
|
||||
SelectDirectory() string
|
||||
SelectSaveFile(title string, filter string) string
|
||||
|
||||
// Window Runtime
|
||||
SetColour(string) error
|
||||
|
@ -119,10 +119,10 @@ func (h *Bridge) SelectFile(title string, filter string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// OpenDialog is unsupported for Bridge but required
|
||||
// SelectDirectory is unsupported for Bridge but required
|
||||
// for the Renderer interface
|
||||
func (h *Bridge) OpenDialog() string {
|
||||
h.log.Warn("OpenDialog() unsupported in bridge mode")
|
||||
func (h *Bridge) SelectDirectory() string {
|
||||
h.log.Warn("SelectDirectory() unsupported in bridge mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -263,9 +263,9 @@ func (w *WebView) SelectFile(title string, filter string) string {
|
||||
return result
|
||||
}
|
||||
|
||||
// OpenDialog opens a dialog that allows the user to select a directory
|
||||
func (w *WebView) OpenDialog() []string {
|
||||
var result []string
|
||||
// SelectDirectory opens a dialog that allows the user to select a directory
|
||||
func (w *WebView) SelectDirectory() 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,6 +281,24 @@ 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()
|
||||
|
@ -1,10 +1,7 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/lib/interfaces"
|
||||
)
|
||||
import "github.com/wailsapp/wails/lib/interfaces"
|
||||
import "strings"
|
||||
|
||||
// Dialog exposes an interface to native dialogs
|
||||
type Dialog struct {
|
||||
@ -31,9 +28,14 @@ func (r *Dialog) SelectFile(params ...string) string {
|
||||
return r.renderer.SelectFile(title, filter)
|
||||
}
|
||||
|
||||
// OpenDialog prompts the user to select a directory
|
||||
func (r *Dialog) OpenDialog(params ...string) []string {
|
||||
title := "Select File"
|
||||
// SelectDirectory prompts the user to select a directory
|
||||
func (r *Dialog) SelectDirectory() string {
|
||||
return r.renderer.SelectDirectory()
|
||||
}
|
||||
|
||||
// SelectSaveFile prompts the user to select a file for saving
|
||||
func (r *Dialog) SelectSaveFile(params ...string) string {
|
||||
title := "Select Save"
|
||||
filter := ""
|
||||
if len(params) > 0 {
|
||||
title = params[0]
|
||||
@ -41,5 +43,5 @@ func (r *Dialog) OpenDialog(params ...string) []string {
|
||||
if len(params) > 1 {
|
||||
filter = strings.Replace(params[1], " ", "", -1)
|
||||
}
|
||||
return r.renderer.OpenDialog(title, filter)
|
||||
return r.renderer.SelectSaveFile(title, filter)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user