Author: post
Date: 2011-04-19 14:04:32 +0200 (Tue, 19 Apr 2011)
New Revision: 4011

Modified:
   trunk/src/gtk-interface.c
   trunk/src/rs-store.c
   trunk/src/rs-store.h
Log:
Fix jumping to first image, when deleting the last image.

Modified: trunk/src/gtk-interface.c
===================================================================
--- trunk/src/gtk-interface.c   2011-04-19 11:06:45 UTC (rev 4010)
+++ trunk/src/gtk-interface.c   2011-04-19 12:04:32 UTC (rev 4011)
@@ -308,6 +308,7 @@
                /* Load next image if deleting */
                if (next_name)
                        next_name = rs_store_get_prevnext(rs->store, next_name, 
2);
+
                gui_set_block_keyboard(TRUE);
        }
 
@@ -336,6 +337,10 @@
                g_string_printf(gs, _("Changed photo priority (%d)"),prio);
        gui_status_notify(gs->str);
 
+       /* If deleting, and no next image, we are most likely at last image */
+       if (prio == 51 && NULL == next_name) 
+               next_name = rs_store_get_first_last(rs->store, 2);
+
        /* Load next image if deleting */
        if (next_name)
                rs_store_set_selected_name(rs->store, next_name, TRUE);

Modified: trunk/src/rs-store.c
===================================================================
--- trunk/src/rs-store.c        2011-04-19 11:06:45 UTC (rev 4010)
+++ trunk/src/rs-store.c        2011-04-19 12:04:32 UTC (rev 4011)
@@ -1717,7 +1717,53 @@
        return(fullname);
 }
 
+
 /**
+ * Get the filename of the first or last thumbnail
+ * @param store A RSStore
+ * @param direction 1:  first, 2: last
+ * @return filename of next or previous file, NULL if none.
+ */
+const gchar*
+rs_store_get_first_last(RSStore *store, guint direction)
+{
+       GtkTreeIter iter;
+       GtkTreeIter iter_temp;
+       GtkTreePath *newpath = NULL;
+       gchar *new_name = NULL;
+       GtkTreeModel *model = gtk_icon_view_get_model 
(GTK_ICON_VIEW(store->current_iconview));
+       gboolean found = FALSE;
+
+       if (direction == 1) /* Select first*/
+       {
+               newpath = gtk_tree_path_new_first();
+               if (gtk_tree_model_get_iter(model, &iter, newpath))
+                       found = TRUE;
+       }
+       if (direction == 2) /* Select last */
+       {
+               /* If nothing is selected, select last thumbnail */
+               newpath = gtk_tree_path_new_first();
+               if (gtk_tree_model_get_iter(model, &iter, newpath))
+               {
+                       iter_temp = iter;
+                       while (gtk_tree_model_iter_next(model, &iter_temp))
+                               iter = iter_temp;
+                       newpath = gtk_tree_model_get_path(model, &iter);
+                       found = TRUE;
+               }
+       }
+       if (newpath && found)
+       {
+               if (gtk_tree_model_get_iter(model, &iter, newpath))
+                       gtk_tree_model_get(model, &iter, FULLNAME_COLUMN, 
&new_name, -1);
+               /* Free the new path */
+               gtk_tree_path_free(newpath);
+       }
+       return new_name;
+}
+
+/**
  * Get the filename of the previous or next thumbnail
  * @param store A RSStore
  * @param current_filename Current filename or NULL if none
@@ -1750,7 +1796,7 @@
                {
                        ret = gtk_tree_path_prev(newpath);
                }
-               else /* Next */
+               else if (direction == 2) /* Next */
                {
                        gtk_tree_path_next(newpath);
                        ret = gtk_tree_model_get_iter(gtk_icon_view_get_model 
(iconview), &iter, newpath);
@@ -1783,14 +1829,6 @@
                }
        }
 
-       /* If we got no hit, fall back to this */
-       if (ret == FALSE)
-       {
-               /* If nothing is selected, select first thumbnail */
-               newpath = gtk_tree_path_new_first();
-               if (gtk_tree_model_get_iter(model, &iter, newpath))
-                       ret = TRUE;
-       }
        if (newpath && ret)
        {
                GtkTreeIter i;
@@ -1819,6 +1857,9 @@
        g_assert(RS_IS_STORE(store));
        const gchar* new_name = rs_store_get_prevnext(store, current_filename, 
direction);
 
+       if (!new_name)
+               new_name = rs_store_get_first_last(store, direction);
+
        if (new_name)
                return rs_store_set_selected_name(store, new_name, TRUE);
 

Modified: trunk/src/rs-store.h
===================================================================
--- trunk/src/rs-store.h        2011-04-19 11:06:45 UTC (rev 4010)
+++ trunk/src/rs-store.h        2011-04-19 12:04:32 UTC (rev 4011)
@@ -161,6 +161,15 @@
 rs_store_get_name(RSStore *store, GtkTreeIter *iter);
 
 /**
+ * Get the filename of the first or last thumbnail
+ * @param store A RSStore
+ * @param direction 1:  first, 2: last
+ * @return filename of next or previous file, NULL if none.
+ */
+const gchar*
+rs_store_get_first_last(RSStore *store, guint direction);
+
+/**
  * Get the filename of the previous or next thumbnail
  * @param store A RSStore
  * @param current_filename Current filename or NULL if none


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to