static void toggle_italic (GtkToggleButton *button, gpointer data) { GMenuModel *model; GActionGroup *group; GSimpleAction *action; gboolean adding; GMenuModel *m; GtkTreeView *tv = data; GtkTreeModel *store; model = g_object_get_data (G_OBJECT (button), "model"); group = g_object_get_data (G_OBJECT (button), "group"); store = gtk_tree_view_get_model (tv); adding = gtk_toggle_button_get_active (button); m = g_menu_model_get_item_link (model, g_menu_model_get_n_items (model) - 1, G_MENU_LINK_SECTION); if (adding) { action = g_simple_action_new_stateful ("italic", NULL, g_variant_new_boolean (FALSE)); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (activate_toggle), NULL); g_object_unref (action); action_list_add (store, "italic"); g_menu_insert (G_MENU (m), 1, "Italic", "italic"); } else { g_action_map_remove_action (G_ACTION_MAP (group), "italic"); action_list_remove (store, "italic"); g_menu_remove (G_MENU (m), 1); } }
static void disable_plugin (const gchar *name) { GMenuModel *plugin_menu; g_print ("Disabling '%s' plugin\n", name); plugin_menu = find_plugin_menu (); if (plugin_menu) { const gchar *id; gint i; for (i = 0; i < g_menu_model_get_n_items (plugin_menu); i++) { if (g_menu_model_get_item_attribute (plugin_menu, i, "id", "s", &id) && g_strcmp0 (id, name) == 0) { g_menu_remove (G_MENU (plugin_menu), i); g_print ("Menus of '%s' plugin removed\n", name); } } } else g_warning ("Plugin menu not found\n"); g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()), name); g_print ("Actions of '%s' plugin removed\n", name); if (g_strcmp0 (name, "red") == 0) is_red_plugin_enabled = FALSE; else is_black_plugin_enabled = FALSE; }
void gw_application_set_win_menubar (GwApplication *application, GMenuModel *menumodel) { //Sanity checks g_return_if_fail (application != NULL); g_return_if_fail (menumodel != NULL); if (g_menu_model_get_n_items (menumodel) == 0) return; //Declarations GMenuModel *menubar; gint length; //Initializations menubar = gtk_application_get_menubar (GTK_APPLICATION (application)); g_return_if_fail (menubar != NULL); length = g_menu_model_get_n_items (menubar); //Clear the menubar while (length-- > 0) g_menu_remove (G_MENU (menubar), 0); //Add the menuitem linking the menus { GMenuItem *menuitem = g_menu_item_new_section (NULL, menumodel); if (menuitem != NULL) { g_menu_append_item (G_MENU (menubar), menuitem); g_object_unref (menuitem); menuitem = NULL; } gw_application_add_accelerators (application, menubar); } }
static void gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window, GtkSettings *settings) { gboolean shown_by_shell; g_object_get (settings, "gtk-shell-shows-menubar", &shown_by_shell, NULL); if (shown_by_shell) { /* the shell shows it, so don't show it locally */ if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) != 0) g_menu_remove (window->priv->menubar_section, 0); } else { /* the shell does not show it, so make sure we show it */ if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) == 0) { GMenuModel *menubar; menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window))); if (menubar != NULL) g_menu_append_section (window->priv->menubar_section, NULL, menubar); } } }
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); }
static void gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window, GtkSettings *settings) { gboolean shown_by_shell; gboolean shown_by_titlebar; g_object_get (settings, "gtk-shell-shows-app-menu", &shown_by_shell, NULL); shown_by_titlebar = _gtk_window_titlebar_shows_app_menu (GTK_WINDOW (window)); if (shown_by_shell || shown_by_titlebar) { /* the shell shows it, so don't show it locally */ if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) != 0) g_menu_remove (window->priv->app_menu_section, 0); } else { /* the shell does not show it, so make sure we show it */ if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) == 0) { GMenuModel *app_menu = NULL; if (gtk_window_get_application (GTK_WINDOW (window)) != NULL) app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window))); if (app_menu != NULL) { const gchar *app_name; gchar *name; app_name = g_get_application_name (); if (app_name != g_get_prgname ()) { /* the app has set its application name, use it */ name = g_strdup (app_name); } else { /* get the name from .desktop file */ name = gtk_application_window_get_app_desktop_name (); if (name == NULL) name = g_strdup (_("Application")); } g_menu_append_submenu (window->priv->app_menu_section, name, app_menu); g_free (name); } } } }
static void toggle_speed (GtkToggleButton *button, gpointer data) { GMenuModel *model; GActionGroup *group; GSimpleAction *action; gboolean adding; GMenuModel *m; GMenu *submenu; GtkTreeView *tv = data; GtkTreeModel *store; model = g_object_get_data (G_OBJECT (button), "model"); group = g_object_get_data (G_OBJECT (button), "group"); store = gtk_tree_view_get_model (tv); adding = gtk_toggle_button_get_active (button); m = g_menu_model_get_item_link (model, 1, G_MENU_LINK_SECTION); if (adding) { action = g_simple_action_new ("faster", NULL); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (activate_action), NULL); g_object_unref (action); action = g_simple_action_new ("slower", NULL); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (activate_action), NULL); g_object_unref (action); action_list_add (store, "faster"); action_list_add (store, "slower"); submenu = g_menu_new (); g_menu_append (submenu, "Faster", "faster"); g_menu_append (submenu, "Slower", "slower"); g_menu_append_submenu (G_MENU (m), "Speed", G_MENU_MODEL (submenu)); } else { g_action_map_remove_action (G_ACTION_MAP (group), "faster"); g_action_map_remove_action (G_ACTION_MAP (group), "slower"); action_list_remove (store, "faster"); action_list_remove (store, "slower"); g_menu_remove (G_MENU (m), g_menu_model_get_n_items (m) - 1); } }
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 toggle_sumerian (GtkToggleButton *button, gpointer data) { GMenuModel *model; gboolean adding; GMenuModel *m; model = g_object_get_data (G_OBJECT (button), "model"); adding = gtk_toggle_button_get_active (button); m = g_menu_model_get_item_link (model, g_menu_model_get_n_items (model) - 1, G_MENU_LINK_SECTION); m = g_menu_model_get_item_link (m, g_menu_model_get_n_items (m) - 1, G_MENU_LINK_SUBMENU); if (adding) g_menu_append (G_MENU (m), "Sumerian", "lang::sumerian"); else g_menu_remove (G_MENU (m), g_menu_model_get_n_items (m) - 1); }
void gw_menumodel_set_links (GMenuModel *menumodel, const gchar *LABEL, const gchar *NEW_LABEL, const gchar *LINK_TYPE, GMenuModel *link) { //Sanity checks g_return_if_fail (menumodel != NULL); g_return_if_fail (LABEL != NULL); g_return_if_fail (LINK_TYPE != NULL); //Declarations gint total_items; gint index; gchar *label; gboolean valid; GMenuItem *menuitem; GMenuModel *sublink; //Initializations total_items = g_menu_model_get_n_items (menumodel); for (index = 0; index < total_items; index++) { valid = g_menu_model_get_item_attribute (menumodel, index, G_MENU_ATTRIBUTE_LABEL, "s", &label, NULL); if (valid == TRUE && label != NULL) { if (label != NULL && strcmp (label, LABEL) == 0) { menuitem = g_menu_item_new (NEW_LABEL, NULL); g_menu_item_set_link (menuitem, LINK_TYPE, link); g_menu_remove (G_MENU (menumodel), index); g_menu_insert_item (G_MENU (menumodel), index, menuitem); g_object_unref (menuitem); menuitem = NULL; } g_free (label); label = NULL; } //Recursive work sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SUBMENU); if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link); sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SECTION); if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link); } }
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); }