version 1.24, 2012/08/14 09:17:14 |
version 1.25, 2012/08/27 21:29:23 |
|
|
void (*freefn)(struct window_choose_data *); |
void (*freefn)(struct window_choose_data *); |
}; |
}; |
|
|
int window_choose_index_key(int); |
int window_choose_key_index(struct window_choose_mode_data *, u_int); |
|
int window_choose_index_key(struct window_choose_mode_data *, int); |
void window_choose_prompt_input(enum window_choose_input_type, |
void window_choose_prompt_input(enum window_choose_input_type, |
const char *, struct window_pane *, int); |
const char *, struct window_pane *, int); |
|
|
|
|
item->wcd = wcd; |
item->wcd = wcd; |
item->pos = ARRAY_LENGTH(&data->list) - 1; |
item->pos = ARRAY_LENGTH(&data->list) - 1; |
|
|
data->width = snprintf (tmp, sizeof tmp , "%u", item->pos); |
data->width = xsnprintf (tmp, sizeof tmp , "%u", item->pos); |
} |
} |
|
|
void |
void |
|
|
|
|
items = ARRAY_LENGTH(&data->list); |
items = ARRAY_LENGTH(&data->list); |
|
|
switch (mode_key_lookup(&data->mdata, key)) { |
if (data->input_type == WINDOW_CHOOSE_GOTO_ITEM) { |
case MODEKEYCHOICE_CANCEL: |
switch (mode_key_lookup(&data->mdata, key)) { |
window_choose_fire_callback(wp, NULL); |
case MODEKEYCHOICE_CANCEL: |
window_pane_reset_mode(wp); |
data->input_type = WINDOW_CHOOSE_NORMAL; |
break; |
window_choose_redraw_screen(wp); |
case MODEKEYCHOICE_CHOOSE: |
|
switch (data->input_type) { |
|
case WINDOW_CHOOSE_NORMAL: |
|
item = &ARRAY_ITEM(&data->list, data->selected); |
|
window_choose_fire_callback(wp, item->wcd); |
|
window_pane_reset_mode(wp); |
|
break; |
break; |
case WINDOW_CHOOSE_GOTO_ITEM: |
case MODEKEYCHOICE_CHOOSE: |
n = strtonum(data->input_str, 0, INT_MAX, NULL); |
n = strtonum(data->input_str, 0, INT_MAX, NULL); |
if (n > items - 1) |
if (n > items - 1) { |
|
data->input_type = WINDOW_CHOOSE_NORMAL; |
|
window_choose_redraw_screen(wp); |
break; |
break; |
|
} |
item = &ARRAY_ITEM(&data->list, n); |
item = &ARRAY_ITEM(&data->list, n); |
window_choose_fire_callback(wp, item->wcd); |
window_choose_fire_callback(wp, item->wcd); |
window_pane_reset_mode(wp); |
window_pane_reset_mode(wp); |
break; |
break; |
|
case MODEKEYCHOICE_BACKSPACE: |
|
input_len = strlen(data->input_str); |
|
if (input_len > 0) |
|
data->input_str[input_len - 1] = '\0'; |
|
window_choose_redraw_screen(wp); |
|
break; |
|
default: |
|
if (key < '0' || key > '9') |
|
break; |
|
window_choose_prompt_input(WINDOW_CHOOSE_GOTO_ITEM, |
|
"Goto Item", wp, key); |
|
break; |
} |
} |
|
return; |
|
} |
|
|
|
switch (mode_key_lookup(&data->mdata, key)) { |
|
case MODEKEYCHOICE_CANCEL: |
|
window_choose_fire_callback(wp, NULL); |
|
window_pane_reset_mode(wp); |
break; |
break; |
|
case MODEKEYCHOICE_CHOOSE: |
|
item = &ARRAY_ITEM(&data->list, data->selected); |
|
window_choose_fire_callback(wp, item->wcd); |
|
window_pane_reset_mode(wp); |
|
break; |
case MODEKEYCHOICE_UP: |
case MODEKEYCHOICE_UP: |
if (items == 0) |
if (items == 0) |
break; |
break; |
|
|
window_choose_redraw_screen(wp); |
window_choose_redraw_screen(wp); |
break; |
break; |
case MODEKEYCHOICE_STARTNUMBERPREFIX: |
case MODEKEYCHOICE_STARTNUMBERPREFIX: |
if (key < '0' && key > '9') |
key &= KEYC_MASK_KEY; |
|
if (key < '0' || key > '9') |
break; |
break; |
|
window_choose_prompt_input(WINDOW_CHOOSE_GOTO_ITEM, |
/* |
"Goto Item", wp, key); |
* If there's less than ten items (0-9) then pressing a number |
|
* will automatically select that item; otherwise, prompt for |
|
* the item to go to. |
|
*/ |
|
if (ARRAY_LENGTH(&data->list) - 1 <= 9) { |
|
idx = window_choose_index_key(key); |
|
if (idx < 0 || (u_int) idx >= ARRAY_LENGTH(&data->list)) |
|
break; |
|
data->selected = idx; |
|
|
|
item = &ARRAY_ITEM(&data->list, data->selected); |
|
window_choose_fire_callback(wp, item->wcd); |
|
window_pane_reset_mode(wp); |
|
} else { |
|
window_choose_prompt_input( |
|
WINDOW_CHOOSE_GOTO_ITEM, "Goto item", wp, key); |
|
} |
|
break; |
break; |
default: |
default: |
|
idx = window_choose_index_key(data, key); |
|
if (idx < 0 || (u_int) idx >= ARRAY_LENGTH(&data->list)) |
|
break; |
|
data->selected = idx; |
|
|
|
item = &ARRAY_ITEM(&data->list, data->selected); |
|
window_choose_fire_callback(wp, item->wcd); |
|
window_pane_reset_mode(wp); |
break; |
break; |
} |
} |
} |
} |
|
|
struct screen *s = &data->screen; |
struct screen *s = &data->screen; |
struct grid_cell gc; |
struct grid_cell gc; |
size_t last, xoff = 0; |
size_t last, xoff = 0; |
char hdr[32]; |
char hdr[32], label[32]; |
int utf8flag; |
int utf8flag, key; |
|
|
if (data->callbackfn == NULL) |
if (data->callbackfn == NULL) |
fatalx("called before callback assigned"); |
fatalx("called before callback assigned"); |
|
|
if (item->wcd->wl != NULL && |
if (item->wcd->wl != NULL && |
item->wcd->wl->flags & WINLINK_ALERTFLAGS) |
item->wcd->wl->flags & WINLINK_ALERTFLAGS) |
gc.attr |= GRID_ATTR_BRIGHT; |
gc.attr |= GRID_ATTR_BRIGHT; |
screen_write_nputs(ctx, screen_size_x(s) - 1, |
|
&gc, utf8flag, "(%*d) %s", data->width, |
|
item->pos, item->name); |
|
|
|
|
key = window_choose_key_index(data, data->top + py); |
|
if (key != -1) |
|
xsnprintf (label, sizeof label, "(%c)", key); |
|
else |
|
xsnprintf (label, sizeof label, "(%d)", item->pos); |
|
screen_write_nputs(ctx, screen_size_x(s) - 1, &gc, utf8flag, |
|
"%*s %s", data->width + 2, label, item->name); |
} |
} |
while (s->cx < screen_size_x(s)) |
while (s->cx < screen_size_x(s)) |
screen_write_putc(ctx, &gc, ' '); |
screen_write_putc(ctx, &gc, ' '); |
|
|
} |
} |
|
|
int |
int |
window_choose_index_key(int key) |
window_choose_key_index(struct window_choose_mode_data *data, u_int idx) |
{ |
{ |
static const char keys[] = "0123456789"; |
static const char keys[] = "0123456789" |
|
"abcdefghijklmnopqrstuvwxyz" |
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
const char *ptr; |
const char *ptr; |
|
int mkey; |
|
|
|
for (ptr = keys; *ptr != '\0'; ptr++) { |
|
mkey = mode_key_lookup(&data->mdata, *ptr); |
|
if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER) |
|
continue; |
|
if (idx-- == 0) |
|
return (*ptr); |
|
} |
|
return (-1); |
|
} |
|
|
|
int |
|
window_choose_index_key(struct window_choose_mode_data *data, int key) |
|
{ |
|
static const char keys[] = "0123456789" |
|
"abcdefghijklmnopqrstuvwxyz" |
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
const char *ptr; |
|
int mkey; |
u_int idx = 0; |
u_int idx = 0; |
|
|
for (ptr = keys; *ptr != '\0'; ptr++) { |
for (ptr = keys; *ptr != '\0'; ptr++) { |
|
mkey = mode_key_lookup(&data->mdata, *ptr); |
|
if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER) |
|
continue; |
if (key == *ptr) |
if (key == *ptr) |
return (idx); |
return (idx); |
idx++; |
idx++; |