[Xfce4-commits] <midori:master> Remember text typed in the location when switching tabs

Christian Dywan noreply at xfce.org
Sun Oct 4 16:28:01 CEST 2009


Updating branch refs/heads/master
         to b53c39b82eabd8f10b656b14b0e125f58ef488c7 (commit)
       from d4c9c87f79e3dd2d1ebba7972fd1102d90aba343 (commit)

commit b53c39b82eabd8f10b656b14b0e125f58ef488c7
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Oct 4 02:32:50 2009 +0200

    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.

 midori/midori-browser.c        |   42 ++++++++++++++++++----
 midori/midori-locationaction.c |   74 +++++++++++++++++++++++++++++++++++----
 midori/midori-locationaction.h |    9 ++++-
 3 files changed, 108 insertions(+), 17 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 346e055..2d48f23 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -4312,22 +4312,45 @@ gtk_notebook_switch_page_cb (GtkWidget*       notebook,
                              guint            page_num,
                              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;
     GtkAction* action;
     const gchar* title;
     gchar* window_title;
 
-    if (!(view = midori_browser_get_current_tab (browser)))
+    if (!(widget = midori_browser_get_current_tab (browser)))
         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");
-    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_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);
     gtk_window_set_title (GTK_WINDOW (browser), 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_update_interface (browser);
-    _midori_browser_update_progress (browser, MIDORI_VIEW (view));
+    _midori_browser_update_progress (browser, view);
 }
 
 static void
@@ -5414,8 +5437,11 @@ midori_browser_init (MidoriBrowser* browser)
     g_object_unref (rcstyle);
     gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
     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_CALLBACK (gtk_notebook_switch_page_cb),
+                            G_CALLBACK (gtk_notebook_switch_page_after_cb),
                             browser);
     g_signal_connect (browser->notebook, "page-reordered",
                       G_CALLBACK (midori_browser_notebook_page_reordered_cb),
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index f19f0d9..f4eaeca 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -26,6 +26,7 @@ struct _MidoriLocationAction
 {
     GtkAction parent_instance;
 
+    gchar* text;
     gchar* uri;
     KatzeArray* search_engines;
     gdouble progress;
@@ -352,7 +353,7 @@ midori_location_action_create_model (void)
 static void
 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->progress = 0.0;
     location_action->secondary_icon = NULL;
@@ -374,6 +375,7 @@ midori_location_action_finalize (GObject* object)
 {
     MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (object);
 
+    katze_assign (location_action->text, NULL);
     katze_assign (location_action->uri, NULL);
     katze_assign (location_action->search_engines, NULL);
 
@@ -551,8 +553,15 @@ midori_location_action_create_tool_item (GtkAction* action)
     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
-midori_location_action_key_press_event_cb (GtkWidget*   widget,
+midori_location_action_key_press_event_cb (GtkEntry*    entry,
                                            GdkEventKey* event,
                                            GtkAction*   action)
 {
@@ -564,7 +573,7 @@ midori_location_action_key_press_event_cb (GtkWidget*   widget,
     case GDK_KP_Enter:
     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,
                 (event->state & GDK_MOD1_MASK) ? TRUE : FALSE);
@@ -582,8 +591,8 @@ midori_location_action_key_press_event_cb (GtkWidget*   widget,
 
 static gboolean
 midori_location_action_focus_in_event_cb (GtkWidget*   widget,
-                                           GdkEventKey* event,
-                                           GtkAction*   action)
+                                          GdkEventKey* event,
+                                          GtkAction*   action)
 {
     g_signal_emit (action, signals[FOCUS_IN], 0);
     return FALSE;
@@ -905,7 +914,7 @@ midori_location_entry_match_selected_cb (GtkEntryCompletion*   completion,
     gchar* uri;
     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_free (uri);
 
@@ -928,7 +937,7 @@ midori_location_entry_action_activated_cb (GtkEntryCompletion*   completion,
         if (!item)
             return;
         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_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_PRIMARY, pixbuf);
             g_object_unref (pixbuf);
+            katze_assign (location_action->text, uri);
             katze_assign (location_action->uri, uri);
 
             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_object_connect (gtk_bin_get_child (GTK_BIN (entry)),
+                      "signal::changed",
+                      midori_location_action_changed_cb, action,
                       "signal::key-press-event",
                       midori_location_action_key_press_event_cb, action,
                       "signal::focus-in-event",
@@ -1107,6 +1119,14 @@ midori_location_action_disconnect_proxy (GtkAction* action,
         (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*
 midori_location_action_get_uri (MidoriLocationAction* location_action)
 {
@@ -1116,13 +1136,34 @@ midori_location_action_get_uri (MidoriLocationAction* location_action)
 }
 
 /**
+ * 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:
  * @location_action: a #MidoriLocationAction
  * @text: a string
  *
  * 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,
                                  const gchar*          text)
 {
@@ -1132,12 +1173,20 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
     GtkTreeIter iter;
     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))))
         return;
 
     if (midori_location_action_iter_lookup (location_action, text, &iter))
+    {
         gtk_tree_model_get (location_action->model,
                             &iter, FAVICON_COL, &icon, -1);
+        katze_assign (location_action->uri, g_strdup (text));
+    }
     else
         icon = g_object_ref (location_action->default_icon);
 
@@ -1156,6 +1205,15 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
         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
 midori_location_action_set_uri (MidoriLocationAction* location_action,
                                 const gchar*          uri)
diff --git a/midori/midori-locationaction.h b/midori/midori-locationaction.h
index 593d55d..3655430 100644
--- a/midori/midori-locationaction.h
+++ b/midori/midori-locationaction.h
@@ -1,5 +1,5 @@
 /*
- Copyright (C) 2008 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2008-2009 Christian Dywan <christian at twotoasts.de>
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -51,6 +51,13 @@ void
 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*
 midori_location_action_get_uri              (MidoriLocationAction* location_action);
 
 void



More information about the Xfce4-commits mailing list