mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
/SAVEWINDOWS saves now split windows
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1202 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
88b091cc95
commit
5ab27ea604
@ -26,6 +26,7 @@ irssi_SOURCES = \
|
||||
gui-windows.c \
|
||||
mainwindows.c \
|
||||
mainwindow-activity.c \
|
||||
mainwindows-save.c \
|
||||
statusbar.c \
|
||||
statusbar-items.c \
|
||||
irssi.c \
|
||||
|
@ -58,6 +58,9 @@ void gui_textwidget_deinit(void);
|
||||
void mainwindow_activity_init(void);
|
||||
void mainwindow_activity_deinit(void);
|
||||
|
||||
void mainwindows_save_init(void);
|
||||
void mainwindows_save_deinit(void);
|
||||
|
||||
static GMainLoop *main_loop;
|
||||
int quitting;
|
||||
|
||||
@ -122,6 +125,7 @@ static void textui_finish_init(void)
|
||||
gui_textwidget_init();
|
||||
mainwindows_init();
|
||||
mainwindow_activity_init();
|
||||
mainwindows_save_init();
|
||||
gui_windows_init();
|
||||
statusbar_init();
|
||||
|
||||
@ -159,6 +163,7 @@ static void textui_deinit(void)
|
||||
gui_printtext_deinit();
|
||||
gui_readline_deinit();
|
||||
gui_windows_deinit();
|
||||
mainwindows_save_deinit();
|
||||
mainwindow_activity_deinit();
|
||||
mainwindows_deinit();
|
||||
gui_expandos_deinit();
|
||||
|
195
src/fe-text/mainwindows-save.c
Normal file
195
src/fe-text/mainwindows-save.c
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
mainwindows-save.c : irssi
|
||||
|
||||
Copyright (C) 2001 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "misc.h"
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "mainwindows.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
static void main_window_save(MAIN_WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
GString *str;
|
||||
char num[MAX_INT_STRLEN];
|
||||
|
||||
ltoa(num, window->active->refnum);
|
||||
node = config_node_section(node, num, NODE_TYPE_BLOCK);
|
||||
|
||||
iconfig_node_set_int(node, "first_line", window->first_line);
|
||||
iconfig_node_set_int(node, "lines", window->lines);
|
||||
|
||||
str = g_string_new(NULL);
|
||||
for (tmp = window->sticky_windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *rec = tmp->data;
|
||||
g_string_sprintfa(str, "%d ", rec->refnum);
|
||||
}
|
||||
if (str->len > 1) {
|
||||
g_string_truncate(str, str->len-1);
|
||||
iconfig_node_set_str(node, "sticky", str->str);
|
||||
}
|
||||
g_string_free(str, TRUE);
|
||||
}
|
||||
|
||||
static void sig_windows_saved(void)
|
||||
{
|
||||
CONFIG_NODE *node;
|
||||
|
||||
iconfig_set_str(NULL, "mainwindows", NULL);
|
||||
node = iconfig_node_traverse("mainwindows", TRUE);
|
||||
|
||||
g_slist_foreach(mainwindows, (GFunc) main_window_save, node);
|
||||
}
|
||||
|
||||
static int window_node_cmp(CONFIG_NODE *n1, CONFIG_NODE *n2)
|
||||
{
|
||||
return config_node_get_int(n1, "first_line", 0) <
|
||||
config_node_get_int(n2, "first_line", 0) ? -1 : 1;
|
||||
}
|
||||
|
||||
static GSList *read_sorted_windows(CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp, *output;
|
||||
|
||||
output = NULL;
|
||||
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
||||
output = g_slist_insert_sorted(output, tmp->data,
|
||||
(GCompareFunc) window_node_cmp);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void restore_sticky_windows(CONFIG_NODE *node,
|
||||
MAIN_WINDOW_REC *mainwindow)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
char **sticky_list, **sticky;
|
||||
|
||||
sticky_list = g_strsplit(config_node_get_str(node, "sticky", ""), " ", -1);
|
||||
for (sticky = sticky_list; *sticky != NULL; sticky++) {
|
||||
window = window_find_refnum(atoi(*sticky));
|
||||
if (window != NULL) {
|
||||
mainwindow->sticky_windows =
|
||||
g_slist_append(mainwindow->sticky_windows,
|
||||
window);
|
||||
}
|
||||
}
|
||||
g_strfreev(sticky_list);
|
||||
}
|
||||
|
||||
static WINDOW_REC *window_find_hidden(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *rec = tmp->data;
|
||||
|
||||
if (!is_window_visible(rec))
|
||||
return rec;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void sig_windows_restored(void)
|
||||
{
|
||||
MAIN_WINDOW_REC *mainwindow, *lowerwin;
|
||||
WINDOW_REC *window;
|
||||
CONFIG_NODE *node;
|
||||
GSList *tmp, *tmp2, *sorted_windows, *sorted_config;
|
||||
int count, newsize;
|
||||
|
||||
node = iconfig_node_traverse("mainwindows", FALSE);
|
||||
if (node == NULL) return;
|
||||
|
||||
/* create all windows, shrink the lower windows to minimum size */
|
||||
lowerwin = mainwindows->data;
|
||||
count = g_slist_length(node->value);
|
||||
while (count > 1) {
|
||||
window = window_find_hidden();
|
||||
if (window == NULL)
|
||||
break;
|
||||
|
||||
mainwindow = mainwindow_create();
|
||||
if (mainwindow == NULL)
|
||||
break;
|
||||
|
||||
mainwindow->active = window;
|
||||
WINDOW_GUI(window)->parent = mainwindow;
|
||||
|
||||
active_mainwin = NULL;
|
||||
window_set_active(window);
|
||||
|
||||
if (lowerwin->lines > WINDOW_MIN_SIZE)
|
||||
mainwindow_set_size(lowerwin, WINDOW_MIN_SIZE);
|
||||
count--;
|
||||
|
||||
lowerwin = mainwindow;
|
||||
}
|
||||
|
||||
sorted_config = read_sorted_windows(node);
|
||||
sorted_windows = mainwindows_get_sorted(FALSE);
|
||||
for (tmp = sorted_windows, tmp2 = sorted_config;
|
||||
tmp != NULL && tmp2 != NULL;
|
||||
tmp = tmp->next, tmp2 = tmp2->next) {
|
||||
MAIN_WINDOW_REC *mainwindow = tmp->data;
|
||||
CONFIG_NODE *node = tmp2->data;
|
||||
|
||||
window = window_find_refnum(atoi(node->key));
|
||||
if (window == NULL) {
|
||||
mainwindow_destroy(mainwindow);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_window_visible(window)) {
|
||||
active_mainwin = WINDOW_GUI(window)->parent;
|
||||
window_set_active(window_find_hidden());
|
||||
}
|
||||
|
||||
active_mainwin = mainwindow;
|
||||
window_set_active(window);
|
||||
|
||||
restore_sticky_windows(node, mainwindow);
|
||||
|
||||
newsize = config_node_get_int(node, "lines", 0);
|
||||
if (newsize > 0)
|
||||
mainwindow_set_size(mainwindow, newsize);
|
||||
}
|
||||
g_slist_free(sorted_windows);
|
||||
g_slist_free(sorted_config);
|
||||
|
||||
irssi_redraw();
|
||||
}
|
||||
|
||||
void mainwindows_save_init(void)
|
||||
{
|
||||
signal_add("windows saved", (SIGNAL_FUNC) sig_windows_saved);
|
||||
signal_add("windows restored", (SIGNAL_FUNC) sig_windows_restored);
|
||||
}
|
||||
|
||||
void mainwindows_save_deinit(void)
|
||||
{
|
||||
signal_remove("windows saved", (SIGNAL_FUNC) sig_windows_saved);
|
||||
signal_remove("windows restored", (SIGNAL_FUNC) sig_windows_restored);
|
||||
}
|
@ -30,7 +30,6 @@
|
||||
#include "statusbar.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
#define WINDOW_MIN_SIZE 2
|
||||
#define NEW_WINDOW_SIZE (WINDOW_MIN_SIZE + 1)
|
||||
|
||||
GSList *mainwindows;
|
||||
@ -268,7 +267,7 @@ static int mainwindows_compare_reverse(MAIN_WINDOW_REC *w1, MAIN_WINDOW_REC *w2)
|
||||
return w1->first_line < w2->first_line ? 1 : -1;
|
||||
}
|
||||
|
||||
static GSList *mainwindows_get_sorted(int reverse)
|
||||
GSList *mainwindows_get_sorted(int reverse)
|
||||
{
|
||||
GSList *tmp, *list;
|
||||
|
||||
@ -457,14 +456,9 @@ static void mainwindows_resize_two(MAIN_WINDOW_REC *grow_win,
|
||||
statusbar_redraw(shrink_win->statusbar);
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW GROW [<lines>] */
|
||||
static void cmd_window_grow(const char *data)
|
||||
static int mainwindow_grow(MAIN_WINDOW_REC *window, int count)
|
||||
{
|
||||
MAIN_WINDOW_REC *window, *shrink_win;
|
||||
int count;
|
||||
|
||||
count = *data == '\0' ? 1 : atoi(data);
|
||||
window = WINDOW_GUI(active_win)->parent;
|
||||
MAIN_WINDOW_REC *shrink_win;
|
||||
|
||||
/* shrink lower window */
|
||||
shrink_win = mainwindows_find_lower(window->last_line);
|
||||
@ -474,33 +468,24 @@ static void cmd_window_grow(const char *data)
|
||||
} else {
|
||||
/* shrink upper window */
|
||||
shrink_win = mainwindows_find_upper(window->first_line);
|
||||
if (shrink_win != NULL && shrink_win->lines-count >= WINDOW_MIN_SIZE) {
|
||||
window->first_line -= count;
|
||||
shrink_win->last_line -= count;
|
||||
} else {
|
||||
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_WINDOW_TOO_SMALL);
|
||||
return;
|
||||
}
|
||||
if (shrink_win == NULL ||
|
||||
shrink_win->lines-count < WINDOW_MIN_SIZE)
|
||||
return FALSE;
|
||||
|
||||
window->first_line -= count;
|
||||
shrink_win->last_line -= count;
|
||||
}
|
||||
|
||||
mainwindows_resize_two(window, shrink_win, count);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW SHRINK [<lines>] */
|
||||
static void cmd_window_shrink(const char *data)
|
||||
static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count)
|
||||
{
|
||||
MAIN_WINDOW_REC *window, *grow_win;
|
||||
int count;
|
||||
MAIN_WINDOW_REC *grow_win;
|
||||
|
||||
count = *data == '\0' ? 1 : atoi(data);
|
||||
|
||||
window = WINDOW_GUI(active_win)->parent;
|
||||
if (window->lines-count < WINDOW_MIN_SIZE) {
|
||||
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_WINDOW_TOO_SMALL);
|
||||
return;
|
||||
}
|
||||
if (window->lines-count < WINDOW_MIN_SIZE)
|
||||
return FALSE;
|
||||
|
||||
grow_win = mainwindows_find_lower(window->last_line);
|
||||
if (grow_win != NULL) {
|
||||
@ -508,13 +493,53 @@ static void cmd_window_shrink(const char *data)
|
||||
grow_win->first_line -= count;
|
||||
} else {
|
||||
grow_win = mainwindows_find_upper(window->first_line);
|
||||
if (grow_win == NULL) return;
|
||||
if (grow_win == NULL) return FALSE;
|
||||
|
||||
window->first_line += count;
|
||||
grow_win->last_line += count;
|
||||
}
|
||||
|
||||
mainwindows_resize_two(grow_win, window, count);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void mainwindow_set_size(MAIN_WINDOW_REC *window, int size)
|
||||
{
|
||||
size -= window->lines;
|
||||
if (size < 0)
|
||||
mainwindow_shrink(window, size);
|
||||
else
|
||||
mainwindow_grow(window, size);
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW GROW [<lines>] */
|
||||
static void cmd_window_grow(const char *data)
|
||||
{
|
||||
MAIN_WINDOW_REC *window;
|
||||
int count;
|
||||
|
||||
count = *data == '\0' ? 1 : atoi(data);
|
||||
window = WINDOW_GUI(active_win)->parent;
|
||||
|
||||
if (!mainwindow_grow(window, count)) {
|
||||
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_WINDOW_TOO_SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW SHRINK [<lines>] */
|
||||
static void cmd_window_shrink(const char *data)
|
||||
{
|
||||
MAIN_WINDOW_REC *window;
|
||||
int count;
|
||||
|
||||
count = *data == '\0' ? 1 : atoi(data);
|
||||
window = WINDOW_GUI(active_win)->parent;
|
||||
|
||||
if (!mainwindow_shrink(window, count)) {
|
||||
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_WINDOW_TOO_SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW SIZE <lines> */
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "fe-windows.h"
|
||||
#include "screen.h"
|
||||
|
||||
#define WINDOW_MIN_SIZE 2
|
||||
|
||||
typedef struct {
|
||||
WINDOW_REC *active;
|
||||
GSList *sticky_windows; /* list of windows allowed to show only in this mainwindow */
|
||||
@ -27,9 +29,12 @@ MAIN_WINDOW_REC *mainwindow_create(void);
|
||||
void mainwindow_destroy(MAIN_WINDOW_REC *window);
|
||||
|
||||
void mainwindows_redraw(void);
|
||||
void mainwindows_resize(int ychange, int xchange);
|
||||
void mainwindows_recreate(void);
|
||||
|
||||
void mainwindow_set_size(MAIN_WINDOW_REC *window, int size);
|
||||
void mainwindows_resize(int ychange, int xchange);
|
||||
|
||||
int mainwindows_reserve_lines(int count, int up);
|
||||
GSList *mainwindows_get_sorted(int reverse);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user