[anjuta/symbol-db-model] symbol-db: Added symbol activation to navigate to file and line



commit e435da911fa0f22e739796249d07d51ef241db0b
Author: Naba Kumar <naba gnome org>
Date:   Sun Mar 14 15:56:43 2010 +0200

    symbol-db: Added symbol activation to navigate to file and line

 plugins/symbol-db/plugin.c                 |    6 ++-
 plugins/symbol-db/symbol-db-model-global.c |   60 ++++++++++++++++++++++++----
 plugins/symbol-db/symbol-db-model-global.h |    2 +
 plugins/symbol-db/symbol-db-views.c        |   58 ++++++++++++++++++++++++++-
 plugins/symbol-db/symbol-db-views.h        |    3 +-
 5 files changed, 117 insertions(+), 12 deletions(-)
---
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index 0af63af..12b0809 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -2016,7 +2016,8 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 
 	if (sdb_plugin->dbv_view_tree1)
 		gtk_widget_destroy (sdb_plugin->dbv_view_tree1);
-	sdb_plugin->dbv_view_tree1 = symbol_db_view_global_new (sdb_plugin->sdbe_project);
+	sdb_plugin->dbv_view_tree1 = symbol_db_view_global_new (sdb_plugin->sdbe_project,
+	                                                        sdb_plugin);
 	gtk_notebook_prepend_page (GTK_NOTEBOOK (sdb_plugin->dbv_notebook),
 	                           sdb_plugin->dbv_view_tree1, 
 	                           gtk_label_new ("New symbols"));
@@ -2452,7 +2453,8 @@ symbol_db_activate (AnjutaPlugin *plugin)
 	sdb_plugin->dbv_view_tab_label = gtk_label_new (_("Global" ));
 
 	/* FIXME: */
-	sdb_plugin->dbv_view_tree1 = symbol_db_view_global_new (sdb_plugin->sdbe_project);
+	sdb_plugin->dbv_view_tree1 = symbol_db_view_global_new (sdb_plugin->sdbe_project,
+	                                                        sdb_plugin);
 	g_object_add_weak_pointer (G_OBJECT (sdb_plugin->dbv_view_tree1),
 							   (gpointer)&sdb_plugin->dbv_view_tree1);
 	
diff --git a/plugins/symbol-db/symbol-db-model-global.c b/plugins/symbol-db/symbol-db-model-global.c
index 602cc4a..ff2d0da 100644
--- a/plugins/symbol-db/symbol-db-model-global.c
+++ b/plugins/symbol-db/symbol-db-model-global.c
@@ -32,6 +32,15 @@ struct _SymbolDBModelGlobalPriv
 enum {
 	DATA_COL_SYMBOL_ID,
 	DATA_COL_SYMBOL_NAME,
+	DATA_COL_SYMBOL_FILE_LINE,
+	DATA_COL_SYMBOL_FILE_SCOPE,
+	DATA_COL_SYMBOL_ARGS,
+	DATA_COL_SYMBOL_RETURNTYPE,
+	DATA_COL_SYMBOL_KIND_NAME,
+	DATA_COL_SYMBOL_FILE_PATH,
+	DATA_COL_SYMBOL_ACCESS,
+	DATA_COL_SYMBOL_TYPE,
+	DATA_COL_SYMBOL_TYPE_NAME,
 	DATA_N_COLS
 };
 
@@ -102,14 +111,13 @@ symbol_db_model_global_get_children (SymbolDBModel *model, gint tree_level,
 				(priv->dbe, SYMTYPE_CLASS | SYMTYPE_ENUM | SYMTYPE_STRUCT |
 				 SYMTYPE_TYPEDEF | SYMTYPE_UNION, TRUE, TRUE, limit, offset,
 				 SYMINFO_SIMPLE | SYMINFO_ACCESS | SYMINFO_TYPE |
-				 SYMINFO_FILE_PATH | SYMINFO_KIND);
+				 SYMINFO_FILE_PATH);
 			break;
 		case 1:
 			symbol_id = g_value_get_int (&column_values[DATA_COL_SYMBOL_ID]);
 			iter = symbol_db_engine_get_scope_members_by_symbol_id
 				(priv->dbe, symbol_id, limit, offset, SYMINFO_SIMPLE |
-				 SYMINFO_ACCESS | SYMINFO_TYPE | SYMINFO_FILE_PATH |
-				 SYMINFO_KIND);
+				 SYMINFO_ACCESS | SYMINFO_TYPE | SYMINFO_FILE_PATH);
 			break;
 		default:
 			return NULL;
@@ -155,6 +163,17 @@ symbol_db_model_global_get_query_value (SymbolDBModel *model,
 }
 
 static void
+on_symbol_db_global_dbe_unref (SymbolDBModelGlobal *model)
+{
+	SymbolDBModelGlobalPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (model));
+	priv = GET_PRIV (model);
+	priv->dbe = NULL;
+	/* FIXME: Reset model */
+}
+
+static void
 symbol_db_model_global_set_property (GObject *object, guint prop_id,
                                      const GValue *value, GParamSpec *pspec)
 {
@@ -167,8 +186,13 @@ symbol_db_model_global_set_property (GObject *object, guint prop_id,
 	{
 	case PROP_SYMBOL_DB_ENGINE:
 		if (priv->dbe)
-			g_object_unref (priv->dbe);
+			g_object_weak_unref (G_OBJECT (priv->dbe),
+			                    (GWeakNotify)on_symbol_db_global_dbe_unref,
+			                     object);
 		priv->dbe = g_value_dup_object (value);
+		g_object_weak_ref (G_OBJECT (priv->dbe),
+			                    (GWeakNotify)on_symbol_db_global_dbe_unref,
+			                     object);
 		/* TODO: Reset model */
 		break;
 	default:
@@ -206,7 +230,9 @@ symbol_db_model_global_finalize (GObject *object)
 	priv = GET_PRIV (object);
 	
 	if (priv->dbe)
-		g_object_unref (priv->dbe);
+		g_object_weak_unref (G_OBJECT (priv->dbe),
+		                     (GWeakNotify)on_symbol_db_global_dbe_unref,
+		                     object);
 	G_OBJECT_CLASS (symbol_db_model_global_parent_class)->finalize (object);
 }
 
@@ -214,14 +240,32 @@ static void
 symbol_db_model_global_init (SymbolDBModelGlobal *object)
 {
 	SymbolDBModelGlobalPriv *priv;
-	GType types[] = {G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING};
-	gint data_cols[] = {DATA_COL_SYMBOL_ID, -1, DATA_COL_SYMBOL_NAME};
+	
+	GType types[] = {
+		G_TYPE_INT,
+		GDK_TYPE_PIXBUF,
+		G_TYPE_STRING,
+		G_TYPE_STRING,
+		G_TYPE_INT,
+	};
+
+	gint data_cols[] = {
+		DATA_COL_SYMBOL_ID,
+		-1,
+		DATA_COL_SYMBOL_NAME,
+		DATA_COL_SYMBOL_FILE_PATH,
+		DATA_COL_SYMBOL_FILE_LINE,
+	};
 	
 	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (object));
 	priv = GET_PRIV (object);
 	
 	priv->dbe = NULL;
-	symbol_db_model_set_columns (SYMBOL_DB_MODEL (object), 3, types, data_cols);
+
+	g_assert ((sizeof (types) / sizeof (GType)) == (sizeof (data_cols) / sizeof (gint)));
+	symbol_db_model_set_columns (SYMBOL_DB_MODEL (object),
+	                             (sizeof (types) / sizeof (GType)),
+	                             types, data_cols);
 }
 
 static void
diff --git a/plugins/symbol-db/symbol-db-model-global.h b/plugins/symbol-db/symbol-db-model-global.h
index dddb376..5d69a4b 100644
--- a/plugins/symbol-db/symbol-db-model-global.h
+++ b/plugins/symbol-db/symbol-db-model-global.h
@@ -39,6 +39,8 @@ enum {
 	SYMBOL_DB_MODEL_GLOBAL_COL_SYMBOL_ID,
 	SYMBOL_DB_MODEL_GLOBAL_COL_PIXBUF,
 	SYMBOL_DB_MODEL_GLOBAL_COL_LABEL,
+	SYMBOL_DB_MODEL_GLOBAL_COL_FILE,
+	SYMBOL_DB_MODEL_GLOBAL_COL_LINE,
 	SYMBOL_DB_MODEL_GLOBAL_COL_N_COLS
 };
 
diff --git a/plugins/symbol-db/symbol-db-views.c b/plugins/symbol-db/symbol-db-views.c
index 361a9d0..dd853b6 100644
--- a/plugins/symbol-db/symbol-db-views.c
+++ b/plugins/symbol-db/symbol-db-views.c
@@ -17,11 +17,61 @@
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <gtk/gtktreeview.h>
+#include <libanjuta/interfaces/ianjuta-document-manager.h>
+#include <libanjuta/interfaces/ianjuta-markable.h>
 #include "symbol-db-model-global.h"
 #include "symbol-db-engine.h"
+#include "symbol-db-views.h"
+#include "plugin.h"
+
+static void
+on_global_treeview_row_activated (GtkTreeView *view, GtkTreePath *arg1,
+								 GtkTreeViewColumn *arg2,
+								 SymbolDBPlugin *plugin)
+{
+	GtkTreeModel *model;
+	GtkTreeSelection *selection;
+	GtkTreeIter iter;
+	IAnjutaDocumentManager *docman;
+	GFile* file;
+	gchar *filename, *full_path;
+	gint line;
+
+	AnjutaShell *shell = ANJUTA_PLUGIN (plugin)->shell;
+	selection = gtk_tree_view_get_selection (view);
+	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+	    return;
+
+	gtk_tree_model_get (model, &iter,
+	                    SYMBOL_DB_MODEL_GLOBAL_COL_FILE, &filename,
+	                    SYMBOL_DB_MODEL_GLOBAL_COL_LINE, &line,
+	                    -1);
+	g_return_if_fail (filename != NULL);
+
+	docman = anjuta_shell_get_interface (shell, IAnjutaDocumentManager,
+	                                     NULL);
+	g_return_if_fail (docman != NULL);
+
+	full_path = g_build_filename (plugin->project_root_dir, filename, NULL);
+	file = g_file_new_for_path (full_path);
+	ianjuta_document_manager_goto_file_line (docman, file, line, NULL);
+	g_free (full_path);
+	g_free (filename);
+	g_object_unref (file);
+
+	if (IANJUTA_IS_MARKABLE (plugin->current_editor))
+	{
+		ianjuta_markable_delete_all_markers (IANJUTA_MARKABLE (plugin->current_editor),
+		                                     IANJUTA_MARKABLE_LINEMARKER,
+		                                     NULL);
+
+		ianjuta_markable_mark (IANJUTA_MARKABLE (plugin->current_editor),
+		                       line, IANJUTA_MARKABLE_LINEMARKER, NULL);
+	}
+}
 
 GtkWidget*
-symbol_db_view_global_new (SymbolDBEngine *dbe)
+symbol_db_view_global_new (SymbolDBEngine *dbe, SymbolDBPlugin *plugin)
 {
 	GtkWidget *sw;
 	GtkTreeModel *model;
@@ -32,6 +82,12 @@ symbol_db_view_global_new (SymbolDBEngine *dbe)
 	model = symbol_db_model_global_new (dbe);
 	
 	dbv = gtk_tree_view_new_with_model (model);
+	g_object_unref (model);
+
+	g_signal_connect (G_OBJECT (dbv), "row-activated",
+					  G_CALLBACK (on_global_treeview_row_activated), plugin);
+
+
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (dbv), FALSE);
 	gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (dbv), TRUE);
 	
diff --git a/plugins/symbol-db/symbol-db-views.h b/plugins/symbol-db/symbol-db-views.h
index d085163..e166211 100644
--- a/plugins/symbol-db/symbol-db-views.h
+++ b/plugins/symbol-db/symbol-db-views.h
@@ -21,10 +21,11 @@
 #define _SYMBOL_DB_VIEWS_H_
 
 #include "symbol-db-engine.h"
+#include "plugin.h"
 
 G_BEGIN_DECLS
 
-GtkWidget* symbol_db_view_global_new (SymbolDBEngine *dbe);
+GtkWidget* symbol_db_view_global_new (SymbolDBEngine *dbe, SymbolDBPlugin *plugin);
 
 G_END_DECLS
 



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