diff --git a/gui/action.go b/gui/action.go index 8523516..e0ba03d 100644 --- a/gui/action.go +++ b/gui/action.go @@ -3,6 +3,9 @@ package gui import ( "log" "strconv" + "strings" + + "github.com/sqweek/dialog" ) type BufferAction struct { @@ -19,6 +22,25 @@ func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction } } +func OpenFile(v *View, commands []string) bool { + path, err := dialog.File().Title("Open file").Load() + if err != nil { + log.Println(err) + return false + } + + buff := v.AddBuffer() + if len(strings.TrimSpace(path)) == 0 { + return false + } + + buff.OpenFile(path) + buff.SetFocus(true) + v.focusedBuff = buff.index + + return false +} + func NewFile(v *View, commands []string) bool { // TODO some nice error stuff // have an error roll thing in the view? @@ -109,6 +131,7 @@ var actions = map[string]BufferAction{ "goto": NewBufferAction("goto", GotoLine), "new": NewBufferAction("new", NewFile), + "open": NewBufferAction("open", OpenFile), "save": NewBufferAction("save", Save), "delete_line": NewBufferAction("delete_line", DeleteLine), "close_buffer": NewBufferAction("close_buffer", CloseBuffer),