[anjuta/sdb-queries] symbol-db: Implement symbol search view using model



commit 45db0e13de1506031514bd5c21c422b4ec494281
Author: Naba Kumar <naba gnome org>
Date:   Wed Jun 16 21:49:36 2010 +0300

    symbol-db: Implement symbol search view using model

 plugins/symbol-db/Makefile.am              |   26 +--
 plugins/symbol-db/plugin.c                 |    7 +
 plugins/symbol-db/symbol-db-model-search.c |  269 ++++++++++++++++++++++++++++
 plugins/symbol-db/symbol-db-model-search.h |   56 ++++++
 plugins/symbol-db/symbol-db-views.c        |   26 +++
 plugins/symbol-db/symbol-db-views.h        |    3 +-
 6 files changed, 367 insertions(+), 20 deletions(-)
---
diff --git a/plugins/symbol-db/Makefile.am b/plugins/symbol-db/Makefile.am
index 42ec570..13d429b 100644
--- a/plugins/symbol-db/Makefile.am
+++ b/plugins/symbol-db/Makefile.am
@@ -56,43 +56,31 @@ libanjuta_symbol_db_la_SOURCES = \
 	plugin.h \
 	readtags.c \
 	readtags.h \
-	symbol-db-engine-iterator.c \
-	symbol-db-engine-iterator.h \
-	symbol-db-view-search.h \
-	symbol-db-view-search.c \
-	symbol-db-engine-iterator-node.h \
-	symbol-db-engine-iterator-node.c \
 	symbol-db-system.h \
 	symbol-db-system.c \
 	symbol-db-prefs.h \
 	symbol-db-prefs.c \
-	symbol-db-engine-queries.c \
-	symbol-db-engine-queries.h \
 	symbol-db-engine-utils.c \
 	symbol-db-engine-utils.h \
 	symbol-db-engine-priv.h \
 	symbol-db-engine-core.c \
 	symbol-db-engine-core.h \
 	symbol-db-engine.h \
-	symbol-db-iface.c \
-	symbol-db-iface.h \
-	symbol-db-search-command.h \
-	symbol-db-search-command.c \
+	symbol-db-query.h \
+	symbol-db-query.c \
+	symbol-db-query-result.h \
+	symbol-db-query-result.c \
 	symbol-db-model.c \
 	symbol-db-model.h \
 	symbol-db-model-project.c \
 	symbol-db-model-project.h \
 	symbol-db-model-file.c \
 	symbol-db-model-file.h \
+	symbol-db-model-search.c \
+	symbol-db-model-search.h \
 	symbol-db-views.c \
 	symbol-db-views.h \
-	libgda-extra/gda-data-model-concat.c \
-	libgda-extra/gda-data-model-concat.h \
-	$(BUILT_SOURCES) \
-	symbol-db-query.h \
-	symbol-db-query.c \
-	symbol-db-query-result.h \
-	symbol-db-query-result.c
+	$(BUILT_SOURCES)
 
 libanjuta_symbol_db_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index bcda80d..5045e45 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -2133,6 +2133,13 @@ symbol_db_activate (AnjutaPlugin *plugin)
 	gtk_notebook_append_page (GTK_NOTEBOOK (sdb_plugin->dbv_notebook),
 							  view, gtk_label_new (_("Global" )));
 
+	/* Global symbols */
+	view = symbol_db_view_new (SYMBOL_DB_VIEW_SEARCH,
+	                           sdb_plugin->sdbe_project,
+	                           sdb_plugin);
+	gtk_notebook_append_page (GTK_NOTEBOOK (sdb_plugin->dbv_notebook),
+							  view, gtk_label_new (_("Search" )));
+
 	gtk_widget_show_all (sdb_plugin->dbv_notebook);
 
 	/* setting focus to the tree_view*/
diff --git a/plugins/symbol-db/symbol-db-model-search.c b/plugins/symbol-db/symbol-db-model-search.c
new file mode 100644
index 0000000..9010960
--- /dev/null
+++ b/plugins/symbol-db/symbol-db-model-search.c
@@ -0,0 +1,269 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * symbol-db-model-search.c
+ * Copyright (C) Naba Kumar 2010 <naba gnome org>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libanjuta/anjuta-debug.h>
+#include "symbol-db-engine.h"
+#include "symbol-db-model-search.h"
+
+#define SDB_MODEL_SEARCH_SQL " \
+	SELECT \
+		symbol.symbol_id, \
+		symbol.name, \
+		symbol.file_position, \
+		symbol.scope_definition_id, \
+		symbol.signature, \
+		symbol.returntype, \
+		file.file_path, \
+		sym_access.access_name, \
+		sym_type.type_type, \
+		sym_type.type_name, \
+		sym_kind.is_container \
+	FROM symbol \
+	LEFT JOIN file ON symbol.file_defined_id = file.file_id \
+	LEFT JOIN sym_access ON symbol.access_kind_id = sym_access.access_kind_id \
+	LEFT JOIN sym_type ON symbol.type_id = sym_type.type_id \
+	LEFT JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id \
+	WHERE symbol.name LIKE ## /* name:'pattern' type:gchararray */ \
+	ORDER BY symbol.name \
+	LIMIT ## /* name:'limit' type:gint */ \
+	OFFSET ## /* name:'offset' type:gint */ \
+	"
+
+struct _SymbolDBModelSearchPriv
+{
+	gchar *search_pattern;
+	guint refresh_queue_id;
+	GdaStatement *stmt;
+	GdaSet *params;
+	GdaHolder *param_pattern, *param_limit, *param_offset;
+};
+
+enum
+{
+	PROP_0,
+	PROP_SEARCH_PATTERN
+};
+
+G_DEFINE_TYPE (SymbolDBModelSearch, sdb_model_search,
+               SYMBOL_DB_TYPE_MODEL_PROJECT);
+
+static void
+sdb_model_search_update_sql_stmt (SymbolDBModel *model)
+{
+	SymbolDBEngine *dbe;
+	SymbolDBModelSearchPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (model));
+	priv = SYMBOL_DB_MODEL_SEARCH (model)->priv;
+	
+	g_object_get (model, "symbol-db-engine", &dbe, NULL);
+	priv->stmt = symbol_db_engine_get_statement (dbe, SDB_MODEL_SEARCH_SQL);
+	gda_statement_get_parameters (priv->stmt, &priv->params, NULL);
+	priv->param_pattern = gda_set_get_holder (priv->params, "pattern");
+	priv->param_limit = gda_set_get_holder (priv->params, "limit");
+	priv->param_offset = gda_set_get_holder (priv->params, "offset");
+}
+
+static GdaDataModel*
+sdb_model_search_get_children (SymbolDBModel *model, gint tree_level,
+                             GValue column_values[], gint offset,
+                             gint limit)
+{
+	SymbolDBEngine *dbe;
+	SymbolDBModelSearchPriv *priv;
+	GValue ival = {0};
+	GValue sval = {0};
+
+	g_return_val_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (model), 0);
+	priv = SYMBOL_DB_MODEL_SEARCH (model)->priv;
+
+	if (tree_level > 0)
+		return NULL; /* It's a flat list */
+	
+	g_object_get (model, "symbol-db-engine", &dbe, NULL);
+	
+	/* If engine is not connected, there is nothing we can show */
+	if (!dbe || !symbol_db_engine_is_connected (dbe) || !priv->search_pattern)
+		return NULL;
+
+	if (!priv->stmt)
+		sdb_model_search_update_sql_stmt (model);
+	
+	/* Initialize parameters */
+	g_value_init (&ival, G_TYPE_INT);
+	g_value_init (&sval, G_TYPE_STRING);
+	g_value_set_int (&ival, limit);
+	gda_holder_set_value (priv->param_limit, &ival, NULL);
+	g_value_set_int (&ival, offset);
+	gda_holder_set_value (priv->param_offset, &ival, NULL);
+	g_value_set_static_string (&sval, priv->search_pattern);
+	gda_holder_set_value (priv->param_pattern, &sval, NULL);
+	g_value_reset (&sval);
+
+	return symbol_db_engine_execute_select (dbe, priv->stmt, priv->params);
+}
+
+static gint
+sdb_model_search_get_n_children (SymbolDBModel *model, gint tree_level,
+                               GValue column_values[])
+{
+	gint n_children = 0;
+	GdaDataModel *data_model;
+
+	if (tree_level > 0)
+		return 0; /* It's a flat list */
+	
+	data_model = sdb_model_search_get_children (model, tree_level,
+	                                          column_values, 0,
+	                                          500);
+	if (GDA_IS_DATA_MODEL (data_model))
+	{
+		n_children = gda_data_model_get_n_rows (data_model);
+		g_object_unref (data_model);
+	}
+	return n_children;
+}
+
+static gboolean
+sdb_model_search_get_has_child (SymbolDBModel *model, gint tree_level,
+                                GValue column_values[])
+{
+	return FALSE;
+}
+
+static gboolean
+sdb_model_search_refresh_idle (gpointer object)
+{
+	SymbolDBModelSearchPriv *priv;
+	priv = SYMBOL_DB_MODEL_SEARCH (object)->priv;
+	symbol_db_model_update (SYMBOL_DB_MODEL (object));
+	priv->refresh_queue_id = 0;
+	return FALSE;
+}
+
+static void
+sdb_model_search_set_property (GObject *object, guint prop_id,
+                             const GValue *value, GParamSpec *pspec)
+{
+	gchar *old_pattern;
+	SymbolDBModelSearchPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (object));
+	priv = SYMBOL_DB_MODEL_SEARCH (object)->priv;
+	
+	switch (prop_id)
+	{
+	case PROP_SEARCH_PATTERN:
+		old_pattern = priv->search_pattern;
+		priv->search_pattern = g_strdup_printf ("%%%s%%",
+		                                        g_value_get_string (value));
+		if (g_strcmp0 (old_pattern, priv->search_pattern) != 0)
+		{
+			if (priv->refresh_queue_id)
+				g_source_remove (priv->refresh_queue_id);
+			priv->refresh_queue_id =
+					g_idle_add (sdb_model_search_refresh_idle, object);
+		}
+		g_free (old_pattern);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+sdb_model_search_get_property (GObject *object, guint prop_id,
+                             GValue *value, GParamSpec *pspec)
+{
+	SymbolDBModelSearchPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (object));
+	priv = SYMBOL_DB_MODEL_SEARCH (object)->priv;
+	
+	switch (prop_id)
+	{
+	case PROP_SEARCH_PATTERN:
+		g_value_set_string (value, priv->search_pattern);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+sdb_model_search_finalize (GObject *object)
+{
+	SymbolDBModelSearchPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (object));
+	priv = SYMBOL_DB_MODEL_SEARCH (object)->priv;
+	g_free (priv->search_pattern);
+	if (priv->stmt)
+	{
+		g_object_unref (priv->stmt);
+		g_object_unref (priv->params);
+	}
+	if (priv->refresh_queue_id)
+		g_source_remove (priv->refresh_queue_id);
+	g_free (priv);
+	
+	G_OBJECT_CLASS (sdb_model_search_parent_class)->finalize (object);
+}
+
+static void
+sdb_model_search_init (SymbolDBModelSearch *object)
+{
+	SymbolDBModelSearchPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_SEARCH (object));
+
+	priv = g_new0 (SymbolDBModelSearchPriv, 1);
+	object->priv = priv;
+}
+
+static void
+sdb_model_search_class_init (SymbolDBModelSearchClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	SymbolDBModelClass* model_class = SYMBOL_DB_MODEL_CLASS (klass);
+	
+	object_class->finalize = sdb_model_search_finalize;
+	object_class->set_property = sdb_model_search_set_property;
+	object_class->get_property = sdb_model_search_get_property;
+
+	model_class->get_n_children = sdb_model_search_get_n_children;
+	model_class->get_children =  sdb_model_search_get_children;
+	model_class->get_has_child = sdb_model_search_get_has_child;
+	
+	g_object_class_install_property
+		(object_class, PROP_SEARCH_PATTERN,
+		 g_param_spec_string ("search-pattern",
+		                      "Search Pattern",
+		                      "Search pattern to match",
+		                      NULL, G_PARAM_READABLE | G_PARAM_WRITABLE));
+}
+
+GtkTreeModel*
+symbol_db_model_search_new (SymbolDBEngine* dbe)
+{
+	return GTK_TREE_MODEL (g_object_new (SYMBOL_DB_TYPE_MODEL_SEARCH,
+	                                     "symbol-db-engine", dbe, NULL));
+}
diff --git a/plugins/symbol-db/symbol-db-model-search.h b/plugins/symbol-db/symbol-db-model-search.h
new file mode 100644
index 0000000..4c7e771
--- /dev/null
+++ b/plugins/symbol-db/symbol-db-model-search.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * symbol-db-model-file.h
+ * Copyright (C) Naba Kumar 2010 <naba gnome org>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYMBOL_DB_MODEL_SEARCH_H_
+#define _SYMBOL_DB_MODEL_SEARCH_H_
+
+#include <glib-object.h>
+#include "symbol-db-model-project.h"
+
+G_BEGIN_DECLS
+
+#define SYMBOL_DB_TYPE_MODEL_SEARCH             (sdb_model_search_get_type ())
+#define SYMBOL_DB_MODEL_SEARCH(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYMBOL_DB_TYPE_MODEL_SEARCH, SymbolDBModelSearch))
+#define SYMBOL_DB_MODEL_SEARCH_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), SYMBOL_DB_TYPE_MODEL_SEARCH, SymbolDBModelSearchClass))
+#define SYMBOL_DB_IS_MODEL_SEARCH(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYMBOL_DB_TYPE_MODEL_SEARCH))
+#define SYMBOL_DB_IS_MODEL_SEARCH_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), SYMBOL_DB_TYPE_MODEL_SEARCH))
+#define SYMBOL_DB_MODEL_SEARCH_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), SYMBOL_DB_TYPE_MODEL_SEARCH, SymbolDBModelSearchClass))
+
+typedef struct _SymbolDBModelSearchClass SymbolDBModelSearchClass;
+typedef struct _SymbolDBModelSearch SymbolDBModelSearch;
+typedef struct _SymbolDBModelSearchPriv SymbolDBModelSearchPriv;
+
+struct _SymbolDBModelSearchClass
+{
+	SymbolDBModelProjectClass parent_class;
+};
+
+struct _SymbolDBModelSearch
+{
+	SymbolDBModelProject parent_instance;
+
+	SymbolDBModelSearchPriv *priv;
+};
+
+GType sdb_model_search_get_type (void) G_GNUC_CONST;
+GtkTreeModel* symbol_db_model_search_new (SymbolDBEngine* dbe);
+
+G_END_DECLS
+
+#endif /* _SYMBOL_DB_MODEL_SEARCH_H_ */
diff --git a/plugins/symbol-db/symbol-db-views.c b/plugins/symbol-db/symbol-db-views.c
index b25494a..0d9d4a1 100644
--- a/plugins/symbol-db/symbol-db-views.c
+++ b/plugins/symbol-db/symbol-db-views.c
@@ -21,6 +21,7 @@
 #include <libanjuta/interfaces/ianjuta-markable.h>
 #include "symbol-db-model-project.h"
 #include "symbol-db-model-file.h"
+#include "symbol-db-model-search.h"
 #include "symbol-db-engine.h"
 #include "symbol-db-views.h"
 #include "plugin.h"
@@ -121,6 +122,12 @@ on_treeview_has_child_toggled (GtkTreeModel *model,
 	g_free (symbol_name);
 }
 
+static void
+on_search_entry_changed (GtkEntry *entry, SymbolDBModelSearch *model)
+{
+	g_object_set (model, "search-pattern", gtk_entry_get_text (entry), NULL);
+}
+
 GtkWidget*
 symbol_db_view_new (SymbolViewType view_type,
                     SymbolDBEngine *dbe, SymbolDBPlugin *plugin)
@@ -130,12 +137,18 @@ symbol_db_view_new (SymbolViewType view_type,
 	GtkWidget *dbv;
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *renderer;
+	GtkWidget *vbox = NULL;
+	GtkWidget *entry;
 
 	switch (view_type)
 	{
 		case SYMBOL_DB_VIEW_FILE:
 			model = symbol_db_model_file_new (dbe);
 			break;
+		case SYMBOL_DB_VIEW_SEARCH:
+			model = symbol_db_model_search_new (dbe);
+			g_object_set (model, "show-file-line", TRUE, NULL);
+			break;
 		default:
 			model = symbol_db_model_project_new (dbe);
 	}
@@ -193,5 +206,18 @@ symbol_db_view_new (SymbolViewType view_type,
 	gtk_widget_show (dbv);
 	gtk_container_add (GTK_CONTAINER (sw), dbv);
 	gtk_widget_show (sw);
+
+	if (view_type == SYMBOL_DB_VIEW_SEARCH)
+	{
+		entry = gtk_entry_new ();
+		g_signal_connect (entry, "changed",
+		                  G_CALLBACK (on_search_entry_changed), model);
+		gtk_widget_show (entry);
+		vbox = gtk_vbox_new (FALSE, 3);
+		gtk_widget_show (vbox);
+		gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+		gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+		return vbox;
+	}
 	return sw;
 }
diff --git a/plugins/symbol-db/symbol-db-views.h b/plugins/symbol-db/symbol-db-views.h
index 0ba221f..044450b 100644
--- a/plugins/symbol-db/symbol-db-views.h
+++ b/plugins/symbol-db/symbol-db-views.h
@@ -27,7 +27,8 @@ G_BEGIN_DECLS
 
 typedef enum {
 	SYMBOL_DB_VIEW_PROJECT,
-	SYMBOL_DB_VIEW_FILE
+	SYMBOL_DB_VIEW_FILE,
+	SYMBOL_DB_VIEW_SEARCH
 } SymbolViewType;
 
 GtkWidget* symbol_db_view_new (SymbolViewType view_type,



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