Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-common / core / window-commands.c
index e54478d7ff2dc197cfa5d4e3f02d31e7ba6e2d3c..05332cad4bef1b0f82acc3db7285e9bb712c1a17 100644 (file)
@@ -64,7 +64,8 @@ static void window_print_items(WINDOW_REC *win)
                type = module_find_id_str("WINDOW ITEM TYPE", item->type);
                printformat_window(win, MSGLEVEL_CLIENTCRAP,
                                   TXT_WINDOW_INFO_ITEM,
-                                  type == NULL ? "??" : type, item->name,
+                                  type == NULL ? "??" : type,
+                                  item->visible_name,
                                   item->server == NULL ? "" :
                                   item->server->tag);
        }
@@ -182,7 +183,7 @@ static void cmd_window_new(const char *data, void *server, WI_ITEM_REC *item)
        window_change_server(window, server);
 }
 
-/* SYNTAX: WINDOW CLOSE [<first> [<last>] */
+/* SYNTAX: WINDOW CLOSE [<first> [<last>]] */
 static void cmd_window_close(const char *data)
 {
         GSList *tmp, *destroys;
@@ -279,6 +280,8 @@ static WINDOW_REC *window_highest_activity(WINDOW_REC *window)
 static void cmd_window_goto(const char *data)
 {
        WINDOW_REC *window;
+       char *target;
+       void *free_arg;
 
        g_return_if_fail(data != NULL);
 
@@ -287,13 +290,18 @@ static void cmd_window_goto(const char *data)
                return;
        }
 
-       if (g_strcasecmp(data, "active") == 0)
+       if (!cmd_get_params(data, &free_arg, 1, &target))
+               return;
+
+       if (g_strcasecmp(target, "active") == 0)
                 window = window_highest_activity(active_win);
        else
-                window = window_find_item(active_win->active_server, data);
+                window = window_find_item(active_win->active_server, target);
 
        if (window != NULL)
                window_set_active(window);
+
+       cmd_params_free(free_arg);
 }
 
 /* SYNTAX: WINDOW NEXT */
@@ -346,14 +354,17 @@ static void cmd_window_immortal(const char *data)
 {
        int set;
 
-       if (g_strcasecmp(data, "ON") == 0)
+       if (*data == '\0')
+               set = active_win->immortal;
+       else if (g_strcasecmp(data, "ON") == 0)
                 set = TRUE;
        else if (g_strcasecmp(data, "OFF") == 0)
                 set = FALSE;
        else if (g_strcasecmp(data, "TOGGLE") == 0)
                 set = !active_win->immortal;
        else {
-               printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE);
+               printformat_window(active_win, MSGLEVEL_CLIENTERROR,
+                                  TXT_NOT_TOGGLE);
                return;
        }
 
@@ -389,6 +400,8 @@ static void cmd_window_server(const char *data)
        if (*tag == '\0')
                cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
        server = server_find_tag(tag);
+       if (server == NULL)
+               server = server_find_lookup_tag(tag);
 
        if (g_hash_table_lookup(optlist, "unsticky") != NULL &&
            active_win->servertag != NULL) {
@@ -424,7 +437,12 @@ static void cmd_window_server(const char *data)
 
 static void cmd_window_item(const char *data, void *server, WI_ITEM_REC *item)
 {
-       command_runsub("window item", data, server, item);
+        while (*data == ' ') data++;
+
+       if (is_numeric(data, '\0'))
+               signal_emit("command window item goto", 3, data, server, item);
+       else
+               command_runsub("window item", data, server, item);
 }
 
 /* SYNTAX: WINDOW ITEM PREV */
@@ -439,14 +457,29 @@ static void cmd_window_item_next(void)
        window_item_next(active_win);
 }
 
-/* SYNTAX: WINDOW ITEM GOTO <name> */
+/* SYNTAX: WINDOW ITEM GOTO <number>|<name> */
 static void cmd_window_item_goto(const char *data, SERVER_REC *server)
 {
-        WI_ITEM_REC *item;
+       WI_ITEM_REC *item;
+       GSList *tmp;
+       void *free_arg;
+       char *target;
+       
+       if (!cmd_get_params(data, &free_arg, 1, &target))
+               return;
+
+       if (is_numeric(target, '\0')) {
+               /* change to specified number */
+               tmp = g_slist_nth(active_win->items, atoi(target)-1);
+               item = tmp == NULL ? NULL : tmp->data;
+       } else {
+               item = window_item_find_window(active_win, server, target);
+       }
 
-        item = window_item_find_window(active_win, server, data);
         if (item != NULL)
                 window_item_set_active(active_win, item);
+
+       cmd_params_free(free_arg);
 }
 
 /* SYNTAX: WINDOW ITEM MOVE <number>|<name> */
@@ -505,9 +538,13 @@ static void cmd_window_number(const char *data)
 /* SYNTAX: WINDOW NAME <name> */
 static void cmd_window_name(const char *data)
 {
-       if (window_find_name(data) == NULL)
+       WINDOW_REC *win;
+
+       win = window_find_name(data);
+       if (win == NULL || win == active_win)
                window_set_name(active_win, data);
-       else {
+       else if (active_win->name == NULL ||
+                strcmp(active_win->name, data) != 0) {
                printformat_window(active_win, MSGLEVEL_CLIENTERROR,
                                   TXT_WINDOW_NAME_NOT_UNIQUE, data);
        }
@@ -599,17 +636,10 @@ static void cmd_window_move_next(void)
         window_refnums_move_right(active_win);
 }
 
-/* SYNTAX: WINDOW MOVE <number>|<direction> */
-static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
+static void active_window_move_to(int new_refnum)
 {
-       int new_refnum, refnum;
-
-       if (!is_numeric(data, 0)) {
-               command_runsub("window move", data, server, item);
-                return;
-       }
+       int refnum;
 
-       new_refnum = atoi(data);
        if (new_refnum > active_win->refnum) {
                for (;;) {
                        refnum = window_refnum_next(active_win->refnum, FALSE);
@@ -629,6 +659,29 @@ static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *i
        }
 }
 
+/* SYNTAX: WINDOW MOVE FIRST */
+static void cmd_window_move_first(void)
+{
+       active_window_move_to(1);
+}
+
+/* SYNTAX: WINDOW MOVE LAST */
+static void cmd_window_move_last(void)
+{
+       active_window_move_to(windows_refnum_last());
+}
+
+/* SYNTAX: WINDOW MOVE <number>|<direction> */
+static void cmd_window_move(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
+{
+       if (!is_numeric(data, 0)) {
+               command_runsub("window move", data, server, item);
+                return;
+       }
+
+       active_window_move_to(atoi(data));
+}
+
 /* SYNTAX: WINDOW LIST */
 static void cmd_window_list(void)
 {
@@ -643,7 +696,7 @@ static void cmd_window_list(void)
                levelstr = bits2level(rec->level);
                printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_WINDOWLIST_LINE,
                            rec->refnum, rec->name == NULL ? "" : rec->name,
-                           rec->active == NULL ? "" : rec->active->name,
+                           rec->active == NULL ? "" : rec->active->visible_name,
                            rec->active_server == NULL ? "" : ((SERVER_REC *) rec->active_server)->tag,
                            levelstr);
                g_free(levelstr);
@@ -720,7 +773,8 @@ static void cmd_foreach_window(const char *data)
                 list = g_slist_remove(list, list->data);
        }
 
-        active_win = old;
+       if (g_slist_find(windows, old) != NULL)
+               active_win = old;
 }
 
 void window_commands_init(void)
@@ -748,6 +802,8 @@ void window_commands_init(void)
        command_bind("window move", NULL, (SIGNAL_FUNC) cmd_window_move);
        command_bind("window move prev", NULL, (SIGNAL_FUNC) cmd_window_move_prev);
        command_bind("window move next", NULL, (SIGNAL_FUNC) cmd_window_move_next);
+       command_bind("window move first", NULL, (SIGNAL_FUNC) cmd_window_move_first);
+       command_bind("window move last", NULL, (SIGNAL_FUNC) cmd_window_move_last);
        command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
        command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
        command_bind("layout", NULL, (SIGNAL_FUNC) cmd_layout);
@@ -787,6 +843,8 @@ void window_commands_deinit(void)
        command_unbind("window move", (SIGNAL_FUNC) cmd_window_move);
        command_unbind("window move prev", (SIGNAL_FUNC) cmd_window_move_prev);
        command_unbind("window move next", (SIGNAL_FUNC) cmd_window_move_next);
+       command_unbind("window move first", (SIGNAL_FUNC) cmd_window_move_first);
+       command_unbind("window move last", (SIGNAL_FUNC) cmd_window_move_last);
        command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
        command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
        command_unbind("layout", (SIGNAL_FUNC) cmd_layout);