# HG changeset patch # User zas_ # Date 1211110798 0 # Node ID 54980ddfe1ce46b3d0c10f9b96001236b1dcf6d9 # Parent ac0ede6a53cfe4de63ac0139ad93dfdf4073a578 Memorize text to display in the log window when the window is not yet created. On log window display, the memorized text is then recalled and displayed. diff -r ac0ede6a53cf -r 54980ddfe1ce src/logwindow.c --- a/src/logwindow.c Sun May 18 07:36:57 2008 +0000 +++ b/src/logwindow.c Sun May 18 11:39:58 2008 +0000 @@ -17,8 +17,6 @@ #include -#define TRIM_LINES 25 - typedef struct _LogWindow LogWindow; @@ -166,6 +164,8 @@ gtk_text_view_scroll_mark_onscreen(text, mark); gtk_window_present(GTK_WINDOW(logwin->window)); + + log_window_append("", LOG_NORMAL); // to flush memorized lines } @@ -183,6 +183,13 @@ log_window_show(logwindow); } +typedef struct _LogMsg LogMsg; + +struct _LogMsg { + gchar *text; + LogType type; +}; + void log_window_append(const gchar *str, LogType type) { GtkTextView *text; @@ -190,8 +197,28 @@ GtkTextIter iter; gint line_limit = 1000; //FIXME: option gchar *str_utf8; + static GList *memory = NULL; - if (logwindow == NULL) return; + if (logwindow == NULL && *str) + { + LogMsg *msg = g_new(LogMsg, 1); + + msg->text = g_strdup(str); + msg->type = type; + + memory = g_list_prepend(memory, msg); + + while (g_list_length(memory) >= line_limit) + { + GList *work = g_list_last(memory); + LogMsg *oldest_msg = work->data; + + g_free(oldest_msg->text); + memory = g_list_delete_link(memory, work); + } + + return; + } text = GTK_TEXT_VIEW(logwindow->text); buffer = gtk_text_view_get_buffer(text); @@ -202,16 +229,36 @@ gtk_text_buffer_get_start_iter(buffer, &start); end = start; - gtk_text_iter_forward_lines(&end, TRIM_LINES); + gtk_text_iter_forward_lines(&end, logwindow->lines - line_limit); gtk_text_buffer_delete(buffer, &start, &end); - logwindow->lines = gtk_text_buffer_get_line_count(buffer); } gtk_text_buffer_get_end_iter(buffer, &iter); - str_utf8 = utf8_validate_or_convert((gchar *)str); - gtk_text_buffer_insert_with_tags_by_name - (buffer, &iter, str_utf8, -1, logdefs[type].tag, NULL); + { + GList *work = g_list_last(memory); + + while (work) + { + GList *prev; + LogMsg *oldest_msg = work->data; + + str_utf8 = utf8_validate_or_convert((gchar *)oldest_msg->text); + gtk_text_buffer_insert_with_tags_by_name + (buffer, &iter, str_utf8, -1, logdefs[oldest_msg->type].tag, NULL); + + prev = work->prev; + memory = g_list_delete_link(memory, work); + work = prev; + } + } + + if (*str) + { + str_utf8 = utf8_validate_or_convert((gchar *)str); + gtk_text_buffer_insert_with_tags_by_name + (buffer, &iter, str_utf8, -1, logdefs[type].tag, NULL); + } if (GTK_WIDGET_VISIBLE(text)) { @@ -221,5 +268,5 @@ gtk_text_view_scroll_mark_onscreen(text, mark); } - logwindow->lines++; + logwindow->lines = gtk_text_buffer_get_line_count(buffer); }