[Goodies-commits] r5817 - xfbib/branches/gobject/src
Jesper Karlsson
zarper at xfce.org
Sun Oct 26 13:21:57 CET 2008
Author: zarper
Date: 2008-10-26 12:21:57 +0000 (Sun, 26 Oct 2008)
New Revision: 5817
Modified:
xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
xfbib/branches/gobject/src/xfbib-multiple-input.c
Log:
Modified how the entry edit dialog handles compound strings.
Squashed som bugs in the handling of compound strings.
Modified: xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c 2008-10-26 09:57:53 UTC (rev 5816)
+++ xfbib/branches/gobject/src/xfbib-entry-edit-dialog.c 2008-10-26 12:21:57 UTC (rev 5817)
@@ -50,6 +50,13 @@
{NULL}
};
+struct input {
+ GtkWidget *label; /* Label and NULL objects */
+ GtkWidget *input; /* Entry and multiple inputs */
+ GtkWidget *button;
+ GList *gl; /* Used for compound strings */
+};
+
struct _XfbibEntryEditDialog
{
XfceTitledDialog parent;
@@ -58,9 +65,7 @@
GtkWidget *key_label;
GtkWidget *key_entry;
GtkWidget *key_button;
- GtkWidget *inputs_label[XFBIB_BIBTEX_FIELD_N_FIELDS]; /* Label and NULL objects */
- GtkWidget *inputs[XFBIB_BIBTEX_FIELD_N_FIELDS]; /* Entry and multiple inputs */
- GtkWidget *inputs_button[XFBIB_BIBTEX_FIELD_N_FIELDS];
+ struct input inputs[XFBIB_BIBTEX_FIELD_N_FIELDS];
GtkWidget *note_boxes[5];
GtkWidget *notebook;
};
@@ -89,15 +94,15 @@
char *tmp;
str = g_string_new("");
- lastname = xfbib_multiple_input_get_nth_row_ith_column(XFBIB_MULTIPLE_INPUT (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_AUTHOR]),0,0);
+ lastname = xfbib_multiple_input_get_nth_row_ith_column(XFBIB_MULTIPLE_INPUT (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_AUTHOR].input),0,0);
if(lastname != NULL) {
tmp = strrchr(lastname, ' ') + 1;
g_string_append(str, tmp);
}
- g_string_append(str, (gtk_entry_get_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_YEAR])) + 2));
+ g_string_append(str, (gtk_entry_get_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_YEAR].input)) + 2));
- title = gtk_entry_get_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_TITLE]));
+ title = gtk_entry_get_text(GTK_ENTRY (XFBIB_ENTRY_EDIT_DIALOG (user_data)->inputs[XFBIB_BIBTEX_FIELD_TITLE].input));
split = g_strsplit(title, " ", 2);
title = split[0];
g_string_append(str, title);
@@ -107,13 +112,12 @@
}
static void
-cb_edit_compound_string_clicked (GtkButton *button, GtkEntry *entry)
+cb_edit_compound_string_clicked (GtkButton *button, struct input *inputs)
{
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,
@@ -127,26 +131,26 @@
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
multiple_input = xfbib_multiple_input_new("Text/String key", "TODO");
- if(gtk_entry_get_visibility(entry) == TRUE) {
- xfbib_multiple_input_set_text(XFBIB_MULTIPLE_INPUT(multiple_input), gtk_entry_get_text(entry));
+ if(GTK_WIDGET_IS_SENSITIVE(inputs->input)) {
+ if(strcmp(gtk_entry_get_text(GTK_ENTRY(inputs->input)), "") != 0) {
+ xfbib_multiple_input_set_text(XFBIB_MULTIPLE_INPUT(multiple_input), gtk_entry_get_text(GTK_ENTRY(inputs->input)));
+ }
+ } else {
+ xfbib_multiple_input_set(XFBIB_MULTIPLE_INPUT(multiple_input), inputs->gl);
}
+
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_widget_set_sensitive(GTK_WIDGET(entry), TRUE);
- gtk_entry_set_visibility(entry, TRUE);
- gtk_entry_set_text(entry, str);
+ 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(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_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));
}
}
@@ -254,17 +258,17 @@
for (i = 0; i < XFBIB_BIBTEX_FIELD_N_FIELDS; i++) {
/* Create the Input object */
if (i == XFBIB_BIBTEX_FIELD_AUTHOR || i == XFBIB_BIBTEX_FIELD_EDITOR) {
- instance->inputs[i] = xfbib_multiple_input_new(xfbib_bibtex_field_constants[i].label, xfbib_bibtex_field_constants[i].tooltip);
+ instance->inputs[i].input = 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_bibtex_field_constants[i].label);
- gtk_misc_set_alignment(GTK_MISC(instance->inputs_label[i]), 0, 0.5);
+ instance->inputs[i].label = gtk_label_new(xfbib_bibtex_field_constants[i].label);
+ gtk_misc_set_alignment(GTK_MISC(instance->inputs[i].label), 0, 0.5);
- instance->inputs[i] = gtk_entry_new();
- gtk_widget_set_tooltip_text(instance->inputs[i], xfbib_bibtex_field_constants[i].tooltip);
+ instance->inputs[i].input = gtk_entry_new();
+ gtk_widget_set_tooltip_text(instance->inputs[i].input, 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"));
- g_signal_connect(G_OBJECT (instance->inputs_button[i]), "clicked", G_CALLBACK (cb_edit_compound_string_clicked), instance->inputs[i]);
+ instance->inputs[i].button = gtk_button_new();
+ gtk_container_add(GTK_CONTAINER(instance->inputs[i].button), xfbib_get_image("xfbib-compound-string.png"));
+ g_signal_connect(G_OBJECT (instance->inputs[i].button), "clicked", G_CALLBACK (cb_edit_compound_string_clicked), &(instance->inputs[i]));
}
/* Add the input object to the correct box */
@@ -307,11 +311,11 @@
break;
}
if (i == XFBIB_BIBTEX_FIELD_AUTHOR || i == XFBIB_BIBTEX_FIELD_EDITOR) {
- gtk_table_attach_defaults(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i], row[box], row[box]+1, 0, 1);
+ gtk_table_attach_defaults(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i].input, row[box], row[box]+1, 0, 1);
} else {
- gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs_label[i], 0, 1, row[box], row[box]+1, GTK_FILL, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i], 1, 2, row[box], row[box]+1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
- gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs_button[i], 2, 3, row[box], row[box]+1, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i].label, 0, 1, row[box], row[box]+1, GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i].input, 1, 2, row[box], row[box]+1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(instance->note_boxes[box]), instance->inputs[i].button, 2, 3, row[box], row[box]+1, GTK_FILL, GTK_FILL, 0, 0);
}
row[box]++;
}
@@ -362,7 +366,7 @@
if (entry != NULL) {
bibtype = xfbib_bibtex_entry_get_bibtype(entry);
for (n = 0; xfbib_type_constants[n].text != NULL; n++) {
- if (xfbib_type_constants[n].text == bibtype) {
+ if (strcasecmp(xfbib_type_constants[n].text, bibtype) == 0) {
gtk_combo_box_set_active(GTK_COMBO_BOX (entry_edit_dialog->type_combo_box), n);
break;
}
@@ -371,7 +375,6 @@
gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->key_entry), xfbib_bibtex_entry_get_key(entry));
for (n = 0; n < XFBIB_BIBTEX_FIELD_N_FIELDS; n++) {
-
list = xfbib_bibtex_entry_get_fields(entry);
for (i = 0, value = NULL; i < g_list_length(list); i++) {
@@ -382,31 +385,27 @@
break;
}
}
-
if (value == NULL) {
/* Did not find a matching field */
continue;
}
+
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]),
+ 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]),
+ 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], FALSE);
- gtk_entry_set_invisible_char(entry, ' ');
- gtk_entry_set_visibility(entry, FALSE);
+ 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]),
+ xfbib_multiple_input_set(XFBIB_MULTIPLE_INPUT((entry_edit_dialog->inputs[n]).input),
xfbib_bibtex_value_get(value));
} else {
- /* For details on the below line see function 'cb_edit_compound_string_clicked' */
- gtk_entry_set_text(GTK_ENTRY (entry_edit_dialog->inputs[n]),
- xfbib_bibtex_value_get(value));
+ entry_edit_dialog->inputs[n].gl = xfbib_bibtex_value_get(value);
}
}
}
@@ -430,13 +429,13 @@
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]));
+ str = xfbib_multiple_input_get_str(XFBIB_MULTIPLE_INPUT((entry_edit_dialog->inputs[n]).input));
if(str == NULL) {
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])));
+ xfbib_bibtex_value_set(value, xfbib_multiple_input_get(XFBIB_MULTIPLE_INPUT((entry_edit_dialog->inputs[n]).input)));
} else if(strcmp(str, "") == 0) {
continue;
} else {
@@ -448,23 +447,22 @@
field_list = g_list_append(field_list, field);
xfbib_bibtex_field_set_value(field, value);
} else {
- 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) {
+ 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 */
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_value_set_str(value, gtk_entry_get_text(GTK_ENTRY(entry_edit_dialog->inputs[n].input)));
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_value_set(value, entry_edit_dialog->inputs[n].gl);
xfbib_bibtex_field_set_value(field, value);
field_list = g_list_append(field_list, field);
}
Modified: xfbib/branches/gobject/src/xfbib-multiple-input.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-26 09:57:53 UTC (rev 5816)
+++ xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-26 12:21:57 UTC (rev 5817)
@@ -229,7 +229,6 @@
gint n;
model = gtk_tree_view_get_model(GTK_TREE_VIEW (multiple_input->tree_view));
-
column = gtk_tree_view_get_column(GTK_TREE_VIEW(multiple_input->tree_view), 0);
title = gtk_tree_view_column_get_title(column);
@@ -298,12 +297,14 @@
const gchar *str;
int n;
- for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1)) != NULL; n++) {
- if(strcmp(str, "") != 0) {
- /* Atleast one string found, needs to be handled by xfbib_multiple_input_get */
+ for(n = 0; xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0) != NULL; n++) {
+ str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1);
+ if(str != NULL) {
+ /* Atleast one bibtex string found, needs to be handled by xfbib_multiple_input_get */
return NULL;
}
}
+ /* Only text in multiple input, create one long string and return it */
strbuf = g_string_new("");
for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0)) != NULL; n++) {
if(n != 0) {
@@ -318,27 +319,27 @@
xfbib_multiple_input_get(XfbibMultipleInput *multiple_input)
{
GList *list = NULL;
- GString *strbuf;
+ XfbibString *str;
XfbibBibtexString *string;
XfbibBibtexValue *value;
- const gchar *str, *text;
+ const gchar *bibstr, *text;
gint n;
- for(n = 0; (str = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0)) != NULL; n++) {
- text = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1);
- if(strcmp(text, "") != 0) {
+ for(n = 0; (text = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 0)) != NULL; n++) {
+ bibstr = xfbib_multiple_input_get_nth_row_ith_column(multiple_input, n, 1);
+ if(bibstr != NULL) {
string = xfbib_bibtex_string_new();
value = xfbib_bibtex_value_new();
- xfbib_bibtex_string_set_variable(string, str);
+ xfbib_bibtex_string_set_variable(string, bibstr);
xfbib_bibtex_value_set_str(value, text);
xfbib_bibtex_string_set_value(string, value);
list = g_list_append(list, G_OBJECT(string));
} else {
- strbuf = g_string_new("");
- g_string_append(strbuf, str);
- list = g_list_append(list, G_OBJECT(strbuf));
+ str = xfbib_string_new();
+ xfbib_string_set(str, text);
+ list = g_list_append(list, G_OBJECT(str));
}
}
return list;
More information about the Goodies-commits
mailing list