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

Merge branch 'master' into otr

This commit is contained in:
James Booth 2013-09-26 00:43:31 +01:00
commit 3512114cf1
6 changed files with 138 additions and 0 deletions

View File

@ -1289,6 +1289,8 @@ cons_navigation_help(void)
cons_show("");
cons_show("Alt-1 : This console window.");
cons_show("Alt-2..Alt-0 : Chat windows.");
cons_show("Alt-LEFT : Previous chat window");
cons_show("Alt-RIGHT : Next chat window");
cons_show("F1 : This console window.");
cons_show("F2..F10 : Chat windows.");
cons_show("UP, DOWN : Navigate input history.");

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

@ -40,6 +40,7 @@
#include "log.h"
#include "profanity.h"
#include "ui/ui.h"
#include "ui/windows.h"
#include "xmpp/xmpp.h"
#define _inp_win_refresh() prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1)
@ -359,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) {
@ -592,6 +603,12 @@ _handle_alt_key(char *input, int *size, int key)
case '0':
ui_switch_win(0);
break;
case KEY_LEFT:
ui_previous_win();
break;
case KEY_RIGHT:
ui_next_win();
break;
case 263:
case 127:
input[*size] = '\0';

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);