Passed
Push — main ( 05b53a...cd1aeb )
by Rafael
01:13
created

ui.*FileBrowser.updateList   A

Complexity

Conditions 4

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
dl 0
loc 10
rs 9.95
c 0
b 0
f 0
nop 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