xed-tab: Clean up some uses of GtkStock

This commit is contained in:
JosephMcc 2017-01-01 21:41:09 -08:00
parent baea0e93b9
commit d77659fdcd
2 changed files with 44 additions and 87 deletions

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
@ -108,7 +108,7 @@ xed_tab_label_get_property (GObject *object,
} }
static void static void
close_button_clicked_cb (GtkWidget *widget, close_button_clicked_cb (GtkWidget *widget,
XedTabLabel *tab_label) XedTabLabel *tab_label)
{ {
g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL); g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL);
@ -172,12 +172,17 @@ sync_state (XedTab *tab, GParamSpec *pspec, XedTabLabel *tab_label)
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
pixbuf = _xed_tab_get_icon (tab); pixbuf = _xed_tab_get_icon (tab);
gtk_image_set_from_pixbuf (GTK_IMAGE (tab_label->priv->icon), pixbuf);
if (pixbuf != NULL) if (pixbuf != NULL)
g_object_unref (pixbuf); {
gtk_image_set_from_pixbuf (GTK_IMAGE (tab_label->priv->icon), pixbuf);
gtk_widget_show (tab_label->priv->icon); g_clear_object (&pixbuf);
gtk_widget_show (tab_label->priv->icon);
}
else
{
gtk_widget_hide (tab_label->priv->icon);
}
gtk_widget_hide (tab_label->priv->spinner); gtk_widget_hide (tab_label->priv->spinner);
gtk_spinner_stop (GTK_SPINNER (tab_label->priv->spinner)); gtk_spinner_stop (GTK_SPINNER (tab_label->priv->spinner));
@ -218,7 +223,7 @@ static void
xed_tab_label_class_init (XedTabLabelClass *klass) xed_tab_label_class_init (XedTabLabelClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = xed_tab_label_finalize; object_class->finalize = xed_tab_label_finalize;
object_class->set_property = xed_tab_label_set_property; object_class->set_property = xed_tab_label_set_property;
object_class->get_property = xed_tab_label_get_property; object_class->get_property = xed_tab_label_get_property;
@ -329,7 +334,7 @@ xed_tab_label_set_close_button_sensitive (XedTabLabel *tab_label,
state = xed_tab_get_state (tab_label->priv->tab); state = xed_tab_get_state (tab_label->priv->tab);
gtk_widget_set_sensitive (tab_label->priv->close_button, gtk_widget_set_sensitive (tab_label->priv->close_button,
tab_label->priv->close_button_sensitive && tab_label->priv->close_button_sensitive &&
(state != XED_TAB_STATE_CLOSING) && (state != XED_TAB_STATE_CLOSING) &&
(state != XED_TAB_STATE_SAVING) && (state != XED_TAB_STATE_SAVING) &&

View File

@ -1656,55 +1656,6 @@ _xed_tab_get_tooltips (XedTab *tab)
return tip; return tip;
} }
static GdkPixbuf *
resize_icon (GdkPixbuf *pixbuf,
gint size)
{
gint width, height;
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
/* if the icon is larger than the nominal size, scale down */
if (MAX (width, height) > size)
{
GdkPixbuf *scaled_pixbuf;
if (width > height)
{
height = height * size / width;
width = size;
}
else
{
width = width * size / height;
height = size;
}
scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = scaled_pixbuf;
}
return pixbuf;
}
static GdkPixbuf *
get_stock_icon (GtkIconTheme *theme,
const gchar *stock,
gint size)
{
GdkPixbuf *pixbuf;
pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL);
if (pixbuf == NULL)
{
return NULL;
}
return resize_icon (pixbuf, size);
}
static GdkPixbuf * static GdkPixbuf *
get_icon (GtkIconTheme *theme, get_icon (GtkIconTheme *theme,
GFile *location, GFile *location,
@ -1717,7 +1668,7 @@ get_icon (GtkIconTheme *theme,
if (location == NULL) if (location == NULL)
{ {
return get_stock_icon (theme, GTK_STOCK_FILE, size); return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL);
} }
/* FIXME: Doing a sync stat is bad, this should be fixed */ /* FIXME: Doing a sync stat is bad, this should be fixed */
@ -1728,7 +1679,7 @@ get_icon (GtkIconTheme *theme,
NULL); NULL);
if (info == NULL) if (info == NULL)
{ {
return get_stock_icon (theme, GTK_STOCK_FILE, size); return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL);
} }
gicon = g_file_info_get_icon (info); gicon = g_file_info_get_icon (info);
@ -1736,7 +1687,7 @@ get_icon (GtkIconTheme *theme,
if (gicon == NULL) if (gicon == NULL)
{ {
g_object_unref (info); g_object_unref (info);
return get_stock_icon (theme, GTK_STOCK_FILE, size); return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL);
} }
icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0); icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0);
@ -1744,18 +1695,18 @@ get_icon (GtkIconTheme *theme,
if (icon_info == NULL) if (icon_info == NULL)
{ {
return get_stock_icon (theme, GTK_STOCK_FILE, size); return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL);
} }
pixbuf = gtk_icon_info_load_icon (icon_info, NULL); pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
gtk_icon_info_free (icon_info); g_object_unref (icon_info);
if (pixbuf == NULL) if (pixbuf == NULL)
{ {
return get_stock_icon (theme, GTK_STOCK_FILE, size); return gtk_icon_theme_load_icon (theme, "text-x-generic", size, 0, NULL);
} }
return resize_icon (pixbuf, size); return pixbuf;
} }
/* FIXME: add support for theme changed. I think it should be as easy as /* FIXME: add support for theme changed. I think it should be as easy as
@ -1763,15 +1714,15 @@ get_icon (GtkIconTheme *theme,
GdkPixbuf * GdkPixbuf *
_xed_tab_get_icon (XedTab *tab) _xed_tab_get_icon (XedTab *tab)
{ {
GdkPixbuf *pixbuf;
GtkIconTheme *theme;
GdkScreen *screen; GdkScreen *screen;
GtkIconTheme *theme;
gint icon_size; gint icon_size;
const gchar *icon_name;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (XED_IS_TAB (tab), NULL); g_return_val_if_fail (XED_IS_TAB (tab), NULL);
screen = gtk_widget_get_screen (GTK_WIDGET (tab)); screen = gtk_widget_get_screen (GTK_WIDGET (tab));
theme = gtk_icon_theme_get_for_screen (screen); theme = gtk_icon_theme_get_for_screen (screen);
g_return_val_if_fail (theme != NULL, NULL); g_return_val_if_fail (theme != NULL, NULL);
@ -1780,52 +1731,53 @@ _xed_tab_get_icon (XedTab *tab)
switch (tab->priv->state) switch (tab->priv->state)
{ {
case XED_TAB_STATE_LOADING: case XED_TAB_STATE_LOADING:
pixbuf = get_stock_icon (theme, GTK_STOCK_OPEN, icon_size); icon_name = "document-open-symbolic";
break; break;
case XED_TAB_STATE_REVERTING: case XED_TAB_STATE_REVERTING:
pixbuf = get_stock_icon (theme, GTK_STOCK_REVERT_TO_SAVED, icon_size); icon_name = "document-revert-symbolic";
break; break;
case XED_TAB_STATE_SAVING: case XED_TAB_STATE_SAVING:
pixbuf = get_stock_icon (theme, GTK_STOCK_SAVE, icon_size); icon_name = "document-save-symbolic";
break; break;
case XED_TAB_STATE_PRINTING: case XED_TAB_STATE_PRINTING:
pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT, icon_size); icon_name = "printer-printing-symbolic";
break; break;
case XED_TAB_STATE_PRINT_PREVIEWING: case XED_TAB_STATE_PRINT_PREVIEWING:
case XED_TAB_STATE_SHOWING_PRINT_PREVIEW: case XED_TAB_STATE_SHOWING_PRINT_PREVIEW:
pixbuf = get_stock_icon (theme, GTK_STOCK_PRINT_PREVIEW, icon_size); icon_name = "printer-symbolic";
break; break;
case XED_TAB_STATE_LOADING_ERROR: case XED_TAB_STATE_LOADING_ERROR:
case XED_TAB_STATE_REVERTING_ERROR: case XED_TAB_STATE_REVERTING_ERROR:
case XED_TAB_STATE_SAVING_ERROR: case XED_TAB_STATE_SAVING_ERROR:
case XED_TAB_STATE_GENERIC_ERROR: case XED_TAB_STATE_GENERIC_ERROR:
pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_ERROR, icon_size); icon_name = "dialog-error-symbolic";
break; break;
case XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION: case XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION:
pixbuf = get_stock_icon (theme, GTK_STOCK_DIALOG_WARNING, icon_size); icon_name = "dialog-warning-symbolic";
break; break;
default: default:
{ icon_name = NULL;
GFile *location; }
XedDocument *doc;
doc = xed_tab_get_document (tab); if (icon_name != NULL)
{
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, icon_size, 0, NULL);
}
else
{
GFile *location;
XedDocument *doc;
location = xed_document_get_location (doc); doc = xed_tab_get_document (tab);
pixbuf = get_icon (theme, location, icon_size); location = xed_document_get_location (doc);
pixbuf = get_icon (theme, location, icon_size);
if (location)
{
g_object_unref (location);
}
}
} }
return pixbuf; return pixbuf;