[evolution-data-server/triple-click-source-selector: 2/2] Bug 611873 - Make triple-clicking a shortcut for "Show Only This ..."



commit 8137bfb5e13a8847f37fa779de9eeb4d6f1668a3
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               |  120 +++++++++++++++++---
 libedataserverui/e-source-selector.h               |    3 +
 4 files changed, 116 insertions(+), 18 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 93d459c..07d3aa5 100644
--- a/libedataserverui/e-source-selector.c
+++ b/libedataserverui/e-source-selector.c
@@ -842,19 +842,26 @@ static gboolean
 source_selector_button_press_event (GtkWidget *widget,
                                     GdkEventButton *event)
 {
-	ESourceSelectorPrivate *priv;
+	ESourceSelector *selector;
 	GtkWidgetClass *widget_class;
 	GtkTreePath *path;
 	ESource *source = NULL;
+	gboolean right_click = FALSE;
+	gboolean triple_click = FALSE;
 	gboolean row_exists;
 	gboolean res = FALSE;
 
-	priv = E_SOURCE_SELECTOR_GET_PRIVATE (widget);
+	selector = E_SOURCE_SELECTOR (widget);
 
-	priv->toggled_last = FALSE;
+	selector->priv->toggled_last = FALSE;
 
-	/* only process right-clicks */
-	if (event->button != 3 || event->type != GDK_BUTTON_PRESS)
+	/* 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 (
@@ -875,7 +882,8 @@ source_selector_button_press_event (GtkWidget *widget,
 			/* Do not emit popup since we will
 			 * not be able to get the ESource. */
 			if (E_IS_SOURCE_GROUP (data)) {
-				priv->primary_source_group = g_object_ref (data);
+				selector->priv->primary_source_group =
+					g_object_ref (data);
 				/* Data shuld be unreffed after
 				 * creating the new source. */
 				goto chainup;
@@ -885,14 +893,21 @@ source_selector_button_press_event (GtkWidget *widget,
 		}
 	}
 
-	if (source != NULL)
-		e_source_selector_set_primary_selection (
-			E_SOURCE_SELECTOR (widget), source);
+	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);
 
-	g_signal_emit (widget, signals[POPUP_EVENT], 0, source, event, &res);
+	if (triple_click) {
+		e_source_selector_select_exclusive (selector, source);
+		res = TRUE;
+	}
 
-	if (source != NULL)
-		g_object_unref (source);
+	g_object_unref (source);
 
 	return res;
 
@@ -1483,8 +1498,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);
@@ -1520,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);
@@ -1540,6 +1557,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
@@ -1557,8 +1641,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);
 }
 
 /**
@@ -1692,10 +1777,9 @@ e_source_selector_set_primary_selection (ESourceSelector *selector,
 	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;
diff --git a/libedataserverui/e-source-selector.h b/libedataserverui/e-source-selector.h
index 4f46d52..b20cd61 100644
--- a/libedataserverui/e-source-selector.h
+++ b/libedataserverui/e-source-selector.h
@@ -86,6 +86,9 @@ void		e_source_selector_select_source	(ESourceSelector *selector,
 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);



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