From 48e6ebbe1ec8bb2631bbe5afe7c67ea0198d43d4 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 23 Apr 2012 22:40:47 +0000 Subject: [PATCH] Use a helper function to fire choose callback. --- window-choose.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/window-choose.c b/window-choose.c index ccd09afc..70eb651f 100644 --- a/window-choose.c +++ b/window-choose.c @@ -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); }