[Goodies-commits] r5676 - xfbib/branches/gobject/src

Jesper Karlsson zarper at xfce.org
Sat Oct 18 13:06:32 CEST 2008


Author: zarper
Date: 2008-10-18 11:06:32 +0000 (Sat, 18 Oct 2008)
New Revision: 5676

Modified:
   xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
Log:
Some code cleanup and basic compound string editing capabilities (still very crude).


Modified: xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-18 07:40:59 UTC (rev 5675)
+++ xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-18 11:06:32 UTC (rev 5676)
@@ -31,38 +31,6 @@
 #include "xfbib-bibtex-entry.h"
 
 static struct {
-	gchar *label;
-	gchar *tooltip;
-}xfbib_input_constants[] = {
-	{"Address", "Address of publisher"},
-	{"Annote", "Annotation for annotated bibliography styles"},
-	{"Author", "Name(s) of the author(s), separated by 'and' if more than one"},
-	{"Booktitle", "Title of the book, if only part of it is being cited"},
-	{"Chapter", "Chapter number"},
-	{"Crossref", "Citation key of the cross-referenced entry"},
-	{"Edition", "Edition of the book (such as \"first\" or \"second\")"},
-	{"Editor", "Name(s) of the editor(s), separated by 'and' if more than one"},
-	{"E-print", "Specification of electronic publication"},
-	{"HowPublished", "Publishing method if the method is nonstandard"},
-	{"Institution", "Institution that was involved in the publishing"},
-	{"Journal", "Journal or magazine in which the work was published"},
-	{"Key", "Hidden field used for specifying or overriding the alphabetical order of entries"},
-	{"Month", "Month of publication or creation if unpublished"},
-	{"Note", "Miscellaneous extra information"},
-	{"Number", "Number of journal, magazine, or tech-report"},
-	{"Organization", "Sponsor of the conference"},
-	{"Pages", "Page numbers separated by commas or double-hyphens"},
-	{"Publisher", "Name of publisher"},
-	{"School", "School where thesis was written"},
-	{"Series", "Series of books in which the book was published"},
-	{"Title", "Title of the work"},
-	{"Type", "Type of technical report"},
-	{"URL", "Internet address"},
-	{"Volume", "Number of the volume"},
-	{"Year", "Year of publication or creation if unpublished"}
-};
-
-static struct {
 	gchar *text;
 }xfbib_type_constants[] = {
 	{"Article"},
@@ -134,13 +102,50 @@
 	title = split[0];
 	g_string_append(str, title);
 
-	gtk_entry_set_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->key_entry), g_string_free(str, FALSE));
+	gtk_entry_set_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->key_entry), str->str);
+	g_string_free(str, TRUE);
 }
 
 static void
 cb_edit_compound_string_clicked (GtkButton *button, GtkEntry *entry)
 {
 	g_printf("cb_compound_string_clicked\n");
+
+	GtkWidget *multiple_input;
+	const gchar *str;
+	GList *list;
+
+	GtkWidget *dialog = xfce_titled_dialog_new_with_buttons("Edit compund string",
+                                                    NULL,
+                                                    GTK_DIALOG_MODAL & GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                    NULL);
+	gtk_window_set_icon_name(GTK_WINDOW(dialog), "xfbib");
+	
+	/* Add OK and cancel button */
+	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_OK);
+	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+	
+	multiple_input = xfbib_multiple_input_new("TODO", "TODO");
+	gtk_box_pack_start(GTK_BOX (GTK_DIALOG(dialog)->vbox), multiple_input, TRUE, TRUE, 6); 
+	
+	gtk_widget_show_all(GTK_WIDGET(dialog));
+
+	if(gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+		str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT (multiple_input));
+		if(str != NULL) {
+			gtk_entry_set_text(entry, str);
+		} else {
+			gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE);
+			gtk_entry_set_invisible_char(entry, ' ');
+			gtk_entry_set_visibility(entry, FALSE);
+			list = xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT (multiple_input));
+			/* TODO: This is a very bad solution */
+			gtk_entry_set_text(entry, list);
+		}
+	}
+
+	gtk_widget_destroy(dialog);
 }
 
 static GtkWidget*
@@ -189,7 +194,6 @@
 	return type;
 }
 
-
 static void
 xfbib_entry_edit_dialog_class_init(XfbibEntryEditDialogClass *klass)
 {
@@ -244,13 +248,13 @@
 	for (i = 0; i < XFBIB_FIELD_N_FIELDS; i++) {
 		/* Create the Input object */
 		if (i == XFBIB_FIELD_AUTHOR || i == XFBIB_FIELD_EDITOR) {
-			instance->inputs[i] = xfbib_multiple_input_new(xfbib_input_constants[i].label, xfbib_input_constants[i].tooltip);
+			instance->inputs[i] = xfbib_multiple_input_new(xfbib_bibtex_field_constants[i].label, xfbib_bibtex_field_constants[i].tooltip);
 		} else {
-			instance->inputs_label[i] = gtk_label_new(xfbib_input_constants[i].label);
+			instance->inputs_label[i] = gtk_label_new(xfbib_bibtex_field_constants[i].label);
 			gtk_misc_set_alignment(GTK_MISC(instance->inputs_label[i]), 0, 0.5);
 
 			instance->inputs[i] = gtk_entry_new();
-			gtk_widget_set_tooltip_text(instance->inputs[i], xfbib_input_constants[i].tooltip);
+			gtk_widget_set_tooltip_text(instance->inputs[i], xfbib_bibtex_field_constants[i].tooltip);
 
 			instance->inputs_button[i] = gtk_button_new();
 			gtk_container_add(GTK_CONTAINER(instance->inputs_button[i]), xfbib_get_image("xfbib-compound-string.png"));
@@ -264,12 +268,10 @@
 			case XFBIB_FIELD_SCHOOL:
 			case XFBIB_FIELD_TITLE:
 			case XFBIB_FIELD_TYPE:
-				/* Box 0 */
 				box = 0;
 				break;
 			case XFBIB_FIELD_AUTHOR:
 			case XFBIB_FIELD_EDITOR:
-				/* Box 1 */
 				box = 1;
 				break;
 			case XFBIB_FIELD_BOOKTITLE:
@@ -280,7 +282,6 @@
 			case XFBIB_FIELD_PAGES:
 			case XFBIB_FIELD_VOLUME:
 			case XFBIB_FIELD_YEAR:
-				/* Box 2 */
 				box = 2;
 				break;
 			case XFBIB_FIELD_ADDRESS:
@@ -288,7 +289,6 @@
 			case XFBIB_FIELD_JOURNAL:
 			case XFBIB_FIELD_PUBLISHER:
 			case XFBIB_FIELD_SERIES:
-				/* Box 3 */
 				box = 3;
 				break;
 			case XFBIB_FIELD_ANNOTE:
@@ -297,7 +297,6 @@
 			case XFBIB_FIELD_KEY:
 			case XFBIB_FIELD_NOTE:
 			case XFBIB_FIELD_URL:
-				/* Box 4 */
 				box = 4;
 				break;
 		}
@@ -382,14 +381,6 @@
 				/* Did not find a matching field */
 				continue;
 			}
-			/*
-			field = xfbib_bibtex_entry_get_field_by_column(entry, n);
-			
-			
-			if (field == NULL) {
-				continue;
-			}
-			*/
 			if (g_list_length(xfbib_bibtex_value_get(value)) == 1) {
 				/* Single value */
 				if (n == XFBIB_FIELD_AUTHOR || n == XFBIB_FIELD_EDITOR) {
@@ -433,7 +424,7 @@
 			str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n]));
 			if(str == NULL) {
 				field = xfbib_bibtex_field_new();
-				xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
+				xfbib_bibtex_field_set_variable(field, xfbib_bibtex_field_constants[n].label);
 				value = xfbib_bibtex_value_new();
 				/* TODO: Don't add field if GList = NULL */
 				xfbib_bibtex_value_set(value, xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n])));
@@ -441,23 +432,33 @@
 				continue;
 			} else {
 				field = xfbib_bibtex_field_new();
-				xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
+				xfbib_bibtex_field_set_variable(field, xfbib_bibtex_field_constants[n].label);
 				value = xfbib_bibtex_value_new();
 				xfbib_bibtex_value_set_str(value, str);
 			}
 			field_list = g_list_append(field_list, field);
 			xfbib_bibtex_field_set_value(field, value);
 		} else {
-			if(strcmp(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])), "") == 0) {
-				continue;
+			if(gtk_entry_get_visibility(GTK_ENTRY(entry_edit_dialog->inputs[n])) == TRUE) {
+				if(strcmp(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])), "") == 0) {
+					continue;
+				}
+				/* TODO: check if they are integers or strings(variables), don't assume text */
+				field = xfbib_bibtex_field_new();
+				xfbib_bibtex_field_set_variable(field, xfbib_bibtex_field_constants[n].label);
+				value = xfbib_bibtex_value_new();
+				xfbib_bibtex_value_set_str(value, gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])));
+				xfbib_bibtex_field_set_value(field, value);
+				field_list = g_list_append(field_list, field);
+			} else {
+				field = xfbib_bibtex_field_new();
+				xfbib_bibtex_field_set_variable(field, xfbib_bibtex_field_constants[n].label);
+				value = xfbib_bibtex_value_new();
+				/* For details on the below line see function 'cb_edit_compound_string_clicked' */
+				xfbib_bibtex_value_set(value, (gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n]))));
+				xfbib_bibtex_field_set_value(field, value);
+				field_list = g_list_append(field_list, field);
 			}
-			/* TODO: check if they are integers or strings(variables), don't assume text */
-			field = xfbib_bibtex_field_new();
-			xfbib_bibtex_field_set_variable(field, xfbib_input_constants[n].label);
-			value = xfbib_bibtex_value_new();
-			xfbib_bibtex_value_set_str(value, gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n])));
-			xfbib_bibtex_field_set_value(field, value);
-			field_list = g_list_append(field_list, field);
 		}
 	}
 	xfbib_bibtex_entry_set_fields(entry, field_list);




More information about the Goodies-commits mailing list