Include a Other Software section in Help file
[geeqie.git] / src / view_dir.c
index a98632d..425e7ef 100644 (file)
 #include "filedata.h"
 #include "layout_image.h"
 #include "layout_util.h"
+#include "menu.h"
 #include "pixbuf_util.h"
 #include "ui_fileops.h"
 #include "ui_tree_edit.h"
 #include "ui_menu.h"
+#include "ui_misc.h"
 #include "utilops.h"
 #include "uri_utils.h"
 #include "view_dir_list.h"
@@ -49,8 +51,7 @@ static PixmapFolders *folder_icons_new(GtkWidget *widget)
        pf->open   = gtk_widget_render_icon(widget, GTK_STOCK_OPEN, size, NULL);
        pf->deny   = gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL);
        pf->parent = gtk_widget_render_icon(widget, GTK_STOCK_GO_UP, size, NULL);
-       /* FIXME: this is not a suitable icon */
-       pf->link = gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL);
+       pf->link = gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL); /** @FIXME this is not a suitable icon */
 #else
        /* GQView legacy icons */
        pf->close  = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
@@ -106,7 +107,7 @@ static void vd_destroy_cb(GtkWidget *widget, gpointer data)
        g_free(vd);
 }
 
-ViewDir *vd_new(DirViewType type, FileData *dir_fd)
+ViewDir *vd_new(LayoutWindow *lw)
 {
        ViewDir *vd = g_new0(ViewDir, 1);
 
@@ -115,13 +116,14 @@ ViewDir *vd_new(DirViewType type, FileData *dir_fd)
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vd->widget),
                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
 
+       vd->layout = lw;
        vd->pf = folder_icons_new(vd->widget);
 
-       switch (type)
-       {
-       case DIRVIEW_LIST: vd = vdlist_new(vd, dir_fd); break;
-       case DIRVIEW_TREE: vd = vdtree_new(vd, dir_fd); break;
-       }
+       switch (lw->options.dir_view_type)
+               {
+               case DIRVIEW_LIST: vd = vdlist_new(vd, lw->dir_fd); break;
+               case DIRVIEW_TREE: vd = vdtree_new(vd, lw->dir_fd); break;
+               }
 
        gtk_container_add(GTK_CONTAINER(vd->widget), vd->view);
 
@@ -141,7 +143,7 @@ ViewDir *vd_new(DirViewType type, FileData *dir_fd)
        file_data_register_notify_func(vd_notify_cb, vd, NOTIFY_PRIORITY_HIGH);
 
        /* vd_set_fd expects that vd_notify_cb is already registered */
-       if (dir_fd) vd_set_fd(vd, dir_fd);
+       if (lw->dir_fd) vd_set_fd(vd, lw->dir_fd);
 
        gtk_widget_show(vd->view);
 
@@ -566,10 +568,14 @@ static void vd_toggle_show_hidden_files_cb(GtkWidget *widget, gpointer data)
        if (vd->layout) layout_refresh(vd->layout);
 }
 
-static void vd_pop_menu_new_rename_cb(gboolean success, const gchar *new_path, gpointer data)
+static void vd_pop_menu_new_folder_cb(gboolean success, const gchar *new_path, gpointer data)
 {
        ViewDir *vd = data;
        FileData *fd = NULL;
+       GtkTreeIter iter;
+       GtkTreePath *tpath;
+       GtkTreeModel *store;
+
        if (!success) return;
 
        switch (vd->type)
@@ -588,7 +594,13 @@ static void vd_pop_menu_new_rename_cb(gboolean success, const gchar *new_path, g
                        }
                        break;
                }
-       vd_rename_by_data(vd, fd);
+
+       if (!fd || !vd_find_row(vd, fd, &iter)) return;
+       store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
+       tpath = gtk_tree_model_get_path(store, &iter);
+       gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE);
+
+       gtk_tree_path_free(tpath);
 }
 
 static void vd_pop_menu_new_cb(GtkWidget *widget, gpointer data)
@@ -612,7 +624,7 @@ static void vd_pop_menu_new_cb(GtkWidget *widget, gpointer data)
                        break;
                }
 
-       file_util_create_dir(dir_fd, widget, vd_pop_menu_new_rename_cb, vd);
+       file_util_create_dir(dir_fd, vd->layout->window, vd_pop_menu_new_folder_cb, vd);
 }
 
 static void vd_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
@@ -622,12 +634,49 @@ static void vd_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
        vd_rename_by_data(vd, vd->click_fd);
 }
 
+static void vd_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
+{
+       ViewDir *vd = data;
+       gboolean ascend;
+
+       if (!vd) return;
+
+       if (!vd->layout) return;
+
+       ascend = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
+       layout_views_set_sort(vd->layout, vd->layout->options.dir_view_list_sort.method, ascend);
+
+       if (vd->layout) layout_refresh(vd->layout);
+}
+
+static void vd_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
+{
+       ViewDir *vd;
+       SortType type;
+
+       vd = submenu_item_get_data(widget);
+
+       if (!vd) return;
+       if (!vd->layout) return;
+
+       type = (SortType)GPOINTER_TO_INT(data);
+
+       if (type == SORT_NAME || type == SORT_TIME)
+               {
+               layout_views_set_sort(vd->layout, type, vd->layout->options.dir_view_list_sort.ascend);
+
+               if (vd->layout) layout_refresh(vd->layout);
+               }
+}
+
 GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
 {
        GtkWidget *menu;
        gboolean active;
        gboolean rename_delete_active = FALSE;
        gboolean new_folder_active = FALSE;
+       GtkWidget *submenu;
+       GtkWidget *item;
 
        active = (fd != NULL);
        switch (vd->type)
@@ -703,6 +752,14 @@ GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
        menu_item_add_radio(menu, _("View as _Tree"), GINT_TO_POINTER(DIRVIEW_TREE), vd->type == DIRVIEW_TREE,
                         G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
 
+       if (vd->type == DIRVIEW_LIST)
+               {
+               submenu = submenu_add_dir_sort(NULL, G_CALLBACK(vd_pop_menu_sort_cb), vd, FALSE, FALSE, TRUE, vd->layout->options.dir_view_list_sort.method);
+               menu_item_add_check(submenu, _("Ascending"), vd->layout->options.dir_view_list_sort.ascend, G_CALLBACK(vd_pop_menu_sort_ascend_cb), (vd));
+               item = menu_item_add(menu, _("_Sort"), NULL, NULL);
+               gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+               }
+
        menu_item_add_divider(menu);
 
        menu_item_add_check(menu, _("Show _hidden files"), options->file_filter.show_hidden_files,
@@ -716,7 +773,7 @@ GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
 
 void vd_new_folder(ViewDir *vd, FileData *dir_fd)
 {
-       file_util_create_dir(dir_fd, vd->widget, vd_pop_menu_new_rename_cb, vd);
+       file_util_create_dir(dir_fd, vd->layout->window, vd_pop_menu_new_folder_cb, vd);
 }
 
 /*
@@ -794,6 +851,7 @@ static void vd_dnd_drop_receive(GtkWidget *widget,
        ViewDir *vd = data;
        GtkTreePath *tpath;
        FileData *fd = NULL;
+       GdkDragAction action;
 
        vd->click_fd = NULL;
 
@@ -821,13 +879,44 @@ static void vd_dnd_drop_receive(GtkWidget *widget,
 
                if (active)
                        {
-                       if (gdk_drag_context_get_actions(context) == GDK_ACTION_COPY)
+/** @FIXME With GTK2 gdk_drag_context_get_actions() shows the state of the
+ * shift and control keys during the drag operation. With GTK3 this is not
+ * so. This is a workaround.
+ */
+#if GTK_CHECK_VERSION(3,0,0)
+                       GdkModifierType mask;
+
+                       gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &mask);
+                       if (mask & GDK_CONTROL_MASK)
+                               {
+                               action = GDK_ACTION_COPY;
+                               }
+                       else if (mask & GDK_SHIFT_MASK)
+                               {
+                               action = GDK_ACTION_MOVE;
+                               }
+#else
+                       action = (gdk_drag_context_get_actions(context));
+#endif
+                       if (action != GDK_ACTION_COPY && action != GDK_ACTION_MOVE)
+                               {
+                               if (options->dnd_default_action == DND_ACTION_COPY)
+                                       {
+                                       action = GDK_ACTION_COPY;
+                                       }
+                               else if (options->dnd_default_action == DND_ACTION_MOVE)
+                                       {
+                                       action = GDK_ACTION_MOVE;
+                                       }
+                               }
+
+                       if (action == GDK_ACTION_COPY)
                                {
                                file_util_copy_simple(list, fd->path, vd->widget);
                                done = TRUE;
                                list = NULL;
                                }
-                       else if (gdk_drag_context_get_actions(context) == GDK_ACTION_MOVE)
+                       else if (action == GDK_ACTION_MOVE)
                                {
                                file_util_move_simple(list, fd->path, vd->widget);
                                done = TRUE;
@@ -1050,6 +1139,11 @@ gboolean vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
        GtkTreePath *tpath;
        FileData *fd = NULL;
 
+       if (defined_mouse_buttons(widget, bevent, vd->layout))
+               {
+               return TRUE;
+               }
+
        if (vd->type == DIRVIEW_LIST && !options->view_dir_list_single_click_enter)
                return FALSE;
 
@@ -1092,6 +1186,42 @@ gboolean vd_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        ViewDir *vd = data;
        gboolean ret = FALSE;
+       FileData *fd;
+       GtkTreePath *tpath;
+       GtkTreeIter iter;
+       NodeData *nd = NULL;
+       GtkTreeModel *store;
+
+       if (bevent->button == MOUSE_BUTTON_RIGHT)
+               {
+               if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, &tpath, NULL, NULL, NULL))
+                       {
+                       store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
+                       gtk_tree_model_get_iter(store, &iter, tpath);
+
+                       switch (vd->type)
+                               {
+                               case DIRVIEW_LIST:
+                                       gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
+                                       vd->click_fd = fd;
+                                       break;
+                               case DIRVIEW_TREE:
+                                       gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
+                                       vd->click_fd = (nd) ? nd->fd : NULL;
+                               }
+
+                       if (vd->click_fd)
+                               {
+                               vd_color_set(vd, vd->click_fd, TRUE);
+                               }
+                       }
+
+               vd->popup = vd_pop_menu(vd, vd->click_fd);
+               gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL,
+                              bevent->button, bevent->time);
+
+               return TRUE;
+               }
 
        switch (vd->type)
        {