diff options
author | Joe <rbo@gmx.us> | 2024-05-13 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-05-13 20:20:20 +0200 |
commit | 0ddfbf62fde8b8e0bde9a548b203d67b812ab61e (patch) | |
tree | 9843ed6d3420f1295e2b30355cfa743d4fa62202 | |
parent | gg (diff) | |
download | hardflip-0ddfbf62fde8b8e0bde9a548b203d67b812ab61e.tar.gz hardflip-0ddfbf62fde8b8e0bde9a548b203d67b812ab61e.tar.bz2 hardflip-0ddfbf62fde8b8e0bde9a548b203d67b812ab61e.tar.xz hardflip-0ddfbf62fde8b8e0bde9a548b203d67b812ab61e.tar.zst hardflip-0ddfbf62fde8b8e0bde9a548b203d67b812ab61e.zip |
fix
-rw-r--r-- | ROADMAP.md | 4 | ||||
-rw-r--r-- | src/c_litems.go | 32 | ||||
-rw-r--r-- | src/e_events.go | 49 | ||||
-rw-r--r-- | src/e_keys.go | 10 | ||||
-rw-r--r-- | src/i_help.go | 1 | ||||
-rw-r--r-- | src/i_insert.go | 11 | ||||
-rw-r--r-- | src/i_ui.go | 6 |
7 files changed, 73 insertions, 40 deletions
@@ -40,8 +40,8 @@ ## v0.7 - [x] scroll insert -- [ ] help -- [ ] rename dirs +- [x] help +- [x] rename dirs - [ ] better readline ## v0.8 diff --git a/src/c_litems.go b/src/c_litems.go index 3f5a654..2b92816 100644 --- a/src/c_litems.go +++ b/src/c_litems.go @@ -82,6 +82,22 @@ func (litems *ItemsList) add_back(node *ItemsNode) { litems.last = last.next } +// adds an item node to the list after the current selected item +func (litems *ItemsList) add_after(node *ItemsNode) { + if litems.head == nil || litems.curr == nil { + litems.add_back(node) + return + } + curr := litems.curr + node.prev = curr + node.next = curr.next + curr.next = node + if litems.last == curr { + litems.last = node + } + litems.curr = node +} + // removes an item node from the list and resets the ids func (litems *ItemsList) del(item *ItemsNode) { if litems.head == nil { @@ -122,22 +138,6 @@ func (litems *ItemsList) del(item *ItemsNode) { } } -// sets litems.curr to be used -func (litems *ItemsList) sel(id int) { - curr := litems.head - - if curr == nil { - litems.curr = nil - } - for curr.next != nil && curr.ID != id { - curr = curr.next - } - if curr.ID != id { - litems.curr = nil - } - litems.curr = curr -} - func (item *ItemsNode) is_dir() bool { if item.Dirs == nil { return false diff --git a/src/e_events.go b/src/e_events.go index 783e707..d954837 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -318,22 +318,47 @@ func e_mkdir(data *HardData, ui *HardUI) { func e_rename(data *HardData, ui *HardUI) error { tmp := data.litems.curr + name := "" + if tmp.is_dir() == false { + name = tmp.Host.Name + } else { + name = tmp.Dirs.Name + } - if len(ui.buff) == 0 || tmp == nil || tmp.is_dir() == true || - ui.buff == tmp.Host.Name { + if len(ui.buff) == 0 || tmp == nil || ui.buff == 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 + if tmp.is_dir() == false { + 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 + } + return nil + } else { + old_path := data.data_dir + tmp.Dirs.path() + new_path := data.data_dir + tmp.Dirs.Parent.path() + data.ui.buff + if err := os.Rename(old_path, new_path); err != nil { + c_error_mode("can't rename " + old_path, err, &data.ui) + return err + } + path := tmp.Dirs.Parent.path() + e_reload_data(data) + for curr := data.litems.head; curr != nil; curr = curr.next { + if curr.is_dir() == true && + curr.Dirs.Name == ui.buff && + curr.Dirs.Parent.path() == path { + data.litems.curr = curr + return nil + } + } + return nil } - return nil } func e_set_drive_keys(data *HardData) { diff --git a/src/e_keys.go b/src/e_keys.go index 3fe9d6c..2d05380 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -242,10 +242,13 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { } else if (event.Rune() == 'c' || event.Rune() == 'C' || event.Rune() == 'A') && - data.litems.curr != nil && - data.litems.curr.is_dir() == false { + data.litems.curr != nil { ui.mode = RENAME_MODE - ui.buff = data.litems.curr.Host.Name + if data.litems.curr.is_dir() == false { + ui.buff = data.litems.curr.Host.Name + } else { + ui.buff = data.litems.curr.Dirs.Name + } } else if event.Rune() == '?' { ui.mode = HELP_MODE ui.help_scroll = 0 @@ -821,6 +824,7 @@ func e_rename_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { if err := e_rename(data, ui); err != nil { ui.s.HideCursor() ui.buff = "" + return true } } else { e_readline(event, &ui.buff) diff --git a/src/i_help.go b/src/i_help.go index c13b0b7..fa3852f 100644 --- a/src/i_help.go +++ b/src/i_help.go @@ -79,7 +79,6 @@ func i_draw_help(ui *HardUI) { ui.s.SetContent(win.L, win.B - 1, '▼', nil, ui.style[BOX_STYLE]) } - // TODO: here } func i_help_normal(ui HardUI, win Quad, line *int) bool { diff --git a/src/i_insert.go b/src/i_insert.go index e191bc4..09e1537 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -188,11 +188,12 @@ func i_insert_host(data *HardData, insert *HostNode) error { } curr := data.litems.curr if curr != nil { - curr.next = item - if curr.next.next != nil { - data.litems.curr.next.next.prev = item - } - data.litems.curr = data.litems.curr.next + data.litems.add_after(item) + // curr.next = item + // if curr.next.next != nil { + // data.litems.curr.next.next.prev = item + // } + // data.litems.curr = data.litems.curr.next } else { data.litems.add_back(item) data.litems.curr = data.litems.head diff --git a/src/i_ui.go b/src/i_ui.go index 3e0de04..82e6878 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -445,7 +445,11 @@ func i_prompt_dir(ui HardUI, prompt string, home_dir string) { func i_prompt_insert(ui HardUI, curr *ItemsNode) { path := "/" if curr != nil { - path = curr.path() + if curr.is_dir() == false { + path = curr.path() + } else { + path = curr.Dirs.Parent.path() + } } path = path[1:] prompt := "Name: " |