-
Notifications
You must be signed in to change notification settings - Fork 0
/
texteditor.go
81 lines (61 loc) · 1.69 KB
/
texteditor.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"io/ioutil"
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
)
var count int = 1
func showTextEditor() {
w := myApp.NewWindow("Text Editor")
content := container.NewVBox(
container.NewHBox(
widget.NewLabel("Text editor"),
),
)
content.Add(widget.NewButton("Add New File", func() {
content.Add(widget.NewLabel("New File" + strconv.Itoa(count)))
count++
}))
input := widget.NewMultiLineEntry()
input.SetPlaceHolder("Enter text...")
input.Resize(fyne.NewSize(400, 400))
saveBtn := widget.NewButton("Save Text file", func() {
saveFileDialog := dialog.NewFileSave(
func(uc fyne.URIWriteCloser, _ error) {
textData := []byte(input.Text)
uc.Write(textData)
}, w)
saveFileDialog.SetFileName("New File" + strconv.Itoa(count-1) + ".txt")
saveFileDialog.Show()
})
openBtn := widget.NewButton("Open text file", func() {
openFileDialog := dialog.NewFileOpen(
func(r fyne.URIReadCloser, _ error) {
ReadData, _ := ioutil.ReadAll(r)
output := fyne.NewStaticResource("New File", ReadData)
viewData := widget.NewMultiLineEntry()
viewData.SetText(string(output.StaticContent))
w := fyne.CurrentApp().NewWindow(
string(output.StaticName))
w.SetContent(container.NewScroll(viewData))
w.Resize(fyne.NewSize(400, 400))
w.Show()
}, w)
openFileDialog.SetFilter(storage.NewExtensionFileFilter([]string{".txt"}))
openFileDialog.Show()
})
textContainer := container.NewVBox(
content,
input,
container.NewHBox(
saveBtn,
openBtn,
),
)
w.SetContent(container.NewBorder(DeskBtn, nil, nil, nil, textContainer))
w.Show()
}