From c461ebb1e4f05f3278adb57f154ad505e3d025e2 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Sat, 10 Sep 2022 17:45:02 -0400 Subject: [PATCH] Refactor verbatim copy style into separate actions After discussing the recently merged feature to allow copying and pasting the verbatim class and style attributes, rather than the default behavior of copying and pasting the computed style, it was decided that we prefer to have both options available as separate actions. Accordingly, split the existing "paste style" into "paste computed style" and "paste verbatim style", adjusting the guts as needed. Note that this adds an "inkscape:computed-style" attribute to our "additional information" node when copying to the clipboard, which contains the computed style. This information was previously saved in the "style" attribute, which now contains a verbatim copy of the "style" attribute of the source object instead. This may result in unexpected behavior if users are somehow copying and pasting between different versions of Inkscape. --- share/keys/carbon.xml | 2 +- share/keys/inkscape.xml | 2 +- share/keys/right-handed-illustration.xml | 2 +- share/keys/xara.xml | 2 +- share/ui/menus.ui | 7 +++- src/actions/actions-edit.cpp | 19 ++++++++--- src/object/object-set.h | 2 +- src/selection-chemistry.cpp | 4 +-- src/ui/clipboard.cpp | 43 ++++++++++-------------- src/ui/clipboard.h | 2 +- src/ui/dialog/inkscape-preferences.cpp | 15 --------- src/ui/dialog/inkscape-preferences.h | 5 --- src/widgets/mappings.xml | 3 +- 13 files changed, 49 insertions(+), 59 deletions(-) diff --git a/share/keys/carbon.xml b/share/keys/carbon.xml index 6cce735b81..2128f3555f 100644 --- a/share/keys/carbon.xml +++ b/share/keys/carbon.xml @@ -98,7 +98,7 @@ See "inkscape.xml" for information about file structure. - + diff --git a/share/keys/inkscape.xml b/share/keys/inkscape.xml index 38ef269632..ef57bae5b3 100644 --- a/share/keys/inkscape.xml +++ b/share/keys/inkscape.xml @@ -138,7 +138,7 @@ override) the bindings in the main default.xml. - + diff --git a/share/keys/right-handed-illustration.xml b/share/keys/right-handed-illustration.xml index 63e56cfdf6..8d0923f46d 100644 --- a/share/keys/right-handed-illustration.xml +++ b/share/keys/right-handed-illustration.xml @@ -122,7 +122,7 @@ Future improvements: - + diff --git a/share/keys/xara.xml b/share/keys/xara.xml index a0826ab6e2..cde7ba9a78 100644 --- a/share/keys/xara.xml +++ b/share/keys/xara.xml @@ -133,7 +133,7 @@ Hom/end keys-select minimum or maximum feather values - + diff --git a/share/ui/menus.ui b/share/ui/menus.ui index 74c05df7b5..5e4b67b248 100644 --- a/share/ui/menus.ui +++ b/share/ui/menus.ui @@ -156,7 +156,12 @@ _Style - app.paste-style + app.paste-style-computed + edit-paste-style + + + _Style + app.paste-style-verbatim edit-paste-style diff --git a/src/actions/actions-edit.cpp b/src/actions/actions-edit.cpp index cb273d6e32..6d4e77dad8 100644 --- a/src/actions/actions-edit.cpp +++ b/src/actions/actions-edit.cpp @@ -81,12 +81,21 @@ copy(InkscapeApplication *app) } void -paste_style(InkscapeApplication *app) +paste_style_computed(InkscapeApplication *app) { auto selection = app->get_active_selection(); // Paste Style - selection->pasteStyle(); + selection->pasteStyle(true); +} + +void +paste_style_verbatim(InkscapeApplication *app) +{ + auto selection = app->get_active_selection(); + + // Paste Style + selection->pasteStyle(false); } void @@ -290,7 +299,8 @@ std::vector> raw_data_edit = { {"app.object-to-guides", N_("Objects to Guides"), "Edit", N_("Convert selected objects to a collection of guidelines aligned with their edges")}, {"app.cut", N_("Cut"), "Edit", N_("Cut selection to clipboard")}, {"app.copy", N_("Copy"), "Edit", N_("Copy selection to clipboard")}, - {"app.paste-style", N_("Paste Style"), "Edit", N_("Apply the style of the copied object to selection")}, + {"app.paste-style-computed", N_("Paste Computed Style"), "Edit", N_("Apply the computed style of the copied object to selection")}, + {"app.paste-style-verbatim", N_("Paste Verbatim Style"), "Edit", N_("Apply the verbatim style and class of the copied object to selection")}, {"app.paste-size", N_("Paste Size"), "Edit", N_("Scale selection to match the size of the copied object")}, {"app.paste-width", N_("Paste Width"), "Edit", N_("Scale selection horizontally to match the width of the copied object")}, {"app.paste-height", N_("Paste Height"), "Edit", N_("Scale selection vertically to match the height of the copied object")}, @@ -330,7 +340,8 @@ add_actions_edit(InkscapeApplication* app) gapp->add_action( "object-to-guides", sigc::bind(sigc::ptr_fun(&object_to_guides), app)); gapp->add_action( "cut", sigc::bind(sigc::ptr_fun(&cut), app)); gapp->add_action( "copy", sigc::bind(sigc::ptr_fun(©), app)); - gapp->add_action( "paste-style", sigc::bind(sigc::ptr_fun(&paste_style), app)); + gapp->add_action( "paste-style-computed", sigc::bind(sigc::ptr_fun(&paste_style_computed), app)); + gapp->add_action( "paste-style-verbatim", sigc::bind(sigc::ptr_fun(&paste_style_verbatim), app)); gapp->add_action( "paste-size", sigc::bind(sigc::ptr_fun(&paste_size), app)); gapp->add_action( "paste-width", sigc::bind(sigc::ptr_fun(&paste_width), app)); gapp->add_action( "paste-height", sigc::bind(sigc::ptr_fun(&paste_height), app)); diff --git a/src/object/object-set.h b/src/object/object-set.h index e761ce6755..ff3f13a96f 100644 --- a/src/object/object-set.h +++ b/src/object/object-set.h @@ -447,7 +447,7 @@ public: //in selection-chemistry.cpp void copy(); void cut(); - void pasteStyle(); + void pasteStyle(bool use_computed); void pasteSize(bool apply_x, bool apply_y); void pasteSizeSeparately(bool apply_x, bool apply_y); void pastePathEffect(); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 79532a443a..afbaf89ece 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1328,10 +1328,10 @@ void sp_selection_paste(SPDesktop *desktop, bool in_place, bool on_page) } } -void ObjectSet::pasteStyle() +void ObjectSet::pasteStyle(bool use_computed) { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); - if (cm->pasteStyle(this)) { + if (cm->pasteStyle(this, use_computed)) { DocumentUndo::done(document(), _("Paste style"), INKSCAPE_ICON("edit-paste-style")); } } diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 89af358ff0..57eb87b7df 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -27,7 +27,7 @@ // TODO: reduce header bloat if possible #include "context-fns.h" -#include "desktop-style.h" // for sp_desktop_set_style, used in _pasteStyle +#include "desktop-style.h" // for sp_desktop_set_style, used in pasteStyle #include "desktop.h" #include "display/curve.h" #include "document.h" @@ -109,7 +109,7 @@ public: void copySymbol(Inkscape::XML::Node* symbol, gchar const* style, SPDocument *source, Geom::Rect const &bbox) override; void insertSymbol(SPDesktop *desktop, Geom::Point const &shift_dt) override; bool paste(SPDesktop *desktop, bool in_place, bool on_page) override; - bool pasteStyle(ObjectSet *set) override; + bool pasteStyle(ObjectSet *set, bool use_computed) override; bool pasteSize(ObjectSet *set, bool separately, bool apply_x, bool apply_y) override; bool pastePathEffect(ObjectSet *set) override; Glib::ustring getPathParameter(SPDesktop* desktop) override; @@ -700,9 +700,9 @@ void ClipboardManagerImpl::_cleanStyle(SPCSSAttr *style) } /** - * Implements the Paste Style action. + * Implements the Paste {Computed,Verbatim} Style actions. */ -bool ClipboardManagerImpl::pasteStyle(ObjectSet *set) +bool ClipboardManagerImpl::pasteStyle(ObjectSet *set, bool use_computed) { if (set->desktop() == nullptr) { return false; @@ -717,7 +717,7 @@ bool ClipboardManagerImpl::pasteStyle(ObjectSet *set) auto tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == nullptr ) { // no document, but we can try _text_style - if (_text_style) { + if (_text_style && use_computed) { _cleanStyle(_text_style); sp_desktop_set_style(set, set->desktop(), _text_style); return true; @@ -727,17 +727,17 @@ bool ClipboardManagerImpl::pasteStyle(ObjectSet *set) } } - static auto *const prefs = Inkscape::Preferences::get(); - auto const copy_computed = prefs->getBool("/options/copycomputedstyle/value", true); - Inkscape::XML::Node *root = tempdoc->getReprRoot(); Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1); bool pasted = false; if (clipnode) { - if (copy_computed) { - SPCSSAttr *style = sp_repr_css_attr(clipnode, "style"); + if (use_computed) { + SPCSSAttr *style = sp_repr_css_attr(clipnode, "inkscape:computed-style"); + if (!style) { + style = sp_repr_css_attr(clipnode, "style"); + } sp_desktop_set_style(set, set->desktop(), style); } else { for (auto node : set->xmlNodes()) { @@ -998,8 +998,6 @@ std::vector ClipboardManagerImpl::getElementsOfType(SPDesktop *de */ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) { - static auto *const prefs = Inkscape::Preferences::get(); - auto const copy_computed = prefs->getBool("/options/copycomputedstyle/value", true); SPPage *page = nullptr; // copy the defs used by all items @@ -1082,23 +1080,18 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) else obj_copy = _copyNode(obj, _doc, _clipnode); - if (copy_computed) { - // copy complete inherited style - _copyCompleteStyle(item, obj_copy); - } + // copy complete inherited style + _copyCompleteStyle(item, obj_copy); } } // copy style for Paste Style action if (auto item = selection->singleItem()) { - if (copy_computed) { - SPCSSAttr *style = take_style_from_item(item); - _cleanStyle(style); - sp_repr_css_set(_clipnode, style, "style"); - sp_repr_css_attr_unref(style); - } else { - _clipnode->copyAttribute("class", item->getRepr(), true); - _clipnode->copyAttribute("style", item->getRepr(), true); - } + SPCSSAttr *style = take_style_from_item(item); + _cleanStyle(style); + sp_repr_css_set(_clipnode, style, "inkscape:computed-style"); + sp_repr_css_attr_unref(style); + _clipnode->copyAttribute("class", item->getRepr(), true); + _clipnode->copyAttribute("style", item->getRepr(), true); // copy path effect from the first path if (gchar const *effect = item->getRepr()->attribute("inkscape:path-effect")) { diff --git a/src/ui/clipboard.h b/src/ui/clipboard.h index b2537ed5aa..ba4bbbd33b 100644 --- a/src/ui/clipboard.h +++ b/src/ui/clipboard.h @@ -46,7 +46,7 @@ public: virtual void copySymbol(Inkscape::XML::Node* symbol, gchar const* style, SPDocument *source, Geom::Rect const &bbox) = 0; virtual void insertSymbol(SPDesktop *desktop, Geom::Point const &shift_dt) = 0; virtual bool paste(SPDesktop *desktop, bool in_place = false, bool on_page = false) = 0; - virtual bool pasteStyle(ObjectSet *set) = 0; + virtual bool pasteStyle(ObjectSet *set, bool use_computed) = 0; virtual bool pasteSize(ObjectSet *set, bool separately, bool apply_x, bool apply_y) = 0; virtual bool pastePathEffect(ObjectSet *set) = 0; virtual Glib::ustring getPathParameter(SPDesktop* desktop) = 0; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index fe27b914c0..19ee2e40ba 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -2627,21 +2627,6 @@ void InkscapePreferences::initPageBehavior() this->AddPage(_page_markers, _("Markers"), iter_behavior, PREFS_PAGE_BEHAVIOR_MARKERS); - // Clipboard options - _clipboard_style_computed.init(_("Copy computed style"), "/options/copycomputedstyle/value", 1, true, nullptr); - _clipboard_style_verbatim.init(_("Copy class and style attributes verbatim"), "/options/copycomputedstyle/value", 0, - false, &_clipboard_style_computed); - - _page_clipboard.add_group_header(_("Copying objects to the clipboard")); - _page_clipboard.add_line(true, "", _clipboard_style_computed, "", - _("Object style= attribute will be set to the computed style, " - "preserving the object's appearance as in previous Inkscape versions")); - _page_clipboard.add_line( - true, "", _clipboard_style_verbatim, "", - _("Object style= and class= values will be copied verbatim and may be removed by 'paste style'")); - - this->AddPage(_page_clipboard, _("Clipboard"), iter_behavior, PREFS_PAGE_BEHAVIOR_CLIPBOARD); - // Document cleanup options _page_cleanup.add_group_header( _("Document cleanup")); _cleanup_swatches.init ( _("Remove unused swatches when doing a document cleanup"), "/options/cleanupswatches/value", false); // text label diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 779c695f41..fb3338b2cf 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -93,7 +93,6 @@ enum PREFS_PAGE_BEHAVIOR_CLONES, PREFS_PAGE_BEHAVIOR_MASKS, PREFS_PAGE_BEHAVIOR_MARKERS, - PREFS_PAGE_BEHAVIOR_CLIPBOARD, PREFS_PAGE_BEHAVIOR_CLEANUP, PREFS_PAGE_BEHAVIOR_LPE, PREFS_PAGE_IO, @@ -194,7 +193,6 @@ protected: UI::Widget::DialogPage _page_clones; UI::Widget::DialogPage _page_mask; UI::Widget::DialogPage _page_markers; - UI::Widget::DialogPage _page_clipboard; UI::Widget::DialogPage _page_cleanup; UI::Widget::DialogPage _page_lpe; @@ -401,9 +399,6 @@ protected: UI::Widget::PrefCheckButton _markers_color_custom; UI::Widget::PrefCheckButton _markers_color_update; - UI::Widget::PrefRadioButton _clipboard_style_computed; - UI::Widget::PrefRadioButton _clipboard_style_verbatim; - UI::Widget::PrefCheckButton _cleanup_swatches; UI::Widget::PrefCheckButton _lpe_copy_mirroricons; diff --git a/src/widgets/mappings.xml b/src/widgets/mappings.xml index c3993614d7..4589de250a 100644 --- a/src/widgets/mappings.xml +++ b/src/widgets/mappings.xml @@ -15,7 +15,8 @@ - + + -- GitLab