From ea3c58f0ec9610d4af87261926373ddc6b3ee5ed Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 17 Nov 2022 06:29:17 -0500 Subject: [PATCH] gtk-demo: Add folders to the clipboard demo This is handy for testing a case where folder dnd does not work with the file transfer portal. See #5348 --- demos/gtk-demo/clipboard.c | 33 +++++++++++++++++++++++++++++++++ demos/gtk-demo/clipboard.ui | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c index 80825ce982..fd103a676c 100644 --- a/demos/gtk-demo/clipboard.c +++ b/demos/gtk-demo/clipboard.c @@ -248,6 +248,38 @@ open_file_cb (GtkWidget *button) file_chooser_response, button); } +static void +folder_chooser_response (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GtkFileDialog *dialog = GTK_FILE_DIALOG (source); + GtkButton *button = GTK_BUTTON (user_data); + GFile *file; + + file = gtk_file_dialog_select_folder_finish (dialog, result, NULL); + if (file) + { + file_button_set_file (button, file); + g_object_unref (file); + + update_copy_button_sensitivity (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK)); + } +} + +static void +open_folder_cb (GtkWidget *button) +{ + GtkFileDialog *dialog; + + dialog = gtk_file_dialog_new (); + + gtk_file_dialog_select_folder (dialog, + GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)), + NULL, + NULL, + folder_chooser_response, button); +} static void update_paste_button_sensitivity (GdkClipboard *clipboard, GtkWidget *paste_button) @@ -346,6 +378,7 @@ do_clipboard (GtkWidget *do_widget) gtk_builder_cscope_add_callback (scope, source_changed_cb); gtk_builder_cscope_add_callback (scope, text_changed_cb); gtk_builder_cscope_add_callback (scope, open_file_cb); + gtk_builder_cscope_add_callback (scope, open_folder_cb); gtk_builder_cscope_add_callback (scope, on_drop); gtk_builder_cscope_add_callback (scope, drag_prepare); builder = gtk_builder_new (); diff --git a/demos/gtk-demo/clipboard.ui b/demos/gtk-demo/clipboard.ui index 6cc7ed4324..a373537f6b 100644 --- a/demos/gtk-demo/clipboard.ui +++ b/demos/gtk-demo/clipboard.ui @@ -32,6 +32,7 @@ Color Image File + Folder @@ -166,6 +167,30 @@ + + + Folder + + + + + capture + + + + center + + + + 0 + start + + + + + + +