static void _gth_browser_update_entry_point_list (GthBrowser *browser) { BrowserData *data; GList *entry_points; GList *scan; data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); g_return_if_fail (data != NULL); g_menu_remove_all (data->entry_points_menu); entry_points = gth_main_get_all_entry_points (); for (scan = entry_points; scan; scan = scan->next) { GthFileData *file_data = scan->data; GMenuItem *item; char *uri; item = _g_menu_item_new_for_file (file_data->file, NULL); uri = g_file_get_uri (file_data->file); g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri); g_menu_append_item (data->entry_points_menu, item); g_free (uri); g_object_unref (item); } _g_object_list_unref (entry_points); }
static void _gth_browser_update_system_bookmark_list (GthBrowser *browser) { BrowserData *browser_data; GFile *bookmark_file; GFileInputStream *input_stream; UpdateBookmarksData *data; browser_data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); g_return_if_fail (browser_data != NULL); g_menu_remove_all (browser_data->system_bookmarks_menu); /* give priority to XDG_CONFIG_HOME/gtk-3.0/bookmarks if not found * try the old ~/.gtk-bookmarks */ bookmark_file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, "gtk-3.0", "bookmarks", NULL); if (! g_file_query_exists (bookmark_file, NULL)) { char *path; g_object_unref (bookmark_file); path = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL); bookmark_file = g_file_new_for_path (path); g_free (path); } input_stream = g_file_read (bookmark_file, NULL, NULL); g_object_unref (bookmark_file); if (input_stream == NULL) return; data = g_new0 (UpdateBookmarksData, 1); data->browser = g_object_ref (browser); data->stream = (GInputStream*) input_stream; data->file_content = g_string_new (""); g_input_stream_read_async (data->stream, data->buffer, BUFFER_SIZE - 1, G_PRIORITY_DEFAULT, NULL, update_system_bookmark_list_ready, data); }
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); }
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 actions_changed_cb (G_GNUC_UNUSED GtkWidget *widget, GMenuModel *model, gpointer data) { GMenu *menu = NULL; g_return_if_fail (EKIGA_IS_WINDOW (data)); EkigaWindow *self = EKIGA_WINDOW (data); menu = G_MENU (gtk_builder_get_object (self->priv->builder, "menubar")); g_menu_remove_all (menu); /* Those are Actions from the selected Presentity and Heap */ if (model) { g_menu_insert_section (menu, 0, NULL, model); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->priv->menu_button), G_MENU_MODEL (menu)); } else gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->priv->menu_button), NULL); }
static void ephy_notebook_rebuild_tab_menu (EphyNotebook *notebook) { GMenuItem *item; const char *text; char *ellipsized_text; int num_pages; GtkWidget *window; GActionGroup *group; GAction *action; gint current_page; g_menu_remove_all (notebook->tab_menu); num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); /* TODO: Add favicon as well. Will have to ditch GMenu. :( */ for (int i = 0; i < num_pages; i++) { text = get_nth_tab_label_text (GTK_NOTEBOOK (notebook), i); ellipsized_text = ellipsize_tab_label (text); item = g_menu_item_new (ellipsized_text, NULL); g_menu_item_set_action_and_target (item, "win.show-tab", "u", (guint)i, NULL); g_menu_append_item (notebook->tab_menu, item); g_free (ellipsized_text); g_object_unref (item); } current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); if (current_page < 0) return; window = gtk_widget_get_toplevel (GTK_WIDGET (notebook)); group = gtk_widget_get_action_group (window, "win"); /* Is window being destroyed? */ if (group == NULL) return; action = g_action_map_lookup_action (G_ACTION_MAP (group), "show-tab"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_uint32 ((guint32)current_page)); }
void nautilus_gmenu_replace_section (GMenu *menu, const gchar *section_id, GMenuModel *section) { GMenuModel *orig_section; GMenuItem *item; gint idx; orig_section = find_gmenu_model (G_MENU_MODEL (menu), section_id); g_return_if_fail (orig_section != NULL); g_menu_remove_all (G_MENU (orig_section)); for (idx = 0; idx < g_menu_model_get_n_items (section); idx++) { item = g_menu_item_new_from_model (section, idx); g_menu_append_item (G_MENU (orig_section), item); g_object_unref (item); } g_object_unref (orig_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 _gth_browser_update_bookmark_list (GthBrowser *browser) { BrowserData *data; GBookmarkFile *bookmarks; char **uris; int i; data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY); g_return_if_fail (data != NULL); g_menu_remove_all (data->bookmarks_menu); bookmarks = gth_main_get_default_bookmarks (); uris = g_bookmark_file_get_uris (bookmarks, NULL); for (i = 0; uris[i] != NULL; i++) { GFile *file; char *name; GMenuItem *item; file = g_file_new_for_uri (uris[i]); name = g_bookmark_file_get_title (bookmarks, uris[i], NULL); item = _g_menu_item_new_for_file (file, name); g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uris[i]); g_menu_append_item (data->bookmarks_menu, item); g_object_unref (item); g_free (name); g_object_unref (file); } _gth_browser_update_system_bookmark_list (browser); g_strfreev (uris); }