Add a back button in the toolbar: it allows to go back and forth between two director...
authorLaurent Monin <geeqie@norz.org>
Sat, 22 Nov 2008 16:24:23 +0000 (16:24 +0000)
committerLaurent Monin <geeqie@norz.org>
Sat, 22 Nov 2008 16:24:23 +0000 (16:24 +0000)
src/layout.c
src/layout_util.c
src/typedefs.h
src/ui_tabcomp.c
src/ui_tabcomp.h

index 7edbc91..d877622 100644 (file)
@@ -183,6 +183,25 @@ static void layout_vd_select_cb(ViewDir *vd, const gchar *path, gpointer data)
        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 @@ static GtkWidget *layout_tool_setup(LayoutWindow *lw)
        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);
 
index ca83a59..50c4ca7 100644 (file)
@@ -1556,6 +1556,34 @@ static void layout_button_thumb_cb(GtkWidget *widget, gpointer data)
        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 @@ GtkWidget *layout_button_bar(LayoutWindow *lw)
                                     _("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);
index 2fb0fbb..2b5533e 100644 (file)
@@ -493,6 +493,8 @@ struct _LayoutWindow
        gint thumbs_enabled;
        gint marks_enabled;
 
+       GtkWidget *back_button;
+
        /* dir view */
 
        LayoutLocation dir_location;
index 7207558..b402d52 100644 (file)
@@ -63,9 +63,12 @@ struct _TabCompData
        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 @@ void tab_completion_append_to_history(GtkWidget *entry, const gchar *path)
        TabCompData *td;
        GtkTreeModel *store;
        GList *work;
+       gint n = 0;
 
        td = g_object_get_data(G_OBJECT(entry), "tab_completion_data");
 
@@ -752,7 +756,12 @@ void tab_completion_append_to_history(GtkWidget *entry, const gchar *path)
                {
                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 @@ void tab_completion_add_tab_func(GtkWidget *entry, void (*tab_func)(const gchar
        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;
index 8de9351..e807e5a 100644 (file)
@@ -27,6 +27,7 @@ void tab_completion_add_tab_func(GtkWidget *entry, void (*tab_func)(const gchar
 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