-
Notifications
You must be signed in to change notification settings - Fork 26
/
defyne.go
56 lines (46 loc) · 1.08 KB
/
defyne.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
package main
import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
xWidget "fyne.io/x/fyne/widget"
)
type fileTab struct {
editor
uri fyne.URI
}
type defyne struct {
win fyne.Window
projectRoot fyne.URI
fileTabs *container.DocTabs
fileTree *xWidget.FileTree
openEditors map[*container.TabItem]*fileTab
}
func (d *defyne) openEditor(u fyne.URI) {
for tab, item := range d.openEditors {
if item.uri.String() == u.String() {
d.fileTabs.Select(tab)
return
}
}
var ed editor
for name, e := range editorsByFilename {
if strings.Contains(u.Name(), name) {
ed = e(u, d.win)
}
}
if ed == nil {
if _, ok := editorsByMime[u.MimeType()]; !ok {
dialog.ShowInformation("No registered editor",
"No known editor for mime "+u.MimeType(), d.win)
return
}
ed = editorsByMime[u.MimeType()](u, d.win)
}
newTab := container.NewTabItemWithIcon(u.Name(), theme.FileTextIcon(), ed.content())
d.openEditors[newTab] = &fileTab{ed, u}
d.fileTabs.Append(newTab)
d.fileTabs.Select(newTab)
}