mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added window title autocomplete to /close command
This commit is contained in:
parent
7938db0a25
commit
2e99df1ac2
@ -115,6 +115,7 @@ 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);
|
||||
static char* _close_autocomplete(ProfWin *window, const char *const input);
|
||||
|
||||
GHashTable *commands = NULL;
|
||||
|
||||
@ -808,7 +809,7 @@ static struct cmd_t command_defs[] =
|
||||
{ "<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." },
|
||||
{ "<roomoccupantjid>", "Go to private chat roomoccupantjid if open." },
|
||||
{ "xmlconsole", "Go to the XML Console window if open." })
|
||||
CMD_EXAMPLES(
|
||||
"/win console",
|
||||
@ -921,13 +922,24 @@ static struct cmd_t command_defs[] =
|
||||
CMD_TAGS(
|
||||
CMD_TAG_UI)
|
||||
CMD_SYN(
|
||||
"/close [<num>]",
|
||||
"/close",
|
||||
"/close <num>",
|
||||
"/close <barejid>",
|
||||
"/close <nick>",
|
||||
"/close <roomjid>",
|
||||
"/close <roomoccupantjid>",
|
||||
"/close xmlconsole",
|
||||
"/close all|read")
|
||||
CMD_DESC(
|
||||
"Close windows. "
|
||||
"Passing no argument closes the current window.")
|
||||
CMD_ARGS(
|
||||
{ "<num>", "Close the specified window." },
|
||||
{ "<num>", "Close specified window number." },
|
||||
{ "<barejid>", "Close chat window with contact by JID if open." },
|
||||
{ "<nick>", "Close chat window with contact by nickname if open." },
|
||||
{ "<roomjid>", "Close chat room window with roomjid if open." },
|
||||
{ "<roomoccupantjid>", "Close private chat roomoccupantjid if open." },
|
||||
{ "xmlconsole", "Close the XML Console window if open." },
|
||||
{ "all", "Close all windows." },
|
||||
{ "read", "Close all windows that have no unread messages." })
|
||||
CMD_NOEXAMPLES
|
||||
@ -1886,7 +1898,6 @@ static Autocomplete account_clear_ac;
|
||||
static Autocomplete account_default_ac;
|
||||
static Autocomplete account_status_ac;
|
||||
static Autocomplete disco_ac;
|
||||
static Autocomplete close_ac;
|
||||
static Autocomplete wins_ac;
|
||||
static Autocomplete roster_ac;
|
||||
static Autocomplete roster_show_ac;
|
||||
@ -2138,10 +2149,6 @@ cmd_init(void)
|
||||
autocomplete_add(account_status_ac, "dnd");
|
||||
autocomplete_add(account_status_ac, "last");
|
||||
|
||||
close_ac = autocomplete_new();
|
||||
autocomplete_add(close_ac, "read");
|
||||
autocomplete_add(close_ac, "all");
|
||||
|
||||
wins_ac = autocomplete_new();
|
||||
autocomplete_add(wins_ac, "unread");
|
||||
autocomplete_add(wins_ac, "prune");
|
||||
@ -2474,7 +2481,6 @@ cmd_uninit(void)
|
||||
autocomplete_free(account_default_ac);
|
||||
autocomplete_free(account_status_ac);
|
||||
autocomplete_free(disco_ac);
|
||||
autocomplete_free(close_ac);
|
||||
autocomplete_free(wins_ac);
|
||||
autocomplete_free(roster_ac);
|
||||
autocomplete_free(roster_header_ac);
|
||||
@ -2685,7 +2691,6 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
autocomplete_reset(account_default_ac);
|
||||
autocomplete_reset(account_status_ac);
|
||||
autocomplete_reset(disco_ac);
|
||||
autocomplete_reset(close_ac);
|
||||
autocomplete_reset(wins_ac);
|
||||
autocomplete_reset(roster_ac);
|
||||
autocomplete_reset(roster_header_ac);
|
||||
@ -2759,6 +2764,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
bookmark_autocomplete_reset();
|
||||
prefs_reset_room_trigger_ac();
|
||||
win_reset_search_attempts();
|
||||
win_close_reset_search_attempts();
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -2949,8 +2955,8 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
}
|
||||
}
|
||||
|
||||
gchar *cmds[] = { "/prefs", "/disco", "/close", "/room", "/autoping" };
|
||||
Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, room_ac, autoping_ac };
|
||||
gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping" };
|
||||
Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac };
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
|
||||
result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE);
|
||||
@ -2995,6 +3001,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
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);
|
||||
g_hash_table_insert(ac_funcs, "/close", _close_autocomplete);
|
||||
|
||||
int len = strlen(input);
|
||||
char parsed[len+1];
|
||||
@ -4290,6 +4297,19 @@ _win_autocomplete(ProfWin *window, const char *const input)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
_close_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *found = NULL;
|
||||
|
||||
found = autocomplete_param_with_func(input, "/close", win_close_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
_subject_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
|
@ -1057,6 +1057,128 @@ cmd_wins(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_close(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
if (g_strcmp0(args[0], "all") == 0) {
|
||||
int count = ui_close_all_wins();
|
||||
if (count == 0) {
|
||||
cons_show("No windows to close.");
|
||||
} else if (count == 1) {
|
||||
cons_show("Closed 1 window.");
|
||||
} else {
|
||||
cons_show("Closed %d windows.", count);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "read") == 0) {
|
||||
int count = ui_close_read_wins();
|
||||
if (count == 0) {
|
||||
cons_show("No windows to close.");
|
||||
} else if (count == 1) {
|
||||
cons_show("Closed 1 window.");
|
||||
} else {
|
||||
cons_show("Closed %d windows.", count);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean is_num = TRUE;
|
||||
int index = 0;
|
||||
if (args[0] != NULL) {
|
||||
int i = 0;
|
||||
for (i = 0; i < strlen(args[0]); i++) {
|
||||
if (!isdigit(args[0][i])) {
|
||||
is_num = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_num) {
|
||||
index = atoi(args[0]);
|
||||
}
|
||||
} else {
|
||||
index = wins_get_current_num();
|
||||
}
|
||||
|
||||
if (is_num) {
|
||||
if (index < 0 || index == 10) {
|
||||
cons_show("No such window exists.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
cons_show("Cannot close console window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfWin *toclose = wins_get_by_num(index);
|
||||
if (!toclose) {
|
||||
cons_show("Window is not open.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// check for unsaved form
|
||||
if (ui_win_has_unsaved_form(index)) {
|
||||
ui_current_print_line("You have unsaved changes, use /form submit or /form cancel");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle leaving rooms, or chat
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
ui_close_connected_win(index);
|
||||
}
|
||||
|
||||
// close the window
|
||||
ui_close_win(index);
|
||||
cons_show("Closed window %d", index);
|
||||
|
||||
// Tidy up the window list.
|
||||
if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) {
|
||||
wins_tidy();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
if (g_strcmp0(args[0], "console") == 0) {
|
||||
cons_show("Cannot close console window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfWin *toclose = wins_get_by_string(args[0]);
|
||||
if (!toclose) {
|
||||
cons_show("Window \"%s\" does not exist.", args[0]);
|
||||
return TRUE;
|
||||
}
|
||||
index = wins_get_num(toclose);
|
||||
|
||||
// check for unsaved form
|
||||
if (ui_win_has_unsaved_form(index)) {
|
||||
ui_current_print_line("You have unsaved changes, use /form submit or /form cancel");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle leaving rooms, or chat
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
ui_close_connected_win(index);
|
||||
}
|
||||
|
||||
// close the window
|
||||
ui_close_win(index);
|
||||
cons_show("Closed window %s", args[0]);
|
||||
|
||||
// Tidy up the window list.
|
||||
if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) {
|
||||
wins_tidy();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_win(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
@ -3958,78 +4080,6 @@ cmd_clear(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_close(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
int index = 0;
|
||||
int count = 0;
|
||||
|
||||
if (args[0] == NULL) {
|
||||
index = wins_get_current_num();
|
||||
} else if (strcmp(args[0], "all") == 0) {
|
||||
count = ui_close_all_wins();
|
||||
if (count == 0) {
|
||||
cons_show("No windows to close.");
|
||||
} else if (count == 1) {
|
||||
cons_show("Closed 1 window.");
|
||||
} else {
|
||||
cons_show("Closed %d windows.", count);
|
||||
}
|
||||
return TRUE;
|
||||
} else if (strcmp(args[0], "read") == 0) {
|
||||
count = ui_close_read_wins();
|
||||
if (count == 0) {
|
||||
cons_show("No windows to close.");
|
||||
} else if (count == 1) {
|
||||
cons_show("Closed 1 window.");
|
||||
} else {
|
||||
cons_show("Closed %d windows.", count);
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
index = atoi(args[0]);
|
||||
}
|
||||
|
||||
if (index < 0 || index == 10) {
|
||||
cons_show("No such window exists.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
cons_show("Cannot close console window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfWin *toclose = wins_get_by_num(index);
|
||||
if (!toclose) {
|
||||
cons_show("Window is not open.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// check for unsaved form
|
||||
if (ui_win_has_unsaved_form(index)) {
|
||||
ui_current_print_line("You have unsaved changes, use /form submit or /form cancel");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// handle leaving rooms, or chat
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
ui_close_connected_win(index);
|
||||
}
|
||||
|
||||
// close the window
|
||||
ui_close_win(index);
|
||||
cons_show("Closed window %d", index);
|
||||
|
||||
// Tidy up the window list.
|
||||
if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) {
|
||||
wins_tidy();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_leave(ProfWin *window, const char *const command, gchar **args)
|
||||
{
|
||||
|
@ -50,6 +50,7 @@
|
||||
static GHashTable *windows;
|
||||
static int current;
|
||||
static Autocomplete wins_ac;
|
||||
static Autocomplete wins_close_ac;
|
||||
|
||||
void
|
||||
wins_init(void)
|
||||
@ -64,6 +65,10 @@ wins_init(void)
|
||||
|
||||
wins_ac = autocomplete_new();
|
||||
autocomplete_add(wins_ac, "console");
|
||||
|
||||
wins_close_ac = autocomplete_new();
|
||||
autocomplete_add(wins_close_ac, "all");
|
||||
autocomplete_add(wins_close_ac, "read");
|
||||
}
|
||||
|
||||
ProfWin*
|
||||
@ -374,6 +379,7 @@ wins_close_by_num(int i)
|
||||
{
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
autocomplete_remove(wins_ac, chatwin->barejid);
|
||||
autocomplete_remove(wins_close_ac, chatwin->barejid);
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
@ -382,6 +388,7 @@ wins_close_by_num(int i)
|
||||
const char* nick = p_contact_name(contact);
|
||||
if (nick) {
|
||||
autocomplete_remove(wins_ac, nick);
|
||||
autocomplete_remove(wins_close_ac, nick);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -392,17 +399,20 @@ wins_close_by_num(int i)
|
||||
{
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
autocomplete_remove(wins_ac, mucwin->roomjid);
|
||||
autocomplete_remove(wins_close_ac, mucwin->roomjid);
|
||||
break;
|
||||
}
|
||||
case WIN_PRIVATE:
|
||||
{
|
||||
ProfPrivateWin *privwin = (ProfPrivateWin*)window;
|
||||
autocomplete_remove(wins_ac, privwin->fulljid);
|
||||
autocomplete_remove(wins_close_ac, privwin->fulljid);
|
||||
break;
|
||||
}
|
||||
case WIN_XML:
|
||||
{
|
||||
autocomplete_remove(wins_ac, "xmlconsole");
|
||||
autocomplete_remove(wins_close_ac, "xmlconsole");
|
||||
break;
|
||||
}
|
||||
case WIN_MUC_CONFIG:
|
||||
@ -437,6 +447,7 @@ wins_new_xmlconsole(void)
|
||||
ProfWin *newwin = win_create_xmlconsole();
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, "xmlconsole");
|
||||
autocomplete_add(wins_close_ac, "xmlconsole");
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -450,11 +461,13 @@ wins_new_chat(const char *const barejid)
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
|
||||
autocomplete_add(wins_ac, barejid);
|
||||
autocomplete_add(wins_close_ac, barejid);
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
const char* nick = p_contact_name(contact);
|
||||
if (nick) {
|
||||
autocomplete_add(wins_ac, nick);
|
||||
autocomplete_add(wins_close_ac, nick);
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,6 +483,7 @@ wins_new_muc(const char *const roomjid)
|
||||
ProfWin *newwin = win_create_muc(roomjid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, roomjid);
|
||||
autocomplete_add(wins_close_ac, roomjid);
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -493,6 +507,7 @@ wins_new_private(const char *const fulljid)
|
||||
ProfWin *newwin = win_create_private(fulljid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
autocomplete_add(wins_ac, fulljid);
|
||||
autocomplete_add(wins_close_ac, fulljid);
|
||||
return newwin;
|
||||
}
|
||||
|
||||
@ -803,15 +818,28 @@ win_autocomplete(const char *const search_str)
|
||||
return autocomplete_complete(wins_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
char*
|
||||
win_close_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(wins_close_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
win_reset_search_attempts(void)
|
||||
{
|
||||
autocomplete_reset(wins_ac);
|
||||
}
|
||||
|
||||
void
|
||||
win_close_reset_search_attempts(void)
|
||||
{
|
||||
autocomplete_reset(wins_close_ac);
|
||||
}
|
||||
|
||||
void
|
||||
wins_destroy(void)
|
||||
{
|
||||
g_hash_table_destroy(windows);
|
||||
autocomplete_free(wins_ac);
|
||||
autocomplete_free(wins_close_ac);
|
||||
}
|
||||
|
@ -84,5 +84,7 @@ void wins_show_subwin(ProfWin *window);
|
||||
|
||||
char* win_autocomplete(const char *const search_str);
|
||||
void win_reset_search_attempts(void);
|
||||
char* win_close_autocomplete(const char *const search_str);
|
||||
void win_close_reset_search_attempts(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user