forked from fyne-io/flatpak_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (45 loc) · 1.19 KB
/
main.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
51
52
53
54
55
package main
import (
"io/ioutil"
"log"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.NewWithID("io.fyne.flatpak_demo")
w := a.NewWindow("Flatpak Demo")
markdown := widget.NewMultiLineEntry()
preview := widget.NewRichText()
markdown.OnChanged = preview.ParseMarkdown
open := &widget.Button{Text: "Open file", Icon: theme.ContentAddIcon(), OnTapped: func() {
files := dialog.NewFileOpen(func(file fyne.URIReadCloser, err error) {
if err != nil {
log.Println(err)
return
} else if file == nil {
return
}
text, err := ioutil.ReadAll(file)
if err != nil {
log.Println(err)
return
}
markdown.SetText(string(text))
a.SendNotification(&fyne.Notification{Title: "Opened a file", Content: file.URI().Name() + " was opened correctly."})
}, w)
files.SetFilter(storage.NewExtensionFileFilter([]string{".md"}))
files.Show()
}}
w.SetContent(
container.NewBorder(container.NewHBox(open), nil, nil, nil,
container.NewHSplit(markdown, preview),
),
)
w.Resize(fyne.NewSize(600, 400))
w.ShowAndRun()
}