[file-roller/wip/jtojnar/search-jump: 31/31] Add context menu item to navigate to a file from search
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller/wip/jtojnar/search-jump: 31/31] Add context menu item to navigate to a file from search
- Date: Fri, 15 Jul 2022 14:25:44 +0000 (UTC)
commit a62f247e23deee154e0a2b8bcbba3a490546754c
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 | 1 +
src/fr-window.c | 10 ++++++++--
src/fr-window.h | 1 +
src/ui/menus.ui | 5 +++++
8 files changed, 44 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 08c8f3b0..4d32e384 100644
--- a/src/fr-window-actions-entries.h
+++ b/src/fr-window-actions-entries.h
@@ -41,6 +41,7 @@ static const GActionEntry fr_window_actions[] = {
{ "go-back", fr_window_activate_go_back },
{ "go-forward", fr_window_activate_go_forward },
{ "go-home", fr_window_activate_go_home },
+ { "navigate-to", fr_window_activate_navigate_to },
{ "open-folder", fr_window_activate_open_folder },
{ "open-with", fr_window_activate_open_with },
{ "reload", fr_window_activate_reload },
diff --git a/src/fr-window.c b/src/fr-window.c
index 9063c06b..64115cce 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -1125,6 +1125,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 && window->priv->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);
@@ -3331,6 +3332,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)
{
GtkTreeSelection *selection;
@@ -3357,6 +3359,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));
}
@@ -4645,7 +4651,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));
@@ -8442,7 +8448,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 7bbffec5..f6438692 100644
--- a/src/fr-window.h
+++ b/src/fr-window.h
@@ -198,6 +198,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]