Total Lines | 60 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package ui |
||
2 | |||
3 | import ( |
||
4 | "image/color" |
||
5 | |||
6 | "fyne.io/fyne/v2" |
||
7 | "fyne.io/fyne/v2/canvas" |
||
8 | "fyne.io/fyne/v2/container" |
||
9 | "fyne.io/fyne/v2/data/binding" |
||
10 | "fyne.io/fyne/v2/widget" |
||
11 | "github.com/rchargel/hdfs-explorer/files" |
||
12 | ) |
||
13 | |||
14 | type FileBrowser struct { |
||
15 | client files.FileSystemClient |
||
16 | files binding.StringList |
||
17 | path string |
||
18 | } |
||
19 | |||
20 | func NewFileBrowser(client files.FileSystemClient) *FileBrowser { |
||
21 | b := &FileBrowser{client, binding.NewStringList(), "/"} |
||
22 | b.updateList() |
||
23 | return b |
||
24 | } |
||
25 | |||
26 | func (b *FileBrowser) Tab() *container.TabItem { |
||
27 | // TODO implement custom widget for file exploration |
||
28 | l := widget.NewListWithData( |
||
29 | b.files, |
||
30 | func() fyne.CanvasObject { |
||
31 | t := canvas.NewText("template", color.Black) |
||
32 | return t |
||
33 | }, |
||
34 | func(di binding.DataItem, co fyne.CanvasObject) { |
||
35 | t := co.(*canvas.Text) |
||
36 | str, _ := di.(binding.String).Get() |
||
37 | t.Text = str |
||
38 | }, |
||
39 | ) |
||
40 | |||
41 | return container.NewTabItem( |
||
42 | b.client.Name(), |
||
43 | container.NewMax(l), |
||
44 | ) |
||
45 | } |
||
46 | |||
47 | func (b *FileBrowser) Close() { |
||
48 | b.client.Close() |
||
49 | } |
||
50 | |||
51 | func (b *FileBrowser) updateList() { |
||
52 | go func() { |
||
53 | orig := make([]string, 0) |
||
54 | if b.path != "/" { |
||
55 | orig = append(orig, "..") |
||
56 | } |
||
57 | b.files.Set(orig) |
||
58 | info, _ := b.client.List(b.path) |
||
59 | for _, file := range info { |
||
60 | b.files.Append(file.Name()) |
||
61 | } |
||
64 |