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

David Gustafsson tssj at xfce.org
Sun Oct 26 01:22:24 CEST 2008


Author: tssj
Date: 2008-10-25 23:22:24 +0000 (Sat, 25 Oct 2008)
New Revision: 5808

Added:
   xfbib/branches/gobject/src/xfbib-entry-tree-view.c
   xfbib/branches/gobject/src/xfbib-entry-tree-view.h
Removed:
   xfbib/branches/gobject/src/xfbib-tree-view.c
   xfbib/branches/gobject/src/xfbib-tree-view.h
Modified:
   xfbib/branches/gobject/src/Makefile.am
   xfbib/branches/gobject/src/main.c
   xfbib/branches/gobject/src/xfbib-bibtex.c
   xfbib/branches/gobject/src/xfbib-file-io.c
   xfbib/branches/gobject/src/xfbib-list-store.c
   xfbib/branches/gobject/src/xfbib-list-store.h
   xfbib/branches/gobject/src/xfbib-menu-bar.c
   xfbib/branches/gobject/src/xfbib-string.c
   xfbib/branches/gobject/src/xfbib-toolbar.c
   xfbib/branches/gobject/src/xfbib-window.c
   xfbib/branches/gobject/src/xfbib-window.h
Log:
Initial very basic support for Variables


Modified: xfbib/branches/gobject/src/Makefile.am
===================================================================
--- xfbib/branches/gobject/src/Makefile.am	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/Makefile.am	2008-10-25 23:22:24 UTC (rev 5808)
@@ -10,6 +10,8 @@
 	xfbib-bibtex-entry.h \
 	xfbib-entry-edit-dialog.c \
 	xfbib-entry-edit-dialog.h \
+	xfbib-entry-tree-view.c \
+	xfbib-entry-tree-view.h \
 	xfbib-bibtex-field.c \
 	xfbib-bibtex-field.h \
 	xfbib-file-io.c \
@@ -36,12 +38,12 @@
 	xfbib-strbuf.h \
 	xfbib-string.c \
 	xfbib-string.h \
+	xfbib-string-tree-view.c \
+	xfbib-string-tree-view.h \
 	xfbib-bibtex-string.c \
 	xfbib-bibtex-string.h \
 	xfbib-toolbar.c \
 	xfbib-toolbar.h \
-	xfbib-tree-view.c \
-	xfbib-tree-view.h \
 	xfbib-bibtex-value.c \
 	xfbib-bibtex-value.h \
 	xfbib-window.c \

Modified: xfbib/branches/gobject/src/main.c
===================================================================
--- xfbib/branches/gobject/src/main.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/main.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -105,7 +105,7 @@
 			/* Multiple files */
 			/* TODO: Check that output file is present */
 			if (output_file == NULL) {
-				g_printf("Error merging files, no output file specified\n");
+				g_print("Error merging files, no output file specified\n");
 				return EXIT_FAILURE;
 			}
 			xfbib_state_set_filename(state, output_file);

Modified: xfbib/branches/gobject/src/xfbib-bibtex.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-bibtex.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -426,8 +426,8 @@
 	g_list_free (elements->list);
 	elements->list = NULL;
 #endif
+	elements->n_entries = 0;
 	elements->n_strings = 0;
-	elements->n_entries = 0;
 }
 
 void
@@ -448,7 +448,7 @@
 }
 
 /*
- * Return the position of the new entry, counting from 0
+ * Return the position of the new object, counting from 0
  */
 gint
 xfbib_bibtex_replace(XfbibBibtex *elements, GObject *old_obj, GObject *new_obj)
@@ -456,10 +456,10 @@
 	GObject *obj;
 	gint n = 0;
 	g_return_val_if_fail(XFBIB_IS_BIBTEX(elements) &&
-			(XFBIB_IS_BIBTEX_ENTRY(old_obj) && 
+			((XFBIB_IS_BIBTEX_ENTRY(old_obj) && 
 			XFBIB_IS_BIBTEX_ENTRY(new_obj)) ||
 			(XFBIB_IS_BIBTEX_STRING(old_obj) && 
-			XFBIB_IS_BIBTEX_STRING(new_obj)), -1);
+			XFBIB_IS_BIBTEX_STRING(new_obj))), -1);
 
 #if G_SEQUENCE
 	GSequenceIter *iter;

Copied: xfbib/branches/gobject/src/xfbib-entry-tree-view.c (from rev 5805, xfbib/branches/gobject/src/xfbib-tree-view.c)
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-tree-view.c	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-entry-tree-view.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gtk/gtk.h>
+
+#include "xfbib-list-store.h"
+#include "xfbib-entry-tree-view.h"
+#include "xfbib-bibtex.h"
+#include "xfbib-state.h"
+#include "xfbib-bibtex-entry.h"
+#include "xfbib-entry-edit-dialog.h"
+
+static struct {
+	gchar *label;
+	gchar *tooltip;
+}xfbib_field_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"}
+};
+
+struct _XfbibEntryTreeView
+{
+	GtkTreeView parent;
+};
+
+typedef struct _XfbibEntryTreeViewClass
+{
+	GtkTreeViewClass parent;
+} XfbibEntryTreeViewClass;
+
+static void xfbib_entry_tree_view_class_init(XfbibEntryTreeViewClass *klass);
+
+static void xfbib_entry_tree_view_init(XfbibEntryTreeView *instance);
+static void xfbib_entry_tree_view_finalize(GObject *obj);
+
+static GObjectClass *xfbib_entry_tree_view_parent_class = NULL;
+
+static void
+cb_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
+{
+	g_print("cb_row_activated\n");
+	XfbibState *state;
+	XfbibBibtexEntry *entry, *new_entry;
+	GtkWidget *dialog;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	state = xfbib_state_new();
+	model = gtk_tree_view_get_model(tree_view);
+
+	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));
+		}
+		gtk_widget_destroy(dialog);
+	}
+}
+
+static gboolean
+cb_button_press (GtkWidget *tree_view, GdkEventButton *event, gpointer data)
+{
+	g_print("cb_button_press\n");
+	XfbibBibtexEntry *new_entry;
+	GtkTreeModel *model;
+	GtkWidget *dialog;
+
+	if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
+		/* single click with the right mouse button */
+		/* TODO: Add a context menu here */
+	} else if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
+		/* double click with the left mouse button */
+
+		model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view));
+
+		/* Check if any row has been selected */
+		if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection
+					(GTK_TREE_VIEW(tree_view)), NULL, NULL)) {
+			/* 
+			 * A row is selected Let the other cb_row_activated()
+			 * function take care of the rest.
+			 */
+			/* TODO: Take care of the event here instead */
+			return FALSE;
+		}
+
+		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));
+		}
+		gtk_widget_destroy(dialog);
+
+	} else {
+		return FALSE;
+	}
+	return TRUE;
+}
+
+
+GType
+xfbib_entry_tree_view_get_type (void)
+{
+	static GType type = 0;
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof (XfbibEntryTreeViewClass),
+			NULL,   /* base_init */
+			NULL,   /* base_finalize */
+			(GClassInitFunc) xfbib_entry_tree_view_class_init,   /* class_init */
+			NULL,   /* class_finalize */
+			NULL,   /* class_data */
+			sizeof (XfbibEntryTreeView),
+			0,      /* n_preallocs */
+			(GInstanceInitFunc) xfbib_entry_tree_view_init    /* instance_init */
+		};
+		type = g_type_register_static (GTK_TYPE_TREE_VIEW, "XfbibEntryTreeView", &info, 0);
+	}
+	return type;
+}
+
+
+static void
+xfbib_entry_tree_view_class_init(XfbibEntryTreeViewClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *)klass;
+
+	xfbib_entry_tree_view_parent_class = g_type_class_peek_parent (klass);
+
+	object_class->finalize = xfbib_entry_tree_view_finalize;
+}
+
+static void
+xfbib_entry_tree_view_init(XfbibEntryTreeView *instance)
+{
+	GtkTreeViewColumn *column;
+	GtkCellRenderer *renderer;
+	GtkTreeModel *model;
+	gint i;
+
+	/* Connect the double-click on a row to a callback function */
+	g_signal_connect(GTK_TREE_VIEW(instance), "row-activated", (GCallback) cb_row_activated, NULL);
+	/* Connect the double-click NOT on a row to a callback function */
+	g_signal_connect(GTK_WIDGET(instance), "button-press-event", (GCallback) cb_button_press, NULL);
+	
+	for (i = 0; i < XFBIB_BIBTEX_FIELD_N_FIELDS; i++) {
+		switch (i) {
+			case XFBIB_BIBTEX_FIELD_ANNOTE:
+			case XFBIB_BIBTEX_FIELD_BOOKTITLE:
+			case XFBIB_BIBTEX_FIELD_CHAPTER:
+			case XFBIB_BIBTEX_FIELD_CROSSREF:
+			case XFBIB_BIBTEX_FIELD_EDITION:
+			case XFBIB_BIBTEX_FIELD_EDITOR:
+			case XFBIB_BIBTEX_FIELD_EPRINT:
+			case XFBIB_BIBTEX_FIELD_HOWPUBLISHED:
+			case XFBIB_BIBTEX_FIELD_INSTITUTION:
+			case XFBIB_BIBTEX_FIELD_JOURNAL:
+			case XFBIB_BIBTEX_FIELD_KEY:
+			case XFBIB_BIBTEX_FIELD_MONTH:
+			case XFBIB_BIBTEX_FIELD_NOTE:
+			case XFBIB_BIBTEX_FIELD_NUMBER:
+			case XFBIB_BIBTEX_FIELD_ORGANIZATION:
+			case XFBIB_BIBTEX_FIELD_PAGES:
+			case XFBIB_BIBTEX_FIELD_PUBLISHER:
+			case XFBIB_BIBTEX_FIELD_SCHOOL:
+			case XFBIB_BIBTEX_FIELD_SERIES:
+			case XFBIB_BIBTEX_FIELD_TYPE:
+			case XFBIB_BIBTEX_FIELD_URL:
+			case XFBIB_BIBTEX_FIELD_VOLUME:
+				continue;
+				break;
+		}
+		column = gtk_tree_view_column_new();
+
+		gtk_tree_view_column_set_title(column, xfbib_field_constants[i].label);
+
+		/* pack tree view column into tree view */
+		gtk_tree_view_append_column(GTK_TREE_VIEW(instance), column);
+
+		renderer = gtk_cell_renderer_text_new();
+
+		/* pack cell renderer into tree view column */
+		gtk_tree_view_column_pack_start(column, renderer, TRUE);
+
+		/*
+		 * connect 'text' property of the cell renderer to
+		 * model column that contains the first name
+		 */
+		gtk_tree_view_column_add_attribute(column, renderer, "text", i);
+	}
+
+	model = GTK_TREE_MODEL(xfbib_list_store_new(TYPE_ENTRY));
+	gtk_tree_view_set_model(GTK_TREE_VIEW(instance), model);
+	g_object_unref(model); /* destroy model automatically with view */
+}
+
+static void
+xfbib_entry_tree_view_finalize(GObject *obj)
+{
+	G_OBJECT_CLASS(xfbib_entry_tree_view_parent_class)->finalize(obj);
+}
+
+GtkWidget *
+xfbib_entry_tree_view_new()
+{
+	XfbibEntryTreeView *tree_view;
+	tree_view = g_object_new(XFBIB_TYPE_ENTRY_TREE_VIEW, NULL);
+	return GTK_WIDGET(tree_view);
+}
+


Property changes on: xfbib/branches/gobject/src/xfbib-entry-tree-view.c
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: xfbib/branches/gobject/src/xfbib-entry-tree-view.h (from rev 5750, xfbib/branches/gobject/src/xfbib-tree-view.h)
===================================================================
--- xfbib/branches/gobject/src/xfbib-entry-tree-view.h	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-entry-tree-view.h	2008-10-25 23:22:24 UTC (rev 5808)
@@ -0,0 +1,43 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFBIB_ENTRY_TREE_VIEW_H
+#define __XFBIB_ENTRY_TREE_VIEW_H
+
+#include <gtk/gtk.h>
+
+#define XFBIB_TYPE_ENTRY_TREE_VIEW             (xfbib_entry_tree_view_get_type())
+#define XFBIB_ENTRY_TREE_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_ENTRY_TREE_VIEW, XfbibEntryTreeView))
+#define XFBIB_IS_ENTRY_TREE_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_ENTRY_TREE_VIEW))
+#define XFBIB_ENTRY_TREE_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_ENTRY_TREE_VIEW, XfbibEntryTreeViewClass))
+#define XFBIB_IS_ENTRY_TREE_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_ENTRY_TREE_VIEW))
+#define XFBIB_ENTRY_TREE_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_ENTRY_TREE_VIEW, XfbibEntryTreeViewClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibEntryTreeView         XfbibEntryTreeView;
+
+GType xfbib_entry_tree_view_get_type() G_GNUC_CONST;
+
+GtkWidget *xfbib_entry_tree_view_new(void);
+
+G_END_DECLS
+
+#endif //__XFBIB_ENTRY_TREE_VIEW_H
+


Property changes on: xfbib/branches/gobject/src/xfbib-entry-tree-view.h
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: xfbib/branches/gobject/src/xfbib-file-io.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-file-io.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -29,11 +29,11 @@
 #include "xfbib-file-io.h"
 #include "xfbib-state.h"
 #include "xfbib-bibtex.h"
+#include "xfbib-bibtex-field.h"
 #include "xfbib-bibtex-entry.h"
 #include "xfbib-bibtex-comment.h"
 #include "xfbib-bibtex-preamble.h"
 #include "xfbib-bibtex-string.h"
-#include "xfbib-bibtex-field.h"
 #include "xfbib-bibtex-value.h"
 #include "xfbib-string.h"
 #include "xfbib-integer.h"
@@ -53,7 +53,7 @@
 {
 	XfbibState *state;
 	XfbibBibtex *elements;
-	GtkTreeModel *list_store_entries;
+	GtkTreeModel *list_store_entries, *list_store_strings;
 	gchar *contents, *name;
 	gsize length;
 	gint i, ret, n_entries, n_strings;
@@ -65,7 +65,8 @@
 
 	window = xfbib_state_get_window(state);
 	elements = xfbib_state_get_bibtex_elements(state);
-	list_store_entries = gtk_tree_view_get_model(GTK_TREE_VIEW(xfbib_window_get_tree_view(XFBIB_WINDOW(window))));
+	list_store_entries = gtk_tree_view_get_model(GTK_TREE_VIEW(xfbib_window_get_tree_view(XFBIB_WINDOW(window), TYPE_ENTRY)));
+	list_store_strings = gtk_tree_view_get_model(GTK_TREE_VIEW(xfbib_window_get_tree_view(XFBIB_WINDOW(window), TYPE_STRING)));
 	
 	name = filename;
 
@@ -83,6 +84,7 @@
 		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
 		if ((ret = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)) {
 			xfbib_list_store_clear(XFBIB_LIST_STORE(list_store_entries));
+			xfbib_list_store_clear(XFBIB_LIST_STORE(list_store_strings));
 			name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 		} else {
 			gtk_widget_destroy(dialog);
@@ -104,9 +106,9 @@
 			for (i = n_entries; i < xfbib_bibtex_get_n(elements, TYPE_ENTRY); i++)
 				xfbib_list_store_row_inserted(XFBIB_LIST_STORE(list_store_entries), i);
 			/* TODO: Update the string tree_view */
-/*			for (i = n_entries; i < xfbib_bibtex_get_n(elements, TYPE_ENTRY); i++)
-				xfbib_list_store_row_inserted(XFBIB_LIST_STORE(list_store_entries), i);
-*/
+			for (i = n_strings; i < xfbib_bibtex_get_n(elements, TYPE_STRING); i++)
+				xfbib_list_store_row_inserted(XFBIB_LIST_STORE(list_store_strings), i);
+
 		}
 	}
 	

Modified: xfbib/branches/gobject/src/xfbib-list-store.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-list-store.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -20,6 +20,7 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#include <string.h>
 #include <gtk/gtk.h>
 #include <libxfcegui4/libxfcegui4.h>
 
@@ -266,6 +267,9 @@
 	if (list_store->stamp != iter->stamp)
 		return;
 
+	/* Just to make the compiler stop nagging */
+	field = NULL;
+
 	g_value_init (value, G_TYPE_STRING);
 
 	switch (list_store->type) {
@@ -293,7 +297,16 @@
 			g_value_set_string(value, (tmp == NULL) ? "" : tmp);
 			break;
 		case TYPE_STRING:
-			g_value_set_string(value, "TODO");
+			g_return_if_fail(column < XFBIB_BIBTEX_STRING_N_STRINGS &&
+					XFBIB_IS_BIBTEX_STRING(iter->user_data));
+
+			if (column == XFBIB_BIBTEX_STRING_VARIABLE) {
+				g_value_set_string(value, xfbib_bibtex_string_get_variable(iter->user_data));
+			} else if (column == XFBIB_BIBTEX_STRING_VALUE) {
+				tmp = xfbib_bibtex_value_get_str(xfbib_bibtex_string_get_value(iter->user_data));
+				g_value_set_string(value, (tmp == NULL) ? "" : tmp);
+			}
+
 			break;
 		default:
 			return;
@@ -479,17 +492,9 @@
 xfbib_list_store_clear(XfbibListStore *list_store)
 {
 	XfbibBibtex *elements;
-	GtkTreeIter iter;
 	g_return_if_fail(XFBIB_IS_LIST_STORE(list_store));
 
 	elements = xfbib_state_get_bibtex_elements(list_store->state);
-
-	while (xfbib_bibtex_get_n(elements, list_store->type) > 0) {
-		iter.stamp = list_store->stamp;
-		iter.user_data = xfbib_bibtex_get_nth(elements, 0, list_store->type);
-		xfbib_list_store_remove(list_store, &iter);
-	}
-
 	xfbib_bibtex_remove_all(elements);
 
 	/* Old iters are not valid any more so change the stamp */
@@ -559,7 +564,7 @@
 }
 
 void
-xfbib_list_store_replace_entry(XfbibListStore *list_store, GObject *old_obj, GObject *new_obj)
+xfbib_list_store_replace(XfbibListStore *list_store, GObject *old_obj, GObject *new_obj)
 {
 	XfbibBibtex *elements;
 	gint n;

Modified: xfbib/branches/gobject/src/xfbib-list-store.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.h	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-list-store.h	2008-10-25 23:22:24 UTC (rev 5808)
@@ -22,7 +22,6 @@
 
 #include <gtk/gtk.h>
 #include "xfbib-bibtex.h"
-#include "xfbib-bibtex-entry.h"
 
 #define XFBIB_TYPE_LIST_STORE             (xfbib_list_store_get_type())
 #define XFBIB_LIST_STORE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_LIST_STORE, XfbibListStore))

Modified: xfbib/branches/gobject/src/xfbib-menu-bar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-menu-bar.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -28,6 +28,7 @@
 #include "xfbib-entry-edit-dialog.h"
 #include "xfbib-menu-bar.h"
 #include "xfbib-bibtex-field.h"
+#include "xfbib-bibtex-string.h"
 #include "xfbib-bibtex.h"
 #include "xfbib-file-io.h"
 #include "xfbib-state.h"
@@ -62,7 +63,7 @@
 static void
 cb_file_new_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-	g_printf("File/New\n");
+	g_print("File/New\n");
 }
 
 static void
@@ -70,7 +71,7 @@
 {
 	XfbibState *state;
 	gchar *filename;
-	g_printf("File/Open\n");
+	g_print("File/Open\n");
 
 	state = xfbib_state_new();
 
@@ -84,7 +85,7 @@
 cb_file_save_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
 	XfbibState *state;
-	g_printf("File/Save\n");
+	g_print("File/Save\n");
 	state = xfbib_state_new();
 
 	xfbib_file_io_save(xfbib_state_get_filename(state));
@@ -93,7 +94,7 @@
 static void
 cb_file_save_as_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-	g_printf("File/Save As\n");
+	g_print("File/Save As\n");
 	xfbib_file_io_save_as();
 }
 
@@ -110,11 +111,11 @@
 	XfbibBibtexEntry *new_entry;
 	GtkTreeModel *model;
 	GtkWidget *dialog;
-	g_printf("Entry/Add\n");
+	g_print("Entry/Add\n");
 
 	state = xfbib_state_new();
 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(xfbib_window_get_tree_view(
-					XFBIB_WINDOW(xfbib_state_get_window(state)))));
+					XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_ENTRY)));
 
 	dialog = xfbib_entry_edit_dialog_new(NULL);
 
@@ -133,10 +134,10 @@
 	GtkTreeSelection *selection;
 	GtkTreeModel     *model;
 	GtkTreeIter       iter;
-	g_printf("Entry/Remove\n");
+	g_print("Entry/Remove\n");
 
 	state = xfbib_state_new();
-	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state))));
+	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_ENTRY));
 
 	/* This will only work in single or browse selection mode! */
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
@@ -156,10 +157,10 @@
 	GtkTreeSelection *selection;
 	GtkTreeModel *model;
 	GtkTreeIter iter;
-	g_printf("Entry/Edit\n");
+	g_print("Entry/Edit\n");
 
 	state = xfbib_state_new();
-	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state))));
+	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_ENTRY));
 
 	/* This will only work in single or browse selection mode! */
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
@@ -169,7 +170,7 @@
 		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_entry(XFBIB_LIST_STORE(model), entry, new_entry);
+			xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(entry), G_OBJECT(new_entry));
 		}
 		gtk_widget_destroy(dialog);
 	} else {
@@ -180,16 +181,82 @@
 static void
 cb_variable_add_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-	g_printf("Variable/add\n");
+	XfbibState *state;
+	XfbibBibtexString *new_string;
+	GtkTreeModel *model;
+	GtkWidget *dialog;
+	g_print("Variable/add\n");
+
+	state = xfbib_state_new();
+	model = gtk_tree_view_get_model(GTK_TREE_VIEW(xfbib_window_get_tree_view(
+					XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_STRING)));
+#if 0
+	dialog = xfbib_entry_edit_dialog_new(NULL);
+
+	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+		new_string = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+		xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_string));
+	}
+	gtk_widget_destroy(dialog);
+#endif
 }
 
 static void
 cb_variable_remove_activate (GtkMenuItem *menuitem, gpointer user_data)
 {
-	g_printf("Variable/Remove\n");
+	XfbibState *state;
+	GtkWidget *tree_view;
+	GtkTreeSelection *selection;
+	GtkTreeModel     *model;
+	GtkTreeIter       iter;
+	g_print("Variable/Remove\n");
+
+	state = xfbib_state_new();
+	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_STRING));
+
+	/* This will only work in single or browse selection mode! */
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+		xfbib_list_store_remove(XFBIB_LIST_STORE(model), &iter);
+	} else {
+		xfce_err("No row has been selected for removal");
+	}
 }
 
 static void
+cb_variable_edit_activate (GtkMenuItem *menuitem, gpointer user_data)
+{
+	XfbibState *state;
+	XfbibBibtexString *string, *new_string;
+	GtkWidget *tree_view, *dialog;
+	GtkTreeSelection *selection;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	g_print("Variable/Edit\n");
+
+	state = xfbib_state_new();
+	tree_view = GTK_WIDGET(xfbib_window_get_tree_view(XFBIB_WINDOW(xfbib_state_get_window(state)), TYPE_STRING));
+
+	/* This will only work in single or browse selection mode! */
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+		string = XFBIB_BIBTEX_ENTRY(xfbib_list_store_get(XFBIB_LIST_STORE(model), &iter));
+
+#if 0
+		dialog = xfbib_entry_edit_dialog_new(string);
+		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+			new_string = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
+			xfbib_list_store_replace(XFBIB_LIST_STORE(model), G_OBJECT(string), G_OBJECT(new_string));
+		}
+		gtk_widget_destroy(dialog);
+#endif
+	} else {
+		xfce_err("No row has been selected for edit");
+	}
+
+}
+
+static void
 cb_help_about_activate (GtkMenuItem *menuitem, gpointer ignored)
 {
 	gchar* xfbib_authors[] = {"David Gustafsson <david.s.gustafsson at gmail.com>",
@@ -334,6 +401,12 @@
 	g_signal_connect_swapped (G_OBJECT (item), "activate",
 			G_CALLBACK (cb_variable_remove_activate), instance);
 
+	item = gtk_image_menu_item_new_from_stock(GTK_STOCK_EDIT, accel);
+	gtk_menu_shell_append(GTK_MENU_SHELL(instance->variable), item);
+	g_signal_connect_swapped (G_OBJECT (item), "activate",
+			G_CALLBACK (cb_variable_edit_activate), instance);
+
+
 	item = gtk_menu_item_new_with_label("Variable");
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), instance->variable);
 	gtk_menu_shell_append(GTK_MENU_SHELL(instance), item);

Modified: xfbib/branches/gobject/src/xfbib-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-string.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -90,7 +90,7 @@
 xfbib_string_set(XfbibString *string, const gchar *str)
 {
 	g_free(string->str);
-	g_printf("Setting string: <%s>\n", str);
+	g_print("Setting string: <%s>\n", str);
 	string->str = g_strdup(str);
 }
 

Modified: xfbib/branches/gobject/src/xfbib-toolbar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-toolbar.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-toolbar.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -54,7 +54,7 @@
 
 	XfbibState *state;
 	gchar *filename;
-	g_printf("Toolbar_Open\n");
+	g_print("Toolbar_Open\n");
 
 	state = xfbib_state_new();
 
@@ -68,7 +68,7 @@
 cb_save_clicked (GtkButton *buttonitem, gpointer user_data)
 {
 	XfbibState *state;
-	g_printf("Toolbar_Save\n");
+	g_print("Toolbar_Save\n");
 	state = xfbib_state_new();
 
 	xfbib_file_io_save(xfbib_state_get_filename(state));

Deleted: xfbib/branches/gobject/src/xfbib-tree-view.c

Deleted: xfbib/branches/gobject/src/xfbib-tree-view.h

Modified: xfbib/branches/gobject/src/xfbib-window.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-window.c	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-window.c	2008-10-25 23:22:24 UTC (rev 5808)
@@ -25,7 +25,8 @@
 #include "xfbib-window.h"
 #include "xfbib-menu-bar.h"
 #include "xfbib-toolbar.h"
-#include "xfbib-tree-view.h"
+#include "xfbib-entry-tree-view.h"
+#include "xfbib-string-tree-view.h"
 #include "xfbib-statusbar.h"
 #include "xfbib-file-io.h"
 
@@ -33,10 +34,13 @@
 {
 	GtkWindow parent;
 	GtkWidget *vbox;
-	GtkWidget *scrolled_window;
 	GtkWidget *menu_bar;
 	GtkWidget *toolbar;
-	GtkWidget *tree_view;
+	GtkWidget *notebook;
+	GtkWidget *entry_scrolled_window;
+	GtkWidget *entry_tree_view;
+	GtkWidget *string_scrolled_window;
+	GtkWidget *string_tree_view;
 	GtkWidget *status_bar;
 };
 	
@@ -96,15 +100,30 @@
 	instance->toolbar = xfbib_toolbar_new(instance);
 	gtk_box_pack_start(GTK_BOX(instance->vbox), instance->toolbar, FALSE, FALSE, 0);
 	
-	instance->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (instance->scrolled_window),
+
+	instance->notebook = gtk_notebook_new ();
+	gtk_container_set_border_width(GTK_CONTAINER (instance->notebook), 0);
+	gtk_notebook_set_tab_pos (GTK_NOTEBOOK (instance->notebook), GTK_POS_TOP);
+	gtk_box_pack_start(GTK_BOX(instance->vbox), instance->notebook, TRUE , TRUE, 0);
+
+
+	instance->entry_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (instance->entry_scrolled_window),
 			GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-	gtk_box_pack_start(GTK_BOX(instance->vbox), instance->scrolled_window, TRUE , TRUE, 0);
+	gtk_notebook_append_page (GTK_NOTEBOOK (instance->notebook), instance->entry_scrolled_window, gtk_label_new("Entry"));
 
-	instance->tree_view = xfbib_tree_view_new();
-	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(instance->scrolled_window),
-			instance->tree_view);
+	instance->entry_tree_view = xfbib_entry_tree_view_new();
+	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(instance->entry_scrolled_window), instance->entry_tree_view);
+	
+	instance->string_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (instance->string_scrolled_window),
+			GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+	gtk_notebook_append_page (GTK_NOTEBOOK (instance->notebook), instance->string_scrolled_window, gtk_label_new("Variable"));
 
+	instance->string_tree_view = xfbib_string_tree_view_new();
+	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(instance->string_scrolled_window), instance->string_tree_view);
+	
+
 	instance->status_bar = xfbib_statusbar_new();
 	gtk_box_pack_end(GTK_BOX(instance->vbox), instance->status_bar, FALSE, FALSE, 0);
 
@@ -136,8 +155,12 @@
 }
 
 GtkWidget *
-xfbib_window_get_tree_view(XfbibWindow *window)
+xfbib_window_get_tree_view(XfbibWindow *window, enum XFBIB_BIBTEX_TYPE type)
 {
 	g_return_val_if_fail(XFBIB_IS_WINDOW(window), NULL);
-	return window->tree_view;
+	if (type == TYPE_ENTRY)
+		return window->entry_tree_view;
+	else if (type == TYPE_STRING)
+		return window->string_tree_view;
+	return NULL;
 }

Modified: xfbib/branches/gobject/src/xfbib-window.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-window.h	2008-10-25 22:35:44 UTC (rev 5807)
+++ xfbib/branches/gobject/src/xfbib-window.h	2008-10-25 23:22:24 UTC (rev 5808)
@@ -40,7 +40,7 @@
 GtkWidget *xfbib_window_new();
 void xfbib_window_set_title(XfbibWindow *, gchar *);
 XfbibBibtex *xfbib_window_get_elements(XfbibWindow *);
-GtkWidget *xfbib_window_get_tree_view(XfbibWindow *);
+GtkWidget *xfbib_window_get_tree_view(XfbibWindow *, enum XFBIB_BIBTEX_TYPE);
 
 G_END_DECLS
 




More information about the Goodies-commits mailing list