From db7c60b9a560f7371c37d59f106fbc395923eff3 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 15 Mar 2001 21:05:40 +0000 Subject: [PATCH] /WINDOW CLOSE [ [] - you can close multiple windows once now. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1396 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/window-commands.c | 42 +++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index bb56c5e8..17cf65e5 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -59,12 +59,46 @@ static void cmd_window_new(const char *data, void *server, WI_ITEM_REC *item) window_change_server(window, server); } -/* SYNTAX: WINDOW CLOSE */ +/* SYNTAX: WINDOW CLOSE [ [] */ static void cmd_window_close(const char *data) { - /* destroy window unless it's the last one */ - if (windows->next != NULL) - window_destroy(active_win); + GSList *tmp, *destroys; + char *first, *last; + int first_num, last_num; + void *free_arg; + + if (!cmd_get_params(data, &free_arg, 2, &first, &last)) + return; + + if ((*first != '\0' && !is_numeric(first, '\0')) || + ((*last != '\0') && !is_numeric(last, '\0'))) { + cmd_params_free(free_arg); + return; + } + + first_num = *first == '\0' ? active_win->refnum : atoi(first); + last_num = *last == '\0' ? active_win->refnum : atoi(last); + + /* get list of windows to destroy */ + destroys = NULL; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + if (rec->refnum >= first_num && rec->refnum <= last_num) + destroys = g_slist_append(destroys, rec); + } + + /* really destroy the windows */ + while (destroys != NULL) { + WINDOW_REC *rec = destroys->data; + + if (windows->next != NULL) + window_destroy(rec); + + destroys = g_slist_remove(destroys, rec); + } + + cmd_params_free(free_arg); } /* SYNTAX: WINDOW REFNUM */