From 054adec9bea2b1473badbfcbb2ad0c4616269759 Mon Sep 17 00:00:00 2001 From: bulia byak Date: Sun, 15 Jun 2008 16:22:56 +0000 Subject: new command: relink clone to copied object (bzr r5948) --- src/selection-chemistry.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 0f92f9680..d4964c284 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1864,6 +1864,56 @@ sp_selection_clone() g_slist_free(newsel); } +void +sp_selection_relink() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (!desktop) + return; + + Inkscape::Selection *selection = sp_desktop_selection(desktop); + + if (selection->isEmpty()) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select clones to relink.")); + return; + } + + Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + const gchar *newid = cm->getFirstObjectID(); + if (!newid) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Copy an object to clipboard to relink clones to.")); + return; + } + gchar *newref = g_strdup_printf ("#%s", newid); + + // Get a copy of current selection. + GSList *new_select = NULL; + bool relinked = false; + for (GSList *items = (GSList *) selection->itemList(); + items != NULL; + items = items->next) + { + SPItem *item = (SPItem *) items->data; + + if (!SP_IS_USE(item)) + continue; + + SP_OBJECT_REPR(item)->setAttribute("xlink:href", newref); + SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + relinked = true; + } + + g_free(newref); + + if (!relinked) { + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No clones to relink in the selection.")); + } else { + sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_UNLINK_CLONE, + _("Relink clone")); + } +} + + void sp_selection_unlink() { @@ -1874,7 +1924,7 @@ sp_selection_unlink() Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a clone to unlink.")); + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select clones to unlink.")); return; } -- cgit v1.2.3