-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
79 lines (67 loc) · 1.9 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//go:generate fyne bundle -o bundled.go Icon.png
package main
import (
"os"
"github.com/fyshos/fyles/pkg/fyles"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
)
const winTitle = "Fyles"
func main() {
a := app.NewWithID("com.fyshos.fyles")
a.SetIcon(resourceIconPng)
w := a.NewWindow(winTitle)
w.SetPadded(false)
panels := []fyne.CanvasObject{}
addPanel := func(path string) {
current := storage.NewFileURI(path)
item := makePanel(current, w)
panels = append(panels,
container.NewStack(
canvas.NewRectangle(theme.BackgroundColor()),
item))
}
path, _ := os.Getwd()
for i := 1; i < len(os.Args); i++ {
addPanel(os.Args[i])
}
if len(panels) == 0 {
addPanel(path)
}
bg := canvas.NewRectangle(theme.OverlayBackgroundColor())
w.SetContent(container.NewStack(bg,
container.NewGridWithColumns(len(panels), panels...)))
w.Resize(fyne.NewSize(float32(15+(540*len(panels))), 310))
changes := make(chan fyne.Settings)
go func() {
for range changes {
bg.FillColor = theme.OverlayBackgroundColor()
bg.Refresh()
panelColor := theme.BackgroundColor()
for _, p := range panels {
bg := p.(*fyne.Container).Objects[0]
bg.(*canvas.Rectangle).FillColor = panelColor
bg.Refresh()
}
}
}()
a.Settings().AddChangeListener(changes)
w.ShowAndRun()
}
func makePanel(dir fyne.URI, w fyne.Window) fyne.CanvasObject {
ui := &fylesUI{win: w, filter: filterHidden()}
tools := ui.makeToolbar()
ui.items = fyles.NewFylesPanel(ui.itemTapped, w)
ui.items.Filter = ui.filter
tapper := newDirTapPanel(ui)
ui.fileScroll = container.NewScroll(container.NewStack(tapper, ui.items))
ui.fileTree = ui.makeFilesPanel(dir)
ui.setDirectory(dir)
mainSplit := container.NewHSplit(ui.fileTree, ui.fileScroll)
mainSplit.Offset = 0.3
return container.NewBorder(tools, nil, nil, nil, mainSplit)
}