~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/bfu/hierbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Hiearchic listboxes browser dialog commons */
2
 
/* $Id: hierbox.c,v 1.201.2.7 2005/05/01 21:05:57 jonas Exp $ */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
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)
86
84
{
87
 
        struct listbox_item *box;
88
 
 
89
 
        box = traverse_listbox_items_list(item, data, 1, 1, NULL, NULL);
90
 
        if (item != box) return box;
91
 
 
92
 
        box = traverse_listbox_items_list(item, data, -1, 1, NULL, NULL);
93
 
        return (item == box) ? NULL : box;
 
85
        struct listbox_item *new_item;
 
86
 
 
87
        new_item = traverse_listbox_items_list(item, data, 1, 1, NULL, NULL);
 
88
        if (item != new_item) return new_item;
 
89
 
 
90
        new_item = traverse_listbox_items_list(item, data, -1, 1, NULL, NULL);
 
91
        return (item == new_item) ? NULL : new_item;
94
92
}
95
93
 
96
94
void
100
98
 
101
99
        assert(box_item && list_empty(box_item->child));
102
100
 
103
 
        /* If we are removing the top or the selected box we have to figure out
104
 
         * a replacement. */
105
 
 
106
 
        foreach (box_data, browser->boxes) {
107
 
                if (box_data->sel == box_item)
108
 
                        box_data->sel = replace_listbox_item(box_item, box_data);
109
 
 
110
 
                if (box_data->top == box_item)
111
 
                        box_data->top = replace_listbox_item(box_item, box_data);
112
 
        }
113
 
 
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. */
 
105
 
 
106
                foreach (box_data, browser->boxes) {
 
107
                        if (box_data->sel == box_item)
 
108
                                box_data->sel = replace_listbox_item(box_item,
 
109
                                                                     box_data);
 
110
 
 
111
                        if (box_data->top == box_item)
 
112
                                box_data->top = replace_listbox_item(box_item,
 
113
                                                                     box_data);
 
114
                }
 
115
 
 
116
                del_from_list(box_item);
 
117
 
 
118
                update_hierbox_browser(browser);
 
119
        }
116
120
 
117
121
        mem_free(box_item);
118
 
        update_hierbox_browser(browser);
119
122
}
120
123
 
121
124
 
122
125
static void
123
 
recursively_set_expanded(struct listbox_item *box, int expanded)
 
126
recursively_set_expanded(struct listbox_item *item, int expanded)
124
127
{
125
128
        struct listbox_item *child;
126
129
 
127
 
        if (box->type != BI_FOLDER)
 
130
        if (item->type != BI_FOLDER)
128
131
                return;
129
132
 
130
 
        box->expanded = expanded;
 
133
        item->expanded = expanded;
131
134
 
132
 
        foreach (child, box->child)
 
135
        foreach (child, item->child)
133
136
                recursively_set_expanded(child, expanded);
134
137
}
135
138
 
136
 
static int
137
 
test_search(struct listbox_item *item, void *data_, int *offset)
138
 
{
139
 
        struct listbox_context *listbox_context = data_;
140
 
 
141
 
        listbox_context->offset--;
142
 
 
143
 
        if (item == listbox_context->box->sel) *offset = 0;
144
 
        return 0;
145
 
}
146
 
 
147
 
static t_handler_event_status
 
139
static widget_handler_status_T
148
140
hierbox_ev_kbd(struct dialog_data *dlg_data)
149
141
{
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;
157
149
 
158
150
        /* Check if listbox has something to say to this */
163
155
 
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);
167
159
 
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;
173
165
 
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;
177
169
 
184
176
                        struct listbox_item *root = box->ops->get_root(selected);
185
177
 
186
178
                        if (root) {
187
 
                                struct listbox_context ctx;
188
 
 
189
 
                                memset(&ctx, 0, sizeof(ctx));
190
 
                                ctx.box = box;
191
 
                                ctx.offset = 1;
192
 
 
193
 
                                traverse_listbox_items_list(
194
 
                                                root, box, 0, 1,
195
 
                                                test_search, &ctx);
196
 
                                listbox_sel_move(dlg_data->widgets_data,
197
 
                                                 ctx.offset);
 
179
                                listbox_sel(widget_data, root);
198
180
                        }
199
181
 
200
182
                } else if (selected->type == BI_FOLDER) {
201
183
                        recursively_set_expanded(selected, 0);
202
184
                }
203
185
 
204
 
        } else if (action == ACT_MENU_EXPAND) {
 
186
        } else if (action_id == ACT_MENU_EXPAND) {
205
187
                /* Recursively expand all folders */
206
188
 
207
189
                if (!selected || box->sel->type != BI_FOLDER)
209
191
 
210
192
                recursively_set_expanded(box->sel, 1);
211
193
 
212
 
        } else if (action == ACT_MENU_SEARCH) {
 
194
        } else if (action_id == ACT_MENU_SEARCH) {
213
195
                if (!box->ops->match)
214
196
                        return EVENT_NOT_PROCESSED;
215
197
 
224
206
        if (browser->expansion_callback)
225
207
                browser->expansion_callback();
226
208
 
227
 
        display_widget(dlg_data, dlg_data->widgets_data);
 
209
        display_widget(dlg_data, widget_data);
228
210
 
229
211
        return EVENT_PROCESSED;
230
212
}
231
213
 
232
 
static t_handler_event_status
 
214
static widget_handler_status_T
233
215
hierbox_ev_init(struct dialog_data *dlg_data)
234
216
{
235
217
        struct hierbox_browser *browser = dlg_data->dlg->udata2;
251
233
        return EVENT_NOT_PROCESSED;     /* FIXME: is this correct ? --Zas */
252
234
}
253
235
 
254
 
static t_handler_event_status
 
236
static widget_handler_status_T
255
237
hierbox_ev_abort(struct dialog_data *dlg_data)
256
238
{
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)
286
268
{
287
269
        struct term_event *ev = dlg_data->term_event;
420
402
 
421
403
/* Info action */
422
404
 
423
 
t_handler_event_status
 
405
widget_handler_status_T
424
406
push_hierbox_info_button(struct dialog_data *dlg_data, struct widget_data *button)
425
407
{
426
408
        struct listbox_data *box = get_dlg_listbox_data(dlg_data);
466
448
        struct listbox_item *item;
467
449
 
468
450
        foreach (item, root->child) {
469
 
                struct uri *uri;
470
 
 
471
451
                if (item->type == BI_FOLDER) {
472
452
                        recursively_goto_listbox(ses, item, box);
473
453
                        continue;
 
454
 
 
455
                } else if (item->type == BI_LEAF) {
 
456
                        struct uri *uri = box->ops->get_uri(item);
 
457
 
 
458
                        if (!uri) continue;
 
459
 
 
460
                        open_uri_in_new_tab(ses, uri, 1, 0);
 
461
                        done_uri(uri);
474
462
                }
475
 
 
476
 
                uri = box->ops->get_uri(item);
477
 
                if (!uri) continue;
478
 
 
479
 
                open_uri_in_new_tab(ses, uri, 1, 0);
480
 
                done_uri(uri);
481
463
        }
482
464
}
483
465
 
489
471
        if (item->marked) {
490
472
                struct session *ses = context->dlg_data->dlg->udata;
491
473
                struct listbox_data *box = context->box;
492
 
                struct uri *uri;
493
474
 
494
475
                if (item->type == BI_FOLDER) {
495
476
                        recursively_goto_listbox(ses, item, box);
496
477
                        return 0;
 
478
 
 
479
                } else if (item->type == BI_LEAF) {
 
480
                        struct uri *uri = box->ops->get_uri(item);
 
481
 
 
482
                        if (!uri) return 0;
 
483
 
 
484
                        open_uri_in_new_tab(ses, uri, 1, 0);
 
485
                        done_uri(uri);
497
486
                }
498
 
 
499
 
                uri = box->ops->get_uri(item);
500
 
                if (!uri) return 0;
501
 
 
502
 
                open_uri_in_new_tab(ses, uri, 1, 0);
503
 
                done_uri(uri);
504
487
        }
505
488
 
506
489
        return 0;
507
490
}
508
491
 
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)
512
495
{
530
513
        } else if (box->sel->type == BI_FOLDER) {
531
514
                recursively_goto_listbox(ses, box->sel, box);
532
515
 
533
 
        } else {
 
516
        } else if (box->sel->type == BI_LEAF) {
534
517
                struct uri *uri = box->ops->get_uri(box->sel);
535
518
 
536
519
                if (uri) {
537
520
                        goto_uri(ses, uri);
538
521
                        done_uri(uri);
539
522
                }
 
523
 
 
524
        } else {
 
525
                mem_free(context);
 
526
                return EVENT_PROCESSED;
540
527
        }
541
528
 
542
529
        mem_free(context);
701
688
                listbox_sel_move(context->widget_data, -1);
702
689
}
703
690
 
704
 
t_handler_event_status
 
691
widget_handler_status_T
705
692
push_hierbox_delete_button(struct dialog_data *dlg_data,
706
693
                           struct widget_data *button)
707
694
{
825
812
                                    delete_unused, context);
826
813
}
827
814
 
828
 
t_handler_event_status
 
815
widget_handler_status_T
829
816
push_hierbox_clear_button(struct dialog_data *dlg_data,
830
817
                          struct widget_data *button)
831
818
{
950
937
        mem_free(context);
951
938
}
952
939
 
953
 
t_handler_event_status
 
940
widget_handler_status_T
954
941
push_hierbox_search_button(struct dialog_data *dlg_data,
955
942
                           struct widget_data *button)
956
943
{