xed-panel: Clean up more uses of GtkStock

Also update a couple of the plugins that call this functionality
This commit is contained in:
JosephMcc 2017-01-01 15:41:06 -08:00
parent 8ab7e902bb
commit ded60fbe20
5 changed files with 20 additions and 124 deletions

View File

@ -531,8 +531,8 @@ xed_file_browser_plugin_activate (PeasActivatable *activatable)
XedFileBrowserPluginPrivate *data; XedFileBrowserPluginPrivate *data;
XedWindow *window; XedWindow *window;
XedPanel * panel; XedPanel * panel;
GtkWidget * image; // GtkWidget * image;
GdkPixbuf * pixbuf; // GdkPixbuf * pixbuf;
XedFileBrowserStore * store; XedFileBrowserStore * store;
gchar *data_dir; gchar *data_dir;
GSettingsSchemaSource *schema_source; GSettingsSchemaSource *schema_source;
@ -578,21 +578,18 @@ xed_file_browser_plugin_activate (PeasActivatable *activatable)
data); data);
panel = xed_window_get_side_panel (window); panel = xed_window_get_side_panel (window);
pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager", // pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager",
GTK_ICON_SIZE_MENU); // GTK_ICON_SIZE_MENU);
if (pixbuf) { // if (pixbuf) {
image = gtk_image_new_from_pixbuf(pixbuf); // image = gtk_image_new_from_pixbuf(pixbuf);
g_object_unref(pixbuf); // g_object_unref(pixbuf);
} else { // } else {
image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU); // image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU);
} // }
gtk_widget_show(image); // gtk_widget_show(image);
xed_panel_add_item (panel, xed_panel_add_item (panel, GTK_WIDGET (data->tree_widget), _("File Browser"), "system-file-manager");
GTK_WIDGET (data->tree_widget),
_("File Browser"),
image);
gtk_widget_show (GTK_WIDGET (data->tree_widget)); gtk_widget_show (GTK_WIDGET (data->tree_widget));
add_popup_ui (data); add_popup_ui (data);

View File

@ -121,10 +121,7 @@ xed_taglist_plugin_activate (PeasActivatable *activatable)
priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir);
g_free (data_dir); g_free (data_dir);
xed_panel_add_item_with_stock_icon (side_panel, xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add");
priv->taglist_panel,
_("Tags"),
GTK_STOCK_ADD);
} }
static void static void

View File

@ -323,68 +323,6 @@ xed_panel_class_init (XedPanelClass *klass)
0); 0);
} }
/* This is ugly, since it supports only known
* storage types of GtkImage, otherwise fall back
* to the empty icon.
* See http://bugzilla.gnome.org/show_bug.cgi?id=317520.
*/
static void
set_gtk_image_from_gtk_image (GtkImage *image,
GtkImage *source)
{
switch (gtk_image_get_storage_type (source))
{
case GTK_IMAGE_EMPTY:
gtk_image_clear (image);
break;
case GTK_IMAGE_PIXBUF:
{
GdkPixbuf *pb;
pb = gtk_image_get_pixbuf (source);
gtk_image_set_from_pixbuf (image, pb);
}
break;
case GTK_IMAGE_STOCK:
{
gchar *s_id;
GtkIconSize s;
gtk_image_get_stock (source, &s_id, &s);
gtk_image_set_from_stock (image, s_id, s);
}
break;
case GTK_IMAGE_ICON_SET:
{
GtkIconSet *is;
GtkIconSize s;
gtk_image_get_icon_set (source, &is, &s);
gtk_image_set_from_icon_set (image, is, s);
}
break;
case GTK_IMAGE_ANIMATION:
{
GdkPixbufAnimation *a;
a = gtk_image_get_animation (source);
gtk_image_set_from_animation (image, a);
}
break;
case GTK_IMAGE_ICON_NAME:
{
const gchar *n;
GtkIconSize s;
gtk_image_get_icon_name (source, &n, &s);
gtk_image_set_from_icon_name (image, n, s);
}
break;
default:
gtk_image_set_from_stock (image, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
}
}
static void static void
xed_panel_init (XedPanel *panel) xed_panel_init (XedPanel *panel)
{ {
@ -521,7 +459,7 @@ update_tabs_visibility (XedPanel *panel)
* @panel: a #XedPanel * @panel: a #XedPanel
* @item: the #GtkWidget to add to the @panel * @item: the #GtkWidget to add to the @panel
* @name: the name to be shown in the @panel * @name: the name to be shown in the @panel
* @image: the image to be shown in the @panel * @icon_name: the name of the icon to be shown in the @panel
* *
* Adds a new item to the @panel. * Adds a new item to the @panel.
*/ */
@ -529,35 +467,29 @@ void
xed_panel_add_item (XedPanel *panel, xed_panel_add_item (XedPanel *panel,
GtkWidget *item, GtkWidget *item,
const gchar *name, const gchar *name,
GtkWidget *image) const gchar *icon_name)
{ {
XedPanelItem *data; XedPanelItem *data;
GtkWidget *tab_label; GtkWidget *tab_label;
GtkWidget *menu_label; GtkWidget *menu_label;
gint w, h;
g_return_if_fail (XED_IS_PANEL (panel)); g_return_if_fail (XED_IS_PANEL (panel));
g_return_if_fail (GTK_IS_WIDGET (item)); g_return_if_fail (GTK_IS_WIDGET (item));
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
g_return_if_fail (image == NULL || GTK_IS_IMAGE (image));
data = g_new (XedPanelItem, 1); data = g_new (XedPanelItem, 1);
data->name = g_strdup (name); data->name = g_strdup (name);
if (image == NULL) if (icon_name)
{ {
/* default to empty */ data->icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
} }
else else
{ {
data->icon = image; data->icon = gtk_image_new_from_icon_name ("text-x-generic", GTK_ICON_SIZE_MENU);
} }
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
gtk_widget_set_size_request (data->icon, w, h);
g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, data); g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, data);
tab_label = build_tab_label (panel, item, data->name, data->icon); tab_label = build_tab_label (panel, item, data->name, data->icon);
@ -577,31 +509,6 @@ xed_panel_add_item (XedPanel *panel,
g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item); g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item);
} }
/**
* xed_panel_add_item_with_stock_icon:
* @panel: a #XedPanel
* @item: the #GtkWidget to add to the @panel
* @name: the name to be shown in the @panel
* @stock_id: a stock id
*
* Same as xed_panel_add_item() but using an image from stock.
*/
void
xed_panel_add_item_with_stock_icon (XedPanel *panel,
GtkWidget *item,
const gchar *name,
const gchar *stock_id)
{
GtkWidget *icon = NULL;
if (stock_id != NULL)
{
icon = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
}
xed_panel_add_item (panel, item, name, icon);
}
/** /**
* xed_panel_remove_item: * xed_panel_remove_item:
* @panel: a #XedPanel * @panel: a #XedPanel

View File

@ -96,12 +96,7 @@ GtkWidget *xed_panel_new (GtkOrientation orientation);
void xed_panel_add_item (XedPanel *panel, void xed_panel_add_item (XedPanel *panel,
GtkWidget *item, GtkWidget *item,
const gchar *name, const gchar *name,
GtkWidget *image); const gchar *icon_name);
void xed_panel_add_item_with_stock_icon (XedPanel *panel,
GtkWidget *item,
const gchar *name,
const gchar *stock_id);
gboolean xed_panel_remove_item (XedPanel *panel, gboolean xed_panel_remove_item (XedPanel *panel,
GtkWidget *item); GtkWidget *item);

View File

@ -3177,7 +3177,7 @@ create_side_panel (XedWindow *window)
g_signal_connect_after (window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window); g_signal_connect_after (window->priv->side_panel, "hide", G_CALLBACK (side_panel_visibility_changed), window);
documents_panel = xed_documents_panel_new (window); documents_panel = xed_documents_panel_new (window);
xed_panel_add_item_with_stock_icon (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"), xed_panel_add_item (XED_PANEL (window->priv->side_panel), documents_panel, _("Documents"),
GTK_STOCK_FILE); GTK_STOCK_FILE);
} }