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

Jesper Karlsson zarper at xfce.org
Sun Oct 26 19:58:36 CET 2008


Author: zarper
Date: 2008-10-26 18:58:36 +0000 (Sun, 26 Oct 2008)
New Revision: 5821

Modified:
   xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
   xfbib/branches/gobject/src/xfbib-entry-tree-view.c
   xfbib/branches/gobject/src/xfbib-menu-bar.c
Log:
Added some warning dialogs if the type or key has not been entered for a bibtex entry.
Some code cleanup.


Modified: xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-26 18:08:59 UTC (rev 5820)
+++ xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c	2008-10-26 18:58:36 UTC (rev 5821)
@@ -148,8 +148,8 @@
 			gtk_widget_set_sensitive(GTK_WIDGET(inputs->input), TRUE);
 			gtk_entry_set_text(GTK_ENTRY(inputs->input), str);
 		} else {
+			gtk_widget_set_sensitive(GTK_WIDGET(inputs->input), FALSE);
 			gtk_entry_set_text(GTK_ENTRY(inputs->input), "");
-			gtk_widget_set_sensitive(GTK_WIDGET(inputs->input), FALSE);
 			inputs->gl = xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT (multiple_input));
 		}
 	}
@@ -393,18 +393,18 @@
 			if (g_list_length(xfbib_bibtex_value_get(value)) == 1) {
 				/* Single value */
 				if (n == XFBIB_BIBTEX_FIELD_AUTHOR || n == XFBIB_BIBTEX_FIELD_EDITOR) {
-					xfbib_multiple_input_set_text (XFBIB_MULTIPLE_INPUT ((entry_edit_dialog->inputs[n]).input),
+					xfbib_multiple_input_set_text (XFBIB_MULTIPLE_INPUT (entry_edit_dialog->inputs[n].input),
 							xfbib_bibtex_value_get_str(value));
 				} else {
-					gtk_entry_set_text(GTK_ENTRY ((entry_edit_dialog->inputs[n]).input),
+					gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->inputs[n].input),
 							xfbib_bibtex_value_get_str(value));
 				}
 			} else {
-				gtk_widget_set_sensitive((entry_edit_dialog->inputs[n]).input, FALSE);
 				if (n == XFBIB_BIBTEX_FIELD_AUTHOR || n == XFBIB_BIBTEX_FIELD_EDITOR) {
-					xfbib_multiple_input_set(XFBIB_MULTIPLE_INPUT((entry_edit_dialog->inputs[n]).input),
+					xfbib_multiple_input_set(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n].input),
 							xfbib_bibtex_value_get(value));
 				} else {
+					gtk_widget_set_sensitive(entry_edit_dialog->inputs[n].input, FALSE);
 					entry_edit_dialog->inputs[n].gl = xfbib_bibtex_value_get(value);
 				}
 			}
@@ -429,26 +429,26 @@
 	xfbib_bibtex_entry_set_bibtype(entry, gtk_combo_box_get_active_text(GTK_COMBO_BOX(entry_edit_dialog->type_combo_box)));
 	for (n = 0; n < XFBIB_BIBTEX_FIELD_N_FIELDS; n++) {
 		if (n == XFBIB_BIBTEX_FIELD_AUTHOR || n == XFBIB_BIBTEX_FIELD_EDITOR) {
-			str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT((entry_edit_dialog->inputs[n]).input));
-			if(str == NULL) {
+			str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n].input));
+			if(str != NULL) {
+				if(strcmp(str, "") == 0) {
+					continue;
+				}
 				field = xfbib_bibtex_field_new();
 				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]).input)));
-			} else if(strcmp(str, "") == 0) {
-				continue;
+				xfbib_bibtex_value_set_str(value, str);
 			} else {
 				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, str);
+				xfbib_bibtex_value_set(value, xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT(entry_edit_dialog->inputs[n].input)));
 			}
 			field_list = g_list_append(field_list, field);
 			xfbib_bibtex_field_set_value(field, value);
 		} else {
-			if(GTK_WIDGET_IS_SENSITIVE(GTK_ENTRY((entry_edit_dialog->inputs[n]).input))) {
-				if(strcmp(gtk_entry_get_text(GTK_ENTRY((entry_edit_dialog->inputs[n]).input)), "") == 0) {
+			if(GTK_WIDGET_IS_SENSITIVE(GTK_ENTRY(entry_edit_dialog->inputs[n].input))) {
+				if(strcmp(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n].input)), "") == 0) {
 					continue;
 				}
 				/* TODO: check if they are integers or strings(variables), don't assume text */
@@ -472,3 +472,18 @@
 	return entry;
 }
 
+gboolean
+xfbib_entry_edit_dialog_valid_entry(XfbibEntryEditDialog *entry_edit_dialog)
+{
+	if(gtk_combo_box_get_active(GTK_COMBO_BOX(entry_edit_dialog->type_combo_box)) == -1) {
+		xfce_warn("A BibTeX type is required!");
+		return FALSE;
+	}
+	if(strcmp(gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->key_entry)), "") == 0) {
+		xfce_warn("BibTex key is required!");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+

Modified: xfbib/branches/gobject/src/xfbib-entry-tree-view.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-tree-view.c	2008-10-26 18:08:59 UTC (rev 5820)
+++ xfbib/branches/gobject/src/xfbib-entry-tree-view.c	2008-10-26 18:58:36 UTC (rev 5821)
@@ -94,9 +94,16 @@
 	if (gtk_tree_model_get_iter(model, &iter, path)) {
 		entry = XFBIB_BIBTEX_ENTRY(xfbib_list_store_get(XFBIB_LIST_STORE(model), &iter));
 		dialog = xfbib_entry_edit_dialog_new(entry);
-		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-			new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
-			xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(entry), G_OBJECT(new_entry));
+		for(;;) {
+			if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+				if(xfbib_entry_edit_dialog_valid_entry(dialog)) {
+					new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+					xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(entry), G_OBJECT(new_entry));
+					break;
+				}
+			} else {
+				break;
+			}
 		}
 		gtk_widget_destroy(dialog);
 	}
@@ -131,10 +138,17 @@
 
 		dialog = xfbib_entry_edit_dialog_new(NULL);
 
-		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-			new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
-			xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_entry));
-		}
+		for(;;) {
+			if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+				if(xfbib_entry_edit_dialog_valid_entry(dialog)) {
+					new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+					xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_entry));
+					break;
+				}
+			} else {
+				break;
+			}
+		} 
 		gtk_widget_destroy(dialog);
 
 	} else {

Modified: xfbib/branches/gobject/src/xfbib-menu-bar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-10-26 18:08:59 UTC (rev 5820)
+++ xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-10-26 18:58:36 UTC (rev 5821)
@@ -119,9 +119,15 @@
 
 	dialog = xfbib_entry_edit_dialog_new(NULL);
 
-	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-		new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
-		xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_entry));
+	for(;;) {
+		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+			if(xfbib_entry_edit_dialog_valid_entry(dialog)) {
+				new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+				xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_entry));
+			}
+		} else {
+			break;
+		}
 	}
 	gtk_widget_destroy(dialog);
 }
@@ -168,9 +174,15 @@
 		entry = XFBIB_BIBTEX_ENTRY(xfbib_list_store_get(XFBIB_LIST_STORE(model), &iter));
 
 		dialog = xfbib_entry_edit_dialog_new(entry);
-		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
-			new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
-			xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(entry), G_OBJECT(new_entry));
+		for(;;) {
+			if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+				if(xfbib_entry_edit_dialog_valid_entry(dialog)) {
+					new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+					xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(entry), G_OBJECT(new_entry));
+				}
+			} else {
+				break;
+			}
 		}
 		gtk_widget_destroy(dialog);
 	} else {




More information about the Goodies-commits mailing list