Example #1
0
static gboolean
activatable_update_gicon (GtkImageMenuItem *image_menu_item, GtkAction *action)
{
    GtkWidget   *image;
    GIcon       *icon = gtk_action_get_gicon (action);
    const gchar *stock_id;
    gboolean     ret = FALSE;

    stock_id = gtk_action_get_stock_id (action);

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

    image = gtk_image_menu_item_get_image (image_menu_item);

    if (icon && GTK_IS_IMAGE (image) &&
            !(stock_id && gtk_icon_factory_lookup_default (stock_id)))
    {
        gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_MENU);
        ret = TRUE;
    }

    G_GNUC_END_IGNORE_DEPRECATIONS;

    return ret;
}
Example #2
0
static void
gtk_tool_button_sync_action_properties (GtkActivatable *activatable,
				        GtkAction      *action)
{
  GtkToolButton *button;
  GIcon         *icon;
  const gchar   *stock_id;
  GtkIconSet    *icon_set = NULL;

  parent_activatable_iface->sync_action_properties (activatable, action);

  if (!action)
    return;

  if (!gtk_activatable_get_use_action_appearance (activatable))
    return;

  button = GTK_TOOL_BUTTON (activatable);
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
  stock_id = gtk_action_get_stock_id (action);
  G_GNUC_END_IGNORE_DEPRECATIONS;

  gtk_tool_button_set_label (button, gtk_action_get_short_label (action));
  gtk_tool_button_set_use_underline (button, TRUE);
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
  gtk_tool_button_set_stock_id (button, stock_id);
  G_GNUC_END_IGNORE_DEPRECATIONS;
  gtk_tool_button_set_icon_name (button, gtk_action_get_icon_name (action));

  if (stock_id)
    {
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
      icon_set = gtk_icon_factory_lookup_default (stock_id);
      G_GNUC_END_IGNORE_DEPRECATIONS;
    }

  if (icon_set != NULL)
      gtk_tool_button_set_icon_widget (button, NULL);
  else if ((icon = gtk_action_get_gicon (action)) != NULL)
    {
      GtkIconSize icon_size = gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (button));
      GtkWidget  *image = gtk_tool_button_get_icon_widget (button);
      
      if (!image)
	{
	  image = gtk_image_new ();
	  gtk_widget_show (image);
	  gtk_tool_button_set_icon_widget (button, image);
	}

      gtk_image_set_from_gicon (GTK_IMAGE (image), icon, icon_size);
    }
  else if (gtk_action_get_icon_name (action))
    gtk_tool_button_set_icon_name (button, gtk_action_get_icon_name (action));
  else
    gtk_tool_button_set_label (button, gtk_action_get_short_label (action));
}
Example #3
0
static void
gtk_tool_button_update (GtkActivatable *activatable,
			GtkAction      *action,
			const gchar    *property_name)
{
  GtkToolButton *button;
  GtkWidget *image;

  parent_activatable_iface->update (activatable, action, property_name);

  if (!gtk_activatable_get_use_action_appearance (activatable))
    return;

  button = GTK_TOOL_BUTTON (activatable);
  
  if (strcmp (property_name, "short-label") == 0)
    gtk_tool_button_set_label (button, gtk_action_get_short_label (action));
  else if (strcmp (property_name, "stock-id") == 0)
    gtk_tool_button_set_stock_id (button, gtk_action_get_stock_id (action));
  else if (strcmp (property_name, "gicon") == 0)
    {
      const gchar *stock_id = gtk_action_get_stock_id (action);
      GIcon *icon = gtk_action_get_gicon (action);
      GtkIconSize icon_size = GTK_ICON_SIZE_BUTTON;

      if ((stock_id && gtk_icon_factory_lookup_default (stock_id)) || !icon)
	image = NULL;
      else 
	{   
	  image = gtk_tool_button_get_icon_widget (button);
	  icon_size = gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (button));

	  if (!image)
	    image = gtk_image_new ();
	}

      gtk_tool_button_set_icon_widget (button, image);
      gtk_image_set_from_gicon (GTK_IMAGE (image), icon, icon_size);

    }
  else if (strcmp (property_name, "icon-name") == 0)
    gtk_tool_button_set_icon_name (button, gtk_action_get_icon_name (action));
}
static void
seahorse_generate_select_constructed (GObject *obj)
{
	SeahorseGenerateSelect *self = SEAHORSE_GENERATE_SELECT (obj);
	gchar *text;
	GtkCellRenderer *pixcell;
	GtkTreeSelection *selection;
	GtkTreeIter iter;
	GList *actions;
	GList *l, *k;
	GIcon *icon;
	GtkBuilder *builder;
	const gchar *path;
	GError *error = NULL;
	const gchar *icon_name;
	GtkAction *action;

	G_OBJECT_CLASS (seahorse_generate_select_parent_class)->constructed (obj);

	self->store = gtk_list_store_new (COLUMN_N_COLUMNS, G_TYPE_ICON, G_TYPE_STRING, GTK_TYPE_ACTION);
	gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (self->store), on_list_sort, NULL, NULL);
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);

	self->action_groups = seahorse_registry_object_instances ("generator");
	for (l = self->action_groups; l != NULL; l = g_list_next (l)) {
		actions = gtk_action_group_list_actions (l->data);
		for (k = actions; k != NULL; k = g_list_next (k)) {
			action = k->data;

			text = g_strdup_printf (TEMPLATE, gtk_action_get_label (action),
			                        gtk_action_get_tooltip (action));

			icon = gtk_action_get_gicon (action);
			if (icon == NULL) {
				icon_name = gtk_action_get_icon_name (action);
				if (icon_name)
					icon = g_themed_icon_new (icon_name);
				gtk_action_get_stock_id (action);
			} else {
				g_object_ref (icon);
			}

			gtk_list_store_append (self->store, &iter);
			gtk_list_store_set (self->store, &iter,
			                    COLUMN_TEXT, text, 
			                    COLUMN_ICON, icon, 
			                    COLUMN_ACTION, k->data,
			                    -1);
			g_clear_object (&icon);
		}

		g_list_free (actions);
	}

	builder = gtk_builder_new ();
	path = "/org/gnome/Seahorse/seahorse-generate-select.xml";
	gtk_builder_add_from_resource (builder, path, &error);
	if (error != NULL) {
		g_warning ("couldn't load ui file: %s", path);
		g_clear_error (&error);
		g_object_unref (builder);
		return;
	}

	/* Setup the dialog */
	gtk_window_set_modal (GTK_WINDOW (self), TRUE);
	gtk_window_set_default_size (GTK_WINDOW (self), -1, 410);
	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))),
	                    GTK_WIDGET (gtk_builder_get_object (builder, "generate-select")),
	                    TRUE, TRUE, 0);
	gtk_dialog_add_buttons (GTK_DIALOG (self),
	                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
	                        _("Continue"), GTK_RESPONSE_OK,
	                        NULL);

	/* Hook it into the view */
	self->view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "keytype-tree"));

	g_object_unref (builder);

	pixcell = gtk_cell_renderer_pixbuf_new ();
	g_object_set (pixcell, "stock-size", GTK_ICON_SIZE_DND, NULL);
	gtk_tree_view_insert_column_with_attributes (self->view, -1, "", pixcell, "gicon", COLUMN_ICON, NULL);
	gtk_tree_view_insert_column_with_attributes (self->view, -1, "", gtk_cell_renderer_text_new (), "markup", COLUMN_TEXT, NULL);
	gtk_tree_view_set_model (self->view, GTK_TREE_MODEL (self->store));

	/* Setup selection, select first item */
	selection = gtk_tree_view_get_selection (self->view);
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);

	gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
	gtk_tree_selection_select_iter (selection, &iter);

	g_signal_connect (self->view, "row-activated", G_CALLBACK (on_row_activated), self);
	g_object_set (self->view, "height-request", 410, NULL);

	g_signal_connect (self, "response", G_CALLBACK (on_response), self);
}