[Nautilus-list] [PATCH] location bar autocompletion
- From: David Emory Watson <dwatson cs ucr edu>
- To: nautilus-list lists eazel com
- Subject: [Nautilus-list] [PATCH] location bar autocompletion
- Date: Sat, 23 Feb 2002 15:51:15 -0800
This patch works, but is almost certainly wrong. I am still trying to
figure out the correct way to connect the editable_key_press_callback
(). I guess I don't really understand the comment about needing a
marshaled callback...
Note: if you want to try this code out before the real fix is committed
to CVS, you will need to apply the patch by hand since I edited it
(removed ws changes) to make it easier to read...
? components/image-viewer/Makefile
? components/image-viewer/Makefile.in
? components/image-viewer/Nautilus_View_image.server
? components/image-viewer/nautilus-image-view
Index: src/nautilus-location-bar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-location-bar.c,v
retrieving revision 1.81
diff -p -u -r1.81 nautilus-location-bar.c
--- src/nautilus-location-bar.c 2002/02/19 22:53:43 1.81
+++ src/nautilus-location-bar.c 2002/02/23 23:35:51
@@ -1,4 +1,3 @@
-
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
@@ -239,8 +237,6 @@ style_set_handler (GtkWidget *widget, Gt
#endif
}
-#if GNOME2_CONVERSION_COMPLETE
-
/* utility routine to determine the string to expand to. If we don't have anything yet, accept
the whole string, otherwise accept the largest part common to both */
@@ -301,13 +297,14 @@ try_to_expand_path (gpointer callback_da
GList *element;
GnomeVFSURI *uri;
GtkEditable *editable;
-
+
uint base_length;
int current_path_length;
int offset;
char *base_name_uri_escaped;
char *base_name;
char *user_location;
+ uint user_location_length;
char *current_path;
char *dir_name;
char *expand_text;
@@ -317,6 +314,7 @@ try_to_expand_path (gpointer callback_da
editable = GTK_EDITABLE (bar->details->entry);
user_location = gtk_editable_get_chars (editable, 0, -1);
+ user_location_length = strlen (user_location);
bar->details->idle_id = 0;
/* if it's just '~' or '~/', don't expand because slash shouldn't be appended */
@@ -383,15 +381,19 @@ try_to_expand_path (gpointer callback_da
g_free (expand_name);
}
}
-
- /* if we've got something, add it to the entry */
+
+ /* if we've got something, add it to the entry */
if (expand_text != NULL
&& !eel_str_has_suffix (current_path, expand_text)
&& base_length < strlen (expand_text)) {
- gtk_entry_append_text (GTK_ENTRY (editable), expand_text + base_length);
- gtk_entry_select_region (GTK_ENTRY (editable),
- current_path_length - offset,
- current_path_length - offset + strlen (expand_text) - base_length);
+ gtk_editable_insert_text (editable,
+ expand_text + base_length,
+ strlen (expand_text) - base_length,
+ &user_location_length);
+
+ gtk_editable_select_region (editable,
+ current_path_length - offset,
+ current_path_length - offset + strlen (expand_text) - base_length);
}
g_free (expand_text);
@@ -485,31 +487,21 @@ position_and_selection_are_at_end (GtkEd
return gtk_editable_get_position (editable) == end;
}
-/* Handle changes in the location entry. This is a marshal-style
- * callback so that we don't mess up the return value.
- */
-static void
-editable_key_press_callback (GtkObject *object,
- gpointer data,
- guint n_args,
- GtkArg *args)
+static gboolean
+editable_key_press_callback (gpointer data,
+ GdkEventKey *event,
+ GtkWidget *widget)
{
- GtkEditable *editable;
- GdkEventKey *event;
- gboolean *return_value_location;
+ GtkEntry *entry;
+ GtkEditable *editable;
NautilusLocationBar *bar;
const char *unexpanded_text;
char *expanded_text;
-
- g_assert (n_args == 1);
- g_assert (args != NULL);
+ entry = GTK_ENTRY (widget);
+ editable = GTK_EDITABLE (entry);
bar = NAUTILUS_LOCATION_BAR (data);
- editable = GTK_EDITABLE (object);
- event = GTK_VALUE_POINTER (args[0]);
- return_value_location = GTK_RETLOC_BOOL (args[1]);
-
/* After typing the right arrow key we move the selection to
* the end.
*/
@@ -530,8 +522,7 @@ editable_key_press_callback (GtkObject *
* when we type a key that would have inserted characters.
*/
if (position_and_selection_are_at_end (editable)) {
- if (*return_value_location
- && entry_would_have_inserted_characters (event)) {
+ if (entry_would_have_inserted_characters (event)) {
if (event->keyval == GDK_slash
&& has_exactly_one_slash (editable)) {
/* It's OK for us to call
@@ -563,8 +554,9 @@ editable_key_press_callback (GtkObject *
}
nautilus_location_bar_update_label (bar);
+
+ return FALSE;
}
-#endif
static void
real_activate (NautilusNavigationBar *navigation_bar)
@@ -672,38 +664,31 @@ nautilus_location_bar_init (NautilusLoca
G_CALLBACK (nautilus_navigation_bar_location_changed),
bar);
-#if GNOME2_CONVERSION_COMPLETE
- /* The callback uses the marshal interface directly
- * so it can both read and write the return value.
- */
- gtk_signal_connect_full (GTK_OBJECT (entry), "key_press_event",
- NULL, editable_key_press_callback,
- bar, NULL,
- FALSE, TRUE);
-#endif
-
+ g_signal_connect_swapped (entry, "key_press_event",
+ G_CALLBACK (editable_key_press_callback),
+ bar);
+
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (bar), hbox);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]