From cf4bfd6b75b8bc7b164303ff82af7fefca9983eb Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Thu, 15 Jun 2006 20:53:38 +0000 Subject: [PATCH] do_move_bookmarks: replace destb and desti parameters with insert_as_child flag Simplify do_move_bookmarks (from a readability perspective) by replacing the destb and desti parameters with a new insert_as_child flag. Inspired by Kalle Olavi Niemitalo. [ Backported from commit 32ec5d1db3fc1d97d076931e379d3bd4a3fae11b in ELinks 0.12.GIT. This change is not required for fixing bug 760, but the bookmark code in ELinks 0.12.GIT has been tested more with the change than without it, so I think applying it is safest. --KON ] --- src/bookmarks/dialogs.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/bookmarks/dialogs.c b/src/bookmarks/dialogs.c index 0de61645..9f9dd46f 100644 --- a/src/bookmarks/dialogs.c +++ b/src/bookmarks/dialogs.c @@ -353,15 +353,12 @@ update_depths(struct listbox_item *parent) /* Traverse all bookmarks and move all marked items * _into_ destb or, if destb is NULL, _after_ dest. */ static void -do_move_bookmark(struct bookmark *dest, struct list_head *destb, - struct list_head *desti, struct list_head *src, - struct listbox_data *box) +do_move_bookmark(struct bookmark *dest, int insert_as_child, + struct list_head *src, struct listbox_data *box) { static int move_bookmark_event_id = EVENT_NONE; struct bookmark *bm, *next; - assert((destb && desti) || (!destb && !desti)); - set_event_id(move_bookmark_event_id, "bookmark-move"); foreachsafe (bm, next, *src) { @@ -371,9 +368,7 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb, bm->box_item->marked = 0; - trigger_event(move_bookmark_event_id, bm, - destb ? (struct bookmark *) destb - : dest); + trigger_event(move_bookmark_event_id, bm, dest); foreach (item, bookmark_browser.dialogs) { struct widget_data *widget_data; @@ -388,14 +383,16 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb, del_from_list(bm->box_item); del_from_list(bm); - add_at_pos(destb ? (struct bookmark *) destb - : dest, - bm); - add_at_pos(desti ? (struct listbox_item *) desti - : dest->box_item, - bm->box_item); - - bm->root = destb ? dest : dest->root; + if (insert_as_child) { + add_to_list(dest->child, bm); + add_to_list(dest->box_item->child, bm->box_item); + bm->root = dest; + insert_as_child = 0; + } else { + add_at_pos(dest, bm); + add_at_pos(dest->box_item, bm->box_item); + bm->root = dest->root; + } bm->box_item->depth = bm->root ? bm->root->box_item->depth + 1 @@ -405,7 +402,6 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb, update_depths(bm->box_item); dest = bm; - desti = destb = NULL; /* We don't want to care about anything marked inside * of the marked folder, let's move it as a whole @@ -415,7 +411,8 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb, } if (bm->box_item->type == BI_FOLDER) { - do_move_bookmark(dest, destb, desti, &bm->child, box); + do_move_bookmark(dest, insert_as_child, + &bm->child, box); } } } @@ -426,14 +423,13 @@ push_move_button(struct dialog_data *dlg_data, { struct listbox_data *box = get_dlg_listbox_data(dlg_data); struct bookmark *dest = NULL; - struct list_head *destb = NULL, *desti = NULL; + int insert_as_child = 0; if (!box->sel) return EVENT_PROCESSED; /* nowhere to move to */ dest = box->sel->udata; if (box->sel->type == BI_FOLDER && box->sel->expanded) { - destb = &((struct bookmark *) box->sel->udata)->child; - desti = &box->sel->child; + insert_as_child = 1; } /* Avoid recursion headaches (prevents moving a folder into itself). */ move_cache_root_avoid = NULL; @@ -447,7 +443,7 @@ push_move_button(struct dialog_data *dlg_data, } } - do_move_bookmark(dest, destb, desti, &bookmarks, box); + do_move_bookmark(dest, insert_as_child, &bookmarks, box); bookmarks_set_dirty();