Sync OpenBSD patchset 1098:

Use a helper function to fire choose callback.
This commit is contained in:
Tiago Cunha 2012-04-24 16:21:43 +00:00
parent 6df8953f4f
commit c8c6a23d66

View File

@ -29,6 +29,7 @@ void window_choose_key(struct window_pane *, struct session *, int);
void window_choose_mouse(
struct window_pane *, struct session *, struct mouse_event *);
void window_choose_fire_callback(struct window_pane *, int);
void window_choose_redraw_screen(struct window_pane *);
void window_choose_write_line(
struct window_pane *, struct screen_write_ctx *, u_int);
@ -169,6 +170,20 @@ window_choose_resize(struct window_pane *wp, u_int sx, u_int sy)
window_choose_redraw_screen(wp);
}
void
window_choose_fire_callback(struct window_pane *wp, int idx)
{
struct window_choose_mode_data *data = wp->modedata;
const struct window_mode *oldmode;
oldmode = wp->mode;
wp->mode = NULL;
data->callbackfn(data->data, idx);
wp->mode = oldmode;
}
/* ARGSUSED */
void
window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
@ -184,12 +199,12 @@ window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
switch (mode_key_lookup(&data->mdata, key)) {
case MODEKEYCHOICE_CANCEL:
data->callbackfn(data->data, -1);
window_choose_fire_callback(wp, -1);
window_pane_reset_mode(wp);
break;
case MODEKEYCHOICE_CHOOSE:
item = &ARRAY_ITEM(&data->list, data->selected);
data->callbackfn(data->data, item->idx);
window_choose_fire_callback(wp, item->idx);
window_pane_reset_mode(wp);
break;
case MODEKEYCHOICE_UP:
@ -295,7 +310,7 @@ window_choose_key(struct window_pane *wp, unused struct session *sess, int key)
data->selected = idx;
item = &ARRAY_ITEM(&data->list, data->selected);
data->callbackfn(data->data, item->idx);
window_choose_fire_callback(wp, item->idx);
window_pane_reset_mode(wp);
break;
}
@ -324,7 +339,7 @@ window_choose_mouse(
data->selected = idx;
item = &ARRAY_ITEM(&data->list, data->selected);
data->callbackfn(data->data, item->idx);
window_choose_fire_callback(wp, item->idx);
window_pane_reset_mode(wp);
}