[gtk/matthiasc/for-master: 3/9] node-editor: Support pasting the image




commit 1e1f199b56e1d8b37cdde21c6fbcb4e902968d80
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Apr 2 21:24:59 2021 -0400

    node-editor: Support pasting the image
    
    Add a button that copies the image to the clipboard.

 demos/node-editor/node-editor-window.c  | 19 +++++++++++++++++++
 demos/node-editor/node-editor-window.ui |  6 ++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c
index 03da8c67bd..ce4198d683 100644
--- a/demos/node-editor/node-editor-window.c
+++ b/demos/node-editor/node-editor-window.c
@@ -635,6 +635,24 @@ export_image_cb (GtkWidget        *button,
   gtk_widget_show (dialog);
 }
 
+static void
+clip_image_cb (GtkWidget        *button,
+               NodeEditorWindow *self)
+{
+  GdkTexture *texture;
+  GdkClipboard *clipboard;
+
+  texture = create_texture (self);
+  if (texture == NULL)
+    return;
+
+  clipboard = gtk_widget_get_clipboard (GTK_WIDGET (self));
+
+  gdk_clipboard_set_texture (clipboard, texture);
+
+  g_object_unref (texture);
+}
+
 static void
 testcase_name_entry_changed_cb (GtkWidget        *button,
                                 GParamSpec       *pspec,
@@ -826,6 +844,7 @@ node_editor_window_class_init (NodeEditorWindowClass *class)
   gtk_widget_class_bind_template_callback (widget_class, open_cb);
   gtk_widget_class_bind_template_callback (widget_class, save_cb);
   gtk_widget_class_bind_template_callback (widget_class, export_image_cb);
+  gtk_widget_class_bind_template_callback (widget_class, clip_image_cb);
   gtk_widget_class_bind_template_callback (widget_class, testcase_save_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, testcase_name_entry_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, dark_mode_cb);
diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui
index 73b8b9ce4b..fc26719819 100644
--- a/demos/node-editor/node-editor-window.ui
+++ b/demos/node-editor/node-editor-window.ui
@@ -122,8 +122,10 @@
           </object>
         </child>
         <child type="start">
-          <object class="GtkSeparator">
-            <property name="orientation">vertical</property>
+          <object class="GtkButton">
+            <property name="icon-name">edit-copy-symbolic</property>
+            <property name="tooltip-text">Copy image to clipboard</property>
+            <signal name="clicked" handler="clip_image_cb"/>
           </object>
         </child>
         <child type="start">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]