diff options
author | Joe <rbo@gmx.us> | 2024-04-25 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-04-25 20:20:20 +0200 |
commit | 9ff62bb39b69c75ee15508a7266d45e15c0608a2 (patch) | |
tree | d2787f48a5fde0b8e9521e548f39e22f36a691d8 | |
parent | ok (diff) | |
download | hardflip-9ff62bb39b69c75ee15508a7266d45e15c0608a2.tar.gz hardflip-9ff62bb39b69c75ee15508a7266d45e15c0608a2.tar.bz2 hardflip-9ff62bb39b69c75ee15508a7266d45e15c0608a2.tar.xz hardflip-9ff62bb39b69c75ee15508a7266d45e15c0608a2.tar.zst hardflip-9ff62bb39b69c75ee15508a7266d45e15c0608a2.zip |
rename go
-rw-r--r-- | ROADMAP.md | 3 | ||||
-rw-r--r-- | src/e_events.go | 24 | ||||
-rw-r--r-- | src/e_keys.go | 8 |
3 files changed, 24 insertions, 11 deletions
@@ -35,7 +35,7 @@ - [x] ssh jump for rdp - [x] edit - [x] move -- [ ] rename +- [x] rename ## v0.7 @@ -57,6 +57,7 @@ - [ ] fuzz - [ ] rename dirs +- [ ] undo maybe ## v1.2 - ghetto bird diff --git a/src/e_events.go b/src/e_events.go index 60f7db9..21cad94 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -316,14 +316,24 @@ func e_mkdir(data *HardData, ui *HardUI) { } } -func e_rename(data *HardData, ui *HardUI) { - if len(ui.buff) == 0 || - data.litems.curr == nil || data.litems.curr.is_dir() == true { - return +func e_rename(data *HardData, ui *HardUI) error { + tmp := data.litems.curr + + if len(ui.buff) == 0 || tmp == nil || tmp.is_dir() == true || + ui.buff == tmp.Host.Name { + return nil + } + new_host := e_deep_copy_host(data.litems.curr.Host) + new_host.Name = ui.buff + ui.insert_method = INSERT_MOVE + i_insert_host(data, &new_host) + data.litems.del(tmp) + file_path := data.data_dir + tmp.Host.parent.path() + tmp.Host.filename + if err := os.Remove(file_path); err != nil { + c_error_mode("can't remove " + file_path, err, &data.ui) + return err } - data.litems.curr.Host.Name = ui.buff - // ui.insert_method = INSERT_MOVE - // i_insert_host(data, new_host) + return nil } func e_set_drive_keys(data *HardData) { diff --git a/src/e_keys.go b/src/e_keys.go index d160f47..621b9ea 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -240,8 +240,7 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { ui.msg_buff = "pasted " + new_host.Name } else if (event.Rune() == 'c' || event.Rune() == 'C' || - event.Rune() == 'r' || - event.Rune() == 'R') && + event.Rune() == 'A') && data.litems.curr != nil && data.litems.curr.is_dir() == false { ui.mode = RENAME_MODE @@ -780,7 +779,10 @@ func e_rename_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { event.Key() == tcell.KeyCtrlC { data.insert = nil } else if event.Key() == tcell.KeyEnter { - e_rename(data, ui) + if err := e_rename(data, ui); err != nil { + ui.s.HideCursor() + ui.buff = "" + } } else { e_readline(event, &ui.buff) return true |