filechooserwidget: Port to new clipboard

We use the new GDK_TYPE_FILE_LIST here.
This commit is contained in:
Benjamin Otte 2017-11-29 09:52:38 +01:00
parent 6b326b14c0
commit ca96fac488

View File

@ -28,7 +28,6 @@
#include "gtkcellrendererpixbuf.h" #include "gtkcellrendererpixbuf.h"
#include "gtkcellrenderertext.h" #include "gtkcellrenderertext.h"
#include "gtkcheckmenuitem.h" #include "gtkcheckmenuitem.h"
#include "gtkclipboard.h"
#include "gtkcomboboxtext.h" #include "gtkcomboboxtext.h"
#include "gtkcssnumbervalueprivate.h" #include "gtkcssnumbervalueprivate.h"
#include "gtkdragsource.h" #include "gtkdragsource.h"
@ -1655,61 +1654,6 @@ rename_file_cb (GSimpleAction *action,
gtk_tree_selection_selected_foreach (selection, rename_selected_cb, impl); gtk_tree_selection_selected_foreach (selection, rename_selected_cb, impl);
} }
/* callback used to set data to clipboard */
static void
copy_file_get_cb (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer data)
{
GSList *selected_files = data;
if (selected_files)
{
gint num_files = g_slist_length (selected_files);
gchar **uris;
gint i;
GSList *l;
uris = g_new (gchar *, num_files + 1);
uris[num_files] = NULL; /* null terminator */
i = 0;
for (l = selected_files; l; l = l->next)
{
GFile *file = (GFile *) l->data;
if (gtk_selection_data_targets_include_uri (selection_data))
uris[i] = g_file_get_uri (file);
else /* if (info == SELECTION_TEXT) - let this be the fallback */
uris[i] = g_file_get_parse_name (file);
i++;
}
if (gtk_selection_data_targets_include_uri (selection_data))
gtk_selection_data_set_uris (selection_data, uris);
else /* if (info == SELECTION_TEXT) - let this be the fallback */
{
char *str = g_strjoinv (" ", uris);
gtk_selection_data_set_text (selection_data, str, -1);
g_free (str);
}
g_strfreev (uris);
}
}
/* callback used to clear the clipboard data */
static void
copy_file_clear_cb (GtkClipboard *clipboard,
gpointer data)
{
GSList *selected_files = data;
g_slist_free_full (selected_files, g_object_unref);
}
/* Callback used when the "Copy files location" menu item is activated */ /* Callback used when the "Copy files location" menu item is activated */
static void static void
copy_file_location_cb (GSimpleAction *action, copy_file_location_cb (GSimpleAction *action,
@ -1723,21 +1667,20 @@ copy_file_location_cb (GSimpleAction *action,
if (selected_files) if (selected_files)
{ {
GtkClipboard *clipboard; GdkClipboard *clipboard;
GdkContentFormats *target_list; GdkContentProvider *provider;
GValue value = G_VALUE_INIT;
clipboard = gtk_widget_get_old_clipboard (GTK_WIDGET (impl), GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl));
target_list = gdk_content_formats_new (NULL, 0); g_value_init (&value, GDK_TYPE_FILE_LIST);
target_list = gtk_content_formats_add_text_targets (target_list); g_value_take_boxed (&value, selected_files);
target_list = gtk_content_formats_add_uri_targets (target_list);
gtk_clipboard_set_with_data (clipboard, target_list, provider = gdk_content_provider_new_for_value (&value);
copy_file_get_cb, g_value_unset (&value);
copy_file_clear_cb,
selected_files);
gdk_content_formats_unref (target_list); gdk_clipboard_set_content (clipboard, provider);
g_object_unref (provider);
} }
} }
@ -6687,12 +6630,15 @@ out:
} }
static void static void
paste_text_received (GtkClipboard *clipboard, paste_text_received (GObject *source,
const gchar *text, GAsyncResult *result,
GtkFileChooserWidget *impl) gpointer data)
{ {
GtkFileChooserWidget *impl = data;
GFile *file; GFile *file;
char *text;
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (source), result, NULL);
if (!text) if (!text)
return; return;
@ -6702,17 +6648,19 @@ paste_text_received (GtkClipboard *clipboard,
location_popup_handler (impl, text); location_popup_handler (impl, text);
g_object_unref (file); g_object_unref (file);
g_free (text);
} }
/* Handler for the "location-popup-on-paste" keybinding signal */ /* Handler for the "location-popup-on-paste" keybinding signal */
static void static void
location_popup_on_paste_handler (GtkFileChooserWidget *impl) location_popup_on_paste_handler (GtkFileChooserWidget *impl)
{ {
GtkClipboard *clipboard = gtk_widget_get_old_clipboard (GTK_WIDGET (impl), GdkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl));
GDK_SELECTION_CLIPBOARD);
gtk_clipboard_request_text (clipboard, gdk_clipboard_read_text_async (clipboard,
(GtkClipboardTextReceivedFunc) paste_text_received, NULL,
impl); paste_text_received,
impl);
} }
/* Implementation for GtkFileChooserEmbed::should_respond() */ /* Implementation for GtkFileChooserEmbed::should_respond() */