summaryrefslogtreecommitdiffstats
path: root/src/file.cpp
diff options
context:
space:
mode:
authorDenis Declara <declara91@gmail.com>2012-04-15 12:29:45 +0000
committerDenis Declara <declara91@gmail.com>2012-04-15 12:29:45 +0000
commit6b5ff661a46ea1779c86f6947006c5ed32926117 (patch)
treea5b170f0830854e99ad065055ee2a3996933e614 /src/file.cpp
parentImproved User interface. (diff)
parenti18n. Fix for Bug #980518 (Please use c-format). (diff)
downloadinkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.tar.gz
inkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.zip
Trunk merge
(bzr r11073.1.15)
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp104
1 files changed, 100 insertions, 4 deletions
diff --git a/src/file.cpp b/src/file.cpp
index dbf8fc7d4..2ce532f03 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -36,6 +36,7 @@
#include "dir-util.h"
#include "document-private.h"
#include "document-undo.h"
+#include "event-context.h"
#include "extension/db.h"
#include "extension/input.h"
#include "extension/output.h"
@@ -642,6 +643,17 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
return FALSE;
}
+ if (SP_ACTIVE_DESKTOP) {
+ if (! SP_ACTIVE_DESKTOP->event_log) {
+ g_message("file_save: ->event_log == NULL. please report to bug #967416");
+ }
+ if (! SP_ACTIVE_DESKTOP->messageStack()) {
+ g_message("file_save: ->messageStack() == NULL. please report to bug #967416");
+ }
+ } else {
+ g_message("file_save: SP_ACTIVE_DESKTOP == NULL. please report to bug #967416");
+ }
+
SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Document saved."));
return true;
@@ -859,10 +871,11 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens
g_warning( "Error converting save filename to UTF-8." );
Inkscape::Extension::Output *omod = dynamic_cast<Inkscape::Extension::Output *>(selectionType);
- Glib::ustring save_extension = (std::string)omod->get_extension();
-
- if ( !hasEnding(fileName, save_extension.c_str()) ) {
- fileName += save_extension.c_str();
+ if (omod) {
+ Glib::ustring save_extension = (std::string)omod->get_extension();
+ if ( !hasEnding(fileName, save_extension.c_str()) ) {
+ fileName += save_extension.c_str();
+ }
}
// FIXME: does the argument !is_copy really convey the correct meaning here?
@@ -974,6 +987,89 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d
######################*/
/**
+ * Paste the contents of a document into the active desktop.
+ * @param clipdoc The document to paste
+ * @param in_place Whether to paste the selection where it was when copied
+ * @pre @c clipdoc is not empty and items can be added to the current layer
+ */
+void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
+{
+ //TODO: merge with file_import()
+
+ SPDocument *target_document = sp_desktop_document(desktop);
+ Inkscape::XML::Node *root = clipdoc->getReprRoot();
+ Inkscape::XML::Node *target_parent = desktop->currentLayer()->getRepr();
+
+ // copy definitions
+ desktop->doc()->importDefs(clipdoc);
+
+ // copy objects
+ GSList *pasted_objects = NULL;
+ for (Inkscape::XML::Node *obj = root->firstChild() ; obj ; obj = obj->next()) {
+ // Don't copy metadata, defs, named views and internal clipboard contents to the document
+ if (!strcmp(obj->name(), "svg:defs")) {
+ continue;
+ }
+ if (!strcmp(obj->name(), "svg:metadata")) {
+ continue;
+ }
+ if (!strcmp(obj->name(), "sodipodi:namedview")) {
+ continue;
+ }
+ if (!strcmp(obj->name(), "inkscape:clipboard")) {
+ continue;
+ }
+ Inkscape::XML::Node *obj_copy = obj->duplicate(target_document->getReprDoc());
+ target_parent->appendChild(obj_copy);
+ Inkscape::GC::release(obj_copy);
+
+ pasted_objects = g_slist_prepend(pasted_objects, (gpointer) obj_copy);
+ }
+
+ // Change the selection to the freshly pasted objects
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+ selection->setReprList(pasted_objects);
+
+ // invers apply parent transform
+ Geom::Affine doc2parent = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
+ sp_selection_apply_affine(selection, desktop->dt2doc() * doc2parent * desktop->doc2dt(), true, false);
+
+ // Update (among other things) all curves in paths, for bounds() to work
+ target_document->ensureUpToDate();
+
+ // move selection either to original position (in_place) or to mouse pointer
+ Geom::OptRect sel_bbox = selection->visualBounds();
+ if (sel_bbox) {
+ // get offset of selection to original position of copied elements
+ Geom::Point pos_original;
+ Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
+ if (clipnode) {
+ Geom::Point min, max;
+ sp_repr_get_point(clipnode, "min", &min);
+ sp_repr_get_point(clipnode, "max", &max);
+ pos_original = Geom::Point(min[Geom::X], max[Geom::Y]);
+ }
+ Geom::Point offset = pos_original - sel_bbox->corner(3);
+
+ if (!in_place) {
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop);
+ sp_event_context_discard_delayed_snap_event(desktop->event_context);
+
+ // get offset from mouse pointer to bbox center, snap to grid if enabled
+ Geom::Point mouse_offset = desktop->point() - sel_bbox->midpoint();
+ offset = m.multipleOfGridPitch(mouse_offset - offset, sel_bbox->midpoint() + offset) + offset;
+ m.unSetup();
+ }
+
+ sp_selection_move_relative(selection, offset);
+ }
+
+ g_slist_free(pasted_objects);
+}
+
+
+/**
* Import a resource. Called by sp_file_import()
*/
SPObject *