mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +09:00
Run action completion on saves with prompts at the right time
This commit is contained in:
@@ -638,10 +638,10 @@ func (h *BufPane) Save() bool {
|
|||||||
if h.Buf.Path == "" {
|
if h.Buf.Path == "" {
|
||||||
h.SaveAs()
|
h.SaveAs()
|
||||||
} else {
|
} else {
|
||||||
h.saveBufToFile(h.Buf.Path)
|
h.saveBufToFile(h.Buf.Path, "Save")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveAs saves the buffer to disk with the given name
|
// SaveAs saves the buffer to disk with the given name
|
||||||
@@ -655,16 +655,15 @@ func (h *BufPane) SaveAs() bool {
|
|||||||
InfoBar.Error("Error parsing arguments: ", err)
|
InfoBar.Error("Error parsing arguments: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.saveBufToFile(filename)
|
h.saveBufToFile(filename, "SaveAs")
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function saves the buffer to `filename` and changes the buffer's path and name
|
// This function saves the buffer to `filename` and changes the buffer's path and name
|
||||||
// to `filename` if the save is successful
|
// to `filename` if the save is successful
|
||||||
func (h *BufPane) saveBufToFile(filename string) {
|
func (h *BufPane) saveBufToFile(filename string, action string) {
|
||||||
err := h.Buf.SaveAs(filename)
|
err := h.Buf.SaveAs(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasSuffix(err.Error(), "permission denied") {
|
if strings.HasSuffix(err.Error(), "permission denied") {
|
||||||
@@ -678,6 +677,7 @@ func (h *BufPane) saveBufToFile(filename string) {
|
|||||||
h.Buf.SetName(filename)
|
h.Buf.SetName(filename)
|
||||||
InfoBar.Message("Saved " + filename)
|
InfoBar.Message("Saved " + filename)
|
||||||
}
|
}
|
||||||
|
h.completeAction(action)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -687,6 +687,7 @@ func (h *BufPane) saveBufToFile(filename string) {
|
|||||||
h.Buf.Path = filename
|
h.Buf.Path = filename
|
||||||
h.Buf.SetName(filename)
|
h.Buf.SetName(filename)
|
||||||
InfoBar.Message("Saved " + filename)
|
InfoBar.Message("Saved " + filename)
|
||||||
|
h.completeAction(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,8 +361,8 @@ func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int
|
|||||||
_, isMulti := MultiActions[name]
|
_, isMulti := MultiActions[name]
|
||||||
if (!isMulti && cursor == 0) || isMulti {
|
if (!isMulti && cursor == 0) || isMulti {
|
||||||
if h.PluginCB("pre" + name) {
|
if h.PluginCB("pre" + name) {
|
||||||
asuccess := action(h)
|
success := action(h)
|
||||||
psuccess := h.PluginCB("on" + name)
|
success = success && h.PluginCB("on"+name)
|
||||||
|
|
||||||
if isMulti {
|
if isMulti {
|
||||||
if recording_macro {
|
if recording_macro {
|
||||||
@@ -372,13 +372,17 @@ func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return asuccess && psuccess
|
return success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *BufPane) completeAction(action string) {
|
||||||
|
h.PluginCB("on" + action)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *BufPane) HasKeyEvent(e Event) bool {
|
func (h *BufPane) HasKeyEvent(e Event) bool {
|
||||||
_, ok := BufKeyBindings[e]
|
_, ok := BufKeyBindings[e]
|
||||||
return ok
|
return ok
|
||||||
|
|||||||
Reference in New Issue
Block a user