1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Bookmarks: Fix update after move

do_move_bookmark was only updating the selection in the bookmarks manager
window in which the Move button was pressed. Now all windows are updated.

This patch also prevents a crash when the first item that was displayed
in a box was the last child of a folder and was being moved (the comment
removed in this patch was incorrect in assuming that bm->box->next must
be valid because it neglected to account for non-root children).

This change required that I move the definition of struct
hierbox_dialog_list_item from src/bfu/hierbox.c to src/bfu/hierbox.h.

Thanks to Kalle Olavi Niemitalo for finding both the update problem
and the crash.
This commit is contained in:
Miciah Dashiel Butler Masters 2006-06-15 21:14:51 +00:00 committed by Miciah Dashiel Butler Masters
parent fed0d6bd54
commit 6f98f5fd96
3 changed files with 19 additions and 17 deletions

View File

@ -24,13 +24,6 @@
#include "terminal/terminal.h" #include "terminal/terminal.h"
struct hierbox_dialog_list_item {
LIST_HEAD(struct hierbox_dialog_list_item);
struct dialog_data *dlg_data;
};
void void
update_hierbox_browser(struct hierbox_browser *browser) update_hierbox_browser(struct hierbox_browser *browser)
{ {

View File

@ -50,6 +50,12 @@ struct hierbox_browser {
ops, \ ops, \
} }
struct hierbox_dialog_list_item {
LIST_HEAD(struct hierbox_dialog_list_item);
struct dialog_data *dlg_data;
};
void done_listbox_item(struct hierbox_browser *browser, struct listbox_item *item); void done_listbox_item(struct hierbox_browser *browser, struct listbox_item *item);
void update_hierbox_browser(struct hierbox_browser *browser); void update_hierbox_browser(struct hierbox_browser *browser);

View File

@ -363,6 +363,8 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
/* Prevent moving a folder into itself. */ /* Prevent moving a folder into itself. */
result |= MOVE_BOOKMARK_CYCLE; result |= MOVE_BOOKMARK_CYCLE;
} else { } else {
struct hierbox_dialog_list_item *item;
result |= MOVE_BOOKMARK_MOVED; result |= MOVE_BOOKMARK_MOVED;
bm->box_item->marked = 0; bm->box_item->marked = 0;
@ -370,15 +372,17 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb,
destb ? (struct bookmark *) destb destb ? (struct bookmark *) destb
: dest); : dest);
if (box->top == bm->box_item) { foreach (item, bookmark_browser.dialogs) {
/* It's theoretically impossible that bm->next struct widget_data *widget_data;
* would be invalid (point to list_head), as it struct listbox_data *box2;
* would be case only when there would be only
* one item in the list, and then bm != dest
* will save us already. */
box->top = bm->box_item->next;
}
widget_data = item->dlg_data->widgets_data;
box2 = get_listbox_widget_data(widget_data);
if (box2->top == bm->box_item)
listbox_sel_move(widget_data, 1);
}
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 add_at_pos(destb ? (struct bookmark *) destb
@ -423,7 +427,6 @@ 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; struct list_head *destb = NULL, *desti = NULL;
struct widget_data *widget_data = dlg_data->widgets_data;
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 */
@ -452,7 +455,7 @@ push_move_button(struct dialog_data *dlg_data,
#ifdef BOOKMARKS_RESAVE #ifdef BOOKMARKS_RESAVE
write_bookmarks(); write_bookmarks();
#endif #endif
display_widget(dlg_data, widget_data); /* the hierbox */ update_hierbox_browser(&bookmark_browser);
} }
#ifndef CONFIG_SMALL #ifndef CONFIG_SMALL
else if (result & MOVE_BOOKMARK_CYCLE) { else if (result & MOVE_BOOKMARK_CYCLE) {