17
16
#include "bfu/msgbox.h"
18
17
#include "bfu/text.h"
19
18
#include "config/kbdbind.h"
20
#include "dialogs/download.h"
21
19
#include "intl/gettext/libintl.h"
22
20
#include "protocol/uri.h"
23
#include "sched/task.h"
21
#include "session/task.h"
24
22
#include "terminal/screen.h"
25
23
#include "terminal/tab.h"
26
24
#include "terminal/terminal.h"
84
82
static inline struct listbox_item *
85
83
replace_listbox_item(struct listbox_item *item, struct listbox_data *data)
87
struct listbox_item *box;
89
box = traverse_listbox_items_list(item, data, 1, 1, NULL, NULL);
90
if (item != box) return box;
92
box = traverse_listbox_items_list(item, data, -1, 1, NULL, NULL);
93
return (item == box) ? NULL : box;
85
struct listbox_item *new_item;
87
new_item = traverse_listbox_items_list(item, data, 1, 1, NULL, NULL);
88
if (item != new_item) return new_item;
90
new_item = traverse_listbox_items_list(item, data, -1, 1, NULL, NULL);
91
return (item == new_item) ? NULL : new_item;
101
99
assert(box_item && list_empty(box_item->child));
103
/* If we are removing the top or the selected box we have to figure out
106
foreach (box_data, browser->boxes) {
107
if (box_data->sel == box_item)
108
box_data->sel = replace_listbox_item(box_item, box_data);
110
if (box_data->top == box_item)
111
box_data->top = replace_listbox_item(box_item, box_data);
114
101
/* The option dialog needs this test */
115
if (box_item->next) del_from_list(box_item);
102
if (box_item->next) {
103
/* If we are removing the top or the selected box
104
* we have to figure out a replacement. */
106
foreach (box_data, browser->boxes) {
107
if (box_data->sel == box_item)
108
box_data->sel = replace_listbox_item(box_item,
111
if (box_data->top == box_item)
112
box_data->top = replace_listbox_item(box_item,
116
del_from_list(box_item);
118
update_hierbox_browser(browser);
117
121
mem_free(box_item);
118
update_hierbox_browser(browser);
123
recursively_set_expanded(struct listbox_item *box, int expanded)
126
recursively_set_expanded(struct listbox_item *item, int expanded)
125
128
struct listbox_item *child;
127
if (box->type != BI_FOLDER)
130
if (item->type != BI_FOLDER)
130
box->expanded = expanded;
133
item->expanded = expanded;
132
foreach (child, box->child)
135
foreach (child, item->child)
133
136
recursively_set_expanded(child, expanded);
137
test_search(struct listbox_item *item, void *data_, int *offset)
139
struct listbox_context *listbox_context = data_;
141
listbox_context->offset--;
143
if (item == listbox_context->box->sel) *offset = 0;
147
static t_handler_event_status
139
static widget_handler_status_T
148
140
hierbox_ev_kbd(struct dialog_data *dlg_data)
150
142
struct hierbox_browser *browser = dlg_data->dlg->udata2;
152
144
struct widget *widget = widget_data->widget;
153
145
struct listbox_data *box;
154
146
struct listbox_item *selected;
155
enum menu_action action;
147
enum menu_action action_id;
156
148
struct term_event *ev = dlg_data->term_event;
158
150
/* Check if listbox has something to say to this */
164
156
box = get_dlg_listbox_data(dlg_data);
165
157
selected = box->sel;
166
action = kbd_action(KEYMAP_MENU, ev, NULL);
158
action_id = kbd_action(KEYMAP_MENU, ev, NULL);
168
if (action == ACT_MENU_SELECT) {
160
if (action_id == ACT_MENU_SELECT) {
169
161
if (!selected) return EVENT_PROCESSED;
170
162
if (selected->type != BI_FOLDER)
171
163
return EVENT_NOT_PROCESSED;
172
164
selected->expanded = !selected->expanded;
174
} else if (action == ACT_MENU_UNEXPAND) {
166
} else if (action_id == ACT_MENU_UNEXPAND) {
175
167
/* Recursively unexpand all folders */
176
168
if (!selected) return EVENT_PROCESSED;
184
176
struct listbox_item *root = box->ops->get_root(selected);
187
struct listbox_context ctx;
189
memset(&ctx, 0, sizeof(ctx));
193
traverse_listbox_items_list(
196
listbox_sel_move(dlg_data->widgets_data,
179
listbox_sel(widget_data, root);
200
182
} else if (selected->type == BI_FOLDER) {
201
183
recursively_set_expanded(selected, 0);
204
} else if (action == ACT_MENU_EXPAND) {
186
} else if (action_id == ACT_MENU_EXPAND) {
205
187
/* Recursively expand all folders */
207
189
if (!selected || box->sel->type != BI_FOLDER)
224
206
if (browser->expansion_callback)
225
207
browser->expansion_callback();
227
display_widget(dlg_data, dlg_data->widgets_data);
209
display_widget(dlg_data, widget_data);
229
211
return EVENT_PROCESSED;
232
static t_handler_event_status
214
static widget_handler_status_T
233
215
hierbox_ev_init(struct dialog_data *dlg_data)
235
217
struct hierbox_browser *browser = dlg_data->dlg->udata2;
251
233
return EVENT_NOT_PROCESSED; /* FIXME: is this correct ? --Zas */
254
static t_handler_event_status
236
static widget_handler_status_T
255
237
hierbox_ev_abort(struct dialog_data *dlg_data)
257
239
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
281
263
* unselectable, instead one of the buttons below is always active. So, we
282
264
* always first let the listbox catch the keypress and handle it, and if it
283
265
* doesn't care, we pass it on to the button. */
284
static t_handler_event_status
266
static widget_handler_status_T
285
267
hierbox_dialog_event_handler(struct dialog_data *dlg_data)
287
269
struct term_event *ev = dlg_data->term_event;
466
448
struct listbox_item *item;
468
450
foreach (item, root->child) {
471
451
if (item->type == BI_FOLDER) {
472
452
recursively_goto_listbox(ses, item, box);
455
} else if (item->type == BI_LEAF) {
456
struct uri *uri = box->ops->get_uri(item);
460
open_uri_in_new_tab(ses, uri, 1, 0);
476
uri = box->ops->get_uri(item);
479
open_uri_in_new_tab(ses, uri, 1, 0);
489
471
if (item->marked) {
490
472
struct session *ses = context->dlg_data->dlg->udata;
491
473
struct listbox_data *box = context->box;
494
475
if (item->type == BI_FOLDER) {
495
476
recursively_goto_listbox(ses, item, box);
479
} else if (item->type == BI_LEAF) {
480
struct uri *uri = box->ops->get_uri(item);
484
open_uri_in_new_tab(ses, uri, 1, 0);
499
uri = box->ops->get_uri(item);
502
open_uri_in_new_tab(ses, uri, 1, 0);
509
t_handler_event_status
492
widget_handler_status_T
510
493
push_hierbox_goto_button(struct dialog_data *dlg_data,
511
494
struct widget_data *button)