static void application_startup_cb (GApplication *application, GnomeControlCenter *shell) { GMenu *menu, *section; GAction *action; action = G_ACTION (g_simple_action_new ("help", NULL)); g_action_map_add_action (G_ACTION_MAP (application), action); g_signal_connect (action, "activate", G_CALLBACK (help_activated), shell); action = G_ACTION (g_simple_action_new ("quit", NULL)); g_action_map_add_action (G_ACTION_MAP (application), action); g_signal_connect (action, "activate", G_CALLBACK (quit_activated), shell); menu = g_menu_new (); section = g_menu_new (); g_menu_append (section, _("Help"), "app.help"); g_menu_append (section, _("Quit"), "app.quit"); g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (menu)); gtk_application_add_accelerator (GTK_APPLICATION (application), "F1", "app.help", NULL); /* nothing else to do here, we don't want to show a window before * we've looked at the commandline */ }
static void gtk_application_window_init (GtkApplicationWindow *window) { window->priv = gtk_application_window_get_instance_private (window); window->priv->actions = gtk_application_window_actions_new (window); window->priv->app_menu_section = g_menu_new (); window->priv->menubar_section = g_menu_new (); window->priv->accels = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accels); gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (window->priv->actions)); /* window->priv->actions is the one and only ref on the group, so when * we dispose, the action group will die, disconnecting all signals. */ g_signal_connect_swapped (window->priv->actions, "action-added", G_CALLBACK (g_action_group_action_added), window); g_signal_connect_swapped (window->priv->actions, "action-enabled-changed", G_CALLBACK (g_action_group_action_enabled_changed), window); g_signal_connect_swapped (window->priv->actions, "action-state-changed", G_CALLBACK (g_action_group_action_state_changed), window); g_signal_connect_swapped (window->priv->actions, "action-removed", G_CALLBACK (g_action_group_action_removed), window); }
static void gtk_application_window_init (GtkApplicationWindow *window) { window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, GTK_TYPE_APPLICATION_WINDOW, GtkApplicationWindowPrivate); window->priv->actions = gtk_application_window_actions_new (window); window->priv->app_menu_section = g_menu_new (); window->priv->menubar_section = g_menu_new (); window->priv->accels = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accels); /* window->priv->actions is the one and only ref on the group, so when * we dispose, the action group will die, disconnecting all signals. */ g_signal_connect_swapped (window->priv->actions, "action-added", G_CALLBACK (g_action_group_action_added), window); g_signal_connect_swapped (window->priv->actions, "action-enabled-changed", G_CALLBACK (g_action_group_action_enabled_changed), window); g_signal_connect_swapped (window->priv->actions, "action-state-changed", G_CALLBACK (g_action_group_action_state_changed), window); g_signal_connect_swapped (window->priv->actions, "action-removed", G_CALLBACK (g_action_group_action_removed), window); window->priv->muxer = G_ACTION_OBSERVABLE (g_action_muxer_new ()); }
static void cc_application_startup (GApplication *application) { CcApplication *self = CC_APPLICATION (application); GMenu *menu; GMenu *section; GSimpleAction *action; G_APPLICATION_CLASS (cc_application_parent_class)->startup (application); #ifdef HAVE_CHEESE if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS) { g_critical ("Unable to initialize Clutter"); return; } #endif /* HAVE_CHEESE */ /* register a symbolic icon size for use in sidebar lists */ gtk_icon_size_register ("cc-sidebar-list", 24, 24); action = g_simple_action_new ("help", NULL); g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (help_activated), self); g_object_unref (action); action = g_simple_action_new ("quit", NULL); g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (cc_application_quit), self); g_object_unref (action); /* Launch panel by id. The parameter is a (panel_id, array_of_panel_parameters) * tuple. The GVariant-containing array usually is just the same array of * strings that would be generated by passing panel-specific arguments on * the command line. */ action = g_simple_action_new ("launch-panel", G_VARIANT_TYPE ("(sav)")); g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action)); g_signal_connect (action, "activate", G_CALLBACK (launch_panel_activated), self); g_object_unref (action); menu = g_menu_new (); section = g_menu_new (); g_menu_append (section, _("Help"), "app.help"); g_menu_append (section, _("Quit"), "app.quit"); g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (menu)); gtk_application_add_accelerator (GTK_APPLICATION (application), "F1", "app.help", NULL); self->priv->window = cc_window_new (GTK_APPLICATION (application)); }
static void gcal_application_set_app_menu (GApplication *app) { GcalApplicationPrivate *priv; GMenu *app_menu; GMenu *view_as; GSimpleAction *about; GSimpleAction *quit; g_return_if_fail (GCAL_IS_APPLICATION (app)); priv = GCAL_APPLICATION (app)->priv; app_menu = g_menu_new (); priv->view = g_simple_action_new_stateful ( "view", G_VARIANT_TYPE_STRING, g_settings_get_value (priv->settings, "active-view")); g_signal_connect (priv->view, "activate", G_CALLBACK (gcal_application_change_view), app); g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (priv->view)); view_as = g_menu_new (); g_menu_append (view_as, _("Weeks"), "app.view::week"); g_menu_append (view_as, _("Months"), "app.view::month"); g_menu_append_section (app_menu, _("View as"), G_MENU_MODEL (view_as)); about = g_simple_action_new ("about", NULL); g_signal_connect (about, "activate", G_CALLBACK (gcal_application_show_about), app); g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (about)); g_menu_append (app_menu, _("About"), "app.about"); quit = g_simple_action_new ("quit", NULL); g_signal_connect (quit, "activate", G_CALLBACK (gcal_application_quit), app); g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (quit)); g_menu_append (app_menu, _("Quit"), "app.quit"); gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (app_menu)); }
/* Startup function for the menu we are creating in this sample */ static void startup (GApplication *app, gpointer user_data) { GMenu *menu; GSimpleAction *quit_action; /* Initialize the GMenu, and add a menu item with label "About" and action * "win.about". Also add another menu item with label "Quit" and action * "app.quit" */ menu = g_menu_new (); g_menu_append (menu, "About", "win.about"); g_menu_append (menu, "Quit", "app.quit"); /* Create a new simple action for the application. (In this case it is the * "quit" action. */ quit_action = g_simple_action_new ("quit", NULL); /* Ensure that the menu we have just created is set for the overall application */ gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (menu)); g_signal_connect (quit_action, "activate", G_CALLBACK (quit_cb), app); g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit_action)); }
static void photos_base_model_constructed (GObject *object) { PhotosBaseModel *self = PHOTOS_BASE_MODEL (object); G_OBJECT_CLASS (photos_base_model_parent_class)->constructed (object); self->model = g_menu_new (); g_signal_connect_object (self->mngr, "object-added", G_CALLBACK (photos_base_model_refresh), self, G_CONNECT_SWAPPED); g_signal_connect_object (self->mngr, "object-removed", G_CALLBACK (photos_base_model_refresh), self, G_CONNECT_SWAPPED); g_signal_connect_object (self->mngr, "active-changed", G_CALLBACK (photos_base_model_active_changed), self, G_CONNECT_SWAPPED); photos_base_model_refresh (self); }
static void _brio_application_set_app_menu (GApplication *app) { GMenu *app_menu = g_menu_new (); GSimpleAction *about; GSimpleAction *quit; about = g_simple_action_new ("about", NULL); g_signal_connect (about, "activate", G_CALLBACK (_brio_application_show_about), app); g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (about)); g_menu_append (app_menu, _("About"), "app.about"); quit = g_simple_action_new ("quit", NULL); g_signal_connect (quit, "activate", G_CALLBACK (_brio_application_quit), app); g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (quit)); g_menu_append (app_menu, _("Quit"), "app.quit"); gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (app_menu)); }
static void gw_application_load_menubar (GwApplication *application) { GMenuModel *menumodel; menumodel = G_MENU_MODEL (g_menu_new ()); gtk_application_set_menubar (GTK_APPLICATION (application), menumodel); }
G_MODULE_EXPORT gboolean gw_window_focus_in_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) { //Declarations GwWindow *window; GwApplication *application; GMenuModel *menumodel; gboolean os_shows_win_menu; GtkSettings *settings; //Initializations window = GW_WINDOW (widget); application = gw_window_get_application (window); settings = gtk_settings_get_default (); g_object_get (settings, "gtk-shell-shows-menubar", &os_shows_win_menu, NULL); menumodel = gw_window_get_transient_for_menumodel (window); if (menumodel == NULL) menumodel = G_MENU_MODEL (g_menu_new ()); if (menumodel == NULL) return FALSE; if (os_shows_win_menu) gw_application_set_win_menubar (GW_APPLICATION (application), menumodel); return FALSE; }
static void ephy_notebook_constructed (GObject *object) { EphyNotebook *notebook = EPHY_NOTEBOOK (object); GtkWidget *hbox; GtkWidget *button; EphyPagesPopover *popover; G_OBJECT_CLASS (ephy_notebook_parent_class)->constructed (object); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), hbox, GTK_PACK_END); gtk_widget_show (hbox); button = gtk_menu_button_new (); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); /* Translators: tooltip for the tab switcher menu button */ gtk_widget_set_tooltip_text (button, _("View open tabs")); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); gtk_widget_show (button); notebook->tab_menu = g_menu_new (); /* Remove this when popover menus become scrollable. */ gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE); popover = ephy_pages_popover_new (GTK_WIDGET (button)); ephy_pages_popover_set_notebook (popover, notebook); gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), GTK_WIDGET (popover)); }
static void startup_wizard(GApplication *app, gpointer user_data) { g_action_map_add_action_entries(G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); GMenu *app_menu = g_menu_new(); g_menu_append(app_menu, _("Preferences"), "app.preferences"); GMenu *service_app_menu_sec = g_menu_new(); g_menu_append(service_app_menu_sec, _("Quit"), "app.quit"); g_menu_append_section(app_menu, /*no title*/NULL, G_MENU_MODEL(service_app_menu_sec)); gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL(app_menu)); }
int main (int argc, char **argv) { IndicatorTestService indicator = { 0 }; GMenuItem *item; GMenu *submenu; GActionEntry entries[] = { { "_header", NULL, NULL, "{'label': <'Test'>," " 'icon': <'indicator-test'>," " 'accessible-desc': <'Test indicator'> }", NULL }, { "show", activate_show, NULL, NULL, NULL } }; GMainLoop *loop; indicator.actions = g_simple_action_group_new (); g_simple_action_group_add_entries (indicator.actions, entries, G_N_ELEMENTS (entries), NULL); submenu = g_menu_new (); g_menu_append (submenu, "Show", "indicator.show"); item = g_menu_item_new (NULL, "indicator._header"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_submenu (item, G_MENU_MODEL (submenu)); indicator.menu = g_menu_new (); g_menu_append_item (indicator.menu, item); g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.test", G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired, NULL, name_lost, &indicator, NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (submenu); g_object_unref (item); g_object_unref (indicator.actions); g_object_unref (indicator.menu); g_object_unref (loop); return 0; }
static GMenuModel * create_main_menu() { GMenu *menu = g_menu_new(); g_menu_append(menu, i18n("Side Pane"), "cainteoir.side-pane"); return G_MENU_MODEL(menu); }
static void activate (GApplication *app, gpointer user_data) { GtkWidget *win; GtkWidget *button; GSimpleActionGroup *doc_actions; GtkBuilder *builder; GMenuModel *doc_menu; GMenuModel *win_menu; GMenu *button_menu; GMenuItem *section; if (gtk_application_get_windows (GTK_APPLICATION (app)) != NULL) return; win = gtk_application_window_new (GTK_APPLICATION (app)); doc_actions = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (doc_actions), doc_entries, G_N_ELEMENTS (doc_entries), win); g_action_map_add_action_entries (G_ACTION_MAP (win), win_entries, G_N_ELEMENTS (win_entries), win); builder = gtk_builder_new (); gtk_builder_add_from_string (builder, menu_ui, -1, NULL); doc_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "doc-menu")); win_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "win-menu")); button_menu = g_menu_new (); section = g_menu_item_new_section (NULL, doc_menu); g_menu_item_set_attribute (section, "action-namespace", "s", "doc"); g_menu_append_item (button_menu, section); g_object_unref (section); section = g_menu_item_new_section (NULL, win_menu); g_menu_item_set_attribute (section, "action-namespace", "s", "win"); g_menu_append_item (button_menu, section); g_object_unref (section); button = gtk_menu_button_new (); gtk_button_set_label (GTK_BUTTON (button), "Menu"); gtk_widget_insert_action_group (button, "doc", G_ACTION_GROUP (doc_actions)); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (button_menu)); gtk_container_add (GTK_CONTAINER (win), button); gtk_container_set_border_width (GTK_CONTAINER (win), 12); gtk_widget_show_all (win); g_object_unref (button_menu); g_object_unref (doc_actions); g_object_unref (builder); }
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 activate (GtkApplication *app, gpointer user_data) { GMenu *submenu; GtkWidget *grid; GMenu *menumodel; GtkWidget *window; GtkWidget *menubutton; GSimpleAction *about_action; window = gtk_application_window_new (app); grid = gtk_grid_new (); gtk_window_set_title (GTK_WINDOW (window), "MenuButton Example"); gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); menubutton = gtk_menu_button_new (); gtk_widget_set_size_request (menubutton, 80, 35); gtk_grid_attach (GTK_GRID (grid), menubutton, 0, 0, 1, 1); gtk_container_add (GTK_CONTAINER (window), grid); menumodel = g_menu_new (); g_menu_append (menumodel, "New", "app.new"); g_menu_append (menumodel, "About", "win.about"); submenu = g_menu_new (); g_menu_append_submenu (menumodel, "Other", G_MENU_MODEL (submenu)); g_menu_append (submenu, "Quit", "app.quit"); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menubutton), G_MENU_MODEL (menumodel)); about_action = g_simple_action_new ("about", NULL); g_signal_connect (about_action, "activate", G_CALLBACK (about_callback), GTK_WINDOW (window)); g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (about_action)); gtk_widget_show_all (window); }
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 gtk_application_menu_changed_quartz (GObject *object, GParamSpec *pspec, gpointer user_data) { GtkApplication *application = GTK_APPLICATION (object); GMenu *combined; combined = g_menu_new (); g_menu_append_submenu (combined, "Application", gtk_application_get_app_menu (application)); g_menu_append_section (combined, NULL, gtk_application_get_menubar (application)); gtk_quartz_set_main_menu (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (application->priv->muxer)); }
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); }
/** * irc_context_get_menu: * * Returns: (transfer full): New menu currently valid for context */ GMenuModel * irc_context_get_menu (IrcContext *self) { GMenuModel *menu = IRC_CONTEXT_GET_IFACE(self)->get_menu(self); // Always have a close entry GMenu *shared_menu = g_menu_new (); const char *id = irc_context_get_id (self); g_autofree char *action = g_strdup_printf ("context.close('%s')", id); g_menu_append (shared_menu, _("Close"), action); g_menu_append_section (G_MENU(menu), NULL, G_MENU_MODEL(shared_menu)); return menu; }
static GMenu *build_app_menu() { GMenu *menu; GMenu *top_section; GMenu *bottom_section; GMenuItem *pref_menu_item; GMenuItem *about_menu_item; GMenuItem *quit_menu_item; menu = g_menu_new(); top_section = g_menu_new(); bottom_section = g_menu_new(); pref_menu_item = g_menu_item_new(_("_Preferences"), "app.pref"); about_menu_item = g_menu_item_new(_("_About"), "app.about"); quit_menu_item = g_menu_item_new(_("_Quit"), "app.quit"); g_menu_append_section(menu, NULL, G_MENU_MODEL(top_section)); g_menu_append_section(menu, NULL, G_MENU_MODEL(bottom_section)); g_menu_append_item(top_section, pref_menu_item); g_menu_append_item(bottom_section, about_menu_item); g_menu_append_item(bottom_section, quit_menu_item); return menu; }
/** * Creates window menu */ GtkWidget *create_windowmenu (ezeedo_wrapper_structure *ezeedo) { // define widgets GtkWidget *windowmenu_button; GtkWidget *win; GMenu *windowmenu; win = ezeedo->window; // define actions GSimpleAction *toggle_action; // create gear menu windowmenu = g_menu_new (); g_menu_append (windowmenu, "Toggle sidebar", "win.toggle_sidebar"); // create actions toggle_action = g_simple_action_new ("toggle_sidebar", NULL); g_signal_connect (toggle_action, "activate", G_CALLBACK(toggle_sidebar), ezeedo); g_action_map_add_action (G_ACTION_MAP(win), G_ACTION(toggle_action)); // activate ctrl-h const gchar* toggle_accels[2] = { "<Ctrl>H", NULL }; gtk_application_set_accels_for_action (GTK_APPLICATION(ezeedo->application), "win.toggle_sidebar", toggle_accels); // create window menu windowmenu_button = gtk_menu_button_new (); gtk_menu_button_set_direction (GTK_MENU_BUTTON(windowmenu_button), GTK_ARROW_NONE); // attach window menu to button gtk_menu_button_set_use_popover (GTK_MENU_BUTTON(windowmenu_button), true); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON(windowmenu_button), G_MENU_MODEL(windowmenu)); // return button with window menu return (windowmenu_button); }
static GMenu *open_btn_build_menu() { GMenu *menu; GMenuItem *open_menu_item; GMenuItem *open_loc_menu_item; menu = g_menu_new(); open_menu_item = g_menu_item_new(_("_Open"), "app.open"); open_loc_menu_item = g_menu_item_new(_("Open _Location"), "app.openloc"); g_menu_append_item(menu, open_menu_item); g_menu_append_item(menu, open_loc_menu_item); return menu; }
static void enable_plugin (const gchar *name) { GMenuModel *plugin_menu; GAction *action; g_print ("Enabling '%s' plugin\n", name); action = (GAction *)g_simple_action_new (name, NULL); g_signal_connect (action, "activate", G_CALLBACK (plugin_action), (gpointer)name); g_action_map_add_action (G_ACTION_MAP (g_application_get_default ()), action); g_print ("Actions of '%s' plugin added\n", name); g_object_unref (action); plugin_menu = find_plugin_menu (); if (plugin_menu) { GMenu *section; GMenuItem *item; gchar *label; gchar *action_name; section = g_menu_new (); label = g_strdup_printf ("Turn text %s", name); action_name = g_strconcat ("app.", name, NULL); g_menu_insert (section, 0, label, action_name); g_free (label); g_free (action_name); item = g_menu_item_new_section (NULL, (GMenuModel*)section); g_menu_item_set_attribute (item, "id", "s", name); g_menu_append_item (G_MENU (plugin_menu), item); g_object_unref (item); g_object_unref (section); g_print ("Menus of '%s' plugin added\n", name); } else g_warning ("Plugin menu not found\n"); if (g_strcmp0 (name, "red") == 0) is_red_plugin_enabled = TRUE; else is_black_plugin_enabled = TRUE; }
static void photos_base_model_constructed (GObject *object) { PhotosBaseModel *self = PHOTOS_BASE_MODEL (object); PhotosBaseModelPrivate *priv = self->priv; GApplication *app; const gchar *action_id; gchar *detailed_signal; G_OBJECT_CLASS (photos_base_model_parent_class)->constructed (object); priv->model = g_menu_new (); g_signal_connect_object (priv->mngr, "object-added", G_CALLBACK (photos_base_model_refresh), self, G_CONNECT_SWAPPED); g_signal_connect_object (priv->mngr, "object-removed", G_CALLBACK (photos_base_model_refresh), self, G_CONNECT_SWAPPED); app = g_application_get_default (); action_id = photos_base_manager_get_action_id (priv->mngr); detailed_signal = g_strconcat ("action-state-changed::", action_id, NULL); g_signal_connect_object (app, detailed_signal, G_CALLBACK (photos_base_model_action_state_changed), self, G_CONNECT_SWAPPED); g_free (detailed_signal); g_signal_connect_object (priv->mngr, "active-changed", G_CALLBACK (photos_base_model_active_changed), self, G_CONNECT_SWAPPED); photos_base_model_refresh (self); }
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 photos_base_model_refresh (PhotosBaseModel *self) { PhotosBaseModelPrivate *priv = self->priv; GHashTable *objects; GHashTableIter hash_iter; GMenu *section; GObject *object; const gchar *action_id; const gchar *id; const gchar *title; g_menu_remove_all (priv->model); title = photos_base_manager_get_title (priv->mngr); action_id = photos_base_manager_get_action_id (priv->mngr); section = g_menu_new (); g_menu_append_section (priv->model, title, G_MENU_MODEL (section)); objects = photos_base_manager_get_objects (priv->mngr); g_hash_table_iter_init (&hash_iter, objects); while (g_hash_table_iter_next (&hash_iter, (gpointer *) &id, (gpointer *) &object)) { GMenuItem *menu_item; GVariant *target_value; gchar *name; g_object_get (object, "name", &name, NULL); menu_item = g_menu_item_new (name, NULL); target_value = g_variant_new ("s", id); g_menu_item_set_action_and_target_value (menu_item, action_id, target_value); g_menu_append_item (section, menu_item); g_free (name); } g_object_unref (section); }
static void photos_base_model_refresh (PhotosBaseModel *self) { g_autoptr (GMenu) section = NULL; const gchar *action_id; const gchar *title; guint i; guint n_items; g_menu_remove_all (self->model); title = photos_base_manager_get_title (self->mngr); action_id = photos_base_manager_get_action_id (self->mngr); section = g_menu_new (); g_menu_append_section (self->model, title, G_MENU_MODEL (section)); n_items = g_list_model_get_n_items (G_LIST_MODEL (self->mngr)); for (i = 0; i < n_items; i++) { g_autoptr (GMenuItem) menu_item = NULL; g_autoptr (GObject) object = NULL; const gchar *id; g_autofree gchar *name = NULL; object = g_list_model_get_object (G_LIST_MODEL (self->mngr), i); if (!photos_filterable_is_search_criterion (PHOTOS_FILTERABLE (object))) continue; id = photos_filterable_get_id (PHOTOS_FILTERABLE (object)); g_object_get (object, "name", &name, NULL); menu_item = g_menu_item_new (name, NULL); g_menu_item_set_action_and_target (menu_item, action_id, "s", id); g_menu_append_item (section, menu_item); } }
static void gtk_application_window_update_menubar (GtkApplicationWindow *window) { gboolean should_have_menubar; gboolean have_menubar; have_menubar = window->priv->menubar != NULL; should_have_menubar = window->priv->show_menubar && (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) || g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section))); if (have_menubar && !should_have_menubar) { gtk_widget_unparent (window->priv->menubar); window->priv->menubar = NULL; gtk_widget_queue_resize (GTK_WIDGET (window)); } if (!have_menubar && should_have_menubar) { GMenu *combined; combined = g_menu_new (); g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->app_menu_section)); g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->menubar_section)); window->priv->menubar = gtk_menu_bar_new_from_model (G_MENU_MODEL (combined)); gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window)); gtk_widget_show_all (window->priv->menubar); g_object_unref (combined); gtk_widget_queue_resize (GTK_WIDGET (window)); } }