[nautilus] Update the location bar and dialog to the new API.



commit 54b044b9eaa3614498bf4a56ea915ff3a46f5e6d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 7 15:33:36 2010 +0200

    Update the location bar and dialog to the new API.
    
    This also fixes bug #346422. Thanks to Amos Brocco for the initial
    patch.

 src/nautilus-location-bar.c    |   29 +++--------------------------
 src/nautilus-location-dialog.c |   24 ++++++++++++------------
 2 files changed, 15 insertions(+), 38 deletions(-)
---
diff --git a/src/nautilus-location-bar.c b/src/nautilus-location-bar.c
index 52a618d..ca57e3d 100644
--- a/src/nautilus-location-bar.c
+++ b/src/nautilus-location-bar.c
@@ -281,28 +281,6 @@ label_button_pressed_callback (GtkWidget             *widget,
 	return FALSE;
 }
 
-static int
-get_editable_number_of_chars (GtkEditable *editable)
-{
-	char *text;
-	int length;
-
-	text = gtk_editable_get_chars (editable, 0, -1);
-	length = g_utf8_strlen (text, -1);
-	g_free (text);
-	return length;
-}
-
-static void
-set_position_and_selection_to_end (GtkEditable *editable)
-{
-	int end;
-
-	end = get_editable_number_of_chars (editable);
-	gtk_editable_select_region (editable, end, end);
-	gtk_editable_set_position (editable, end);
-}
-
 static void
 editable_activate_callback (GtkEntry *entry,
 			    gpointer user_data)
@@ -428,7 +406,7 @@ nautilus_location_bar_init (NautilusLocationBar *bar)
 	entry = nautilus_location_entry_new ();
 	
 	g_signal_connect_object (entry, "activate",
-				 G_CALLBACK (editable_activate_callback), bar, 0);
+				 G_CALLBACK (editable_activate_callback), bar, G_CONNECT_AFTER);
 	g_signal_connect_object (entry, "changed",
 				 G_CALLBACK (editable_changed_callback), bar, 0);
 
@@ -505,9 +483,8 @@ nautilus_location_bar_set_location (NautilusNavigationBar *navigation_bar,
 		file = g_file_new_for_uri (location);
 		formatted_location = g_file_get_parse_name (file);
 		g_object_unref (file);
-		nautilus_entry_set_text (NAUTILUS_ENTRY (bar->details->entry),
-					 formatted_location);
-		set_position_and_selection_to_end (GTK_EDITABLE (bar->details->entry));
+		nautilus_location_entry_update_current_location (NAUTILUS_LOCATION_ENTRY (bar->details->entry),
+								 formatted_location);
 		g_free (formatted_location);
 	}
 
diff --git a/src/nautilus-location-dialog.c b/src/nautilus-location-dialog.c
index 2a1f502..ce38466 100644
--- a/src/nautilus-location-dialog.c
+++ b/src/nautilus-location-dialog.c
@@ -180,10 +180,10 @@ nautilus_location_dialog_init (NautilusLocationDialog *dialog)
 	
 	dialog->details->entry = nautilus_location_entry_new ();
         gtk_entry_set_width_chars (GTK_ENTRY (dialog->details->entry), 30);
-	g_signal_connect (dialog->details->entry,
-			  "activate", 
-			  G_CALLBACK (entry_activate_callback),
-			  dialog);
+	g_signal_connect_after (dialog->details->entry,
+				"activate",
+				G_CALLBACK (entry_activate_callback),
+				dialog);
 	
 	gtk_widget_show (dialog->details->entry);
 	
@@ -219,17 +219,19 @@ GtkWidget *
 nautilus_location_dialog_new (NautilusWindow *window)
 {
 	NautilusWindowSlot *slot;
+	NautilusLocationDialog *loc_dialog;
 	GtkWidget *dialog;
 	GFile *location;
 	char *formatted_location;
 	
 	dialog = gtk_widget_new (NAUTILUS_TYPE_LOCATION_DIALOG, NULL);
+	loc_dialog = NAUTILUS_LOCATION_DIALOG (dialog);
 
 	if (window) {
 		gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
 		gtk_window_set_screen (GTK_WINDOW (dialog),
 				       gtk_window_get_screen (GTK_WINDOW (window)));
-		NAUTILUS_LOCATION_DIALOG (dialog)->details->window = window;
+		loc_dialog->details->window = window;
 	}
 
 	slot = window->details->active_pane->active_slot;
@@ -241,13 +243,12 @@ nautilus_location_dialog_new (NautilusWindow *window)
 		} else {
 			formatted_location = g_file_get_parse_name (location);
 		}
-		nautilus_entry_set_text (NAUTILUS_ENTRY (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), formatted_location);
-		gtk_editable_select_region (GTK_EDITABLE (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), 0, -1);
-		gtk_editable_set_position (GTK_EDITABLE (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), -1);
+		nautilus_location_entry_update_current_location (NAUTILUS_LOCATION_ENTRY (loc_dialog->details->entry),
+								 formatted_location);
 		g_free (formatted_location);
 	}
 	
-	gtk_widget_grab_focus (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry);
+	gtk_widget_grab_focus (loc_dialog->details->entry);
 
 	return dialog;
 }
@@ -256,7 +257,6 @@ void
 nautilus_location_dialog_set_location (NautilusLocationDialog *dialog,
 				       const char *location)
 {
-	nautilus_entry_set_text (NAUTILUS_ENTRY (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), location);
-	gtk_editable_select_region (GTK_EDITABLE (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), 0, 0);
-	gtk_editable_set_position (GTK_EDITABLE (NAUTILUS_LOCATION_DIALOG (dialog)->details->entry), -1);
+	nautilus_location_entry_update_current_location (NAUTILUS_LOCATION_ENTRY (dialog->details->entry),
+							 location);
 }



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