Files

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

2019-10-08 06:12:08 +11:00
package runtime
import "github.com/wailsapp/wails/lib/interfaces"
2020-06-18 10:12:47 +09:00
import "strings"
2019-10-08 06:12:08 +11:00
// Dialog exposes an interface to native dialogs
type Dialog struct {
renderer interfaces.Renderer
}
// NewDialog creates a new Dialog struct
func NewDialog(renderer interfaces.Renderer) *Dialog {
return &Dialog{
renderer: renderer,
}
}
// SelectFile prompts the user to select a file
func (r *Dialog) SelectFile(params ...string) string {
2020-06-17 19:09:09 +09:00
title := "Select File"
filter := ""
if len(params) > 0 {
2020-06-17 19:09:09 +09:00
title = params[0]
}
2020-06-17 19:09:09 +09:00
if len(params) > 1 {
2020-06-18 10:12:47 +09:00
filter = strings.Replace(params[1], " ", "", -1)
2020-06-17 19:09:09 +09:00
}
return r.renderer.SelectFile(title, filter)
2019-10-08 06:12:08 +11:00
}
// 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 {
2020-06-17 19:09:09 +09:00
title := "Select Save"
filter := ""
if len(params) > 0 {
2020-06-17 19:09:09 +09:00
title = params[0]
}
2020-06-17 19:09:09 +09:00
if len(params) > 1 {
2020-06-18 10:12:47 +09:00
filter = strings.Replace(params[1], " ", "", -1)
2020-06-17 19:09:09 +09:00
}
return r.renderer.SelectSaveFile(title, filter)
2019-10-08 06:12:08 +11:00
}