diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2012-01-15 11:26:04 +0000 |
|---|---|---|
| committer | Johan Engelen <goejendaagh@zonnet.nl> | 2012-01-15 11:26:04 +0000 |
| commit | bbe40ef819359465fabfa938c86a7faba7357473 (patch) | |
| tree | 530b2435e33ade395b2248562cc13ae0cb768a1a /src | |
| parent | ege-appear-time-tracker GSEAL (diff) | |
| download | inkscape-bbe40ef819359465fabfa938c86a7faba7357473.tar.gz inkscape-bbe40ef819359465fabfa938c86a7faba7357473.zip | |
add a menu item for using the Clone original LPE efficiently.
(bzr r10889)
Diffstat (limited to 'src')
| -rw-r--r-- | src/menus-skeleton.h | 1 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 57 | ||||
| -rw-r--r-- | src/selection-chemistry.h | 1 | ||||
| -rw-r--r-- | src/verbs.cpp | 5 | ||||
| -rw-r--r-- | src/verbs.h | 1 |
5 files changed, 65 insertions, 0 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index dccd17c59..405385781 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -72,6 +72,7 @@ static char const menus_skeleton[] = " <verb verb-id=\"EditUnlinkClone\" />\n" " <verb verb-id=\"EditRelinkClone\" />\n" " <verb verb-id=\"EditCloneSelectOriginal\" />\n" +" <verb verb-id=\"EditCloneOriginalPathLPE\" />\n" " </submenu>\n" " <verb verb-id=\"SelectionCreateBitmap\" />\n" " <separator/>\n" diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f7160cea8..97bc5a39f 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2271,6 +2271,63 @@ sp_select_clone_original(SPDesktop *desktop) } } +/** +* This creates a new path, applies the Original Path LPE, and has it refer to the selection. +*/ +void sp_selection_clone_original_path_lpe(SPDesktop *desktop) +{ + if (desktop == NULL) { + return; + } + + Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPItem *item = selection->singleItem(); + if (g_slist_length((GSList *) selection->itemList()) != 1 || !item) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one</b> path to clone.")); + return; + } + if ( !(SP_IS_SHAPE(item) || SP_IS_TEXT(item)) ) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one <b>path</b> to clone.")); + return; + } + + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *parent = item->getRepr()->parent(); + + // create the LPE + Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); + { + lpe_repr->setAttribute("effect", "clone_original"); + gchar *href = g_strdup_printf("#%s", item->getRepr()->attribute("id")); + lpe_repr->setAttribute("linkedpath", href); + g_free(href); + desktop->doc()->getDefs()->getRepr()->addChild(lpe_repr, NULL); // adds to <defs> and assigns the 'id' attribute + } + const gchar * lpe_id = lpe_repr->attribute("id"); + Inkscape::GC::release(lpe_repr); + + // create the new path + Inkscape::XML::Node *clone = xml_doc->createElement("svg:path"); + { + clone->setAttribute("d", "M 0 0", false); + // add the new clone to the top of the original's parent + parent->appendChild(clone); + SPObject *clone_obj = desktop->doc()->getObjectById(clone->attribute("id")); + if (SP_IS_LPE_ITEM(clone_obj)) { + gchar *href = g_strdup_printf("#%s", lpe_id); + sp_lpe_item_add_path_effect( SP_LPE_ITEM(clone_obj), href, false ); + g_free(href); + } + } + + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, + _("Clone original path")); + + // select the new object: + selection->set(clone); + + Inkscape::GC::release(clone); +} void sp_selection_to_marker(SPDesktop *desktop, bool apply) { diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 1c193fc93..1b09d98c9 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -57,6 +57,7 @@ void sp_selection_clone(SPDesktop *desktop); void sp_selection_unlink(SPDesktop *desktop); void sp_selection_relink(SPDesktop *desktop); void sp_select_clone_original(SPDesktop *desktop); +void sp_selection_clone_original_path_lpe(SPDesktop *desktop); void sp_selection_to_marker(SPDesktop *desktop, bool apply = true); void sp_selection_to_guides(SPDesktop *desktop); diff --git a/src/verbs.cpp b/src/verbs.cpp index c3a2f0897..39ecd957e 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -939,6 +939,9 @@ void EditVerb::perform(SPAction *action, void *data) case SP_VERB_EDIT_CLONE_SELECT_ORIGINAL: sp_select_clone_original(dt); break; + case SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE: + sp_selection_clone_original_path_lpe(dt); + break; case SP_VERB_EDIT_SELECTION_2_MARKER: sp_selection_to_marker(dt); break; @@ -2248,6 +2251,8 @@ Verb *Verb::_base_verbs[] = { N_("Relink the selected clones to the object currently on the clipboard"), NULL), new EditVerb(SP_VERB_EDIT_CLONE_SELECT_ORIGINAL, "EditCloneSelectOriginal", N_("Select _Original"), N_("Select the object to which the selected clone is linked"), INKSCAPE_ICON("edit-select-original")), + new EditVerb(SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, "EditCloneOriginalPathLPE", N_("Clone original path (LPE)"), + N_("Creates a new path, applies the Clone original LPE, and refers it to the selected path"), NULL), new EditVerb(SP_VERB_EDIT_SELECTION_2_MARKER, "ObjectsToMarker", N_("Objects to _Marker"), N_("Convert selection to a line marker"), NULL), new EditVerb(SP_VERB_EDIT_SELECTION_2_GUIDES, "ObjectsToGuides", N_("Objects to Gu_ides"), diff --git a/src/verbs.h b/src/verbs.h index d2b0acd41..79390941d 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -80,6 +80,7 @@ enum { SP_VERB_EDIT_UNLINK_CLONE, SP_VERB_EDIT_RELINK_CLONE, SP_VERB_EDIT_CLONE_SELECT_ORIGINAL, + SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, SP_VERB_EDIT_SELECTION_2_MARKER, SP_VERB_EDIT_SELECTION_2_GUIDES, SP_VERB_EDIT_TILE, |
