[Xfce4-commits] <ristretto:master> Improve positioning code and file-open behaviour

Stephan Arts stephan at xfce.org
Wed Aug 12 12:22:37 CEST 2009


Updating branch refs/heads/master
         to 5cc4ebc2809050737072f9add17a1b2359c3049c (commit)
       from 61b9578d193049de5af0e74779e3d63d39d7da2c (commit)

commit 5cc4ebc2809050737072f9add17a1b2359c3049c
Author: Stephan Arts <stephan at xfce.org>
Date:   Mon Jun 1 23:44:14 2009 +0200

    Improve positioning code and file-open behaviour

 ChangeLog         |    5 ++++
 src/Makefile.am   |    1 -
 src/image_list.c  |   69 ++++++++++++++++++----------------------------------
 src/main_window.c |   11 +++++++-
 4 files changed, 39 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 37808a3..bdc08f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-06-01  Stephan Arts <stephan at xfce.org>
 
+	* src/main_window.c
+	  src/image_list.c: Improve positioning code and file-open behaviour
+
+2009-06-01  Stephan Arts <stephan at xfce.org>
+
 	* src/save_dialog.c
 	  src/save_dialog.h: Remove save-dialog code not going to support that
 	  anyways
diff --git a/src/Makefile.am b/src/Makefile.am
index b2c5db9..c201e0f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,7 +12,6 @@ ristretto_SOURCES = \
 	thumbnail_bar.c thumbnail_bar.h \
 	thumbnail.c thumbnail.h \
 	main.c
-#	save_dialog.h save_dialog.c
 
 ristretto_CFLAGS = \
 	$(GTK_CFLAGS) \
diff --git a/src/image_list.c b/src/image_list.c
index 5975e9a..092fcfb 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -68,7 +68,6 @@ struct _RsttoImageListIterPriv
 {
     RsttoImageList *image_list;
     RsttoImage *image;
-    gint position;
 };
 
 struct _RsttoImageListPriv
@@ -368,7 +367,6 @@ rstto_image_list_iter_new (RsttoImageList *nav, RsttoImage *image)
     iter = g_object_new(RSTTO_TYPE_IMAGE_LIST_ITER, NULL);
     iter->priv->image = image;
     iter->priv->image_list = nav;
-    iter->priv->position = -1;
 
     return iter;
 }
@@ -397,24 +395,14 @@ rstto_image_list_iter_get_position (RsttoImageListIter *iter)
 {
     if (iter->priv->image == NULL)
     {
-        if ((iter->priv->position == -1) && (rstto_image_list_get_n_images (iter->priv->image_list) > 0))
-        {
-            rstto_image_list_iter_set_position (iter, 0);
-        }
+        return -1;
     }
-    return iter->priv->position;
+    return g_list_index (iter->priv->image_list->priv->images, iter->priv->image);
 }
 
 RsttoImage *
 rstto_image_list_iter_get_image (RsttoImageListIter *iter)
 {
-    if (iter->priv->image == NULL)
-    {
-        if ((iter->priv->position == -1) && (rstto_image_list_get_n_images (iter->priv->image_list) > 0))
-        {
-            rstto_image_list_iter_set_position (iter, 0);
-        }
-    }
     return RSTTO_IMAGE (iter->priv->image);
 }
 
@@ -428,38 +416,30 @@ rstto_image_list_iter_set_position (RsttoImageListIter *iter, gint pos)
     }
 
     iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, pos); 
-    if (iter->priv->image)
-    {
-        iter->priv->position = pos;
-    }
-    else
-    {
-        iter->priv->position = -1;
-    }
+
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
 }
 
 gboolean
 rstto_image_list_iter_next (RsttoImageListIter *iter)
 {
+    GList *position = NULL;
     if (iter->priv->image)
     {
+        position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
         iter->priv->image = NULL;
     }
 
-    iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, iter->priv->position+1); 
-    if (iter->priv->image)
-    {
-        iter->priv->position++;
-    }
+    position = g_list_next (position);
+    if (position)
+        iter->priv->image = position->data; 
     else
     {
-        iter->priv->position = 0;
-        iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, 0); 
-        if (iter->priv->image == NULL)
-        {
-            iter->priv->position = -1;
-        }
+        position = g_list_first (iter->priv->image_list->priv->images);
+        if (position)
+            iter->priv->image = position->data; 
+        else
+            iter->priv->image = NULL;
     }
 
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
@@ -468,25 +448,25 @@ rstto_image_list_iter_next (RsttoImageListIter *iter)
 gboolean
 rstto_image_list_iter_previous (RsttoImageListIter *iter)
 {
+    GList *position = NULL;
     if (iter->priv->image)
     {
+        position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
         iter->priv->image = NULL;
     }
 
-    iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, iter->priv->position-1); 
-    if (iter->priv->image)
-    {
-        iter->priv->position--;
-    }
+    position = g_list_previous (position);
+    if (position)
+        iter->priv->image = position->data; 
     else
     {
-        iter->priv->position = g_list_length (iter->priv->image_list->priv->images)-1;
-        iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, iter->priv->position); 
-        if (iter->priv->image == NULL)
-        {
-            iter->priv->position = -1;
-        }
+        position = g_list_last (iter->priv->image_list->priv->images);
+        if (position)
+            iter->priv->image = position->data; 
+        else
+            iter->priv->image = NULL;
     }
+
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
 }
 
@@ -494,7 +474,6 @@ RsttoImageListIter *
 rstto_image_list_iter_clone (RsttoImageListIter *iter)
 {
     RsttoImageListIter *new_iter = rstto_image_list_iter_new (iter->priv->image_list, iter->priv->image);
-    new_iter->priv->position = iter->priv->position;
 
     return new_iter;
 }
diff --git a/src/main_window.c b/src/main_window.c
index 17eee26..c757808 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -994,6 +994,7 @@ cb_rstto_main_window_open_image (GtkWidget *widget, RsttoMainWindow *window)
     GSList *files = NULL, *_files_iter;
     GValue current_uri_val = {0, };
     gchar *uri = NULL;
+    guint pos = 0;
 
     g_value_init (&current_uri_val, G_TYPE_STRING);
     g_object_get_property (G_OBJECT(window->priv->settings_manager), "current-uri", &current_uri_val);
@@ -1027,6 +1028,7 @@ cb_rstto_main_window_open_image (GtkWidget *widget, RsttoMainWindow *window)
     {
         files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
         _files_iter = files;
+        pos = rstto_image_list_iter_get_position (window->priv->iter);
         while (_files_iter)
         {
             file = _files_iter->data;
@@ -1049,6 +1051,9 @@ cb_rstto_main_window_open_image (GtkWidget *widget, RsttoMainWindow *window)
             }
             _files_iter = g_slist_next (_files_iter);
         }
+
+        if (pos == -1)
+            rstto_image_list_iter_set_position (window->priv->iter, 0);
         g_value_set_string (&current_uri_val, gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dialog)));
         g_object_set_property (G_OBJECT(window->priv->settings_manager), "current-uri", &current_uri_val);
 
@@ -1081,6 +1086,7 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
     const gchar *content_type = NULL;
     gchar *uri = NULL;
     GValue current_uri_val = {0, };
+    guint pos = 0;
 
     g_value_init (&current_uri_val, G_TYPE_STRING);
     g_object_get_property (G_OBJECT(window->priv->settings_manager), "current-uri", &current_uri_val);
@@ -1102,6 +1108,7 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
         file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
 
         file_enumarator = g_file_enumerate_children (file, "standard::*", 0, NULL, NULL);
+        pos = rstto_image_list_iter_get_position (window->priv->iter);
         while (file_info = g_file_enumerator_next_file (file_enumarator, NULL, NULL))
         {
             filename = g_file_info_get_name (file_info);
@@ -1110,7 +1117,6 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
 
             if (strncmp (content_type, "image/", 6) == 0)
             {
-
                 rstto_image_list_add_file (window->priv->props.image_list, child_file, NULL);
             }
 
@@ -1118,6 +1124,9 @@ cb_rstto_main_window_open_folder (GtkWidget *widget, RsttoMainWindow *window)
             g_object_unref (file_info);
         }
 
+        if (pos == -1)
+            rstto_image_list_iter_set_position (window->priv->iter, 0);
+
         uri = g_file_get_uri (file);
         gtk_recent_manager_add_item (window->priv->recent_manager, uri);
         g_free (uri);



More information about the Xfce4-commits mailing list