Mercurial > geeqie.yaz
annotate src/logwindow.c @ 1516:c30965f99b3c
improved Scroll reset method in preferences dialog
author | nadvornik |
---|---|
date | Sun, 05 Apr 2009 09:25:48 +0000 |
parents | 8b89e3ff286b |
children | 0e6d7afe0739 |
rev | line source |
---|---|
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
1 /* |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
2 * Geeqie |
1284 | 3 * Copyright (C) 2008 - 2009 The Geeqie Team |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
4 * |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
5 * Author: Vladimir Nadvornik, Laurent Monin |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
6 * based on logwindow.[ch] from Sylpheed 2.4.7 (C) Hiroyuki Yamamoto |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
7 * |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
8 * This software is released under the GNU General Public License (GNU GPL). |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
9 * Please read the included file COPYING for more information. |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
10 * This software comes with no warranty of any kind, use at your own risk! |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
11 */ |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
12 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
13 #include "main.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
14 #include "logwindow.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
15 |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
767
diff
changeset
|
16 #include "misc.h" |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
17 #include "window.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
18 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
19 #include <gdk/gdkkeysyms.h> |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
20 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
21 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
22 typedef struct _LogWindow LogWindow; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
23 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
24 struct _LogWindow |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
25 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
26 GtkWidget *window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
27 GtkWidget *scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
28 GtkWidget *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
29 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
30 GdkColor colors[LOG_COUNT]; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
31 |
736 | 32 guint lines; |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
33 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
34 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
35 typedef struct _LogDef LogDef; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
36 struct _LogDef |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
37 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
38 LogType type; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
39 const gchar *tag; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
40 const gchar *color; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
41 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
42 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
43 /* Keep LogType order !! */ |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
44 static LogDef logdefs[LOG_COUNT] = { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
45 { LOG_NORMAL, "normal", "black" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
46 { LOG_MSG, "message", "blue" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
47 { LOG_WARN, "warning", "orange" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
48 { LOG_ERROR, "error", "red" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
49 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
50 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
51 static LogWindow *logwindow = NULL; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
52 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
53 static void hide_cb(GtkWidget *widget, LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
54 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
55 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
56 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
57 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
58 LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
59 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
60 if (event && event->keyval == GDK_Escape) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
61 gtk_widget_hide(logwin->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
62 return FALSE; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
63 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
64 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
65 static LogWindow *log_window_create(void) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
66 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
67 LogWindow *logwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
68 GtkWidget *window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
69 GtkWidget *scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
70 GtkWidget *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
71 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
72 GtkTextIter iter; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
73 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
74 logwin = g_new0(LogWindow, 1); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
75 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
76 window = window_new(GTK_WINDOW_TOPLEVEL, "log", NULL, NULL, _("Log")); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
77 gtk_widget_set_size_request(window, 520, 400); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
78 g_signal_connect(G_OBJECT(window), "delete_event", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
79 G_CALLBACK(gtk_widget_hide_on_delete), NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
80 g_signal_connect(G_OBJECT(window), "key_press_event", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
81 G_CALLBACK(key_pressed), logwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
82 g_signal_connect(G_OBJECT(window), "hide", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
83 G_CALLBACK(hide_cb), logwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
84 gtk_widget_realize(window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
85 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
86 scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
87 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
88 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
89 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
90 GTK_SHADOW_IN); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
91 gtk_container_add(GTK_CONTAINER(window), scrolledwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
92 gtk_widget_show(scrolledwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
93 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
94 text = gtk_text_view_new(); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
95 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
96 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
97 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
98 gtk_text_buffer_get_start_iter(buffer, &iter); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
99 gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
100 gtk_container_add(GTK_CONTAINER(scrolledwin), text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
101 gtk_widget_show(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
102 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
103 logwin->window = window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
104 logwin->scrolledwin = scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
105 logwin->text = text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
106 logwin->lines = 1; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
107 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
108 return logwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
109 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
110 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
111 static void log_window_init(LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
112 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
113 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
114 GdkColormap *colormap; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
115 gboolean success[LOG_COUNT - 1]; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
116 gint i; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
117 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
118 g_assert(logwin != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
119 g_assert(logwin->colors != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
120 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
121 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
122 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
123 gboolean ok = gdk_color_parse(logdefs[i].color, &logwin->colors[i]); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
124 if (ok == TRUE) continue; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
125 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
126 if (i == LOG_NORMAL) return; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
127 memcpy(&logwin->colors[i], &logwin->colors[LOG_NORMAL], sizeof(GdkColor)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
128 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
129 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
130 colormap = gdk_drawable_get_colormap(logwin->window->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
131 gdk_colormap_alloc_colors(colormap, logwin->colors, LOG_COUNT, FALSE, TRUE, success); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
132 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
133 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
134 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
135 if (success[i] == FALSE) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
136 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
137 GtkStyle *style; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
138 gint j; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
139 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
140 g_warning("LogWindow: color allocation failed\n"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
141 style = gtk_widget_get_style(logwin->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
142 for (j = LOG_NORMAL; j < LOG_COUNT; j++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
143 logwin->colors[j] = style->black; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
144 break; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
145 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
146 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
147 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
148 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
149 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
150 gtk_text_buffer_create_tag(buffer, logdefs[i].tag, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
151 "foreground-gdk", &logwin->colors[i], |
683 | 152 "family", "MonoSpace", |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
153 NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
154 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
155 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
156 static void log_window_show(LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
157 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
158 GtkTextView *text = GTK_TEXT_VIEW(logwin->text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
159 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
160 GtkTextMark *mark; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
161 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
162 g_assert(logwin != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
163 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
164 buffer = gtk_text_view_get_buffer(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
165 mark = gtk_text_buffer_get_mark(buffer, "end"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
166 gtk_text_view_scroll_mark_onscreen(text, mark); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
167 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
168 gtk_window_present(GTK_WINDOW(logwin->window)); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
169 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
170 log_window_append("", LOG_NORMAL); // to flush memorized lines |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
171 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
172 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
173 void log_window_new(void) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
174 { |
681 | 175 if (logwindow == NULL) |
176 { | |
177 LogWindow *logwin; | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
178 |
681 | 179 logwin = log_window_create(); |
180 log_window_init(logwin); | |
181 logwindow = logwin; | |
182 } | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
183 |
681 | 184 log_window_show(logwindow); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
185 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
186 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
187 typedef struct _LogMsg LogMsg; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
188 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
189 struct _LogMsg { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
190 gchar *text; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
191 LogType type; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
192 }; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
193 |
683 | 194 |
195 static void log_window_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter, | |
196 const gchar *text, const gchar *tag) | |
197 { | |
198 gchar *str_utf8; | |
199 | |
200 if (!text || !*text) return; | |
201 | |
767
e73d30e0c896
Make utf8_validate_or_convert() to always allocate a new string.
zas_
parents:
736
diff
changeset
|
202 str_utf8 = utf8_validate_or_convert(text); |
683 | 203 gtk_text_buffer_insert_with_tags_by_name(buffer, iter, str_utf8, -1, tag, NULL); |
767
e73d30e0c896
Make utf8_validate_or_convert() to always allocate a new string.
zas_
parents:
736
diff
changeset
|
204 g_free(str_utf8); |
683 | 205 } |
206 | |
207 | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
208 void log_window_append(const gchar *str, LogType type) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
209 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
210 GtkTextView *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
211 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
212 GtkTextIter iter; |
736 | 213 guint line_limit = 1000; //FIXME: option |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
214 static GList *memory = NULL; |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
215 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
216 if (logwindow == NULL) |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
217 { |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
218 if (*str) { |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
219 LogMsg *msg = g_new(LogMsg, 1); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
220 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
221 msg->text = g_strdup(str); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
222 msg->type = type; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
223 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
224 memory = g_list_prepend(memory, msg); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
225 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
226 while (g_list_length(memory) >= line_limit) |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
227 { |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
228 GList *work = g_list_last(memory); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
229 LogMsg *oldest_msg = work->data; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
230 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
231 g_free(oldest_msg->text); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
232 memory = g_list_delete_link(memory, work); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
233 } |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
234 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
235 return; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
236 } |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
237 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
238 text = GTK_TEXT_VIEW(logwindow->text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
239 buffer = gtk_text_view_get_buffer(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
240 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
241 if (line_limit > 0 && logwindow->lines >= line_limit) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
242 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
243 GtkTextIter start, end; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
244 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
245 gtk_text_buffer_get_start_iter(buffer, &start); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
246 end = start; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
247 gtk_text_iter_forward_lines(&end, logwindow->lines - line_limit); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
248 gtk_text_buffer_delete(buffer, &start, &end); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
249 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
250 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
251 gtk_text_buffer_get_end_iter(buffer, &iter); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
252 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
253 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
254 GList *work = g_list_last(memory); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
255 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
256 while (work) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
257 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
258 GList *prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
259 LogMsg *oldest_msg = work->data; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
260 |
683 | 261 log_window_insert_text(buffer, &iter, oldest_msg->text, logdefs[oldest_msg->type].tag); |
262 | |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
263 prev = work->prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
264 memory = g_list_delete_link(memory, work); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
265 work = prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
266 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
267 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
268 |
683 | 269 log_window_insert_text(buffer, &iter, str, logdefs[type].tag); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
270 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
271 if (GTK_WIDGET_VISIBLE(text)) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
272 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
273 GtkTextMark *mark; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
274 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
275 mark = gtk_text_buffer_get_mark(buffer, "end"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
276 gtk_text_view_scroll_mark_onscreen(text, mark); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
277 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
278 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
279 logwindow->lines = gtk_text_buffer_get_line_count(buffer); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
280 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1022
diff
changeset
|
281 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |