-
Notifications
You must be signed in to change notification settings - Fork 25
/
panels.go
99 lines (80 loc) · 1.99 KB
/
panels.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"strings"
"fyne.io/fyne/v2"
"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"
xWidget "fyne.io/x/fyne/widget"
"github.com/fyne-io/terminal"
)
func (d *defyne) makeEditorPanel() fyne.CanvasObject {
welcome := widget.NewLabel("Welcome to Defyne, the Fyne IDE.\n\nChoose a project file from the list.")
d.fileTabs = container.NewDocTabs(
container.NewTabItemWithIcon("Welcome", theme.HomeIcon(),
container.NewCenter(welcome)))
d.fileTabs.CloseIntercept = func(t *container.TabItem) {
ed, ok := d.openEditors[t]
if !ok { // welcome tab
return
}
if !ed.changed() {
ed.close()
d.fileTabs.Remove(t)
delete(d.openEditors, t)
return
}
dialog.ShowConfirm("File is unsaved", "Are you sure you wish to close?",
func(ok bool) {
if !ok {
return
}
ed.close()
d.fileTabs.Remove(t)
delete(d.openEditors, t)
}, d.win)
}
return container.NewStack(d.fileTabs)
}
func (d *defyne) makeFilesPanel() *xWidget.FileTree {
d.openEditors = make(map[*container.TabItem]*fileTab)
files := xWidget.NewFileTree(d.projectRoot)
files.Filter = filterHidden()
files.Sorter = func(u1, u2 fyne.URI) bool {
return u1.String() < u2.String() // Sort alphabetically
}
files.OnSelected = func(uid widget.TreeNodeID) {
u, err := storage.ParseURI(uid)
isDir, _ := storage.CanList(u)
if isDir {
return
}
if err != nil {
dialog.ShowError(err, d.win)
}
d.openEditor(u)
}
return files
}
func (d *defyne) makeTerminalPanel() fyne.CanvasObject {
term := terminal.New()
term.SetStartDir(d.projectRoot.Path())
go term.RunLocalShell()
return term
}
type filter struct{}
func (f *filter) Matches(u fyne.URI) bool {
name := u.Name()
if name[0] == '.' {
return false
}
if name == "go.sum" || (len(name) > 7 && strings.Index(name, ".gui.go") == len(u.Name())-7) {
return false
}
return true
}
func filterHidden() storage.FileFilter {
return &filter{}
}