[evolution-data-server/mmeeks-gdbus-import] Bug 611873 - Make triple-clicking a shortcut for "Show Only This ..."



commit b963e4c472253ff05a0ce976b2b9d31d0869605b
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Mar 5 11:38:07 2010 -0500

    Bug 611873 - Make triple-clicking a shortcut for "Show Only This ..."
    
    Adds e_source_selector_select_exclusive() to libedataserverui.

 .../libedataserverui/libedataserverui-sections.txt |    2 +
 .../libedataserverui/tmpl/e-source-selector.sgml   |    9 +
 libedataserverui/e-source-selector.c               |  161 +++++++++++++++++++-
 libedataserverui/e-source-selector.h               |   59 ++++----
 4 files changed, 198 insertions(+), 33 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index db14cc8..89dc125 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -273,6 +273,7 @@ e_source_selector_new
 e_source_selector_get_source_list
 e_source_selector_select_source
 e_source_selector_unselect_source
+e_source_selector_select_exclusive
 e_source_selector_source_is_selected
 e_source_selector_get_selection
 e_source_selector_free_selection
@@ -289,6 +290,7 @@ E_IS_SOURCE_SELECTOR
 E_TYPE_SOURCE_SELECTOR
 E_SOURCE_SELECTOR_CLASS
 E_IS_SOURCE_SELECTOR_CLASS
+E_SOURCE_SELECTOR_GET_CLASS
 ESourceSelectorClass
 <SUBSECTION Private>
 ESourceSelectorPrivate
diff --git a/docs/reference/libedataserverui/tmpl/e-source-selector.sgml b/docs/reference/libedataserverui/tmpl/e-source-selector.sgml
index 7fc5168..442f3c7 100644
--- a/docs/reference/libedataserverui/tmpl/e-source-selector.sgml
+++ b/docs/reference/libedataserverui/tmpl/e-source-selector.sgml
@@ -100,6 +100,15 @@ ESourceSelector
 @source: 
 
 
+<!-- ##### FUNCTION e_source_selector_select_exclusive ##### -->
+<para>
+
+</para>
+
+ selector: 
+ source: 
+
+
 <!-- ##### FUNCTION e_source_selector_source_is_selected ##### -->
 <para>
 
diff --git a/libedataserverui/e-source-selector.c b/libedataserverui/e-source-selector.c
index 27a6a79..1b91f35 100644
--- a/libedataserverui/e-source-selector.c
+++ b/libedataserverui/e-source-selector.c
@@ -912,6 +912,86 @@ source_selector_finalize (GObject *object)
 	G_OBJECT_CLASS (e_source_selector_parent_class)->finalize (object);
 }
 
+static gboolean
+source_selector_button_press_event (GtkWidget *widget,
+                                    GdkEventButton *event)
+{
+	ESourceSelector *selector;
+	GtkWidgetClass *widget_class;
+	GtkTreePath *path;
+	ESource *source = NULL;
+	gboolean right_click = FALSE;
+	gboolean triple_click = FALSE;
+	gboolean row_exists;
+	gboolean res = FALSE;
+
+	selector = E_SOURCE_SELECTOR (widget);
+
+	selector->priv->toggled_last = FALSE;
+
+	/* Triple-clicking a source selects it exclusively. */
+
+	if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+		right_click = TRUE;
+	else if (event->button == 1 && event->type == GDK_3BUTTON_PRESS)
+		triple_click = TRUE;
+	else
+		goto chainup;
+
+	row_exists = gtk_tree_view_get_path_at_pos (
+		GTK_TREE_VIEW (widget), event->x, event->y,
+		&path, NULL, NULL, NULL);
+
+	/* Get the source/group */
+	if (row_exists) {
+		GtkTreeModel *model;
+		GtkTreeIter iter;
+		gpointer data;
+
+		model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+
+		if (gtk_tree_model_get_iter (model, &iter, path)) {
+			gtk_tree_model_get (model, &iter, 0, &data, -1);
+
+			/* Do not emit popup since we will
+			 * not be able to get the ESource. */
+			if (E_IS_SOURCE_GROUP (data)) {
+				selector->priv->primary_source_group =
+					g_object_ref (data);
+				/* Data shuld be unreffed after
+				 * creating the new source. */
+				goto chainup;
+			}
+
+			source = E_SOURCE (data);
+		}
+	}
+
+	if (source == NULL)
+		goto chainup;
+
+	e_source_selector_set_primary_selection (selector, source);
+
+	if (right_click)
+		g_signal_emit (
+			widget, signals[POPUP_EVENT], 0, source, event, &res);
+
+	if (triple_click) {
+		e_source_selector_select_exclusive (selector, source);
+		res = TRUE;
+	}
+
+	g_object_unref (source);
+
+	return res;
+
+chainup:
+
+	/* Chain up to parent's button_press_event() method. */
+	widget_class = GTK_WIDGET_CLASS (e_source_selector_parent_class);
+	return widget_class->button_press_event (widget, event);
+}
+
 static void
 source_selector_drag_leave (GtkWidget *widget,
                             GdkDragContext *context,
@@ -1420,8 +1500,9 @@ e_source_selector_select_source (ESourceSelector *selector,
 	g_return_if_fail (E_IS_SOURCE (source));
 
 	source = find_source (selector, source);
+	g_return_if_fail (source != NULL);
 
-	if (!source || source_is_selected (selector, source))
+	if (source_is_selected (selector, source))
 		return;
 
 	select_source (selector, source);
@@ -1455,8 +1536,9 @@ e_source_selector_unselect_source (ESourceSelector *selector,
 	g_return_if_fail (E_IS_SOURCE (source));
 
 	source = find_source (selector, source);
+	g_return_if_fail (source != NULL);
 
-	if (!source || !source_is_selected (selector, source))
+	if (!source_is_selected (selector, source))
 		return;
 
 	unselect_source (selector, source);
@@ -1473,6 +1555,73 @@ e_source_selector_unselect_source (ESourceSelector *selector,
 	}
 }
 
+/* Helper for e_source_selector_select_exclusive() */
+static gboolean
+source_selector_select_exclusive_foreach (GtkTreeModel *model,
+                                          GtkTreePath *path,
+                                          GtkTreeIter *iter,
+                                          gpointer user_data)
+{
+	ESource *source;
+
+	struct {
+		ESourceSelector *selector;
+		ESource *source_to_select;
+	} *data = user_data;
+
+	if (gtk_tree_path_get_depth (path) != 2)
+		return FALSE;
+
+	gtk_tree_model_get (model, iter, 0, &source, -1);
+
+	if (source == data->source_to_select)
+		select_source (data->selector, source);
+	else
+		unselect_source (data->selector, source);
+
+	gtk_tree_model_row_changed (model, path, iter);
+
+	g_object_unref (source);
+
+	return FALSE;
+}
+
+/**
+ * e_source_selector_select_exclusive:
+ * @selector: An #ESourceSelector widget
+ * @source: An #ESource.
+ *
+ * Select @source in @selector and unselect all others.
+ **/
+void
+e_source_selector_select_exclusive (ESourceSelector *selector,
+                                    ESource *source)
+{
+	GtkTreeModel *model;
+
+	struct {
+		ESourceSelector *selector;
+		ESource *source_to_select;
+	} data;
+
+	g_return_if_fail (E_IS_SOURCE_SELECTOR (selector));
+	g_return_if_fail (E_IS_SOURCE (source));
+
+	source = find_source (selector, source);
+	g_return_if_fail (source != NULL);
+
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector));
+
+	data.selector = selector;
+	data.source_to_select = source;
+
+	gtk_tree_model_foreach (
+		model, (GtkTreeModelForeachFunc)
+		source_selector_select_exclusive_foreach, &data);
+
+	g_signal_emit (selector, signals[SELECTION_CHANGED], 0);
+}
+
 /**
  * e_source_selector_source_is_selected:
  * @selector: An #ESourceSelector widget
@@ -1490,8 +1639,9 @@ e_source_selector_source_is_selected (ESourceSelector *selector,
 	g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
 	source = find_source (selector, source);
+	g_return_val_if_fail (source != NULL, FALSE);
 
-	return source && source_is_selected (selector, source);
+	return source_is_selected (selector, source);
 }
 
 /**
@@ -1624,10 +1774,9 @@ e_source_selector_set_primary_selection (ESourceSelector *selector, ESource *sou
 	g_return_if_fail (E_IS_SOURCE (source));
 
 	priv = selector->priv;
-	source = find_source (selector, source);
 
-	if (!source)
-		return;
+	source = find_source (selector, source);
+	g_return_if_fail (source != NULL);
 
 	if (find_source_iter (selector, source, &parent_iter, &source_iter)) {
 		GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector));
diff --git a/libedataserverui/e-source-selector.h b/libedataserverui/e-source-selector.h
index 4304013..64e5267 100644
--- a/libedataserverui/e-source-selector.h
+++ b/libedataserverui/e-source-selector.h
@@ -65,33 +65,38 @@ struct _ESourceSelectorClass {
 	gpointer padding3;
 };
 
-GType  e_source_selector_get_type  (void);
-
-GtkWidget *e_source_selector_new  (ESourceList *list);
-ESourceList *	e_source_selector_get_source_list (ESourceSelector *selector);
-
-void      e_source_selector_select_source       (ESourceSelector *selector,
-						 ESource         *source);
-void      e_source_selector_unselect_source     (ESourceSelector *selector,
-						 ESource         *source);
-gboolean  e_source_selector_source_is_selected  (ESourceSelector *selector,
-						 ESource         *source);
-
-GSList *e_source_selector_get_selection   (ESourceSelector *selector);
-void    e_source_selector_free_selection  (GSList          *list);
-
-void      e_source_selector_show_selection   (ESourceSelector *selector,
-					      gboolean         show);
-gboolean  e_source_selector_selection_shown  (ESourceSelector *selector);
-
-void e_source_selector_set_select_new (ESourceSelector *selector, gboolean state);
-
-void     e_source_selector_edit_primary_selection  (ESourceSelector *selector);
-ESource *e_source_selector_peek_primary_selection  (ESourceSelector *selector);
-void     e_source_selector_set_primary_selection   (ESourceSelector *selector,
-						    ESource         *source);
-
-ESourceGroup *e_source_selector_get_primary_source_group (ESourceSelector *selector);
+GType		e_source_selector_get_type	(void);
+GtkWidget *	e_source_selector_new		(ESourceList *list);
+ESourceList *	e_source_selector_get_source_list
+						(ESourceSelector *selector);
+void		e_source_selector_select_source	(ESourceSelector *selector,
+						 ESource *source);
+void		e_source_selector_unselect_source
+						(ESourceSelector *selector,
+						 ESource *source);
+void		e_source_selector_select_exclusive
+						(ESourceSelector *selector,
+						 ESource *source);
+gboolean	e_source_selector_source_is_selected
+						(ESourceSelector *selector,
+						 ESource *source);
+GSList *	e_source_selector_get_selection	(ESourceSelector *selector);
+void		e_source_selector_free_selection(GSList *list);
+void		e_source_selector_show_selection(ESourceSelector *selector,
+						 gboolean show);
+gboolean	e_source_selector_selection_shown
+						(ESourceSelector *selector);
+void		e_source_selector_set_select_new(ESourceSelector *selector,
+						 gboolean state);
+void		e_source_selector_edit_primary_selection
+						(ESourceSelector *selector);
+ESource *	e_source_selector_peek_primary_selection
+						(ESourceSelector *selector);
+void		e_source_selector_set_primary_selection
+						(ESourceSelector *selector,
+						 ESource *source);
+ESourceGroup *	e_source_selector_get_primary_source_group
+						(ESourceSelector *selector);
 
 G_END_DECLS
 



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