Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package ui |
||
2 | |||
3 | import ( |
||
4 | "fyne.io/fyne/v2/container" |
||
5 | "fyne.io/fyne/v2/layout" |
||
6 | "github.com/rchargel/hdfs-explorer/files" |
||
7 | ) |
||
8 | |||
9 | type FileBrowser struct { |
||
10 | name string |
||
11 | files HdfsFileInfoList |
||
12 | path string |
||
13 | } |
||
14 | |||
15 | func NewFileBrowser(client files.FileSystemClient) *FileBrowser { |
||
16 | b := &FileBrowser{client.Name(), NewHdfsFileInfoList(client), "/"} |
||
17 | b.update() |
||
18 | return b |
||
19 | } |
||
20 | |||
21 | func (b *FileBrowser) Tab() *container.TabItem { |
||
22 | l := NewFileDirectoryList(b.files, b.updatePath) |
||
23 | scroll := container.NewVScroll(l.container) |
||
24 | c := container.NewHBox(scroll, layout.NewSpacer()) |
||
25 | return container.NewTabItem(b.name, c) |
||
26 | } |
||
27 | |||
28 | func (b *FileBrowser) Close() { |
||
29 | b.files.Close() |
||
30 | } |
||
31 | |||
32 | func (b *FileBrowser) update() { |
||
33 | go func() { |
||
34 | b.files.UpdatePath(b.path) |
||
35 | }() |
||
36 | } |
||
37 | |||
38 | func (b *FileBrowser) updatePath(name string) { |
||
39 | if name == ".." { |
||
40 | b.path = files.Parent(b.path) |
||
41 | } else { |
||
42 | b.path = files.Join(b.path, name) |
||
43 | } |
||
44 | b.update() |
||
45 | } |
||
46 |