Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Tue, 16 Jun 2015 13:43:45 UTC Commit: 358758c9f8feddac6c3a06005f309b53506c99d5 https://github.com/geany/geany/commit/358758c9f8feddac6c3a06005f309b53506c99...
Log Message: ----------- Show icons corresponding to MIME types in the file browser plugin
Modified Paths: -------------- plugins/filebrowser.c
Modified: plugins/filebrowser.c 48 lines changed, 44 insertions(+), 4 deletions(-) =================================================================== @@ -185,6 +185,39 @@ static gboolean check_filtered(const gchar *base_name) }
+static GIcon *get_icon(const gchar *fname) +{ + GIcon *icon = NULL; + gchar *ctype; + + ctype = g_content_type_guess(fname, NULL, 0, NULL); + + if (ctype) + { + icon = g_content_type_get_icon(ctype); + if (icon) + { + GtkIconInfo *icon_info; + + icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0); + if (!icon_info) + { + g_object_unref(icon); + icon = NULL; + } + else + gtk_icon_info_free(icon_info); + } + g_free(ctype); + } + + if (!icon) + icon = g_themed_icon_new("text-x-generic"); + + return icon; +} + + /* name is in locale encoding */ static void add_item(const gchar *name) { @@ -192,6 +225,7 @@ static void add_item(const gchar *name) gchar *fname, *utf8_name, *utf8_fullname; const gchar *sep; gboolean dir; + GIcon *icon;
if (G_UNLIKELY(EMPTY(name))) return; @@ -227,12 +261,15 @@ static void add_item(const gchar *name)
gtk_list_store_append(file_store, &iter); } + + icon = dir ? g_themed_icon_new("folder") : get_icon(utf8_name); gtk_list_store_set(file_store, &iter, - FILEVIEW_COLUMN_ICON, (dir) ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE, + FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, utf8_name, FILEVIEW_COLUMN_FILENAME, utf8_fullname, FILEVIEW_COLUMN_IS_DIR, dir, -1); + g_object_unref(icon); done: g_free(utf8_name); g_free(utf8_fullname); @@ -244,6 +281,7 @@ static void add_top_level_entry(void) { GtkTreeIter iter; gchar *utf8_dir; + GIcon *icon;
if (EMPTY(g_path_skip_root(current_dir))) return; /* ignore 'C:' or '/' */ @@ -254,12 +292,14 @@ static void add_top_level_entry(void) gtk_list_store_prepend(file_store, &iter); last_dir_iter = gtk_tree_iter_copy(&iter);
+ icon = g_themed_icon_new("folder"); gtk_list_store_set(file_store, &iter, - FILEVIEW_COLUMN_ICON, GTK_STOCK_DIRECTORY, + FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, "..", FILEVIEW_COLUMN_FILENAME, utf8_dir, FILEVIEW_COLUMN_IS_DIR, TRUE, -1); + g_object_unref(icon); g_free(utf8_dir); }
@@ -826,7 +866,7 @@ static void prepare_file_view(void) GtkTreeViewColumn *column; GtkTreeSelection *selection;
- file_store = gtk_list_store_new(FILEVIEW_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); + file_store = gtk_list_store_new(FILEVIEW_N_COLUMNS, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
gtk_tree_view_set_model(GTK_TREE_VIEW(file_view), GTK_TREE_MODEL(file_store)); g_object_unref(file_store); @@ -835,7 +875,7 @@ static void prepare_file_view(void) text_renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new(); gtk_tree_view_column_pack_start(column, icon_renderer, FALSE); - gtk_tree_view_column_set_attributes(column, icon_renderer, "stock-id", FILEVIEW_COLUMN_ICON, NULL); + gtk_tree_view_column_set_attributes(column, icon_renderer, "gicon", FILEVIEW_COLUMN_ICON, NULL); gtk_tree_view_column_pack_start(column, text_renderer, TRUE); gtk_tree_view_column_set_attributes(column, text_renderer, "text", FILEVIEW_COLUMN_NAME, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(file_view), column);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).