1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added "read" parameter to /close

Closes all windows where there are no unread messages
This commit is contained in:
James Booth 2013-05-16 22:34:05 +01:00
parent 57e64bebe5
commit 2f92752365
3 changed files with 26 additions and 3 deletions

View File

@ -482,12 +482,13 @@ static struct cmd_t main_commands[] =
{ "/close", { "/close",
_cmd_close, parse_args, 0, 1, _cmd_close, parse_args, 0, 1,
{ "/close [win|all]", "Close a window window.", { "/close [win|read|all]", "Close a window window.",
{ "/close [win|all]", { "/close [win|read|all]",
"----------------", "---------------------",
"Passing no argument will close the current window.", "Passing no argument will close the current window.",
"Passing 2,3,4,5,6,7,8,9 or 0 will close the specified window.", "Passing 2,3,4,5,6,7,8,9 or 0 will close the specified window.",
"Passing 'all' will close all currently open windows.", "Passing 'all' will close all currently open windows.",
"Passing 'read' will close all windows that have no unread messages.",
"The console window cannot be closed.", "The console window cannot be closed.",
"If in a chat room, you will leave the room.", "If in a chat room, you will leave the room.",
NULL } } }, NULL } } },
@ -2520,6 +2521,17 @@ _cmd_close(gchar **args, struct cmd_help_t help)
cons_show("Closed all windows."); cons_show("Closed all windows.");
return TRUE; return TRUE;
} else if (strcmp(args[0], "read") == 0) {
for (curr = 1; curr <= 9; curr++) {
if (ui_win_exists(curr) && (ui_win_unread(curr) == 0)) {
if (conn_status == JABBER_CONNECTED) {
_close_connected_win(curr);
}
ui_close_win(curr);
}
}
cons_show("Closed windows.");
return TRUE;
} else { } else {
index = atoi(args[0]); index = atoi(args[0]);
if (index == 0) { if (index == 0) {

View File

@ -1215,6 +1215,16 @@ ui_unread(void)
return result; return result;
} }
int
ui_win_unread(int index)
{
if (windows[index] != NULL) {
return windows[index]->unread;
} else {
return 0;
}
}
static void static void
_ui_draw_win_title(void) _ui_draw_win_title(void)
{ {

View File

@ -79,6 +79,7 @@ win_type_t ui_win_type(int index);
char * ui_recipient(int index); char * ui_recipient(int index);
void ui_close_win(int index); void ui_close_win(int index);
gboolean ui_win_exists(int index); gboolean ui_win_exists(int index);
int ui_win_unread(int index);
// ui events // ui events
void ui_contact_typing(const char * const from); void ui_contact_typing(const char * const from);