[latexila] Don't use gtk_widget_render_icon_pixbuf() (deprecated)



commit 8879d1b95db4d353bf42c5b863ec305424f361a7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Dec 24 22:37:50 2014 +0100

    Don't use gtk_widget_render_icon_pixbuf() (deprecated)

 docs/reference/latexila-sections.txt |    1 +
 src/completion.vala                  |   14 ++++++++------
 src/liblatexila/latexila-utils.c     |   32 ++++++++++++++++++++++++++++++++
 src/liblatexila/latexila-utils.h     |    3 +++
 src/utils.vala                       |    6 ------
 5 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index fa84048..68e2c17 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -236,6 +236,7 @@ latexila_utils_get_shortname
 latexila_utils_get_extension
 latexila_utils_replace_home_dir_with_tilde
 latexila_utils_register_icons
+latexila_utils_get_pixbuf_from_icon_name
 latexila_utils_str_replace
 latexila_utils_file_query_exists_async
 latexila_utils_file_query_exists_finish
diff --git a/src/completion.vala b/src/completion.vala
index cece274..a97636e 100644
--- a/src/completion.vala
+++ b/src/completion.vala
@@ -71,9 +71,9 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
     private CompletionArgument _current_arg;
     private CompletionChoice _current_choice;
 
-    private Gdk.Pixbuf _icon_cmd;
-    private Gdk.Pixbuf _icon_choice;
-    private Gdk.Pixbuf _icon_package_required;
+    private Gdk.Pixbuf? _icon_cmd;
+    private Gdk.Pixbuf? _icon_choice;
+    private Gdk.Pixbuf? _icon_package_required;
 
     private SourceCompletionInfo _calltip_window = null;
     private Label _calltip_window_label = null;
@@ -84,9 +84,11 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
         _settings = new GLib.Settings ("org.gnome.latexila.preferences.latex");
 
         // icons
-        _icon_cmd = Utils.get_pixbuf_from_stock ("completion_cmd", IconSize.MENU);
-        _icon_choice = Utils.get_pixbuf_from_stock ("gray-square", IconSize.MENU);
-        _icon_package_required = Utils.get_pixbuf_from_stock (Stock.DIALOG_WARNING,
+        _icon_cmd = Latexila.utils_get_pixbuf_from_icon_name ("completion_cmd",
+            IconSize.MENU);
+        _icon_choice = Latexila.utils_get_pixbuf_from_icon_name ("gray-square",
+            IconSize.MENU);
+        _icon_package_required = Latexila.utils_get_pixbuf_from_icon_name ("dialog-warning",
             IconSize.MENU);
 
         load_data ();
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index c101530..c6df9c6 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -159,6 +159,38 @@ latexila_utils_register_icons (void)
 }
 
 /**
+ * latexila_utils_get_pixbuf_from_icon_name:
+ * @icon_name: an icon name.
+ * @icon_size: an icon size.
+ *
+ * Returns: (nullable) (transfer full): the corresponding #GdkPixbuf.
+ */
+GdkPixbuf *
+latexila_utils_get_pixbuf_from_icon_name (const gchar *icon_name,
+                                          GtkIconSize  icon_size)
+{
+  gint size;
+  GdkPixbuf *pixbuf;
+  GError *error = NULL;
+
+  gtk_icon_size_lookup (icon_size, &size, NULL);
+
+  pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                     icon_name,
+                                     size,
+                                     0,
+                                     &error);
+
+  if (error != NULL)
+    {
+      g_warning ("Error when loading icon \"%s\": %s", icon_name, error->message);
+      g_error_free (error);
+    }
+
+  return pixbuf;
+}
+
+/**
  * latexila_utils_str_replace:
  * @string: a string
  * @search: the search string
diff --git a/src/liblatexila/latexila-utils.h b/src/liblatexila/latexila-utils.h
index ff12893..9d58327 100644
--- a/src/liblatexila/latexila-utils.h
+++ b/src/liblatexila/latexila-utils.h
@@ -32,6 +32,9 @@ gchar *         latexila_utils_replace_home_dir_with_tilde      (const gchar *fi
 
 void            latexila_utils_register_icons                   (void);
 
+GdkPixbuf *     latexila_utils_get_pixbuf_from_icon_name        (const gchar *icon_name,
+                                                                 GtkIconSize  icon_size);
+
 gchar *         latexila_utils_str_replace                      (const gchar *string,
                                                                  const gchar *search,
                                                                  const gchar *replacement);
diff --git a/src/utils.vala b/src/utils.vala
index 7c92a3b..14a51b4 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -283,12 +283,6 @@ namespace Utils
         return -1;
     }
 
-    public Gdk.Pixbuf get_pixbuf_from_stock (string stock_id, Gtk.IconSize size)
-    {
-        Gtk.Invisible widget = new Gtk.Invisible ();
-        return widget.render_icon_pixbuf (stock_id, size);
-    }
-
     public Grid get_dialog_component (string title, Widget widget)
     {
         Grid grid = new Grid ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]