[Goodies-commits] r4072 - in xfbib/trunk: . src

Jesper Karlsson zarper at xfce.org
Wed Mar 19 01:17:01 CET 2008


Author: zarper
Date: 2008-03-19 00:17:01 +0000 (Wed, 19 Mar 2008)
New Revision: 4072

Modified:
   xfbib/trunk/TODO
   xfbib/trunk/src/entry_edit_dialog.c
   xfbib/trunk/src/open.c
   xfbib/trunk/src/treeview.c
   xfbib/trunk/src/treeview.h
Log:
Xfbib: Changed the inputmethod of Author and Editor to listform instead of entries.

Modified: xfbib/trunk/TODO
===================================================================
--- xfbib/trunk/TODO	2008-03-18 20:19:15 UTC (rev 4071)
+++ xfbib/trunk/TODO	2008-03-19 00:17:01 UTC (rev 4072)
@@ -2,8 +2,6 @@
 
 - Right click menu. (0.0.2)
 
-- Create a better input method for author and editor, now if the user does not add \and between the authors, and there are to many of them, the file will fail on compilation in bibtex.
-
 - Save before exiting dialog.
 
 - Test suite for the parser.

Modified: xfbib/trunk/src/entry_edit_dialog.c
===================================================================
--- xfbib/trunk/src/entry_edit_dialog.c	2008-03-18 20:19:15 UTC (rev 4071)
+++ xfbib/trunk/src/entry_edit_dialog.c	2008-03-19 00:17:01 UTC (rev 4072)
@@ -64,10 +64,9 @@
 	gtk_widget_modify_base(entry, GTK_STATE_NORMAL, &color);
 }
 
-static int change_color(GtkEntry *entry)
+static int change_color_entry(GtkEntry *entry)
 {
-	_DEBUG(("change_color"));
-	
+	_DEBUG(("change_color_entry"));
 	if (strcmp(gtk_entry_get_text(entry), "") == 0) {
 		set_color_base(GTK_WIDGET(entry), RED);
 		return 0;
@@ -77,6 +76,20 @@
 	}
 }
 
+static int change_color_view(GtkTreeView *entry)
+{
+	_DEBUG(("change_color_view"));
+	GtkTreeIter iter;
+	gboolean empty = gtk_tree_model_get_iter_first(gtk_tree_view_get_model(entry), &iter);
+	if (empty) {
+		set_color_base(GTK_WIDGET(entry), RED);
+		return 0;
+	} else {
+		set_color_base(GTK_WIDGET(entry), GREEN);
+		return 1;
+	}
+}
+
 static int get_entry_pos(char *str)
 {
 	_DEBUG(("get_entry_pos"));
@@ -110,76 +123,76 @@
 	switch(type) {
 		case ARTICLE:
 			_DEBUG(("Article"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("journal")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("journal")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case BOOK:
 			_DEBUG(("book"));
-			if (!change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry)))
-				if (change_color(GTK_ENTRY(entries[get_entry_pos("editor")].entry)))
+			if (!change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry)))
+				if (change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("editor")].entry)))
 					set_color_base(entries[get_entry_pos("author")].entry, WHITE);
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("publisher")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("publisher")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case BOOKLET:
 			_DEBUG(("booklet"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
 			break;
 		case CONFERENCE:
 		case INCOLLECTION:
 		case INPROCEEDINGS:
 			_DEBUG(("conference/incollection/inproceedings"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("booktitle")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("booktitle")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case INBOOK:
 			_DEBUG(("inbook"));
-			if (!change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry)))
-				if (change_color(GTK_ENTRY(entries[get_entry_pos("editor")].entry)))
+			if (!change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry)))
+				if (change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("editor")].entry)))
 					set_color_base(entries[get_entry_pos("author")].entry, WHITE);
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			if (!change_color(GTK_ENTRY(entries[get_entry_pos("chapter")].entry)))
-				if (change_color(GTK_ENTRY(entries[get_entry_pos("pages")].entry)))
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			if (!change_color_entry(GTK_ENTRY(entries[get_entry_pos("chapter")].entry)))
+				if (change_color_entry(GTK_ENTRY(entries[get_entry_pos("pages")].entry)))
 					set_color_base(entries[get_entry_pos("chapter")].entry, WHITE);
-			change_color(GTK_ENTRY(entries[get_entry_pos("publisher")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("publisher")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case MANUAL:
 			_DEBUG(("manual"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
 			break;
 		case MASTERSTHESIS:
 			_DEBUG(("mastersthesis"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("school")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("school")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case MISC:
 			_DEBUG(("misc"));
 			break;
 		case PHDTHESIS:
 			_DEBUG(("phdthesis"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case TECHREPORT:
 			_DEBUG(("techreport"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("institution")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("year")].entry));
+			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("institution")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("year")].entry));
 			break;
 		case UNPUBLISHED:
 			_DEBUG(("unpublished"));
-			change_color(GTK_ENTRY(entries[get_entry_pos("author")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("title")].entry));
-			change_color(GTK_ENTRY(entries[get_entry_pos("note")].entry));
+			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("title")].entry));
+			change_color_entry(GTK_ENTRY(entries[get_entry_pos("note")].entry));
 	}
 }
 
@@ -278,13 +291,39 @@
 		gtk_entry_set_text(entry, text);
 }
 
+static void add_event_handler (struct edit_entry *entry)
+{
+	_DEBUG(("add_event_handler"));
+	GtkListStore *list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(entry->entry)));
+	GtkTreeIter iter;
+	gtk_list_store_append(list, &iter);
+	gtk_list_store_set(list, &iter, 0, strcasecmp(gtk_label_get_text(GTK_LABEL(entry->label)), "author") == 0 ? "NewAuthor" : "NewEditor", -1);
+}
+
+static void remove_event_handler (struct edit_entry *entry)
+{
+	_DEBUG(("remove_event_handler"));
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GtkTreeSelection *selection;
+	
+	model = gtk_tree_view_get_model(GTK_TREE_VIEW(entry->entry));
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(entry->entry));
+	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+		gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
+	} else {
+		_DEBUG(("No row selected"));
+	}
+}
+
 void show_entry_edit_dialog(struct xfbib *xfbib, struct entry *selected)
 {
 	_DEBUG(("show_entry_edit_dialog"));
 	
-	GtkWidget *dialog, *notebook, *hbox, *key_entry, *combobox, *vbox[4];
+	GtkWidget *dialog, *notebook, *hbox, *key_entry, *combobox, *vbox[5];
+	GtkWidget *vboxes[2], *hboxes, *adds[2], *removes[2], *buttonboxes[2];
 	struct edit_entry edit_entry[N_ENTRIES];
-	int i, pos;
+	int i, pos, n;
 	struct tag *tags;
 	char *type;
 	const gchar *value, *key;
@@ -328,46 +367,78 @@
 
 	hbox = create_hbox(&combobox, &key_entry, edit_entry);
 
-	for (i = 0; i < 4; i++)
+	for (i = 0; i < 5; i++)
 		vbox[i] = gtk_vbox_new(FALSE, 10);
+		
+	hboxes = gtk_hbox_new(FALSE, 10);
 
 	for (i = 0; i < N_ENTRIES; i++)  {
-		edit_entry[i].label = gtk_label_new(i == HOWPUBLISHED ? N_("How Published") : label_entry[i]);
-		edit_entry[i].entry = gtk_entry_new();
-		gtk_entry_set_width_chars(GTK_ENTRY (edit_entry[i].entry), 30);
-		gtk_widget_set_tooltip_text (edit_entry[i].entry, tooltips[i]);
-		edit_entry[i].hbox = gtk_hbox_new(FALSE, 10);
-		edit_entry[i].toggle = gtk_toggle_button_new_with_label ("aA");
-		gtk_widget_set_tooltip_text (edit_entry[i].toggle, _("Toggle case sensitivity."));
-		gtk_box_pack_start(GTK_BOX(edit_entry[i].hbox), edit_entry[i].label, FALSE, FALSE, 10);
-		gtk_box_pack_end(GTK_BOX(edit_entry[i].hbox), edit_entry[i].toggle, FALSE, TRUE, 10);
-		gtk_box_pack_end(GTK_BOX(edit_entry[i].hbox), edit_entry[i].entry, FALSE, TRUE, 10);
-		g_signal_connect (G_OBJECT (GTK_ENTRY(edit_entry[i].entry)), "changed",
-                      G_CALLBACK (entry_changed_event), combobox);
+		if (i != AUTHOR && i != EDITOR) {
+			edit_entry[i].label = gtk_label_new(i == HOWPUBLISHED ? N_("How Published") : label_entry[i]);
+			edit_entry[i].entry = gtk_entry_new();
+			gtk_entry_set_width_chars(GTK_ENTRY (edit_entry[i].entry), 30);
+			gtk_widget_set_tooltip_text (edit_entry[i].entry, tooltips[i]);
+			edit_entry[i].hbox = gtk_hbox_new(FALSE, 10);
+			edit_entry[i].toggle = gtk_toggle_button_new_with_label ("aA");
+			gtk_widget_set_tooltip_text (edit_entry[i].toggle, _("Toggle case sensitivity."));
+			gtk_box_pack_start(GTK_BOX(edit_entry[i].hbox), edit_entry[i].label, FALSE, FALSE, 10);
+			gtk_box_pack_end(GTK_BOX(edit_entry[i].hbox), edit_entry[i].toggle, FALSE, TRUE, 10);
+			gtk_box_pack_end(GTK_BOX(edit_entry[i].hbox), edit_entry[i].entry, FALSE, TRUE, 10);
+			g_signal_connect (G_OBJECT (GTK_ENTRY(edit_entry[i].entry)), "changed",
+	                      G_CALLBACK (entry_changed_event), combobox);
 		
-		if (i == AUTHOR || i == EDITOR || i == INSTITUTION || i == ORGANIZATION || i == SCHOOL || i == TITLE || i == TYPE)
+		if (i == INSTITUTION || i == ORGANIZATION || i == SCHOOL || i == TITLE || i == TYPE)
 			gtk_box_pack_start (GTK_BOX (vbox[0]), edit_entry[i].hbox, FALSE, FALSE, 2);
+		//else if (i == AUTHOR || i == EDITOR)
+			//gtk_box_pack_start (GTK_BOX (vbox[1]), edit_entry[i].hbox, FALSE, FALSE, 2);
 		else if (i == BOOKTITLE || i == CHAPTER || i == EDITION || i == MONTH || i == NUMBER || i == PAGES || i == VOLUME || i == YEAR)
-			gtk_box_pack_start (GTK_BOX (vbox[1]), edit_entry[i].hbox, FALSE, FALSE, 2);
+			gtk_box_pack_start (GTK_BOX (vbox[2]), edit_entry[i].hbox, FALSE, FALSE, 2);
 		else if (i == ADDRESS || i == HOWPUBLISHED || i == JOURNAL || i == PUBLISHER || i == SERIES)
-			gtk_box_pack_start (GTK_BOX (vbox[2]), edit_entry[i].hbox, FALSE, FALSE, 2);
+			gtk_box_pack_start (GTK_BOX (vbox[3]), edit_entry[i].hbox, FALSE, FALSE, 2);
 		else
-			gtk_box_pack_start (GTK_BOX (vbox[3]), edit_entry[i].hbox, FALSE, FALSE, 2);
-	}
+			gtk_box_pack_start (GTK_BOX (vbox[4]), edit_entry[i].hbox, FALSE, FALSE, 2);
+		} else {
+			_DEBUG(("Author/Editor"));
+			n = (i == EDITOR);
+			edit_entry[i].label = gtk_label_new(label_entry[i]);
+			edit_entry[i].entry = create_author_editor_treeview(xfbib, (char*) label_entry[i]);
+			adds[n] = gtk_button_new_from_stock(GTK_STOCK_ADD);
+			removes[n] = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
+			edit_entry[i].toggle = gtk_toggle_button_new_with_label ("aA");
+			gtk_widget_set_tooltip_text (edit_entry[i].toggle, _("Toggle case sensitivity."));
+			vboxes[n] = gtk_vbox_new(FALSE, 10);
+			buttonboxes[n] = gtk_hbox_new(FALSE, 10);
+			gtk_box_pack_start(GTK_BOX(vboxes[n]), edit_entry[i].entry, TRUE, TRUE, 10);
+			gtk_box_pack_start(GTK_BOX(buttonboxes[n]), adds[n], FALSE, FALSE, 10);
+			gtk_box_pack_start(GTK_BOX(buttonboxes[n]), removes[n], FALSE, FALSE, 10);
+			g_signal_connect_swapped(G_OBJECT(adds[n]), "clicked", G_CALLBACK(add_event_handler), &edit_entry[i]);
+			g_signal_connect_swapped(G_OBJECT(removes[n]), "clicked", G_CALLBACK(remove_event_handler), &edit_entry[i]);
+			gtk_box_pack_start(GTK_BOX(buttonboxes[n]), edit_entry[i].toggle, FALSE, FALSE, 10);
+			gtk_box_pack_start(GTK_BOX(vboxes[n]), buttonboxes[n], FALSE, FALSE, 10);
+			gtk_box_pack_start(GTK_BOX(hboxes), vboxes[n], FALSE, FALSE, 10);
+		}
+	}	
 
 	notebook = gtk_notebook_new ();
 	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
 	
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[0], gtk_label_new(_("Title")));	
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[1], gtk_label_new(_("Publication")));	
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[2], gtk_label_new(_("Publisher")));	
-	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[3], gtk_label_new(_("Misc")));	
+	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[0], gtk_label_new(_("Title")));
+	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), hboxes, gtk_label_new(_("Author/Editor")));
+	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[2], gtk_label_new(_("Publication")));	
+	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[3], gtk_label_new(_("Publisher")));	
+	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox[4], gtk_label_new(_("Misc")));	
 
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 10);
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, TRUE, 10);
 
 	gtk_widget_show_all(dialog);
 
+	GtkListStore *list;
+	GtkTreeIter iter;
+	GtkTreeModel *model;
+	int x, max, len;
+	char *prev, *tmp, *str;
+
 	if (selected != NULL) {
 		_DEBUG(("Entry selected"));
 		if ((pos = get_type_pos(selected->type)) != -1) {
@@ -377,7 +448,32 @@
 			for (tags = selected->tags; tags != NULL; tags = tags->next) {
 				pos = get_entry_pos(tags->name);
 				if (pos != -1) {
-					set_entry_text(GTK_ENTRY(edit_entry[pos].entry), tags->value);
+					if (pos == AUTHOR || pos == EDITOR) {
+						_DEBUG(("read in author or editor"));
+						list = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(edit_entry[pos].entry)));
+						
+						str = tags->value;
+						max = strlen(str);
+						for(x = 0, prev = str; x < max; x++) {
+							if (str[x] == ' ' && str[x+1] == '\\' && str[x+2] == 'a' && str[x+3] == 'n' && str[x+4] == 'd' && str[x+5] == ' ') {
+								len = &str[x] - prev;
+								tmp = malloc(sizeof(char) * (len+1));
+								strncpy(tmp, prev, len);
+								tmp[len+1] = '\0';
+								gtk_list_store_append(list, &iter);
+								gtk_list_store_set(list, &iter, 0, tmp, -1);
+								prev = &str[x+6];
+							}
+						}
+						len = &str[x] - prev;
+						tmp = malloc(sizeof(char) * (len+1));
+						strncpy(tmp, prev, len);
+						tmp[len+1] = '\0';
+						gtk_list_store_append(list, &iter);
+						gtk_list_store_set(list, &iter, 0, tmp, -1);
+					} else {
+						set_entry_text(GTK_ENTRY(edit_entry[pos].entry), tags->value);
+					}
 					if (tags->sense)
 						gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (edit_entry[pos].toggle), TRUE);
 					else
@@ -405,7 +501,6 @@
 			} else {
 				if (selected == NULL) {
 					_DEBUG(("Add new entry"));
-					/* TODO: Maybe you shouldnt have to set the type and key */
 					selected = add_entry(&xfbib->list, type,(char*) key);
 				} else {
 					_DEBUG(("Edit old entry"));
@@ -414,7 +509,28 @@
 					free_tags(selected->tags);
 				}
 				for (i = 0; i < N_ENTRIES; i++) {
-					value = gtk_entry_get_text(GTK_ENTRY(edit_entry[i].entry));
+					if (i == AUTHOR || i == EDITOR) {
+						model = gtk_tree_view_get_model(GTK_TREE_VIEW(edit_entry[i].entry));
+						if (gtk_tree_model_get_iter_first(model, &iter)) {
+							_DEBUG(("Pasting together Author/Editor"));
+							value = "";
+							do {
+								_DEBUG(("Pasting together Author/Editor"));
+								gtk_tree_model_get (model, &iter, 0, &tmp);
+								_DEBUG(("Pasting together Author/Editor"));
+								if (strcmp(value, "") == 0) {
+									_DEBUG(("IF"));
+									value = strdup(tmp);
+								} else {
+									_DEBUG(("ELSE"));
+									value = strcat(strcat((char *) value, " \\and "),tmp);
+								}
+									_DEBUG(("Pasting together Author/Editor"));
+							} while (gtk_tree_model_iter_next(model, &iter));
+						}
+					} else {
+						value = gtk_entry_get_text(GTK_ENTRY(edit_entry[i].entry));
+					}
 					if(GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(edit_entry[i].entry)) && (strcmp(value, "") != 0)) {
 						fprintf(stderr, "label = %s\tvalue = %s\n",
 								gtk_label_get_text(GTK_LABEL(edit_entry[i].label)), value);

Modified: xfbib/trunk/src/open.c
===================================================================
--- xfbib/trunk/src/open.c	2008-03-18 20:19:15 UTC (rev 4071)
+++ xfbib/trunk/src/open.c	2008-03-19 00:17:01 UTC (rev 4072)
@@ -32,6 +32,6 @@
 	update_treeview(xfbib);
 	_DEBUG(("Opening: %s", xfbib->filename));
 	gtk_window_set_title(GTK_WINDOW(xfbib->window.window), create_title(xfbib));
-	statusbar_push((GtkStatusbar *) xfbib->window.statusbar, 0, strcat(filename, _(" loaded...")));
+	statusbar_push((GtkStatusbar *) xfbib->window.statusbar, 0, /*strcat(filename,*/ _(" loaded...")/*)*/);	//TODO: Investigate why this fails sometimes.
 	return 0;
 }

Modified: xfbib/trunk/src/treeview.c
===================================================================
--- xfbib/trunk/src/treeview.c	2008-03-18 20:19:15 UTC (rev 4071)
+++ xfbib/trunk/src/treeview.c	2008-03-19 00:17:01 UTC (rev 4072)
@@ -17,6 +17,7 @@
 #include <libxfcegui4/libxfcegui4.h>
 #include <libintl.h>
 #include <config.h>
+#include <string.h>
 
 #include "treeview.h"
 #include "xfbib.h"
@@ -60,6 +61,43 @@
 	}
 }
 
+static void cell_edited (GtkCellRendererText *renderer, char *path, char *new_text, GtkTreeView *treeview)
+{
+	_DEBUG(("cell edited"));
+	GtkTreeIter iter;
+	GtkTreeModel *model;
+	if (strcasecmp (new_text, "") != 0) {
+  		model = gtk_tree_view_get_model (treeview);
+  		if (gtk_tree_model_get_iter_from_string (model, &iter, path))
+    		gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, new_text, -1);
+  	}
+}
+
+GtkWidget *create_author_editor_treeview(struct xfbib *xfbib, char *title)
+{
+	_DEBUG(("create_author_editor_treeview"));
+	GtkWidget *treeview;
+	GtkListStore *list;
+	GtkCellRenderer *renderer;
+	GtkTreeViewColumn *column;
+
+	treeview = gtk_tree_view_new();
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(renderer, "editable", TRUE, NULL);
+    g_signal_connect(renderer, "edited", (GCallback) cell_edited, treeview);
+    
+    column = gtk_tree_view_column_new_with_attributes(title, renderer, "text", 0, NULL);
+    gtk_tree_view_column_set_resizable(GTK_TREE_VIEW_COLUMN(column), TRUE);
+    gtk_tree_view_column_set_min_width(GTK_TREE_VIEW_COLUMN(column), 100);
+   	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
+
+	list = gtk_list_store_new (VAR_N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);
+
+	gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(list));
+	return treeview; 
+}
+
 GtkWidget *create_variable_treeview(struct xfbib *xfbib)
 {
 	_DEBUG(("create_variable_treeview"));

Modified: xfbib/trunk/src/treeview.h
===================================================================
--- xfbib/trunk/src/treeview.h	2008-03-18 20:19:15 UTC (rev 4071)
+++ xfbib/trunk/src/treeview.h	2008-03-19 00:17:01 UTC (rev 4072)
@@ -34,4 +34,5 @@
 
 GtkWidget *create_main_treeview(struct xfbib*);
 GtkWidget *create_variable_treeview(struct xfbib*);
+GtkWidget *create_author_editor_treeview(struct xfbib *xfbib, char *title);
 void update_treeview(struct xfbib*);




More information about the Goodies-commits mailing list