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

David Gustafsson tssj at xfce.org
Sun Oct 26 01:23:38 CEST 2008


Author: tssj
Date: 2008-10-25 23:23:38 +0000 (Sat, 25 Oct 2008)
New Revision: 5809

Added:
   xfbib/branches/gobject/src/xfbib-string-tree-view.c
   xfbib/branches/gobject/src/xfbib-string-tree-view.h
Log:
Forgot to add the string-tree-view to the previous commit.


Added: xfbib/branches/gobject/src/xfbib-string-tree-view.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string-tree-view.c	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-string-tree-view.c	2008-10-25 23:23:38 UTC (rev 5809)
@@ -0,0 +1,243 @@
+/*
+ * 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-string-tree-view.h"
+#include "xfbib-bibtex.h"
+#include "xfbib-state.h"
+#include "xfbib-bibtex-string.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 _XfbibStringTreeView
+{
+	GtkTreeView parent;
+};
+
+typedef struct _XfbibStringTreeViewClass
+{
+	GtkTreeViewClass parent;
+} XfbibStringTreeViewClass;
+
+static void xfbib_string_tree_view_class_init(XfbibStringTreeViewClass *klass);
+
+static void xfbib_string_tree_view_init(XfbibStringTreeView *instance);
+static void xfbib_string_tree_view_finalize(GObject *obj);
+
+static GObjectClass *xfbib_string_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;
+	XfbibBibtexString *string, *new_string;
+	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)) {
+		string = XFBIB_BIBTEX_ENTRY(xfbib_list_store_get(XFBIB_LIST_STORE(model), &iter));
+#if 0
+		dialog = xfbib_string_edit_dialog_new(string);
+		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+			new_string = xfbib_string_edit_dialog_get(XFBIB_STRING_EDIT_DIALOG(dialog));
+			xfbib_list_store_replace(XFBIB_LIST_STORE(model), string, new_string);
+		}
+		gtk_widget_destroy(dialog);
+#endif
+	}
+}
+
+static gboolean
+cb_button_press (GtkWidget *tree_view, GdkEventButton *event, gpointer data)
+{
+	g_print("cb_button_press\n");
+	XfbibBibtexString *new_string;
+	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;
+		}
+#if 0
+
+		dialog = xfbib_string_edit_dialog_new(NULL);
+
+		if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+			new_entry = xfbib_string_edit_dialog_get_entry(XFBIB_STRING_EDIT_DIALOG(dialog));
+			xfbib_list_store_add(XFBIB_LIST_STORE(model), G_OBJECT(new_entry));
+		}
+		gtk_widget_destroy(dialog);
+#endif
+
+	} else {
+		return FALSE;
+	}
+	return TRUE;
+}
+
+
+GType
+xfbib_string_tree_view_get_type (void)
+{
+	static GType type = 0;
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof (XfbibStringTreeViewClass),
+			NULL,   /* base_init */
+			NULL,   /* base_finalize */
+			(GClassInitFunc) xfbib_string_tree_view_class_init,   /* class_init */
+			NULL,   /* class_finalize */
+			NULL,   /* class_data */
+			sizeof (XfbibStringTreeView),
+			0,      /* n_preallocs */
+			(GInstanceInitFunc) xfbib_string_tree_view_init    /* instance_init */
+		};
+		type = g_type_register_static (GTK_TYPE_TREE_VIEW, "XfbibStringTreeView", &info, 0);
+	}
+	return type;
+}
+
+
+static void
+xfbib_string_tree_view_class_init(XfbibStringTreeViewClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *)klass;
+
+	xfbib_string_tree_view_parent_class = g_type_class_peek_parent (klass);
+
+	object_class->finalize = xfbib_string_tree_view_finalize;
+}
+
+static void
+xfbib_string_tree_view_init(XfbibStringTreeView *instance)
+{
+	GtkTreeViewColumn *column;
+	GtkCellRenderer *renderer;
+	GtkTreeModel *model;
+
+	/* 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);
+
+	/* Variable Column */
+	column = gtk_tree_view_column_new();
+	gtk_tree_view_column_set_visible(column, TRUE);
+	gtk_tree_view_column_set_clickable(column, TRUE);
+	gtk_tree_view_column_set_title(column, "Variable" );
+	/* 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", 0);
+
+	/* Value Column */
+	column = gtk_tree_view_column_new();
+	gtk_tree_view_column_set_title(column, "Value" );
+	/* 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", 1);
+	
+	model = GTK_TREE_MODEL(xfbib_list_store_new(TYPE_STRING));
+	gtk_tree_view_set_model(GTK_TREE_VIEW(instance), model);
+	g_object_unref(model); /* destroy model automatically with view */
+}
+
+static void
+xfbib_string_tree_view_finalize(GObject *obj)
+{
+	G_OBJECT_CLASS(xfbib_string_tree_view_parent_class)->finalize(obj);
+}
+
+GtkWidget *
+xfbib_string_tree_view_new()
+{
+	XfbibStringTreeView *tree_view;
+	tree_view = g_object_new(XFBIB_TYPE_STRING_TREE_VIEW, NULL);
+	return GTK_WIDGET(tree_view);
+}
+

Added: xfbib/branches/gobject/src/xfbib-string-tree-view.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-string-tree-view.h	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-string-tree-view.h	2008-10-25 23:23:38 UTC (rev 5809)
@@ -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_STRING_TREE_VIEW_H
+#define __XFBIB_STRING_TREE_VIEW_H
+
+#include <gtk/gtk.h>
+
+#define XFBIB_TYPE_STRING_TREE_VIEW             (xfbib_string_tree_view_get_type())
+#define XFBIB_STRING_TREE_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_STRING_TREE_VIEW, XfbibStringTreeView))
+#define XFBIB_IS_STRING_TREE_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_STRING_TREE_VIEW))
+#define XFBIB_STRING_TREE_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_STRING_TREE_VIEW, XfbibStringTreeViewClass))
+#define XFBIB_IS_STRING_TREE_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_STRING_TREE_VIEW))
+#define XFBIB_STRING_TREE_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_STRING_TREE_VIEW, XfbibStringTreeViewClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibStringTreeView         XfbibStringTreeView;
+
+GType xfbib_string_tree_view_get_type() G_GNUC_CONST;
+
+GtkWidget *xfbib_string_tree_view_new(void);
+
+G_END_DECLS
+
+#endif //__XFBIB_STRING_TREE_VIEW_H
+




More information about the Goodies-commits mailing list