]> spindle.queued.net Git - midori/commitdiff
Add a button to change the alignment to the panel
authorChristian Dywan <christian@twotoasts.de>
Sun, 22 Feb 2009 18:23:45 +0000 (19:23 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 22 Feb 2009 18:23:45 +0000 (19:23 +0100)
midori/midori-browser.c
midori/midori-panel.c

index 03a974d65592a60af38557e70c5e7ae0273eb5fb..89065de364e95a344a7b5f0a0661245bb4bc7b6b 100644 (file)
@@ -2744,6 +2744,35 @@ midori_panel_notify_position_cb (GObject*       hpaned,
             (GSourceFunc)midori_browser_panel_timeout, hpaned, NULL);
 }
 
+static void
+midori_panel_notify_right_aligned_cb (MidoriPanel*   panel,
+                                      GParamSpec*    pspec,
+                                      MidoriBrowser* browser)
+{
+    gboolean right_aligned = katze_object_get_boolean (panel, "right-aligned");
+    GtkWidget* hpaned = gtk_widget_get_parent (browser->panel);
+    GtkWidget* vpaned = gtk_widget_get_parent (browser->notebook);
+
+    g_object_set (browser->settings, "right-align-sidepanel", right_aligned, NULL);
+
+    g_object_ref (browser->panel);
+    g_object_ref (vpaned);
+    gtk_container_remove (GTK_CONTAINER (hpaned), browser->panel);
+    gtk_container_remove (GTK_CONTAINER (hpaned), vpaned);
+    if (right_aligned)
+    {
+        gtk_paned_pack1 (GTK_PANED (hpaned), vpaned, FALSE, FALSE);
+        gtk_paned_pack2 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE);
+    }
+    else
+    {
+        gtk_paned_pack1 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE);
+        gtk_paned_pack2 (GTK_PANED (hpaned), vpaned, FALSE, FALSE);
+    }
+    g_object_unref (browser->panel);
+    g_object_unref (vpaned);
+}
+
 static gboolean
 midori_panel_close_cb (MidoriPanel*   panel,
                        MidoriBrowser* browser)
@@ -3609,9 +3638,11 @@ midori_browser_init (MidoriBrowser* browser)
     gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
     gtk_widget_show (hpaned);
     browser->panel = g_object_new (MIDORI_TYPE_PANEL,
-                                "shadow-type", GTK_SHADOW_IN,
-                                "menu", browser->menu_tools,
-                                NULL);
+                                   "shadow-type", GTK_SHADOW_IN,
+                                   "menu", browser->menu_tools,
+                                   NULL);
+    g_signal_connect (browser->panel, "notify::right-aligned",
+                      G_CALLBACK (midori_panel_notify_right_aligned_cb), browser);
     g_signal_connect (browser->panel, "close",
                       G_CALLBACK (midori_panel_close_cb), browser);
     gtk_paned_pack1 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE);
@@ -3889,7 +3920,6 @@ _midori_browser_update_settings (MidoriBrowser* browser)
     gint last_window_width, last_window_height;
     MidoriWindowState last_window_state;
     gboolean compact_sidepanel, right_align_sidepanel;
-    GtkWidget* hpaned, *vpaned;
     gint last_panel_position, last_panel_page;
     gboolean show_menubar, show_navigationbar, show_bookmarkbar;
     gboolean show_panel, show_statusbar;
@@ -3963,24 +3993,6 @@ _midori_browser_update_settings (MidoriBrowser* browser)
     }
 
     midori_panel_set_compact (MIDORI_PANEL (browser->panel), compact_sidepanel);
-    hpaned = gtk_widget_get_parent (browser->panel);
-    vpaned = gtk_widget_get_parent (browser->notebook);
-    g_object_ref (browser->panel);
-    g_object_ref (vpaned);
-    gtk_container_remove (GTK_CONTAINER (hpaned), browser->panel);
-    gtk_container_remove (GTK_CONTAINER (hpaned), vpaned);
-    if (right_align_sidepanel)
-    {
-        gtk_paned_pack1 (GTK_PANED (hpaned), vpaned, FALSE, FALSE);
-        gtk_paned_pack2 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE);
-    }
-    else
-    {
-        gtk_paned_pack1 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE);
-        gtk_paned_pack2 (GTK_PANED (hpaned), vpaned, FALSE, FALSE);
-    }
-    g_object_unref (browser->panel);
-    g_object_unref (vpaned);
     midori_panel_set_right_aligned (MIDORI_PANEL (browser->panel),
                                     right_align_sidepanel);
     gtk_paned_set_position (GTK_PANED (gtk_widget_get_parent (browser->panel)),
index 667a82957110489d9fe627e857a3e1ea9d1ba397..41574536d408bf85b4284d802d4089082ac911ad 100644 (file)
@@ -24,12 +24,15 @@ struct _MidoriPanel
     GtkHBox parent_instance;
 
     GtkWidget* toolbar;
+    GtkToolItem* button_align;
     GtkWidget* toolbar_label;
     GtkWidget* frame;
     GtkWidget* toolbook;
     GtkWidget* notebook;
     GSList*    group;
     GtkMenu*   menu;
+
+    gboolean right_aligned;
 };
 
 struct _MidoriPanelClass
@@ -49,7 +52,8 @@ enum
 
     PROP_SHADOW_TYPE,
     PROP_MENU,
-    PROP_PAGE
+    PROP_PAGE,
+    PROP_RIGHT_ALIGNED,
 };
 
 enum {
@@ -147,6 +151,22 @@ midori_panel_class_init (MidoriPanelClass* class)
                                      "The index of the current page",
                                      -1, G_MAXINT, -1,
                                      flags));
+
+    /**
+    * MidoriWebSettings:right-aligned:
+    *
+    * Whether to align the panel on the right.
+    *
+    * Since: 0.1.3
+    */
+    g_object_class_install_property (gobject_class,
+                                     PROP_RIGHT_ALIGNED,
+                                     g_param_spec_boolean (
+                                     "right-aligned",
+                                     "Right aligned",
+                                     "Whether the panel is aligned to the right",
+                                     FALSE,
+                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -157,6 +177,13 @@ midori_panel_button_close_clicked_cb (GtkWidget*   toolitem,
     g_signal_emit (panel, signals[CLOSE], 0, &return_value);
 }
 
+static void
+midori_panel_button_align_clicked_cb (GtkWidget*   toolitem,
+                                      MidoriPanel* panel)
+{
+    midori_panel_set_right_aligned (panel, !panel->right_aligned);
+}
+
 static void
 midori_panel_destroy_cb (MidoriPanel* panel)
 {
@@ -172,6 +199,8 @@ midori_panel_init (MidoriPanel* panel)
     GtkWidget* labelbar;
     GtkToolItem* toolitem;
 
+    panel->right_aligned = FALSE;
+
     /* Create the sidebar */
     panel->toolbar = gtk_toolbar_new ();
     gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), GTK_TOOLBAR_BOTH);
@@ -195,6 +224,19 @@ midori_panel_init (MidoriPanel* panel)
     gtk_container_add (GTK_CONTAINER (toolitem), panel->toolbar_label);
     gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6);
     gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, -1);
+    toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
+    gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem),
+                               _("Align sidepanel on the right"));
+    gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (toolitem),
+                               _("Whether to align the sidepanel on the right"));
+    g_signal_connect (toolitem, "clicked",
+        G_CALLBACK (midori_panel_button_align_clicked_cb), panel);
+    #if HAVE_OSX
+    gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, 0);
+    #else
+    gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, -1);
+    #endif
+    panel->button_align = toolitem;
     toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
     gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("Close panel"));
     gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (toolitem), _("Close panel"));
@@ -255,6 +297,9 @@ midori_panel_set_property (GObject*      object,
     case PROP_PAGE:
         midori_panel_set_current_page (panel, g_value_get_int (value));
         break;
+    case PROP_RIGHT_ALIGNED:
+        midori_panel_set_right_aligned (panel, g_value_get_boolean (value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -281,6 +326,9 @@ midori_panel_get_property (GObject*    object,
     case PROP_PAGE:
         g_value_set_int (value, midori_panel_get_current_page (panel));
         break;
+    case PROP_RIGHT_ALIGNED:
+        g_value_set_boolean (value, panel->right_aligned);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -341,6 +389,10 @@ midori_panel_set_right_aligned (MidoriPanel* panel,
     box = gtk_widget_get_parent (panel->toolbar);
     gtk_box_reorder_child (GTK_BOX (box), panel->toolbar,
         right_aligned ? -1 : 0);
+    gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (panel->button_align),
+        right_aligned ? GTK_STOCK_GO_BACK : GTK_STOCK_GO_FORWARD);
+    panel->right_aligned = right_aligned;
+    g_object_notify (G_OBJECT (panel), "right-aligned");
 }
 
 static void