Add a button to change the alignment to the panel

This commit is contained in:
Christian Dywan 2009-02-22 19:23:45 +01:00
parent 3b074844e3
commit 94532ab9f8
2 changed files with 87 additions and 23 deletions

View file

@ -2744,6 +2744,35 @@ midori_panel_notify_position_cb (GObject* hpaned,
(GSourceFunc)midori_browser_panel_timeout, hpaned, NULL); (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 static gboolean
midori_panel_close_cb (MidoriPanel* panel, midori_panel_close_cb (MidoriPanel* panel,
MidoriBrowser* browser) MidoriBrowser* browser)
@ -3609,9 +3638,11 @@ midori_browser_init (MidoriBrowser* browser)
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
gtk_widget_show (hpaned); gtk_widget_show (hpaned);
browser->panel = g_object_new (MIDORI_TYPE_PANEL, browser->panel = g_object_new (MIDORI_TYPE_PANEL,
"shadow-type", GTK_SHADOW_IN, "shadow-type", GTK_SHADOW_IN,
"menu", browser->menu_tools, "menu", browser->menu_tools,
NULL); 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_signal_connect (browser->panel, "close",
G_CALLBACK (midori_panel_close_cb), browser); G_CALLBACK (midori_panel_close_cb), browser);
gtk_paned_pack1 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE); 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; gint last_window_width, last_window_height;
MidoriWindowState last_window_state; MidoriWindowState last_window_state;
gboolean compact_sidepanel, right_align_sidepanel; gboolean compact_sidepanel, right_align_sidepanel;
GtkWidget* hpaned, *vpaned;
gint last_panel_position, last_panel_page; gint last_panel_position, last_panel_page;
gboolean show_menubar, show_navigationbar, show_bookmarkbar; gboolean show_menubar, show_navigationbar, show_bookmarkbar;
gboolean show_panel, show_statusbar; 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); 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), midori_panel_set_right_aligned (MIDORI_PANEL (browser->panel),
right_align_sidepanel); right_align_sidepanel);
gtk_paned_set_position (GTK_PANED (gtk_widget_get_parent (browser->panel)), gtk_paned_set_position (GTK_PANED (gtk_widget_get_parent (browser->panel)),

View file

@ -24,12 +24,15 @@ struct _MidoriPanel
GtkHBox parent_instance; GtkHBox parent_instance;
GtkWidget* toolbar; GtkWidget* toolbar;
GtkToolItem* button_align;
GtkWidget* toolbar_label; GtkWidget* toolbar_label;
GtkWidget* frame; GtkWidget* frame;
GtkWidget* toolbook; GtkWidget* toolbook;
GtkWidget* notebook; GtkWidget* notebook;
GSList* group; GSList* group;
GtkMenu* menu; GtkMenu* menu;
gboolean right_aligned;
}; };
struct _MidoriPanelClass struct _MidoriPanelClass
@ -49,7 +52,8 @@ enum
PROP_SHADOW_TYPE, PROP_SHADOW_TYPE,
PROP_MENU, PROP_MENU,
PROP_PAGE PROP_PAGE,
PROP_RIGHT_ALIGNED,
}; };
enum { enum {
@ -147,6 +151,22 @@ midori_panel_class_init (MidoriPanelClass* class)
"The index of the current page", "The index of the current page",
-1, G_MAXINT, -1, -1, G_MAXINT, -1,
flags)); 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 static void
@ -157,6 +177,13 @@ midori_panel_button_close_clicked_cb (GtkWidget* toolitem,
g_signal_emit (panel, signals[CLOSE], 0, &return_value); 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 static void
midori_panel_destroy_cb (MidoriPanel* panel) midori_panel_destroy_cb (MidoriPanel* panel)
{ {
@ -172,6 +199,8 @@ midori_panel_init (MidoriPanel* panel)
GtkWidget* labelbar; GtkWidget* labelbar;
GtkToolItem* toolitem; GtkToolItem* toolitem;
panel->right_aligned = FALSE;
/* Create the sidebar */ /* Create the sidebar */
panel->toolbar = gtk_toolbar_new (); panel->toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), GTK_TOOLBAR_BOTH); 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_add (GTK_CONTAINER (toolitem), panel->toolbar_label);
gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6); gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6);
gtk_toolbar_insert (GTK_TOOLBAR (labelbar), toolitem, -1); 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); toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("Close panel")); gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("Close panel"));
gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (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: case PROP_PAGE:
midori_panel_set_current_page (panel, g_value_get_int (value)); midori_panel_set_current_page (panel, g_value_get_int (value));
break; break;
case PROP_RIGHT_ALIGNED:
midori_panel_set_right_aligned (panel, g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -281,6 +326,9 @@ midori_panel_get_property (GObject* object,
case PROP_PAGE: case PROP_PAGE:
g_value_set_int (value, midori_panel_get_current_page (panel)); g_value_set_int (value, midori_panel_get_current_page (panel));
break; break;
case PROP_RIGHT_ALIGNED:
g_value_set_boolean (value, panel->right_aligned);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -341,6 +389,10 @@ midori_panel_set_right_aligned (MidoriPanel* panel,
box = gtk_widget_get_parent (panel->toolbar); box = gtk_widget_get_parent (panel->toolbar);
gtk_box_reorder_child (GTK_BOX (box), panel->toolbar, gtk_box_reorder_child (GTK_BOX (box), panel->toolbar,
right_aligned ? -1 : 0); 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 static void