mirror of
https://github.com/rkd77/elinks.git
synced 2025-04-18 00:47:36 -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.
This commit is contained in:
parent
6f98f5fd96
commit
32ec5d1db3
@ -343,16 +343,13 @@ enum move_bookmark_flags {
|
|||||||
/* Traverse all bookmarks and move all marked items
|
/* Traverse all bookmarks and move all marked items
|
||||||
* _into_ destb or, if destb is NULL, _after_ dest. */
|
* _into_ destb or, if destb is NULL, _after_ dest. */
|
||||||
static enum move_bookmark_flags
|
static enum move_bookmark_flags
|
||||||
do_move_bookmark(struct bookmark *dest, struct list_head *destb,
|
do_move_bookmark(struct bookmark *dest, int insert_as_child,
|
||||||
struct list_head *desti, struct list_head *src,
|
struct list_head *src, struct listbox_data *box)
|
||||||
struct listbox_data *box)
|
|
||||||
{
|
{
|
||||||
static int move_bookmark_event_id = EVENT_NONE;
|
static int move_bookmark_event_id = EVENT_NONE;
|
||||||
struct bookmark *bm, *next;
|
struct bookmark *bm, *next;
|
||||||
enum move_bookmark_flags result = MOVE_BOOKMARK_NONE;
|
enum move_bookmark_flags result = MOVE_BOOKMARK_NONE;
|
||||||
|
|
||||||
assert((destb && desti) || (!destb && !desti));
|
|
||||||
|
|
||||||
set_event_id(move_bookmark_event_id, "bookmark-move");
|
set_event_id(move_bookmark_event_id, "bookmark-move");
|
||||||
|
|
||||||
foreachsafe (bm, next, *src) {
|
foreachsafe (bm, next, *src) {
|
||||||
@ -368,9 +365,7 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
|
|||||||
result |= MOVE_BOOKMARK_MOVED;
|
result |= MOVE_BOOKMARK_MOVED;
|
||||||
bm->box_item->marked = 0;
|
bm->box_item->marked = 0;
|
||||||
|
|
||||||
trigger_event(move_bookmark_event_id, bm,
|
trigger_event(move_bookmark_event_id, bm, dest);
|
||||||
destb ? (struct bookmark *) destb
|
|
||||||
: dest);
|
|
||||||
|
|
||||||
foreach (item, bookmark_browser.dialogs) {
|
foreach (item, bookmark_browser.dialogs) {
|
||||||
struct widget_data *widget_data;
|
struct widget_data *widget_data;
|
||||||
@ -385,14 +380,16 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
|
|||||||
|
|
||||||
del_from_list(bm->box_item);
|
del_from_list(bm->box_item);
|
||||||
del_from_list(bm);
|
del_from_list(bm);
|
||||||
add_at_pos(destb ? (struct bookmark *) destb
|
if (insert_as_child) {
|
||||||
: dest,
|
add_to_list(dest->child, bm);
|
||||||
bm);
|
add_to_list(dest->box_item->child, bm->box_item);
|
||||||
add_at_pos(desti ? (struct listbox_item *) desti
|
bm->root = dest;
|
||||||
: dest->box_item,
|
insert_as_child = 0;
|
||||||
bm->box_item);
|
} else {
|
||||||
|
add_at_pos(dest, bm);
|
||||||
bm->root = destb ? dest : dest->root;
|
add_at_pos(dest->box_item, bm->box_item);
|
||||||
|
bm->root = dest->root;
|
||||||
|
}
|
||||||
|
|
||||||
bm->box_item->depth = bm->root
|
bm->box_item->depth = bm->root
|
||||||
? bm->root->box_item->depth + 1
|
? bm->root->box_item->depth + 1
|
||||||
@ -402,7 +399,6 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
|
|||||||
update_depths(bm->box_item);
|
update_depths(bm->box_item);
|
||||||
|
|
||||||
dest = bm;
|
dest = bm;
|
||||||
desti = destb = NULL;
|
|
||||||
|
|
||||||
/* We don't want to care about anything marked inside
|
/* We don't want to care about anything marked inside
|
||||||
* of the marked folder, let's move it as a whole
|
* of the marked folder, let's move it as a whole
|
||||||
@ -412,7 +408,7 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bm->box_item->type == BI_FOLDER) {
|
if (bm->box_item->type == BI_FOLDER) {
|
||||||
result |= do_move_bookmark(dest, destb, desti,
|
result |= do_move_bookmark(dest, insert_as_child,
|
||||||
&bm->child, box);
|
&bm->child, box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -426,15 +422,14 @@ push_move_button(struct dialog_data *dlg_data,
|
|||||||
{
|
{
|
||||||
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
||||||
struct bookmark *dest = NULL;
|
struct bookmark *dest = NULL;
|
||||||
struct list_head *destb = NULL, *desti = NULL;
|
int insert_as_child = 0;
|
||||||
enum move_bookmark_flags result;
|
enum move_bookmark_flags result;
|
||||||
|
|
||||||
if (!box->sel) return EVENT_PROCESSED; /* nowhere to move to */
|
if (!box->sel) return EVENT_PROCESSED; /* nowhere to move to */
|
||||||
|
|
||||||
dest = box->sel->udata;
|
dest = box->sel->udata;
|
||||||
if (box->sel->type == BI_FOLDER && box->sel->expanded) {
|
if (box->sel->type == BI_FOLDER && box->sel->expanded) {
|
||||||
destb = &((struct bookmark *) box->sel->udata)->child;
|
insert_as_child = 1;
|
||||||
desti = &box->sel->child;
|
|
||||||
}
|
}
|
||||||
/* Avoid recursion headaches (prevents moving a folder into itself). */
|
/* Avoid recursion headaches (prevents moving a folder into itself). */
|
||||||
move_cache_root_avoid = NULL;
|
move_cache_root_avoid = NULL;
|
||||||
@ -448,7 +443,7 @@ push_move_button(struct dialog_data *dlg_data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = do_move_bookmark(dest, destb, desti, &bookmarks, box);
|
result = do_move_bookmark(dest, insert_as_child, &bookmarks, box);
|
||||||
if (result & MOVE_BOOKMARK_MOVED) {
|
if (result & MOVE_BOOKMARK_MOVED) {
|
||||||
bookmarks_set_dirty();
|
bookmarks_set_dirty();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user