From: Christian Dywan Date: Sun, 26 Jul 2009 20:00:10 +0000 (+0200) Subject: Implement Options menu via a button on the side panel X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef785dd7842a5fe2fb06b883cac9359b92f4f2cf;p=midori Implement Options menu via a button on the side panel The new button is visible on all panels and pops up a menu, which allows toggling the panel titles and the operating controls. A new signal "populate-option-menu" makes it extendible. --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 0f65fe07..77856a00 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -180,6 +180,11 @@ GtkWidget* midori_panel_construct_menu_item (MidoriPanel* panel, MidoriViewable* viewable); +static void +midori_browser_settings_notify (MidoriWebSettings* web_settings, + GParamSpec* pspec, + MidoriBrowser* browser); + static GtkAction* _action_by_name (MidoriBrowser* browser, const gchar* name) @@ -3957,6 +3962,38 @@ midori_panel_notify_page_cb (MidoriPanel* panel, g_object_set (browser->settings, "last-panel-page", page, NULL); } +static void +midori_panel_notify_show_titles_cb (MidoriPanel* panel, + GParamSpec* pspec, + MidoriBrowser* browser) +{ + gboolean show_titles = katze_object_get_boolean (panel, "show-titles"); + if (browser->settings) + { + g_signal_handlers_block_by_func (browser->settings, + midori_browser_settings_notify, browser); + g_object_set (browser->settings, "compact-sidepanel", !show_titles, NULL); + g_signal_handlers_unblock_by_func (browser->settings, + midori_browser_settings_notify, browser); + } +} + +static void +midori_panel_notify_show_controls_cb (MidoriPanel* panel, + GParamSpec* pspec, + MidoriBrowser* browser) +{ + gboolean show_controls = katze_object_get_boolean (panel, "show-controls"); + if (browser->settings) + { + g_signal_handlers_block_by_func (browser->settings, + midori_browser_settings_notify, browser); + g_object_set (browser->settings, "show-panel-controls", show_controls, NULL); + g_signal_handlers_unblock_by_func (browser->settings, + midori_browser_settings_notify, browser); + } +} + static void midori_panel_notify_right_aligned_cb (MidoriPanel* panel, GParamSpec* pspec, @@ -5014,12 +5051,18 @@ 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", - G_CALLBACK (midori_panel_close_cb), browser); + g_object_connect (browser->panel, + "signal::notify::page", + midori_panel_notify_page_cb, browser, + "signal::notify::show-titles", + midori_panel_notify_show_titles_cb, browser, + "signal::notify::show-controls", + midori_panel_notify_show_controls_cb, browser, + "signal::notify::right-aligned", + midori_panel_notify_right_aligned_cb, browser, + "signal::close", + midori_panel_close_cb, browser, + NULL); gtk_paned_pack1 (GTK_PANED (hpaned), browser->panel, FALSE, FALSE); /* Notebook, containing all views */ @@ -5317,7 +5360,7 @@ _midori_browser_update_settings (MidoriBrowser* browser) gboolean remember_last_window_size; gint last_window_width, last_window_height; MidoriWindowState last_window_state; - gboolean compact_sidepanel, right_align_sidepanel; + gboolean compact_sidepanel, show_panel_controls, right_align_sidepanel; gint last_panel_position, last_panel_page; gboolean show_menubar, show_bookmarkbar; gboolean show_panel, show_transferbar; @@ -5338,6 +5381,7 @@ _midori_browser_update_settings (MidoriBrowser* browser) "last-window-height", &last_window_height, "last-window-state", &last_window_state, "compact-sidepanel", &compact_sidepanel, + "show-panel-controls", &show_panel_controls, "right-align-sidepanel", &right_align_sidepanel, "last-panel-position", &last_panel_position, "last-panel-page", &last_panel_page, @@ -5411,9 +5455,9 @@ _midori_browser_update_settings (MidoriBrowser* browser) } } - midori_panel_set_compact (MIDORI_PANEL (browser->panel), compact_sidepanel); - midori_panel_set_right_aligned (MIDORI_PANEL (browser->panel), - right_align_sidepanel); + g_object_set (browser->panel, "show-titles", !compact_sidepanel, + "show-controls", show_panel_controls, + "right-aligned", right_align_sidepanel, NULL); gtk_paned_set_position (GTK_PANED (gtk_widget_get_parent (browser->panel)), last_panel_position); /* The browser may not yet be visible, which means that we can't set the @@ -5457,8 +5501,11 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings, else if (name == g_intern_string ("toolbar-items")) _midori_browser_set_toolbar_items (browser, g_value_get_string (&value)); else if (name == g_intern_string ("compact-sidepanel")) - midori_panel_set_compact (MIDORI_PANEL (browser->panel), - g_value_get_boolean (&value)); + g_object_set (browser->panel, "show-titles", + !g_value_get_boolean (&value), NULL); + else if (name == g_intern_string ("show-controls")) + g_object_set (browser->panel, "show-controls", + g_value_get_boolean (&value), NULL); else if (name == g_intern_string ("always-show-tabbar")) _toggle_tabbar_smartly (browser); else if (name == g_intern_string ("show-navigationbar")) diff --git a/midori/midori-panel.c b/midori/midori-panel.c index 655118c4..f1cb0487 100644 --- a/midori/midori-panel.c +++ b/midori/midori-panel.c @@ -23,6 +23,7 @@ struct _MidoriPanel { GtkHBox parent_instance; + GtkWidget* labelbar; GtkWidget* toolbar; GtkToolItem* button_align; GtkToolItem* button_detach; @@ -32,6 +33,8 @@ struct _MidoriPanel GtkWidget* notebook; GtkMenu* menu; + gboolean show_titles; + gboolean show_controls; gboolean right_aligned; }; @@ -53,6 +56,8 @@ enum PROP_SHADOW_TYPE, PROP_MENU, PROP_PAGE, + PROP_SHOW_TITLES, + PROP_SHOW_CONTROLS, PROP_RIGHT_ALIGNED, }; @@ -160,6 +165,38 @@ midori_panel_class_init (MidoriPanelClass* class) -1, G_MAXINT, -1, flags)); + /** + * MidoriWebSettings:show-titles: + * + * Whether to show panel titles. + * + * Since: 0.1.9 + */ + g_object_class_install_property (gobject_class, + PROP_SHOW_TITLES, + g_param_spec_boolean ( + "show-titles", + "Show Titles", + "Whether to show panel titles", + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * MidoriWebSettings:show-controls: + * + * Whether to show operating controls. + * + * Since: 0.1.9 + */ + g_object_class_install_property (gobject_class, + PROP_SHOW_CONTROLS, + g_param_spec_boolean ( + "show-controls", + "Show Controls", + "Whether to show operating controls", + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** * MidoriWebSettings:right-aligned: * @@ -310,6 +347,8 @@ midori_panel_init (MidoriPanel* panel) GtkWidget* labelbar; GtkToolItem* toolitem; + panel->show_titles = TRUE; + panel->show_controls = TRUE; panel->right_aligned = FALSE; /* Create the sidebar */ @@ -326,6 +365,7 @@ midori_panel_init (MidoriPanel* panel) /* Create the titlebar */ labelbar = gtk_toolbar_new (); + panel->labelbar = labelbar; gtk_toolbar_set_icon_size (GTK_TOOLBAR (labelbar), GTK_ICON_SIZE_MENU); gtk_toolbar_set_style (GTK_TOOLBAR (labelbar), GTK_TOOLBAR_ICONS); toolitem = gtk_tool_item_new (); @@ -417,6 +457,19 @@ midori_panel_set_property (GObject* object, case PROP_PAGE: midori_panel_set_current_page (panel, g_value_get_int (value)); break; + case PROP_SHOW_TITLES: + panel->show_titles = g_value_get_boolean (value); + #if HAVE_HILDON + panel->show_titles = TRUE; + #endif + gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), + panel->show_titles ? GTK_TOOLBAR_BOTH : GTK_TOOLBAR_ICONS); + break; + case PROP_SHOW_CONTROLS: + panel->show_controls = g_value_get_boolean (value); + sokoke_widget_set_visible (panel->labelbar, panel->show_controls); + sokoke_widget_set_visible (panel->toolbar, panel->show_controls); + break; case PROP_RIGHT_ALIGNED: midori_panel_set_right_aligned (panel, g_value_get_boolean (value)); break; @@ -446,6 +499,12 @@ midori_panel_get_property (GObject* object, case PROP_PAGE: g_value_set_int (value, midori_panel_get_current_page (panel)); break; + case PROP_SHOW_TITLES: + g_value_set_boolean (value, panel->show_titles); + break; + case PROP_SHOW_CONTROLS: + g_value_set_boolean (value, panel->show_controls); + break; case PROP_RIGHT_ALIGNED: g_value_set_boolean (value, panel->right_aligned); break; @@ -476,6 +535,8 @@ midori_panel_new (void) * @compact: %TRUE if the panel should be compact * * Determines if the panel should be compact. + * + * Deprecated: 0.1.9 **/ void midori_panel_set_compact (MidoriPanel* panel, @@ -483,11 +544,7 @@ midori_panel_set_compact (MidoriPanel* panel, { g_return_if_fail (MIDORI_IS_PANEL (panel)); - #if HAVE_HILDON - compact = TRUE; - #endif - gtk_toolbar_set_style (GTK_TOOLBAR (panel->toolbar), - compact ? GTK_TOOLBAR_ICONS : GTK_TOOLBAR_BOTH); + g_object_set (panel, "show-titles", !compact, NULL); } /** @@ -610,6 +667,54 @@ midori_panel_construct_tool_item (MidoriPanel* panel, return toolitem; } +static void +midori_panel_show_titles_toggled_cb (GtkWidget* menuitem, + MidoriPanel* panel) +{ + g_object_set (panel, "show-titles", !panel->show_titles, NULL); +} + +static void +midori_panel_show_controls_toggled_cb (GtkWidget* menuitem, + MidoriPanel* panel) +{ + g_object_set (panel, "show-controls", !panel->show_controls, NULL); +} + +static void +midori_panel_options_clicked_cb (GtkToolItem* toolitem, + MidoriPanel* panel) +{ + gint n; + GtkWidget* viewable; + GtkWidget* menu; + GtkWidget* menuitem; + + n = midori_panel_get_current_page (panel); + viewable = midori_panel_get_nth_page (panel, n); + menu = gtk_menu_new (); + #if !HAVE_HILDON + menuitem = gtk_check_menu_item_new_with_mnemonic (_("Show panel _titles")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), + panel->show_titles); + g_signal_connect (menuitem, "toggled", + G_CALLBACK (midori_panel_show_titles_toggled_cb), panel); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + gtk_widget_show (menuitem); + #endif + menuitem = gtk_check_menu_item_new_with_mnemonic (_("Show operating _controls")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), + panel->show_controls); + g_signal_connect (menuitem, "toggled", + G_CALLBACK (midori_panel_show_controls_toggled_cb), panel); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); + gtk_widget_show (menuitem); + g_signal_emit_by_name (viewable, "populate-option-menu", menu); + + katze_widget_popup (GTK_WIDGET (toolitem), GTK_MENU (menu), + NULL, SOKOKE_MENU_POSITION_LEFT); +} + /** * midori_panel_append_page: * @panel: a #MidoriPanel @@ -636,6 +741,7 @@ midori_panel_append_page (MidoriPanel* panel, GObjectClass* gobject_class; GtkWidget* widget; GtkWidget* toolbar; + GtkToolItem* toolitem; const gchar* label; guint n; @@ -666,6 +772,12 @@ midori_panel_append_page (MidoriPanel* panel, gtk_container_add (GTK_CONTAINER (panel->notebook), scrolled); toolbar = midori_viewable_get_toolbar (viewable); + toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_PROPERTIES); + gtk_tool_item_set_tooltip_text (toolitem, _("Options")); + g_signal_connect (toolitem, "clicked", + G_CALLBACK (midori_panel_options_clicked_cb), panel); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, 0); + gtk_widget_show (GTK_WIDGET (toolitem)); gtk_widget_show (toolbar); gtk_container_add (GTK_CONTAINER (panel->toolbook), toolbar); g_signal_connect (viewable, "destroy", diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index 50ee3871..ada6ad5d 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -562,11 +562,9 @@ midori_preferences_set_settings (MidoriPreferences* preferences, #if !HAVE_HILDON button = katze_property_proxy (settings, "middle-click-opens-selection", NULL); INDENTED_ADD (button, 0, 1, 3, 4); - button = katze_property_proxy (settings, "compact-sidepanel", NULL); - WIDGET_ADD (button, 1, 2, 3, 4); + button = katze_property_proxy (settings, "open-popups-in-tabs", NULL); + SPANNED_ADD (button, 1, 2, 3, 4); #endif - /* button = katze_property_proxy (settings, "open-popups-in-tabs", NULL); - SPANNED_ADD (button, 0, 1, 4, 5);*/ button = katze_property_proxy (settings, "open-tabs-next-to-current", NULL); WIDGET_ADD (button, 0, 1, 5, 6); button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL); diff --git a/midori/midori-viewable.c b/midori/midori-viewable.c index 7d43ea28..2425ad39 100644 --- a/midori/midori-viewable.c +++ b/midori/midori-viewable.c @@ -13,6 +13,14 @@ #include +enum { + POPULATE_OPTION_MENU, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + static void midori_viewable_base_init (MidoriViewableIface* iface); @@ -68,6 +76,27 @@ midori_viewable_base_init (MidoriViewableIface* iface) if (initialized) return; + /** + * MidoriViewable::populate-option-menu: + * @viewable: the object on which the signal is emitted + * @menu: the #GtkMenu to populate + * + * Emitted when an Option menu is displayed, for instance + * when the user clicks the Options button in the panel. + * + * Since: 0.1.9 + */ + signals[POPULATE_OPTION_MENU] = g_signal_new ( + "populate-option-menu", + G_TYPE_FROM_INTERFACE (iface), + (GSignalFlags)(G_SIGNAL_RUN_LAST), + 0, + 0, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + GTK_TYPE_MENU); + iface->p = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); iface->get_stock_id = midori_viewable_default_get_stock_id; @@ -258,6 +287,6 @@ midori_viewable_get_toolbar (MidoriViewable* viewable) toolbar = MIDORI_VIEWABLE_GET_IFACE (viewable)->get_toolbar (viewable); if (!toolbar) - toolbar = gtk_event_box_new (); + toolbar = gtk_toolbar_new (); return toolbar; } diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index d08aba92..9b0aba94 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -48,6 +48,7 @@ struct _MidoriWebSettings gboolean search_engines_in_completion; gchar* toolbar_items; gboolean compact_sidepanel; + gboolean show_panel_controls; gboolean right_align_sidepanel; MidoriStartup load_on_startup; @@ -123,6 +124,7 @@ enum PROP_SEARCH_ENGINES_IN_COMPLETION, PROP_TOOLBAR_ITEMS, PROP_COMPACT_SIDEPANEL, + PROP_SHOW_PANEL_CONTROLS, PROP_RIGHT_ALIGN_SIDEPANEL, PROP_LOAD_ON_STARTUP, @@ -529,6 +531,22 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class) FALSE, flags)); + /** + * MidoriWebSettings:show-panel-controls: + * + * Whether to show the operating controls of the panel. + * + * Since: 0.1.9 + */ + g_object_class_install_property (gobject_class, + PROP_SHOW_PANEL_CONTROLS, + g_param_spec_boolean ( + "show-panel-controls", + _("Show operating controls of the panel"), + _("Whether to show the operating controls of the panel"), + TRUE, + flags)); + /** * MidoriWebSettings:right-sidepanel: * @@ -1000,6 +1018,7 @@ midori_web_settings_init (MidoriWebSettings* web_settings) web_settings->notify_transfer_completed = TRUE; web_settings->download_folder = g_strdup (midori_get_download_dir ()); web_settings->http_proxy = NULL; + web_settings->show_panel_controls = TRUE; web_settings->open_popups_in_tabs = TRUE; web_settings->remember_last_form_inputs = TRUE; web_settings->remember_last_downloaded_files = TRUE; @@ -1174,6 +1193,9 @@ midori_web_settings_set_property (GObject* object, case PROP_COMPACT_SIDEPANEL: web_settings->compact_sidepanel = g_value_get_boolean (value); break; + case PROP_SHOW_PANEL_CONTROLS: + web_settings->show_panel_controls = g_value_get_boolean (value); + break; case PROP_RIGHT_ALIGN_SIDEPANEL: web_settings->right_align_sidepanel = g_value_get_boolean (value); break; @@ -1386,6 +1408,9 @@ midori_web_settings_get_property (GObject* object, case PROP_COMPACT_SIDEPANEL: g_value_set_boolean (value, web_settings->compact_sidepanel); break; + case PROP_SHOW_PANEL_CONTROLS: + g_value_set_boolean (value, web_settings->show_panel_controls); + break; case PROP_RIGHT_ALIGN_SIDEPANEL: g_value_set_boolean (value, web_settings->right_align_sidepanel); break;