[gedit] file-browser: correct color for symbolic icons in dark mode



commit 9913f5ae478cad6eca232034a81212f067cfa4c7
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sat Nov 24 15:40:24 2018 +0100

    file-browser: correct color for symbolic icons in dark mode
    
    Previously, symbolics icons were hard-coded with pixbufs in the stores,
    means no re-colorization when the theme change.
    
    fix #99

 plugins/filebrowser/gedit-file-bookmarks-store.c   | 53 ++++++++---------
 plugins/filebrowser/gedit-file-bookmarks-store.h   |  1 +
 plugins/filebrowser/gedit-file-browser-store.c     |  9 ++-
 plugins/filebrowser/gedit-file-browser-store.h     |  1 +
 plugins/filebrowser/gedit-file-browser-utils.c     | 43 ++++++++++++++
 plugins/filebrowser/gedit-file-browser-utils.h     | 29 +++++-----
 plugins/filebrowser/gedit-file-browser-view.c      | 39 +++++++++++--
 plugins/filebrowser/gedit-file-browser-widget.c    | 66 ++++++++++++++++++----
 .../resources/ui/gedit-file-browser-widget.ui      | 12 ++--
 9 files changed, 187 insertions(+), 66 deletions(-)
---
diff --git a/plugins/filebrowser/gedit-file-bookmarks-store.c 
b/plugins/filebrowser/gedit-file-bookmarks-store.c
index 6bd8b44c6..df0968d7f 100644
--- a/plugins/filebrowser/gedit-file-bookmarks-store.c
+++ b/plugins/filebrowser/gedit-file-bookmarks-store.c
@@ -99,6 +99,7 @@ gedit_file_bookmarks_store_init (GeditFileBookmarksStore *obj)
 static void
 add_node (GeditFileBookmarksStore *model,
          GdkPixbuf               *pixbuf,
+         const gchar             *icon_name,
          const gchar             *name,
          GObject                 *obj,
          guint                    flags,
@@ -110,6 +111,7 @@ add_node (GeditFileBookmarksStore *model,
 
        gtk_tree_store_set (GTK_TREE_STORE (model), &newiter,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON, pixbuf,
+                           GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON_NAME, icon_name,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_NAME, name,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, obj,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, flags,
@@ -126,27 +128,26 @@ add_file (GeditFileBookmarksStore *model,
          guint                    flags,
          GtkTreeIter             *iter)
 {
-       GdkPixbuf *pixbuf = NULL;
        gboolean native = g_file_is_native (file);
+       gchar *icon_name = NULL;
        gchar *newname;
 
        if (native && !g_file_query_exists (file, NULL))
                return FALSE;
 
        if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_HOME)
-               pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("user-home-symbolic", 
GTK_ICON_SIZE_MENU);
+               icon_name = g_strdup ("user-home-symbolic");
        else if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP)
-               pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("user-desktop-symbolic", 
GTK_ICON_SIZE_MENU);
+               icon_name = g_strdup ("user-desktop-symbolic");
        else if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT)
-               pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("drive-harddisk-symbolic", 
GTK_ICON_SIZE_MENU);
-
-       if (pixbuf == NULL)
+               icon_name = g_strdup ("drive-harddisk-symbolic");
+       else
        {
                /* getting the icon is a sync get_info call, so we just do it for local files */
                if (native)
-                       pixbuf = gedit_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU, TRUE);
+                       icon_name = gedit_file_browser_utils_symbolic_icon_name_from_file (file);
                else
-                       pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("folder-symbolic", 
GTK_ICON_SIZE_MENU);
+                       icon_name = g_strdup ("folder-symbolic");
        }
 
        if (name == NULL)
@@ -154,11 +155,9 @@ add_file (GeditFileBookmarksStore *model,
        else
                newname = g_strdup (name);
 
-       add_node (model, pixbuf, newname, G_OBJECT (file), flags, iter);
-
-       if (pixbuf)
-               g_object_unref (pixbuf);
+       add_node (model, NULL, icon_name, newname, G_OBJECT (file), flags, iter);
 
+       g_free (icon_name);
        g_free (newname);
 
        return TRUE;
@@ -238,21 +237,22 @@ init_special_directories (GeditFileBookmarksStore *model)
 }
 
 static void
-get_fs_properties (gpointer    fs,
-                  gchar     **name,
-                  GdkPixbuf **pixbuf,
-                  guint      *flags)
+get_fs_properties (gpointer   fs,
+                  gchar    **name,
+                  gchar    **icon_name,
+                  guint     *flags)
 {
        GIcon *icon = NULL;
 
        *flags = GEDIT_FILE_BOOKMARKS_STORE_IS_FS;
        *name = NULL;
-       *pixbuf = NULL;
+       *icon_name = NULL;
 
        if (G_IS_DRIVE (fs))
        {
                icon = g_drive_get_symbolic_icon (G_DRIVE (fs));
                *name = g_drive_get_name (G_DRIVE (fs));
+               *icon_name = gedit_file_browser_utils_name_from_themed_icon (icon);
 
                *flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE;
        }
@@ -260,6 +260,7 @@ get_fs_properties (gpointer    fs,
        {
                icon = g_volume_get_symbolic_icon (G_VOLUME (fs));
                *name = g_volume_get_name (G_VOLUME (fs));
+               *icon_name = gedit_file_browser_utils_name_from_themed_icon (icon);
 
                *flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME;
        }
@@ -267,35 +268,30 @@ get_fs_properties (gpointer    fs,
        {
                icon = g_mount_get_symbolic_icon (G_MOUNT (fs));
                *name = g_mount_get_name (G_MOUNT (fs));
+               *icon_name = gedit_file_browser_utils_name_from_themed_icon (icon);
 
                *flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT;
        }
 
        if (icon)
-       {
-               *pixbuf = gedit_file_browser_utils_pixbuf_from_icon (icon, GTK_ICON_SIZE_MENU);
                g_object_unref (icon);
-       }
 }
 
-
 static void
 add_fs (GeditFileBookmarksStore *model,
        gpointer                 fs,
        guint                    flags,
        GtkTreeIter             *iter)
 {
-       gchar *name;
-       GdkPixbuf *pixbuf;
+       gchar *icon_name = NULL;
+       gchar *name = NULL;
        guint fsflags;
 
-       get_fs_properties (fs, &name, &pixbuf, &fsflags);
-       add_node (model, pixbuf, name, fs, flags | fsflags, iter);
-
-       if (pixbuf)
-               g_object_unref (pixbuf);
+       get_fs_properties (fs, &name, &icon_name, &fsflags);
+       add_node (model, NULL, icon_name, name, fs, flags | fsflags, iter);
 
        g_free (name);
+       g_free (icon_name);
        check_mount_separator (model, GEDIT_FILE_BOOKMARKS_STORE_IS_FS, TRUE);
 }
 
@@ -801,6 +797,7 @@ gedit_file_bookmarks_store_new (void)
        GType column_types[] = {
                GDK_TYPE_PIXBUF,
                G_TYPE_STRING,
+               G_TYPE_STRING,
                G_TYPE_OBJECT,
                G_TYPE_UINT
        };
diff --git a/plugins/filebrowser/gedit-file-bookmarks-store.h 
b/plugins/filebrowser/gedit-file-bookmarks-store.h
index ac47a79a5..19de53b8d 100644
--- a/plugins/filebrowser/gedit-file-bookmarks-store.h
+++ b/plugins/filebrowser/gedit-file-bookmarks-store.h
@@ -39,6 +39,7 @@ typedef struct _GeditFileBookmarksStorePrivate GeditFileBookmarksStorePrivate;
 enum
 {
        GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON = 0,
+       GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON_NAME,
        GEDIT_FILE_BOOKMARKS_STORE_COLUMN_NAME,
        GEDIT_FILE_BOOKMARKS_STORE_COLUMN_OBJECT,
        GEDIT_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
diff --git a/plugins/filebrowser/gedit-file-browser-store.c b/plugins/filebrowser/gedit-file-browser-store.c
index 497578b47..582fcc30d 100644
--- a/plugins/filebrowser/gedit-file-browser-store.c
+++ b/plugins/filebrowser/gedit-file-browser-store.c
@@ -85,6 +85,7 @@ struct _FileBrowserNode
 {
        GFile           *file;
        guint            flags;
+       gchar           *icon_name;
        gchar           *name;
        gchar           *markup;
 
@@ -476,6 +477,7 @@ gedit_file_browser_store_init (GeditFileBrowserStore *obj)
        obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_MARKUP] = G_TYPE_STRING;
        obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_FLAGS] = G_TYPE_UINT;
        obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_ICON] = GDK_TYPE_PIXBUF;
+       obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_ICON_NAME] = G_TYPE_STRING;
        obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_NAME] = G_TYPE_STRING;
        obj->priv->column_types[GEDIT_FILE_BROWSER_STORE_COLUMN_EMBLEM] = GDK_TYPE_PIXBUF;
 
@@ -702,6 +704,9 @@ gedit_file_browser_store_get_value (GtkTreeModel *tree_model,
                case GEDIT_FILE_BROWSER_STORE_COLUMN_ICON:
                        g_value_set_object (value, node->icon);
                        break;
+               case GEDIT_FILE_BROWSER_STORE_COLUMN_ICON_NAME:
+                       g_value_set_string (value, node->icon_name);
+                       break;
                case GEDIT_FILE_BROWSER_STORE_COLUMN_NAME:
                        g_value_set_string (value, node->name);
                        break;
@@ -1417,6 +1422,7 @@ file_browser_node_free (GeditFileBrowserStore *model,
        if (node->emblem)
                g_object_unref (node->emblem);
 
+       g_free (node->icon_name);
        g_free (node->name);
        g_free (node->markup);
 
@@ -2165,8 +2171,7 @@ model_add_node_from_dir (GeditFileBrowserStore *model,
                if (node->name == NULL)
                        file_browser_node_set_name (node);
 
-               if (node->icon == NULL)
-                       node->icon = gedit_file_browser_utils_pixbuf_from_theme ("folder-symbolic", 
GTK_ICON_SIZE_MENU);
+               node->icon_name = g_strdup ("folder-symbolic");
 
                model_add_node (model, node, parent);
        }
diff --git a/plugins/filebrowser/gedit-file-browser-store.h b/plugins/filebrowser/gedit-file-browser-store.h
index cbf8f3c4c..02df0cb1b 100644
--- a/plugins/filebrowser/gedit-file-browser-store.h
+++ b/plugins/filebrowser/gedit-file-browser-store.h
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
 typedef enum
 {
        GEDIT_FILE_BROWSER_STORE_COLUMN_ICON = 0,
+       GEDIT_FILE_BROWSER_STORE_COLUMN_ICON_NAME,
        GEDIT_FILE_BROWSER_STORE_COLUMN_MARKUP,
        GEDIT_FILE_BROWSER_STORE_COLUMN_LOCATION,
        GEDIT_FILE_BROWSER_STORE_COLUMN_FLAGS,
diff --git a/plugins/filebrowser/gedit-file-browser-utils.c b/plugins/filebrowser/gedit-file-browser-utils.c
index d358ce165..a3818252c 100644
--- a/plugins/filebrowser/gedit-file-browser-utils.c
+++ b/plugins/filebrowser/gedit-file-browser-utils.c
@@ -138,6 +138,49 @@ gedit_file_browser_utils_pixbuf_from_file (GFile       *file,
        return ret;
 }
 
+gchar *
+gedit_file_browser_utils_symbolic_icon_name_from_file (GFile *file)
+{
+       GFileInfo *info;
+       GIcon *icon;
+
+       info = g_file_query_info (file,
+                                 G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 NULL,
+                                 NULL);
+
+       if (!info)
+               return NULL;
+
+       if ((icon = g_file_info_get_symbolic_icon (info)) && G_IS_THEMED_ICON (icon))
+       {
+               const gchar * const *names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+               return g_strdup (names[0]);
+       }
+
+       g_object_unref (info);
+       return NULL;
+}
+
+gchar *
+gedit_file_browser_utils_name_from_themed_icon (GIcon *icon)
+{
+       GtkIconTheme *theme;
+       const gchar * const *names;
+
+       if (!G_IS_THEMED_ICON (icon))
+               return NULL;
+
+       theme = gtk_icon_theme_get_default ();
+       names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+
+       if (gtk_icon_theme_has_icon (theme, names[0]))
+               return g_strdup (names[0]);
+
+       return NULL;
+}
+
 gchar *
 gedit_file_browser_utils_file_basename (GFile *file)
 {
diff --git a/plugins/filebrowser/gedit-file-browser-utils.h b/plugins/filebrowser/gedit-file-browser-utils.h
index 6b9c3595a..165f513a2 100644
--- a/plugins/filebrowser/gedit-file-browser-utils.h
+++ b/plugins/filebrowser/gedit-file-browser-utils.h
@@ -24,22 +24,23 @@
 #include <gedit/gedit-window.h>
 #include <gio/gio.h>
 
-GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_theme     (gchar const    *name,
-                                                                GtkIconSize     size);
+gchar           *gedit_file_browser_utils_name_from_themed_icon         (GIcon          *icon);
+GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_theme             (gchar const    *name,
+                                                                        GtkIconSize     size);
 
-GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_icon      (GIcon          *icon,
-                                                                GtkIconSize     size);
-GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_file      (GFile          *file,
-                                                                GtkIconSize     size,
-                                                                gboolean        use_symbolic);
+GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_icon              (GIcon          *icon,
+                                                                        GtkIconSize     size);
+GdkPixbuf      *gedit_file_browser_utils_pixbuf_from_file              (GFile          *file,
+                                                                        GtkIconSize     size,
+                                                                        gboolean        use_symbolic);
+gchar           *gedit_file_browser_utils_symbolic_icon_name_from_file  (GFile *file);
+gchar          *gedit_file_browser_utils_file_basename                 (GFile          *file);
 
-gchar          *gedit_file_browser_utils_file_basename         (GFile          *file);
-
-gboolean        gedit_file_browser_utils_confirmation_dialog   (GeditWindow    *window,
-                                                                GtkMessageType  type,
-                                                                gchar const    *message,
-                                                                gchar const    *secondary,
-                                                                gchar const    *button_label);
+gboolean        gedit_file_browser_utils_confirmation_dialog           (GeditWindow    *window,
+                                                                        GtkMessageType  type,
+                                                                        gchar const    *message,
+                                                                        gchar const    *secondary,
+                                                                        gchar const    *button_label);
 
 #endif /* GEDIT_FILE_BROWSER_UTILS_H */
 /* ex:set ts=8 noet: */
diff --git a/plugins/filebrowser/gedit-file-browser-view.c b/plugins/filebrowser/gedit-file-browser-view.c
index 2e3fa8925..476dabadf 100644
--- a/plugins/filebrowser/gedit-file-browser-view.c
+++ b/plugins/filebrowser/gedit-file-browser-view.c
@@ -950,6 +950,35 @@ cell_data_cb (GtkTreeViewColumn    *tree_column,
        g_object_set (cell, "editable", editable, "underline", underline, NULL);
 }
 
+static void
+icon_renderer_cb (GtkTreeViewColumn    *tree_column,
+                  GtkCellRenderer      *cell,
+                  GtkTreeModel         *tree_model,
+                  GtkTreeIter          *iter,
+                  GeditFileBrowserView *obj)
+{
+       GdkPixbuf *pixbuf;
+       gchar *icon_name;
+       gboolean set_pixbuf = FALSE;
+
+       gtk_tree_model_get (tree_model,
+                           iter,
+                           GEDIT_FILE_BROWSER_STORE_COLUMN_ICON_NAME, &icon_name,
+                           GEDIT_FILE_BROWSER_STORE_COLUMN_ICON, &pixbuf,
+                           -1);
+
+       if (pixbuf != NULL && (GEDIT_IS_FILE_BROWSER_STORE (tree_model) || icon_name == NULL))
+               set_pixbuf = TRUE;
+
+       if (set_pixbuf)
+               g_object_set (cell, "pixbuf", pixbuf, NULL);
+       else
+               g_object_set (cell, "icon-name", icon_name, NULL);
+
+       g_clear_object (&pixbuf);
+       g_free (icon_name);
+}
+
 static void
 gedit_file_browser_view_init (GeditFileBrowserView *obj)
 {
@@ -961,10 +990,12 @@ gedit_file_browser_view_init (GeditFileBrowserView *obj)
        gtk_tree_view_column_pack_start (obj->priv->column,
                                         obj->priv->pixbuf_renderer,
                                         FALSE);
-       gtk_tree_view_column_add_attribute (obj->priv->column,
-                                           obj->priv->pixbuf_renderer,
-                                           "pixbuf",
-                                           GEDIT_FILE_BROWSER_STORE_COLUMN_ICON);
+
+       gtk_tree_view_column_set_cell_data_func (obj->priv->column,
+                                                obj->priv->pixbuf_renderer,
+                                                (GtkTreeCellDataFunc)icon_renderer_cb,
+                                                obj,
+                                                NULL);
 
        obj->priv->text_renderer = gtk_cell_renderer_text_new ();
        gtk_tree_view_column_pack_start (obj->priv->column,
diff --git a/plugins/filebrowser/gedit-file-browser-widget.c b/plugins/filebrowser/gedit-file-browser-widget.c
index bb391e7b6..f971cd0de 100644
--- a/plugins/filebrowser/gedit-file-browser-widget.c
+++ b/plugins/filebrowser/gedit-file-browser-widget.c
@@ -52,6 +52,7 @@ enum
 enum
 {
        COLUMN_ICON,
+       COLUMN_ICON_NAME,
        COLUMN_NAME,
        COLUMN_FILE,
        COLUMN_ID,
@@ -103,6 +104,7 @@ typedef struct
 typedef struct
 {
        gchar     *name;
+       gchar     *icon_name;
        GdkPixbuf *icon;
 } NameIcon;
 
@@ -123,6 +125,8 @@ struct _GeditFileBrowserWidgetPrivate
        GtkWidget               *locations_button;
        GtkWidget               *locations_popover;
        GtkWidget               *locations_treeview;
+       GtkTreeViewColumn       *treeview_icon_column;
+       GtkCellRenderer         *treeview_icon_renderer;
        GtkTreeSelection        *locations_treeview_selection;
        GtkWidget               *locations_button_arrow;
        GtkWidget               *locations_cellview;
@@ -278,6 +282,7 @@ free_name_icon (gpointer data)
        if (item == NULL)
                return;
 
+       g_free (item->icon_name);
        g_free (item->name);
 
        if (item->icon)
@@ -530,6 +535,8 @@ gedit_file_browser_widget_class_init (GeditFileBrowserWidgetClass *klass)
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
locations_popover);
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
locations_treeview);
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
locations_treeview_selection);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
treeview_icon_column);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
treeview_icon_renderer);
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
locations_cellview);
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, 
locations_button_arrow);
        gtk_widget_class_bind_template_child_private (widget_class, GeditFileBrowserWidget, locations_model);
@@ -576,6 +583,7 @@ static gboolean
 get_from_bookmark_file (GeditFileBrowserWidget  *obj,
                        GFile                   *file,
                        gchar                  **name,
+                       gchar                  **icon_name,
                        GdkPixbuf              **icon)
 {
        NameIcon *item = (NameIcon *)g_hash_table_lookup (obj->priv->bookmarks_hash, file);
@@ -584,6 +592,7 @@ get_from_bookmark_file (GeditFileBrowserWidget  *obj,
                return FALSE;
 
        *name = g_strdup (item->name);
+       *icon_name = g_strdup (item->icon_name);
 
        if (icon != NULL && item->icon != NULL)
        {
@@ -600,16 +609,17 @@ insert_path_item (GeditFileBrowserWidget *obj,
                  GtkTreeIter            *iter)
 {
        gchar *unescape = NULL;
+       gchar *icon_name = NULL;
        GdkPixbuf *icon = NULL;
 
        /* Try to get the icon and name from the bookmarks hash */
-       if (!get_from_bookmark_file (obj, file, &unescape, &icon))
+       if (!get_from_bookmark_file (obj, file, &unescape, &icon_name, &icon))
        {
                /* It's not a bookmark, fetch the name and the icon ourselves */
                unescape = gedit_file_browser_utils_file_basename (file);
 
                /* Get the icon */
-               icon = gedit_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU, TRUE);
+               icon_name = gedit_file_browser_utils_symbolic_icon_name_from_file (file);
        }
 
        gtk_list_store_insert_after (obj->priv->locations_model, iter, after);
@@ -617,6 +627,7 @@ insert_path_item (GeditFileBrowserWidget *obj,
        gtk_list_store_set (obj->priv->locations_model,
                            iter,
                            COLUMN_ICON, icon,
+                           COLUMN_ICON_NAME, icon_name,
                            COLUMN_NAME, unescape,
                            COLUMN_FILE, file,
                            COLUMN_ID, PATH_ID,
@@ -625,6 +636,7 @@ insert_path_item (GeditFileBrowserWidget *obj,
        if (icon)
                g_object_unref (icon);
 
+       g_free (icon_name);
        g_free (unescape);
 }
 
@@ -636,6 +648,7 @@ insert_separator_item (GeditFileBrowserWidget *obj)
        gtk_list_store_insert (obj->priv->locations_model, &iter, 1);
        gtk_list_store_set (obj->priv->locations_model, &iter,
                            COLUMN_ICON, NULL,
+                           COLUMN_ICON_NAME, NULL,
                            COLUMN_NAME, NULL,
                            COLUMN_ID, SEPARATOR_ID, -1);
 }
@@ -734,16 +747,13 @@ static void
 fill_locations_model (GeditFileBrowserWidget *obj)
 {
        GeditFileBrowserWidgetPrivate *priv = obj->priv;
-       GtkListStore *store;
        GtkTreeIter iter;
-       GdkPixbuf *icon;
-
-       store = obj->priv->locations_model;
-       icon = gedit_file_browser_utils_pixbuf_from_theme ("user-bookmarks-symbolic", GTK_ICON_SIZE_MENU);
 
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter,
-                           COLUMN_ICON, icon,
+       gtk_list_store_append (priv->locations_model, &iter);
+       gtk_list_store_set (priv->locations_model,
+                           &iter,
+                           COLUMN_ICON, NULL,
+                           COLUMN_ICON_NAME, "user-bookmarks-symbolic",
                            COLUMN_NAME, _("Bookmarks"),
                            COLUMN_ID, BOOKMARKS_ID, -1);
 
@@ -783,6 +793,7 @@ add_bookmark_hash (GeditFileBrowserWidget *obj,
        GtkTreeModel *model = GTK_TREE_MODEL (obj->priv->bookmarks_store);
        GdkPixbuf *pixbuf;
        gchar *name;
+       gchar *icon_name;
        GFile *location;
        NameIcon *item;
 
@@ -792,11 +803,13 @@ add_bookmark_hash (GeditFileBrowserWidget *obj,
        gtk_tree_model_get (model,
                            iter,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON, &pixbuf,
+                           GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON_NAME, &icon_name,
                            GEDIT_FILE_BOOKMARKS_STORE_COLUMN_NAME, &name,
                            -1);
 
        item = g_slice_new (NameIcon);
        item->name = name;
+       item->icon_name = icon_name;
        item->icon = pixbuf;
 
        g_hash_table_insert (obj->priv->bookmarks_hash,
@@ -909,6 +922,31 @@ static GActionEntry browser_entries[] = {
        { "home", home_activated }
 };
 
+static void
+locations_icon_renderer_cb (GtkTreeViewColumn      *tree_column,
+                           GtkCellRenderer        *cell,
+                           GtkTreeModel           *tree_model,
+                           GtkTreeIter            *iter,
+                           GeditFileBrowserWidget *obj)
+{
+       GdkPixbuf *pixbuf;
+       gchar *icon_name;
+
+       gtk_tree_model_get (tree_model,
+                           iter,
+                           GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON_NAME, &icon_name,
+                           GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON, &pixbuf,
+                           -1);
+
+       if (icon_name != NULL)
+               g_object_set (cell, "icon-name", icon_name, NULL);
+       else
+               g_object_set (cell, "pixbuf", pixbuf, NULL);
+
+       g_clear_object (&pixbuf);
+       g_free (icon_name);
+}
+
 static void
 gedit_file_browser_widget_init (GeditFileBrowserWidget *obj)
 {
@@ -972,6 +1010,11 @@ gedit_file_browser_widget_init (GeditFileBrowserWidget *obj)
 
        /* locations popover */
        gtk_tree_selection_set_mode (obj->priv->locations_treeview_selection, GTK_SELECTION_SINGLE);
+       gtk_tree_view_column_set_cell_data_func (obj->priv->treeview_icon_column,
+                                                obj->priv->treeview_icon_renderer,
+                                                (GtkTreeCellDataFunc)locations_icon_renderer_cb,
+                                                obj,
+                                                NULL);
        fill_locations_model (obj);
 
        g_signal_connect (obj->priv->locations_treeview_selection, "changed",
@@ -1341,8 +1384,10 @@ create_goto_menu_item (GeditFileBrowserWidget *obj,
 {
        Location *loc = (Location *) (item->data);
        GtkWidget *result;
+       gchar *icon_name = NULL;
        gchar *unescape = NULL;
 
+       if (!get_from_bookmark_file (obj, loc->virtual_root, &unescape, &icon_name, NULL))
                unescape = gedit_file_browser_utils_file_basename (loc->virtual_root);
 
        result = gtk_menu_item_new_with_label (unescape);
@@ -1353,6 +1398,7 @@ create_goto_menu_item (GeditFileBrowserWidget *obj,
 
        gtk_widget_show (result);
 
+       g_free (icon_name);
        g_free (unescape);
 
        return result;
diff --git a/plugins/filebrowser/resources/ui/gedit-file-browser-widget.ui 
b/plugins/filebrowser/resources/ui/gedit-file-browser-widget.ui
index 957d77901..e4fb300a0 100644
--- a/plugins/filebrowser/resources/ui/gedit-file-browser-widget.ui
+++ b/plugins/filebrowser/resources/ui/gedit-file-browser-widget.ui
@@ -5,6 +5,8 @@
     <columns>
       <!-- column-name icon -->
       <column type="GdkPixbuf"/>
+      <!-- column-name icon name -->
+      <column type="gchararray"/>
       <!-- column-name name -->
       <column type="gchararray"/>
       <!-- column-name file -->
@@ -38,9 +40,6 @@
               <object class="GtkTreeViewColumn" id="treeview_icon_column">
                 <child>
                   <object class="GtkCellRendererPixbuf" id="treeview_icon_renderer"/>
-                  <attributes>
-                    <attribute name="pixbuf">0</attribute>
-                  </attributes>
                 </child>
               </object>
             </child>
@@ -51,7 +50,7 @@
                     <property name="ellipsize">end</property>
                   </object>
                   <attributes>
-                    <attribute name="text">1</attribute>
+                    <attribute name="text">2</attribute>
                   </attributes>
                 </child>
               </object>
@@ -156,16 +155,13 @@
                     <property name="model">locations_model</property>
                     <child>
                       <object class="GtkCellRendererPixbuf" id="cellview_icon_renderer"/>
-                      <attributes>
-                        <attribute name="pixbuf">0</attribute>
-                      </attributes>
                     </child>
                     <child>
                       <object class="GtkCellRendererText" id="cellview_name_renderer">
                         <property name="ellipsize">end</property>
                       </object>
                       <attributes>
-                        <attribute name="text">1</attribute>
+                        <attribute name="text">2</attribute>
                       </attributes>
                     </child>
                   </object>


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