Implement a context menu for extensions in the extension panel
This commit is contained in:
parent
7bd151a3e9
commit
5a748a36ad
1 changed files with 149 additions and 0 deletions
|
@ -343,6 +343,149 @@ midori_extensions_treeview_cursor_changed_cb (GtkTreeView* treeview,
|
|||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
midori_extensions_preferences_activate_cb (GtkWidget* menuitem,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
MidoriExtension* extension;
|
||||
|
||||
extension = g_object_get_data (G_OBJECT (menuitem), "MidoriExtension");
|
||||
g_return_if_fail (extension != NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
midori_extensions_website_activate_cb (GtkWidget* menuitem,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
gchar* uri;
|
||||
gint n;
|
||||
MidoriBrowser* browser;
|
||||
|
||||
MidoriExtension* extension;
|
||||
|
||||
extension = g_object_get_data (G_OBJECT (menuitem), "MidoriExtension");
|
||||
g_return_if_fail (extension != NULL);
|
||||
uri = katze_object_get_string (extension, "website");
|
||||
|
||||
browser = midori_browser_get_for_widget (GTK_WIDGET (extensions));
|
||||
n = midori_browser_add_uri (browser, uri);
|
||||
midori_browser_set_current_page (browser, n);
|
||||
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
static void
|
||||
midori_extensions_about_activate_cb (GtkWidget* menuitem,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
MidoriExtension* extension;
|
||||
|
||||
extension = g_object_get_data (G_OBJECT (menuitem), "MidoriExtension");
|
||||
g_return_if_fail (extension != NULL);
|
||||
}
|
||||
|
||||
static GtkWidget*
|
||||
midori_extensions_popup_menu_item (GtkMenu* menu,
|
||||
const gchar* stock_id,
|
||||
const gchar* label,
|
||||
MidoriExtension* extension,
|
||||
gpointer callback,
|
||||
gboolean enabled,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
GtkWidget* menuitem;
|
||||
|
||||
menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL);
|
||||
if (label)
|
||||
gtk_label_set_text_with_mnemonic (GTK_LABEL (gtk_bin_get_child (
|
||||
GTK_BIN (menuitem))), label);
|
||||
|
||||
if (!enabled)
|
||||
gtk_widget_set_sensitive (menuitem, FALSE);
|
||||
|
||||
g_object_set_data (G_OBJECT (menuitem), "MidoriExtension", extension);
|
||||
|
||||
if (callback)
|
||||
g_signal_connect (menuitem, "activate", G_CALLBACK (callback), extensions);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
|
||||
gtk_widget_show (menuitem);
|
||||
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
static void
|
||||
midori_extensions_popup (GtkWidget* widget,
|
||||
GdkEventButton* event,
|
||||
MidoriExtension* extension,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
GtkWidget* menu;
|
||||
gchar* website;
|
||||
|
||||
website = katze_object_get_string (extension, "website");
|
||||
|
||||
menu = gtk_menu_new ();
|
||||
midori_extensions_popup_menu_item (GTK_MENU (menu), GTK_STOCK_PREFERENCES, NULL, extension,
|
||||
midori_extensions_preferences_activate_cb, FALSE,
|
||||
extensions);
|
||||
midori_extensions_popup_menu_item (GTK_MENU (menu), GTK_STOCK_HOME, NULL, extension,
|
||||
midori_extensions_website_activate_cb, website != NULL,
|
||||
extensions);
|
||||
midori_extensions_popup_menu_item (GTK_MENU (menu), GTK_STOCK_ABOUT, NULL, extension,
|
||||
midori_extensions_about_activate_cb, FALSE,
|
||||
extensions);
|
||||
|
||||
sokoke_widget_popup (widget, GTK_MENU (menu),
|
||||
event, SOKOKE_MENU_POSITION_CURSOR);
|
||||
|
||||
g_free (website);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
midori_extensions_popup_menu_cb (GtkWidget* widget,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
||||
{
|
||||
MidoriExtension *extension;
|
||||
|
||||
gtk_tree_model_get (model, &iter, 0, &extension, -1);
|
||||
|
||||
midori_extensions_popup (widget, NULL, extension, extensions);
|
||||
g_object_unref (extension);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
midori_extensions_button_press_event_cb (GtkWidget* widget,
|
||||
GdkEventButton* event,
|
||||
MidoriExtensions* extensions)
|
||||
{
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (event->button != 2 && event->button != 3)
|
||||
return FALSE;
|
||||
|
||||
if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter))
|
||||
{
|
||||
MidoriExtension *extension;
|
||||
|
||||
gtk_tree_model_get (model, &iter, 0, &extension, -1);
|
||||
|
||||
midori_extensions_popup (widget, event, extension, extensions);
|
||||
g_object_unref (extension);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
midori_extensions_init (MidoriExtensions* extensions)
|
||||
{
|
||||
|
@ -372,6 +515,12 @@ midori_extensions_init (MidoriExtensions* extensions)
|
|||
g_signal_connect (extensions->treeview, "cursor-changed",
|
||||
G_CALLBACK (midori_extensions_treeview_cursor_changed_cb),
|
||||
extensions);
|
||||
g_signal_connect (extensions->treeview, "button-press-event",
|
||||
G_CALLBACK (midori_extensions_button_press_event_cb),
|
||||
extensions);
|
||||
g_signal_connect (extensions->treeview, "popup-menu",
|
||||
G_CALLBACK (midori_extensions_popup_menu_cb),
|
||||
extensions);
|
||||
gtk_widget_show (extensions->treeview);
|
||||
gtk_box_pack_start (GTK_BOX (extensions), extensions->treeview, TRUE, TRUE, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue