1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-29 03:17:53 -04:00

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 32ec5d1db3 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 ]
This commit is contained in:
Miciah Dashiel Butler Masters 2006-06-15 20:53:38 +00:00 committed by Kalle Olavi Niemitalo
parent f287d5aa31
commit cf4bfd6b75

View File

@ -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();