Remember text typed in the location when switching tabs

The API of the location action is adjusted so that any typed
text can be retrieved, distinguished from a confirmed URI.
This commit is contained in:
Christian Dywan 2009-10-04 02:32:50 +02:00
parent d4c9c87f79
commit b53c39b82e
3 changed files with 108 additions and 17 deletions

View file

@ -4312,22 +4312,45 @@ gtk_notebook_switch_page_cb (GtkWidget* notebook,
guint page_num, guint page_num,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* view; GtkWidget* widget;
GtkAction* action;
const gchar* text;
if (!(widget = midori_browser_get_current_tab (browser)))
return;
action = _action_by_name (browser, "Location");
text = midori_location_action_get_text (MIDORI_LOCATION_ACTION (action));
g_object_set_data_full (G_OBJECT (widget), "midori-browser-typed-text",
g_strdup (text), g_free);
}
static void
gtk_notebook_switch_page_after_cb (GtkWidget* notebook,
GtkNotebookPage* page,
guint page_num,
MidoriBrowser* browser)
{
GtkWidget* widget;
MidoriView* view;
const gchar* uri; const gchar* uri;
GtkAction* action; GtkAction* action;
const gchar* title; const gchar* title;
gchar* window_title; gchar* window_title;
if (!(view = midori_browser_get_current_tab (browser))) if (!(widget = midori_browser_get_current_tab (browser)))
return; return;
uri = midori_view_get_display_uri (MIDORI_VIEW (view)); view = MIDORI_VIEW (widget);
uri = g_object_get_data (G_OBJECT (widget), "midori-browser-typed-text");
if (!uri)
uri = midori_view_get_display_uri (view);
action = _action_by_name (browser, "Location"); action = _action_by_name (browser, "Location");
midori_location_action_set_uri (MIDORI_LOCATION_ACTION (action), uri); midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri);
midori_location_action_set_icon (MIDORI_LOCATION_ACTION (action), midori_location_action_set_icon (MIDORI_LOCATION_ACTION (action),
midori_view_get_icon (MIDORI_VIEW (view))); midori_view_get_icon (view));
title = midori_view_get_display_title (MIDORI_VIEW (view)); title = midori_view_get_display_title (view);
window_title = g_strconcat (title, " - ", g_get_application_name (), NULL); window_title = g_strconcat (title, " - ", g_get_application_name (), NULL);
gtk_window_set_title (GTK_WINDOW (browser), window_title); gtk_window_set_title (GTK_WINDOW (browser), window_title);
g_free (window_title); g_free (window_title);
@ -4342,7 +4365,7 @@ gtk_notebook_switch_page_cb (GtkWidget* notebook,
_midori_browser_set_statusbar_text (browser, NULL); _midori_browser_set_statusbar_text (browser, NULL);
_midori_browser_update_interface (browser); _midori_browser_update_interface (browser);
_midori_browser_update_progress (browser, MIDORI_VIEW (view)); _midori_browser_update_progress (browser, view);
} }
static void static void
@ -5414,8 +5437,11 @@ midori_browser_init (MidoriBrowser* browser)
g_object_unref (rcstyle); g_object_unref (rcstyle);
gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE); gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
gtk_paned_pack2 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE); gtk_paned_pack2 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE);
g_signal_connect (browser->notebook, "switch-page",
G_CALLBACK (gtk_notebook_switch_page_cb),
browser);
g_signal_connect_after (browser->notebook, "switch-page", g_signal_connect_after (browser->notebook, "switch-page",
G_CALLBACK (gtk_notebook_switch_page_cb), G_CALLBACK (gtk_notebook_switch_page_after_cb),
browser); browser);
g_signal_connect (browser->notebook, "page-reordered", g_signal_connect (browser->notebook, "page-reordered",
G_CALLBACK (midori_browser_notebook_page_reordered_cb), G_CALLBACK (midori_browser_notebook_page_reordered_cb),

View file

@ -26,6 +26,7 @@ struct _MidoriLocationAction
{ {
GtkAction parent_instance; GtkAction parent_instance;
gchar* text;
gchar* uri; gchar* uri;
KatzeArray* search_engines; KatzeArray* search_engines;
gdouble progress; gdouble progress;
@ -352,7 +353,7 @@ midori_location_action_create_model (void)
static void static void
midori_location_action_init (MidoriLocationAction* location_action) midori_location_action_init (MidoriLocationAction* location_action)
{ {
location_action->uri = NULL; location_action->text = location_action->uri = NULL;
location_action->search_engines = NULL; location_action->search_engines = NULL;
location_action->progress = 0.0; location_action->progress = 0.0;
location_action->secondary_icon = NULL; location_action->secondary_icon = NULL;
@ -374,6 +375,7 @@ midori_location_action_finalize (GObject* object)
{ {
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object); MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
katze_assign (location_action->text, NULL);
katze_assign (location_action->uri, NULL); katze_assign (location_action->uri, NULL);
katze_assign (location_action->search_engines, NULL); katze_assign (location_action->search_engines, NULL);
@ -551,8 +553,15 @@ midori_location_action_create_tool_item (GtkAction* action)
return toolitem; return toolitem;
} }
static void
midori_location_action_changed_cb (GtkEntry* entry,
MidoriLocationAction* location_action)
{
katze_assign (location_action->text, g_strdup (gtk_entry_get_text (entry)));
}
static gboolean static gboolean
midori_location_action_key_press_event_cb (GtkWidget* widget, midori_location_action_key_press_event_cb (GtkEntry* entry,
GdkEventKey* event, GdkEventKey* event,
GtkAction* action) GtkAction* action)
{ {
@ -564,7 +573,7 @@ midori_location_action_key_press_event_cb (GtkWidget* widget,
case GDK_KP_Enter: case GDK_KP_Enter:
case GDK_Return: case GDK_Return:
{ {
if ((uri = gtk_entry_get_text (GTK_ENTRY (widget))) && *uri) if ((uri = gtk_entry_get_text (entry)) && *uri)
{ {
g_signal_emit (action, signals[SUBMIT_URI], 0, uri, g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
(event->state & GDK_MOD1_MASK) ? TRUE : FALSE); (event->state & GDK_MOD1_MASK) ? TRUE : FALSE);
@ -582,8 +591,8 @@ midori_location_action_key_press_event_cb (GtkWidget* widget,
static gboolean static gboolean
midori_location_action_focus_in_event_cb (GtkWidget* widget, midori_location_action_focus_in_event_cb (GtkWidget* widget,
GdkEventKey* event, GdkEventKey* event,
GtkAction* action) GtkAction* action)
{ {
g_signal_emit (action, signals[FOCUS_IN], 0); g_signal_emit (action, signals[FOCUS_IN], 0);
return FALSE; return FALSE;
@ -905,7 +914,7 @@ midori_location_entry_match_selected_cb (GtkEntryCompletion* completion,
gchar* uri; gchar* uri;
gtk_tree_model_get (model, iter, URI_COL, &uri, -1); gtk_tree_model_get (model, iter, URI_COL, &uri, -1);
midori_location_action_set_uri (location_action, uri); midori_location_action_set_text (location_action, uri);
g_signal_emit (location_action, signals[SUBMIT_URI], 0, uri, FALSE); g_signal_emit (location_action, signals[SUBMIT_URI], 0, uri, FALSE);
g_free (uri); g_free (uri);
@ -928,7 +937,7 @@ midori_location_entry_action_activated_cb (GtkEntryCompletion* completion,
if (!item) if (!item)
return; return;
search = sokoke_search_uri (uri, keywords); search = sokoke_search_uri (uri, keywords);
midori_location_action_set_uri (location_action, search); midori_location_action_set_text (location_action, search);
g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE); g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE);
g_free (search); g_free (search);
} }
@ -1030,6 +1039,7 @@ midori_location_action_entry_changed_cb (GtkComboBox* combo_box,
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry), gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
GTK_ICON_ENTRY_PRIMARY, pixbuf); GTK_ICON_ENTRY_PRIMARY, pixbuf);
g_object_unref (pixbuf); g_object_unref (pixbuf);
katze_assign (location_action->text, uri);
katze_assign (location_action->uri, uri); katze_assign (location_action->uri, uri);
g_signal_emit (location_action, signals[ACTIVE_CHANGED], 0, g_signal_emit (location_action, signals[ACTIVE_CHANGED], 0,
@ -1083,6 +1093,8 @@ midori_location_action_connect_proxy (GtkAction* action,
G_CALLBACK (midori_location_action_entry_changed_cb), action); G_CALLBACK (midori_location_action_entry_changed_cb), action);
g_object_connect (gtk_bin_get_child (GTK_BIN (entry)), g_object_connect (gtk_bin_get_child (GTK_BIN (entry)),
"signal::changed",
midori_location_action_changed_cb, action,
"signal::key-press-event", "signal::key-press-event",
midori_location_action_key_press_event_cb, action, midori_location_action_key_press_event_cb, action,
"signal::focus-in-event", "signal::focus-in-event",
@ -1107,6 +1119,14 @@ midori_location_action_disconnect_proxy (GtkAction* action,
(action, proxy); (action, proxy);
} }
/**
* midori_location_action_get_uri:
* @location_action: a #MidoriLocationAction
*
* Retrieves the current URI. See also midori_location_action_get_text().
*
* Return value: the current URI
**/
const gchar* const gchar*
midori_location_action_get_uri (MidoriLocationAction* location_action) midori_location_action_get_uri (MidoriLocationAction* location_action)
{ {
@ -1115,14 +1135,35 @@ midori_location_action_get_uri (MidoriLocationAction* location_action)
return location_action->uri; return location_action->uri;
} }
/**
* midori_location_action_get_text:
* @location_action: a #MidoriLocationAction
*
* Retrieves the current text, which may be the current URI or
* anything typed in the entry.
*
* Return value: the current text
*
* Since: 0.2.0
**/
const gchar*
midori_location_action_get_text (MidoriLocationAction* location_action)
{
g_return_val_if_fail (MIDORI_IS_LOCATION_ACTION (location_action), NULL);
return location_action->text;
}
/** /**
* midori_location_action_set_text: * midori_location_action_set_text:
* @location_action: a #MidoriLocationAction * @location_action: a #MidoriLocationAction
* @text: a string * @text: a string
* *
* Sets the entry text to @text and, if applicable, updates the icon. * Sets the entry text to @text and, if applicable, updates the icon.
*
* Since: 0.2.0
**/ **/
static void void
midori_location_action_set_text (MidoriLocationAction* location_action, midori_location_action_set_text (MidoriLocationAction* location_action,
const gchar* text) const gchar* text)
{ {
@ -1132,12 +1173,20 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
GtkTreeIter iter; GtkTreeIter iter;
GdkPixbuf* icon; GdkPixbuf* icon;
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
g_return_if_fail (text != NULL);
katze_assign (location_action->text, g_strdup (text));
if (!(proxies = gtk_action_get_proxies (GTK_ACTION (location_action)))) if (!(proxies = gtk_action_get_proxies (GTK_ACTION (location_action))))
return; return;
if (midori_location_action_iter_lookup (location_action, text, &iter)) if (midori_location_action_iter_lookup (location_action, text, &iter))
{
gtk_tree_model_get (location_action->model, gtk_tree_model_get (location_action->model,
&iter, FAVICON_COL, &icon, -1); &iter, FAVICON_COL, &icon, -1);
katze_assign (location_action->uri, g_strdup (text));
}
else else
icon = g_object_ref (location_action->default_icon); icon = g_object_ref (location_action->default_icon);
@ -1156,6 +1205,15 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
g_object_unref (icon); g_object_unref (icon);
} }
/**
* midori_location_action_set_uri:
* @location_action: a #MidoriLocationAction
* @uri: an URI string
*
* Sets the entry URI to @uri and, if applicable, updates the icon.
*
* Deprecated: 0.2.0
**/
void void
midori_location_action_set_uri (MidoriLocationAction* location_action, midori_location_action_set_uri (MidoriLocationAction* location_action,
const gchar* uri) const gchar* uri)

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de> Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -50,6 +50,13 @@ midori_location_action_freeze (MidoriLocationAction* location_actio
void void
midori_location_action_thaw (MidoriLocationAction* location_action); midori_location_action_thaw (MidoriLocationAction* location_action);
const gchar*
midori_location_action_get_text (MidoriLocationAction* location_action);
void
midori_location_action_set_text (MidoriLocationAction* location_action,
const gchar* text);
const gchar* const gchar*
midori_location_action_get_uri (MidoriLocationAction* location_action); midori_location_action_get_uri (MidoriLocationAction* location_action);