mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
new file + open file commands; commands can take args
This commit is contained in:
parent
ac351ec9db
commit
bcab1eee76
1
foo_bar_baz
Normal file
1
foo_bar_baz
Normal file
@ -0,0 +1 @@
|
||||
this is the file new_bar_baz!
|
@ -4,23 +4,37 @@ import "os"
|
||||
|
||||
type BufferAction struct {
|
||||
name string
|
||||
proc func(*View) bool
|
||||
proc func(*View, []string) bool
|
||||
}
|
||||
|
||||
func NewBufferAction(name string, proc func(*View) bool) BufferAction {
|
||||
func NewBufferAction(name string, proc func(*View, []string) bool) BufferAction {
|
||||
return BufferAction{
|
||||
name: name,
|
||||
proc: proc,
|
||||
}
|
||||
}
|
||||
|
||||
func NewFile(v *View, commands []string) bool {
|
||||
// TODO some nice error stuff
|
||||
// have an error roll thing in the view?
|
||||
|
||||
buff := v.AddBuffer()
|
||||
buff.OpenFile(commands[0])
|
||||
|
||||
buff.SetFocus(true)
|
||||
v.focusedBuff = buff.index
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
var actions = map[string]BufferAction{
|
||||
"new": NewBufferAction("new", NewFile),
|
||||
"save": NewBufferAction("save", Save),
|
||||
"delete_line": NewBufferAction("delete_line", DeleteLine),
|
||||
"close_buffer": NewBufferAction("close_buffer", CloseBuffer),
|
||||
"paste": NewBufferAction("paste", Paste),
|
||||
"show_palette": NewBufferAction("show_palette", ShowPalette),
|
||||
"exit": NewBufferAction("exit", func(*View) bool {
|
||||
"exit": NewBufferAction("exit", func(*View, []string) bool {
|
||||
// TODO do this properly lol
|
||||
os.Exit(0)
|
||||
return false
|
||||
|
@ -268,7 +268,7 @@ func (b *Buffer) processTextInput(r rune) bool {
|
||||
actionName, actionExists := cfg.Shortcuts.Supers[string(unicode.ToLower(r))]
|
||||
if actionExists {
|
||||
if action, ok := actions[actionName]; ok {
|
||||
return action.proc(b.parent)
|
||||
return action.proc(b.parent, []string{})
|
||||
}
|
||||
} else {
|
||||
log.Println("warning, unimplemented shortcut ctrl+", unicode.ToLower(r), actionName)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package gui
|
||||
|
||||
func CloseBuffer(v *View) bool {
|
||||
func CloseBuffer(v *View, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
|
@ -1,6 +1,6 @@
|
||||
package gui
|
||||
|
||||
func DeleteLine(v *View) bool {
|
||||
func DeleteLine(v *View, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
|
@ -130,7 +130,7 @@ func (b *CommandPalette) processCommand() {
|
||||
return
|
||||
}
|
||||
|
||||
action.proc(b.parent)
|
||||
action.proc(b.parent, tokenizedLine[1:])
|
||||
}
|
||||
|
||||
func (b *CommandPalette) calculateSuggestions() {
|
||||
|
@ -7,14 +7,14 @@ import (
|
||||
"log"
|
||||
)
|
||||
|
||||
func ShowPalette(v *View) bool {
|
||||
func ShowPalette(v *View, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
v.UnfocusBuffers()
|
||||
v.focusPalette(b)
|
||||
return true
|
||||
}
|
||||
|
||||
func Paste(v *View) bool {
|
||||
func Paste(v *View, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
@ -38,7 +38,7 @@ func Paste(v *View) bool {
|
||||
// if the buffer is modified it will be
|
||||
// re-rendered.
|
||||
|
||||
func Save(v *View) bool {
|
||||
func Save(v *View, commands []string) bool {
|
||||
b := v.getCurrentBuff()
|
||||
if b == nil {
|
||||
return false
|
||||
|
@ -137,7 +137,7 @@ func (n *View) OnUpdate() bool {
|
||||
if actionExists {
|
||||
if action, ok := actions[actionName]; ok {
|
||||
log.Println("Executing action '" + actionName + "'")
|
||||
return action.proc(n)
|
||||
return action.proc(n, []string{})
|
||||
}
|
||||
} else {
|
||||
log.Println("warning, unimplemented shortcut ctrl +", string(unicode.ToLower(r)), actionName)
|
||||
|
Loading…
Reference in New Issue
Block a user