2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Authors: Vladimir Nadvornik, Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "logwindow.h"
28 typedef struct _LogWindow LogWindow;
33 GtkWidget *scrolledwin;
35 GtkTextTag *color_tags[LOG_COUNT];
37 GtkWidget *regexp_box;
41 GtkWidget *timer_data;
42 GtkWidget *debug_level;
43 gint debug_value; /**< Not used */
44 GtkWidget *search_entry_box;
45 gboolean highlight_all;
49 LOGWINDOW_SEARCH_BACKWARDS,
50 LOGWINDOW_SEARCH_FORWARDS
51 } LogWindowSearchDirection;
53 static LogWindow *logwindow = NULL;
55 static void hide_cb(GtkWidget *UNUSED(widget), LogWindow *UNUSED(logwin))
59 static gboolean iter_char_search_cb(gunichar ch, gpointer data)
63 if (ch == GPOINTER_TO_UINT(data))
76 * @brief Handle escape and F1 keys
82 * If escape key pressed, hide log window. \n
83 * If no text selected, form a selection bounded by space characters or
84 * start and end of line. \n
85 * If F1 pressed, execute command line program: \n
86 * <options->log_window.action> <selected text>
89 static gboolean key_pressed(GtkWidget *UNUSED(widget), GdkEventKey *event, LogWindow *logwin)
91 GtkTextBuffer *buffer;
93 GtkTextIter chr_start;
94 GtkTextIter cursor_iter;
96 GtkTextIter line_start;
97 GtkTextMark *cursor_mark;
101 if (event && event->keyval == GDK_KEY_Escape)
102 gtk_widget_hide(logwin->window);
104 if (event && event->keyval == GDK_KEY_F1)
106 if (strlen(options->log_window.action) > 0)
108 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
110 if (!gtk_text_buffer_get_has_selection(buffer))
112 cursor_mark = gtk_text_buffer_get_insert(buffer);
113 gtk_text_buffer_get_iter_at_mark(buffer, &cursor_iter, cursor_mark);
115 line_start = cursor_iter;
116 gtk_text_iter_set_line_offset(&line_start, 0);
117 line_end = cursor_iter;
118 gtk_text_iter_forward_to_line_end(&line_end);
120 chr_start = cursor_iter;
121 gtk_text_iter_backward_find_char(&chr_start, (GtkTextCharPredicate)iter_char_search_cb, GUINT_TO_POINTER(' '), &line_start);
123 chr_end = cursor_iter;
124 gtk_text_iter_forward_find_char(&chr_end, (GtkTextCharPredicate)iter_char_search_cb, GUINT_TO_POINTER(' '), &line_end);
126 gtk_text_buffer_select_range(buffer, &chr_start, &chr_end);
129 if (gtk_text_buffer_get_selection_bounds(gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end))
131 sel_text = gtk_text_buffer_get_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end, FALSE);
133 cmd_line = g_strconcat(options->log_window.action, " ", sel_text, NULL);
147 static void log_window_pause_cb(GtkWidget *UNUSED(widget), gpointer UNUSED(data))
149 options->log_window.paused = !options->log_window.paused;
152 static void log_window_line_wrap_cb(GtkWidget *UNUSED(widget), gpointer data)
154 LogWindow *logwin = static_cast<LogWindow *>(data);
156 options->log_window.line_wrap = !options->log_window.line_wrap;
158 if (options->log_window.line_wrap)
160 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(logwin->text), GTK_WRAP_WORD);
164 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(logwin->text), GTK_WRAP_NONE);
168 static void log_window_timer_data_cb(GtkWidget *UNUSED(widget), gpointer UNUSED(data))
170 options->log_window.timer_data = !options->log_window.timer_data;
173 static void log_window_regexp_cb(GtkWidget *text_entry, gpointer UNUSED(data))
177 new_regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_entry)));
178 set_regexp(new_regexp);
182 static void remove_green_bg(LogWindow *logwin)
184 GtkTextIter start_find;
185 GtkTextIter start_match;
186 GtkTextIter end_match;
187 GtkTextBuffer *buffer;
193 text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
194 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
195 gtk_text_buffer_get_start_iter(buffer, &start_find);
197 while (gtk_text_iter_forward_search(&start_find, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL))
199 list = gtk_text_iter_get_tags(&start_match);
202 g_object_get(list->data, "name", &tag_name, NULL);
203 if (g_strcmp0(tag_name, "green_bg") == 0)
205 gtk_text_buffer_remove_tag_by_name(buffer, "green_bg", &start_match, &end_match);
211 offset = gtk_text_iter_get_offset(&end_match);
212 gtk_text_buffer_get_iter_at_offset(buffer, &start_find, offset);
216 static void search_activate_event(GtkEntry *UNUSED(widget), LogWindow *logwin)
218 GtkTextIter start_find;
219 GtkTextIter start_match;
220 GtkTextIter end_match;
221 GtkTextBuffer *buffer;
222 GtkTextMark *cursor_mark;
223 GtkTextIter cursor_iter;
227 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
228 text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
230 if (logwin->highlight_all)
232 gtk_text_buffer_get_start_iter(buffer, &start_find);
234 while (gtk_text_iter_forward_search(&start_find, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL))
236 gtk_text_buffer_apply_tag_by_name(buffer, "gray_bg", &start_match, &end_match);
237 offset = gtk_text_iter_get_offset(&end_match);
238 gtk_text_buffer_get_iter_at_offset(buffer, &start_find, offset);
243 cursor_mark = gtk_text_buffer_get_insert(buffer);
244 gtk_text_buffer_get_iter_at_mark(buffer, &cursor_iter, cursor_mark);
246 if (gtk_text_iter_forward_search(&cursor_iter, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL))
248 gtk_text_buffer_apply_tag_by_name(buffer, "gray_bg", &start_match, &end_match);
253 static gboolean search_keypress_event(GtkWidget *UNUSED(widget), GdkEventKey *UNUSED(event), LogWindow *logwin, LogWindowSearchDirection direction)
255 GtkTextIter start_find;
256 GtkTextIter start_match;
257 GtkTextIter end_match;
258 GtkTextIter start_sel;
261 GtkTextBuffer *buffer;
262 GtkTextMark *cursor_mark;
263 GtkTextIter cursor_iter;
265 gboolean match_found = FALSE;
268 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
269 gtk_text_buffer_get_start_iter(buffer, &start_find);
271 text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
272 if (strlen(text) == 0)
274 selected = gtk_text_buffer_get_selection_bounds(buffer, &start_sel, &end_sel);
277 text = gtk_text_buffer_get_text(buffer, &start_sel, &end_sel, FALSE);
278 gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), text);
282 if (logwin->highlight_all)
284 while (gtk_text_iter_forward_search(&start_find, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL))
286 gtk_text_buffer_apply_tag_by_name(buffer, "gray_bg", &start_match, &end_match);
287 offset = gtk_text_iter_get_offset(&end_match);
288 gtk_text_buffer_get_iter_at_offset(buffer, &start_find, offset);
292 cursor_mark = gtk_text_buffer_get_insert(buffer);
293 gtk_text_buffer_get_iter_at_mark(buffer, &cursor_iter, cursor_mark);
295 if (direction == LOGWINDOW_SEARCH_BACKWARDS)
297 match_found = gtk_text_iter_backward_search( &cursor_iter, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL);
301 match_found = gtk_text_iter_forward_search( &cursor_iter, text, GTK_TEXT_SEARCH_VISIBLE_ONLY, &start_match, &end_match, NULL);
306 remove_green_bg(logwin);
308 gtk_text_buffer_apply_tag_by_name(buffer, "green_bg", &start_match, &end_match);
310 if (direction == LOGWINDOW_SEARCH_BACKWARDS)
312 gtk_text_buffer_place_cursor(buffer, &start_match);
316 gtk_text_buffer_place_cursor(buffer, &end_match);
319 cursor_mark = gtk_text_buffer_get_insert(buffer);
320 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(logwin->text), cursor_mark, 0.2, FALSE, 0.0, 0.0);
326 static gboolean backwards_keypress_event_cb(GtkWidget *widget, GdkEventKey *event, LogWindow *logwin)
328 search_keypress_event(widget, event, logwin, LOGWINDOW_SEARCH_BACKWARDS);
333 static gboolean forwards_keypress_event_cb(GtkWidget *widget, GdkEventKey *event, LogWindow *logwin)
335 search_keypress_event(widget, event, logwin, LOGWINDOW_SEARCH_FORWARDS);
340 static gboolean all_keypress_event_cb(GtkToggleButton *widget, LogWindow *logwin)
342 logwin->highlight_all = gtk_toggle_button_get_active(widget);
347 static gboolean debug_changed_cb(GtkSpinButton *widget, LogWindow *UNUSED(logwin))
349 set_debug_level((gtk_spin_button_get_value(widget)));
354 static void search_entry_icon_cb(GtkEntry *UNUSED(entry), GtkEntryIconPosition pos, GdkEvent *UNUSED(event), gpointer userdata)
356 LogWindow *logwin = static_cast<LogWindow *>(userdata);
357 GtkTextIter start_find;
358 GtkTextIter end_find;
359 GtkTextBuffer *buffer;
361 if (pos == GTK_ENTRY_ICON_SECONDARY)
363 gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), "");
365 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
366 gtk_text_buffer_get_start_iter(buffer, &start_find);
367 gtk_text_buffer_get_end_iter(buffer, &end_find);
368 gtk_text_buffer_remove_tag_by_name(buffer, "gray_bg", &start_find, &end_find);
369 gtk_text_buffer_remove_tag_by_name(buffer, "green_bg", &start_find, &end_find);
373 static void filter_entry_icon_cb(GtkEntry *entry, GtkEntryIconPosition UNUSED(pos), GdkEvent *UNUSED(event), gpointer UNUSED(userdata))
375 const gchar *blank = "";
376 gtk_entry_set_text(entry, blank);
380 static LogWindow *log_window_create(LayoutWindow *lw)
384 GtkWidget *scrolledwin;
386 GtkTextBuffer *buffer;
391 GtkWidget *label = NULL;
392 GtkWidget *search_box;
393 GtkWidget *backwards_button;
394 GtkWidget *forwards_button;
395 GtkWidget *all_button;
398 GtkWidget *image = NULL;
400 logwin = g_new0(LogWindow, 1);
402 window = window_new(GTK_WINDOW_TOPLEVEL, "log", NULL, NULL, _("Log"));
404 win_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
405 gtk_container_add(GTK_CONTAINER(window), win_vbox);
406 gtk_widget_show(win_vbox);
408 gtk_window_resize(GTK_WINDOW(window), lw->options.log_window.w,
409 lw->options.log_window.h);
410 gtk_window_move(GTK_WINDOW(window), lw->options.log_window.x, lw->options.log_window.y);
412 g_signal_connect(G_OBJECT(window), "delete_event",
413 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
414 g_signal_connect(G_OBJECT(window), "key_press_event",
415 G_CALLBACK(key_pressed), logwin);
416 g_signal_connect(G_OBJECT(window), "hide",
417 G_CALLBACK(hide_cb), logwin);
418 gtk_widget_realize(window);
420 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
421 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
422 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
423 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
426 gtk_box_pack_start(GTK_BOX(win_vbox), scrolledwin, TRUE, TRUE, 0);
427 gtk_widget_show(scrolledwin);
429 text = gtk_text_view_new();
430 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
431 if (options->log_window.line_wrap)
433 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
437 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
439 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
440 gtk_text_buffer_get_start_iter(buffer, &iter);
441 gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE);
442 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
443 gtk_widget_show(text);
446 gtk_text_buffer_create_tag(buffer, "gray_bg", "background", "gray", NULL);
447 gtk_text_buffer_create_tag(buffer, "green_bg", "background", "#00FF00", NULL);
449 hbox = pref_box_new(win_vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
451 gtk_widget_show(hbox);
452 logwin->debug_level = pref_spin_new_int(hbox, _("Debug level:"), NULL, 0, 4, 1, get_debug_level(), &logwin->debug_value);
453 g_signal_connect(logwin->debug_level, "value-changed", G_CALLBACK(debug_changed_cb), logwin);
455 logwin->pause = gtk_toggle_button_new();
456 label = gtk_label_new("Pause");
457 gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->pause), _("Pause scrolling"));
458 gtk_container_add(GTK_CONTAINER(logwin->pause), label) ;
459 gtk_box_pack_start(GTK_BOX(hbox),logwin->pause, FALSE, FALSE, 0) ;
460 g_signal_connect(logwin->pause, "toggled", G_CALLBACK(log_window_pause_cb), logwin);
461 gtk_widget_show_all(logwin->pause);
463 logwin->wrap = gtk_toggle_button_new();
464 label = gtk_label_new("Wrap");
465 gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->wrap), _("Enable line wrap"));
466 gtk_container_add(GTK_CONTAINER(logwin->wrap), label) ;
467 gtk_box_pack_start(GTK_BOX(hbox),logwin->wrap, FALSE, FALSE, 0) ;
468 g_signal_connect(logwin->wrap, "toggled", G_CALLBACK(log_window_line_wrap_cb), logwin);
469 gtk_widget_show_all(logwin->wrap);
471 logwin->timer_data = gtk_toggle_button_new();
472 label = gtk_label_new("Timer");
473 gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->timer_data), _("Enable timer data"));
474 gtk_container_add(GTK_CONTAINER(logwin->timer_data), label) ;
475 gtk_box_pack_start(GTK_BOX(hbox),logwin->timer_data, FALSE, FALSE, 0) ;
476 if (options->log_window.timer_data)
478 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(logwin->timer_data), TRUE);
480 g_signal_connect(logwin->timer_data, "toggled", G_CALLBACK(log_window_timer_data_cb), logwin);
481 gtk_widget_show_all(logwin->timer_data);
483 search_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
484 gtk_container_add(GTK_CONTAINER(hbox), search_box);
485 gtk_widget_show(search_box);
487 logwin->search_entry_box = gtk_entry_new();
488 gtk_box_pack_start(GTK_BOX(search_box), logwin->search_entry_box, FALSE, FALSE, 0);
489 gtk_widget_show(logwin->search_entry_box);
490 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND);
491 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
492 gtk_widget_show(search_box);
493 gtk_widget_set_tooltip_text(logwin->search_entry_box, _("Search for text in log window"));
494 g_signal_connect(logwin->search_entry_box, "icon-press", G_CALLBACK(search_entry_icon_cb), logwin);
495 g_signal_connect(logwin->search_entry_box, "activate", G_CALLBACK(search_activate_event), logwin);
497 theme = gtk_icon_theme_get_default();
498 pixbuf = gtk_icon_theme_load_icon(theme, "pan-up-symbolic", 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
499 image = gtk_image_new_from_pixbuf(pixbuf);
500 backwards_button = gtk_button_new();
501 gtk_button_set_image(GTK_BUTTON(backwards_button), GTK_WIDGET(image));
502 gtk_widget_set_tooltip_text(backwards_button, _("Search backwards"));
503 gtk_box_pack_start(GTK_BOX(search_box), backwards_button, FALSE, FALSE, 0);
504 gtk_widget_show(backwards_button);
505 g_signal_connect(backwards_button, "button_release_event", G_CALLBACK(backwards_keypress_event_cb), logwin);
506 g_object_unref(pixbuf);
508 pixbuf = gtk_icon_theme_load_icon(theme, "pan-down-symbolic", 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
509 image = gtk_image_new_from_pixbuf(pixbuf);
510 forwards_button = gtk_button_new();
511 gtk_button_set_image(GTK_BUTTON(forwards_button), GTK_WIDGET(image));
512 gtk_widget_set_tooltip_text(forwards_button, _("Search forwards"));
513 gtk_box_pack_start(GTK_BOX(search_box), forwards_button, FALSE, FALSE, 0);
514 gtk_widget_show(forwards_button);
515 g_signal_connect(forwards_button, "button_release_event", G_CALLBACK(forwards_keypress_event_cb), logwin);
516 g_object_unref(pixbuf);
518 pixbuf = gtk_icon_theme_load_icon(theme, "edit-select-all-symbolic", 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
519 image = gtk_image_new_from_pixbuf(pixbuf);
520 all_button = gtk_toggle_button_new();
521 gtk_button_set_image(GTK_BUTTON(all_button), GTK_WIDGET(image));
522 gtk_widget_set_tooltip_text(GTK_WIDGET(all_button), _("Highlight all"));
523 gtk_box_pack_start(GTK_BOX(search_box), all_button, FALSE, FALSE, 0) ;
524 g_signal_connect(all_button, "toggled", G_CALLBACK(all_keypress_event_cb), logwin);
525 gtk_widget_show_all(all_button);
526 g_object_unref(pixbuf);
528 pref_label_new(hbox, _("Filter regexp"));
530 textbox = gtk_entry_new();
531 gtk_box_pack_start(GTK_BOX(hbox), textbox, FALSE, FALSE, 0);
532 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(textbox), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
533 gtk_widget_show(textbox);
534 g_signal_connect(G_OBJECT(textbox), "activate",
535 G_CALLBACK(log_window_regexp_cb), logwin);
536 g_signal_connect(textbox, "icon-press", G_CALLBACK(filter_entry_icon_cb), logwin);
539 logwin->window = window;
540 logwin->scrolledwin = scrolledwin;
543 logwin->regexp_box = textbox;
544 lw->log_window = logwin->window;
548 static void log_window_init(LogWindow *logwin)
550 GtkTextBuffer *buffer;
552 g_assert(logwin != NULL);
554 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
556 logwin->color_tags[LOG_NORMAL] = gtk_text_buffer_create_tag (buffer,
557 "black_foreground", "foreground", "black",
558 "family", "MonoSpace", NULL);
559 logwin->color_tags[LOG_MSG] = gtk_text_buffer_create_tag (buffer,
560 "blue_foreground", "foreground", "blue",
561 "family", "MonoSpace", NULL);
562 logwin->color_tags[LOG_WARN] = gtk_text_buffer_create_tag (buffer,
563 "orange_foreground", "foreground", "orange",
564 "family", "MonoSpace", NULL);
565 logwin->color_tags[LOG_ERROR] = gtk_text_buffer_create_tag (buffer,
566 "red_foreground", "foreground", "red",
567 "family", "MonoSpace", NULL);
570 static void log_window_show(LogWindow *logwin)
572 GtkTextView *text = GTK_TEXT_VIEW(logwin->text);
573 GtkTextBuffer *buffer;
577 buffer = gtk_text_view_get_buffer(text);
578 mark = gtk_text_buffer_get_mark(buffer, "end");
579 gtk_text_view_scroll_mark_onscreen(text, mark);
581 gtk_window_present(GTK_WINDOW(logwin->window));
583 log_window_append("", LOG_NORMAL); // to flush memorized lines
585 regexp = g_strdup(get_regexp());
588 gtk_entry_set_text(GTK_ENTRY(logwin->regexp_box), regexp);
593 void log_window_new(LayoutWindow *lw)
595 if (logwindow == NULL)
599 logwin = log_window_create(lw);
600 log_window_init(logwin);
604 log_window_show(logwindow);
607 typedef struct _LogMsg LogMsg;
614 static void log_window_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter,
615 const gchar *text, GtkTextTag *tag)
619 if (!text || !*text) return;
621 str_utf8 = utf8_validate_or_convert(text);
622 gtk_text_buffer_insert_with_tags(buffer, iter, str_utf8, -1, tag, NULL);
626 void log_window_append(const gchar *str, LogType type)
629 GtkTextBuffer *buffer;
631 static GList *memory = NULL;
633 if (logwindow == NULL)
636 LogMsg *msg = g_new(LogMsg, 1);
638 msg->text = g_strdup(str);
641 memory = g_list_prepend(memory, msg);
643 while (g_list_length(memory) >= (guint)options->log_window_lines)
645 GList *work = g_list_last(memory);
646 LogMsg *oldest_msg = static_cast<LogMsg *>(work->data);
648 g_free(oldest_msg->text);
649 memory = g_list_delete_link(memory, work);
655 text = GTK_TEXT_VIEW(logwindow->text);
656 buffer = gtk_text_view_get_buffer(text);
658 if (options->log_window_lines > 0 && logwindow->lines >= options->log_window_lines)
660 GtkTextIter start, end;
662 gtk_text_buffer_get_start_iter(buffer, &start);
664 gtk_text_iter_forward_lines(&end, logwindow->lines - options->log_window_lines);
665 gtk_text_buffer_delete(buffer, &start, &end);
668 gtk_text_buffer_get_end_iter(buffer, &iter);
671 GList *work = g_list_last(memory);
676 LogMsg *oldest_msg = static_cast<LogMsg *>(work->data);
678 log_window_insert_text(buffer, &iter, oldest_msg->text,
679 logwindow->color_tags[oldest_msg->type]);
682 memory = g_list_delete_link(memory, work);
687 log_window_insert_text(buffer, &iter, str, logwindow->color_tags[type]);
689 if (!options->log_window.paused)
691 if (gtk_widget_get_visible(GTK_WIDGET(text)))
695 mark = gtk_text_buffer_get_mark(buffer, "end");
696 gtk_text_view_scroll_mark_onscreen(text, mark);
700 logwindow->lines = gtk_text_buffer_get_line_count(buffer);
702 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */