[Goodies-commits] r4130 - xfbib/trunk/src

Jesper Karlsson zarper at xfce.org
Sun Mar 30 00:10:21 CET 2008


Author: zarper
Date: 2008-03-29 23:10:21 +0000 (Sat, 29 Mar 2008)
New Revision: 4130

Modified:
   xfbib/trunk/src/entry_edit_dialog.c
   xfbib/trunk/src/open.c
   xfbib/trunk/src/treeview.c
Log:
Xfbib: Author and editor lists now get colored correctly.
Fixed some memory issues.

Modified: xfbib/trunk/src/entry_edit_dialog.c
===================================================================
--- xfbib/trunk/src/entry_edit_dialog.c	2008-03-29 20:11:43 UTC (rev 4129)
+++ xfbib/trunk/src/entry_edit_dialog.c	2008-03-29 23:10:21 UTC (rev 4130)
@@ -39,6 +39,8 @@
 	"Institution", "Journal", "Key", "Month", "Note",
 	"Number", "Organization", "Pages", "Publisher", "School",
 	"Series", "Title", "Type", "URL", "Volume", "Year"};
+	
+gint combobox_type;
 
 static char* get_last_name(char *name)
 {
@@ -98,8 +100,8 @@
 		color.green = 0xffff;
 		color.blue = 0xffff;
 	}
-
-	gtk_widget_modify_base(entry, GTK_STATE_NORMAL, &color);
+	if (entry != NULL)
+		gtk_widget_modify_base(entry, GTK_STATE_NORMAL, &color);
 }
 
 static int change_color_entry(GtkEntry *entry)
@@ -141,10 +143,12 @@
 	return -1;
 }
 
-static void entry_colors(struct edit_entry *entries, gint type)
+static void entry_colors(struct edit_entry *entries)
 {
 	_DEBUG(("entry_colors"));
 	
+	extern gint combobox_type;
+	
 	set_color_base(entries[get_entry_pos("author")].entry, WHITE);
 	set_color_base(entries[get_entry_pos("editor")].entry, WHITE);
 	set_color_base(entries[get_entry_pos("chapter")].entry, WHITE);
@@ -158,7 +162,7 @@
 	set_color_base(entries[get_entry_pos("institution")].entry, WHITE);
 	set_color_base(entries[get_entry_pos("note")].entry, WHITE);
 	
-	switch(type) {
+	switch(combobox_type) {
 		case ARTICLE:
 			_DEBUG(("Article"));
 			change_color_view(GTK_TREE_VIEW(entries[get_entry_pos("author")].entry));
@@ -234,10 +238,12 @@
 	}
 }
 
-static void entry_sensitivity(struct edit_entry *entries, gint type)
+static void entry_sensitivity(struct edit_entry *entries)
 {
 	_DEBUG(("entry_sensitivity"));
 	
+	extern gint combobox_type;
+	
 	/* These entries are not used by any of the standard types in BibTeX */
 	//gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("url")].entry), FALSE);
 	//gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("e-print")].entry), FALSE);
@@ -251,36 +257,38 @@
 	//gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("key")].entry), TRUE);
 	//gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("note")].entry), TRUE);
 	
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("author")].entry), type == PROCEEDINGS ? FALSE : TRUE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("editor")].entry), type == BOOK || type == CONFERENCE || type == INBOOK || type == INCOLLECTION || type == INPROCEEDINGS || type == PROCEEDINGS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("institution")].entry), type == TECHREPORT || type == MASTERSTHESIS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("organization")].entry), type == CONFERENCE || type == INCOLLECTION || type == INPROCEEDINGS || type == MANUAL || type == PROCEEDINGS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("school")].entry), type == MASTERSTHESIS || type == PHDTHESIS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("type")].entry), type == TECHREPORT ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("booktitle")].entry), type == CONFERENCE || type == INCOLLECTION || type == INPROCEEDINGS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("chapter")].entry), type == INBOOK ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("edition")].entry), type == BOOK || type == INBOOK || type == MANUAL ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("number")].entry), type == ARTICLE || type == TECHREPORT ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("pages")].entry), type == ARTICLE || type == CONFERENCE || type == INBOOK || type == INCOLLECTION || type == INPROCEEDINGS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("volume")].entry), type == ARTICLE || type == BOOK || type == INBOOK ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("address")].entry), type == ARTICLE || type == MISC || type == UNPUBLISHED ? FALSE : TRUE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("howpublished")].entry), type == BOOKLET || type == MISC ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("journal")].entry), type == ARTICLE ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("publisher")].entry), type == BOOK || type == CONFERENCE || type == INBOOK || type == INCOLLECTION || type == INPROCEEDINGS || type == PROCEEDINGS ? TRUE : FALSE);
-	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("series")].entry), type == BOOK || type == INBOOK ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("author")].entry), combobox_type == PROCEEDINGS ? FALSE : TRUE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("editor")].entry), combobox_type == BOOK || combobox_type == CONFERENCE || combobox_type == INBOOK || combobox_type == INCOLLECTION || combobox_type == INPROCEEDINGS || combobox_type == PROCEEDINGS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("institution")].entry), combobox_type == TECHREPORT || combobox_type == MASTERSTHESIS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("organization")].entry), combobox_type == CONFERENCE || combobox_type == INCOLLECTION || combobox_type == INPROCEEDINGS || combobox_type == MANUAL || combobox_type == PROCEEDINGS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("school")].entry), combobox_type == MASTERSTHESIS || combobox_type == PHDTHESIS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("type")].entry), combobox_type == TECHREPORT ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("booktitle")].entry), combobox_type == CONFERENCE || combobox_type == INCOLLECTION || combobox_type == INPROCEEDINGS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("chapter")].entry), combobox_type == INBOOK ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("edition")].entry), combobox_type == BOOK || combobox_type == INBOOK || combobox_type == MANUAL ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("number")].entry), combobox_type == ARTICLE || combobox_type == TECHREPORT ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("pages")].entry), combobox_type == ARTICLE || combobox_type == CONFERENCE || combobox_type == INBOOK || combobox_type == INCOLLECTION || combobox_type == INPROCEEDINGS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("volume")].entry), combobox_type == ARTICLE || combobox_type == BOOK || combobox_type == INBOOK ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("address")].entry), combobox_type == ARTICLE || combobox_type == MISC || combobox_type == UNPUBLISHED ? FALSE : TRUE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("howpublished")].entry), combobox_type == BOOKLET || combobox_type == MISC ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("journal")].entry), combobox_type == ARTICLE ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("publisher")].entry), combobox_type == BOOK || combobox_type == CONFERENCE || combobox_type == INBOOK || combobox_type == INCOLLECTION || combobox_type == INPROCEEDINGS || combobox_type == PROCEEDINGS ? TRUE : FALSE);
+	gtk_widget_set_sensitive(GTK_WIDGET(entries[get_entry_pos("series")].entry), combobox_type == BOOK || combobox_type == INBOOK ? TRUE : FALSE);
 }
 
-static void combobox_changed_event(GtkComboBox *widget, struct edit_entry *edit_entry)
+static void combobox_changed_event(GtkComboBox *widget, struct edit_entry *edit_entries)
 {
 	_DEBUG(("combobox_changed_event"));
-	entry_colors(edit_entry, gtk_combo_box_get_active(widget));
-	entry_sensitivity(edit_entry, gtk_combo_box_get_active(widget));
+	extern gint combobox_type;
+	combobox_type = gtk_combo_box_get_active(widget);
+	entry_colors(edit_entries);
+	entry_sensitivity(edit_entries);
 }
 
-static void entry_changed_event(GtkEntry *widget, GtkComboBox *combobox)
+static void entry_changed_event(GtkEntry *widget, struct edit_entry *edit_entries)
 {
 	_DEBUG(("entry_changed_event"));
-	g_signal_emit_by_name(G_OBJECT (combobox), "changed");
+	entry_colors(edit_entries);
 }
 
 static GtkWidget *create_hbox(GtkWidget **combobox, GtkWidget **key_entry, gpointer edit_entry)
@@ -305,7 +313,7 @@
 	gtk_entry_completion_set_text_column (completion, 0);
 	gtk_entry_completion_set_minimum_key_length(completion, 0);
 
-        g_signal_connect(GTK_WIDGET(*key_entry), "focus-in-event", G_CALLBACK(cb_focus_in_event), edit_entry);
+    g_signal_connect(GTK_WIDGET(*key_entry), "focus-in-event", G_CALLBACK(cb_focus_in_event), edit_entry);
 
 
 	*combobox = gtk_combo_box_new_text();
@@ -344,31 +352,64 @@
 		gtk_entry_set_text(entry, text);
 }
 
-static void add_event_handler (struct edit_entry *entry)
+static void add_author_event_handler (struct edit_entry *edit_entries)
 {
 	_DEBUG(("add_event_handler"));
+	struct edit_entry *entry = (struct edit_entry *) &edit_entries[get_entry_pos("author")];
 	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);
+	gtk_list_store_set(list, &iter, 0, "NewAuthor", -1);
+	entry_colors(edit_entries);
 }
 
-static void remove_event_handler (struct edit_entry *entry)
+static void remove_author_event_handler (struct edit_entry *edit_entries)
 {
 	_DEBUG(("remove_event_handler"));
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 	GtkTreeSelection *selection;
 	
+	struct edit_entry *entry = (struct edit_entry *) &edit_entries[get_entry_pos("author")];
 	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);
+		entry_colors(edit_entries);
 	} else {
 		_DEBUG(("No row selected"));
 	}
 }
 
+static void add_editor_event_handler (struct edit_entry *edit_entries)
+{
+	_DEBUG(("add_event_handler"));
+	struct edit_entry *entry = (struct edit_entry *) &edit_entries[get_entry_pos("editor")];
+	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, "NewEditor", -1);
+	entry_colors(edit_entries);
+}
+
+static void remove_editor_event_handler (struct edit_entry *edit_entries)
+{
+	_DEBUG(("remove_event_handler"));
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GtkTreeSelection *selection;
+	
+	struct edit_entry *entry = (struct edit_entry *) &edit_entries[get_entry_pos("editor")];
+	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);
+		entry_colors(edit_entries);
+	} else {
+		_DEBUG(("No row selected"));
+	}
+}
+
 static void set_list_text (GtkListStore *list, char *str)
 {
 	_DEBUG(("set_list_text"));
@@ -463,7 +504,7 @@
 			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 (edit_entry[i].entry), "changed", G_CALLBACK (entry_changed_event), combobox);
+			g_signal_connect (G_OBJECT (edit_entry[i].entry), "changed", G_CALLBACK (entry_changed_event), edit_entry);
 		
 			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);
@@ -484,8 +525,13 @@
 			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], TRUE, FALSE, 1);
 			gtk_box_pack_start(GTK_BOX(buttonboxes[n]), removes[n], TRUE, FALSE, 1);
-			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]);
+			if (i == AUTHOR) {
+				g_signal_connect_swapped(G_OBJECT(adds[n]), "clicked", G_CALLBACK(add_author_event_handler), edit_entry);
+				g_signal_connect_swapped(G_OBJECT(removes[n]), "clicked", G_CALLBACK(remove_author_event_handler), edit_entry);
+			} else {
+				g_signal_connect_swapped(G_OBJECT(adds[n]), "clicked", G_CALLBACK(add_editor_event_handler), edit_entry);
+				g_signal_connect_swapped(G_OBJECT(removes[n]), "clicked", G_CALLBACK(remove_editor_event_handler), edit_entry);
+			}
 			gtk_box_pack_start(GTK_BOX(buttonboxes[n]), edit_entry[i].toggle, TRUE, FALSE, 1);
 			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);
@@ -572,7 +618,7 @@
 									if (value == NULL)
 										value = strdup(name);
 									else  {
-										value = (char *) realloc(value, sizeof(char)*strlen(value) + sizeof(char)*strlen(" \\and ") + sizeof(char)*strlen(name) + sizeof(char));
+										value = (char *) realloc(value, sizeof(char)*(strlen(value) + strlen(" \\and ") + strlen(name) + 1));
 										strcat(strcat((char *) value, " \\and "), name);
 									}
 								} while (gtk_tree_model_iter_next(model, &iter));

Modified: xfbib/trunk/src/open.c
===================================================================
--- xfbib/trunk/src/open.c	2008-03-29 20:11:43 UTC (rev 4129)
+++ xfbib/trunk/src/open.c	2008-03-29 23:10:21 UTC (rev 4130)
@@ -34,7 +34,7 @@
 	update_treeview(xfbib);
 	_DEBUG(("Opening: %s", xfbib->filename));
 	gtk_window_set_title(GTK_WINDOW(xfbib->window.window), create_title(xfbib));
-	filename = (char *) realloc(filename, sizeof(char)*strlen(filename) + sizeof(char)*strlen(" loaded..."));
+	filename = (char *) realloc(filename, sizeof(char)*(strlen(filename) + strlen(" loaded...") + 1));
 	statusbar_push((GtkStatusbar *) xfbib->window.statusbar, 0, strcat(filename, _(" loaded...")));
 	return 0;
 }

Modified: xfbib/trunk/src/treeview.c
===================================================================
--- xfbib/trunk/src/treeview.c	2008-03-29 20:11:43 UTC (rev 4129)
+++ xfbib/trunk/src/treeview.c	2008-03-29 23:10:21 UTC (rev 4130)
@@ -95,6 +95,7 @@
 	list = gtk_list_store_new (1, G_TYPE_STRING);
 
 	gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(list));
+	g_object_unref(list);
 	return treeview; 
 }
 
@@ -121,6 +122,7 @@
 	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));
+	g_object_unref(list);
 	return treeview; 
 }
 
@@ -151,6 +153,7 @@
 	list = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
 
 	gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(list));
+	g_object_unref(list);
 	return treeview; 
 }	
 




More information about the Goodies-commits mailing list