Trim trailing white spaces.
[geeqie.git] / src / view_file_list.c
index c036aaa..b0bd169 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -136,55 +136,14 @@ static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTree
        return NULL;
 }
 
-#if 0
-static gint vflist_find_sidecar_list_idx(GList *work, FileData *fd)
-{
-       gint i = 0;
-       while (work)
-               {
-               FileData *fd_p = work->data;
-               if (fd == fd_p) return i;
-
-               i++;
-
-               GList *work2 = fd_p->sidecar_files;
-               while (work2)
-                       {
-                       fd_p = work2->data;
-                       if (fd == fd_p) return i;
-
-                       i++;
-                       work2 = work2->next;
-                       }
-               work = work->next;
-               }
-       return -1;
-}
-
-static gint vflist_sidecar_list_count(GList *work)
-{
-       gint i = 0;
-       while (work)
-               {
-               FileData *fd = work->data;
-               i++;
-
-               GList *work2 = fd->sidecar_files;
-               while (work2)
-                       {
-                       i++;
-                       work2 = work2->next;
-                       }
-               work = work->next;
-               }
-       return i;
-}
-#endif
-
 static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
 {
        FileData *fd;
        gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
+
+       /* it seems that gtk_tree_store_clear may call some callbacks
+          that use the column. Set the pointer to NULL to be safe. */
+       gtk_tree_store_set(GTK_TREE_STORE(model), iter, FILE_COLUMN_POINTER, NULL, -1);
        file_data_unref(fd);
        return FALSE;
 }
@@ -220,27 +179,6 @@ static void vflist_move_cursor(ViewFile *vf, GtkTreeIter *iter)
 }
 
 
-static gint vflist_column_idx(ViewFile *vf, gint store_idx)
-{
-       GList *columns, *work;
-       gint i = 0;
-
-       columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview));
-       work = columns;
-       while (work)
-               {
-               GtkTreeViewColumn *column = work->data;
-               if (store_idx == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx")))
-                       break;
-               work = work->next;
-               i++;
-               }
-
-       g_list_free(columns);
-       return i;
-}
-
-
 /*
  *-----------------------------------------------------------------------------
  * dnd
@@ -253,8 +191,6 @@ static void vflist_dnd_get(GtkWidget *widget, GdkDragContext *context,
 {
        ViewFile *vf = data;
        GList *list = NULL;
-       gchar *uri_text = NULL;
-       gint total;
 
        if (!VFLIST(vf)->click_fd) return;
 
@@ -268,15 +204,8 @@ static void vflist_dnd_get(GtkWidget *widget, GdkDragContext *context,
                }
 
        if (!list) return;
-
-       uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
+       uri_selection_data_set_uris_from_filelist(selection_data, list);
        filelist_free(list);
-
-       DEBUG_1("%s", uri_text);
-
-       gtk_selection_data_set(selection_data, selection_data->target,
-                              8, (guchar *)uri_text, total);
-       g_free(uri_text);
 }
 
 static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
@@ -305,7 +234,7 @@ static void vflist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
 
-       if (context->action == GDK_ACTION_MOVE)
+       if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                {
                vf_refresh(vf);
                }
@@ -322,18 +251,12 @@ static void vflist_drag_data_received(GtkWidget *entry_widget, GdkDragContext *c
 
                if (fd) {
                        /* Add keywords to file */
-                       gchar *str = g_strndup((gchar *)selection->data, selection->length);
+                       gchar *str = (gchar *) gtk_selection_data_get_text(selection);
                        GList *kw_list = string_to_keywords_list(str);
                        
                        metadata_append_list(fd, KEYWORD_KEY, kw_list);
                        string_list_free(kw_list);
                        g_free(str);
-/*
-file notification should handle this automatically
-                       if (vf->layout && vf->layout->bar_info) {
-                               bar_set_fd(vf->layout->bar_info, fd);
-                       }
-*/
                }
        }
 }
@@ -363,26 +286,18 @@ void vflist_dnd_init(ViewFile *vf)
  *-----------------------------------------------------------------------------
  */
 
-GList *vflist_pop_menu_file_list(ViewFile *vf)
+GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
 {
-       GList *list;
-       if (!VFLIST(vf)->click_fd) return NULL;
+       GList *list = g_list_append(NULL, file_data_ref(fd));
 
-       if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
-               {
-               return vf_selection_get_list(vf);
-               }
-
-       list = g_list_append(NULL, file_data_ref(VFLIST(vf)->click_fd));
-
-       if (VFLIST(vf)->click_fd->sidecar_files)
+       if (fd->sidecar_files)
                {
                /* check if the row is expanded */
                GtkTreeModel *store;
                GtkTreeIter iter;
                
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
-               if (vflist_find_row(vf, VFLIST(vf)->click_fd, &iter) >= 0)
+               if (vflist_find_row(vf, fd, &iter) >= 0)
                        {
                        GtkTreePath *tpath;
 
@@ -390,7 +305,7 @@ GList *vflist_pop_menu_file_list(ViewFile *vf)
                        if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath))
                                {
                                /* unexpanded - add whole group */
-                               GList *work = VFLIST(vf)->click_fd->sidecar_files;
+                               GList *work = fd->sidecar_files;
                                while (work)
                                        {
                                        FileData *sfd = work->data;
@@ -406,6 +321,18 @@ GList *vflist_pop_menu_file_list(ViewFile *vf)
        return list;
 }
 
+GList *vflist_pop_menu_file_list(ViewFile *vf)
+{
+       if (!VFLIST(vf)->click_fd) return NULL;
+
+       if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
+               {
+               return vf_selection_get_list(vf);
+               }
+       return vflist_selection_get_one(vf, VFLIST(vf)->click_fd);
+}
+
+
 void vflist_pop_menu_view_cb(GtkWidget *widget, gpointer data)
 {
        ViewFile *vf = data;
@@ -445,7 +372,7 @@ void vflist_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
 
                        tpath = gtk_tree_model_get_path(store, &iter);
                        tree_edit_by_path(GTK_TREE_VIEW(vf->listview), tpath,
-                                         vflist_column_idx(vf, FILE_COLUMN_NAME), VFLIST(vf)->click_fd->name,
+                                         FILE_VIEW_COLUMN_FORMATTED, VFLIST(vf)->click_fd->name,
                                          vflist_row_rename_cb, vf);
                        gtk_tree_path_free(tpath);
                        }
@@ -512,7 +439,7 @@ static gboolean vflist_row_rename_cb(TreeEditData *td, const gchar *old, const g
        else
                {
                gchar *old_path = g_build_filename(vf->dir_fd->path, old, NULL);
-               FileData *fd = file_data_new_simple(old_path); /* get the fd from cache */
+               FileData *fd = file_data_new_group(old_path); /* get the fd from cache */
                file_util_rename_simple(fd, new_path, vf->listview);
                file_data_unref(fd);
                g_free(old_path);
@@ -545,7 +472,7 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
        ViewFile *vf = data;
        GtkTreePath *tpath;
 
-       if (event->keyval != GDK_Menu) return FALSE;
+       if (event->keyval != GDK_KEY_Menu) return FALSE;
 
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, NULL);
        if (tpath)
@@ -596,9 +523,6 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
 
                gtk_tree_model_get_iter(store, &iter, tpath);
                gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
-#if 0
-               gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
-#endif
                gtk_tree_path_free(tpath);
                }
 
@@ -642,12 +566,10 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
                return (gtk_tree_selection_count_selected_rows(selection) > 1);
                }
 
-#if 1
        if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS)
                {
                if (vf->layout) layout_image_full_screen_start(vf->layout);
                }
-#endif
 
        return FALSE;
 }
@@ -711,7 +633,6 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
                gtk_tree_selection_unselect_all(selection);
                gtk_tree_selection_select_iter(selection, &iter);
                vflist_move_cursor(vf, &iter);
-//             return TRUE;// FIXME - expand
                }
 
        return FALSE;
@@ -821,13 +742,6 @@ static void vflist_collapse_cb(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTre
  *-----------------------------------------------------------------------------
  */
 
-/*
-static gboolean vflist_dummy_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath,
-                                       gboolean path_currently_selected, gpointer data)
-{
-       return TRUE;
-}
-*/
 
 static gchar* vflist_get_formatted(ViewFile *vf, const gchar *name, const gchar *sidecars, const gchar *size, const gchar *time, gboolean expanded)
  {
@@ -958,7 +872,6 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
 
                        if (valid)
                                {
-                               num_ordered++;
                                gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
                                                   FILE_COLUMN_POINTER, &old_fd,
                                                   FILE_COLUMN_VERSION, &old_version,
@@ -990,6 +903,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
 
                                if (valid)
                                        {
+                                       num_ordered++;
                                        gtk_tree_store_insert_before(store, &new, parent_iter, &iter);
                                        }
                                else
@@ -1022,6 +936,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
                                }
                        else
                                {
+                               num_ordered++;
                                if (fd->version != old_version || force)
                                        {
                                        vflist_setup_iter(vf, store, &iter, fd);
@@ -1245,7 +1160,7 @@ gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
                while (work2)
                        {
                        /* FIXME: return the same index also for sidecars
-                          it is sufficient for next/prev navigation but it should be rewritten 
+                          it is sufficient for next/prev navigation but it should be rewritten
                           without using indexes at all
                        */
                        FileData *sidecar_fd = work2->data;
@@ -1605,11 +1520,11 @@ void vflist_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
                        {
                        case MTS_MODE_SET: selected = mark_val;
                                break;
-                       case MTS_MODE_OR: selected = mark_val | selected;
+                       case MTS_MODE_OR: selected = mark_val || selected;
                                break;
-                       case MTS_MODE_AND: selected = mark_val & selected;
+                       case MTS_MODE_AND: selected = mark_val && selected;
                                break;
-                       case MTS_MODE_MINUS: selected = !mark_val & selected;
+                       case MTS_MODE_MINUS: selected = !mark_val && selected;
                                break;
                        }
 
@@ -1696,7 +1611,7 @@ static void vflist_listview_set_columns(GtkWidget *listview, gboolean thumb, gbo
 
        gtk_tree_view_column_set_fixed_width(column, options->thumbnails.max_width + 4);
 
-       list = gtk_tree_view_column_get_cell_renderers(column);
+       list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
        if (!list) return;
        cell = list->data;
        g_list_free(list);
@@ -1921,10 +1836,6 @@ static void vflist_listview_add_column_toggle(ViewFile *vf, gint n, const gchar
 {
        GtkTreeViewColumn *column;
        GtkCellRenderer *renderer;
-       GtkTreeStore *store;
-       gint index;
-
-       store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
 
        renderer = gtk_cell_renderer_toggle_new();
        column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL);
@@ -1933,7 +1844,7 @@ static void vflist_listview_add_column_toggle(ViewFile *vf, gint n, const gchar
        g_object_set_data(G_OBJECT(column), "column_store_idx", GUINT_TO_POINTER(n));
        g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n));
 
-       index = gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column);
        gtk_tree_view_column_set_fixed_width(column, 22);
        gtk_tree_view_column_set_visible(column, vf->marks_enabled);
 
@@ -2060,7 +1971,11 @@ void vflist_thumb_set(ViewFile *vf, gboolean enable)
           - no need to re-read the directory
           - force update because the formatted string has changed
        */
-       if (vf->layout) vflist_populate_view(vf, TRUE); 
+       if (vf->layout)
+               {
+               vflist_populate_view(vf, TRUE);
+               gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
+               }
 }
 
 void vflist_marks_set(ViewFile *vf, gboolean enable)
@@ -2081,7 +1996,6 @@ void vflist_marks_set(ViewFile *vf, gboolean enable)
                }
 
        g_list_free(columns);
-       //vf_refresh(vf);
 }
 
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */