[libgda] GdaBrowser: right click on tree views selects row



commit ebde59d3af08ef6ca65fc371639c6108789189bb
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Jul 21 17:18:55 2010 +0200

    GdaBrowser: right click on tree views selects row

 tools/browser/browser-connections-list.c           |    2 +-
 .../browser/data-manager/data-favorite-selector.c  |    2 +-
 tools/browser/query-exec/query-editor.c            |    5 +-
 tools/browser/query-exec/query-favorite-selector.c |    2 +-
 tools/browser/schema-browser/favorite-selector.c   |    4 +-
 tools/browser/schema-browser/table-columns.c       |    4 +-
 tools/browser/schema-browser/table-preferences.c   |    2 +-
 tools/browser/support.c                            |   57 ++++++++++++++++++++
 tools/browser/support.h                            |    1 +
 9 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/tools/browser/browser-connections-list.c b/tools/browser/browser-connections-list.c
index 2a7f968..2ed77c9 100644
--- a/tools/browser/browser-connections-list.c
+++ b/tools/browser/browser-connections-list.c
@@ -405,7 +405,7 @@ browser_connections_list_show (BrowserConnection *current)
 		store = gtk_list_store_new (NUM_COLUMNS,
 					    BROWSER_TYPE_CONNECTION);
 		
-		treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+		treeview = browser_make_tree_view (GTK_TREE_MODEL (store));
 		_clist->priv->treeview = GTK_TREE_VIEW (treeview);
 		gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 		gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
diff --git a/tools/browser/data-manager/data-favorite-selector.c b/tools/browser/data-manager/data-favorite-selector.c
index 9450e14..9350911 100644
--- a/tools/browser/data-manager/data-favorite-selector.c
+++ b/tools/browser/data-manager/data-favorite-selector.c
@@ -501,7 +501,7 @@ data_favorite_selector_new (BrowserConnection *bcnc)
 				      G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME,
 				      G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
 				      G_TYPE_STRING, MGR_FAVORITES_NAME_ATT_NAME);
-	treeview = gtk_tree_view_new_with_model (model);
+	treeview = browser_make_tree_view (model);
 	tsel->priv->treeview = treeview;
 	g_object_unref (model);
 
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index ad15fb7..01205c6 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -1,5 +1,5 @@
 /* GNOME DB library
- * Copyright (C) 1999 - 2009 The GNOME Foundation.
+ * Copyright (C) 1999 - 2010 The GNOME Foundation.
  *
  * AUTHORS:
  *      Rodrigo Moya <rodrigo gnome-db org>
@@ -40,6 +40,7 @@
 #include "../browser-connection.h"
 #include "../browser-window.h"
 #include "../common/popup-container.h"
+#include "../support.h"
 
 #define QUERY_EDITOR_LANGUAGE_SQL "gda-sql"
 #define COLOR_ALTER_FACTOR 1.8
@@ -373,7 +374,7 @@ display_completions (QueryEditor *editor)
 			GtkWidget *popup, *sw;
 			
 			model = gtk_list_store_new (1, G_TYPE_STRING);
-			treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+			treeview = browser_make_tree_view (GTK_TREE_MODEL (model));
 			gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 			gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_GRID_LINES_NONE);
 			gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
diff --git a/tools/browser/query-exec/query-favorite-selector.c b/tools/browser/query-exec/query-favorite-selector.c
index 3aebbb2..5cc53a7 100644
--- a/tools/browser/query-exec/query-favorite-selector.c
+++ b/tools/browser/query-exec/query-favorite-selector.c
@@ -467,7 +467,7 @@ query_favorite_selector_new (BrowserConnection *bcnc)
 				      G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
 				      G_TYPE_STRING, MGR_FAVORITES_NAME_ATT_NAME,
 				      G_TYPE_STRING, "summary");
-	treeview = gtk_tree_view_new_with_model (model);
+	treeview = browser_make_tree_view (model);
 	tsel->priv->treeview = treeview;
 	g_object_unref (model);
 
diff --git a/tools/browser/schema-browser/favorite-selector.c b/tools/browser/schema-browser/favorite-selector.c
index 9d57073..a9a4a85 100644
--- a/tools/browser/schema-browser/favorite-selector.c
+++ b/tools/browser/schema-browser/favorite-selector.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The GNOME Foundation
+ * Copyright (C) 2009 - 2010 The GNOME Foundation
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -264,7 +264,7 @@ favorite_selector_new (BrowserConnection *bcnc)
 				      G_TYPE_STRING, MGR_FAVORITES_CONTENTS_ATT_NAME,
 				      G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME,
 				      G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME);
-	treeview = gtk_tree_view_new_with_model (model);
+	treeview = browser_make_tree_view (model);
 	tsel->priv->treeview = treeview;
 	g_object_unref (model);
 
diff --git a/tools/browser/schema-browser/table-columns.c b/tools/browser/schema-browser/table-columns.c
index 9d18d00..a6fe29e 100644
--- a/tools/browser/schema-browser/table-columns.c
+++ b/tools/browser/schema-browser/table-columns.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The GNOME Foundation
+ * Copyright (C) 2009 - 2010 The GNOME Foundation
  *
  * AUTHORS:
  *      Vivien Malerba <malerba gnome-db org>
@@ -388,7 +388,7 @@ table_columns_new (TableInfo *tinfo)
 				      G_TYPE_BOOLEAN, MGR_COLUMNS_COL_NOTNULL_ATT_NAME,
 				      G_TYPE_STRING, MGR_COLUMNS_COL_DEFAULT_ATT_NAME,
                                       G_TYPE_OBJECT, "icon");
-        treeview = gtk_tree_view_new_with_model (model);
+        treeview = browser_make_tree_view (model);
         g_object_unref (model);
 
         /* Colum: Name */
diff --git a/tools/browser/schema-browser/table-preferences.c b/tools/browser/schema-browser/table-preferences.c
index 53d81d4..1c4c469 100644
--- a/tools/browser/schema-browser/table-preferences.c
+++ b/tools/browser/schema-browser/table-preferences.c
@@ -359,7 +359,7 @@ table_preferences_new (TableInfo *tinfo)
 	tpref->priv->columns_store = gtk_list_store_new (NUM_COLUMNS,
 							 G_TYPE_POINTER, G_TYPE_GTYPE,
 							 G_TYPE_STRING);
-	treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tpref->priv->columns_store));
+	treeview = browser_make_tree_view (GTK_TREE_MODEL (tpref->priv->columns_store));
 	tpref->priv->columns_treeview = GTK_TREE_VIEW (treeview);
 	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
 	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
diff --git a/tools/browser/support.c b/tools/browser/support.c
index 065785a..540f25b 100644
--- a/tools/browser/support.c
+++ b/tools/browser/support.c
@@ -520,6 +520,17 @@ connection_removed_cb (BrowserCore *bcore, BrowserConnection *bcnc, GdaDataModel
 	}
 }
 
+/**
+ * browser_make_small_button
+ * @is_toggle:
+ * @label:
+ * @stock_id:
+ * @tooltip:
+ *
+ * Creates a small button
+ *
+ * Returns: a new #GtkWidget
+ */
 GtkWidget *
 browser_make_small_button (gboolean is_toggle, const gchar *label, const gchar *stock_id, const gchar *tooltip)
 {
@@ -558,3 +569,49 @@ browser_make_small_button (gboolean is_toggle, const gchar *label, const gchar *
 		gtk_widget_set_tooltip_text (button, tooltip);
 	return button;
 }
+
+static gboolean
+tree_view_button_pressed_cb (GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+	GtkTreeView *tree_view;
+	GtkTreeSelection *selection;
+
+	if (event->button != 3)
+		return FALSE;
+
+	tree_view = GTK_TREE_VIEW (widget);
+	selection = gtk_tree_view_get_selection (tree_view);
+
+	/* force selection of row on which clicked occurred */
+	GtkTreePath *path;
+	if ((event->window == gtk_tree_view_get_bin_window (tree_view)) &&
+	    gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL)) {
+		gtk_tree_selection_unselect_all (selection);
+		gtk_tree_selection_select_path (selection, path);
+		gtk_tree_path_free (path);
+	}
+
+	return FALSE;
+}
+
+/**
+ * browser_make_tree_view
+ * @model: a #GtkTreeModel
+ *
+ * Creates a #GtkTreeView which, when right clicked, selects the row underneath the mouse
+ * cursor.
+ *
+ * Returns: a new #GtkWidget
+ */
+GtkWidget *
+browser_make_tree_view (GtkTreeModel *model)
+{
+	GtkWidget *tv;
+	g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
+	tv = gtk_tree_view_new_with_model (model);
+
+	g_signal_connect (G_OBJECT (tv), "button-press-event",
+                          G_CALLBACK (tree_view_button_pressed_cb), NULL);
+
+	return tv;
+}
diff --git a/tools/browser/support.h b/tools/browser/support.h
index 29bcdd6..4529338 100644
--- a/tools/browser/support.h
+++ b/tools/browser/support.h
@@ -50,6 +50,7 @@ GtkWidget*         browser_make_tab_label_with_pixbuf (const gchar *label,
 
 GtkWidget          *browser_make_small_button (gboolean is_toggle,
 					       const gchar *label, const gchar *stock_id, const gchar *tooltip);
+GtkWidget          *browser_make_tree_view (GtkTreeModel *model);
 
 /*
  * Widgets navigation



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