]> spindle.queued.net Git - midori/commitdiff
Fix panel "page" notifications and save the last open panel
authorChristian Dywan <christian@twotoasts.de>
Mon, 22 Jun 2009 22:25:09 +0000 (00:25 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 22 Jun 2009 23:05:38 +0000 (01:05 +0200)
midori/midori-browser.c
midori/midori-panel.c

index 81f24160f6fd016ec9227ccaedc209d8adfcdad3..7c116acd51402d4409116c6443c6275a0380bf58 100644 (file)
@@ -3895,6 +3895,16 @@ midori_panel_notify_position_cb (GObject*       hpaned,
             (GSourceFunc)midori_browser_panel_timeout, hpaned, NULL);
 }
 
+static void
+midori_panel_notify_page_cb (MidoriPanel*   panel,
+                             GParamSpec*    pspec,
+                             MidoriBrowser* browser)
+{
+    gint page = katze_object_get_boolean (panel, "page");
+    if (browser->settings && page > -1)
+        g_object_set (browser->settings, "last-panel-page", page, NULL);
+}
+
 static void
 midori_panel_notify_right_aligned_cb (MidoriPanel*   panel,
                                       GParamSpec*    pspec,
@@ -4307,7 +4317,16 @@ midori_browser_size_allocate_cb (MidoriBrowser* browser,
 
     if (GTK_WIDGET_REALIZED (widget))
     {
+        gpointer last_page;
         GdkWindowState state = gdk_window_get_state (widget->window);
+
+        if ((last_page = g_object_get_data (G_OBJECT (browser), "last-page")))
+        {
+            midori_panel_set_current_page (MIDORI_PANEL (browser->panel),
+                GPOINTER_TO_INT (last_page));
+            g_object_set_data (G_OBJECT (browser), "last-page", NULL);
+        }
+
         if (!(state &
             (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN))
             && !browser->alloc_timeout)
@@ -4918,6 +4937,8 @@ midori_browser_init (MidoriBrowser* browser)
     browser->panel = g_object_new (MIDORI_TYPE_PANEL,
                                    "menu", browser->menu_tools,
                                    NULL);
+    g_signal_connect (browser->panel, "notify::page",
+                      G_CALLBACK (midori_panel_notify_page_cb), browser);
     g_signal_connect (browser->panel, "notify::right-aligned",
                       G_CALLBACK (midori_panel_notify_right_aligned_cb), browser);
     g_signal_connect (browser->panel, "close",
@@ -5312,7 +5333,13 @@ _midori_browser_update_settings (MidoriBrowser* browser)
                                     right_align_sidepanel);
     gtk_paned_set_position (GTK_PANED (gtk_widget_get_parent (browser->panel)),
                             last_panel_position);
-    midori_panel_set_current_page (MIDORI_PANEL (browser->panel), last_panel_page);
+    /* The browser may not yet be visible, which means that we can't set the
+       page. So we set it in midori_browser_size_allocate_cb */
+    if (GTK_WIDGET_VISIBLE (browser))
+        midori_panel_set_current_page (MIDORI_PANEL (browser->panel), last_panel_page);
+    else
+        g_object_set_data (G_OBJECT (browser), "last-page",
+                           GINT_TO_POINTER (last_panel_page));
 
     _action_set_active (browser, "Menubar", show_menubar);
     _action_set_active (browser, "Navigationbar", browser->show_navigationbar);
index 2ed40a954381a90283fddbe3b080990ff1a03460..7296335e00c98bac9a5a03b5871901f040aee816 100644 (file)
@@ -797,6 +797,8 @@ midori_panel_page_num (MidoriPanel* panel,
  *
  * The child must be visible, otherwise the underlying GtkNotebook will
  * silently ignore the attempt to switch the page.
+ *
+ * Since 0.1.8 the "page" property is notifying changes.
  **/
 void
 midori_panel_set_current_page (MidoriPanel* panel,
@@ -806,15 +808,15 @@ midori_panel_set_current_page (MidoriPanel* panel,
 
     g_return_if_fail (MIDORI_IS_PANEL (panel));
 
-    gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->toolbook), n);
-    gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->notebook), n);
-
     if ((viewable = midori_panel_get_nth_page (panel, n)))
     {
         const gchar* label;
 
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->toolbook), n);
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->notebook), n);
         label = midori_viewable_get_label (MIDORI_VIEWABLE (viewable));
         g_object_set (panel->toolbar_label, "label", label, NULL);
+        g_object_notify (G_OBJECT (panel), "page");
     }
 }