diff --git a/src/actions/actions-base.cpp b/src/actions/actions-base.cpp index e01833990cf421baa405f299cb9be9fdc698d203..2a70ea24188937ce8528e307e2bda76bcb1146c5 100644 --- a/src/actions/actions-base.cpp +++ b/src/actions/actions-base.cpp @@ -151,13 +151,13 @@ query_all_recurse (SPObject *o) void query_all(InkscapeApplication* app) { - SPDocument* doc = app->get_active_document(); - if (!doc) { - show_output("query_all: no document!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } - SPObject *o = doc->getRoot(); + SPObject *o = document->getRoot(); if (o) { query_all_recurse(o); } diff --git a/src/actions/actions-edit.cpp b/src/actions/actions-edit.cpp index b4e1b99028d4c3f6171a60611152131b26f167bd..c1c64c032e70b20799a350c63e192eb59a28f00f 100644 --- a/src/actions/actions-edit.cpp +++ b/src/actions/actions-edit.cpp @@ -33,7 +33,11 @@ namespace ActionsEdit { void object_to_pattern(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Objects to Pattern selection->tile(); @@ -42,7 +46,11 @@ object_to_pattern(InkscapeApplication *app) void pattern_to_object(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Pattern to Objects selection->untile(); @@ -51,7 +59,11 @@ pattern_to_object(InkscapeApplication *app) void object_to_marker(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Objects to Marker selection->toMarker(); @@ -60,7 +72,11 @@ object_to_marker(InkscapeApplication *app) void object_to_guides(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Objects to Guides selection->toGuides(); @@ -69,7 +85,11 @@ object_to_guides(InkscapeApplication *app) void cut(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Cut selection->cut(); @@ -78,7 +98,11 @@ cut(InkscapeApplication *app) void copy(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Copy selection->copy(); @@ -87,7 +111,11 @@ copy(InkscapeApplication *app) void paste_style(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Style selection->pasteStyle(); @@ -96,7 +124,11 @@ paste_style(InkscapeApplication *app) void paste_size(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Size selection->pasteSize(true,true); @@ -105,7 +137,11 @@ paste_size(InkscapeApplication *app) void paste_width(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Width selection->pasteSize(true, false); @@ -114,7 +150,11 @@ paste_width(InkscapeApplication *app) void paste_height(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Height selection->pasteSize(false, true); @@ -123,7 +163,11 @@ paste_height(InkscapeApplication *app) void paste_size_separately(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Size Separately selection->pasteSizeSeparately(true, true); @@ -132,7 +176,11 @@ paste_size_separately(InkscapeApplication *app) void paste_width_separately(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Width Separately selection->pasteSizeSeparately(true, false); @@ -141,7 +189,11 @@ paste_width_separately(InkscapeApplication *app) void paste_height_separately(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Height Separately selection->pasteSizeSeparately(false, true); @@ -150,7 +202,11 @@ paste_height_separately(InkscapeApplication *app) void duplicate(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Duplicate selection->duplicate(); @@ -158,17 +214,26 @@ duplicate(InkscapeApplication *app) void duplicate_transform(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + selection->duplicate(true); selection->reapplyAffine(); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Duplicate and Transform"), + Inkscape::DocumentUndo::done(document, _("Duplicate and Transform"), INKSCAPE_ICON("edit-duplicate")); } void clone(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Create Clone selection->clone(); @@ -177,7 +242,11 @@ clone(InkscapeApplication *app) void clone_unlink(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Unlink Clone selection->unlink(); @@ -186,7 +255,11 @@ clone_unlink(InkscapeApplication *app) void clone_unlink_recursively(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Unlink Clones recursively selection->unlinkRecursive(false, true); @@ -195,7 +268,11 @@ clone_unlink_recursively(InkscapeApplication *app) void clone_link(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Relink to Copied selection->relink(); @@ -204,7 +281,11 @@ clone_link(InkscapeApplication *app) void select_original(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Select Original selection->cloneOriginal(); @@ -213,7 +294,11 @@ select_original(InkscapeApplication *app) void clone_link_lpe(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Clone original path (LPE) selection->cloneOriginalPathLPE(); @@ -222,7 +307,11 @@ clone_link_lpe(InkscapeApplication *app) void edit_delete(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // For text and node too special handling. if (auto desktop = selection->desktop()) { @@ -246,14 +335,22 @@ edit_delete(InkscapeApplication *app) void edit_delete_selection(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->deleteItems(); } void paste_path_effect(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Paste Path Effect selection->pastePathEffect(); @@ -262,7 +359,11 @@ paste_path_effect(InkscapeApplication *app) void remove_path_effect(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Remove Path Effect selection->removeLPE(); @@ -271,7 +372,11 @@ remove_path_effect(InkscapeApplication *app) void swap_fill_and_stroke(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Swap fill and Stroke selection->swapFillStroke(); @@ -280,7 +385,11 @@ swap_fill_and_stroke(InkscapeApplication *app) void fit_canvas_to_selection(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Fit Page to Selection selection->fitCanvas(true); diff --git a/src/actions/actions-effect.cpp b/src/actions/actions-effect.cpp index ca1d102e58a908d1b03d14c53e2292f759c8e845..234c85c4cee02cf53e974d9d87387e8529604f55 100644 --- a/src/actions/actions-effect.cpp +++ b/src/actions/actions-effect.cpp @@ -24,7 +24,11 @@ void edit_remove_filter(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Remove Filter selection->removeFilter(); diff --git a/src/actions/actions-element-a.cpp b/src/actions/actions-element-a.cpp index 019f443b564800ef5a1601f7bc1500c4b03de9ea..d2bb05f66a289a0ba7dc40b7a548608e37365ffe 100644 --- a/src/actions/actions-element-a.cpp +++ b/src/actions/actions-element-a.cpp @@ -40,7 +40,11 @@ void anchor_open_link(InkscapeApplication* app) { auto window = app->get_active_window(); if (window) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } for (auto item : selection->items()) { auto anchor = cast(item); if (anchor) { diff --git a/src/actions/actions-element-image.cpp b/src/actions/actions-element-image.cpp index 749cda4d6cc8a4253cef3d76515cc6191af38e6c..9e972e86abe9bb5feb0ca5d99606ea3570bdbf50 100644 --- a/src/actions/actions-element-image.cpp +++ b/src/actions/actions-element-image.cpp @@ -50,14 +50,16 @@ Glib::ustring image_get_editor_name(bool is_svg) // Note that edits are external to Inkscape and thus we cannot undo them! void image_edit(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } if (selection->isEmpty()) { // Nothing to do. return; } - auto document = selection->document(); - for (auto item : selection->items()) { auto image = cast(item); if (image) { @@ -139,13 +141,16 @@ void image_edit(InkscapeApplication *app) void image_crop(InkscapeApplication *app) { auto win = app->get_active_window(); - auto doc = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } auto msg = win->get_desktop()->messageStack(); auto const tool = win->get_desktop()->getTool(); int done = 0; int bytes = 0; - auto selection = app->get_active_selection(); if (selection->isEmpty()) { msg->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected.")); return; @@ -198,7 +203,7 @@ void image_crop(InkscapeApplication *app) } // Do flashing after select tool update. msg->flashF(Inkscape::INFORMATION_MESSAGE, ss.str().c_str(), done, Inkscape::Util::format_size(abs(bytes)).c_str()); - Inkscape::DocumentUndo::done(doc, "ActionImageCrop", "Crop Images"); + Inkscape::DocumentUndo::done(document, "ActionImageCrop", "Crop Images"); } else { msg->flash(Inkscape::WARNING_MESSAGE, _("No images cropped!")); } diff --git a/src/actions/actions-file.cpp b/src/actions/actions-file.cpp index 595777f4684300fb511a0e219210831105046e70..850af1b9ca0b374a1178e4b19aa8765146f144c9 100644 --- a/src/actions/actions-file.cpp +++ b/src/actions/actions-file.cpp @@ -76,7 +76,11 @@ void file_rebase(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); - SPDocument *document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } document->rebase(s.get()); document->ensureUpToDate(); @@ -94,7 +98,11 @@ file_rebase(const Glib::VariantBase& value, InkscapeApplication *app) void file_close(InkscapeApplication *app) { - SPDocument *document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } app->document_close(document); app->set_active_document(nullptr); diff --git a/src/actions/actions-hide-lock.cpp b/src/actions/actions-hide-lock.cpp index 80fd132687101d6f6007a68b8a4aa077cd02b7c6..69bc1cfd38ac0eac89f7470f4601963925f2d9b8 100644 --- a/src/actions/actions-hide-lock.cpp +++ b/src/actions/actions-hide-lock.cpp @@ -73,7 +73,11 @@ hide_lock_lock(SPItem* item, bool lock) void hide_lock_unhide_all(InkscapeApplication* app) { - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } auto root = document->getRoot(); bool changed = hide_lock_recurse(&hide_lock_hide, root, false); // Unhide @@ -87,7 +91,11 @@ hide_lock_unhide_all(InkscapeApplication* app) void hide_lock_unlock_all(InkscapeApplication* app) { - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } auto root = document->getRoot(); bool changed = hide_lock_recurse(&hide_lock_lock, root, false); // Unlock @@ -101,9 +109,9 @@ hide_lock_unlock_all(InkscapeApplication* app) void hide_lock_unhide_below(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - if (!selection) { - show_output("hide_lock_unhide_below: no selection!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } @@ -115,7 +123,6 @@ hide_lock_unhide_below(InkscapeApplication *app) } if (changed) { - auto document = app->get_active_document(); Inkscape::DocumentUndo::done(document, _("Unhid selected items and their descendents."), ""); } } @@ -124,9 +131,9 @@ hide_lock_unhide_below(InkscapeApplication *app) void hide_lock_unlock_below(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - if (!selection) { - show_output("hide_lock_unhide_below: no selection!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } @@ -138,7 +145,6 @@ hide_lock_unlock_below(InkscapeApplication *app) } if (changed) { - auto document = app->get_active_document(); Inkscape::DocumentUndo::done(document, _("Unlocked selected items and their descendents."), ""); } } @@ -147,9 +153,9 @@ hide_lock_unlock_below(InkscapeApplication *app) void hide_lock_hide_selected(InkscapeApplication* app, bool hide) { - auto selection = app->get_active_selection(); - if (!selection) { - show_output("hide_lock_hide_selected: no selection!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } @@ -161,7 +167,6 @@ hide_lock_hide_selected(InkscapeApplication* app, bool hide) } if (changed) { - auto document = app->get_active_document(); Inkscape::DocumentUndo::done(document, (hide ? _("Hid selected items.") : _("Unhid selected items.")), ""); selection->clear(); } @@ -171,9 +176,9 @@ hide_lock_hide_selected(InkscapeApplication* app, bool hide) void hide_lock_lock_selected(InkscapeApplication* app, bool lock) { - auto selection = app->get_active_selection(); - if (!selection) { - show_output("hide_lock_lock_selected: no selection!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } @@ -185,7 +190,6 @@ hide_lock_lock_selected(InkscapeApplication* app, bool lock) } if (changed) { - auto document = app->get_active_document(); Inkscape::DocumentUndo::done(document, (lock ? _("Locked selected items.") : _("Unlocked selected items.")), ""); selection->clear(); } diff --git a/src/actions/actions-object-align.cpp b/src/actions/actions-object-align.cpp index 8ec0d853dc74c6065f4c7b84dd22e5b80164d633..b9231be9e18bcab65a3e7e53e6f06a6d05e195b0 100644 --- a/src/actions/actions-object-align.cpp +++ b/src/actions/actions-object-align.cpp @@ -87,6 +87,11 @@ object_align_on_canvas(InkscapeApplication *app) void object_align(const Glib::VariantBase& value, InkscapeApplication *app) { + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); std::vector tokens = Glib::Regex::split_simple(" ", s.get()); @@ -149,10 +154,6 @@ object_align(const Glib::VariantBase& value, InkscapeApplication *app) } // clang-format on - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); selection->setDocument(document); // We force unselect operand in bool LPE. TODO: See if we can use "selected" from below. @@ -274,10 +275,11 @@ object_distribute(const Glib::VariantBase& value, InkscapeApplication *app) Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); auto token = s.get(); - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); std::vector selected(selection->items().begin(), selection->items().end()); @@ -384,7 +386,7 @@ object_distribute(const Glib::VariantBase& value, InkscapeApplication *app) prefs->setInt("/options/clonecompensation/value", saved_compensation); if (changed) { - Inkscape::DocumentUndo::done( document, _("Distribute"), INKSCAPE_ICON("dialog-align-and-distribute")); + Inkscape::DocumentUndo::done(document, _("Distribute"), INKSCAPE_ICON("dialog-align-and-distribute")); } } @@ -411,19 +413,21 @@ object_distribute_text(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); auto token = s.get(); - + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } Geom::Dim2 orientation = Geom::Dim2::X; if (token.find("vertical") != Glib::ustring::npos) { orientation = Geom::Dim2::Y; } - auto selection = app->get_active_selection(); if (selection->size() < 2) { return; } // We should not have to do this! - auto document = app->get_active_document(); selection->setDocument(document); std::vector baselines; @@ -460,7 +464,7 @@ object_distribute_text(const Glib::VariantBase& value, InkscapeApplication *app) ++i; } - Inkscape::DocumentUndo::done( document, _("Distribute"), INKSCAPE_ICON("dialog-align-and-distribute")); + Inkscape::DocumentUndo::done(document, _("Distribute"), INKSCAPE_ICON("dialog-align-and-distribute")); } void @@ -469,7 +473,11 @@ object_align_text(const Glib::VariantBase& value, InkscapeApplication *app) Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); std::vector tokens = Glib::Regex::split_simple(" ", s.get()); - + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Defaults auto target = ObjectAlignTarget::SELECTION; auto orientation = Geom::Dim2::X; @@ -499,10 +507,6 @@ object_align_text(const Glib::VariantBase& value, InkscapeApplication *app) } } - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); selection->setDocument(document); // Find alignment rectangle. This can come from: @@ -694,10 +698,11 @@ object_rearrange(const Glib::VariantBase& value, InkscapeApplication *app) Glib::Variant s = Glib::VariantBase::cast_dynamic >(value); auto token = s.get(); - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); std::vector items(selection->items().begin(), selection->items().end()); @@ -724,17 +729,18 @@ object_rearrange(const Glib::VariantBase& value, InkscapeApplication *app) // Restore compensation setting. prefs->setInt("/options/clonecompensation/value", saved_compensation); - Inkscape::DocumentUndo::done( document, _("Rearrange"), INKSCAPE_ICON("dialog-align-and-distribute")); + Inkscape::DocumentUndo::done(document, _("Rearrange"), INKSCAPE_ICON("dialog-align-and-distribute")); } void object_remove_overlaps(const Glib::VariantBase& value, InkscapeApplication *app) { - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); std::vector items(selection->items().begin(), selection->items().end()); @@ -759,7 +765,7 @@ object_remove_overlaps(const Glib::VariantBase& value, InkscapeApplication *app) // Restore compensation setting. prefs->setInt("/options/clonecompensation/value", saved_compensation); - Inkscape::DocumentUndo::done( document, _("Remove overlaps"), INKSCAPE_ICON("dialog-align-and-distribute")); + Inkscape::DocumentUndo::done(document, _("Remove overlaps"), INKSCAPE_ICON("dialog-align-and-distribute")); } diff --git a/src/actions/actions-object.cpp b/src/actions/actions-object.cpp index 2c2dac94c23e5fdc0ec0d09624d5a5e93cf6e760..39acbadb0371e61430f02c9be59719449d176e9c 100644 --- a/src/actions/actions-object.cpp +++ b/src/actions/actions-object.cpp @@ -37,8 +37,12 @@ object_set_attribute(const Glib::VariantBase& value, InkscapeApplication *app) } auto const attribute = argument.substr(0, comma_position); auto const new_value = argument.substr(comma_position + 1); - - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + if (selection->isEmpty()) { show_output("action:object_set_attribute: selection empty!"); return; @@ -52,7 +56,7 @@ object_set_attribute(const Glib::VariantBase& value, InkscapeApplication *app) } // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionObjectSetAttribute", ""); + Inkscape::DocumentUndo::done(document, "ActionObjectSetAttribute", ""); } @@ -68,7 +72,11 @@ object_set_property(const Glib::VariantBase& value, InkscapeApplication *app) return; } - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } if (selection->isEmpty()) { show_output("action:object_set_property: selection empty!"); return; @@ -85,17 +93,18 @@ object_set_property(const Glib::VariantBase& value, InkscapeApplication *app) } // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionObjectSetProperty", ""); + Inkscape::DocumentUndo::done(document, "ActionObjectSetProperty", ""); } void object_unlink_clones(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); selection->unlink(); @@ -110,7 +119,11 @@ should_remove_original() void object_clip_set(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Clip Set selection->setMask(true, false, should_remove_original()); @@ -120,29 +133,41 @@ object_clip_set(InkscapeApplication *app) void object_clip_set_inverse(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Clip Set Inverse selection->setMask(true, false, should_remove_original()); - Inkscape::LivePathEffect::sp_inverse_powerclip(app->get_active_selection()); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Set Inverse Clip(LPE)"), ""); + Inkscape::LivePathEffect::sp_inverse_powerclip(selection); + Inkscape::DocumentUndo::done(document, _("Set Inverse Clip(LPE)"), ""); } void object_clip_release(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Clip Release - Inkscape::LivePathEffect::sp_remove_powerclip(app->get_active_selection()); + Inkscape::LivePathEffect::sp_remove_powerclip(selection); selection->unsetMask(true, true, should_remove_original()); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Release clipping path"), ""); + Inkscape::DocumentUndo::done(document, _("Release clipping path"), ""); } void object_clip_set_group(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setClipGroup(); // Undo added in setClipGroup(). } @@ -150,39 +175,55 @@ object_clip_set_group(InkscapeApplication *app) void object_mask_set(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Mask Set selection->setMask(false, false, should_remove_original()); - Inkscape::DocumentUndo::done(selection->document(), _("Set mask"), ""); + Inkscape::DocumentUndo::done(document, _("Set mask"), ""); } void object_mask_set_inverse(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Mask Set Inverse selection->setMask(false, false, should_remove_original()); - Inkscape::LivePathEffect::sp_inverse_powermask(app->get_active_selection()); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Set Inverse Mask (LPE)"), ""); + Inkscape::LivePathEffect::sp_inverse_powermask(selection); + Inkscape::DocumentUndo::done(document, _("Set Inverse Mask (LPE)"), ""); } void object_mask_release(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Mask Release - Inkscape::LivePathEffect::sp_remove_powermask(app->get_active_selection()); + Inkscape::LivePathEffect::sp_remove_powermask(selection); selection->unsetMask(false, true, should_remove_original()); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Release mask"), ""); + Inkscape::DocumentUndo::done(document, _("Release mask"), ""); } void object_rotate_90_cw(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Rotate 90 auto desktop = selection->desktop(); @@ -192,7 +233,11 @@ object_rotate_90_cw(InkscapeApplication *app) void object_rotate_90_ccw(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Object Rotate 90 CCW auto desktop = selection->desktop(); @@ -202,7 +247,11 @@ object_rotate_90_ccw(InkscapeApplication *app) void object_flip_horizontal(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } Geom::OptRect bbox = selection->visualBounds(); if (!bbox) { @@ -219,13 +268,17 @@ object_flip_horizontal(InkscapeApplication *app) // Object Flip Horizontal selection->setScaleRelative(center, Geom::Scale(-1.0, 1.0)); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Flip horizontally"), INKSCAPE_ICON("object-flip-horizontal")); + Inkscape::DocumentUndo::done(document, _("Flip horizontally"), INKSCAPE_ICON("object-flip-horizontal")); } void object_flip_vertical(InkscapeApplication *app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } Geom::OptRect bbox = selection->visualBounds(); if (!bbox) { @@ -242,27 +295,29 @@ object_flip_vertical(InkscapeApplication *app) // Object Flip Vertical selection->setScaleRelative(center, Geom::Scale(1.0, -1.0)); - Inkscape::DocumentUndo::done(app->get_active_document(), _("Flip vertically"), INKSCAPE_ICON("object-flip-vertical")); + Inkscape::DocumentUndo::done(document, _("Flip vertically"), INKSCAPE_ICON("object-flip-vertical")); } void object_to_path(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); selection->toCurves(false, Inkscape::Preferences::get()->getBool("/options/clonestocurvesjustunlink/value", true)); } void object_add_corners_lpe(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); std::vector items(selection->items().begin(), selection->items().end()); selection->clear(); @@ -286,10 +341,11 @@ object_add_corners_lpe(InkscapeApplication *app) { void object_stroke_to_path(InkscapeApplication *app) { - auto selection = app->get_active_selection(); - - // We should not have to do this! - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->setDocument(document); selection->strokesToPaths(); diff --git a/src/actions/actions-output.cpp b/src/actions/actions-output.cpp index e4160528e9ab9548afa69ac753ed21b3870abd7f..943a6480070a894c5d630cdd08a61b82ed16a835 100644 --- a/src/actions/actions-output.cpp +++ b/src/actions/actions-output.cpp @@ -232,9 +232,9 @@ export_png_antialias(const Glib::VariantBase& value, InkscapeApplication *app) void export_do(InkscapeApplication *app) { - SPDocument* document = app->get_active_document(); - if (!document) { - show_output("export_do: no documents open!"); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { return; } std::string filename; diff --git a/src/actions/actions-paths.cpp b/src/actions/actions-paths.cpp index 4ff0b800d3b8499addbce8d62500676e5d71fe3b..3a2e80f95909e24f3dcc6e016fdeee3115d2c468 100644 --- a/src/actions/actions-paths.cpp +++ b/src/actions/actions-paths.cpp @@ -29,7 +29,11 @@ void object_path_union(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathUnion(); @@ -38,7 +42,11 @@ object_path_union(InkscapeApplication *app) void select_path_difference(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathDiff(); @@ -47,7 +55,11 @@ select_path_difference(InkscapeApplication *app) void select_path_intersection(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathIntersect(); @@ -56,7 +68,11 @@ select_path_intersection(InkscapeApplication *app) void select_path_exclusion(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathSymDiff(); @@ -65,7 +81,11 @@ select_path_exclusion(InkscapeApplication *app) void select_path_division(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathCut(); @@ -74,7 +94,11 @@ select_path_division(InkscapeApplication *app) void select_path_cut(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeLPESRecursive(true); selection->unlinkRecursive(true); selection->pathSlice(); @@ -83,7 +107,11 @@ select_path_cut(InkscapeApplication *app) void select_path_combine(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->unlinkRecursive(true); selection->combine(); } @@ -91,45 +119,69 @@ select_path_combine(InkscapeApplication *app) void select_path_break_apart(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->breakApart(); } void select_path_split(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->breakApart(false, false); } void select_path_fracture(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } auto boolean_builder = Inkscape::BooleanBuilder(selection); selection->setList(boolean_builder.shape_commit(true)); - Inkscape::DocumentUndo::done(selection->document(), "Fracture", INKSCAPE_ICON("path-fracture")); + Inkscape::DocumentUndo::done(document, "Fracture", INKSCAPE_ICON("path-fracture")); } void select_path_flatten(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } auto boolean_builder = Inkscape::BooleanBuilder(selection, true); selection->setList(boolean_builder.shape_commit(true)); - Inkscape::DocumentUndo::done(selection->document(), "Flatten", INKSCAPE_ICON("path-flatten")); + Inkscape::DocumentUndo::done(document, "Flatten", INKSCAPE_ICON("path-flatten")); } void fill_between_paths(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->fillBetweenMany(); } void select_path_simplify(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->simplifyPaths(); } diff --git a/src/actions/actions-selection-object.cpp b/src/actions/actions-selection-object.cpp index 48f6d58f52c0fcee02d39c54858a2fddee3d1a4a..c1762bf3235296bf601e59a39b050597f7310451 100644 --- a/src/actions/actions-selection-object.cpp +++ b/src/actions/actions-selection-object.cpp @@ -32,24 +32,36 @@ void select_object_group(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->group(); - Inkscape::DocumentUndo::done(selection->document(), C_("Verb", "Group"), INKSCAPE_ICON("object-group")); + Inkscape::DocumentUndo::done(document, C_("Verb", "Group"), INKSCAPE_ICON("object-group")); } void select_object_ungroup(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->ungroup(); - Inkscape::DocumentUndo::done(selection->document(), _("Ungroup"), INKSCAPE_ICON("object-ungroup")); + Inkscape::DocumentUndo::done(document, _("Ungroup"), INKSCAPE_ICON("object-ungroup")); } void select_object_ungroup_pop(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Pop Selected Objects out of Group selection->popFromGroup(); @@ -58,7 +70,11 @@ select_object_ungroup_pop(InkscapeApplication* app) void select_object_link(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Group with auto anchor = selection->group(true); @@ -66,13 +82,17 @@ select_object_link(InkscapeApplication* app) // Open dialog to set link. selection->desktop()->getContainer()->new_dialog("ObjectAttributes"); - Inkscape::DocumentUndo::done(selection->document(), _("Anchor"), INKSCAPE_ICON("object-group")); + Inkscape::DocumentUndo::done(document, _("Anchor"), INKSCAPE_ICON("object-group")); } void selection_top(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Raise to Top selection->raiseToTop(); @@ -81,7 +101,11 @@ selection_top(InkscapeApplication* app) void selection_raise(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Raise selection->raise(); @@ -90,7 +114,11 @@ selection_raise(InkscapeApplication* app) void selection_lower(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Lower selection->lower(); @@ -99,7 +127,11 @@ selection_lower(InkscapeApplication* app) void selection_bottom(InkscapeApplication* app) { - Inkscape::Selection *selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Lower to Bottom selection->lowerToBottom(); @@ -108,21 +140,33 @@ selection_bottom(InkscapeApplication* app) void selection_stack_up(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->stackUp(); } void selection_stack_down(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->stackDown(); } void selection_make_bitmap_copy(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } // Make a Bitmap Copy selection->createBitmapCopy(); diff --git a/src/actions/actions-transform.cpp b/src/actions/actions-transform.cpp index 3f0ca733ad1c49155706f5c95205d32121288bd5..3ef46975f6887a65978f64e6b1d0cd52ad6893d4 100644 --- a/src/actions/actions-transform.cpp +++ b/src/actions/actions-transform.cpp @@ -42,41 +42,57 @@ transform_translate(const Glib::VariantBase& value, InkscapeApplication *app) return; } - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->move(dx, dy); // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionTransformTranslate", ""); + Inkscape::DocumentUndo::done(document, "ActionTransformTranslate", ""); } void transform_rotate(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant d = Glib::VariantBase::cast_dynamic >(value); - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->rotate(d.get()); // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionTransformRotate", ""); + Inkscape::DocumentUndo::done(document, "ActionTransformRotate", ""); } void transform_scale(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant d = Glib::VariantBase::cast_dynamic >(value); - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->scale(d.get()); // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionTransformScale", ""); + Inkscape::DocumentUndo::done(document, "ActionTransformScale", ""); } void transform_grow(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant d = Glib::VariantBase::cast_dynamic >(value); - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->scaleGrow(d.get()); } @@ -85,7 +101,11 @@ transform_grow_step(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant d = Glib::VariantBase::cast_dynamic >(value); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->scaleGrow(d.get() * prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000)); } @@ -93,31 +113,47 @@ void transform_grow_screen(const Glib::VariantBase& value, InkscapeApplication *app) { Glib::Variant d = Glib::VariantBase::cast_dynamic >(value); - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->scaleScreen(d.get()); } void transform_remove(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->removeTransform(); // Needed to update repr (is this the best way?). - Inkscape::DocumentUndo::done(app->get_active_document(), "ActionTransformRemoveTransform", ""); + Inkscape::DocumentUndo::done(document, "ActionTransformRemoveTransform", ""); } void transform_reapply(InkscapeApplication *app) { - auto selection = app->get_active_selection(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } selection->reapplyAffine(); - Inkscape::DocumentUndo::maybeDone(app->get_active_document(), "reapply-transform", _("Reapply Transforms"), + Inkscape::DocumentUndo::maybeDone(document, "reapply-transform", _("Reapply Transforms"), INKSCAPE_ICON("tool-pointer")); } void page_rotate(const Glib::VariantBase& value, InkscapeApplication *app) { - auto document = app->get_active_document(); + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } Glib::Variant i = Glib::VariantBase::cast_dynamic >(value); document->getPageManager().rotatePage(i.get()); Inkscape::DocumentUndo::done(document, "Rotate Page", INKSCAPE_ICON("tool-pages")); diff --git a/src/actions/actions-window.cpp b/src/actions/actions-window.cpp index 3a2f5ef15964ccaacbeb893596e54c7515771d55..0c6f2e858f943095b7994967056498443990969c 100644 --- a/src/actions/actions-window.cpp +++ b/src/actions/actions-window.cpp @@ -25,17 +25,17 @@ void window_open(InkscapeApplication *app) { - SPDocument *document = app->get_active_document(); - if (document) { - InkscapeWindow* window = app->get_active_window(); - if (window && window->get_document() && window->get_document()->getVirgin()) { - // We have a window with an untouched template document, use this window. - app->document_swap (window, document); - } else { - app->window_open(document); - } + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + InkscapeWindow* window = app->get_active_window(); + if (window && window->get_document() && window->get_document()->getVirgin()) { + // We have a window with an untouched template document, use this window. + app->document_swap (window, document); } else { - show_output("window_open(): failed to find document!"); + app->window_open(document); } }