mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 11:10:37 +03:00
open file command!
This commit is contained in:
parent
7b383606d8
commit
e0e53fa246
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user