[gnome-documents] utils: add a helper function to set a single click policy for treeview
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] utils: add a helper function to set a single click policy for treeview
- Date: Mon, 1 Aug 2011 15:23:57 +0000 (UTC)
commit c7f1a8625c8f32b2c1bc17862baa57d4097f783b
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Aug 1 17:19:12 2011 +0200
utils: add a helper function to set a single click policy for treeview
Imported from libeel
src/lib/gd-utils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/gd-utils.h | 3 +++
2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index 01c66f4..a087186 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -188,3 +188,54 @@ gd_queue_thumbnail_job_for_file_finish (GAsyncResult *res)
return g_simple_async_result_get_op_res_gboolean (simple);
}
+
+/* taken from eel/eel-gtk-extensions.c */
+static gboolean
+tree_view_button_press_callback (GtkWidget *tree_view,
+ GdkEventButton *event,
+ gpointer data)
+{
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+
+ if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
+ if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view),
+ event->x, event->y,
+ &path,
+ &column,
+ NULL,
+ NULL)) {
+ gtk_tree_view_row_activated
+ (GTK_TREE_VIEW (tree_view), path, column);
+ }
+ }
+
+ return FALSE;
+}
+
+void
+gd_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
+ gboolean should_activate)
+{
+ guint button_press_id;
+
+ button_press_id = GPOINTER_TO_UINT
+ (g_object_get_data (G_OBJECT (tree_view),
+ "gd-tree-view-activate"));
+
+ if (button_press_id && !should_activate) {
+ g_signal_handler_disconnect (tree_view, button_press_id);
+ g_object_set_data (G_OBJECT (tree_view),
+ "gd-tree-view-activate",
+ NULL);
+ } else if (!button_press_id && should_activate) {
+ button_press_id = g_signal_connect
+ (tree_view,
+ "button_press_event",
+ G_CALLBACK (tree_view_button_press_callback),
+ NULL);
+ g_object_set_data (G_OBJECT (tree_view),
+ "gd-tree-view-activate",
+ GUINT_TO_POINTER (button_press_id));
+ }
+}
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index 4080128..976d44c 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -52,5 +52,8 @@ void gd_queue_thumbnail_job_for_file_async (GFile *file,
gboolean gd_queue_thumbnail_job_for_file_finish (GAsyncResult *res);
+void gd_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
+ gboolean should_activate);
+
#endif /* __GD_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]