From f287d5aa31f0dd71eb2335f84bec5325c5384028 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Thu, 15 Jun 2006 21:14:51 +0000 Subject: [PATCH] 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. [ Backported from commit 6f98f5fd96c8ede06a24a314af95a12cb9b9eb91 in ELinks 0.12.GIT. --KON ] --- src/bfu/hierbox.c | 7 ------- src/bfu/hierbox.h | 6 ++++++ src/bookmarks/dialogs.c | 23 +++++++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/bfu/hierbox.c b/src/bfu/hierbox.c index c30d0747f..30feffe26 100644 --- a/src/bfu/hierbox.c +++ b/src/bfu/hierbox.c @@ -24,13 +24,6 @@ #include "terminal/terminal.h" -struct hierbox_dialog_list_item { - LIST_HEAD(struct hierbox_dialog_list_item); - - struct dialog_data *dlg_data; -}; - - void update_hierbox_browser(struct hierbox_browser *browser) { diff --git a/src/bfu/hierbox.h b/src/bfu/hierbox.h index bf6eadf67..eb17d4a65 100644 --- a/src/bfu/hierbox.h +++ b/src/bfu/hierbox.h @@ -50,6 +50,12 @@ struct hierbox_browser { 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 *box_item); void update_hierbox_browser(struct hierbox_browser *browser); diff --git a/src/bookmarks/dialogs.c b/src/bookmarks/dialogs.c index 1d9df2af6..0de616455 100644 --- a/src/bookmarks/dialogs.c +++ b/src/bookmarks/dialogs.c @@ -367,21 +367,25 @@ do_move_bookmark(struct bookmark *dest, struct list_head *destb, foreachsafe (bm, next, *src) { if (bm != dest /* prevent moving a folder into itself */ && bm->box_item->marked && bm != move_cache_root_avoid) { + struct hierbox_dialog_list_item *item; + bm->box_item->marked = 0; trigger_event(move_bookmark_event_id, bm, destb ? (struct bookmark *) destb : dest); - if (box->top == bm->box_item) { - /* It's theoretically impossible that bm->next - * would be invalid (point to list_head), as it - * 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; - } + foreach (item, bookmark_browser.dialogs) { + struct widget_data *widget_data; + struct listbox_data *box2; + 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); 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 bookmark *dest = NULL; struct list_head *destb = NULL, *desti = NULL; - struct widget_data *widget_data = dlg_data->widgets_data; if (!box->sel) return EVENT_PROCESSED; /* nowhere to move to */ @@ -451,7 +454,7 @@ push_move_button(struct dialog_data *dlg_data, #ifdef BOOKMARKS_RESAVE write_bookmarks(); #endif - display_widget(dlg_data, widget_data); + update_hierbox_browser(&bookmark_browser); return EVENT_PROCESSED; }