[nautilus/wip/antoniof/streamlin-preview-updating: 12/13] application: Hand preview updating over to FilesView
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/streamlin-preview-updating: 12/13] application: Hand preview updating over to FilesView
- Date: Fri, 2 Jul 2021 06:28:03 +0000 (UTC)
commit ae67618bda72fb0ca14cf45b5160c6bb41eb5a22
Author: António Fernandes <antoniof gnome org>
Date: Wed May 26 13:45:23 2021 +0100
application: Hand preview updating over to FilesView
When the NautilusFilesView:selection property changes, this change is
notified to the slot, the the window, then the application, though a
chain of bindings and singals. The application class then calls a
NautilusFilesView method to actually update the preview.
The NautilusApplication class used to update the preview when the
active window changes, but that's no longer the case after the changes
in commit 0b7a7f95f84f775be38e5533a37f93567fba2b59.
This whole roadtrip to NautilusApplication and back is useless now, so
let's handle it all in NautilusFilesView.
src/nautilus-application.c | 49 ----------------------------------------------
src/nautilus-files-view.c | 31 ++++++++++++++++++++++++-----
src/nautilus-files-view.h | 2 --
3 files changed, 26 insertions(+), 56 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 5deae5cc9..973e1b521 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -46,7 +46,6 @@
#include "nautilus-dbus-manager.h"
#include "nautilus-directory-private.h"
#include "nautilus-file.h"
-#include "nautilus-files-view.h"
#include "nautilus-file-operations.h"
#include "nautilus-file-undo-manager.h"
#include "nautilus-file-utilities.h"
@@ -1221,45 +1220,6 @@ nautilus_application_withdraw_notification (NautilusApplication *self,
g_application_withdraw_notification (G_APPLICATION (self), notification_id);
}
-static void
-update_previewer_selection (NautilusApplication *self,
- NautilusWindow *window)
-{
- GtkWindow *gtk_window;
- NautilusWindowSlot *slot;
- NautilusView *view;
- GList *selection;
-
- gtk_window = gtk_application_get_active_window (GTK_APPLICATION (self));
- if (!NAUTILUS_IS_WINDOW (gtk_window))
- {
- return;
- }
-
- if (NAUTILUS_WINDOW (gtk_window) != window)
- {
- return;
- }
-
- slot = nautilus_window_get_active_slot (window);
- if (slot == NULL)
- {
- return;
- }
-
- view = nautilus_window_slot_get_current_view (slot);
- if (!NAUTILUS_IS_FILES_VIEW (view))
- {
- return;
- }
-
- selection = nautilus_window_slot_get_selection (slot);
- if (selection != NULL)
- {
- nautilus_files_view_preview_update (NAUTILUS_FILES_VIEW (view), selection);
- }
-}
-
static void
on_application_shutdown (GApplication *application,
gpointer user_data)
@@ -1549,13 +1509,6 @@ on_slot_removed (NautilusWindow *window,
g_signal_handlers_disconnect_by_func (slot, on_slot_location_changed, self);
}
-static void
-on_active_selection_changed (NautilusWindow *window,
- NautilusApplication *self)
-{
- update_previewer_selection (self, window);
-}
-
static void
nautilus_application_window_added (GtkApplication *app,
GtkWindow *window)
@@ -1571,7 +1524,6 @@ nautilus_application_window_added (GtkApplication *app,
priv->windows = g_list_prepend (priv->windows, window);
g_signal_connect (window, "slot-added", G_CALLBACK (on_slot_added), app);
g_signal_connect (window, "slot-removed", G_CALLBACK (on_slot_removed), app);
- g_signal_connect (window, "active-selection-changed", G_CALLBACK (on_active_selection_changed), app);
}
}
@@ -1591,7 +1543,6 @@ nautilus_application_window_removed (GtkApplication *app,
priv->windows = g_list_remove_all (priv->windows, window);
g_signal_handlers_disconnect_by_func (window, on_slot_added, app);
g_signal_handlers_disconnect_by_func (window, on_slot_removed, app);
- g_signal_handlers_disconnect_by_func (window, on_active_selection_changed, app);
}
/* if this was the last window, close the previewer */
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 378e6bdba..0109f447b 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1287,19 +1287,36 @@ nautilus_files_view_preview_files (NautilusFilesView *view,
nautilus_files_view_preview (view, data);
}
-void
-nautilus_files_view_preview_update (NautilusFilesView *view,
- GList *files)
+static void
+nautilus_files_view_preview_update (NautilusFilesView *view)
{
+ NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
+ GtkApplication *app;
+ GtkWindow *window;
+ g_autolist (NautilusFile) selection = NULL;
PreviewExportData *data;
- if (!nautilus_previewer_is_visible ())
+ if (!priv->active ||
+ !nautilus_previewer_is_visible ())
+ {
+ return;
+ }
+
+ app = GTK_APPLICATION (g_application_get_default ());
+ window = GTK_WINDOW (nautilus_files_view_get_window (view));
+ if (window == NULL || window != gtk_application_get_active_window (app))
+ {
+ return;
+ }
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ if (selection == NULL)
{
return;
}
data = g_new0 (PreviewExportData, 1);
- data->uri = nautilus_file_get_uri (files->data);
+ data->uri = nautilus_file_get_uri (selection->data);
data->is_update = TRUE;
nautilus_files_view_preview (view, data);
@@ -9829,6 +9846,10 @@ nautilus_files_view_init (NautilusFilesView *view)
"end-file-changes",
G_CALLBACK (on_end_file_changes),
view);
+ g_signal_connect (view,
+ "notify::selection",
+ G_CALLBACK (nautilus_files_view_preview_update),
+ view);
g_object_unref (builder);
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 152f25aa0..602cf8bec 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -269,8 +269,6 @@ void nautilus_files_view_activate_file (Nautil
void nautilus_files_view_preview_files (NautilusFilesView *view,
GList *files,
GArray *locations);
-void nautilus_files_view_preview_update (NautilusFilesView *view,
- GList *files);
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]