From 68616208eeeee369e62c9256fc9aba5dbe139e3e Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 20 Sep 2003 09:37:26 +0000 Subject: Remember the address in the location action, so we can restore it when we 2003-09-20 Christian Persch * lib/widgets/ephy-location-entry.c: (ephy_location_entry_class_init), (ephy_location_entry_activation_finished), (location_focus_out_cb), (ephy_location_entry_init), (ephy_location_ignore_prefix), (ephy_location_entry_activate_cb), (ephy_location_entry_set_location), (ephy_location_entry_get_location), (ephy_location_entry_activate), (ephy_location_entry_editable_changed_cb), (ephy_location_entry_clear_history): * lib/widgets/ephy-location-entry.h: * src/ephy-location-action.c: (location_url_activate_cb), (user_changed_cb), (sync_address), (connect_proxy), (disconnect_proxy), (ephy_location_action_set_property), (ephy_location_action_get_property), (ephy_location_action_activate), (ephy_location_action_class_init), (ephy_location_action_init), (ephy_location_action_finalize), (ephy_location_action_get_address), (ephy_location_action_set_address), (clear_history), (ephy_location_action_clear_history): * src/ephy-location-action.h: * src/toolbar.c: (toolbar_class_init), (toolbar_set_property), (sync_user_input_cb), (toolbar_setup_actions), (toolbar_set_window), (toolbar_init), (toolbar_finalize), (toolbar_new), (toolbar_activate_location), (toolbar_set_location), (toolbar_get_location), (toolbar_clear_location_history): * src/toolbar.h: * src/window-commands.c: (window_cmd_load_location): Remember the address in the location action, so we can restore it when we get a new proxy widget. Do some misc cleanups on location entry, removing finished signal; move activation from toolbar into location entry. --- lib/widgets/ephy-location-entry.c | 62 ++++++++++++++++++++++++--------------- lib/widgets/ephy-location-entry.h | 7 +++-- 2 files changed, 43 insertions(+), 26 deletions(-) (limited to 'lib/widgets') diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index 0f2fb663b..e7b30f867 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2002 Ricardo Fernández Pascual + * Copyright (C) 2003 Marco Pesenti Gritti * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify @@ -32,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +55,7 @@ struct _EphyLocationEntryPrivate { gboolean block_set_autocompletion_key; gboolean going_to_site; gboolean user_changed; + gboolean activation_mode; char *autocompletion_key; char *last_action_target; @@ -111,7 +114,6 @@ static GObjectClass *parent_class = NULL; */ enum EphyLocationEntrySignalsEnum { ACTIVATED, - FINISHED, USER_CHANGED, LAST_SIGNAL }; @@ -184,15 +186,6 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass) 2, G_TYPE_STRING, G_TYPE_STRING); - EphyLocationEntrySignals[FINISHED] = g_signal_new ( - "finished", G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP, - G_STRUCT_OFFSET (EphyLocationEntryClass, finished), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0, - G_TYPE_NONE); EphyLocationEntrySignals[USER_CHANGED] = g_signal_new ( "user_changed", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP, @@ -206,10 +199,25 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass) g_type_class_add_private (object_class, sizeof (EphyLocationEntryPrivate)); } +static void +ephy_location_entry_activation_finished (EphyLocationEntry *entry) +{ + if (entry->priv->activation_mode) + { + GtkWidget *toolbar; + + entry->priv->activation_mode = FALSE; + + toolbar = gtk_widget_get_ancestor (GTK_WIDGET (entry), + GTK_TYPE_TOOLBAR); + gtk_widget_hide (toolbar); + } +} + static gboolean location_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EphyLocationEntry *w) { - g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0); + ephy_location_entry_activation_finished (w); return FALSE; } @@ -227,6 +235,7 @@ ephy_location_entry_init (EphyLocationEntry *w) p->last_action_target = NULL; p->before_completion = NULL; p->user_changed = TRUE; + p->activation_mode = FALSE; p->autocompletion_key = NULL; ephy_location_entry_construct_contents (w); @@ -325,7 +334,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *w) static gboolean ephy_location_ignore_prefix (EphyLocationEntry *w) { - char *text; + const char *text; int text_len; int i, k; gboolean result = FALSE; @@ -335,6 +344,8 @@ ephy_location_ignore_prefix (EphyLocationEntry *w) }; text = ephy_location_entry_get_location (w); + g_return_val_if_fail (text != NULL, FALSE); + text_len = g_utf8_strlen (text, -1); for (i = 0; prefixes[i] != NULL; i++) @@ -351,8 +362,6 @@ ephy_location_ignore_prefix (EphyLocationEntry *w) } } - g_free (text); - return result; } @@ -550,7 +559,7 @@ ephy_location_entry_activate_cb (GtkEntry *entry, EphyLocationEntry *w) LOG ("In ephy_location_entry_activate_cb, activating %s", content) g_signal_emit (w, EphyLocationEntrySignals[ACTIVATED], 0, content, target); - g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0); + ephy_location_entry_activation_finished (w); g_free (content); g_free (target); @@ -580,6 +589,8 @@ ephy_location_entry_set_location (EphyLocationEntry *w, EphyLocationEntryPrivate *p = w->priv; int pos; + g_return_if_fail (new_location != NULL); + p->user_changed = FALSE; g_signal_handlers_block_by_func (G_OBJECT (p->entry), @@ -598,11 +609,10 @@ ephy_location_entry_set_location (EphyLocationEntry *w, p->user_changed = TRUE; } -gchar * +const char * ephy_location_entry_get_location (EphyLocationEntry *w) { - char *location = gtk_editable_get_chars (GTK_EDITABLE (w->priv->entry), 0, -1); - return location; + return gtk_entry_get_text (GTK_ENTRY (w->priv->entry)); } static void @@ -717,7 +727,16 @@ ephy_location_entry_autocompletion_window_hidden_cb (EphyAutocompletionWindow *a void ephy_location_entry_activate (EphyLocationEntry *w) { - GtkWidget *toplevel; + GtkWidget *toplevel, *toolbar; + + toolbar = gtk_widget_get_ancestor (GTK_WIDGET (w), GTK_TYPE_TOOLBAR); + + if (!GTK_WIDGET_VISIBLE (toolbar)) + { + w->priv->activation_mode = TRUE; + + gtk_widget_show (toolbar); + } toplevel = gtk_widget_get_toplevel (w->priv->entry); @@ -727,7 +746,6 @@ ephy_location_entry_activate (EphyLocationEntry *w) w->priv->entry); } - static void ephy_location_entry_list_event_after_cb (GtkWidget *list, GdkEvent *event, @@ -749,13 +767,12 @@ ephy_location_entry_editable_changed_cb (GtkEditable *editable, EphyLocationEntr if (p->going_to_site) { - char *url = ephy_location_entry_get_location (e); + const char *url = ephy_location_entry_get_location (e); if (url && url[0] != '\0') { p->going_to_site = FALSE; g_signal_emit (e, EphyLocationEntrySignals[ACTIVATED], 0, NULL, url); } - g_free (url); } if (p->user_changed) @@ -786,4 +803,3 @@ ephy_location_entry_clear_history (EphyLocationEntry *w) { gnome_entry_clear_history (GNOME_ENTRY (w->priv->combo)); } - diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h index 8af364cd7..e4ad695d8 100644 --- a/lib/widgets/ephy-location-entry.h +++ b/lib/widgets/ephy-location-entry.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2002 Ricardo Fernández Pascual + * Copyright (C) 2003 Marco Pesenti Gritti * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify @@ -15,6 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ #ifndef EPHY_LOCATION_ENTRY_H @@ -53,8 +56,6 @@ struct _EphyLocationEntryClass const char *content, const char *target); - void (*finished) (EphyLocationEntry *w); - void (*user_changed) (EphyLocationEntry *w); }; @@ -70,7 +71,7 @@ GType ephy_location_entry_get_type (void); GtkWidget *ephy_location_entry_new (void); void ephy_location_entry_set_location (EphyLocationEntry *w, const gchar *new_location); -gchar *ephy_location_entry_get_location (EphyLocationEntry *w); +const char *ephy_location_entry_get_location (EphyLocationEntry *w); void ephy_location_entry_set_autocompletion (EphyLocationEntry *w, EphyAutocompletion *ac); void ephy_location_entry_activate (EphyLocationEntry *w); -- cgit v1.2.3