/* * The original GMenu is modified adding to the section @submodel_name * the items in @gmenu_to_merge. * @gmenu_to_merge should be a list of menu items. */ void nautilus_gmenu_merge (GMenu *original, GMenu *gmenu_to_merge, const gchar *submodel_name, gboolean prepend) { gint i, n_items; GMenuModel *submodel; GMenuItem *item; g_return_if_fail (G_IS_MENU (original)); g_return_if_fail (G_IS_MENU (gmenu_to_merge)); submodel = find_gmenu_model (G_MENU_MODEL (original), submodel_name); g_return_if_fail (submodel != NULL); n_items = g_menu_model_get_n_items (G_MENU_MODEL (gmenu_to_merge)); for (i = 0; i < n_items; i++) { item = g_menu_item_new_from_model (G_MENU_MODEL (gmenu_to_merge), i); if (prepend) { g_menu_prepend_item (G_MENU (submodel), item); } else { g_menu_append_item (G_MENU (submodel), item); } g_object_unref (item); } g_object_unref (submodel); }
static void gb_project_tree_builder_node_popup (IdeTreeBuilder *builder, IdeTreeNode *node, GMenu *menu) { GObject *item; IdeVcs *vcs; GFile *workdir; GFile *file; g_assert (GB_IS_PROJECT_TREE_BUILDER (builder)); g_assert (IDE_IS_TREE_NODE (node)); g_assert (G_IS_MENU (menu)); item = ide_tree_node_get_item (node); vcs = get_vcs (node); workdir = ide_vcs_get_working_directory (vcs); if (GB_IS_PROJECT_FILE (item) && (file = gb_project_file_get_file (GB_PROJECT_FILE (item))) && !g_file_equal (file, workdir)) { GMenu *mime_section; mime_section = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "gb-project-tree-open-by-mime-section"); populate_mime_handlers (mime_section, GB_PROJECT_FILE (item)); } }
/* * The GMenu @menu is modified adding to the section @submodel_name * the item @item. */ void nautilus_gmenu_add_item_in_submodel (GMenu *menu, GMenuItem *item, const gchar *submodel_name, gboolean prepend) { GMenuModel *submodel; g_return_if_fail (G_IS_MENU (menu)); g_return_if_fail (G_IS_MENU_ITEM (item)); submodel = find_gmenu_model (G_MENU_MODEL (menu), submodel_name); g_return_if_fail (submodel != NULL); if (prepend) { g_menu_prepend_item (G_MENU (submodel), item); } else { g_menu_append_item (G_MENU (submodel), item); } g_object_unref (submodel); }
static void impl_deactivate (EogWindowActivatable *activatable) { EogPostrPlugin *plugin = EOG_POSTR_PLUGIN (activatable); GMenu *menu; GMenuModel *model; gint i; eog_debug (DEBUG_PLUGINS); menu = eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (menu)); /* Remove menu entry */ model = G_MENU_MODEL (menu); for (i = 0; i < g_menu_model_get_n_items (model); i++) { gchar *id; if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) { const gboolean found = (g_strcmp0 (id, EOG_POSTR_PLUGIN_MENU_ID) == 0); g_free (id); if (found) { g_menu_remove (menu, i); break; } } } /* Finally remove action */ g_action_map_remove_action (G_ACTION_MAP (plugin->window), EOG_POSTR_PLUGIN_ACTION); }
void _ide_tree_builder_node_popup (IdeTreeBuilder *builder, IdeTreeNode *node, GMenu *menu) { g_return_if_fail (IDE_IS_TREE_BUILDER (builder)); g_return_if_fail (IDE_IS_TREE_NODE (node)); g_return_if_fail (G_IS_MENU (menu)); g_signal_emit (builder, signals [NODE_POPUP], 0, node, menu); }
GtkWidget* eog_zoom_entry_new(EogScrollView *view, GMenu *menu) { g_return_val_if_fail (EOG_IS_SCROLL_VIEW (view), NULL); g_return_val_if_fail (G_IS_MENU (menu), NULL); return g_object_new (EOG_TYPE_ZOOM_ENTRY, "scroll-view", view, "menu", menu, NULL); }
static void impl_activate (EogWindowActivatable *activatable) { const gchar * const accel_keys[] = { "W", NULL }; EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (activatable); GMenu *model, *menu; GMenuItem *item; GSimpleAction *action; GAction *ref_action; model= eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (model)); /* Setup and inject action */ action = g_simple_action_new (EOG_FIT_TO_WIDTH_PLUGIN_ACTION, NULL); g_signal_connect(action, "activate", G_CALLBACK (fit_to_width_cb), plugin->window); g_action_map_add_action (G_ACTION_MAP (plugin->window), G_ACTION (action)); /* Bind to the zoom-normal action's enabled property to only enable * fit-to-width zooming if zooming is generally enabled */ ref_action = g_action_map_lookup_action (G_ACTION_MAP (plugin->window), "zoom-normal"); if (ref_action) g_object_bind_property (ref_action, "enabled", action, "enabled", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); g_object_unref (action); /* Append entry to the window's gear menu */ menu = g_menu_new (); g_menu_append (menu, _("Fit to width"), "win." EOG_FIT_TO_WIDTH_PLUGIN_ACTION); item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu)); g_menu_item_set_attribute (item, "id", "s", EOG_FIT_TO_WIDTH_PLUGIN_MENU_ID); g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON, "s", "zoom-fit-best-symbolic"); g_menu_append_item (model, item); g_object_unref (item); g_object_unref (menu); /* Define accelerator keys */ gtk_application_set_accels_for_action (GTK_APPLICATION (EOG_APP), "win." EOG_FIT_TO_WIDTH_PLUGIN_ACTION, accel_keys); }
static void eog_reload_plugin_activate (EogWindowActivatable *activatable) { const gchar * const accel_keys[] = { "R", NULL }; EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (activatable); GMenu *model, *menu; GMenuItem *item; GSimpleAction *action; eog_debug (DEBUG_PLUGINS); model= eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (model)); /* Setup and inject action */ action = g_simple_action_new (EOG_RELOAD_PLUGIN_ACTION, NULL); g_signal_connect(action, "activate", G_CALLBACK (reload_cb), plugin->window); g_action_map_add_action (G_ACTION_MAP (plugin->window), G_ACTION (action)); g_object_unref (action); g_signal_connect (G_OBJECT (eog_window_get_thumb_view (plugin->window)), "selection-changed", G_CALLBACK (_selection_changed_cb), plugin); eog_reload_plugin_update_action_state (plugin); /* Append entry to the window's gear menu */ menu = g_menu_new (); g_menu_append (menu, _("Reload Image"), "win." EOG_RELOAD_PLUGIN_ACTION); item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu)); g_menu_item_set_attribute (item, "id", "s", EOG_RELOAD_PLUGIN_MENU_ID); g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON, "s", "view-refresh-symbolic"); g_menu_append_item (model, item); g_object_unref (item); g_object_unref (menu); /* Define accelerator keys */ gtk_application_set_accels_for_action (GTK_APPLICATION (EOG_APP), "win." EOG_RELOAD_PLUGIN_ACTION, accel_keys); }
static void eog_reload_plugin_deactivate (EogWindowActivatable *activatable) { const gchar * const empty_accels[1] = { NULL }; EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (activatable); GMenu *menu; GMenuModel *model; gint i; eog_debug (DEBUG_PLUGINS); menu = eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (menu)); /* Remove menu entry */ model = G_MENU_MODEL (menu); for (i = 0; i < g_menu_model_get_n_items (model); i++) { gchar *id; if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) { const gboolean found = (g_strcmp0 (id, EOG_RELOAD_PLUGIN_MENU_ID) == 0); g_free (id); if (found) { g_menu_remove (menu, i); break; } } } /* Unset accelerator */ gtk_application_set_accels_for_action(GTK_APPLICATION (EOG_APP), "win." EOG_RELOAD_PLUGIN_ACTION, empty_accels); /* Disconnect selection-changed handler as the thumbview would * otherwise still cause callbacks during its own disposal */ g_signal_handlers_disconnect_by_func (eog_window_get_thumb_view (plugin->window), _selection_changed_cb, plugin); /* Finally remove action */ g_action_map_remove_action (G_ACTION_MAP (plugin->window), EOG_RELOAD_PLUGIN_ACTION); }
static void populate_mime_handlers (GMenu *menu, GbProjectFile *project_file) { g_autofree gchar *content_type = NULL; GList *list; GList *iter; GFile *file; g_assert (G_IS_MENU (menu)); g_assert (GB_IS_PROJECT_FILE (project_file)); g_menu_remove_all (menu); file = gb_project_file_get_file (project_file); if (file == NULL) return; content_type = get_content_type (file); if (content_type == NULL) return; list = g_app_info_get_all_for_type (content_type); for (iter = list; iter; iter = iter->next) { g_autoptr(GMenuItem) menu_item = NULL; g_autofree gchar *detailed_action = NULL; GAppInfo *app_info = iter->data; const gchar *display_name; const gchar *app_id; display_name = g_app_info_get_display_name (app_info); app_id = g_app_info_get_id (app_info); detailed_action = g_strdup_printf ("project-tree.open-with('%s')", app_id); menu_item = g_menu_item_new (display_name, detailed_action); g_menu_append_item (menu, menu_item); } g_list_free_full (list, g_object_unref); }
void nautilus_pop_up_context_menu (GtkWidget *parent, GMenu *menu, GdkEventButton *button_event) { GtkWidget *gtk_menu; g_return_if_fail (G_IS_MENU (menu)); g_return_if_fail (GTK_IS_WIDGET (parent)); gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu)); gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL); gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu), button_event ? (GdkEvent *) button_event : gtk_get_current_event ()); g_object_ref_sink (gtk_menu); g_object_unref (gtk_menu); }
static void impl_activate (EogWindowActivatable *activatable) { EogPostrPlugin *plugin = EOG_POSTR_PLUGIN (activatable); GMenu *model, *menu; GMenuItem *item; GSimpleAction *action; eog_debug (DEBUG_PLUGINS); g_return_if_fail (plugin->window != NULL); model= eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (model)); /* Setup and inject action */ action = g_simple_action_new (EOG_POSTR_PLUGIN_ACTION, NULL); g_signal_connect(action, "activate", G_CALLBACK (postr_cb), plugin->window); g_action_map_add_action (G_ACTION_MAP (plugin->window), G_ACTION (action)); g_object_unref (action); /* Append entry to the window's gear menu */ menu = g_menu_new (); g_menu_append (menu, _("Upload to Flickr"), "win." EOG_POSTR_PLUGIN_ACTION); item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu)); g_menu_item_set_attribute (item, "id", "s", EOG_POSTR_PLUGIN_MENU_ID); g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON, "s", "postr"); g_menu_append_item (model, item); g_object_unref (item); g_object_unref (menu); }
static void impl_deactivate (EogWindowActivatable *activatable) { const gchar * const empty_accels[1] = { NULL }; EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (activatable); GMenu *menu; GMenuModel *model; gint i; menu = eog_window_get_gear_menu_section (plugin->window, "plugins-section"); g_return_if_fail (G_IS_MENU (menu)); /* Remove menu entry */ model = G_MENU_MODEL (menu); for (i = 0; i < g_menu_model_get_n_items (model); i++) { gchar *id; if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) { const gboolean found = (g_strcmp0 (id, EOG_FIT_TO_WIDTH_PLUGIN_MENU_ID) == 0); g_free (id); if (found) { g_menu_remove (menu, i); break; } } } /* Unset accelerator */ gtk_application_set_accels_for_action(GTK_APPLICATION (EOG_APP), "win." EOG_FIT_TO_WIDTH_PLUGIN_ACTION, empty_accels); /* Finally remove action */ g_action_map_remove_action (G_ACTION_MAP (plugin->window), EOG_FIT_TO_WIDTH_PLUGIN_ACTION); }
void nautilus_pop_up_context_menu (GtkWidget *parent, GMenu *menu, GdkEventButton *event) { GtkWidget *gtk_menu; int button; g_return_if_fail (G_IS_MENU (menu)); g_return_if_fail (GTK_IS_WIDGET (parent)); gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu)); gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL); /* The event button needs to be 0 if we're popping up this menu from * a button release, else a 2nd click outside the menu with any button * other than the one that invoked the menu will be ignored (instead * of dismissing the menu). This is a subtle fragility of the GTK menu code. */ if (event) { button = event->type == GDK_BUTTON_RELEASE ? 0 : event->button; } else { button = 0; } gtk_menu_popup (GTK_MENU (gtk_menu), /* menu */ NULL, /* parent_menu_shell */ NULL, /* parent_menu_item */ NULL, /* popup_position_func */ NULL, /* popup_position_data */ button, /* button */ event ? event->time : gtk_get_current_event_time ()); /* activate_time */ g_object_ref_sink (gtk_menu); g_object_unref (gtk_menu); }