[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Properly unselect rows; do not drop selection when the focus leaves.
Jannis Pohlmann
noreply at xfce.org
Tue Jun 7 02:58:01 CEST 2011
Updating branch refs/heads/jannis/new-shortcuts-pane
to 5c9fd4e93a227b0efd31c3f086428e419d920613 (commit)
from 59330eb9335940b23288f74e62a42c0e1a7e6912 (commit)
commit 5c9fd4e93a227b0efd31c3f086428e419d920613
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Jun 7 02:56:56 2011 +0200
Properly unselect rows; do not drop selection when the focus leaves.
thunar/thunar-shortcut-row.c | 15 ----
thunar/thunar-shortcuts-view.c | 165 +++++++++++++++++++++++++++++++--------
2 files changed, 131 insertions(+), 49 deletions(-)
diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index d6aa85f..67636fe 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -88,8 +88,6 @@ static gboolean thunar_shortcut_row_focus (GtkWidget *wid
GtkDirectionType direction);
static gboolean thunar_shortcut_row_focus_in_event (GtkWidget *widget,
GdkEventFocus *event);
-static gboolean thunar_shortcut_row_focus_out_event (GtkWidget *widget,
- GdkEventFocus *event);
static void thunar_shortcut_row_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void thunar_shortcut_row_button_state_changed (ThunarShortcutRow *row,
@@ -186,7 +184,6 @@ thunar_shortcut_row_class_init (ThunarShortcutRowClass *klass)
gtkwidget_class->expose_event = thunar_shortcut_row_expose_event;
gtkwidget_class->focus = thunar_shortcut_row_focus;
gtkwidget_class->focus_in_event = thunar_shortcut_row_focus_in_event;
- gtkwidget_class->focus_out_event = thunar_shortcut_row_focus_out_event;
gtkwidget_class->size_request = thunar_shortcut_row_size_request;
g_object_class_install_property (gobject_class, PROP_ICON,
@@ -644,18 +641,6 @@ thunar_shortcut_row_focus_in_event (GtkWidget *widget,
-static gboolean
-thunar_shortcut_row_focus_out_event (GtkWidget *widget,
- GdkEventFocus *event)
-{
- _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_ROW (widget), FALSE);
-
- gtk_widget_set_state (widget, GTK_STATE_NORMAL);
- return TRUE;
-}
-
-
-
static void
thunar_shortcut_row_size_request (GtkWidget *widget,
GtkRequisition *requisition)
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index b8a4c7f..2fb9aed 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -3,18 +3,18 @@
* Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
* Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
*
- * This program is free software; you can redistribute it and/or
+ * This program 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 2 of
+ * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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
+ * 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, write to the Free
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
@@ -68,28 +68,43 @@ enum
-static void thunar_shortcuts_view_constructed (GObject *object);
-static void thunar_shortcuts_view_finalize (GObject *object);
-static void thunar_shortcuts_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void thunar_shortcuts_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void thunar_shortcuts_view_row_inserted (ThunarShortcutsView *view,
- GtkTreePath *path,
- GtkTreeIter *iter,
- GtkTreeModel *model);
-static GtkWidget *thunar_shortcuts_view_get_expander_at (ThunarShortcutsView *view,
- gint index);
-static void thunar_shortcuts_view_row_activated (ThunarShortcutsView *view,
- ThunarFile *file,
- ThunarShortcutRow *row);
-static void thunar_shortcuts_view_open (ThunarShortcutsView *view,
- ThunarFile *file,
- gboolean new_window);
+typedef void (*ThunarShortcutsViewForeachRowFunc) (ThunarShortcutsView *view,
+ ThunarShortcutRow *row,
+ gpointer user_data);
+
+
+
+static void thunar_shortcuts_view_constructed (GObject *object);
+static void thunar_shortcuts_view_finalize (GObject *object);
+static void thunar_shortcuts_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void thunar_shortcuts_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void thunar_shortcuts_view_row_inserted (ThunarShortcutsView *view,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ GtkTreeModel *model);
+static GtkWidget *thunar_shortcuts_view_get_expander_at (ThunarShortcutsView *view,
+ gint index);
+static void thunar_shortcuts_view_row_activated (ThunarShortcutsView *view,
+ ThunarFile *file,
+ ThunarShortcutRow *row);
+static void thunar_shortcuts_view_row_state_changed (ThunarShortcutsView *view,
+ GtkStateType previous_state,
+ ThunarShortcutRow *row);
+static void thunar_shortcuts_view_open (ThunarShortcutsView *view,
+ ThunarFile *file,
+ gboolean new_window);
+static void thunar_shortcuts_view_foreach_row (ThunarShortcutsView *view,
+ ThunarShortcutsViewForeachRowFunc func,
+ gpointer user_data);
+static void thunar_shortcuts_view_unselect_rows (ThunarShortcutsView *view,
+ ThunarShortcutRow *row,
+ gpointer user_data);
@@ -199,7 +214,7 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
gtk_container_add (GTK_CONTAINER (view), alignment);
gtk_widget_show (alignment);
- view->expander_box = gtk_vbox_new (FALSE, 6);
+ view->expander_box = gtk_vbox_new (FALSE, 10);
gtk_container_add (GTK_CONTAINER (alignment), view->expander_box);
gtk_widget_show (view->expander_box);
}
@@ -230,8 +245,8 @@ thunar_shortcuts_view_constructed (GObject *object)
valid_iter = gtk_tree_model_get_iter_first (view->model, &iter);
while (valid_iter)
{
- /* TODO read values from the row and create an expander,
- * shortcut row or drop placeholder, depending on the
+ /* TODO read values from the row and create an expander,
+ * shortcut row or drop placeholder, depending on the
* row values */
gtk_tree_model_get (view->model, &iter,
THUNAR_SHORTCUTS_MODEL_COLUMN_CATEGORY, &category,
@@ -390,7 +405,7 @@ thunar_shortcuts_view_row_inserted (ThunarShortcutsView *view,
/* find the expander for the row widget */
expander = thunar_shortcuts_view_get_expander_at (view, category_index);
-
+
/* if this fails then we are out of sync with the model */
g_assert (expander != NULL);
@@ -402,7 +417,7 @@ thunar_shortcuts_view_row_inserted (ThunarShortcutsView *view,
/* move the row to the correct location */
gtk_box_reorder_child (GTK_BOX (box), shortcut_row, shortcut_index);
-
+
/* show the row now (unless it was hidden by the user) */
if (visible)
gtk_widget_show (shortcut_row);
@@ -410,13 +425,16 @@ thunar_shortcuts_view_row_inserted (ThunarShortcutsView *view,
/* be notified when the user wishes to open the shortcut */
g_signal_connect_swapped (shortcut_row, "activated",
G_CALLBACK (thunar_shortcuts_view_row_activated), view);
+ g_signal_connect_swapped (shortcut_row, "state-changed",
+ G_CALLBACK (thunar_shortcuts_view_row_state_changed),
+ view);
}
}
static GtkWidget *
-thunar_shortcuts_view_get_expander_at (ThunarShortcutsView *view,
+thunar_shortcuts_view_get_expander_at (ThunarShortcutsView *view,
gint expander_index)
{
GtkWidget *expander = NULL;
@@ -427,7 +445,7 @@ thunar_shortcuts_view_get_expander_at (ThunarShortcutsView *view,
_thunar_return_val_if_fail (expander_index >= 0, NULL);
expanders = gtk_container_get_children (GTK_CONTAINER (view->expander_box));
-
+
lp = g_list_nth (expanders, expander_index);
if (lp != NULL)
expander = lp->data;
@@ -454,6 +472,85 @@ thunar_shortcuts_view_row_activated (ThunarShortcutsView *view,
static void
+thunar_shortcuts_view_row_state_changed (ThunarShortcutsView *view,
+ GtkStateType previous_state,
+ ThunarShortcutRow *row)
+{
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+
+ /* check if the row has been selected */
+ if (gtk_widget_get_state (GTK_WIDGET (row)) == GTK_STATE_SELECTED)
+ {
+ /* unselect all other rows */
+ thunar_shortcuts_view_foreach_row (view, thunar_shortcuts_view_unselect_rows, row);
+ }
+}
+
+
+
+static void
+thunar_shortcuts_view_foreach_row (ThunarShortcutsView *view,
+ ThunarShortcutsViewForeachRowFunc func,
+ gpointer user_data)
+{
+ GtkWidget *box;
+ GList *expanders;
+ GList *ep;
+ GList *rows;
+ GList *rp;
+
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+ _thunar_return_if_fail (func != NULL);
+
+ /* get a list of all expanders */
+ expanders = gtk_container_get_children (GTK_CONTAINER (view->expander_box));
+
+ /* iterate over all expanders */
+ for (ep = expanders; ep != NULL; ep = ep->next)
+ {
+ /* get the box that holds the rows */
+ box = gtk_bin_get_child (GTK_BIN (ep->data));
+
+ /* get a list of all rows in the box */
+ rows = gtk_container_get_children (GTK_CONTAINER (box));
+
+ /* iterate over all these rows */
+ for (rp = rows; rp != NULL; rp = rp->next)
+ {
+ /* call the foreach func */
+ (func) (view, THUNAR_SHORTCUT_ROW (rp->data), user_data);
+ }
+
+ /* free the list of rows */
+ g_list_free (rows);
+ }
+
+ /* free the list of expanders */
+ g_list_free (expanders);
+}
+
+
+
+static void
+thunar_shortcuts_view_unselect_rows (ThunarShortcutsView *view,
+ ThunarShortcutRow *row,
+ gpointer user_data)
+{
+ ThunarShortcutRow *selected_row = THUNAR_SHORTCUT_ROW (user_data);
+
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (selected_row));
+
+ /* reset the row state if it is not the selected row */
+ if (row != selected_row)
+ gtk_widget_set_state (GTK_WIDGET (row), GTK_STATE_NORMAL);
+}
+
+
+
+static void
thunar_shortcuts_view_open (ThunarShortcutsView *view,
ThunarFile *file,
gboolean new_window)
More information about the Xfce4-commits
mailing list