Commit 5cc4ebc2 authored by Stephan Arts's avatar Stephan Arts

Improve positioning code and file-open behaviour

parent 61b9578d
2009-06-01 Stephan Arts <stephan@xfce.org>
* src/main_window.c
src/image_list.c: Improve positioning code and file-open behaviour
2009-06-01 Stephan Arts <stephan@xfce.org>
* src/save_dialog.c
......
......@@ -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) \
......
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment