changeset 1167:e812b1a7adda

Add a back button in the toolbar: it allows to go back and forth between two directories. Experimental, please test and comment on ml.
author zas_
date Sat, 22 Nov 2008 16:24:23 +0000
parents 26b9fca795f8
children 0c7534002b0a
files src/layout.c src/layout_util.c src/typedefs.h src/ui_tabcomp.c src/ui_tabcomp.h
diffstat 5 files changed, 76 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Thu Nov 20 17:28:34 2008 +0000
+++ b/src/layout.c	Sat Nov 22 16:24:23 2008 +0000
@@ -183,6 +183,25 @@
 	layout_set_path(lw, path);
 }
 
+static void layout_path_entry_tab_append_cb(const gchar *path, gpointer data, gint n)
+{
+	LayoutWindow *lw = data;
+
+	if (!lw || !lw->back_button) return;
+	if (!layout_valid(&lw)) return;
+
+	if (n >= 2)
+		{
+		/* Enable back button */
+		gtk_widget_set_sensitive(lw->back_button, TRUE);
+		}
+	else
+		{
+		/* Disable back button */
+		gtk_widget_set_sensitive(lw->back_button, FALSE);
+		}
+}
+
 static GtkWidget *layout_tool_setup(LayoutWindow *lw)
 {
 	GtkWidget *box;
@@ -202,6 +221,7 @@
 	tabcomp = tab_completion_new_with_history(&lw->path_entry, NULL, "path_list", -1,
 						  layout_path_entry_cb, lw);
 	tab_completion_add_tab_func(lw->path_entry, layout_path_entry_tab_cb, lw);
+	tab_completion_add_append_func(lw->path_entry, layout_path_entry_tab_append_cb, lw);
 	gtk_box_pack_start(GTK_BOX(box), tabcomp, FALSE, FALSE, 0);
 	gtk_widget_show(tabcomp);
 
--- a/src/layout_util.c	Thu Nov 20 17:28:34 2008 +0000
+++ b/src/layout_util.c	Sat Nov 22 16:24:23 2008 +0000
@@ -1556,6 +1556,34 @@
 	layout_thumb_set(lw, gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)));
 }
 
+/* Back button callback */
+static void layout_button_back_cb(GtkWidget *widget, gpointer data)
+{
+	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++;
+		}
+
+	if (!path) return;
+	
+	/* Open previous path */
+	dir_fd = file_data_new_simple(path);
+	layout_set_fd(lw, dir_fd);
+	file_data_unref(dir_fd);
+}
+
 static void layout_button_home_cb(GtkWidget *widget, gpointer data)
 {
 	const gchar *path;
@@ -1647,6 +1675,10 @@
 				     _("Show thumbnails"), G_CALLBACK(layout_button_thumb_cb), lw);
 	layout_button_custom_icon(button, PIXBUF_INLINE_ICON_THUMB);
 	lw->thumb_button = button;
+	
+	lw->back_button = pref_toolbar_button(box, GTK_STOCK_GO_BACK, NULL, FALSE,
+			    _("Back to previous folder"), G_CALLBACK(layout_button_back_cb), lw);
+	gtk_widget_set_sensitive(lw->back_button, FALSE);
 
 	pref_toolbar_button(box, GTK_STOCK_HOME, NULL, FALSE,
 			    _("Change to home folder"), G_CALLBACK(layout_button_home_cb), lw);
--- a/src/typedefs.h	Thu Nov 20 17:28:34 2008 +0000
+++ b/src/typedefs.h	Sat Nov 22 16:24:23 2008 +0000
@@ -493,6 +493,8 @@
 	gint thumbs_enabled;
 	gint marks_enabled;
 
+	GtkWidget *back_button;
+
 	/* dir view */
 
 	LayoutLocation dir_location;
--- a/src/ui_tabcomp.c	Thu Nov 20 17:28:34 2008 +0000
+++ b/src/ui_tabcomp.c	Sat Nov 22 16:24:23 2008 +0000
@@ -63,9 +63,12 @@
 	GList *file_list;
 	void (*enter_func)(const gchar *, gpointer);
 	void (*tab_func)(const gchar *, gpointer);
+	void (*tab_append_func)(const gchar *, gpointer, gint);
+
 	gpointer enter_data;
 	gpointer tab_data;
-
+	gpointer tab_append_data;
+	
 	GtkWidget *combo;
 	gint has_history;
 	gchar *history_key;
@@ -733,6 +736,7 @@
 	TabCompData *td;
 	GtkTreeModel *store;
 	GList *work;
+	gint n = 0;
 
 	td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
 
@@ -752,7 +756,12 @@
 		{
 		gtk_combo_box_append_text(GTK_COMBO_BOX(td->combo), (gchar *)work->data);
 		work = work->next;
+		n++;
 		}
+
+	if (td->tab_append_func) {
+		td->tab_append_func(path, td->tab_append_data, n);
+	}
 }
 
 GtkWidget *tab_completion_new(GtkWidget **entry, const gchar *text,
@@ -819,6 +828,17 @@
 	td->tab_data = data;
 }
 
+/* Add a callback function called when a new entry is appended to the list */
+void tab_completion_add_append_func(GtkWidget *entry, void (*tab_append_func)(const gchar *, gpointer, gint), gpointer data)
+{
+	TabCompData *td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
+
+	if (!td) return;
+
+	td->tab_append_func = tab_append_func;
+	td->tab_append_data = data;
+}
+
 gchar *remove_trailing_slash(const gchar *path)
 {
 	gint l;
--- a/src/ui_tabcomp.h	Thu Nov 20 17:28:34 2008 +0000
+++ b/src/ui_tabcomp.h	Sat Nov 22 16:24:23 2008 +0000
@@ -27,6 +27,7 @@
 gchar *remove_trailing_slash(const gchar *path);
 
 void tab_completion_add_select_button(GtkWidget *entry, const gchar *title, gint folders_only);
+void tab_completion_add_append_func(GtkWidget *entry, void (*tab_append_func)(const gchar *, gpointer, gint), gpointer data);
 
 
 #endif