[file-roller/wip/jtojnar/search-jump: 53/53] Add context menu item to navigate to a file from search




commit 89cecd81634889f4ca87c7cc07b51381f38840ac
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon May 16 02:33:59 2022 +0200

    Add context menu item to navigate to a file from search

 src/dlg-delete.c                  |  2 +-
 src/dlg-open-with.c               |  2 +-
 src/fr-window-actions-callbacks.c | 27 ++++++++++++++++++++++++++-
 src/fr-window-actions-callbacks.h |  1 +
 src/fr-window-actions-entries.h   |  4 ++++
 src/fr-window.c                   | 10 ++++++++--
 src/fr-window.h                   |  1 +
 src/ui/menus.ui                   |  5 +++++
 8 files changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/src/dlg-delete.c b/src/dlg-delete.c
index d4307a6d..bd64a0e3 100644
--- a/src/dlg-delete.c
+++ b/src/dlg-delete.c
@@ -188,7 +188,7 @@ dlg_delete (GtkWidget *widget,
 {
        FrWindow *window = callback_data;
        dlg_delete__common (window,
-                           fr_window_get_file_list_selection (window, TRUE, NULL));
+                           fr_window_get_file_list_selection (window, TRUE, FALSE, NULL));
 }
 
 
diff --git a/src/dlg-open-with.c b/src/dlg-open-with.c
index e8ebdbfa..8b4fe9f9 100644
--- a/src/dlg-open-with.c
+++ b/src/dlg-open-with.c
@@ -157,7 +157,7 @@ open_with_cb (GtkWidget *widget,
        FrWindow *window = callback_data;
        GList    *file_list;
 
-       file_list = fr_window_get_file_list_selection (window, FALSE, NULL);
+       file_list = fr_window_get_file_list_selection (window, FALSE, FALSE, NULL);
        if (file_list == NULL)
                return;
 
diff --git a/src/fr-window-actions-callbacks.c b/src/fr-window-actions-callbacks.c
index c02e8d79..50de10ff 100644
--- a/src/fr-window-actions-callbacks.c
+++ b/src/fr-window-actions-callbacks.c
@@ -216,6 +216,31 @@ fr_window_activate_rename (GSimpleAction *action,
 }
 
 
+void
+fr_window_activate_navigate_to (GSimpleAction *action,
+                       GVariant      *parameter,
+                       gpointer       user_data)
+{
+       FrWindow *window = FR_WINDOW (user_data);
+       GList *file_list = fr_window_get_file_list_selection (window, FALSE, TRUE, NULL);
+
+       if (file_list == NULL) {
+               return;
+       }
+
+       // g_path_get_dirname will return the directory itself if the path ends with /
+       // so we need to trim it first to be able to get the parent.
+       g_autofree char *selected_path = g_str_has_suffix (file_list->data, G_DIR_SEPARATOR_S) ? 
g_path_get_dirname (file_list->data) : g_strdup (file_list->data);
+       g_autofree char *selected_location = g_path_get_dirname (selected_path);
+       g_autofree char *selected_location_abs = g_strdup_printf ("/%s", selected_location);
+
+       fr_window_go_to_location (window, selected_location_abs, TRUE);
+       fr_window_find (window, FALSE);
+
+       _g_string_list_free (file_list);
+}
+
+
 void
 fr_window_activate_new (GSimpleAction *action,
                        GVariant      *parameter,
@@ -439,7 +464,7 @@ fr_window_activate_view_selection (GSimpleAction *action,
        FrWindow *window = FR_WINDOW (user_data);
        GList    *file_list;
 
-       file_list = fr_window_get_file_list_selection (window, FALSE, NULL);
+       file_list = fr_window_get_file_list_selection (window, FALSE, FALSE, NULL);
        if (file_list != NULL)
                fr_window_open_files (window, file_list, FALSE);
 
diff --git a/src/fr-window-actions-callbacks.h b/src/fr-window-actions-callbacks.h
index 139be8a3..f63d41e9 100644
--- a/src/fr-window-actions-callbacks.h
+++ b/src/fr-window-actions-callbacks.h
@@ -41,6 +41,7 @@ DEF_ACTION_CALLBACK (fr_window_activate_find)
 DEF_ACTION_CALLBACK (fr_window_activate_go_back)
 DEF_ACTION_CALLBACK (fr_window_activate_go_forward)
 DEF_ACTION_CALLBACK (fr_window_activate_go_home)
+DEF_ACTION_CALLBACK (fr_window_activate_navigate_to)
 DEF_ACTION_CALLBACK (fr_window_activate_new)
 DEF_ACTION_CALLBACK (fr_window_activate_open)
 DEF_ACTION_CALLBACK (fr_window_activate_open_folder)
diff --git a/src/fr-window-actions-entries.h b/src/fr-window-actions-entries.h
index d777a319..6ff45ad5 100644
--- a/src/fr-window-actions-entries.h
+++ b/src/fr-window-actions-entries.h
@@ -82,6 +82,10 @@ static const GActionEntry fr_window_actions[] = {
                .name = "go-home",
                .activate = fr_window_activate_go_home,
        },
+       {
+               .name = "navigate-to",
+               .activate = fr_window_activate_navigate_to,
+       },
        {
                .name = "open-folder",
                .activate = fr_window_activate_open_folder,
diff --git a/src/fr-window.c b/src/fr-window.c
index ca41f89d..35888a7d 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -1141,6 +1141,7 @@ fr_window_update_sensitivity (FrWindow *window)
        fr_window_enable_action (window, "edit-password", ! running && (! no_archive && 
window->archive->propPassword));
        fr_window_enable_action (window, "extract-files", file_op);
        fr_window_enable_action (window, "find", ! no_archive);
+       fr_window_enable_action (window, "navigate-to", ! no_archive && private->filter_mode && 
one_file_selected);
        fr_window_enable_action (window, "open-folder", file_op && one_file_selected && dir_selected);
        fr_window_enable_action (window, "open-with", file_op && sel_not_null && ! dir_selected);
        fr_window_enable_action (window, "rename", ! no_archive && ! ro && ! running && can_store_many_files 
&& one_file_selected);
@@ -3387,6 +3388,7 @@ get_dir_list_from_file_data (FrWindow *window,
 GList *
 fr_window_get_file_list_selection (FrWindow *window,
                                   gboolean  recursive,
+                                  gboolean  include_dirs,
                                   gboolean *has_dirs)
 {
        FrWindowPrivate *private = fr_window_get_instance_private (window);
@@ -3414,6 +3416,10 @@ fr_window_get_file_list_selection (FrWindow *window,
                        if (has_dirs != NULL)
                                *has_dirs = TRUE;
 
+                       if (include_dirs) {
+                               list = g_list_append (list, g_strdup (fd->original_path));
+                       }
+
                        if (recursive)
                                list = g_list_concat (list, get_dir_list_from_file_data (window, fd));
                }
@@ -4723,7 +4729,7 @@ fr_window_file_list_drag_data_get (FrWindow         *window,
                char            *data;
 
                tmp = fr_clipboard_data_new ();
-               tmp->files = fr_window_get_file_list_selection (window, TRUE, NULL);
+               tmp->files = fr_window_get_file_list_selection (window, TRUE, FALSE, NULL);
                tmp->op = FR_CLIPBOARD_OP_COPY;
                tmp->base_dir = g_strdup (fr_window_get_current_location (window));
 
@@ -8580,7 +8586,7 @@ fr_window_get_selection (FrWindow   *window,
                g_free (parent_folder);
        }
        else {
-               files = fr_window_get_file_list_selection (window, TRUE, NULL);
+               files = fr_window_get_file_list_selection (window, TRUE, FALSE, NULL);
                base_dir = g_strdup (fr_window_get_current_location (window));
        }
 
diff --git a/src/fr-window.h b/src/fr-window.h
index e31d1b61..859b8f5a 100644
--- a/src/fr-window.h
+++ b/src/fr-window.h
@@ -173,6 +173,7 @@ void            fr_window_set_list_mode                (FrWindow      *window,
 
 GList *         fr_window_get_file_list_selection      (FrWindow    *window,
                                                        gboolean     recursive,
+                                                       gboolean     include_dirs,
                                                        gboolean    *has_dirs);
 GList *         fr_window_get_file_list_from_path_list (FrWindow    *window,
                                                        GList       *path_list,
diff --git a/src/ui/menus.ui b/src/ui/menus.ui
index 69b33f2e..738d6a5d 100644
--- a/src/ui/menus.ui
+++ b/src/ui/menus.ui
@@ -11,6 +11,11 @@
         <attribute name="label" translatable="yes">_Open With…</attribute>
         <attribute name="action">win.open-with</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">Open _Item Location</attribute>
+        <attribute name="hidden-when">action-disabled</attribute>
+        <attribute name="action">win.navigate-to</attribute>
+      </item>
     </section>
     <section>
       <item>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]