2023-03-21 10:26:48 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "os"
|
2023-03-21 16:03:31 -06:00
|
|
|
import "path/filepath"
|
2023-03-21 10:26:48 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
2023-03-30 21:19:04 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
2023-03-21 10:26:48 -06:00
|
|
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
|
|
|
|
|
|
|
func main () {
|
|
|
|
tomo.Run(run)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run () {
|
2023-04-10 00:58:52 -06:00
|
|
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 384, 384))
|
2023-03-21 10:26:48 -06:00
|
|
|
window.SetTitle("File browser")
|
2023-04-18 16:37:50 -06:00
|
|
|
container := elements.NewVBox(elements.SpaceBoth)
|
2023-03-21 10:26:48 -06:00
|
|
|
window.Adopt(container)
|
2023-03-21 16:03:31 -06:00
|
|
|
homeDir, _ := os.UserHomeDir()
|
2023-03-21 10:26:48 -06:00
|
|
|
|
2023-04-18 16:37:50 -06:00
|
|
|
controlBar := elements.NewHBox(elements.SpaceNone)
|
2023-03-30 23:06:29 -06:00
|
|
|
backButton := elements.NewButton("Back")
|
|
|
|
backButton.SetIcon(tomo.IconBackward)
|
2023-03-21 10:26:48 -06:00
|
|
|
backButton.ShowText(false)
|
2023-03-30 23:06:29 -06:00
|
|
|
forwardButton := elements.NewButton("Forward")
|
|
|
|
forwardButton.SetIcon(tomo.IconForward)
|
2023-03-21 10:26:48 -06:00
|
|
|
forwardButton.ShowText(false)
|
2023-03-30 23:06:29 -06:00
|
|
|
refreshButton := elements.NewButton("Refresh")
|
|
|
|
refreshButton.SetIcon(tomo.IconRefresh)
|
2023-03-21 10:26:48 -06:00
|
|
|
refreshButton.ShowText(false)
|
2023-03-30 23:06:29 -06:00
|
|
|
upwardButton := elements.NewButton("Go Up")
|
|
|
|
upwardButton.SetIcon(tomo.IconUpward)
|
2023-03-21 10:26:48 -06:00
|
|
|
upwardButton.ShowText(false)
|
2023-03-30 23:06:29 -06:00
|
|
|
locationInput := elements.NewTextBox("Location", "")
|
2023-03-21 10:26:48 -06:00
|
|
|
|
2023-04-18 16:37:50 -06:00
|
|
|
statusBar := elements.NewHBox(elements.SpaceMargin)
|
|
|
|
directory, _ := elements.NewFile(homeDir, nil)
|
|
|
|
baseName := elements.NewLabel(filepath.Base(homeDir))
|
2023-03-21 16:03:31 -06:00
|
|
|
|
2023-04-18 16:37:50 -06:00
|
|
|
directoryView, _ := elements.NewDirectory(homeDir, nil)
|
2023-03-23 12:45:46 -06:00
|
|
|
updateStatus := func () {
|
|
|
|
filePath, _ := directoryView.Location()
|
2023-03-21 16:03:31 -06:00
|
|
|
directory.SetLocation(filePath, nil)
|
|
|
|
locationInput.SetValue(filePath)
|
|
|
|
baseName.SetText(filepath.Base(filePath))
|
2023-03-21 10:26:48 -06:00
|
|
|
}
|
2023-03-23 12:45:46 -06:00
|
|
|
choose := func (filePath string) {
|
|
|
|
directoryView.SetLocation(filePath, nil)
|
|
|
|
updateStatus()
|
|
|
|
}
|
2023-03-21 10:26:48 -06:00
|
|
|
directoryView.OnChoose(choose)
|
|
|
|
locationInput.OnEnter (func () {
|
|
|
|
choose(locationInput.Value())
|
|
|
|
})
|
|
|
|
choose(homeDir)
|
2023-03-23 12:37:44 -06:00
|
|
|
backButton.OnClick (func () {
|
|
|
|
directoryView.Backward()
|
2023-03-23 12:45:46 -06:00
|
|
|
updateStatus()
|
2023-03-23 12:37:44 -06:00
|
|
|
})
|
|
|
|
forwardButton.OnClick (func () {
|
|
|
|
directoryView.Forward()
|
2023-03-23 12:45:46 -06:00
|
|
|
updateStatus()
|
2023-03-23 12:37:44 -06:00
|
|
|
})
|
|
|
|
refreshButton.OnClick (func () {
|
|
|
|
directoryView.Update()
|
2023-03-23 12:45:46 -06:00
|
|
|
updateStatus()
|
|
|
|
})
|
|
|
|
upwardButton.OnClick (func () {
|
|
|
|
filePath, _ := directoryView.Location()
|
|
|
|
choose(filepath.Dir(filePath))
|
2023-03-23 12:37:44 -06:00
|
|
|
})
|
2023-04-18 16:37:50 -06:00
|
|
|
|
|
|
|
controlBar.Adopt(backButton, forwardButton, refreshButton, upwardButton)
|
|
|
|
controlBar.AdoptExpand(locationInput)
|
|
|
|
statusBar.Adopt(directory, baseName)
|
2023-03-21 10:26:48 -06:00
|
|
|
|
2023-04-18 16:37:50 -06:00
|
|
|
container.Adopt(controlBar)
|
|
|
|
container.AdoptExpand (
|
|
|
|
elements.NewScroll(elements.ScrollVertical, directoryView))
|
|
|
|
container.Adopt(statusBar)
|
2023-03-21 10:26:48 -06:00
|
|
|
|
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
|
|
|
}
|