Move common click_fd member to ViewFile
authorArkadiy Illarionov <qarkai@gmail.com>
Wed, 17 Apr 2024 21:12:26 +0000 (00:12 +0300)
committerColin Clark <colin.clark@cclark.uk>
Fri, 19 Apr 2024 09:09:39 +0000 (10:09 +0100)
src/view-file.h
src/view-file/view-file-icon.cc
src/view-file/view-file-list.cc
src/view-file/view-file.cc

index ae857e5..fbfd923 100644 (file)
@@ -56,6 +56,8 @@ struct ViewFile
        FileData *dir_fd;
        GList *list;
 
+       FileData *click_fd;
+
        SortType sort_method;
        gboolean sort_ascend;
        gboolean sort_case;
@@ -96,7 +98,6 @@ struct ViewFile
 
 struct ViewFileInfoList
 {
-       FileData *click_fd;
        FileData *select_fd;
 
        gboolean thumbs_enabled;
@@ -117,8 +118,6 @@ struct ViewFileInfoIcon
        guint tip_delay_id; /**< event source id */
        FileData *tip_fd;
 
-       FileData *click_fd;
-
        FileData *focus_fd;
        gint focus_row;
        gint focus_column;
index 56b9e54..34de870 100644 (file)
@@ -94,23 +94,23 @@ GList *vficon_selection_get_one(ViewFile *, FileData *fd)
 
 GList *vficon_pop_menu_file_list(ViewFile *vf)
 {
-       if (!VFICON(vf)->click_fd) return nullptr;
+       if (!vf->click_fd) return nullptr;
 
-       if (VFICON(vf)->click_fd->selected & SELECTION_SELECTED)
+       if (vf->click_fd->selected & SELECTION_SELECTED)
                {
                return vf_selection_get_list(vf);
                }
 
-       return vficon_selection_get_one(vf, VFICON(vf)->click_fd);
+       return vficon_selection_get_one(vf, vf->click_fd);
 }
 
 void vficon_pop_menu_view_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       if (!VFICON(vf)->click_fd) return;
+       if (!vf->click_fd) return;
 
-       if (VFICON(vf)->click_fd->selected & SELECTION_SELECTED)
+       if (vf->click_fd->selected & SELECTION_SELECTED)
                {
                GList *list;
 
@@ -120,7 +120,7 @@ void vficon_pop_menu_view_cb(GtkWidget *, gpointer data)
                }
        else
                {
-               view_window_new(VFICON(vf)->click_fd);
+               view_window_new(vf->click_fd);
                }
 }
 
@@ -156,8 +156,8 @@ void vficon_pop_menu_refresh_cb(GtkWidget *, gpointer data)
 void vficon_popup_destroy_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
-       vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, nullptr);
-       VFICON(vf)->click_fd = nullptr;
+       vficon_selection_remove(vf, vf->click_fd, SELECTION_PRELIGHT, nullptr);
+       vf->click_fd = nullptr;
        vf->popup = nullptr;
 }
 
@@ -485,15 +485,15 @@ static void vficon_dnd_get(GtkWidget *, GdkDragContext *,
        auto vf = static_cast<ViewFile *>(data);
        GList *list = nullptr;
 
-       if (!VFICON(vf)->click_fd) return;
+       if (!vf->click_fd) return;
 
-       if (VFICON(vf)->click_fd->selected & SELECTION_SELECTED)
+       if (vf->click_fd->selected & SELECTION_SELECTED)
                {
                list = vf_selection_get_list(vf);
                }
        else
                {
-               list = g_list_append(nullptr, file_data_ref(VFICON(vf)->click_fd));
+               list = g_list_append(nullptr, file_data_ref(vf->click_fd));
                }
 
        if (!list) return;
@@ -528,16 +528,16 @@ static void vficon_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointe
 
        tip_unschedule(vf);
 
-       if (VFICON(vf)->click_fd && VFICON(vf)->click_fd->thumb_pixbuf)
+       if (vf->click_fd && vf->click_fd->thumb_pixbuf)
                {
                gint items;
 
-               if (VFICON(vf)->click_fd->selected & SELECTION_SELECTED)
+               if (vf->click_fd->selected & SELECTION_SELECTED)
                        items = g_list_length(VFICON(vf)->selection);
                else
                        items = 1;
 
-               dnd_set_drag_icon(widget, context, VFICON(vf)->click_fd->thumb_pixbuf, items);
+               dnd_set_drag_icon(widget, context, vf->click_fd->thumb_pixbuf, items);
                }
 }
 
@@ -545,7 +545,7 @@ static void vficon_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, nullptr);
+       vficon_selection_remove(vf, vf->click_fd, SELECTION_PRELIGHT, nullptr);
 
        if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                {
@@ -1223,7 +1223,7 @@ gboolean vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                        fd = vficon_find_data(vf, VFICON(vf)->focus_row, VFICON(vf)->focus_column, nullptr);
                        if (fd)
                                {
-                               VFICON(vf)->click_fd = fd;
+                               vf->click_fd = fd;
                                if (event->state & GDK_CONTROL_MASK)
                                        {
                                        gint selected;
@@ -1249,9 +1249,9 @@ gboolean vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                        break;
                case GDK_KEY_Menu:
                        fd = vficon_find_data(vf, VFICON(vf)->focus_row, VFICON(vf)->focus_column, nullptr);
-                       VFICON(vf)->click_fd = fd;
+                       vf->click_fd = fd;
 
-                       vficon_selection_add(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, nullptr);
+                       vficon_selection_add(vf, vf->click_fd, SELECTION_PRELIGHT, nullptr);
                        tip_unschedule(vf);
 
                        vf->popup = vf_pop_menu(vf);
@@ -1281,18 +1281,18 @@ gboolean vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                                        }
                                else
                                        {
-                                       vficon_select_region_util(vf, VFICON(vf)->click_fd, old_fd, FALSE);
+                                       vficon_select_region_util(vf, vf->click_fd, old_fd, FALSE);
                                        }
-                               vficon_select_region_util(vf, VFICON(vf)->click_fd, new_fd, TRUE);
+                               vficon_select_region_util(vf, vf->click_fd, new_fd, TRUE);
                                vficon_send_layout_select(vf, new_fd);
                                }
                        else if (event->state & GDK_CONTROL_MASK)
                                {
-                               VFICON(vf)->click_fd = new_fd;
+                               vf->click_fd = new_fd;
                                }
                        else
                                {
-                               VFICON(vf)->click_fd = new_fd;
+                               vf->click_fd = new_fd;
                                vf_select_none(vf);
                                vficon_select(vf, new_fd);
                                vficon_send_layout_select(vf, new_fd);
@@ -1337,8 +1337,8 @@ gboolean vficon_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
 
        if (fd)
                {
-               VFICON(vf)->click_fd = fd;
-               vficon_selection_add(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
+               vf->click_fd = fd;
+               vficon_selection_add(vf, vf->click_fd, SELECTION_PRELIGHT, &iter);
 
                switch (bevent->button)
                        {
@@ -1350,13 +1350,13 @@ gboolean vficon_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
 
                                if (bevent->type == GDK_2BUTTON_PRESS && vf->layout)
                                        {
-                                       if (VFICON(vf)->click_fd->format_class == FORMAT_CLASS_COLLECTION)
+                                       if (vf->click_fd->format_class == FORMAT_CLASS_COLLECTION)
                                                {
-                                               collection_window_new(VFICON(vf)->click_fd->path);
+                                               collection_window_new(vf->click_fd->path);
                                                }
                                        else
                                                {
-                                               vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
+                                               vficon_selection_remove(vf, vf->click_fd, SELECTION_PRELIGHT, &iter);
                                                layout_image_full_screen_start(vf->layout);
                                                }
                                        }
@@ -1392,12 +1392,12 @@ gboolean vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
                fd = vficon_find_data_by_coord(vf, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
                }
 
-       if (VFICON(vf)->click_fd)
+       if (vf->click_fd)
                {
-               vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, nullptr);
+               vficon_selection_remove(vf, vf->click_fd, SELECTION_PRELIGHT, nullptr);
                }
 
-       if (!fd || VFICON(vf)->click_fd != fd) return TRUE;
+       if (!fd || vf->click_fd != fd) return TRUE;
 
        was_selected = !!(fd->selected & SELECTION_SELECTED);
 
@@ -1981,7 +1981,7 @@ static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
                        GList *to_delete = work;
                        work = work->next;
                        if (fd == VFICON(vf)->prev_selection) VFICON(vf)->prev_selection = nullptr;
-                       if (fd == VFICON(vf)->click_fd) VFICON(vf)->click_fd = nullptr;
+                       if (fd == vf->click_fd) vf->click_fd = nullptr;
                        file_data_unref(fd);
                        vf->list = g_list_delete_link(vf->list, to_delete);
                        }
index 9404981..b91914a 100644 (file)
@@ -227,15 +227,15 @@ static void vflist_dnd_get(GtkWidget *, GdkDragContext *,
        auto vf = static_cast<ViewFile *>(data);
        GList *list = nullptr;
 
-       if (!VFLIST(vf)->click_fd) return;
+       if (!vf->click_fd) return;
 
-       if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
+       if (vflist_row_is_selected(vf, vf->click_fd))
                {
                list = vf_selection_get_list(vf);
                }
        else
                {
-               list = g_list_append(nullptr, file_data_ref(VFLIST(vf)->click_fd));
+               list = g_list_append(nullptr, file_data_ref(vf->click_fd));
                }
 
        if (!list) return;
@@ -247,19 +247,19 @@ static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointe
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
+       vflist_color_set(vf, vf->click_fd, TRUE);
 
        if (VFLIST(vf)->thumbs_enabled &&
-           VFLIST(vf)->click_fd && VFLIST(vf)->click_fd->thumb_pixbuf)
+           vf->click_fd && vf->click_fd->thumb_pixbuf)
                {
                guint items;
 
-               if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
+               if (vflist_row_is_selected(vf, vf->click_fd))
                        items = vf_selection_count(vf, nullptr);
                else
                        items = 1;
 
-               dnd_set_drag_icon(widget, context, VFLIST(vf)->click_fd->thumb_pixbuf, items);
+               dnd_set_drag_icon(widget, context, vf->click_fd->thumb_pixbuf, items);
                }
 }
 
@@ -267,7 +267,7 @@ static void vflist_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
+       vflist_color_set(vf, vf->click_fd, FALSE);
 
        if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                {
@@ -351,13 +351,13 @@ GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
 
 GList *vflist_pop_menu_file_list(ViewFile *vf)
 {
-       if (!VFLIST(vf)->click_fd) return nullptr;
+       if (!vf->click_fd) return nullptr;
 
-       if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
+       if (vflist_row_is_selected(vf, vf->click_fd))
                {
                return vf_selection_get_list(vf);
                }
-       return vflist_selection_get_one(vf, VFLIST(vf)->click_fd);
+       return vflist_selection_get_one(vf, vf->click_fd);
 }
 
 
@@ -365,7 +365,7 @@ void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
+       if (vflist_row_is_selected(vf, vf->click_fd))
                {
                GList *list;
 
@@ -375,7 +375,7 @@ void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
                }
        else
                {
-               view_window_new(VFLIST(vf)->click_fd);
+               view_window_new(vf->click_fd);
                }
 }
 
@@ -386,7 +386,7 @@ void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
 
        list = vf_pop_menu_file_list(vf);
        if (options->file_ops.enable_in_place_rename &&
-           list && !list->next && VFLIST(vf)->click_fd)
+           list && !list->next && vf->click_fd)
                {
                GtkTreeModel *store;
                GtkTreeIter iter;
@@ -394,14 +394,14 @@ void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
                filelist_free(list);
 
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
-               if (vflist_find_row(vf, VFLIST(vf)->click_fd, &iter) >= 0)
+               if (vflist_find_row(vf, vf->click_fd, &iter) >= 0)
                        {
                        GtkTreePath *tpath;
 
                        tpath = gtk_tree_model_get_path(store, &iter);
                        tree_edit_by_path(GTK_TREE_VIEW(vf->listview), tpath,
-                                         FILE_VIEW_COLUMN_FORMATTED, VFLIST(vf)->click_fd->name,
-                                         vflist_row_rename_cb, vf);
+                                         FILE_VIEW_COLUMN_FORMATTED, vf->click_fd->name,
+                                         vflist_row_rename_cb, vf);
                        gtk_tree_path_free(tpath);
                        }
                return;
@@ -414,7 +414,7 @@ void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
+       vflist_color_set(vf, vf->click_fd, FALSE);
        if (vf->layout)
                {
                layout_thumb_set(vf->layout, !VFLIST(vf)->thumbs_enabled);
@@ -465,7 +465,7 @@ void vflist_pop_menu_show_star_rating_cb(ViewFile *vf)
 {
        vflist_populate_view(vf, TRUE);
 
-       vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
+       vflist_color_set(vf, vf->click_fd, FALSE);
        vflist_star_rating_set(vf, options->show_star_rating);
 }
 
@@ -473,7 +473,7 @@ void vflist_pop_menu_refresh_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
 
-       vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
+       vflist_color_set(vf, vf->click_fd, FALSE);
        vf_refresh(vf);
        gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
 }
@@ -481,8 +481,8 @@ void vflist_pop_menu_refresh_cb(GtkWidget *, gpointer data)
 void vflist_popup_destroy_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
-       vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
-       VFLIST(vf)->click_fd = nullptr;
+       vflist_color_set(vf, vf->click_fd, FALSE);
+       vf->click_fd = nullptr;
        vf->popup = nullptr;
 }
 
@@ -537,12 +537,12 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
 
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
                gtk_tree_model_get_iter(store, &iter, tpath);
-               gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &VFLIST(vf)->click_fd, -1);
+               gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vf->click_fd, -1);
                gtk_tree_path_free(tpath);
                }
        else
                {
-               VFLIST(vf)->click_fd = nullptr;
+               vf->click_fd = nullptr;
                }
 
        vf->popup = vf_pop_menu(vf);
@@ -581,7 +581,7 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
                gtk_tree_path_free(tpath);
                }
 
-       VFLIST(vf)->click_fd = fd;
+       vf->click_fd = fd;
 
        if (bevent->button == MOUSE_BUTTON_RIGHT)
                {
@@ -622,9 +622,9 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
 
        if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS)
                {
-               if (VFLIST(vf)->click_fd->format_class == FORMAT_CLASS_COLLECTION)
+               if (vf->click_fd->format_class == FORMAT_CLASS_COLLECTION)
                        {
-                       collection_window_new(VFLIST(vf)->click_fd->path);
+                       collection_window_new(vf->click_fd->path);
                        }
                else
                        {
@@ -649,7 +649,7 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
 
        if (bevent->button == MOUSE_BUTTON_MIDDLE)
                {
-               vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
+               vflist_color_set(vf, vf->click_fd, FALSE);
                }
 
        if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE)
@@ -671,7 +671,7 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
 
        if (bevent->button == MOUSE_BUTTON_MIDDLE)
                {
-               if (fd && VFLIST(vf)->click_fd == fd)
+               if (fd && vf->click_fd == fd)
                        {
                        GtkTreeSelection *selection;
 
@@ -688,7 +688,7 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
                return TRUE;
                }
 
-       if (fd && VFLIST(vf)->click_fd == fd &&
+       if (fd && vf->click_fd == fd &&
            !(bevent->state & GDK_SHIFT_MASK ) &&
            !(bevent->state & GDK_CONTROL_MASK ) &&
            vflist_row_is_selected(vf, fd))
index 27b0c8e..dc00591 100644 (file)
@@ -407,20 +407,9 @@ static void vf_pop_menu_open_archive_cb(GtkWidget *, gpointer data)
 {
        auto vf = static_cast<ViewFile *>(data);
        LayoutWindow *lw_new;
-       FileData *fd = nullptr;
        gchar *dest_dir;
 
-       switch (vf->type)
-       {
-       case FILEVIEW_LIST:
-               fd = (VFLIST(vf)->click_fd);
-               break;
-       case FILEVIEW_ICON:
-               fd = (VFICON(vf)->click_fd);
-               break;
-       }
-
-       dest_dir = open_archive(fd);
+       dest_dir = open_archive(vf->click_fd);
        if (dest_dir)
                {
                lw_new = layout_new_from_default();
@@ -690,18 +679,13 @@ GtkWidget *vf_pop_menu(ViewFile *vf)
        gboolean class_archive = FALSE;
        GtkAccelGroup *accel_group;
 
-       switch (vf->type)
-       {
-       case FILEVIEW_LIST:
-               vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
-               active = (VFLIST(vf)->click_fd != nullptr);
-               class_archive = (VFLIST(vf)->click_fd != nullptr && VFLIST(vf)->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
-               break;
-       case FILEVIEW_ICON:
-               active = (VFICON(vf)->click_fd != nullptr);
-               class_archive = (VFICON(vf)->click_fd != nullptr && VFICON(vf)->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
-               break;
-       }
+       if (vf->type == FILEVIEW_LIST)
+               {
+               vflist_color_set(vf, vf->click_fd, TRUE);
+               }
+
+       active = (vf->click_fd != nullptr);
+       class_archive = (vf->click_fd != nullptr && vf->click_fd->format_class == FORMAT_CLASS_ARCHIVE);
 
        menu = popup_menu_short_lived();