Simplify ViewFile callbacks
authorArkadiy Illarionov <qarkai@gmail.com>
Sat, 20 Apr 2024 12:55:20 +0000 (15:55 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sat, 20 Apr 2024 16:56:36 +0000 (17:56 +0100)
Remove unused declarations.
Add vf*_pop_menu_add_items().
Split vf_selection_foreach().
Move ViewFileInfo* structs to submodules.

src/view-file.h
src/view-file/view-file-icon.cc
src/view-file/view-file-icon.h
src/view-file/view-file-list.cc
src/view-file/view-file-list.h
src/view-file/view-file.cc

index fbfd923..0402611 100644 (file)
@@ -94,42 +94,10 @@ struct ViewFile
        GList *editmenu_fd_list; /**< file list for edit menu */
 
        guint read_metadata_in_idle_id;
-};
-
-struct ViewFileInfoList
-{
-       FileData *select_fd;
-
-       gboolean thumbs_enabled;
 
-       guint select_idle_id; /**< event source id */
+       using SelectionCallback = std::function<void(FileData *)>;
 };
 
-struct ViewFileInfoIcon
-{
-       /* table stuff */
-       gint columns;
-       gint rows;
-
-       GList *selection;
-       FileData *prev_selection;
-
-       GtkWidget *tip_window;
-       guint tip_delay_id; /**< event source id */
-       FileData *tip_fd;
-
-       FileData *focus_fd;
-       gint focus_row;
-       gint focus_column;
-
-       gboolean show_text;
-};
-
-#define VFLIST(_vf_) ((ViewFileInfoList *)(_vf_->info))
-#define VFICON(_vf_) ((ViewFileInfoIcon *)(_vf_->info))
-
-const gint VIEW_FILE_COLUMN_POINTER = 0; // @todo Use inline constexpr in C++17
-
 void vf_send_update(ViewFile *vf);
 
 ViewFile *vf_new(FileViewType type, FileData *dir_fd);
@@ -165,8 +133,7 @@ GList *vf_get_list(ViewFile *vf);
 guint vf_selection_count(ViewFile *vf, gint64 *bytes);
 GList *vf_selection_get_list(ViewFile *vf);
 GList *vf_selection_get_list_by_index(ViewFile *vf);
-using ViewFileSelectionCallback = std::function<void(FileData *)>;
-void vf_selection_foreach(ViewFile *vf, const ViewFileSelectionCallback &func);
+void vf_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func);
 
 void vf_select_all(ViewFile *vf);
 void vf_select_none(ViewFile *vf);
index 34de870..3582f44 100644 (file)
@@ -40,6 +40,7 @@
 #include "misc.h"
 #include "options.h"
 #include "ui-fileops.h"
+#include "ui-menu.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
@@ -62,7 +63,7 @@ constexpr gint THUMB_BORDER_PADDING = 2;
 constexpr gint VFICON_TIP_DELAY = 500;
 
 enum {
-       FILE_COLUMN_POINTER = VIEW_FILE_COLUMN_POINTER,
+       FILE_COLUMN_POINTER = 0,
        FILE_COLUMN_COUNT
 };
 
@@ -104,10 +105,8 @@ GList *vficon_pop_menu_file_list(ViewFile *vf)
        return vficon_selection_get_one(vf, vf->click_fd);
 }
 
-void vficon_pop_menu_view_cb(GtkWidget *, gpointer data)
+void vficon_pop_menu_view_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        if (!vf->click_fd) return;
 
        if (vf->click_fd->selected & SELECTION_SELECTED)
@@ -124,20 +123,24 @@ void vficon_pop_menu_view_cb(GtkWidget *, gpointer data)
                }
 }
 
-void vficon_pop_menu_rename_cb(GtkWidget *, gpointer data)
+void vficon_pop_menu_rename_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        file_util_rename(nullptr, vf_pop_menu_file_list(vf), vf->listview);
 }
 
-void vficon_pop_menu_show_names_cb(GtkWidget *, gpointer data)
+static void vficon_pop_menu_show_names_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        vficon_toggle_filenames(vf);
 }
 
+void vficon_pop_menu_add_items(ViewFile *vf, GtkWidget *menu)
+{
+       menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
+                           G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
+}
+
 void vficon_pop_menu_show_star_rating_cb(ViewFile *vf)
 {
        GtkAllocation allocation;
@@ -146,19 +149,14 @@ void vficon_pop_menu_show_star_rating_cb(ViewFile *vf)
        vficon_populate_at_new_size(vf, allocation.width, allocation.height, TRUE);
 }
 
-void vficon_pop_menu_refresh_cb(GtkWidget *, gpointer data)
+void vficon_pop_menu_refresh_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        vf_refresh(vf);
 }
 
-void vficon_popup_destroy_cb(GtkWidget *, gpointer data)
+void vficon_popup_destroy_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
        vficon_selection_remove(vf, vf->click_fd, SELECTION_PRELIGHT, nullptr);
-       vf->click_fd = nullptr;
-       vf->popup = nullptr;
 }
 
 /*
@@ -883,6 +881,16 @@ GList *vficon_selection_get_list_by_index(ViewFile *vf)
        return g_list_reverse(list);
 }
 
+void vficon_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func)
+{
+       for (GList *work = VFICON(vf)->selection; work; work = work->next)
+               {
+               auto *fd_n = static_cast<FileData *>(work->data);
+
+               func(fd_n);
+               }
+}
+
 void vficon_select_by_fd(ViewFile *vf, FileData *fd)
 {
        if (!fd) return;
@@ -1182,9 +1190,8 @@ static gint page_height(ViewFile *vf)
  *-------------------------------------------------------------------
  */
 
-gboolean vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+gboolean vficon_press_key_cb(ViewFile *vf, GtkWidget *widget, GdkEventKey *event)
 {
-       auto vf = static_cast<ViewFile *>(data);
        gint focus_row = 0;
        gint focus_col = 0;
        FileData *fd;
@@ -1325,9 +1332,8 @@ static gboolean vficon_motion_cb(GtkWidget *, GdkEventMotion *event, gpointer da
        return FALSE;
 }
 
-gboolean vficon_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
+gboolean vficon_press_cb(ViewFile *vf, GtkWidget *, GdkEventButton *bevent)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GtkTreeIter iter;
        FileData *fd;
 
@@ -1373,9 +1379,8 @@ gboolean vficon_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
        return FALSE;
 }
 
-gboolean vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+gboolean vficon_release_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GtkTreeIter iter;
        FileData *fd = nullptr;
        gboolean was_selected;
@@ -1696,29 +1701,25 @@ void vficon_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case
  *-----------------------------------------------------------------------------
  */
 
-void vficon_thumb_progress_count(GList *list, gint *count, gint *done)
+void vficon_thumb_progress_count(const GList *list, gint &count, gint &done)
 {
-       GList *work = list;
-       while (work)
+       for (const GList *work = list; work; work = work->next)
                {
                auto fd = static_cast<FileData *>(work->data);
-               work = work->next;
 
-               if (fd->thumb_pixbuf) (*done)++;
-               (*count)++;
+               if (fd->thumb_pixbuf) done++;
+               count++;
                }
 }
 
-void vficon_read_metadata_progress_count(GList *list, gint *count, gint *done)
+void vficon_read_metadata_progress_count(const GList *list, gint &count, gint &done)
 {
-       GList *work = list;
-       while (work)
+       for (const GList *work = list; work; work = work->next)
                {
                auto fd = static_cast<FileData *>(work->data);
-               work = work->next;
 
-               if (fd->metadata_in_idle_loaded) (*done)++;
-               (*count)++;
+               if (fd->metadata_in_idle_loaded) done++;
+               count++;
                }
 }
 
@@ -1870,23 +1871,11 @@ FileData *vficon_star_next_fd(ViewFile *vf)
  *-----------------------------------------------------------------------------
  */
 
-gint vficon_index_by_fd(ViewFile *vf, FileData *in_fd)
+gint vficon_index_by_fd(const ViewFile *vf, const FileData *fd)
 {
-       gint p = 0;
-       GList *work;
+       if (!fd) return -1;
 
-       if (!in_fd) return -1;
-
-       work = vf->list;
-       while (work)
-               {
-               auto fd = static_cast<FileData *>(work->data);
-               if (fd == in_fd) return p;
-               work = work->next;
-               p++;
-               }
-
-       return -1;
+       return g_list_index(vf->list, fd);
 }
 
 /*
@@ -2232,10 +2221,8 @@ gboolean vficon_set_fd(ViewFile *vf, FileData *dir_fd)
        return ret;
 }
 
-void vficon_destroy_cb(GtkWidget *, gpointer data)
+void vficon_destroy_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        vf_refresh_idle_cancel(vf);
 
        file_data_unregister_notify_func(vf_notify_cb, vf);
@@ -2249,7 +2236,7 @@ void vficon_destroy_cb(GtkWidget *, gpointer data)
        g_list_free(VFICON(vf)->selection);
 }
 
-ViewFile *vficon_new(ViewFile *vf, FileData *)
+ViewFile *vficon_new(ViewFile *vf)
 {
        GtkListStore *store;
        GtkTreeSelection *selection;
index a0d0938..8822823 100644 (file)
 #include <gtk/gtk.h>
 
 #include "typedefs.h"
+#include "view-file.h"
 
 struct FileData;
-struct ViewFile;
 
-gboolean vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data);
-gboolean vficon_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data);
-gboolean vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data);
+struct ViewFileInfoIcon
+{
+       /* table stuff */
+       gint columns;
+       gint rows;
+
+       GList *selection;
+       FileData *prev_selection;
+
+       GtkWidget *tip_window;
+       guint tip_delay_id; /**< event source id */
+       FileData *tip_fd;
+
+       FileData *focus_fd;
+       gint focus_row;
+       gint focus_column;
+
+       gboolean show_text;
+};
+
+#define VFICON(_vf_) ((ViewFileInfoIcon *)((_vf_)->info))
+
+gboolean vficon_press_key_cb(ViewFile *vf, GtkWidget *widget, GdkEventKey *event);
+gboolean vficon_press_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent);
+gboolean vficon_release_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent);
 
 void vficon_dnd_init(ViewFile *vf);
 
-void vficon_destroy_cb(GtkWidget *widget, gpointer data);
-ViewFile *vficon_new(ViewFile *vf, FileData *dir_fd);
+void vficon_destroy_cb(ViewFile *vf);
+ViewFile *vficon_new(ViewFile *vf);
 
 gboolean vficon_set_fd(ViewFile *vf, FileData *dir_fd);
 gboolean vficon_refresh(ViewFile *vf);
 
-void vficon_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive);
 
 void vficon_marks_set(ViewFile *vf, gboolean enable);
 void vficon_star_rating_set(ViewFile *vf, gboolean enable);
+void vficon_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive);
 
 GList *vficon_selection_get_one(ViewFile *vf, FileData *fd);
 GList *vficon_pop_menu_file_list(ViewFile *vf);
-void vficon_pop_menu_view_cb(GtkWidget *widget, gpointer data);
-void vficon_pop_menu_rename_cb(GtkWidget *widget, gpointer data);
+void vficon_pop_menu_view_cb(ViewFile *vf);
+void vficon_pop_menu_rename_cb(ViewFile *vf);
+void vficon_pop_menu_add_items(ViewFile *vf, GtkWidget *menu);
 void vficon_pop_menu_show_star_rating_cb(ViewFile *vf);
-void vficon_pop_menu_refresh_cb(GtkWidget *widget, gpointer data);
-void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data);
-void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data);
+void vficon_pop_menu_refresh_cb(ViewFile *vf);
+void vficon_popup_destroy_cb(ViewFile *vf);
 
-FileData *vficon_index_get_data(ViewFile *vf, gint row);
-gint vficon_index_by_fd(ViewFile *vf, FileData *in_fd);
-guint vficon_count(ViewFile *vf, gint64 *bytes);
-GList *vficon_get_list(ViewFile *vf);
+gint vficon_index_by_fd(const ViewFile *vf, const FileData *fd);
 
 guint vficon_selection_count(ViewFile *vf, gint64 *bytes);
 GList *vficon_selection_get_list(ViewFile *vf);
 GList *vficon_selection_get_list_by_index(ViewFile *vf);
+void vficon_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func);
 
 void vficon_select_all(ViewFile *vf);
 void vficon_select_none(ViewFile *vf);
@@ -76,11 +96,10 @@ void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
 void vficon_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
 
 
-void vficon_thumb_progress_count(GList *list, gint *count, gint *done);
-void vficon_read_metadata_progress_count(GList *list, gint *count, gint *done);
+void vficon_thumb_progress_count(const GList *list, gint &count, gint &done);
+void vficon_read_metadata_progress_count(const GList *list, gint &count, gint &done);
 void vficon_set_thumb_fd(ViewFile *vf, FileData *fd);
 FileData *vficon_thumb_next_fd(ViewFile *vf);
-void vficon_thumb_reset_all(ViewFile *vf);
 
 FileData *vficon_star_next_fd(ViewFile *vf);
 void vficon_set_star_fd(ViewFile *vf, FileData *fd);
index b91914a..f1c0281 100644 (file)
@@ -40,6 +40,7 @@
 #include "misc.h"
 #include "options.h"
 #include "ui-fileops.h"
+#include "ui-menu.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
@@ -48,7 +49,7 @@
 
 /* Index to tree store */
 enum {
-       FILE_COLUMN_POINTER = VIEW_FILE_COLUMN_POINTER,
+       FILE_COLUMN_POINTER = 0,
        FILE_COLUMN_VERSION,
        FILE_COLUMN_THUMB,
        FILE_COLUMN_FORMATTED,
@@ -361,10 +362,8 @@ GList *vflist_pop_menu_file_list(ViewFile *vf)
 }
 
 
-void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
+void vflist_pop_menu_view_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        if (vflist_row_is_selected(vf, vf->click_fd))
                {
                GList *list;
@@ -379,9 +378,8 @@ void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
                }
 }
 
-void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
+void vflist_pop_menu_rename_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GList *list;
 
        list = vf_pop_menu_file_list(vf);
@@ -410,7 +408,7 @@ void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
        file_util_rename(nullptr, list, vf->listview);
 }
 
-void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
+static void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
@@ -425,6 +423,12 @@ void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
                }
 }
 
+void vflist_pop_menu_add_items(ViewFile *vf, GtkWidget *menu)
+{
+       menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
+                           G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
+}
+
 void vflist_star_rating_set(ViewFile *vf, gboolean enable)
 {
        GList *columns;
@@ -469,21 +473,16 @@ void vflist_pop_menu_show_star_rating_cb(ViewFile *vf)
        vflist_star_rating_set(vf, options->show_star_rating);
 }
 
-void vflist_pop_menu_refresh_cb(GtkWidget *, gpointer data)
+void vflist_pop_menu_refresh_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        vflist_color_set(vf, vf->click_fd, FALSE);
        vf_refresh(vf);
        gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
 }
 
-void vflist_popup_destroy_cb(GtkWidget *, gpointer data)
+void vflist_popup_destroy_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
        vflist_color_set(vf, vf->click_fd, FALSE);
-       vf->click_fd = nullptr;
-       vf->popup = nullptr;
 }
 
 
@@ -522,9 +521,8 @@ static gboolean vflist_row_rename_cb(TreeEditData *, const gchar *old_name, cons
        return FALSE;
 }
 
-gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+gboolean vflist_press_key_cb(ViewFile *vf, GtkWidget *widget, GdkEventKey *event)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
 
        if (event->keyval != GDK_KEY_Menu) return FALSE;
@@ -551,9 +549,8 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
        return TRUE;
 }
 
-gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+gboolean vflist_press_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
        GtkTreeIter iter;
        FileData *fd = nullptr;
@@ -635,9 +632,8 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
        return FALSE;
 }
 
-gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+gboolean vflist_release_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent)
 {
-       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
        GtkTreeIter iter;
        FileData *fd = nullptr;
@@ -1131,39 +1127,35 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case
  */
 
 
-void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
+void vflist_thumb_progress_count(const GList *list, gint &count, gint &done)
 {
-       GList *work = list;
-       while (work)
+       for (const GList *work = list; work; work = work->next)
                {
                auto fd = static_cast<FileData *>(work->data);
-               work = work->next;
 
-               if (fd->thumb_pixbuf) (*done)++;
+               if (fd->thumb_pixbuf) done++;
 
                if (fd->sidecar_files)
                        {
                        vflist_thumb_progress_count(fd->sidecar_files, count, done);
                        }
-               (*count)++;
+               count++;
                }
 }
 
-void vflist_read_metadata_progress_count(GList *list, gint *count, gint *done)
+void vflist_read_metadata_progress_count(const GList *list, gint &count, gint &done)
 {
-       GList *work = list;
-       while (work)
+       for (const GList *work = list; work; work = work->next)
                {
                auto fd = static_cast<FileData *>(work->data);
-               work = work->next;
 
-               if (fd->metadata_in_idle_loaded) (*done)++;
+               if (fd->metadata_in_idle_loaded) done++;
 
                if (fd->sidecar_files)
                        {
                        vflist_read_metadata_progress_count(fd->sidecar_files, count, done);
                        }
-               (*count)++;
+               count++;
                }
 }
 
@@ -1357,31 +1349,21 @@ FileData *vflist_star_next_fd(ViewFile *vf)
  *-----------------------------------------------------------------------------
  */
 
-gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
+gint vflist_index_by_fd(const ViewFile *vf, const FileData *fd)
 {
        gint p = 0;
-       GList *work;
-       GList *work2;
 
-       work = vf->list;
-       while (work)
+       for (const GList *work = vf->list; work; work = work->next)
                {
                auto list_fd = static_cast<FileData *>(work->data);
                if (list_fd == fd) return p;
 
-               work2 = list_fd->sidecar_files;
-               while (work2)
-                       {
-                       /** @FIXME return the same index also for sidecars
-                          it is sufficient for next/prev navigation but it should be rewritten
-                          without using indexes at all
-                       */
-                       auto sidecar_fd = static_cast<FileData *>(work2->data);
-                       if (sidecar_fd == fd) return p;
-                       work2 = work2->next;
-                       }
+               /** @FIXME return the same index also for sidecars
+                  it is sufficient for next/prev navigation but it should be rewritten
+                  without using indexes at all
+               */
+               if (g_list_find(list_fd->sidecar_files, fd)) return p;
 
-               work = work->next;
                p++;
                }
 
@@ -1530,6 +1512,24 @@ GList *vflist_selection_get_list_by_index(ViewFile *vf)
        return g_list_reverse(list);
 }
 
+void vflist_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func)
+{
+       GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
+       GtkTreeModel *store;
+       GtkTreeIter iter;
+       FileData *fd_n;
+
+       for (GList *work = gtk_tree_selection_get_selected_rows(selection, &store); work; work = work->next)
+               {
+               auto *tpath = static_cast<GtkTreePath *>(work->data);
+
+               gtk_tree_model_get_iter(store, &iter, tpath);
+               gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
+
+               func(fd_n);
+               }
+}
+
 void vflist_select_all(ViewFile *vf)
 {
        GtkTreeSelection *selection;
@@ -2096,10 +2096,8 @@ gboolean vflist_set_fd(ViewFile *vf, FileData *dir_fd)
        return ret;
 }
 
-void vflist_destroy_cb(GtkWidget *, gpointer data)
+void vflist_destroy_cb(ViewFile *vf)
 {
-       auto vf = static_cast<ViewFile *>(data);
-
        file_data_unregister_notify_func(vf_notify_cb, vf);
 
        vflist_select_idle_cancel(vf);
@@ -2110,7 +2108,7 @@ void vflist_destroy_cb(GtkWidget *, gpointer data)
        filelist_free(vf->list);
 }
 
-ViewFile *vflist_new(ViewFile *vf, FileData *)
+ViewFile *vflist_new(ViewFile *vf)
 {
        GtkTreeStore *store;
        GtkTreeSelection *selection;
index 6fc64c5..d726f07 100644 (file)
 #include <gtk/gtk.h>
 
 #include "typedefs.h"
+#include "view-file.h"
 
 struct FileData;
-struct ViewFile;
 
-gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data);
-gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data);
-gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data);
+struct ViewFileInfoList
+{
+       FileData *select_fd;
+
+       gboolean thumbs_enabled;
+
+       guint select_idle_id; /**< event source id */
+};
+
+#define VFLIST(_vf_) ((ViewFileInfoList *)((_vf_)->info))
+
+gboolean vflist_press_key_cb(ViewFile *vf, GtkWidget *widget, GdkEventKey *event);
+gboolean vflist_press_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent);
+gboolean vflist_release_cb(ViewFile *vf, GtkWidget *widget, GdkEventButton *bevent);
 
 void vflist_dnd_init(ViewFile *vf);
 
-void vflist_destroy_cb(GtkWidget *widget, gpointer data);
-ViewFile *vflist_new(ViewFile *vf, FileData *dir_fd);
+void vflist_destroy_cb(ViewFile *vf);
+ViewFile *vflist_new(ViewFile *vf);
 
 gboolean vflist_set_fd(ViewFile *vf, FileData *dir_fd);
 gboolean vflist_refresh(ViewFile *vf);
@@ -50,21 +61,19 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case
 
 GList *vflist_selection_get_one(ViewFile *vf, FileData *fd);
 GList *vflist_pop_menu_file_list(ViewFile *vf);
-void vflist_pop_menu_view_cb(GtkWidget *widget, gpointer data);
-void vflist_pop_menu_rename_cb(GtkWidget *widget, gpointer data);
+void vflist_pop_menu_view_cb(ViewFile *vf);
+void vflist_pop_menu_rename_cb(ViewFile *vf);
+void vflist_pop_menu_add_items(ViewFile *vf, GtkWidget *menu);
 void vflist_pop_menu_show_star_rating_cb(ViewFile *vf);
-void vflist_pop_menu_refresh_cb(GtkWidget *widget, gpointer data);
-void vflist_popup_destroy_cb(GtkWidget *widget, gpointer data);
-void vflist_pop_menu_thumbs_cb(GtkWidget *widget, gpointer data);
+void vflist_pop_menu_refresh_cb(ViewFile *vf);
+void vflist_popup_destroy_cb(ViewFile *vf);
 
-FileData *vflist_index_get_data(ViewFile *vf, gint row);
-gint vflist_index_by_fd(ViewFile *vf, FileData *fd);
-guint vflist_count(ViewFile *vf, gint64 *bytes);
-GList *vflist_get_list(ViewFile *vf);
+gint vflist_index_by_fd(const ViewFile *vf, const FileData *fd);
 
 guint vflist_selection_count(ViewFile *vf, gint64 *bytes);
 GList *vflist_selection_get_list(ViewFile *vf);
 GList *vflist_selection_get_list_by_index(ViewFile *vf);
+void vflist_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func);
 
 void vflist_select_all(ViewFile *vf);
 void vflist_select_none(ViewFile *vf);
@@ -77,11 +86,10 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
 
 void vflist_color_set(ViewFile *vf, FileData *fd, gboolean color_set);
 
-void vflist_thumb_progress_count(GList *list, gint *count, gint *done);
-void vflist_read_metadata_progress_count(GList *list, gint *count, gint *done);
+void vflist_thumb_progress_count(const GList *list, gint &count, gint &done);
+void vflist_read_metadata_progress_count(const GList *list, gint &count, gint &done);
 void vflist_set_thumb_fd(ViewFile *vf, FileData *fd);
 FileData *vflist_thumb_next_fd(ViewFile *vf);
-void vflist_thumb_reset_all(ViewFile *vf);
 
 FileData *vflist_star_next_fd(ViewFile *vf);
 void vflist_set_star_fd(ViewFile *vf, FileData *fd);
index dc00591..7be8736 100644 (file)
@@ -137,8 +137,8 @@ static gboolean vf_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: ret = vflist_press_key_cb(widget, event, data); break;
-       case FILEVIEW_ICON: ret = vficon_press_key_cb(widget, event, data); break;
+       case FILEVIEW_LIST: ret = vflist_press_key_cb(vf, widget, event); break;
+       case FILEVIEW_ICON: ret = vficon_press_key_cb(vf, widget, event); break;
        default: ret = FALSE;
        }
 
@@ -158,8 +158,8 @@ static gboolean vf_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: ret = vflist_press_cb(widget, bevent, data); break;
-       case FILEVIEW_ICON: ret = vficon_press_cb(widget, bevent, data); break;
+       case FILEVIEW_LIST: ret = vflist_press_cb(vf, widget, bevent); break;
+       case FILEVIEW_ICON: ret = vficon_press_cb(vf, widget, bevent); break;
        default: ret = FALSE;
        }
 
@@ -173,8 +173,8 @@ static gboolean vf_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointe
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: ret = vflist_release_cb(widget, bevent, data); break;
-       case FILEVIEW_ICON: ret = vficon_release_cb(widget, bevent, data); break;
+       case FILEVIEW_LIST: ret = vflist_release_cb(vf, widget, bevent); break;
+       case FILEVIEW_ICON: ret = vficon_release_cb(vf, widget, bevent); break;
        default: ret = FALSE;
        }
 
@@ -230,41 +230,15 @@ GList *vf_selection_get_list_by_index(ViewFile *vf)
        return ret;
 }
 
-void vf_selection_foreach(ViewFile *vf, const ViewFileSelectionCallback &func)
+void vf_selection_foreach(ViewFile *vf, const ViewFile::SelectionCallback &func)
 {
-       GtkTreeModel *store;
-       GList *work;
-       FileData *fd_n;
-       GtkTreeIter iter;
-
        if (!vf) return;
 
-       if (vf->type == FILEVIEW_ICON)
-               {
-               if (!VFICON(vf)->selection) return;
-               work = VFICON(vf)->selection;
-               }
-       else
-               {
-               GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
-               work = gtk_tree_selection_get_selected_rows(selection, &store);
-               }
-
-       for (; work; work = work->next)
-               {
-               if (vf->type == FILEVIEW_ICON)
-                       {
-                       fd_n = static_cast<FileData *>(work->data);
-                       }
-               else
-                       {
-                       auto *tpath = static_cast<GtkTreePath *>(work->data);
-                       gtk_tree_model_get_iter(store, &iter, tpath);
-                       gtk_tree_model_get(store, &iter, VIEW_FILE_COLUMN_POINTER, &fd_n, -1);
-                       }
-
-               func(fd_n);
-               }
+       switch (vf->type)
+       {
+       case FILEVIEW_LIST: vflist_selection_foreach(vf, func); break;
+       case FILEVIEW_ICON: vficon_selection_foreach(vf, func); break;
+       }
 }
 
 void vf_select_all(ViewFile *vf)
@@ -392,14 +366,14 @@ static void vf_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
        file_util_start_editor_from_filelist(key, vf_pop_menu_file_list(vf), vf->dir_fd->path, vf->listview);
 }
 
-static void vf_pop_menu_view_cb(GtkWidget *widget, gpointer data)
+static void vf_pop_menu_view_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_pop_menu_view_cb(widget, data); break;
-       case FILEVIEW_ICON: vficon_pop_menu_view_cb(widget, data); break;
+       case FILEVIEW_LIST: vflist_pop_menu_view_cb(vf); break;
+       case FILEVIEW_ICON: vficon_pop_menu_view_cb(vf); break;
        }
 }
 
@@ -436,14 +410,14 @@ static void vf_pop_menu_move_cb(GtkWidget *, gpointer data)
        file_util_move(nullptr, vf_pop_menu_file_list(vf), nullptr, vf->listview);
 }
 
-static void vf_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
+static void vf_pop_menu_rename_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_pop_menu_rename_cb(widget, data); break;
-       case FILEVIEW_ICON: vficon_pop_menu_rename_cb(widget, data); break;
+       case FILEVIEW_LIST: vflist_pop_menu_rename_cb(vf); break;
+       case FILEVIEW_ICON: vficon_pop_menu_rename_cb(vf); break;
        }
 }
 
@@ -613,27 +587,30 @@ static void vf_pop_menu_toggle_view_type_cb(GtkWidget *widget, gpointer data)
        layout_views_set(vf->layout, vf->layout->options.dir_view_type, new_type);
 }
 
-static void vf_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
+static void vf_pop_menu_refresh_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(widget, data); break;
-       case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(widget, data); break;
+       case FILEVIEW_LIST: vflist_pop_menu_refresh_cb(vf); break;
+       case FILEVIEW_ICON: vficon_pop_menu_refresh_cb(vf); break;
        }
 }
 
-static void vf_popup_destroy_cb(GtkWidget *widget, gpointer data)
+static void vf_popup_destroy_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_popup_destroy_cb(widget, data); break;
-       case FILEVIEW_ICON: vficon_popup_destroy_cb(widget, data); break;
+       case FILEVIEW_LIST: vflist_popup_destroy_cb(vf); break;
+       case FILEVIEW_ICON: vficon_popup_destroy_cb(vf); break;
        }
 
+       vf->click_fd = nullptr;
+       vf->popup = nullptr;
+
        filelist_free(vf->editmenu_fd_list);
        vf->editmenu_fd_list = nullptr;
 }
@@ -812,14 +789,8 @@ GtkWidget *vf_pop_menu(ViewFile *vf)
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST:
-               menu_item_add_check(menu, _("Show _thumbnails"), VFLIST(vf)->thumbs_enabled,
-                                   G_CALLBACK(vflist_pop_menu_thumbs_cb), vf);
-               break;
-       case FILEVIEW_ICON:
-               menu_item_add_check(menu, _("Show filename _text"), VFICON(vf)->show_text,
-                                   G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
-               break;
+       case FILEVIEW_LIST: vflist_pop_menu_add_items(vf, menu); break;
+       case FILEVIEW_ICON: vficon_pop_menu_add_items(vf, menu); break;
        }
 
        menu_item_add_check(menu, _("Show star rating"), options->show_star_rating,
@@ -858,14 +829,14 @@ gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
        return ret;
 }
 
-static void vf_destroy_cb(GtkWidget *widget, gpointer data)
+static void vf_destroy_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_destroy_cb(widget, data); break;
-       case FILEVIEW_ICON: vficon_destroy_cb(widget, data); break;
+       case FILEVIEW_LIST: vflist_destroy_cb(vf); break;
+       case FILEVIEW_ICON: vficon_destroy_cb(vf); break;
        }
 
        if (vf->popup)
@@ -1321,8 +1292,8 @@ ViewFile *vf_new(FileViewType type, FileData *dir_fd)
 
        switch (type)
        {
-       case FILEVIEW_LIST: vf = vflist_new(vf, dir_fd); break;
-       case FILEVIEW_ICON: vf = vficon_new(vf, dir_fd); break;
+       case FILEVIEW_LIST: vf = vflist_new(vf); break;
+       case FILEVIEW_ICON: vf = vficon_new(vf); break;
        }
 
        vf_dnd_init(vf);
@@ -1373,8 +1344,8 @@ static gdouble vf_thumb_progress(ViewFile *vf)
 
        switch (vf->type)
        {
-       case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
-       case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
+       case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, count, done); break;
+       case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, count, done); break;
        }
 
        DEBUG_1("thumb progress: %d of %d", done, count);
@@ -1387,10 +1358,10 @@ static gdouble vf_read_metadata_in_idle_progress(ViewFile *vf)
        gint done = 0;
 
        switch (vf->type)
-               {
-               case FILEVIEW_LIST: vflist_read_metadata_progress_count(vf->list, &count, &done); break;
-               case FILEVIEW_ICON: vficon_read_metadata_progress_count(vf->list, &count, &done); break;
-               }
+       {
+       case FILEVIEW_LIST: vflist_read_metadata_progress_count(vf->list, count, done); break;
+       case FILEVIEW_ICON: vficon_read_metadata_progress_count(vf->list, count, done); break;
+       }
 
        return static_cast<gdouble>(done) / count;
 }