[Goodies-commits] r4007 - in xfbib/trunk: . src

Jesper Karlsson zarper at xfce.org
Thu Feb 28 21:32:24 CET 2008


Author: zarper
Date: 2008-02-28 20:32:24 +0000 (Thu, 28 Feb 2008)
New Revision: 4007

Modified:
   xfbib/trunk/TODO
   xfbib/trunk/src/menubar.c
   xfbib/trunk/src/node.c
   xfbib/trunk/src/string_edit_dialog.c
   xfbib/trunk/src/treeview.c
Log:
Xfbib: Added menubuttons to add and remove variables.
Added functionality to add and remove variables.

Modified: xfbib/trunk/TODO
===================================================================
--- xfbib/trunk/TODO	2008-02-28 02:50:23 UTC (rev 4006)
+++ xfbib/trunk/TODO	2008-02-28 20:32:24 UTC (rev 4007)
@@ -4,8 +4,6 @@
 
 - Right click menu. (0.0.2)
 
-- Ability to add variables. (0.0.2)
-
 - Test suite for the parser.
 
 - Preamble and comment support.

Modified: xfbib/trunk/src/menubar.c
===================================================================
--- xfbib/trunk/src/menubar.c	2008-02-28 02:50:23 UTC (rev 4006)
+++ xfbib/trunk/src/menubar.c	2008-02-28 20:32:24 UTC (rev 4007)
@@ -29,6 +29,7 @@
 #include "debug.h"
 #include "entry_edit_dialog.h"
 #include "treeview.h"
+#include "string_edit_dialog.h"
 
 static void file_new_event_handler(struct xfbib *xfbib)
 {
@@ -96,6 +97,32 @@
 	update_treeview(xfbib);
 }
 
+static void variable_add_event_handler (struct xfbib *xfbib)
+{
+	_DEBUG(("variable_add_event_handler"));
+	show_string_edit_dialog(xfbib, NULL);
+}
+
+static void variable_remove_event_handler (struct xfbib *xfbib)
+{
+	_DEBUG(("variable_remove_event_handler"));
+	struct node *node;
+	GtkTreeSelection *selection;
+	GtkTreeModel     *model;
+	GtkTreeIter       iter;
+
+	/* This will only work in single or browse selection mode! */
+
+	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(xfbib->window.variable_treeview));
+	if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+		gtk_tree_model_get (model, &iter, VAR_COLUMN_STRING, &node, -1);
+		remove_node(&(xfbib->list), node);
+	} else {
+		_DEBUG(("No row selected"));
+	}
+	update_treeview(xfbib);
+}
+
 static void view_show_toolbar_event_handler (GtkCheckMenuItem *show_toolbar, struct xfbib *xfbib)
 {
 	_DEBUG(("view_show_toolbar_event_handler"));
@@ -175,6 +202,29 @@
 	return item;
 }
 
+static GtkWidget *create_variable_menu(struct xfbib *xfbib, GtkAccelGroup *accel)
+{
+	_DEBUG(("create_variable_menu"));
+	
+	GtkWidget *item, *menu, *add, *remove;
+	
+	item = gtk_menu_item_new_with_mnemonic(_("Variable"));
+	menu = gtk_menu_new();
+	add = gtk_image_menu_item_new_from_stock(GTK_STOCK_ADD, accel);
+	gtk_menu_shell_append(GTK_MENU_SHELL (menu), add);
+	remove = gtk_image_menu_item_new_from_stock(GTK_STOCK_REMOVE, accel);
+	gtk_menu_shell_append(GTK_MENU_SHELL (menu), remove);
+	
+	g_signal_connect_swapped (G_OBJECT (GTK_IMAGE_MENU_ITEM (add)), "activate",
+			G_CALLBACK (variable_add_event_handler), xfbib);
+	g_signal_connect_swapped (G_OBJECT (GTK_IMAGE_MENU_ITEM (remove)), "activate",
+			G_CALLBACK (variable_remove_event_handler), xfbib);
+			
+	gtk_menu_item_set_submenu(GTK_MENU_ITEM (item), menu);
+	
+	return item;
+}
+
 static GtkWidget *create_view_menu(struct xfbib *xfbib)
 {
 	_DEBUG(("create_view_menu"));
@@ -223,6 +273,7 @@
 	struct {
 		GtkWidget *file;
 		GtkWidget *entry;
+		GtkWidget *variable;
 		GtkWidget *view;
 		GtkWidget *help;
 	} items;
@@ -238,6 +289,9 @@
 	items.entry = create_entry_menu(xfbib, accel);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menubar), items.entry);
 	
+	items.variable = create_variable_menu(xfbib, accel);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menubar), items.variable);
+	
 	items.view = create_view_menu(xfbib);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menubar), items.view);
 

Modified: xfbib/trunk/src/node.c
===================================================================
--- xfbib/trunk/src/node.c	2008-02-28 02:50:23 UTC (rev 4006)
+++ xfbib/trunk/src/node.c	2008-02-28 20:32:24 UTC (rev 4007)
@@ -24,6 +24,7 @@
 #include "tag.h"
 #include "comment.h"
 #include "debug.h"
+#include "strings.h"
 
 struct entry *add_entry(struct node **node, char *type, char *key)
 {
@@ -40,7 +41,6 @@
 	}
 }
 
-
 void add_preamble(struct node **node, char *value)
 {
 	_DEBUG(("add_preamble"));
@@ -56,7 +56,6 @@
 	}
 }
 
-
 void add_comment(struct node **node, char *value)
 {
 	_DEBUG(("add_comment"));
@@ -71,7 +70,6 @@
 	}
 }
 
-
 void add_string(struct node **node, char *variable, char *value)
 {
 	_DEBUG(("add_string"));
@@ -86,7 +84,6 @@
 	}
 }
 
-
 void add_tag(struct entry *entry, char *name, char *value)
 {
 	_DEBUG(("add_tag"));
@@ -154,6 +151,7 @@
 {
 	_DEBUG(("remove_node"));
 	if (*nodes != NULL && *nodes == n) {
+		_DEBUG(("Node match"));
 		*nodes = n->next;
 		switch(n->node_type) { 
 			case ENTRY_NODE: 				
@@ -174,7 +172,10 @@
 			}
 		free(n);	
 	} else {
-		remove_node(&(*nodes)->next, n);
+		if (*nodes != NULL)
+			remove_node(&(*nodes)->next, n);
+		else
+			_DEBUG(("Warning: Node match could not be found!"));
 	}
 }
 

Modified: xfbib/trunk/src/string_edit_dialog.c
===================================================================
--- xfbib/trunk/src/string_edit_dialog.c	2008-02-28 02:50:23 UTC (rev 4006)
+++ xfbib/trunk/src/string_edit_dialog.c	2008-02-28 20:32:24 UTC (rev 4007)
@@ -19,6 +19,9 @@
 
 #include "debug.h"
 #include "strings.h"
+#include "node.h"
+#include "xfbib.h"
+#include "treeview.h"
 
 #define VARIABLE 0
 #define VALUE 1
@@ -66,9 +69,13 @@
 
 	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
 		_DEBUG(("Response OK"));
-		change_variable(selected, gtk_entry_get_text(GTK_ENTRY(entry[VARIABLE])));
-		change_value(selected, gtk_entry_get_text(GTK_ENTRY(entry[VALUE])));
-	
+		if (selected != NULL) {
+			change_variable(selected, (char *) gtk_entry_get_text(GTK_ENTRY(entry[VARIABLE])));
+			change_value(selected, (char *) gtk_entry_get_text(GTK_ENTRY(entry[VALUE])));
+		} else {
+			add_string(&xfbib->list, (char *) gtk_entry_get_text(GTK_ENTRY(entry[VARIABLE])), (char *) gtk_entry_get_text(GTK_ENTRY(entry[VALUE])));
+		}
+		update_treeview(xfbib);
 	} else {
 		_DEBUG(("Response Cancel"));
 	}

Modified: xfbib/trunk/src/treeview.c
===================================================================
--- xfbib/trunk/src/treeview.c	2008-02-28 02:50:23 UTC (rev 4006)
+++ xfbib/trunk/src/treeview.c	2008-02-28 20:32:24 UTC (rev 4007)
@@ -118,7 +118,7 @@
 
 void update_treeview(struct xfbib *xfbib)
 {
-	_DEBUG(("add_to_treeview"));
+	_DEBUG(("update_treeview"));
 	GtkTreeIter iter;
 	struct node *n;
 	struct entry *e;




More information about the Goodies-commits mailing list