[nautilus/wip/antoniof/flow-box-preparation: 2/20] files-view: Make preview an action
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/flow-box-preparation: 2/20] files-view: Make preview an action
- Date: Thu, 23 Dec 2021 23:10:43 +0000 (UTC)
commit 8fa6ba94936de2db31ae2976a02d7867cb10b358
Author: António Fernandes <antoniof gnome org>
Date: Sat Dec 18 13:44:11 2021 +0000
files-view: Make preview an action
Preview is activated when Space key is pressed. It has been implemented
in each view's key event handlers. Except the new grid view, where it
is part of the GtkFlowBox::child-activated handler; as this is not an
event handler, it requires calling gtk_get_current_event() in order
to know the pressed key and possible modifiers.
This is problematic because gtk_get_current_event() is gone in GTK 4.
Instead, let's simplify this whole thing by making an action and
setting an accelerator. This will trigger before the event handlers,
so there is no need for the event handlers to do anything about it.
src/nautilus-canvas-view.c | 15 ---------------
src/nautilus-files-view.c | 35 ++++++++++++++++++++++-------------
src/nautilus-files-view.h | 3 ---
src/nautilus-list-view.c | 19 -------------------
src/nautilus-view-icon-controller.c | 23 +----------------------
5 files changed, 23 insertions(+), 72 deletions(-)
---
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index ce162d414..fdb47c328 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -1039,19 +1039,6 @@ canvas_container_activate_callback (NautilusCanvasContainer *container,
0, TRUE);
}
-static void
-canvas_container_activate_previewer_callback (NautilusCanvasContainer *container,
- GList *file_list,
- GArray *locations,
- NautilusCanvasView *canvas_view)
-{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
-
- nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (canvas_view),
- file_list, locations);
-}
-
/* this is called in one of these cases:
* - we activate with enter holding shift
* - we activate with space holding shift
@@ -1390,8 +1377,6 @@ initialize_canvas_container (NautilusCanvasView *canvas_view,
G_CALLBACK (canvas_container_activate_callback), canvas_view, 0);
g_signal_connect_object (canvas_container, "activate-alternate",
G_CALLBACK (canvas_container_activate_alternate_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "activate-previewer",
- G_CALLBACK (canvas_container_activate_previewer_callback), canvas_view, 0);
g_signal_connect_object (canvas_container, "band-select-started",
G_CALLBACK (band_select_started_callback), canvas_view, 0);
g_signal_connect_object (canvas_container, "band-select-ended",
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index dfb7fb26c..cb39a9ef5 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1267,19 +1267,6 @@ nautilus_files_view_preview (NautilusFilesView *view,
}
}
-void
-nautilus_files_view_preview_files (NautilusFilesView *view,
- GList *files,
- GArray *locations)
-{
- PreviewExportData *data = g_new0 (PreviewExportData, 1);
-
- data->uri = nautilus_file_get_uri (files->data);
- data->is_update = FALSE;
-
- nautilus_files_view_preview (view, data);
-}
-
static void
nautilus_files_view_preview_update (NautilusFilesView *view)
{
@@ -1713,6 +1700,23 @@ action_invert_selection (GSimpleAction *action,
nautilus_files_view_invert_selection (user_data);
}
+static void
+action_preview_selection (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusFilesView *view = NAUTILUS_FILES_VIEW (user_data);
+ g_autolist (NautilusFile) selection = NULL;
+ PreviewExportData *data = g_new0 (PreviewExportData, 1);
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+
+ data->uri = nautilus_file_get_uri (selection->data);
+ data->is_update = FALSE;
+
+ nautilus_files_view_preview (view, data);
+}
+
static void
pattern_select_response_cb (GtkWidget *dialog,
int response,
@@ -7206,6 +7210,7 @@ const GActionEntry view_entries[] =
/* Only accesible by shorcuts */
{ "select-pattern", action_select_pattern },
{ "invert-selection", action_invert_selection },
+ { "preview-selection", action_preview_selection },
};
static gboolean
@@ -7789,6 +7794,9 @@ real_update_actions_state (NautilusFilesView *view)
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
can_move_files && !selection_contains_recent &&
!selection_contains_starred);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "preview-selection");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count != 0);
/* Drive menu */
show_mount = (selection != NULL);
@@ -9998,6 +10006,7 @@ nautilus_files_view_init (NautilusFilesView *view)
nautilus_application_set_accelerator (app, "view.select-pattern", "<control>s");
nautilus_application_set_accelerators (app, "view.zoom-standard", zoom_standard_accels);
nautilus_application_set_accelerator (app, "view.invert-selection", "<shift><control>i");
+ nautilus_application_set_accelerator (app, "view.preview-selection", "space");
priv->starred_cancellable = g_cancellable_new ();
priv->tag_manager = nautilus_tag_manager_get ();
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index f1b31d464..afeabc3c5 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -266,9 +266,6 @@ void nautilus_files_view_activate_files (Nautil
void nautilus_files_view_activate_file (NautilusFilesView *view,
NautilusFile *file,
NautilusWindowOpenFlags flags);
-void nautilus_files_view_preview_files (NautilusFilesView *view,
- GList *files,
- GArray *locations);
void nautilus_files_view_start_batching_selection_changes (NautilusFilesView *view);
void nautilus_files_view_stop_batching_selection_changes (NautilusFilesView *view);
void nautilus_files_view_notify_selection_changed (NautilusFilesView *view);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index b8248e0bc..cf06c0b62 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -174,21 +174,6 @@ list_selection_changed_callback (GtkTreeSelection *selection,
nautilus_files_view_notify_selection_changed (view);
}
-static void
-preview_selected_items (NautilusListView *view)
-{
- GList *file_list;
-
- file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
-
- if (file_list != NULL)
- {
- nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (view),
- file_list, NULL);
- nautilus_file_list_free (file_list);
- }
-}
-
static void
activate_selected_items (NautilusListView *view)
{
@@ -893,10 +878,6 @@ on_event_controller_key_key_pressed (GtkEventControllerKey *controller,
{
activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
}
- else
- {
- preview_selected_items (NAUTILUS_LIST_VIEW (view));
- }
return GDK_EVENT_STOP;
}
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index b4746efd5..ed4bee7df 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -981,34 +981,13 @@ on_child_activated (GtkFlowBox *flow_box,
NautilusViewItemModel *item_model;
NautilusFile *file;
g_autoptr (GList) list = NULL;
- GdkEvent *event;
- guint keyval;
- gboolean is_preview = FALSE;
item_model = g_list_model_get_item (G_LIST_MODEL (self->model),
gtk_flow_box_child_get_index (child));
file = nautilus_view_item_model_get_file (item_model);
list = g_list_append (list, file);
- event = gtk_get_current_event ();
- if (event && gdk_event_get_keyval (event, &keyval))
- {
- if (keyval == GDK_KEY_space)
- {
- is_preview = TRUE;
- }
- }
-
- if (is_preview)
- {
- nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (self), list, NULL);
- }
- else
- {
- nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (self), list, 0, TRUE);
- }
-
- g_clear_pointer (&event, gdk_event_free);
+ nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (self), list, 0, TRUE);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]