From b40f531dea45d3b365bd310536afddc32573caad Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 18 Jun 2003 18:06:02 +0000 Subject: Use insert_text delete_text to show/hide the autocompletion window. 2003-06-18 Marco Pesenti Gritti * lib/ephy-autocompletion.c: (ephy_autocompletion_refine_matches), (ephy_autocompletion_update_matches_full_item): * lib/widgets/ephy-location-entry.c: (ephy_location_entry_build), (ephy_location_entry_autocompletion_show_alternatives_to), (real_entry_set_location), (delete_text_cb), (insert_text_cb), (ephy_location_entry_key_press_event_cb), (ephy_location_entry_content_is_text), (ephy_location_entry_activate_cb): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_autocompletion_source_foreach): * src/ephy-location-action.c: (create_tool_item), (location_url_activate_cb): Use insert_text delete_text to show/hide the autocompletion window. Remember last search with autocompletion smart bookmarks. --- ChangeLog | 20 ++++++ lib/ephy-autocompletion.c | 26 +++++--- lib/widgets/ephy-location-entry.c | 125 +++++++++++++++++++++----------------- src/bookmarks/ephy-bookmarks.c | 2 +- src/ephy-location-action.c | 6 +- 5 files changed, 113 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 643f3f0cf..c4eaa79df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2003-06-18 Marco Pesenti Gritti + + * lib/ephy-autocompletion.c: (ephy_autocompletion_refine_matches), + (ephy_autocompletion_update_matches_full_item): + * lib/widgets/ephy-location-entry.c: (ephy_location_entry_build), + (ephy_location_entry_autocompletion_show_alternatives_to), + (real_entry_set_location), (delete_text_cb), (insert_text_cb), + (ephy_location_entry_key_press_event_cb), + (ephy_location_entry_content_is_text), + (ephy_location_entry_activate_cb): + * src/bookmarks/ephy-bookmarks.c: + (ephy_bookmarks_autocompletion_source_foreach): + * src/ephy-location-action.c: (create_tool_item), + (location_url_activate_cb): + + Use insert_text delete_text to show/hide the autocompletion + window. + Remember last search with autocompletion smart bookmarks. + + 2003-06-18 Marco Pesenti Gritti * src/ephy-history-window.c: (confirmation_dialog_construct): diff --git a/lib/ephy-autocompletion.c b/lib/ephy-autocompletion.c index e8fefdf4a..6744512b4 100644 --- a/lib/ephy-autocompletion.c +++ b/lib/ephy-autocompletion.c @@ -293,8 +293,8 @@ ephy_autocompletion_refine_matches (EphyAutocompletion *ac) EphyAutocompletionMatch *mi = &oldmatches.array[i]; if (mi->is_action || - (mi->substring && g_strrstr (mi->match, p->keys[0])) || - (mi->substring && g_strrstr (mi->title, p->keys[0])) || + (mi->match && mi->substring && g_strrstr (mi->match, p->keys[0])) || + (mi->title && mi->substring && g_strrstr (mi->title, p->keys[0])) || !strncmp (key0, mi->title + mi->offset, key0l)) { acma_append (&newmatches, mi, mi->is_action); @@ -341,11 +341,23 @@ ephy_autocompletion_update_matches_full_item (EphyAutocompletionSource *source, guint32 score, EphyAutocompletionPrivate *p) { - g_return_if_fail ((item != NULL) || is_action); - - if (is_action || - (substring && g_strrstr (item, p->keys[0])) || - (substring && g_strrstr (title, p->keys[0]))) + if (substring) + { + if ((item && g_strrstr (item, p->keys[0])) || + (title && g_strrstr (title, p->keys[0]))) + { + EphyAutocompletionMatch m; + m.match = item; + m.title = title; + m.target = target; + m.is_action = is_action; + m.substring = substring; + m.offset = 0; + m.score = score; + acma_append (&p->matches, &m, is_action); + } + } + else if (is_action) { EphyAutocompletionMatch m; m.match = item; diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index a9884f3c3..f595b2140 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -84,9 +84,17 @@ static void ephy_location_entry_autocompletion_show_alternatives (EphyLocationE static void ephy_location_entry_autocompletion_hide_alternatives (EphyLocationEntry *w); static void ephy_location_entry_autocompletion_window_hidden_cb (EphyAutocompletionWindow *aw, EphyLocationEntry *w); - - - +static void +insert_text_cb (GtkWidget *editable, + char *new_text, + int new_text_length, + int *position, + EphyLocationEntry *w); +static void +delete_text_cb (GtkWidget *editable, + int start_pos, + int end_pos, + EphyLocationEntry *w); static gpointer gtk_hbox_class; @@ -219,6 +227,10 @@ ephy_location_entry_build (EphyLocationEntry *w) g_signal_connect (p->entry, "key-press-event", G_CALLBACK (ephy_location_entry_key_press_event_cb), w); + g_signal_connect (p->entry, "insert-text", + G_CALLBACK (insert_text_cb), w); + g_signal_connect (p->entry, "delete-text", + G_CALLBACK (delete_text_cb), w); g_signal_connect (p->entry, "button-press-event", G_CALLBACK (ephy_location_entry_button_press_event_cb), w); @@ -274,8 +286,8 @@ ephy_location_entry_autocompletion_show_alternatives_to (EphyLocationEntry *w) { EphyLocationEntryPrivate *p = w->priv; - g_free (p->before_completion), - p->before_completion = gtk_editable_get_chars (GTK_EDITABLE(p->entry), 0, -1); + g_free (p->before_completion); + p->before_completion = gtk_editable_get_chars (GTK_EDITABLE (p->entry), 0, -1); if (ephy_location_ignore_prefix (w)) return FALSE; @@ -349,17 +361,37 @@ real_entry_set_location (EphyLocationEntry *w, 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); - gtk_editable_insert_text (GTK_EDITABLE (p->entry), new_location, g_utf8_strlen (new_location, -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); } -/* this is from the old location entry, need to do the autocompletion before implementing this */ -static gboolean -ephy_location_entry_key_press_event_cb (GtkWidget *entry, GdkEventKey *event, EphyLocationEntry *w) +static void +delete_text_cb (GtkWidget *editable, + int start_pos, + int end_pos, + EphyLocationEntry *w) +{ + ephy_location_entry_autocompletion_hide_alternatives (w); +} + +static void +insert_text_cb (GtkWidget *editable, + char *new_text, + int new_text_length, + int *position, + EphyLocationEntry *w) { EphyLocationEntryPrivate *p = w->priv; - guint keyval = event->keyval; if (p->autocompletion_timeout != 0) { @@ -373,45 +405,25 @@ ephy_location_entry_key_press_event_cb (GtkWidget *entry, GdkEventKey *event, Ep p->show_alternatives_timeout = 0; } - if (((event->state & GDK_Control_L || event->state & GDK_Control_R) && - (keyval == GDK_a || keyval == GDK_b || keyval == GDK_c || - keyval == GDK_d || keyval == GDK_e || keyval == GDK_f || - keyval == GDK_h || keyval == GDK_k || keyval == GDK_u || - keyval == GDK_v || keyval == GDK_w || keyval == GDK_x)) || - (event->state == 0 && event->keyval == GDK_BackSpace)) - { - ephy_location_entry_autocompletion_hide_alternatives (w); - return FALSE; - } - - /* don't grab alt combos, thus you can still access the menus. */ - if (event->state & GDK_MOD1_MASK) - { - ephy_location_entry_autocompletion_hide_alternatives (w); - return FALSE; - } + w->priv->editing = TRUE; + ephy_location_entry_autocompletion_unselect_alternatives (w); + if (position_is_at_end (GTK_EDITABLE (editable))) + { + p->show_alternatives_timeout = g_timeout_add + (SHOW_ALTERNATIVES_DELAY, + (GSourceFunc) ephy_location_entry_autocompletion_show_alternatives_to, w); + } +} - /* make sure the end key works at all times */ - if ((!((event->state & GDK_SHIFT_MASK) || - (event->state & GDK_CONTROL_MASK) || - (event->state & GDK_MOD1_MASK)) - && (event->keyval == GDK_End))) - { - ephy_location_entry_autocompletion_hide_alternatives (w); - gtk_editable_select_region (GTK_EDITABLE (p->entry), 0, 0); - gtk_editable_set_position (GTK_EDITABLE (p->entry), -1); - ephy_location_entry_autocompletion_unselect_alternatives (w); - return TRUE; - } +static gboolean +ephy_location_entry_key_press_event_cb (GtkWidget *entry, GdkEventKey *event, EphyLocationEntry *w) +{ + EphyLocationEntryPrivate *p = w->priv; switch (event->keyval) { case GDK_Left: case GDK_Right: - case GDK_Up: - case GDK_Down: - case GDK_Page_Up: - case GDK_Page_Down: ephy_location_entry_autocompletion_hide_alternatives (w); return FALSE; case GDK_Escape: @@ -420,15 +432,6 @@ ephy_location_entry_key_press_event_cb (GtkWidget *entry, GdkEventKey *event, Ep ephy_location_entry_autocompletion_hide_alternatives (w); return FALSE; default: - w->priv->editing = TRUE; - ephy_location_entry_autocompletion_unselect_alternatives (w); - if ((event->string[0] > 32) && (event->string[0] < 126) && - position_is_at_end (GTK_EDITABLE (entry))) - { - p->show_alternatives_timeout = g_timeout_add - (SHOW_ALTERNATIVES_DELAY, - (GSourceFunc) ephy_location_entry_autocompletion_show_alternatives_to, w); - } break; } @@ -439,7 +442,8 @@ static gboolean ephy_location_entry_content_is_text (const char *content) { return ((g_strrstr (content, ".") == NULL) && - (g_strrstr (content, "/") == NULL)); + (g_strrstr (content, "/") == NULL) && + (g_strrstr (content, ":") == NULL)); } static void @@ -449,9 +453,17 @@ ephy_location_entry_activate_cb (GtkEntry *entry, EphyLocationEntry *w) char *target = NULL; content = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1); - if (ephy_location_entry_content_is_text (content)) + if (w->priv->last_action_target && + ephy_location_entry_content_is_text (content)) + { + target = g_strdup (w->priv->last_action_target); + } + else { - target = w->priv->last_action_target; + target = content; + content = NULL; + g_free ( w->priv->last_action_target); + w->priv->last_action_target = NULL; } ephy_location_entry_autocompletion_hide_alternatives (w); @@ -460,10 +472,11 @@ ephy_location_entry_activate_cb (GtkEntry *entry, EphyLocationEntry *w) w->priv->editing = FALSE; - g_signal_emit (w, EphyLocationEntrySignals[ACTIVATED], 0, target, content); + g_signal_emit (w, EphyLocationEntrySignals[ACTIVATED], 0, content, target); g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0); g_free (content); + g_free (target); } static void diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 9d4269a4e..86e824fc3 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -183,7 +183,7 @@ ephy_bookmarks_autocompletion_source_foreach (EphyAutocompletionSource *source, (kid, EPHY_NODE_BMK_PROP_KEYWORDS); func (source, keywords, title, url, smart_url, - TRUE, 0, data); + !smart_url, 0, data); } ephy_node_thaw (eb->priv->bookmarks); } diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c index a87796d3d..67ac05be3 100644 --- a/src/ephy-location-action.c +++ b/src/ephy-location-action.c @@ -70,7 +70,7 @@ create_tool_item (EggAction *action) LOG ("Create location toolitem") - item = GTK_WIDGET (egg_tool_item_new ());//(* EGG_ACTION_CLASS (parent_class)->create_tool_item) (action); + item = GTK_WIDGET (egg_tool_item_new ()); location = ephy_location_entry_new (); gtk_container_add (GTK_CONTAINER (item), location); egg_tool_item_set_expand (EGG_TOOL_ITEM (item), TRUE); @@ -88,7 +88,9 @@ location_url_activate_cb (EphyLocationEntry *entry, EphyLocationAction *action) { EphyBookmarks *bookmarks; - LOG ("Location url activated") + + LOG ("Location url activated, content %s target %s", content, target) + bookmarks = ephy_shell_get_bookmarks (ephy_shell); if (!content) -- cgit v1.2.3