mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added /win navigation by jid, win title
This commit is contained in:
parent
393e690165
commit
e5447cf37b
@ -114,6 +114,7 @@ static char* _tls_autocomplete(ProfWin *window, const char *const input);
|
||||
static char* _script_autocomplete(ProfWin *window, const char *const input);
|
||||
static char* _subject_autocomplete(ProfWin *window, const char *const input);
|
||||
static char* _console_autocomplete(ProfWin *window, const char *const input);
|
||||
static char* _win_autocomplete(ProfWin *window, const char *const input);
|
||||
|
||||
GHashTable *commands = NULL;
|
||||
|
||||
@ -789,12 +790,30 @@ static struct cmd_t command_defs[] =
|
||||
CMD_TAGS(
|
||||
CMD_TAG_UI)
|
||||
CMD_SYN(
|
||||
"/win <num>")
|
||||
"/win console",
|
||||
"/win <num>",
|
||||
"/win <barejid>",
|
||||
"/win <nick>",
|
||||
"/win <roomjid>",
|
||||
"/win <roomoccupantjid>",
|
||||
"/win xmlconsole")
|
||||
CMD_DESC(
|
||||
"Move to the specified window.")
|
||||
CMD_ARGS(
|
||||
{ "<num>", "Window number to display." })
|
||||
CMD_NOEXAMPLES
|
||||
{ "console", "Go to the Console window." },
|
||||
{ "<num>", "Go to specified window number." },
|
||||
{ "<barejid>", "Go to chat window with contact by JID if open." },
|
||||
{ "<nick>", "Go to chat window with contact by nickname if open." },
|
||||
{ "<roomjid>", "Go to chat room window with roomjid if open." },
|
||||
{ "<roomoccupantjid>", "Go to private chat roomjidoccupant if open." },
|
||||
{ "xmlconsole", "Go to the XML Console window if open." })
|
||||
CMD_EXAMPLES(
|
||||
"/win console",
|
||||
"/win 4",
|
||||
"/win friend@chat.org",
|
||||
"/win Eddie",
|
||||
"/win bigroom@conference.chat.org",
|
||||
"/win bigroom@conference.chat.org/bruce")
|
||||
},
|
||||
|
||||
{ "/wins",
|
||||
@ -2722,6 +2741,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
|
||||
bookmark_autocomplete_reset();
|
||||
prefs_reset_room_trigger_ac();
|
||||
win_reset_search_attempts();
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -2957,6 +2977,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
g_hash_table_insert(ac_funcs, "/script", _script_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/subject", _subject_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/console", _console_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/win", _win_autocomplete);
|
||||
|
||||
int len = strlen(input);
|
||||
char parsed[len+1];
|
||||
@ -4231,6 +4252,19 @@ _console_autocomplete(ProfWin *window, const char *const input)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
_win_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *found = NULL;
|
||||
|
||||
found = autocomplete_param_with_func(input, "/win", win_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
_subject_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <langinfo.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "chat_session.h"
|
||||
#include "command/commands.h"
|
||||
@ -1059,6 +1060,16 @@ cmd_wins(ProfWin *window, const char *const command, gchar **args)
|
||||
gboolean
|
||||
cmd_win(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
gboolean is_num = TRUE;
|
||||
int i = 0;
|
||||
for (i = 0; i < strlen(args[0]); i++) {
|
||||
if (!isdigit(args[0][i])) {
|
||||
is_num = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_num) {
|
||||
int num = atoi(args[0]);
|
||||
|
||||
ProfWin *focuswin = wins_get_by_num(num);
|
||||
@ -1067,6 +1078,14 @@ cmd_win(ProfWin *window, const char *const command, gchar **args)
|
||||
} else {
|
||||
ui_focus_win(focuswin);
|
||||
}
|
||||
} else {
|
||||
ProfWin *focuswin = wins_get_by_string(args[0]);
|
||||
if (!focuswin) {
|
||||
cons_show("Window \"%s\" does not exist.", args[0]);
|
||||
} else {
|
||||
ui_focus_win(focuswin);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
static GHashTable *windows;
|
||||
static int current;
|
||||
static Autocomplete wins_ac;
|
||||
|
||||
void
|
||||
wins_init(void)
|
||||
@ -60,6 +61,9 @@ wins_init(void)
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(1), console);
|
||||
|
||||
current = 1;
|
||||
|
||||
wins_ac = autocomplete_new();
|
||||
autocomplete_add(wins_ac, "console");
|
||||
}
|
||||
|
||||
ProfWin*
|
||||
@ -209,6 +213,56 @@ wins_get_by_num(int i)
|
||||
return g_hash_table_lookup(windows, GINT_TO_POINTER(i));
|
||||
}
|
||||
|
||||
ProfWin*
|
||||
wins_get_by_string(char *str)
|
||||
{
|
||||
if (g_strcmp0(str, "console") == 0) {
|
||||
ProfWin *conswin = wins_get_console();
|
||||
if (conswin) {
|
||||
return conswin;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strcmp0(str, "xmlconsole") == 0) {
|
||||
ProfXMLWin *xmlwin = wins_get_xmlconsole();
|
||||
if (xmlwin) {
|
||||
return (ProfWin*)xmlwin;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_chat(str);
|
||||
if (chatwin) {
|
||||
return (ProfWin*)chatwin;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
char *barejid = roster_barejid_from_name(str);
|
||||
if (barejid) {
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin) {
|
||||
return (ProfWin*)chatwin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProfMucWin *mucwin = wins_get_muc(str);
|
||||
if (mucwin) {
|
||||
return (ProfWin*)mucwin;
|
||||
}
|
||||
|
||||
ProfPrivateWin *privwin = wins_get_private(str);
|
||||
if (privwin) {
|
||||
return (ProfWin*)privwin;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ProfWin*
|
||||
wins_get_next(void)
|
||||
{
|
||||
@ -313,6 +367,50 @@ wins_close_by_num(int i)
|
||||
win_update_virtual(window);
|
||||
}
|
||||
|
||||
ProfWin *window = wins_get_by_num(i);
|
||||
if (window) {
|
||||
switch (window->type) {
|
||||
case WIN_CHAT:
|
||||
{
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
autocomplete_remove(wins_ac, chatwin->barejid);
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
const char* nick = p_contact_name(contact);
|
||||
if (nick) {
|
||||
autocomplete_remove(wins_ac, nick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case WIN_MUC:
|
||||
{
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
autocomplete_remove(wins_ac, mucwin->roomjid);
|
||||
break;
|
||||
}
|
||||
case WIN_PRIVATE:
|
||||
{
|
||||
ProfPrivateWin *privwin = (ProfPrivateWin*)window;
|
||||
autocomplete_remove(wins_ac, privwin->fulljid);
|
||||
break;
|
||||
}
|
||||
case WIN_XML:
|
||||
{
|
||||
autocomplete_remove(wins_ac, "xmlconsole");
|
||||
break;
|
||||
}
|
||||
case WIN_MUC_CONFIG:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_hash_table_remove(windows, GINT_TO_POINTER(i));
|
||||
status_bar_inactive(i);
|
||||
}
|
||||
@ -338,6 +436,7 @@ wins_new_xmlconsole(void)
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_xmlconsole();
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, "xmlconsole");
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -349,6 +448,16 @@ wins_new_chat(const char *const barejid)
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_chat(barejid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
|
||||
autocomplete_add(wins_ac, barejid);
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
const char* nick = p_contact_name(contact);
|
||||
if (nick) {
|
||||
autocomplete_add(wins_ac, nick);
|
||||
}
|
||||
}
|
||||
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -360,6 +469,7 @@ wins_new_muc(const char *const roomjid)
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_muc(roomjid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, roomjid);
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -382,6 +492,7 @@ wins_new_private(const char *const fulljid)
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_private(fulljid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, fulljid);
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -686,8 +797,21 @@ wins_create_summary(gboolean unread)
|
||||
return result;
|
||||
}
|
||||
|
||||
char*
|
||||
win_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(wins_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
win_reset_search_attempts(void)
|
||||
{
|
||||
autocomplete_reset(wins_ac);
|
||||
}
|
||||
|
||||
void
|
||||
wins_destroy(void)
|
||||
{
|
||||
g_hash_table_destroy(windows);
|
||||
autocomplete_free(wins_ac);
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ ProfWin* wins_get_current(void);
|
||||
void wins_set_current_by_num(int i);
|
||||
|
||||
ProfWin* wins_get_by_num(int i);
|
||||
ProfWin* wins_get_by_string(char *str);
|
||||
|
||||
ProfWin* wins_get_next(void);
|
||||
ProfWin* wins_get_previous(void);
|
||||
@ -81,4 +82,7 @@ gboolean wins_swap(int source_win, int target_win);
|
||||
void wins_hide_subwin(ProfWin *window);
|
||||
void wins_show_subwin(ProfWin *window);
|
||||
|
||||
char* win_autocomplete(const char *const search_str);
|
||||
void win_reset_search_attempts(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user