From 5b80fbd659cd964a59bd8a07ebf09616569608c3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 20 Jun 2003 12:19:44 +0000 Subject: Rewrite the url typed by user overwrite logic to fix bugs. 2003-06-20 Marco Pesenti Gritti * embed/mozilla/EphyWrapper.cpp: * lib/widgets/ephy-location-entry.c: (ephy_location_entry_class_init), (location_focus_out_cb), (ephy_location_entry_init), (insert_text_cb), (ephy_location_entry_key_press_event_cb), (ephy_location_entry_activate_cb), (ephy_location_entry_set_location), (ephy_location_entry_autocompletion_window_url_selected_cb), (ephy_location_entry_autocompletion_window_url_activated_cb), (ephy_location_entry_editable_changed_cb): * lib/widgets/ephy-location-entry.h: * src/ephy-shell.c: (ephy_shell_new_tab): * src/ephy-tab.c: (ephy_tab_set_property), (ephy_tab_set_link_message), (ephy_tab_set_window), (ephy_tab_address_cb), (ensure_address), (ephy_tab_net_state_cb), (ephy_tab_init), (ephy_tab_update_navigation_flags), (ephy_tab_set_location): * src/ephy-tab.h: * src/ephy-window.c: (ephy_window_notebook_switch_page_cb): * src/popup-commands.c: (get_event_info), (popup_cmd_copy_link_address): * src/toolbar.c: (get_location_entry), (location_user_changed_cb), (toolbar_set_window), (toolbar_activate_location), (toolbar_set_location), (toolbar_get_location), (toolbar_clear_location_history): * src/toolbar.h: Rewrite the url typed by user overwrite logic to fix bugs. --- lib/widgets/ephy-location-entry.c | 89 ++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 49 deletions(-) (limited to 'lib/widgets/ephy-location-entry.c') diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index f595b2140..9cd984b80 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -45,7 +45,7 @@ struct _EphyLocationEntryPrivate { gint show_alternatives_timeout; gboolean block_set_autocompletion_key; gboolean going_to_site; - gboolean editing; + gboolean user_changed; gchar *autocompletion_key; gchar *last_completion; @@ -104,6 +104,7 @@ static gpointer gtk_hbox_class; enum EphyLocationEntrySignalsEnum { ACTIVATED, FINISHED, + USER_CHANGED, LAST_SIGNAL }; static gint EphyLocationEntrySignals[LAST_SIGNAL]; @@ -141,13 +142,20 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass) 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, + G_STRUCT_OFFSET (EphyLocationEntryClass, user_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0, + G_TYPE_NONE); } static gboolean location_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EphyLocationEntry *w) { - w->priv->editing = FALSE; - g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0); return FALSE; @@ -159,8 +167,8 @@ ephy_location_entry_init (EphyLocationEntry *w) EphyLocationEntryPrivate *p = g_new0 (EphyLocationEntryPrivate, 1); w->priv = p; p->last_action_target = NULL; - p->editing = FALSE; p->before_completion = NULL; + p->user_changed = TRUE; ephy_location_entry_build (w); @@ -354,27 +362,6 @@ position_is_at_end (GtkEditable *editable) return gtk_editable_get_position (editable) == end; } -static void -real_entry_set_location (EphyLocationEntry *w, - const gchar *new_location) -{ - EphyLocationEntryPrivate *p = w->priv; - int pos; - - g_signal_handlers_block_by_func (G_OBJECT (p->entry), - delete_text_cb, w); - gtk_editable_delete_text (GTK_EDITABLE (p->entry), 0, -1); - g_signal_handlers_unblock_by_func (G_OBJECT (p->entry), - delete_text_cb, w); - - g_signal_handlers_block_by_func (G_OBJECT (p->entry), - insert_text_cb, w); - gtk_editable_insert_text (GTK_EDITABLE (p->entry), new_location, strlen(new_location), - &pos); - g_signal_handlers_unblock_by_func (G_OBJECT (p->entry), - insert_text_cb, w); -} - static void delete_text_cb (GtkWidget *editable, int start_pos, @@ -405,7 +392,6 @@ insert_text_cb (GtkWidget *editable, p->show_alternatives_timeout = 0; } - w->priv->editing = TRUE; ephy_location_entry_autocompletion_unselect_alternatives (w); if (position_is_at_end (GTK_EDITABLE (editable))) { @@ -427,7 +413,7 @@ ephy_location_entry_key_press_event_cb (GtkWidget *entry, GdkEventKey *event, Ep ephy_location_entry_autocompletion_hide_alternatives (w); return FALSE; case GDK_Escape: - real_entry_set_location (w, p->before_completion); + ephy_location_entry_set_location (w, p->before_completion); gtk_editable_set_position (GTK_EDITABLE (p->entry), -1); ephy_location_entry_autocompletion_hide_alternatives (w); return FALSE; @@ -470,8 +456,6 @@ ephy_location_entry_activate_cb (GtkEntry *entry, EphyLocationEntry *w) LOG ("In ephy_location_entry_activate_cb, activating %s", content) - w->priv->editing = FALSE; - g_signal_emit (w, EphyLocationEntrySignals[ACTIVATED], 0, content, target); g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0); @@ -500,10 +484,25 @@ void ephy_location_entry_set_location (EphyLocationEntry *w, const gchar *new_location) { - if (!w->priv->editing) - { - real_entry_set_location (w, new_location); - } + EphyLocationEntryPrivate *p = w->priv; + int pos; + + p->user_changed = FALSE; + + g_signal_handlers_block_by_func (G_OBJECT (p->entry), + delete_text_cb, w); + gtk_editable_delete_text (GTK_EDITABLE (p->entry), 0, -1); + g_signal_handlers_unblock_by_func (G_OBJECT (p->entry), + delete_text_cb, w); + + g_signal_handlers_block_by_func (G_OBJECT (p->entry), + insert_text_cb, w); + gtk_editable_insert_text (GTK_EDITABLE (p->entry), new_location, strlen(new_location), + &pos); + g_signal_handlers_unblock_by_func (G_OBJECT (p->entry), + insert_text_cb, w); + + p->user_changed = TRUE; } gchar * @@ -521,11 +520,11 @@ ephy_location_entry_autocompletion_window_url_selected_cb (EphyAutocompletionWin { if (target) { - real_entry_set_location (w, action ? w->priv->before_completion : target); + ephy_location_entry_set_location (w, action ? w->priv->before_completion : target); } else { - real_entry_set_location (w, w->priv->before_completion); + ephy_location_entry_set_location (w, w->priv->before_completion); gtk_editable_set_position (GTK_EDITABLE (w->priv->entry), -1); } } @@ -589,7 +588,7 @@ ephy_location_entry_autocompletion_window_url_activated_cb (EphyAutocompletionWi } else { - real_entry_set_location (w, target); + ephy_location_entry_set_location (w, target); } content = gtk_editable_get_chars (GTK_EDITABLE(w->priv->entry), 0, -1); @@ -627,19 +626,6 @@ ephy_location_entry_autocompletion_window_hidden_cb (EphyAutocompletionWindow *a } } -void -ephy_location_entry_edit (EphyLocationEntry *w) -{ - GtkWidget *toplevel; - - w->priv->editing = TRUE; - - toplevel = gtk_widget_get_toplevel (w->priv->entry); - - gtk_window_set_focus (GTK_WINDOW(toplevel), - w->priv->entry); -} - void ephy_location_entry_activate (EphyLocationEntry *w) { @@ -683,6 +669,11 @@ ephy_location_entry_editable_changed_cb (GtkEditable *editable, EphyLocationEntr g_free (url); } } + + if (p->user_changed) + { + g_signal_emit (e, EphyLocationEntrySignals[USER_CHANGED], 0); + } } static void -- cgit v1.2.3