-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOpenFile.go
50 lines (48 loc) · 1.02 KB
/
OpenFile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"github.com/harry1453/go-common-file-dialog/cfd"
"log"
"time"
)
func main() {
openDialog, err := cfd.NewOpenFileDialog(cfd.DialogConfig{
Title: "Open A File",
Role: "OpenFileExample",
FileFilters: []cfd.FileFilter{
{
DisplayName: "Text Files (*.txt)",
Pattern: "*.txt",
},
{
DisplayName: "Image Files (*.jpg, *.png)",
Pattern: "*.jpg;*.png",
},
{
DisplayName: "All Files (*.*)",
Pattern: "*.*",
},
},
SelectedFileFilterIndex: 2,
FileName: "file.txt",
DefaultExtension: "txt",
})
if err != nil {
log.Fatal(err)
}
go func() {
time.Sleep(2 * time.Second)
if err := openDialog.SetFileName("hello world"); err != nil {
log.Fatal(err)
}
}()
if err := openDialog.Show(); err != nil {
log.Fatal(err)
}
result, err := openDialog.GetResult()
if err == cfd.ErrorCancelled {
log.Fatal("Dialog was cancelled by the user.")
} else if err != nil {
log.Fatal(err)
}
log.Printf("Chosen file: %s\n", result)
}