comparison src/bar_comment.c @ 1309:55ea4962887a

config file format changed to XML save and restore all layout windows save and restore sidebar configuration
author nadvornik
date Sun, 22 Feb 2009 15:35:37 +0000
parents 8c59e6e50bd8
children 8cca18bce950
comparison
equal deleted inserted replaced
1308:2320339ca8be 1309:55ea4962887a
17 #include "bar.h" 17 #include "bar.h"
18 #include "metadata.h" 18 #include "metadata.h"
19 #include "filedata.h" 19 #include "filedata.h"
20 #include "ui_menu.h" 20 #include "ui_menu.h"
21 #include "ui_misc.h" 21 #include "ui_misc.h"
22 #include "rcfile.h"
22 23
23 static void bar_pane_comment_changed(GtkTextBuffer *buffer, gpointer data); 24 static void bar_pane_comment_changed(GtkTextBuffer *buffer, gpointer data);
24 25
25 /* 26 /*
26 *------------------------------------------------------------------- 27 *-------------------------------------------------------------------
36 PaneData pane; 37 PaneData pane;
37 GtkWidget *widget; 38 GtkWidget *widget;
38 GtkWidget *comment_view; 39 GtkWidget *comment_view;
39 FileData *fd; 40 FileData *fd;
40 gchar *key; 41 gchar *key;
42 gint height;
41 }; 43 };
42 44
43 45
44 static void bar_pane_comment_write(PaneCommentData *pcd) 46 static void bar_pane_comment_write(PaneCommentData *pcd)
45 { 47 {
128 pcd->fd = file_data_ref(fd); 130 pcd->fd = file_data_ref(fd);
129 131
130 bar_pane_comment_update(pcd); 132 bar_pane_comment_update(pcd);
131 } 133 }
132 134
133 gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event) 135 static gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event)
134 { 136 {
135 PaneCommentData *pcd; 137 PaneCommentData *pcd;
136 138
137 pcd = g_object_get_data(G_OBJECT(bar), "pane_data"); 139 pcd = g_object_get_data(G_OBJECT(bar), "pane_data");
138 if (!pcd) return FALSE; 140 if (!pcd) return FALSE;
139 141
140 if (GTK_WIDGET_HAS_FOCUS(pcd->comment_view)) return gtk_widget_event(pcd->comment_view, event); 142 if (GTK_WIDGET_HAS_FOCUS(pcd->comment_view)) return gtk_widget_event(pcd->comment_view, event);
141 143
142 return FALSE; 144 return FALSE;
145 }
146
147 static void bar_pane_comment_write_config(GtkWidget *pane, GString *outstr, gint indent)
148 {
149 PaneCommentData *pcd;
150
151 pcd = g_object_get_data(G_OBJECT(pane), "pane_data");
152 if (!pcd) return;
153
154 write_indent(outstr, indent);
155 g_string_append_printf(outstr, "<pane_comment\n");
156 indent++;
157 WRITE_CHAR(*pcd, pane.title);
158 WRITE_BOOL(*pcd, pane.expanded);
159 WRITE_CHAR(*pcd, key);
160 WRITE_INT(*pcd, height);
161 indent--;
162 write_indent(outstr, indent);
163 g_string_append_printf(outstr, "/>\n");
143 } 164 }
144 165
145 static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data) 166 static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data)
146 { 167 {
147 PaneCommentData *pcd = data; 168 PaneCommentData *pcd = data;
191 212
192 g_free(pcd); 213 g_free(pcd);
193 } 214 }
194 215
195 216
196 GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gint height) 217 GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gboolean expanded, gint height)
197 { 218 {
198 PaneCommentData *pcd; 219 PaneCommentData *pcd;
199 GtkWidget *scrolled; 220 GtkWidget *scrolled;
200 GtkTextBuffer *buffer; 221 GtkTextBuffer *buffer;
201 222
202 pcd = g_new0(PaneCommentData, 1); 223 pcd = g_new0(PaneCommentData, 1);
203 224
204 pcd->pane.pane_set_fd = bar_pane_comment_set_fd; 225 pcd->pane.pane_set_fd = bar_pane_comment_set_fd;
205 pcd->pane.pane_event = bar_pane_comment_event; 226 pcd->pane.pane_event = bar_pane_comment_event;
227 pcd->pane.pane_write_config = bar_pane_comment_write_config;
206 pcd->pane.title = g_strdup(title); 228 pcd->pane.title = g_strdup(title);
229 pcd->pane.expanded = expanded;
207 230
208 pcd->key = g_strdup(key); 231 pcd->key = g_strdup(key);
232 pcd->height = height;
209 233
210 scrolled = gtk_scrolled_window_new(NULL, NULL); 234 scrolled = gtk_scrolled_window_new(NULL, NULL);
211 235
212 pcd->widget = scrolled; 236 pcd->widget = scrolled;
213 g_object_set_data(G_OBJECT(pcd->widget), "pane_data", pcd); 237 g_object_set_data(G_OBJECT(pcd->widget), "pane_data", pcd);
235 file_data_register_notify_func(bar_pane_comment_notify_cb, pcd, NOTIFY_PRIORITY_LOW); 259 file_data_register_notify_func(bar_pane_comment_notify_cb, pcd, NOTIFY_PRIORITY_LOW);
236 260
237 return pcd->widget; 261 return pcd->widget;
238 } 262 }
239 263
264 GtkWidget *bar_pane_comment_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
265 {
266 gchar *title = g_strdup(_("NoName"));
267 gchar *key = g_strdup(COMMENT_KEY);
268 gboolean expanded = TRUE;
269 gint height = 50;
270
271 while (*attribute_names)
272 {
273 const gchar *option = *attribute_names++;
274 const gchar *value = *attribute_values++;
275
276 READ_CHAR_FULL("pane.title", title);
277 READ_CHAR_FULL("key", key);
278 READ_BOOL_FULL("pane.expanded", expanded);
279 READ_INT_FULL("height", height);
280
281
282 DEBUG_1("unknown attribute %s = %s", option, value);
283 }
284
285 return bar_pane_comment_new(title, key, expanded, height);
286 }
287
240 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ 288 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */