New Go to directory view feature that permits to find and display the directory
authorLaurent Monin <geeqie@norz.org>
Tue, 15 Apr 2008 06:56:25 +0000 (06:56 +0000)
committerLaurent Monin <geeqie@norz.org>
Tue, 15 Apr 2008 06:56:25 +0000 (06:56 +0000)
corresponding to an image view.
For example, when you open an image in new window from collection, right clicking on
the newly displayed image will let you choose Go to directory view, which would open
a new window, with image and directory list.
If current directory is the one of the image, menu item is disabled.

src/img-view.c
src/layout.c
src/layout.h
src/layout_image.c

index c93dfb0..b69ec58 100644 (file)
@@ -22,6 +22,8 @@
 #include "image.h"
 #include "image-overlay.h"
 #include "info.h"
+#include "layout.h"
+#include "layout_image.h"
 #include "menu.h"
 #include "pixbuf-renderer.h"
 #include "pixbuf_util.h"
@@ -1223,6 +1225,38 @@ static void view_close_cb(GtkWidget *widget, gpointer data)
        view_window_close(vw);
 }
 
+static LayoutWindow *view_new_layout_with_path(const gchar *path)
+{
+       LayoutWindow *nw;
+
+       nw = layout_new(NULL, FALSE, FALSE);
+       layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
+       layout_set_path(nw, path);
+       return nw;
+}
+
+
+static void view_set_layout_path_cb(GtkWidget *widget, gpointer data)
+{
+       ViewWindow *vw = data;
+       LayoutWindow *lw;
+       const gchar *path;
+       ImageWindow *imd;
+       
+       imd = view_window_active_image(vw);
+
+       if (!imd || !imd->image_fd) return;
+       path = imd->image_fd->path;
+       if (!path) return;
+       
+       lw = layout_find_by_image_fd(imd);
+       if (lw)
+               layout_set_path(lw, path);
+       else
+               view_new_layout_with_path(path);
+       view_window_close(vw);
+}
+
 static GtkWidget *view_popup_menu(ViewWindow *vw)
 {
        GtkWidget *menu;
@@ -1245,6 +1279,7 @@ static GtkWidget *view_popup_menu(ViewWindow *vw)
        menu_item_add_stock(menu, _("_Properties"), GTK_STOCK_PROPERTIES, G_CALLBACK(view_info_cb), vw);
 
        menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(view_new_window_cb), vw);
+       item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(view_set_layout_path_cb), vw);
 
        menu_item_add_divider(menu);
        menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(view_copy_cb), vw);
index ff5d410..fdfb2f7 100644 (file)
@@ -85,6 +85,23 @@ LayoutWindow *layout_find_by_image(ImageWindow *imd)
        return NULL;
 }
 
+LayoutWindow *layout_find_by_image_fd(ImageWindow *imd)
+{
+       GList *work;
+
+       work = layout_window_list;
+       while (work)
+               {
+               LayoutWindow *lw = work->data;
+               work = work->next;
+               if (lw->image->image_fd == imd->image_fd)
+                       return lw;
+               
+               }
+
+       return NULL;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * menu, toolbar, and dir view
index d57b506..9ed7d55 100644 (file)
@@ -26,6 +26,7 @@ void layout_free(LayoutWindow *lw);
 gint layout_valid(LayoutWindow **lw);
 
 LayoutWindow *layout_find_by_image(ImageWindow *imd);
+LayoutWindow *layout_find_by_image_fd(ImageWindow *imd);
 
 const gchar *layout_get_path(LayoutWindow *lw);
 gint layout_set_path(LayoutWindow *lw, const gchar *path);
index 6d79783..a2bfc65 100644 (file)
@@ -709,6 +709,30 @@ static void li_pop_menu_hide_cb(GtkWidget *widget, gpointer data)
        layout_tools_hide_toggle(lw);
 }
 
+static void li_set_layout_path_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+       const gchar *path;
+
+       if (!layout_valid(&lw)) return;
+       
+       path = layout_image_get_path(lw);
+       if (path) layout_set_path(lw, path);
+}
+
+static gint li_check_if_current_path(LayoutWindow *lw, const gchar *path)
+{
+       gchar *dirname;
+       gint ret;
+
+       if (!path || !layout_valid(&lw) || !lw->path) return FALSE;
+
+       dirname = g_path_get_dirname(path);
+       ret = (strcmp(lw->path, dirname) == 0);
+       g_free(dirname);
+       return ret;
+}
+
 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
 {
        GtkWidget *menu;
@@ -740,6 +764,9 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
 
        item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
        if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
+       
+       item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
+       if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
 
        menu_item_add_divider(menu);