#include "secure_save.h"
#include "ui_fileops.h"
+
+/*
+ *-----------------------------------------------------------------------------
+ * Implements a history chain. Used by the Back and Forward toolbar buttons.
+ * Selecting any folder appends the path to the end of the chain.
+ * Pressing the Back and 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 *history_chain = NULL;
+static guint chain_index = G_MAXUINT;
+static gboolean nav_button = FALSE; /** Used to prevent the nav buttons making entries to the chain **/
+
+const gchar *history_chain_back()
+{
+ nav_button = TRUE;
+
+ chain_index = chain_index > 0 ? chain_index - 1 : 0;
+
+ return g_list_nth_data(history_chain, chain_index);
+}
+
+const gchar *history_chain_forward()
+{
+ nav_button= TRUE;
+ guint last = g_list_length(history_chain) - 1;
+
+ chain_index = chain_index < last ? chain_index + 1 : last;
+
+ return g_list_nth_data(history_chain, chain_index);
+}
+
+/**
+ * @brief Appends a path to the history chain
+ * @param path Path selected
+ *
+ * Each time the user selects a new path 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 history_chain_append_end(const gchar *path)
+{
+ GList *work;
+
+ if (!nav_button)
+ {
+ if(chain_index == G_MAXUINT)
+ {
+ history_chain = g_list_append (history_chain, g_strdup(path));
+ chain_index = 0;
+ }
+ else
+ {
+ work = g_list_last(history_chain);
+ if (g_strcmp0(work->data , path) != 0)
+ {
+ history_chain = g_list_append (history_chain, g_strdup(path));
+ chain_index = g_list_length(history_chain) - 1;
+ DEBUG_3("%d %s", chain_index, path);
+ }
+ else
+ {
+ chain_index = g_list_length(history_chain) - 1;
+ }
+ }
+ }
+ else
+ {
+ nav_button = FALSE;
+ }
+}
+
/*
*-----------------------------------------------------------------------------
* history lists
const gchar *history_list_find_last_path_by_key(const gchar *key);
+const gchar *history_chain_back();
+const gchar *history_chain_forward();
+void history_chain_append_end(const gchar *path);
+
/* the returned GList is internal, don't free it */
GList *history_list_get_by_key(const gchar *key);
#include "color-man.h"
#include "filedata.h"
#include "histogram.h"
+#include "history_list.h"
#include "image.h"
#include "image-overlay.h"
#include "layout_config.h"
if (isfile(fd->path)) have_file = TRUE;
}
- if (lw->path_entry) tab_completion_append_to_history(lw->path_entry, lw->dir_fd->path);
+ if (lw->path_entry)
+ {
+ history_chain_append_end(lw->dir_fd->path);
+ tab_completion_append_to_history(lw->path_entry, lw->dir_fd->path);
+ }
layout_sync_path(lw);
layout_list_sync_sort(lw);
{
LayoutWindow *lw = data;
FileData *dir_fd;
- gchar *path = NULL;
- GList *list = history_list_get_by_key("path_list");
- gint n = 0;
- while (list)
- {
- if (n == 1) {
- /* Previous path from history */
- path = (gchar *)list->data;
- break;
- }
- list = list->next;
- n++;
- }
+ /* Obtain previous path */
+ dir_fd = file_data_new_dir(history_chain_back());
+ layout_set_fd(lw, dir_fd);
+ file_data_unref(dir_fd);
+}
- if (!path) return;
+static void layout_menu_forward_cb(GtkAction *action, gpointer data)
+{
+ LayoutWindow *lw = data;
+ FileData *dir_fd;
- /* Open previous path */
- dir_fd = file_data_new_dir(path);
+ /* Obtain next path */
+ dir_fd = file_data_new_dir(history_chain_forward());
layout_set_fd(lw, dir_fd);
file_data_unref(dir_fd);
}
{ "NextImageAlt2", GTK_STOCK_GO_DOWN, N_("_Next Image"), "KP_Page_Down", N_("Next Image"), CB(layout_menu_image_next_cb) },
{ "LastImage", GTK_STOCK_GOTO_BOTTOM, N_("_Last Image"), "End", N_("Last Image"), CB(layout_menu_image_last_cb) },
{ "Back", GTK_STOCK_GO_BACK, N_("_Back"), NULL, N_("Back"), CB(layout_menu_back_cb) },
+ { "Forward", GTK_STOCK_GO_FORWARD, N_("_Forward"), NULL, N_("Forward"), CB(layout_menu_forward_cb) },
{ "Home", GTK_STOCK_HOME, N_("_Home"), NULL, N_("Home"), CB(layout_menu_home_cb) },
{ "Up", GTK_STOCK_GO_UP, N_("_Up"), NULL, N_("Up"), CB(layout_menu_up_cb) },
" <menuitem action='LastImage'/>"
" <separator/>"
" <menuitem action='Back'/>"
+" <menuitem action='Forward'/>"
" <menuitem action='Up'/>"
" <menuitem action='Home'/>"
" <separator/>"
" <toolbar name='ToolBar'>"
" <toolitem action='Thumbnails'/>"
" <toolitem action='Back'/>"
+" <toolitem action='Forward'/>"
" <toolitem action='Up'/>"
" <toolitem action='Home'/>"
" <toolitem action='Refresh'/>"