[PATCH] Bind "escape" in temporary showing location entry to hiding of location bar



Bug 311652 [1] complains that there is no obvious way to switch back
from the location bar to the path bar. The attached patch makes Nautilus
switch back to the path bar when the user presses escape in the location
bar.

-- 
Christian Neumair <chris gnome-de org>
Index: src/nautilus-location-bar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-location-bar.c,v
retrieving revision 1.107
diff -u -p -r1.107 nautilus-location-bar.c
--- src/nautilus-location-bar.c	2 Jun 2005 16:16:55 -0000	1.107
+++ src/nautilus-location-bar.c	28 Jul 2005 18:47:08 -0000
@@ -330,6 +330,15 @@ real_activate (NautilusNavigationBar *na
 }
 
 static void
+real_cancel (NautilusNavigationBar *navigation_bar)
+{
+	char *last_location;
+
+	last_location = NAUTILUS_LOCATION_BAR (navigation_bar)->details->last_location;
+	nautilus_navigation_bar_set_location (navigation_bar, last_location);
+}
+
+static void
 finalize (GObject *object)
 {
 	NautilusLocationBar *bar;
@@ -384,6 +393,7 @@ nautilus_location_bar_class_init (Nautil
 	navigation_bar_class = NAUTILUS_NAVIGATION_BAR_CLASS (class);
 
 	navigation_bar_class->activate = real_activate;
+	navigation_bar_class->cancel = real_cancel;
 	navigation_bar_class->get_location = nautilus_location_bar_get_location;
 	navigation_bar_class->set_location = nautilus_location_bar_set_location;
 }
@@ -503,8 +513,11 @@ nautilus_location_bar_set_location (Naut
 	
 	/* remember the original location for later comparison */
 	
-	g_free (bar->details->last_location);
-	bar->details->last_location = g_strdup (location);
+	if (bar->details->last_location != location) {
+		g_free (bar->details->last_location);
+		bar->details->last_location = g_strdup (location);
+	}
+
 	nautilus_location_bar_update_label (bar);
 }
 
Index: src/nautilus-navigation-bar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-bar.c,v
retrieving revision 1.19
diff -u -p -r1.19 nautilus-navigation-bar.c
--- src/nautilus-navigation-bar.c	3 Jan 2004 18:34:40 -0000	1.19
+++ src/nautilus-navigation-bar.c	28 Jul 2005 18:47:09 -0000
@@ -30,11 +30,14 @@
 #include "nautilus-navigation-bar.h"
 
 #include <eel/eel-gtk-macros.h>
+#include <gdk/gdkkeysyms.h>
 #include <gtk/gtksignal.h>
+#include <gtk/gtkbindings.h>
 #include <string.h>
 
 enum {
 	ACTIVATE,
+	CANCEL,
 	LOCATION_CHANGED,
 	LAST_SIGNAL
 };
@@ -52,6 +55,7 @@ static void
 nautilus_navigation_bar_class_init (NautilusNavigationBarClass *klass)
 {
 	GtkObjectClass *object_class;
+	GtkBindingSet *binding_set;
 
 	object_class = GTK_OBJECT_CLASS (klass);
 	
@@ -65,6 +69,16 @@ nautilus_navigation_bar_class_init (Naut
 		 g_cclosure_marshal_VOID__VOID,
 		 G_TYPE_NONE, 0);
 
+	signals[CANCEL] = g_signal_new
+		("cancel",
+		 G_TYPE_FROM_CLASS (object_class),
+		 G_SIGNAL_RUN_LAST | GTK_RUN_ACTION,
+		 G_STRUCT_OFFSET (NautilusNavigationBarClass,
+				    cancel),
+		 NULL, NULL,
+		 g_cclosure_marshal_VOID__VOID,
+		 G_TYPE_NONE, 0);
+
 	signals[LOCATION_CHANGED] = g_signal_new
 		("location_changed",
 		 G_TYPE_FROM_CLASS (object_class),
@@ -76,6 +90,10 @@ nautilus_navigation_bar_class_init (Naut
 		 G_TYPE_NONE, 1, G_TYPE_STRING);
 
 	klass->activate = NULL;
+	klass->cancel = NULL;
+
+	binding_set = gtk_binding_set_by_class (klass);
+	gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "cancel", 0);
 
 	EEL_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_navigation_bar, get_location);
 	EEL_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_navigation_bar, set_location);
Index: src/nautilus-navigation-bar.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-bar.h,v
retrieving revision 1.8
diff -u -p -r1.8 nautilus-navigation-bar.h
--- src/nautilus-navigation-bar.h	3 Jan 2004 18:34:41 -0000	1.8
+++ src/nautilus-navigation-bar.h	28 Jul 2005 18:47:09 -0000
@@ -49,6 +49,7 @@ typedef struct {
 	/* signals */
 	void         (* location_changed) (NautilusNavigationBar *bar,
 					   const char            *location);
+	void         (* cancel)           (NautilusNavigationBar *bar);
 
 	/* virtual methods */
 	void	     (* activate)	  (NautilusNavigationBar *bar);
Index: src/nautilus-navigation-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-window.c,v
retrieving revision 1.437
diff -u -p -r1.437 nautilus-navigation-window.c
--- src/nautilus-navigation-window.c	23 Jul 2005 17:41:03 -0000	1.437
+++ src/nautilus-navigation-window.c	28 Jul 2005 18:47:09 -0000
@@ -112,6 +112,8 @@ static void side_panel_image_changed_cal
 static void navigation_bar_location_changed_callback (GtkWidget                *widget,
 						      const char               *uri,
 						      NautilusNavigationWindow *window);
+static void navigation_bar_cancel_callback           (GtkWidget                *widget,
+						      NautilusNavigationWindow *window);
 static void path_bar_location_changed_callback       (GtkWidget                *widget,
 						      const char               *uri,
 						      NautilusNavigationWindow *window);
@@ -196,6 +198,8 @@ nautilus_navigation_window_instance_init
 	window->navigation_bar = nautilus_location_bar_new (window);
 	g_signal_connect_object (window->navigation_bar, "location_changed",
 				 G_CALLBACK (navigation_bar_location_changed_callback), window, 0);
+	g_signal_connect_object (window->navigation_bar, "cancel",
+				 G_CALLBACK (navigation_bar_cancel_callback), window, 0);
 
 	gtk_box_pack_start (GTK_BOX (hbox),
 			    window->navigation_bar,
@@ -313,11 +317,8 @@ path_bar_location_changed_callback (GtkW
 	}
 }
 
-
 static void
-navigation_bar_location_changed_callback (GtkWidget *widget,
-					  const char *uri,
-					  NautilusNavigationWindow *window)
+hide_temporary_bars (NautilusNavigationWindow *window)
 {
 	g_assert (NAUTILUS_IS_NAVIGATION_WINDOW (window));
 
@@ -333,9 +334,22 @@ navigation_bar_location_changed_callback
 		}
 		window->details->temporary_navigation_bar = FALSE;
 	}
+}
 
-	
+static void
+navigation_bar_location_changed_callback (GtkWidget *widget,
+					  const char *uri,
+					  NautilusNavigationWindow *window)
+{
+	hide_temporary_bars (window);
 	nautilus_window_go_to (NAUTILUS_WINDOW (window), uri);
+}
+
+static void
+navigation_bar_cancel_callback (GtkWidget *widget,
+				NautilusNavigationWindow *window)
+{
+	hide_temporary_bars (window);
 }
 
 static void

Attachment: signature.asc
Description: This is a digitally signed message part



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