[file-roller] match Nautilus behavior for back and forward buttons



commit bd8807beb9a026be2441aa492815b65a6fc94429
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Nov 25 10:54:24 2012 +0100

    match Nautilus behavior for back and forward buttons
    
    [bug #578837]

 src/fr-window.c |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index d1192f1..d262ad0 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -856,23 +856,38 @@ static void
 fr_window_history_add (FrWindow   *window,
 		       const char *path)
 {
-	if ((window->priv->history != NULL) && (window->priv->history_current != NULL)) {
-		if (strcmp (window->priv->history_current->data, path) == 0)
-			return;
-
-		/* Add locations visited using the back button to the history
-		 * list. */
-		if (window->priv->history != window->priv->history_current) {
-			GList *scan = window->priv->history->next;
-			while (scan != window->priv->history_current->next) {
-				window->priv->history = g_list_prepend (window->priv->history, g_strdup (scan->data));
-				scan = scan->next;
+	if ((window->priv->history_current == NULL) || (g_strcmp0 (path, window->priv->history_current->data) != 0)) {
+		GList *scan;
+		GList *new_current = NULL;
+
+                /* search the path in the history */
+                for (scan = window->priv->history_current; scan; scan = scan->next) {
+                        char *path_in_history = scan->data;
+
+                        if (g_strcmp0 (path, path_in_history) == 0) {
+                        	new_current = scan;
+                        	break;
+                        }
+                }
+
+                if (new_current != NULL) {
+                	window->priv->history_current = new_current;
+                }
+                else {
+			/* remove all the paths after the current position */
+			for (scan = window->priv->history; scan && (scan != window->priv->history_current); /* void */) {
+				GList *next = scan->next;
+
+				window->priv->history = g_list_remove_link (window->priv->history, scan);
+				_g_string_list_free (scan);
+
+				scan = next;
 			}
-		}
-	}
 
-	window->priv->history = g_list_prepend (window->priv->history, g_strdup (path));
-	window->priv->history_current = window->priv->history;
+			window->priv->history = g_list_prepend (window->priv->history, g_strdup (path));
+			window->priv->history_current = window->priv->history;
+                }
+	}
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]