From 83f261fd64b1a1e53782aee4b9ce9970696d3f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sat, 4 Apr 2015 22:26:58 +0200 Subject: [PATCH] filebrowser: Add a flag to the tree model to indicate whether en entry is a directory Used by the subsequent patch which changes "stock-id" to GIcon and disables row type detection using FILEVIEW_COLUMN_ICON. --- plugins/filebrowser.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/plugins/filebrowser.c b/plugins/filebrowser.c index 9d55c59bb6..7c5d4497f3 100644 --- a/plugins/filebrowser.c +++ b/plugins/filebrowser.c @@ -68,6 +68,7 @@ enum FILEVIEW_COLUMN_ICON = 0, FILEVIEW_COLUMN_NAME, FILEVIEW_COLUMN_FILENAME, /* the full filename, including path for display as tooltip */ + FILEVIEW_COLUMN_IS_DIR, FILEVIEW_N_COLUMNS }; @@ -230,6 +231,7 @@ static void add_item(const gchar *name) FILEVIEW_COLUMN_ICON, (dir) ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE, FILEVIEW_COLUMN_NAME, utf8_name, FILEVIEW_COLUMN_FILENAME, utf8_fullname, + FILEVIEW_COLUMN_IS_DIR, dir, -1); done: g_free(utf8_name); @@ -256,6 +258,7 @@ static void add_top_level_entry(void) FILEVIEW_COLUMN_ICON, GTK_STOCK_DIRECTORY, FILEVIEW_COLUMN_NAME, "..", FILEVIEW_COLUMN_FILENAME, utf8_dir, + FILEVIEW_COLUMN_IS_DIR, TRUE, -1); g_free(utf8_dir); } @@ -386,21 +389,15 @@ static gboolean is_folder_selected(GList *selected_items) for (item = selected_items; item != NULL; item = g_list_next(item)) { - gchar *icon; GtkTreeIter iter; GtkTreePath *treepath; treepath = (GtkTreePath*) item->data; gtk_tree_model_get_iter(model, &iter, treepath); - gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_ICON, &icon, -1); + gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_IS_DIR, &dir_found, -1); - if (utils_str_equal(icon, GTK_STOCK_DIRECTORY)) - { - dir_found = TRUE; - g_free(icon); + if (dir_found) break; - } - g_free(icon); } return dir_found; } @@ -829,7 +826,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); + file_store = gtk_list_store_new(FILEVIEW_N_COLUMNS, G_TYPE_STRING, 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); @@ -925,14 +922,14 @@ static GtkWidget *make_filterbar(void) static gboolean completion_match_func(GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data) { - gchar *str, *icon; + gchar *str; + gboolean is_dir; gboolean result = FALSE; gtk_tree_model_get(GTK_TREE_MODEL(file_store), iter, - FILEVIEW_COLUMN_ICON, &icon, FILEVIEW_COLUMN_NAME, &str, -1); + FILEVIEW_COLUMN_IS_DIR, &is_dir, FILEVIEW_COLUMN_NAME, &str, -1); - if (str != NULL && icon != NULL && utils_str_equal(icon, GTK_STOCK_DIRECTORY) && - ! g_str_has_suffix(key, G_DIR_SEPARATOR_S)) + if (str != NULL && is_dir && !g_str_has_suffix(key, G_DIR_SEPARATOR_S)) { /* key is something like "/tmp/te" and str is a filename like "test", * so strip the path from key to make them comparable */ @@ -943,7 +940,6 @@ static gboolean completion_match_func(GtkEntryCompletion *completion, const gcha g_free(str_lowered); } g_free(str); - g_free(icon); return result; }