[gtk+] bgo#580560 - Make Backspace work in the file chooser to to to the parent directory



commit 2b3de3dd75384a0af99f92656cdd70d72319ca6c
Author: Federico Mena Quintero <federico novell com>
Date:   Mon Jun 15 12:37:07 2009 -0500

    bgo#580560 - Make Backspace work in the file chooser to to to the parent directory
    
    GtkFileChooserDefault actually implements a binding signal for
    Backspace, to make it go to the parent directory.  However,
    GtkTreeView was eating our Backspace, and thus the file chooser was
    not getting a chance to execute its binding signal.
    
    GtkTreeView implements a Backspace binding itself, which it uses to
    move to the parent node of the current cursor node.  However, the
    binding handler would return TRUE even if there was no parent to the
    current node.  Now the binding handler only returns TRUE if it
    actually changed the cursor.
    
    Additionally, gtk_tree_view_key_press() sees if no bindings handled a
    key press; in that case, it re-sends the key press to the treeview's
    search entry.  However, sending a Backspace to an empty entry makes
    the entry beep.  Thus, we add a flag that gets set from GtkTreeView's
    Backspace binding handler, to tell gtk_tree_view_key_press() when it
    should *not* re-emit the key press on the search entry.  Sort of,
    "yeah, I didn't handle this key press, but I don't want you to send it
    to the search entry, either!".
    
    Signed-off-by: Federico Mena Quintero <federico novell com>

 gtk/gtktreeprivate.h |    2 ++
 gtk/gtktreeview.c    |   43 +++++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 384c176..44259ab 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -238,6 +238,8 @@ struct _GtkTreeViewPrivate
 
   guint post_validation_flag : 1;
 
+  /* Whether our key press handler is to avoid sending an unhandled binding to the search entry */
+  guint search_entry_avoid_unhandled_binding : 1;
 
   /* Auto expand/collapse timeout in hover mode */
   guint auto_expand_timeout;
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index caa517c..cfe1a14 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -5377,6 +5377,12 @@ gtk_tree_view_key_press (GtkWidget   *widget,
   if (GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->key_press_event (widget, event))
     return TRUE;
 
+  if (tree_view->priv->search_entry_avoid_unhandled_binding)
+    {
+      tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
+      return FALSE;
+    }
+
   /* We pass the event to the search_entry.  If its text changes, then we start
    * the typeahead find capabilities. */
   if (GTK_WIDGET_HAS_FOCUS (tree_view)
@@ -10231,27 +10237,21 @@ gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
   GdkModifierType state;
 
   if (! GTK_WIDGET_HAS_FOCUS (tree_view))
-    return FALSE;
+    goto out;
 
   cursor_path = NULL;
   if (tree_view->priv->cursor)
     cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
 
   if (cursor_path == NULL)
-    return FALSE;
+    goto out;
 
   _gtk_tree_view_find_node (tree_view, cursor_path,
 			    &cursor_tree, &cursor_node);
   if (cursor_tree == NULL)
     {
       gtk_tree_path_free (cursor_path);
-      return FALSE;
-    }
-
-  if (gtk_get_current_event_state (&state))
-    {
-      if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
-        tree_view->priv->ctrl_pressed = TRUE;
+      goto out;
     }
 
   if (cursor_tree->parent_node)
@@ -10262,19 +10262,30 @@ gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
 
       gtk_tree_path_up (cursor_path);
 
+      if (gtk_get_current_event_state (&state))
+	{
+	  if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+	    tree_view->priv->ctrl_pressed = TRUE;
+	}
+
       gtk_tree_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
-    }
+      gtk_tree_view_clamp_node_visible (tree_view, cursor_tree, cursor_node);
 
-  gtk_tree_view_clamp_node_visible (tree_view, cursor_tree, cursor_node);
+      gtk_widget_grab_focus (GTK_WIDGET (tree_view));
+      gtk_tree_view_queue_draw_path (tree_view, cursor_path, NULL);
+      gtk_tree_path_free (cursor_path);
 
-  gtk_widget_grab_focus (GTK_WIDGET (tree_view));
-  gtk_tree_view_queue_draw_path (tree_view, cursor_path, NULL);
-  gtk_tree_path_free (cursor_path);
+      tree_view->priv->ctrl_pressed = FALSE;
 
-  tree_view->priv->ctrl_pressed = FALSE;
+      return TRUE;
+    }
 
-  return TRUE;
+ out:
+
+  tree_view->priv->search_entry_avoid_unhandled_binding = TRUE;
+  return FALSE;
 }
+
 static gboolean
 gtk_tree_view_search_entry_flush_timeout (GtkTreeView *tree_view)
 {



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