draft rename (#197)

*  basic structure

* working rename, without making dir's and selection change

* mkdirAll if necessary

* updated TODO's

* rename with replace prompting

* path prompt and moved functionality to nav.rename()

* renewing now (no set period is needed)

* documentation, keybidning change, load file info after renaming

* go generate
This commit is contained in:
Juris Arturs Majors authored and gokcehan committed 2019-07-20 19:31:19 +03:00
1 parent 27861f06e2
commit bfd01e5ed8
7 files changed
+82 -1

No files matched your search

+51 -1
View File
@@ -472,6 +472,17 @@ func insert(app *app, arg string) {
app.ui.echoerrf("delete: %s", err)
}
}
case strings.HasPrefix(app.ui.cmdPrefix, "replace") ||
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
normal(app)
if arg == "y" {
if err := app.nav.rename(app.ui); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
case app.ui.cmdPrefix == "mark-save: ":
normal(app)
@@ -523,7 +534,6 @@ func insert(app *app, arg string) {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
}
default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
}
@@ -818,6 +828,15 @@ func (e *callExpr) eval(app *app, args []string) {
case "mark-remove":
app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: "
case "rename":
if curr, err := app.nav.currFile(); err != nil {
app.ui.echoerrf("rename: %s:", err)
return
} else {
app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
}
case "sync":
if err := app.nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)
@@ -1029,6 +1048,37 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
}
case "rename: ":
app.ui.cmdPrefix = ""
if curr, err := app.nav.currFile(); err != nil {
app.ui.echoerrf("rename: %s", err)
} else {
wd, err := os.Getwd()
if err != nil {
log.Printf("getting current directory: %s", err)
return
}
oldPathTo := filepath.Join(wd, curr.Name())
newPathTo := filepath.Join(wd, s)
app.nav.renameCache = []string{oldPathTo, newPathTo}
if dir, _ := filepath.Split(s); dir != "" {
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil {
app.ui.cmdPrefix = "create path " + dir + "?[y/N]"
return
}
}
if _, err := os.Stat(newPathTo); err == nil { // file exists
app.ui.cmdPrefix = "replace " + s + "?[y/N]"
return
}
if err := app.nav.rename(app.ui); err != nil {
app.ui.echoerrf("rename: %s", err)
}
}
default:
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
}