diff options
author | Timo Sirainen <cras@irssi.org> | 2002-09-14 23:14:04 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2002-09-14 23:14:04 +0000 |
commit | a83366069fd5e31a123bd402a92d25ad62fed11e (patch) | |
tree | 55f47e0443b586da81e9b4965eb137c3bb19bab8 /src/fe-text | |
parent | 930dd40815f09378369d02d5a77e0597eb5f7620 (diff) | |
download | irssi-a83366069fd5e31a123bd402a92d25ad62fed11e.zip |
window->active_server used to hold non-connected servers, but that was
removed before because it created several problems, especially with scripts.
however that change made /server and /disconnect annoying to use with
non-connected servers.
so, now we have window->connect_server as well. either active_server or
connect_server is set, but never both. commands that can deal properly with
non-connected servers can now use the connect_server, while everyone else
happily thinks that no server is active.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2921 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/gui-readline.c | 97 |
1 files changed, 76 insertions, 21 deletions
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 2e93f649..1cabfac7 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -483,43 +483,98 @@ static void key_active_window(void) signal_emit("command window goto", 3, "active", active_win->active_server, active_win->active); } +static SERVER_REC *get_prev_server(SERVER_REC *current) +{ + int pos; + + if (current == NULL) { + return servers != NULL ? g_slist_last(servers)->data : + lookup_servers != NULL ? + g_slist_last(lookup_servers)->data : NULL; + } + + /* connect2 -> connect1 -> server2 -> server1 -> connect2 -> .. */ + + pos = g_slist_index(servers, current); + if (pos != -1) { + if (pos > 0) + return g_slist_nth(servers, pos-1)->data; + if (lookup_servers != NULL) + return g_slist_last(lookup_servers)->data; + return g_slist_last(servers)->data; + } + + pos = g_slist_index(lookup_servers, current); + g_assert(pos >= 0); + + if (pos > 0) + return g_slist_nth(lookup_servers, pos-1)->data; + if (servers != NULL) + return g_slist_last(servers)->data; + return g_slist_last(lookup_servers)->data; +} + +static SERVER_REC *get_next_server(SERVER_REC *current) +{ + GSList *pos; + + if (current == NULL) { + return servers != NULL ? servers->data : + lookup_servers != NULL ? lookup_servers->data : NULL; + } + + /* server1 -> server2 -> connect1 -> connect2 -> server1 -> .. */ + + pos = g_slist_find(servers, current); + if (pos != NULL) { + if (pos->next != NULL) + return pos->next->data; + if (lookup_servers != NULL) + return lookup_servers->data; + return servers->data; + } + + pos = g_slist_find(lookup_servers, current); + g_assert(pos != NULL); + + if (pos->next != NULL) + return pos->next->data; + if (servers != NULL) + return servers->data; + return lookup_servers->data; +} + static void key_previous_window_item(void) { SERVER_REC *server; - GSList *pos; - if (active_win->items != NULL) - signal_emit("command window item prev", 3, "", active_win->active_server, active_win->active); - else if (servers != NULL) { + if (active_win->items != NULL) { + signal_emit("command window item prev", 3, "", + active_win->active_server, active_win->active); + } else if (servers != NULL || lookup_servers != NULL) { /* change server */ - if (active_win->active_server == NULL) - server = servers->data; - else { - pos = g_slist_find(servers, active_win->active_server); - server = pos->next != NULL ? pos->next->data : servers->data; - } - signal_emit("command window server", 3, server->tag, active_win->active_server, active_win->active); + server = active_win->active_server; + if (server == NULL) + server = active_win->connect_server; + server = get_prev_server(server); + signal_emit("command window server", 3, server->tag, + active_win->active_server, active_win->active); } } static void key_next_window_item(void) { SERVER_REC *server; - int index; if (active_win->items != NULL) { signal_emit("command window item next", 3, "", active_win->active_server, active_win->active); - } - else if (servers != NULL) { + } else if (servers != NULL || lookup_servers != NULL) { /* change server */ - if (active_win->active_server == NULL) - server = servers->data; - else { - index = g_slist_index(servers, active_win->active_server); - server = index > 0 ? g_slist_nth(servers, index-1)->data : - g_slist_last(servers)->data; - } + server = active_win->active_server; + if (server == NULL) + server = active_win->connect_server; + server = get_next_server(server); signal_emit("command window server", 3, server->tag, active_win->active_server, active_win->active); } |