This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/examples/fileBrowser/main.go

92 lines
2.7 KiB
Go
Raw Normal View History

2023-03-21 10:26:48 -06:00
package main
import "os"
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/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements"
2023-03-21 10:26:48 -06:00
import "git.tebibyte.media/sashakoshka/tomo/elements/file"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(384, 384)
window.SetTitle("File browser")
2023-03-30 23:06:29 -06:00
container := containers.NewContainer(layouts.Vertical { true, true })
2023-03-21 10:26:48 -06:00
window.Adopt(container)
homeDir, _ := os.UserHomeDir()
2023-03-21 10:26:48 -06:00
2023-03-30 23:06:29 -06:00
controlBar := containers.NewContainer(layouts.Horizontal { })
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-03-30 23:06:29 -06:00
statusBar := containers.NewContainer(layouts.Horizontal { true, false })
directory, _ := fileElements.NewFile(homeDir, nil)
2023-03-30 23:06:29 -06:00
baseName := elements.NewLabel(filepath.Base(homeDir), false)
scrollContainer := containers.NewScrollContainer(false, true)
2023-03-23 13:56:56 -06:00
directoryView, _ := fileElements.NewDirectory(homeDir, nil)
updateStatus := func () {
filePath, _ := directoryView.Location()
directory.SetLocation(filePath, nil)
locationInput.SetValue(filePath)
baseName.SetText(filepath.Base(filePath))
2023-03-21 10:26:48 -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)
backButton.OnClick (func () {
directoryView.Backward()
updateStatus()
})
forwardButton.OnClick (func () {
directoryView.Forward()
updateStatus()
})
refreshButton.OnClick (func () {
directoryView.Update()
updateStatus()
})
upwardButton.OnClick (func () {
filePath, _ := directoryView.Location()
choose(filepath.Dir(filePath))
})
2023-03-21 10:26:48 -06:00
controlBar.Adopt(backButton, false)
controlBar.Adopt(forwardButton, false)
controlBar.Adopt(refreshButton, false)
controlBar.Adopt(upwardButton, false)
controlBar.Adopt(locationInput, true)
2023-03-21 10:26:48 -06:00
scrollContainer.Adopt(directoryView)
statusBar.Adopt(directory, false)
statusBar.Adopt(baseName, false)
2023-03-21 10:26:48 -06:00
container.Adopt(controlBar, false)
container.Adopt(scrollContainer, true)
container.Adopt(statusBar, false)
2023-03-21 10:26:48 -06:00
window.OnClose(tomo.Stop)
window.Show()
}