Skip to content

Commit

Permalink
filebrowser: Add a flag to the tree model to indicate whether en entr…
Browse files Browse the repository at this point in the history
…y is a directory

Used by the subsequent patch which changes "stock-id" to GIcon and
disables row type detection using FILEVIEW_COLUMN_ICON.
  • Loading branch information
techee committed Apr 14, 2015
1 parent 31ae06f commit 83f261f
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions plugins/filebrowser.c
Expand Up @@ -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
};

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down

0 comments on commit 83f261f

Please sign in to comment.