1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Next and previous windows, handle KEY_CODE_YES terms, jump empty wins

This commit is contained in:
James Booth 2013-09-26 00:25:04 +01:00
parent 8be4cd1f27
commit 2625630ff3
5 changed files with 131 additions and 16 deletions

View File

@ -615,6 +615,68 @@ ui_switch_win(const int i)
}
}
void
ui_next_win(void)
{
ui_current_page_off();
ProfWin *new_current = wins_get_next();
int i = wins_get_num(new_current);
wins_set_current_by_num(i);
ui_current_page_off();
new_current->unread = 0;
if (i == 1) {
title_bar_title();
status_bar_active(1);
} else {
PContact contact = roster_get_contact(new_current->from);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
title_bar_set_recipient(p_contact_name(contact));
} else {
title_bar_set_recipient(new_current->from);
}
} else {
title_bar_set_recipient(new_current->from);
}
title_bar_draw();;
status_bar_active(i);
}
wins_refresh_current();
}
void
ui_previous_win(void)
{
ui_current_page_off();
ProfWin *new_current = wins_get_previous();
int i = wins_get_num(new_current);
wins_set_current_by_num(i);
ui_current_page_off();
new_current->unread = 0;
if (i == 1) {
title_bar_title();
status_bar_active(1);
} else {
PContact contact = roster_get_contact(new_current->from);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
title_bar_set_recipient(p_contact_name(contact));
} else {
title_bar_set_recipient(new_current->from);
}
} else {
title_bar_set_recipient(new_current->from);
}
title_bar_draw();;
status_bar_active(i);
}
wins_refresh_current();
}
void
ui_clear_current(void)
{

View File

@ -360,6 +360,16 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
return 1;
// ALT-LEFT
} else if ((result == KEY_CODE_YES) && (ch == 537)) {
ui_previous_win();
return 1;
// ALT-RIGHT
} else if ((result == KEY_CODE_YES) && (ch == 552)) {
ui_next_win();
return 1;
// other editing keys
} else {
switch(ch) {
@ -560,8 +570,6 @@ _handle_alt_key(char *input, int *size, int key)
{
int end_del = getcurx(inp_win);
int start_del = end_del;
int current = wins_get_current_num();
int new;
switch (key)
{
@ -596,22 +604,10 @@ _handle_alt_key(char *input, int *size, int key)
ui_switch_win(0);
break;
case KEY_LEFT:
if (current == 0) {
new = 9;
} else {
new = current - 1;
}
ui_switch_win(new);
ui_previous_win();
break;
case KEY_RIGHT:
if (current == 9) {
new = 0;
} else {
new = current + 1;
}
ui_switch_win(new);
ui_next_win();
break;
case 263:
case 127:

View File

@ -52,6 +52,8 @@ void ui_idle(void);
void ui_handle_special_keys(const wint_t * const ch, const char * const inp,
const int size);
void ui_switch_win(const int i);
void ui_next_win(void);
void ui_previous_win(void);
unsigned long ui_get_idle_time(void);
void ui_reset_idle_time(void);
void ui_new_chat_win(const char * const to);

View File

@ -90,6 +90,59 @@ wins_get_by_num(int i)
return g_hash_table_lookup(windows, GINT_TO_POINTER(i));
}
ProfWin *
wins_get_next(void)
{
// get and sort win nums
GList *keys = g_hash_table_get_keys(windows);
keys = g_list_sort(keys, cmp_win_num);
GList *curr = keys;
// find our place in the list
while (curr != NULL) {
if (current == GPOINTER_TO_INT(curr->data)) {
break;
}
curr = g_list_next(curr);
}
// if there is a next window return it
curr = g_list_next(curr);
if (curr != NULL) {
return wins_get_by_num(GPOINTER_TO_INT(curr->data));
// otherwise return the first window (console)
} else {
return wins_get_console();
}
}
ProfWin *
wins_get_previous(void)
{
// get and sort win nums
GList *keys = g_hash_table_get_keys(windows);
keys = g_list_sort(keys, cmp_win_num);
GList *curr = keys;
// find our place in the list
while (curr != NULL) {
if (current == GPOINTER_TO_INT(curr->data)) {
break;
}
curr = g_list_next(curr);
}
// if there is a previous window return it
curr = g_list_previous(curr);
if (curr != NULL) {
return wins_get_by_num(GPOINTER_TO_INT(curr->data));
// otherwise return the last window
} else {
int new_num = GPOINTER_TO_INT(g_list_last(keys)->data);
return wins_get_by_num(new_num);
}
}
ProfWin *
wins_get_by_recipient(const char * const recipient)
{

View File

@ -28,6 +28,8 @@ ProfWin * wins_get_console(void);
ProfWin * wins_get_current(void);
void wins_set_current_by_num(int i);
ProfWin * wins_get_by_num(int i);
ProfWin * wins_get_next(void);
ProfWin * wins_get_previous(void);
ProfWin * wins_get_by_recipient(const char * const recipient);
int wins_get_num(ProfWin *window);
int wins_get_current_num(void);