From: Przemek Sitek Date: Fri, 5 Jun 2009 21:55:00 +0000 (+0200) Subject: Implement a context menu for extensions in the extension panel X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a748a36ad2535ea89932f320ef873dd515d9f1e;p=midori Implement a context menu for extensions in the extension panel --- diff --git a/panels/midori-extensions.c b/panels/midori-extensions.c index 1b06a72b..5a18ba85 100644 --- a/panels/midori-extensions.c +++ b/panels/midori-extensions.c @@ -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); }