Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
static void
update_system_bookmark_list_from_content (GthBrowser *browser,
        const char *content)
{
    BrowserData   *data;
    char        **lines;
    int           i;

    data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
    g_return_if_fail (data != NULL);

    lines = g_strsplit (content, "\n", -1);
    for (i = 0; lines[i] != NULL; i++) {
        char      **line;
        char       *uri;
        GFile      *file;
        char       *name;
        GMenuItem  *item;

        line = g_strsplit (lines[i], " ", 2);
        uri = line[0];
        if (uri == NULL) {
            g_strfreev (line);
            continue;
        }

        file = g_file_new_for_uri (uri);
        name = g_strdup (strchr (lines[i], ' '));
        if (name == NULL)
            name = _g_file_get_display_name (file);
        if (name == NULL)
            name = g_file_get_parse_name (file);
        item = _g_menu_item_new_for_file (file, name);
        g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
        g_menu_append_item (data->system_bookmarks_menu, item);

        g_object_unref (item);
        g_free (name);
        g_object_unref (file);
        g_strfreev (line);
    }

    g_strfreev (lines);
}
Exemplo n.º 3
0
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));
}
Exemplo n.º 4
0
/**
 * rb_source_search_add_to_menu:
 * @menu: #GMenu instance to populate
 * @action_namespace: muxer namespace for the action ("app" or "win")
 * @action: search action to attach the menu item to
 * @name: name of the search instance to add
 *
 * Adds a registered search instance to a search menu.
 */
void
rb_source_search_add_to_menu (GMenu *menu, const char *action_namespace, GAction *action, const char *name)
{
	GMenuItem *item;
	RBSourceSearch *search;
	char *action_name;
       
	search = rb_source_search_get_by_name (name);
	g_assert (search != NULL);

	if (action_namespace != NULL) {
		action_name = g_strdup_printf ("%s.%s", action_namespace, g_action_get_name (action));
	} else {
		action_name = g_strdup (g_action_get_name (action));
	}

	item = g_menu_item_new (rb_source_search_get_description (search), NULL);
	g_menu_item_set_action_and_target (item, action_name, "s", name);
	g_menu_append_item (menu, item);

	g_free (action_name);
}
Exemplo n.º 5
0
static void
eog_zoom_entry_populate_free_zoom_section (EogZoomEntry *zoom_entry)
{
	guint   i;

	for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) {
		GMenuItem *item;
		gchar *name;


		if (zoom_levels[i] > EOG_SCROLL_VIEW_MAX_ZOOM_FACTOR)
			break;

		name = eog_zoom_entry_format_zoom_value (zoom_levels[i]);

		item = g_menu_item_new (name, NULL);
		g_menu_item_set_action_and_target (item, "win.zoom-set",
		                                   "d", zoom_levels[i]);
		g_menu_append_item (G_MENU (zoom_entry->priv->zoom_free_section), item);
		g_object_unref (item);
		g_free (name);
	}
}
Exemplo n.º 6
0
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);
    }
}
Exemplo n.º 7
0
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);
}