[dia] [embedded image] Allow paste w/o matching selection



commit dd6eab19c2ca044e763e87cdd5ea863360929870
Author: Hans Breuer <hans breuer org>
Date:   Sun Feb 20 15:37:14 2011 +0100

    [embedded image] Allow paste w/o matching selection
    
    Previously an image (an object responding to dia_object_set_pixbuf())
    needed to be selected to make paste work. Now pasting into the
    selection is still preferred but a new image is created as last
    resort. Paste Image is bound to <control><alt>V

 app/commands.c |   33 +++++++++++++++++++++++++++++++--
 app/menus.c    |    2 +-
 2 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index 327b4aa..f4ee22d 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -260,8 +260,37 @@ received_clipboard_image_handler(GtkClipboard *clipboard,
     list = g_list_next (list);
   }
 
-  if (!change)
-    message_warning (_("No selected object can take an image."));
+  if (!change) {
+    gint x, y;
+    Point pt;
+    DiaObjectType *type;
+    Handle *handle1;
+    Handle *handle2;
+    DiaObject *obj;
+
+    gdk_window_get_pointer (gtk_widget_get_window (ddisp->canvas),
+			    &x, &y, NULL);
+    ddisplay_untransform_coords (ddisp, x, y, &pt.x, &pt.y);
+
+    snap_to_grid(ddisp, &pt.x, &pt.y);
+
+    if (   ((type = object_get_type ("Standard - Image")) != NULL)
+        && ((obj = dia_object_default_create (type, &pt, 
+					     type->default_user_data,
+					     &handle1, &handle2)) != NULL)) {
+      /* as above, transfer the data */
+      change = dia_object_set_pixbuf (obj, pixbuf);
+      if (change) /* ... but drop undo info */
+	change->free (change);
+      diagram_add_object (dia, obj);
+      diagram_select(dia, obj);
+      object_add_updates(obj, dia);
+      ddisplay_do_update_menu_sensitivity(ddisp);
+      diagram_flush(dia);
+    } else {
+      message_warning (_("No selected object can take an image."));
+    }
+  }
 }
 
 void
diff --git a/app/menus.c b/app/menus.c
index d38ff98..e566a19 100644
--- a/app/menus.c
+++ b/app/menus.c
@@ -133,7 +133,7 @@ static const GtkActionEntry display_entries[] =
     { "EditCuttext", NULL, N_("Cut Text"), "<control><shift>X", NULL, G_CALLBACK (edit_cut_text_callback) },
     { "EditPastetext", NULL, N_("Paste _Text"), "<control><shift>V", NULL, G_CALLBACK (edit_paste_text_callback) } ,
 
-    { "EditPasteImage", NULL, N_("Paste _Image"), NULL, NULL, G_CALLBACK (edit_paste_image_callback) },
+    { "EditPasteImage", NULL, N_("Paste _Image"), "<control><alt>V", NULL, G_CALLBACK (edit_paste_image_callback) },
 
   { "Layers", NULL, N_("_Layers"), NULL, NULL, NULL }, 
     { "LayerAdd", DIA_STOCK_LAYER_ADD, N_("Add Layerâ?¦"), NULL, NULL, G_CALLBACK (layers_add_layer_callback) },



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