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"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/file"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
|
|
|
|
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")
|
|
|
|
container := containers.NewContainer(basicLayouts.Vertical { true, true })
|
|
|
|
window.Adopt(container)
|
2023-03-21 16:03:31 -06:00
|
|
|
homeDir, _ := os.UserHomeDir()
|
2023-03-21 10:26:48 -06:00
|
|
|
|
|
|
|
controlBar := containers.NewContainer(basicLayouts.Horizontal { })
|
|
|
|
backButton := basicElements.NewButton("Back")
|
|
|
|
backButton.SetIcon(theme.IconBackward)
|
|
|
|
backButton.ShowText(false)
|
|
|
|
forwardButton := basicElements.NewButton("Forward")
|
|
|
|
forwardButton.SetIcon(theme.IconForward)
|
|
|
|
forwardButton.ShowText(false)
|
|
|
|
refreshButton := basicElements.NewButton("Refresh")
|
|
|
|
refreshButton.SetIcon(theme.IconRefresh)
|
|
|
|
refreshButton.ShowText(false)
|
|
|
|
upwardButton := basicElements.NewButton("Go Up")
|
|
|
|
upwardButton.SetIcon(theme.IconUpward)
|
|
|
|
upwardButton.ShowText(false)
|
|
|
|
locationInput := basicElements.NewTextBox("Location", "")
|
|
|
|
|
2023-03-21 16:03:31 -06:00
|
|
|
statusBar := containers.NewContainer(basicLayouts.Horizontal { true, false })
|
|
|
|
directory, _ := fileElements.NewFile(homeDir, nil)
|
|
|
|
baseName := basicElements.NewLabel(filepath.Base(homeDir), false)
|
|
|
|
|
|
|
|
scrollContainer := containers.NewScrollContainer(false, true)
|
|
|
|
directoryView, _ := fileElements.NewDirectoryView(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-03-21 10:26:48 -06:00
|
|
|
|
2023-03-21 16:03:31 -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)
|
2023-03-21 16:03:31 -06:00
|
|
|
statusBar.Adopt(directory, false)
|
|
|
|
statusBar.Adopt(baseName, false)
|
|
|
|
|
2023-03-21 10:26:48 -06:00
|
|
|
container.Adopt(controlBar, false)
|
|
|
|
container.Adopt(scrollContainer, true)
|
2023-03-21 16:03:31 -06:00
|
|
|
container.Adopt(statusBar, false)
|
2023-03-21 10:26:48 -06:00
|
|
|
|
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
|
|
|
}
|