Extensions used to look for the menu and append items manually.
In order to show Tools in the Compact menu a proper signal
is needed.
Adblock, Shortcuts and Toolbar Editor are ported to the new API.
return dst;
}
+static void
+adblock_browser_populate_tool_menu_cb (MidoriBrowser* browser,
+ GtkWidget* menu,
+ MidoriExtension* extension);
+
static void
adblock_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser,
static void
adblock_deactivate_cb (MidoriExtension* extension,
- GtkWidget* menuitem)
+ MidoriBrowser* browser)
{
MidoriApp* app = midori_extension_get_app (extension);
- gtk_widget_destroy (menuitem);
g_signal_handlers_disconnect_by_func (
- extension, adblock_deactivate_cb, menuitem);
+ browser, adblock_browser_populate_tool_menu_cb, extension);
+ g_signal_handlers_disconnect_by_func (
+ extension, adblock_deactivate_cb, browser);
g_signal_handlers_disconnect_by_func (
app, adblock_app_add_browser_cb, extension);
/* FIXME: Disconnect session callbacks */
}
static void
-adblock_app_add_browser_cb (MidoriApp* app,
- MidoriBrowser* browser,
- MidoriExtension* extension)
+adblock_browser_populate_tool_menu_cb (MidoriBrowser* browser,
+ GtkWidget* menu,
+ MidoriExtension* extension)
{
- GtkWidget* panel;
- GtkWidget* menu;
GtkWidget* menuitem;
- panel = katze_object_get_object (browser, "panel");
- menu = katze_object_get_object (panel, "menu");
menuitem = gtk_menu_item_new_with_mnemonic (_("Configure _Advertisement filters..."));
g_signal_connect (menuitem, "activate",
G_CALLBACK (adblock_menu_configure_filters_activate_cb), extension);
gtk_widget_show (menuitem);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 3);
- g_object_unref (menu);
- g_object_unref (panel);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+}
+static void
+adblock_app_add_browser_cb (MidoriApp* app,
+ MidoriBrowser* browser,
+ MidoriExtension* extension)
+{
+ g_signal_connect (browser, "populate-tool-menu",
+ G_CALLBACK (adblock_browser_populate_tool_menu_cb), extension);
g_signal_connect (extension, "deactivate",
- G_CALLBACK (adblock_deactivate_cb), menuitem);
+ G_CALLBACK (adblock_deactivate_cb), browser);
}
static gboolean
#include <midori/sokoke.h>
#include "config.h"
+static void
+shortcuts_browser_populate_tool_menu_cb (MidoriBrowser* browser,
+ GtkWidget* menu,
+ MidoriExtension* extension);
+
static void
shortcuts_app_add_browser_cb (MidoriApp* app,
MidoriBrowser* browser,
static void
shortcuts_deactivate_cb (MidoriExtension* extension,
- GtkWidget* menuitem)
+ MidoriBrowser* browser)
{
MidoriApp* app = midori_extension_get_app (extension);
- gtk_widget_destroy (menuitem);
g_signal_handlers_disconnect_by_func (
- extension, shortcuts_deactivate_cb, menuitem);
+ browser, shortcuts_browser_populate_tool_menu_cb, extension);
+ g_signal_handlers_disconnect_by_func (
+ extension, shortcuts_deactivate_cb, browser);
g_signal_handlers_disconnect_by_func (
app, shortcuts_app_add_browser_cb, extension);
}
}
static void
-shortcuts_app_add_browser_cb (MidoriApp* app,
- MidoriBrowser* browser,
- MidoriExtension* extension)
+shortcuts_browser_populate_tool_menu_cb (MidoriBrowser* browser,
+ GtkWidget* menu,
+ MidoriExtension* extension)
{
- GtkWidget* panel;
- GtkWidget* menu;
GtkWidget* menuitem;
- panel = katze_object_get_object (browser, "panel");
- menu = katze_object_get_object (panel, "menu");
- g_object_unref (panel);
menuitem = gtk_menu_item_new_with_mnemonic (_("Customize Sh_ortcuts..."));
g_signal_connect (menuitem, "activate",
G_CALLBACK (shortcuts_menu_configure_shortcuts_activate_cb), extension);
gtk_widget_show (menuitem);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem, 3);
- g_object_unref (menu);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+}
+static void
+shortcuts_app_add_browser_cb (MidoriApp* app,
+ MidoriBrowser* browser,
+ MidoriExtension* extension)
+{
+ g_signal_connect (browser, "populate-tool-menu",
+ G_CALLBACK (shortcuts_browser_populate_tool_menu_cb), extension);
g_signal_connect (extension, "deactivate",
- G_CALLBACK (shortcuts_deactivate_cb), menuitem);
+ G_CALLBACK (shortcuts_deactivate_cb), browser);
}
static void
};
static const gint tb_editor_dnd_targets_len = G_N_ELEMENTS(tb_editor_dnd_targets);
+static void tb_editor_browser_populate_tool_menu_cb(MidoriBrowser *browser, GtkWidget *menu, MidoriExtension *ext);
static void tb_editor_app_add_browser_cb(MidoriApp *app, MidoriBrowser *browser, MidoriExtension *ext);
-static void tb_editor_deactivate_cb(MidoriExtension *extension, GtkWidget *menuitem)
+static void tb_editor_deactivate_cb(MidoriExtension *extension, MidoriBrowser *browser)
{
MidoriApp *app = midori_extension_get_app(extension);
- gtk_widget_destroy(menuitem);
- g_signal_handlers_disconnect_by_func(extension, tb_editor_deactivate_cb, menuitem);
+ g_signal_handlers_disconnect_by_func(browser, tb_editor_browser_populate_tool_menu_cb, extension);
+ g_signal_handlers_disconnect_by_func(extension, tb_editor_deactivate_cb, browser);
g_signal_handlers_disconnect_by_func(app, tb_editor_app_add_browser_cb, extension);
}
g_free(tbw);
}
+static void tb_editor_browser_populate_tool_menu_cb(MidoriBrowser *browser, GtkWidget *menu, MidoriExtension *ext)
+{
+ GtkWidget *menuitem;
+
+ menuitem = gtk_menu_item_new_with_mnemonic (_("Customize _Toolbar..."));
+ g_signal_connect (menuitem, "activate",
+ G_CALLBACK (tb_editor_menu_configure_toolbar_activate_cb), browser);
+ gtk_widget_show (menuitem);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+}
static void tb_editor_app_add_browser_cb(MidoriApp *app, MidoriBrowser *browser, MidoriExtension *ext)
{
- GtkWidget *panel;
- GtkWidget *menu;
- GtkWidget *menuitem;
-
- panel = katze_object_get_object(browser, "panel");
- menu = katze_object_get_object(panel, "menu");
- g_object_unref(panel);
- menuitem = gtk_menu_item_new_with_mnemonic(_("Customize _Toolbar..."));
- g_signal_connect(menuitem, "activate",
- G_CALLBACK(tb_editor_menu_configure_toolbar_activate_cb), browser);
- gtk_widget_show(menuitem);
- gtk_menu_shell_insert(GTK_MENU_SHELL (menu), menuitem, 3);
- g_object_unref(menu);
-
- g_signal_connect(ext, "deactivate", G_CALLBACK(tb_editor_deactivate_cb), menuitem);
+ g_signal_connect(browser, "populate-tool-menu", G_CALLBACK(tb_editor_browser_populate_tool_menu_cb), ext);
+ g_signal_connect(ext, "deactivate", G_CALLBACK(tb_editor_deactivate_cb), browser);
}
CONTEXT_READY,
ADD_DOWNLOAD,
SEND_NOTIFICATION,
+ POPULATE_TOOL_MENU,
QUIT,
LAST_SIGNAL
_midori_browser_set_toolbar_style (MidoriBrowser* browser,
MidoriToolbarStyle toolbar_style);
+GtkWidget*
+midori_panel_construct_menu_item (MidoriPanel* panel,
+ MidoriViewable* viewable);
+
static GtkAction*
_action_by_name (MidoriBrowser* browser,
const gchar* name)
G_TYPE_STRING,
G_TYPE_STRING);
+ /**
+ * MidoriBrowser::populate-tool-menu:
+ * @browser: the object on which the signal is emitted
+ * @menu: the #GtkMenu to populate
+ *
+ * Emitted when a Tool menu is displayed, such as the
+ * toplevel Tools in the menubar or the compact menu.
+ *
+ * Since: 0.1.9
+ */
+ signals[POPULATE_TOOL_MENU] = g_signal_new (
+ "populate-tool-menu",
+ G_TYPE_FROM_CLASS (class),
+ (GSignalFlags)(G_SIGNAL_RUN_LAST),
+ 0,
+ 0,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GTK_TYPE_MENU);
+
signals[QUIT] = g_signal_new (
"quit",
G_TYPE_FROM_CLASS (class),
gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
}
+static void
+_action_tools_populate_popup (GtkAction* action,
+ GtkMenu* menu,
+ MidoriBrowser* browser)
+{
+ static const GtkActionEntry actions[] = {
+ { "ManageSearchEngines" },
+ { "ClearPrivateData" },
+ { "-" },
+ { NULL },
+ { "p" },
+ #ifdef G_OS_WIN32
+ { NULL },
+ { "Preferences" },
+ #endif
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (actions); i++)
+ {
+ GtkWidget* menuitem;
+ if (actions[i].name != NULL)
+ {
+ if (actions[i].name[0] == '-')
+ {
+ g_signal_emit (browser, signals[POPULATE_TOOL_MENU], 0, menu);
+ continue;
+ }
+ else if (actions[i].name[0] == 'p')
+ {
+ MidoriPanel* panel;
+ gsize j;
+ GtkWidget* widget;
+
+ panel = MIDORI_PANEL (browser->panel);
+ j = 0;
+ while ((widget = midori_panel_get_nth_page (panel, j++)))
+ {
+ menuitem = midori_panel_construct_menu_item (panel, MIDORI_VIEWABLE (widget));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+ }
+ continue;
+ }
+ menuitem = sokoke_action_create_popup_menu_item (
+ _action_by_name (browser, actions[i].name));
+ }
+ else
+ menuitem = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+ gtk_widget_show (menuitem);
+ }
+}
+
static gboolean
_action_menus_activate_item_alt (GtkAction* action,
KatzeItem* item,
{ "TabNew" },
{ "WindowNew" },
{ "Open" },
- { "PrivateBrowsing" },
{ "Print" },
+ { "PrivateBrowsing" },
{ NULL },
{ "Bookmarkbar" },
{ "Panel" },
{ "Statusbar" },
{ NULL },
+ { "-" },
{ "ClearPrivateData" },
{ "Fullscreen" },
{ "Preferences" },
{
GtkWidget* menuitem;
if (actions[i].name != NULL)
+ {
+ if (actions[i].name[0] == '-')
+ {
+ g_signal_emit (browser, signals[POPULATE_TOOL_MENU], 0, menu);
+ continue;
+ }
menuitem = sokoke_action_create_popup_menu_item (
_action_by_name (browser, actions[i].name));
+ }
else
menuitem = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+ gtk_widget_show (menuitem);
}
-
- gtk_widget_show_all (GTK_WIDGET (menu));
}
static void
{ "BookmarkFolderAdd", NULL,
N_("Add a new _folder"), "",
N_("Add a new bookmark folder"), G_CALLBACK (_action_bookmark_folder_add_activate) },
- { "Tools", NULL, N_("_Tools") },
{ "ManageSearchEngines", GTK_STOCK_PROPERTIES,
N_("_Manage Search Engines"), "<Ctrl><Alt>s",
N_("Add, edit and remove search engines..."),
"<menuitem action='RecentlyVisited'/>"
"</menu>"
"<menuitem action='Bookmarks'/>"
- "<menu action='Tools'>"
- "<menuitem action='ManageSearchEngines'/>"
- "<menuitem action='ClearPrivateData'/>"
- /* Panel items shall be appended here */
- #ifdef G_OS_WIN32
- "<separator/>"
- "<menuitem action='Preferences'/>"
- #endif
- "</menu>"
+ "<menuitem action='Tools'/>"
"<menuitem action='Window'/>"
"<menu action='Help'>"
"<menuitem action='HelpContents'/>"
"<menuitem action='FindPrevious'/>"
"<menuitem action='BookmarkAdd'/>"
"<menuitem action='BookmarkFolderAdd'/>"
+ "<menuitem action='ManageSearchEngines'/>"
+ "<menuitem action='ClearPrivateData'/>"
"<menuitem action='TabPrevious'/>"
"<menuitem action='TabNext'/>"
"<menuitem action='UndoTabClose'/>"
"<menuitem action='TrashEmpty'/>"
+ "<menuitem action='Preferences'/>"
"</menu>"
"</menubar>"
"<toolbar name='toolbar_navigation'>"
gtk_action_group_add_action_with_accel (browser->action_group, action, "");
g_object_unref (action);
+ action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
+ "name", "Tools",
+ "label", _("_Tools"),
+ "array", katze_array_new (KATZE_TYPE_ITEM),
+ NULL);
+ g_object_connect (action,
+ "signal::populate-popup",
+ _action_tools_populate_popup, browser,
+ NULL);
+ gtk_action_group_add_action (browser->action_group, action);
+ g_object_unref (action);
+
action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
"name", "Window",
"label", _("_Window"),
gtk_widget_set_sensitive (menuitem, FALSE);
gtk_menu_item_set_right_justified (GTK_MENU_ITEM (menuitem), TRUE);
gtk_menu_shell_append (GTK_MENU_SHELL (browser->menubar), menuitem);
- browser->menu_tools = gtk_menu_item_get_submenu (GTK_MENU_ITEM (
- gtk_ui_manager_get_widget (ui_manager, "/menubar/Tools")));
- menuitem = gtk_separator_menu_item_new ();
- gtk_widget_show (menuitem);
- gtk_menu_shell_insert (GTK_MENU_SHELL (browser->menu_tools), menuitem, 3);
+ browser->menu_tools = gtk_menu_new ();
homepage = gtk_ui_manager_get_widget (ui_manager, "/menubar/Go/Homepage");
g_signal_connect (homepage, "button-press-event",
GTK_SHADOW_NONE,
flags));
+ /**
+ * MidoriWebSettings:menu:
+ *
+ * This is the menu that holds the panel menu items.
+ *
+ * You shouldn't use this menu or add items.
+ *
+ * Deprecated: 0.1.9
+ */
g_object_class_install_property (gobject_class,
PROP_MENU,
g_param_spec_object (
break;
case PROP_MENU:
katze_object_assign (panel->menu, g_value_dup_object (value));
- /* FIXME: Move existing items to the new menu */
break;
case PROP_PAGE:
midori_panel_set_current_page (panel, g_value_get_int (value));
MidoriPanel* panel)
{
GtkWidget* child;
- GtkToggleToolButton* toolitem;
+ GtkToolItem* toolitem;
guint n;
child = g_object_get_data (G_OBJECT (widget), "page");
- toolitem = g_object_get_data (G_OBJECT (widget), "toolitem");
+ n = midori_panel_page_num (panel, child);
+ toolitem = gtk_toolbar_get_nth_item (GTK_TOOLBAR (panel->toolbar), n);
if (toolitem)
{
/* Unsetting the button before setting it ensures that
it will emit signals even if it was active before */
- gtk_toggle_tool_button_set_active (toolitem, FALSE);
- gtk_toggle_tool_button_set_active (toolitem, TRUE);
- }
- else
- {
- n = midori_panel_page_num (panel, child);
- midori_panel_set_current_page (panel, n);
- g_signal_emit (panel, signals[SWITCH_PAGE], 0, n);
- gtk_widget_show (GTK_WIDGET (panel));
+ GtkToggleToolButton* button = GTK_TOGGLE_TOOL_BUTTON (toolitem);
+ g_signal_handlers_block_by_func (widget,
+ midori_panel_menu_item_activate_cb, panel);
+ gtk_toggle_tool_button_set_active (button, FALSE);
+ gtk_toggle_tool_button_set_active (button, TRUE);
+ g_signal_handlers_unblock_by_func (widget,
+ midori_panel_menu_item_activate_cb, panel);
}
+
+ midori_panel_set_current_page (panel, n);
+ g_signal_emit (panel, signals[SWITCH_PAGE], 0, n);
+ gtk_widget_show (GTK_WIDGET (panel));
+}
+
+/* Private function, used by MidoriBrowser */
+/* static */ GtkWidget*
+midori_panel_construct_menu_item (MidoriPanel* panel,
+ MidoriViewable* viewable)
+{
+ const gchar* stock_id;
+ GtkWidget* menuitem;
+
+ stock_id = midori_viewable_get_stock_id (viewable);
+ menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
+ gtk_widget_show (menuitem);
+ g_object_set_data (G_OBJECT (menuitem), "page", viewable);
+ g_signal_connect (menuitem, "activate",
+ G_CALLBACK (midori_panel_menu_item_activate_cb), panel);
+ return menuitem;
}
static void
GtkWidget* widget;
GtkWidget* toolbar;
const gchar* label;
- const gchar* stock_id;
- GtkToolItem* toolitem;
- GtkWidget* menuitem;
guint n;
g_return_val_if_fail (MIDORI_IS_PANEL (panel), -1);
n = midori_panel_page_num (panel, scrolled);
label = midori_viewable_get_label (viewable);
- stock_id = midori_viewable_get_stock_id (viewable);
-
- toolitem = midori_panel_construct_tool_item (panel, viewable);
-
- if (panel->menu)
- {
- menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
- gtk_widget_show (menuitem);
- g_object_set_data (G_OBJECT (menuitem), "page", viewable);
- g_object_set_data (G_OBJECT (menuitem), "toolitem", toolitem);
- g_signal_connect (menuitem, "activate",
- G_CALLBACK (midori_panel_menu_item_activate_cb),
- panel);
- gtk_menu_shell_insert (GTK_MENU_SHELL (panel->menu), menuitem, 4);
- g_object_set_data (G_OBJECT (scrolled), "panel-menuitem", menuitem);
- g_signal_connect (viewable, "destroy",
- G_CALLBACK (midori_panel_widget_destroy_cb), menuitem);
- }
g_object_set_data (G_OBJECT (viewable), "parent", scrolled);
+ midori_panel_construct_tool_item (panel, viewable);
g_signal_connect (viewable, "destroy",
G_CALLBACK (midori_panel_viewable_destroy_cb), panel);