[nautilus/wip/antoniof/gtk4-restore-clipboard: 6/6] list-view: Reenable clipboard monitoring for cut highlighting
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-restore-clipboard: 6/6] list-view: Reenable clipboard monitoring for cut highlighting
- Date: Wed, 5 Jan 2022 00:41:59 +0000 (UTC)
commit 93381f1e64f264e3dc90af8b8a8daa06f2d2162f
Author: António Fernandes <antoniof gnome org>
Date: Tue Jan 4 21:08:26 2022 +0000
list-view: Reenable clipboard monitoring for cut highlighting
src/nautilus-clipboard.c | 12 ++++++++
src/nautilus-clipboard.h | 1 +
src/nautilus-list-view.c | 77 +++++++++++++++---------------------------------
3 files changed, 37 insertions(+), 53 deletions(-)
---
diff --git a/src/nautilus-clipboard.c b/src/nautilus-clipboard.c
index 63183641d..9c8ec4d48 100644
--- a/src/nautilus-clipboard.c
+++ b/src/nautilus-clipboard.c
@@ -221,6 +221,18 @@ nautilus_clipboard_deserialize (GdkContentDeserializer *deserializer)
deserializer);
}
+/**
+ * nautilus_clipboard_peek_files:
+ * @clip: The current local clipboard value.
+ *
+ * Returns: (transfer none): The internal GList of GFile objects.
+ */
+GList *
+nautilus_clipboard_peek_files (NautilusClipboard *clip)
+{
+ return clip->files;
+}
+
/**
* nautilus_clipboard_get_uri_list:
* @clip: The current local clipboard value.
diff --git a/src/nautilus-clipboard.h b/src/nautilus-clipboard.h
index 137a14e69..5ac1522ae 100644
--- a/src/nautilus-clipboard.h
+++ b/src/nautilus-clipboard.h
@@ -32,6 +32,7 @@ GType nautilus_clipboard_get_type (void);
void nautilus_clipboard_clear_if_colliding_uris (GtkWidget *widget,
const GList *item_uris);
#endif
+GList *nautilus_clipboard_peek_files (NautilusClipboard *clip);
GList *nautilus_clipboard_get_uri_list (NautilusClipboard *clip);
gboolean nautilus_clipboard_is_cut (NautilusClipboard *clip);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index aaf6fce91..bd879b073 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -96,11 +96,8 @@ static char **get_visible_columns (NautilusListView *list_view);
static char **get_default_visible_columns (NautilusListView *list_view);
static char **get_column_order (NautilusListView *list_view);
static char **get_default_column_order (NautilusListView *list_view);
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
-static void on_clipboard_owner_changed (GtkClipboard *clipboard,
- GdkEvent *event,
+static void on_clipboard_owner_changed (GdkClipboard *clipboard,
gpointer user_data);
-#endif
static void popup_column_header_menu (NautilusListView *list_view,
gdouble x,
gdouble y);
@@ -3531,9 +3528,7 @@ static void
nautilus_list_view_dispose (GObject *object)
{
NautilusListView *list_view;
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
- GtkClipboard *clipboard;
-#endif
+ GdkClipboard *clipboard;
list_view = NAUTILUS_LIST_VIEW (object);
@@ -3551,10 +3546,8 @@ nautilus_list_view_dispose (GObject *object)
}
#endif
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
g_signal_handlers_disconnect_by_func (clipboard, on_clipboard_owner_changed, list_view);
-#endif
g_signal_handlers_disconnect_by_func (nautilus_preferences,
default_sort_order_changed_callback,
list_view);
@@ -3695,67 +3688,49 @@ list_view_scroll_to_file (NautilusFilesView *view,
}
}
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
static void
-on_clipboard_contents_received (GtkClipboard *clipboard,
- GtkSelectionData *selection_data,
- gpointer user_data)
+on_clipboard_contents_received (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusListView *view = NAUTILUS_LIST_VIEW (user_data);
-
- if (!view->details->model)
- {
- /* We've been destroyed since call */
- g_object_unref (view);
- return;
- }
+ NautilusFilesView *files_view = NAUTILUS_FILES_VIEW (source_object);
+ NautilusListViewDetails *details = NAUTILUS_LIST_VIEW (files_view)->details;
+ NautilusClipboard *clip;
- if (nautilus_clipboard_is_cut_from_selection_data (selection_data))
+ clip = nautilus_files_view_get_clipboard_finish (files_view, res, NULL);
+ if (clip != NULL && nautilus_clipboard_is_cut (clip))
{
- GList *uris;
GList *files;
- uris = nautilus_clipboard_get_uri_list_from_selection_data (selection_data);
- files = nautilus_file_list_from_uri_list (uris);
- nautilus_list_model_set_highlight_for_files (view->details->model, files);
-
- nautilus_file_list_free (files);
- g_list_free_full (uris, g_free);
+ files = nautilus_clipboard_peek_files (clip);
+ nautilus_list_model_set_highlight_for_files (details->model, files);
}
else
{
- nautilus_list_model_set_highlight_for_files (view->details->model, NULL);
+ nautilus_list_model_set_highlight_for_files (details->model, NULL);
}
-
- g_object_unref (view);
}
static void
-update_clipboard_status (NautilusListView *view)
+update_clipboard_status (NautilusFilesView *view)
{
- g_object_ref (view); /* Need to keep the object alive until we get the reply */
- gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (view)),
- nautilus_clipboard_get_atom (),
- on_clipboard_contents_received,
- view);
+ nautilus_files_view_get_clipboard_async (view,
+ on_clipboard_contents_received,
+ NULL);
}
static void
-on_clipboard_owner_changed (GtkClipboard *clipboard,
- GdkEvent *event,
+on_clipboard_owner_changed (GdkClipboard *clipboard,
gpointer user_data)
{
- update_clipboard_status (NAUTILUS_LIST_VIEW (user_data));
+ update_clipboard_status (NAUTILUS_FILES_VIEW (user_data));
}
-#endif
static void
nautilus_list_view_end_loading (NautilusFilesView *view,
gboolean all_files_seen)
{
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
- update_clipboard_status (NAUTILUS_LIST_VIEW (view));
-#endif
+ update_clipboard_status (NAUTILUS_FILES_VIEW (view));
}
static guint
@@ -3978,9 +3953,7 @@ static void
nautilus_list_view_init (NautilusListView *list_view)
{
GActionGroup *view_action_group;
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
- GtkClipboard *clipboard;
-#endif
+ GdkClipboard *clipboard;
list_view->details = g_new0 (NautilusListViewDetails, 1);
@@ -4022,12 +3995,10 @@ nautilus_list_view_init (NautilusListView *list_view)
G_CALLBACK (default_column_order_changed_callback),
list_view);
-#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
/* React to clipboard changes */
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- g_signal_connect (clipboard, "owner-change",
+ clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
+ g_signal_connect (clipboard, "changed",
G_CALLBACK (on_clipboard_owner_changed), list_view);
-#endif
nautilus_list_view_click_policy_changed (NAUTILUS_FILES_VIEW (list_view));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]