[Xfce4-commits] <xfce4-settings:master> Fix scroll to item.

Nick Schermer noreply at xfce.org
Fri Jan 27 21:14:01 CET 2012


Updating branch refs/heads/master
         to 1194e0ea0a51012c731afe6777e1e41548517a9a (commit)
       from 12be6f57f480ed5cc55f0146fa3a67776d5255ac (commit)

commit 1194e0ea0a51012c731afe6777e1e41548517a9a
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Jan 27 21:12:29 2012 +0100

    Fix scroll to item.
    
    Was not working properly with mouse event, so only
    response to keyboard event.

 .../xfce-settings-manager-dialog.c                 |   39 ++++++++++++++++----
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/xfce4-settings-manager/xfce-settings-manager-dialog.c b/xfce4-settings-manager/xfce-settings-manager-dialog.c
index 2c3c3fd..17c91ce 100644
--- a/xfce4-settings-manager/xfce-settings-manager-dialog.c
+++ b/xfce4-settings-manager/xfce-settings-manager-dialog.c
@@ -125,6 +125,8 @@ static void     xfce_settings_manager_dialog_entry_clear     (GtkWidget
                                                               GtkEntryIconPosition       icon_pos,
                                                               GdkEvent                  *event);
 static void     xfce_settings_manager_dialog_menu_reload     (XfceSettingsManagerDialog *dialog);
+static void     xfce_settings_manager_dialog_scroll_to_item  (GtkWidget                 *iconview,
+                                                              XfceSettingsManagerDialog *dialog);
 
 
 
@@ -466,6 +468,7 @@ xfce_settings_manager_dialog_iconview_keynav_failed (ExoIconView               *
             {
                 /* move cursor, grab-focus will handle the selection */
                 exo_icon_view_set_cursor (new_view, sel_path, NULL, FALSE);
+                xfce_settings_manager_dialog_scroll_to_item (GTK_WIDGET (new_view), dialog);
                 gtk_tree_path_free (sel_path);
 
                 gtk_widget_grab_focus (GTK_WIDGET (new_view));
@@ -542,6 +545,7 @@ xfce_settings_manager_dialog_iconview_focus (GtkWidget                 *iconview
         {
            path = gtk_tree_path_new_from_indices (0, -1);
            exo_icon_view_set_cursor (EXO_ICON_VIEW (iconview), path, NULL, FALSE);
+           xfce_settings_manager_dialog_scroll_to_item (iconview, dialog);
         }
 
         exo_icon_view_select_path (EXO_ICON_VIEW (iconview), path);
@@ -920,24 +924,24 @@ xfce_settings_manager_dialog_filter_category (GtkTreeModel *model,
 
 
 static void
-xfce_settings_manager_dialog_selection_changed (ExoIconView               *iconview,
-                                                XfceSettingsManagerDialog *dialog)
+xfce_settings_manager_dialog_scroll_to_item (GtkWidget                 *iconview,
+                                             XfceSettingsManagerDialog *dialog)
 {
-    GtkAllocation *alloc = &GTK_WIDGET (iconview)->allocation;
+    GtkAllocation *alloc;
     GtkTreePath   *path;
     gint           row, row_height;
     gdouble        rows;
     GtkAdjustment *adjustment;
     gdouble        lower, upper;
 
-    if (gtk_widget_has_focus (GTK_WIDGET (iconview))
-        && exo_icon_view_get_cursor (iconview, &path, NULL))
+    if (exo_icon_view_get_cursor (EXO_ICON_VIEW (iconview), &path, NULL))
     {
         /* get item row */
-        row = exo_icon_view_get_item_row (iconview, path);
+        row = exo_icon_view_get_item_row (EXO_ICON_VIEW (iconview), path);
         gtk_tree_path_free (path);
 
         /* estinated row height */
+        alloc = &iconview->allocation;
         rows = alloc->height / 56;
         row_height = alloc->height / MAX (1.0, (gint) rows);
 
@@ -954,6 +958,25 @@ xfce_settings_manager_dialog_selection_changed (ExoIconView               *iconv
 
 
 static gboolean
+xfce_settings_manager_dialog_key_press_event (GtkWidget                 *iconview,
+                                              GdkEventKey               *event,
+                                              XfceSettingsManagerDialog *dialog)
+{
+    gboolean result;
+
+    /* let exo handle the selection first */
+    result = GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (iconview))->key_press_event (iconview, event);
+
+    /* make sure the selected item is visible */
+    if (result)
+        xfce_settings_manager_dialog_scroll_to_item (iconview, dialog);
+
+    return result;
+}
+
+
+
+static gboolean
 xfce_settings_manager_start_search (GtkWidget                 *iconview,
                                     XfceSettingsManagerDialog *dialog)
 {
@@ -1046,8 +1069,8 @@ xfce_settings_manager_dialog_add_category (XfceSettingsManagerDialog *dialog,
         G_CALLBACK (xfce_settings_manager_dialog_iconview_keynav_failed), dialog);
     g_signal_connect (G_OBJECT (iconview), "item-activated",
         G_CALLBACK (xfce_settings_manager_dialog_item_activated), dialog);
-    g_signal_connect (G_OBJECT (iconview), "selection-changed",
-        G_CALLBACK (xfce_settings_manager_dialog_selection_changed), dialog);
+    g_signal_connect (G_OBJECT (iconview), "key-press-event",
+        G_CALLBACK (xfce_settings_manager_dialog_key_press_event), dialog);
     g_signal_connect (G_OBJECT (iconview), "start-interactive-search",
         G_CALLBACK (xfce_settings_manager_start_search), dialog);
 


More information about the Xfce4-commits mailing list