}
}
+/*
+ *-----------------------------------------------------------------------------
+ * Implements an image history chain. Whenever an image is displayed it is
+ * appended to a chain.
+ * Pressing the Image Back and Image Forward buttons moves along the chain,
+ * but does not make additions to the chain.
+ * The chain always increases and is deleted at the end of the session
+ *-----------------------------------------------------------------------------
+ */
+static GList *image_chain = NULL;
+static guint image_chain_index = G_MAXUINT;
+static gboolean image_nav_button = FALSE; /** Used to prevent the nav buttons making entries to the chain **/
+const gchar *image_chain_back()
+{
+ image_nav_button = TRUE;
+
+ image_chain_index = image_chain_index > 0 ? image_chain_index - 1 : 0;
+
+ return g_list_nth_data(image_chain, image_chain_index);
+}
+
+const gchar *image_chain_forward()
+{
+ image_nav_button= TRUE;
+ guint last = g_list_length(image_chain) - 1;
+
+ image_chain_index = image_chain_index < last ? image_chain_index + 1 : last;
+
+ return g_list_nth_data(image_chain, image_chain_index);
+}
+
+/**
+ * @brief Appends a path to the image history chain
+ * @param path Image path selected
+ *
+ * Each time the user selects a new image it is appended to the chain
+ * except when it is identical to the current last entry
+ * The pointer is always moved to the end of the chain
+ */
+void image_chain_append_end(const gchar *path)
+{
+ GList *work;
+
+ if (!image_nav_button)
+ {
+ if(image_chain_index == G_MAXUINT)
+ {
+ image_chain = g_list_append(image_chain, g_strdup(path));
+ image_chain_index = 0;
+ }
+ else
+ {
+ work = g_list_last(image_chain);
+ gchar *tmp;
+ tmp = work->data;
+ if (g_strcmp0(work->data , path) != 0)
+ {
+ image_chain = g_list_append(image_chain, g_strdup(path));
+ image_chain_index = g_list_length(image_chain) - 1;
+ DEBUG_3("%d %s", image_chain_index, path);
+ }
+ else
+ {
+ image_chain_index = g_list_length(image_chain) - 1;
+ }
+ }
+ }
+ else
+ {
+ image_nav_button = FALSE;
+ }
+}
+
/*
*-----------------------------------------------------------------------------
* history lists
LayoutWindow *lw = data;
FileData *fd = layout_image_get_fd(lw);
- file_data_set_page_num(fd, 1);
+ if (fd->page_total > 0)
+ {
+ file_data_set_page_num(fd, 1);
+ }
}
static void layout_menu_page_last_cb(GtkAction *action, gpointer data)
LayoutWindow *lw = data;
FileData *fd = layout_image_get_fd(lw);
- file_data_set_page_num(fd, -1);
+ if (fd->page_total > 0)
+ {
+ file_data_set_page_num(fd, -1);
+ }
}
static void layout_menu_page_next_cb(GtkAction *action, gpointer data)
LayoutWindow *lw = data;
FileData *fd = layout_image_get_fd(lw);
- file_data_inc_page_num(fd);
+ if (fd->page_total > 0)
+ {
+ file_data_inc_page_num(fd);
+ }
}
static void layout_menu_page_previous_cb(GtkAction *action, gpointer data)
LayoutWindow *lw = data;
FileData *fd = layout_image_get_fd(lw);
- file_data_dec_page_num(fd);
+ if (fd->page_total > 0)
+ {
+ file_data_dec_page_num(fd);
+ }
+}
+
+static void layout_menu_image_forward_cb(GtkAction *action, gpointer data)
+{
+ LayoutWindow *lw = data;
+ FileData *dir_fd;
+
+ /* Obtain next image */
+ layout_set_path(lw, image_chain_forward());
+}
+
+static void layout_menu_image_back_cb(GtkAction *action, gpointer data)
+{
+ LayoutWindow *lw = data;
+ FileData *dir_fd;
+
+ /* Obtain previous image */
+ layout_set_path(lw, image_chain_back());
}
static void layout_menu_split_pane_next_cb(GtkAction *action, gpointer data)
{ "NextImage", GTK_STOCK_GO_DOWN, N_("_Next Image"), "space", N_("Next Image"), CB(layout_menu_image_next_cb) },
{ "NextImageAlt1", GTK_STOCK_GO_DOWN, N_("_Next Image"), "Page_Down", N_("Next Image"), CB(layout_menu_image_next_cb) },
- { "FirstPage", GTK_STOCK_MEDIA_PREVIOUS, N_("_First Page"), "<control>Home", N_( "First Page"), CB(layout_menu_page_first_cb) },
- { "LastPage", GTK_STOCK_MEDIA_NEXT, N_("_Last Page"), "<control>End", N_("Last Page"), CB(layout_menu_page_last_cb) },
- { "NextPage", GTK_STOCK_MEDIA_FORWARD, N_("_Next Page"), "<control>Page_Down", N_("Next Page"), CB(layout_menu_page_next_cb) },
- { "PrevPage", GTK_STOCK_MEDIA_REWIND, N_("_Previous Page"), "<control>Page_Up", N_("Previous Page"), CB(layout_menu_page_previous_cb) },
+ { "ImageForward", GTK_STOCK_GOTO_LAST, N_("Image Forward"), NULL, N_("Image Forward"), CB(layout_menu_image_forward_cb) },
+ { "ImageBack", GTK_STOCK_GOTO_FIRST, N_("Image Back"), NULL, N_("Image Back"), CB(layout_menu_image_back_cb) },
+
+ { "FirstPage", GTK_STOCK_MEDIA_PREVIOUS, N_("_First Page"), NULL, N_( "First Page"), CB(layout_menu_page_first_cb) },
+ { "LastPage", GTK_STOCK_MEDIA_NEXT, N_("_Last Page"), NULL, N_("Last Page"), CB(layout_menu_page_last_cb) },
+ { "NextPage", GTK_STOCK_MEDIA_FORWARD, N_("_Next Page"), NULL, N_("Next Page"), CB(layout_menu_page_next_cb) },
+ { "PrevPage", GTK_STOCK_MEDIA_REWIND, N_("_Previous Page"), NULL, N_("Previous Page"), CB(layout_menu_page_previous_cb) },
{ "NextImageAlt2", GTK_STOCK_GO_DOWN, N_("_Next Image"), "KP_Page_Down", N_("Next Image"), CB(layout_menu_image_next_cb) },
" <menuitem action='PrevImage'/>"
" <menuitem action='NextImage'/>"
" <menuitem action='LastImage'/>"
+" <menuitem action='ImageBack'/>"
+" <menuitem action='ImageForward'/>"
" <separator/>"
" <menuitem action='Back'/>"
" <menuitem action='Forward'/>"
g_list_free(editors_list);
}
-static gboolean go_menu_select(GtkWidget *widget, gpointer data)
-{
- GtkAction *action;
- LayoutWindow *lw = data;
-
- action = gtk_action_group_get_action(lw->action_group, "FirstPage");
- gtk_action_set_sensitive(action, FALSE);
- action = gtk_action_group_get_action(lw->action_group, "PrevPage");
- gtk_action_set_sensitive(action, FALSE);
- action = gtk_action_group_get_action(lw->action_group, "LastPage");
- gtk_action_set_sensitive(action, FALSE);
- action = gtk_action_group_get_action(lw->action_group, "NextPage");
- gtk_action_set_sensitive(action, FALSE);
-
- if (lw->image && lw->image->image_fd && lw->image->image_fd->page_total > 0)
- {
- if (lw->image->image_fd->page_num > 0)
- {
- action = gtk_action_group_get_action(lw->action_group, "FirstPage");
- gtk_action_set_sensitive(action, TRUE);
- action = gtk_action_group_get_action(lw->action_group, "PrevPage");
- gtk_action_set_sensitive(action, TRUE);
- }
- if (lw->image->image_fd->page_num < (lw->image->image_fd->page_total - 1))
- {
- action = gtk_action_group_get_action(lw->action_group, "LastPage");
- gtk_action_set_sensitive(action, TRUE);
- action = gtk_action_group_get_action(lw->action_group, "NextPage");
- gtk_action_set_sensitive(action, TRUE);
- }
- }
-}
-
void layout_actions_setup(LayoutWindow *lw)
{
GError *error;
gtk_action_group_add_actions(lw->action_group,
menu_entries, G_N_ELEMENTS(menu_entries), lw);
-
- action = gtk_action_group_get_action(lw->action_group, "GoMenu");
- g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(go_menu_select), lw);
-
gtk_action_group_add_toggle_actions(lw->action_group,
menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
gtk_action_group_add_radio_actions(lw->action_group,