diff options
-rw-r--r-- | c_ldirs.go | 37 | ||||
-rw-r--r-- | i_events.go | 13 |
2 files changed, 46 insertions, 4 deletions
@@ -79,6 +79,43 @@ func (ldirs *DirsList) add_back(node *DirsNode) { ldirs.last = last.next } +// removes a dir node from the list +func (ldirs *DirsList) del(dir *DirsNode) { + if ldirs.head == nil { + return + } + if ldirs.head == dir { + ldirs.head = ldirs.head.next + if ldirs.head == nil { + ldirs.last = nil + return + } + for ptr := ldirs.head; ptr != nil; ptr = ptr.next { + ptr.ID -= 1 + } + return + } + if ldirs.last == dir { + ptr := ldirs.head + for ptr.next != nil { + ptr = ptr.next + } + ldirs.last = ptr + ldirs.last.next = nil + return + } + ptr := ldirs.head + for ptr.next != nil && ptr.next != dir { + ptr = ptr.next + } + if ptr.next == dir { + ptr.next = ptr.next.next + } + for ptr := ptr.next; ptr != nil; ptr = ptr.next { + ptr.ID -= 1 + } +} + // return the list node with the according id func (ldirs *DirsList) sel(id int) *DirsNode { curr := ldirs.head diff --git a/i_events.go b/i_events.go index e604785..9333cfd 100644 --- a/i_events.go +++ b/i_events.go @@ -160,15 +160,23 @@ func i_delete_dir(data *HardData) { // data.ui.s.Fini() // c_die("can't remove " + dir_path, err) // } + tmp := data.litems.curr.prev + data.ldirs.del(dir) + // TODO: delete folds map reference if folded // TODO: finish this // TODO: litems ldirs and shit and lots of segv // TEST: single empty dir // TEST: single non-empty dir // TEST: first dir // TEST: last dir + // TEST: last dir 4m+ + // TEST: folded } func i_delete_host(data *HardData) { + if data.litems.curr == nil { + return + } if data.litems.curr.is_dir() == true { i_delete_dir(data) return @@ -183,11 +191,8 @@ func i_delete_host(data *HardData) { data.ui.s.Fini() c_die("can't remove " + file_path, err) } - var tmp *ItemsNode + tmp := data.litems.curr.prev host.Parent.lhost.del(host) - if data.litems.curr != nil { - tmp = data.litems.curr.prev - } data.litems.del(data.litems.curr) if tmp == nil { tmp = data.litems.head |