[anjuta-extras] class-inheritance: Use class name to toggle collapsed and expanded class views



commit 638b94e755361b9b6cf0c98248b17dbad3c09e05
Author: Naba Kumar <naba gnome org>
Date:   Wed Feb 24 17:36:13 2010 +0200

    class-inheritance: Use class name to toggle collapsed and expanded class views
    
    Removed "Normal" view item from expanded class view and used class name
    (title) to toggle on and off the expanded view. Also removed redundant
    members menu, which impracticle in some cases because of scrolling. Used
    single click class expansion and collapse.

 plugins/class-inheritance/class-callbacks.c |  152 ++++++++++++---------------
 plugins/class-inheritance/class-callbacks.h |   10 +-
 plugins/class-inheritance/class-inherit.c   |  124 +++-------------------
 plugins/class-inheritance/class-inherit.h   |    4 +-
 4 files changed, 86 insertions(+), 204 deletions(-)
---
diff --git a/plugins/class-inheritance/class-callbacks.c b/plugins/class-inheritance/class-callbacks.c
index 3a165ec..f14f7fd 100644
--- a/plugins/class-inheritance/class-callbacks.c
+++ b/plugins/class-inheritance/class-callbacks.c
@@ -53,76 +53,6 @@ on_canvas_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
 	return FALSE;
 }
 
-void
-on_toggled_menuitem_clicked (GtkCheckMenuItem *checkmenuitem,
-							 gpointer data)
-{
-	NodeData *node;
-	node = (NodeData*)data;
-		
-	if (node->anchored) 
-	{
-		node->anchored = FALSE;
-		
-		/* remove the key from the hash table, if present */
-		if (g_tree_lookup (node->plugin->expansion_node_list, 
-						   GINT_TO_POINTER (node->klass_id))) 
-		{
-			g_tree_remove (node->plugin->expansion_node_list, 
-						   GINT_TO_POINTER (node->klass_id));
-		}
-	}
-	else 
-	{
-		NodeExpansionStatus *node_status;
-		node->anchored = TRUE;
-		
-		node_status = g_new0 (NodeExpansionStatus, 1);
-		node_status->klass_id = node->klass_id;
-		/* set to half. This will display at least NODE_HALF_DISPLAY_ELEM_NUM.
-		 * User will decide whether to show all elements or not. */
-		node_status->expansion_status = NODE_HALF_EXPANDED;
-		
-		/* insert the class name to the hash_table */
-		g_tree_insert (node->plugin->expansion_node_list, 
-							GINT_TO_POINTER (node->klass_id), 
-							node_status);
-	}
-	
-	class_inheritance_update_graph (node->plugin);
-}
-
-void
-on_member_menuitem_clicked (GtkMenuItem *menuitem, gpointer data)
-{
-	NodeData *node;	
-	const gchar *file;
-	gint line;
-	
-	node = (NodeData*)data;
-	file = g_object_get_data (G_OBJECT (menuitem), "__filepath");
-	line = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "__line"));	
-
-	DEBUG_PRINT ("got uri %s [%d]", file, line);
-	
-	if (file)
-	{
-		GFile* gfile;
-		gfile = g_file_new_for_path (file);
-		/* Goto uri line */
-		IAnjutaDocumentManager *dm;
-		dm = anjuta_shell_get_interface (ANJUTA_PLUGIN (node->plugin)->shell,
-										 IAnjutaDocumentManager, NULL);
-		if (dm)
-		{
-			ianjuta_document_manager_goto_file_line (dm, gfile, line, NULL);
-		}
-
-		if (gfile)
-			g_object_unref (gfile);
-	}
-}
-
 gint
 on_nodedata_expanded_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
 {
@@ -151,12 +81,6 @@ on_nodedata_expanded_event (GnomeCanvasItem *item, GdkEvent *event, gpointer dat
 					node_status->expansion_status = NODE_FULL_EXPANDED;
 					class_inheritance_update_graph (plugin);
 			}			
-			else if (strcmp (nodedata->sub_item, NODE_SHOW_NORMAL_VIEW_STR) == 0) 
-			{
-					g_tree_remove (plugin->expansion_node_list, 
-								   GINT_TO_POINTER (nodedata->klass_id));
-					class_inheritance_update_graph (plugin);
-			}
 			else 		/* it's a class member. Take line && uri of definition */
 			{			/* and reach them */
 				const gchar *file;
@@ -210,7 +134,7 @@ on_nodedata_expanded_event (GnomeCanvasItem *item, GdkEvent *event, gpointer dat
 
 
 gint
-on_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+on_collapsed_class_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
 {
 	AnjutaClassInheritance *plugin;
 	NodeData *nodedata;	
@@ -220,35 +144,40 @@ on_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
 
 	switch (event->type)
 	{
-	case GDK_2BUTTON_PRESS:		/* double click */
-		break;
-
 	case GDK_BUTTON_PRESS:		/* single click */
 		if (event->button.button == 1 && !nodedata->anchored)
 		{
-			class_inheritance_show_dynamic_class_popup_menu  (event, data);
+			NodeExpansionStatus *node_status;
+			nodedata->anchored = TRUE;
+
+			node_status = g_new0 (NodeExpansionStatus, 1);
+			node_status->klass_id = nodedata->klass_id;
+			/* set to half. This will display at least NODE_HALF_DISPLAY_ELEM_NUM.
+			 * User will decide whether to show all elements or not. */
+			node_status->expansion_status = NODE_HALF_EXPANDED;
+
+			/* insert the class name to the hash_table */
+			g_tree_insert (nodedata->plugin->expansion_node_list, 
+			               GINT_TO_POINTER (nodedata->klass_id), 
+			               node_status);
+			class_inheritance_update_graph (nodedata->plugin);
+			return TRUE;
 		}
 		break;
 		
 	case GDK_ENTER_NOTIFY:		/* mouse entered in item's area */
 		/* Make the outline wide */
 		gnome_canvas_item_set (nodedata->canvas_item,
-							   "width_units", 2.5,
 							   "fill_color_gdk",
 							   &plugin->canvas->style->base[GTK_STATE_SELECTED],
-							   "outline_color_gdk",
-							   &plugin->canvas->style->text[GTK_STATE_SELECTED],
 							   NULL);
 		return TRUE;
 
 	case GDK_LEAVE_NOTIFY:		/* mouse exited item's area */
 		/* Make the outline thin */
 		gnome_canvas_item_set (nodedata->canvas_item,
-							   "width_units", 1.0,
 							   "fill_color_gdk",
 							   &plugin->canvas->style->base[GTK_STATE_NORMAL],
-							   "outline_color_gdk",
-							   &plugin->canvas->style->text[GTK_STATE_NORMAL],	
 							   NULL);
 		return TRUE;
 	default:
@@ -258,6 +187,55 @@ on_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
 	return FALSE;
 }
 
+gint
+on_expanded_class_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+	AnjutaClassInheritance *plugin;
+	NodeData *nodedata;	
+	
+	nodedata = (NodeData*)data;
+	plugin = nodedata->plugin;
+
+	switch (event->type)
+	{
+	case GDK_BUTTON_PRESS:		/* single click */
+		if (event->button.button == 1 && nodedata->anchored)
+		{
+			nodedata->anchored = FALSE;
+		
+			/* remove the key from the hash table, if present */
+			if (g_tree_lookup (nodedata->plugin->expansion_node_list, 
+							   GINT_TO_POINTER (nodedata->klass_id))) 
+			{
+				g_tree_remove (nodedata->plugin->expansion_node_list, 
+							   GINT_TO_POINTER (nodedata->klass_id));
+			}
+			class_inheritance_update_graph (nodedata->plugin);
+			return TRUE;
+		}
+		break;
+		
+	case GDK_ENTER_NOTIFY:		/* mouse entered in item's area */
+		/* Make the outline wide */
+		gnome_canvas_item_set (nodedata->canvas_item,
+							   "fill_color_gdk",
+							   &plugin->canvas->style->bg[GTK_STATE_PRELIGHT],
+							   NULL);
+		return TRUE;
+
+	case GDK_LEAVE_NOTIFY:		/* mouse exited item's area */
+		/* Make the outline thin */
+		gnome_canvas_item_set (nodedata->canvas_item,
+							   "fill_color_gdk",
+							   &plugin->canvas->style->bg[GTK_STATE_ACTIVE],
+							   NULL);
+		return TRUE;
+	default:
+		break;
+	}
+	
+	return FALSE;
+}
 
 /*----------------------------------------------------------------------------
  * callback for the canvas' right-click menu - update button.
diff --git a/plugins/class-inheritance/class-callbacks.h b/plugins/class-inheritance/class-callbacks.h
index 6545475..95ead44 100644
--- a/plugins/class-inheritance/class-callbacks.h
+++ b/plugins/class-inheritance/class-callbacks.h
@@ -23,12 +23,12 @@
 #include "class-inherit.h"
 
 gint on_canvas_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data);
-	
-void on_toggled_menuitem_clicked (GtkCheckMenuItem *checkmenuitem,
-							 gpointer data);
 
-void on_member_menuitem_clicked (GtkMenuItem *menuitem, gpointer data);
-	
+gint on_collapsed_class_nodedata_event (GnomeCanvasItem *item, GdkEvent *event,
+                                        gpointer data);
+gint on_expanded_class_nodedata_event (GnomeCanvasItem *item, GdkEvent *event,
+                                       gpointer data);
+
 gint on_nodedata_expanded_event (GnomeCanvasItem *item, GdkEvent *event, 
 							gpointer data);
 
diff --git a/plugins/class-inheritance/class-inherit.c b/plugins/class-inheritance/class-inherit.c
index e9110dd..24cad25 100644
--- a/plugins/class-inheritance/class-inherit.c
+++ b/plugins/class-inheritance/class-inherit.c
@@ -117,101 +117,6 @@ class_inheritance_get_symbol_from_agnode_key_name (AnjutaClassInheritance *plugi
 	
 	return symbol;
 }
-
-void
-class_inheritance_show_dynamic_class_popup_menu (GdkEvent *event,
-										   NodeData* nodedata)
-{
-	GtkWidget *item, *image;
-	GtkWidget *checkitem, *separator;
-		
-	/* Destroy the old menu before creating a new one */
-	if (nodedata->menu)
-	{
-		gtk_widget_destroy (nodedata->menu);
-	}
-		
-	nodedata->menu = gtk_menu_new();
-	if (nodedata->klass_id > 0)
-	{
-		IAnjutaSymbolManager *sm;
-		IAnjutaIterable *iter;
-		IAnjutaSymbol *symbol_searched;
-		sm = anjuta_shell_get_interface (ANJUTA_PLUGIN (nodedata->plugin)->shell,
-										 IAnjutaSymbolManager, NULL);
-		if (sm == NULL)
-			return;
-
-		symbol_searched = ianjuta_symbol_manager_get_symbol_by_id (sm, 
-												 nodedata->klass_id,
-												 IANJUTA_SYMBOL_FIELD_SIMPLE,
-												 NULL);
-												 
-		iter = ianjuta_symbol_manager_get_members (sm, symbol_searched,
-												   IANJUTA_SYMBOL_FIELD_SIMPLE |
-												   IANJUTA_SYMBOL_FIELD_TYPE |
-												   IANJUTA_SYMBOL_FIELD_ACCESS |
-												   IANJUTA_SYMBOL_FIELD_FILE_PATH,
-												   NULL);
-		if (iter && ianjuta_iterable_get_length (iter, NULL) > 0)
-		{	
-			do
-			{
-				const gchar *name, *file;
-				const GdkPixbuf *pixbuf;
-				gint line;		
-				IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
-				
-				name = ianjuta_symbol_get_name (symbol, NULL);
-				pixbuf = ianjuta_symbol_get_icon (symbol, NULL);
-				file = ianjuta_symbol_get_extra_info_string (symbol, 
-								IANJUTA_SYMBOL_FIELD_FILE_PATH, NULL);
-				line = ianjuta_symbol_get_line (symbol, NULL);
-				
-				item = gtk_image_menu_item_new_with_label (name);
-				image = gtk_image_new_from_pixbuf ((GdkPixbuf*)pixbuf);
-				gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM
-											   (item), image);
-				
-				if (file)
-				{
-					g_object_set_data_full (G_OBJECT (item), "__filepath",
-											g_strdup (file), g_free);
-					g_object_set_data (G_OBJECT (item), "__line",
-									   GINT_TO_POINTER (line));
-				}
-				gtk_container_add (GTK_CONTAINER (nodedata->menu),
-								   item);
-				g_signal_connect (G_OBJECT (item), "activate",
-											G_CALLBACK (on_member_menuitem_clicked),
-											nodedata);
-			} while (ianjuta_iterable_next (iter, NULL));
-		}
-		if (iter)  
-		{
-			g_object_unref (iter);
-		}			
-	}
-	
-	
-	separator = gtk_separator_menu_item_new ();
-	/* create the check menuitem */
-	checkitem = gtk_check_menu_item_new_with_label (_("Fixed data-view"));
-	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (checkitem),
-									nodedata->anchored);
-	
-	g_signal_connect (G_OBJECT (checkitem), "toggled",
-								G_CALLBACK (on_toggled_menuitem_clicked),
-								nodedata);
-	
-	gtk_container_add (GTK_CONTAINER (nodedata->menu), separator);
-	gtk_container_add (GTK_CONTAINER (nodedata->menu), checkitem);
-		
-	gtk_widget_show_all (nodedata->menu);
-	gtk_menu_popup (GTK_MENU (nodedata->menu), NULL, NULL,
-	                NULL, NULL, event->button.button,
-					event->button.time);	
-}
 	
 /*----------------------------------------------------------------------------
  * initialize the internal graphviz structure.
@@ -406,7 +311,7 @@ cls_inherit_add_node (AnjutaClassInheritance *plugin, const IAnjutaSymbol *node_
 			g_string_append_printf (label, "|%s", NODE_SHOW_ALL_MEMBERS_STR);
 		}
 		
-		g_string_append_printf (label, "|%s }", NODE_SHOW_NORMAL_VIEW_STR);
+		g_string_append_printf (label, "}");
 		agxset(graph_node, sym->index, label->str);
 		
 		/* set the margin for icons */
@@ -610,26 +515,26 @@ cls_inherit_draw_expanded_node (AnjutaClassInheritance *plugin, Agnode_t *graph_
 				                       "fill_color_gdk",
 				                       &plugin->canvas->style->bg[GTK_STATE_ACTIVE],
 				                       NULL);
+				g_signal_connect (GTK_OBJECT (node_data->canvas_item), "event",
+								  G_CALLBACK (on_expanded_class_nodedata_event),
+								  node_data);
 				continue;
 			}
-			else					/* we need to draw the last 2 elements differently */
+			else /* The "more" item is the last */
 			{
-				g_signal_connect (GTK_OBJECT (node_data->canvas_item), "event",
-								  G_CALLBACK (on_nodedata_expanded_event),
-								  node_data);
-
 				if (expansion_status == NODE_HALF_EXPANDED && 
-					j > (NODE_NTH_FIELD (graph_node, i)->n_flds -3)) 
+					j == (NODE_NTH_FIELD (graph_node, i)->n_flds - 1)) 
 				{
+					g_signal_connect (GTK_OBJECT (node_data->canvas_item), "event",
+									  G_CALLBACK (on_nodedata_expanded_event),
+									  node_data);
 					continue;
 				}
-				else				/* only the last one. Usually "Normal view" */
+				else /* Normal class item */
 				{
-					if (expansion_status == NODE_FULL_EXPANDED && 
-						j > (NODE_NTH_FIELD (graph_node, i)->n_flds -2)) 
-					{
-						continue;
-					}
+					g_signal_connect (GTK_OBJECT (node_data->canvas_item), "event",
+									  G_CALLBACK (on_nodedata_expanded_event),
+									  node_data);
 				}
 			}
 			
@@ -672,6 +577,7 @@ cls_inherit_draw_expanded_node (AnjutaClassInheritance *plugin, Agnode_t *graph_
 					/* no need to free 'file'. It'll be freed when object'll be unreffed */
 				}
 			}
+			
 			plugin->drawable_list = g_list_prepend (plugin->drawable_list, item);
 			ianjuta_iterable_next (symbol_iter, NULL);
 		} /*- for */
@@ -744,7 +650,7 @@ cls_inherit_draw_single_node (AnjutaClassInheritance *plugin, Agnode_t *graph_no
 	plugin->node_list = g_list_prepend (plugin->node_list, node_data);
 	
 	g_signal_connect (GTK_OBJECT (node_data->canvas_item), "event",
-					  G_CALLBACK (on_nodedata_event),
+					  G_CALLBACK (on_collapsed_class_nodedata_event),
 					  node_data);
 
 	/* --- texts --- */		
diff --git a/plugins/class-inheritance/class-inherit.h b/plugins/class-inheritance/class-inherit.h
index 9bb260b..09c52a8 100644
--- a/plugins/class-inheritance/class-inherit.h
+++ b/plugins/class-inheritance/class-inherit.h
@@ -27,10 +27,8 @@
 
 G_BEGIN_DECLS
 
-#define NODE_FONT_DEFAULT "-*-clean-medium-r-normal-*-10-*-*-*-*-*-*"
-#define NODE_HALF_DISPLAY_ELEM_NUM			10
+#define NODE_HALF_DISPLAY_ELEM_NUM			30
 #define NODE_SHOW_ALL_MEMBERS_STR			N_("Show all members...")
-#define NODE_SHOW_NORMAL_VIEW_STR			N_("Normal view")
 
 typedef struct _NodeData {
 	GnomeCanvasItem *canvas_item;  	/* item itself */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]