Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-edit.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
14#include "actions-edit.h"
15
16#include <giomm.h>
17#include <glibmm/i18n.h>
18
19#include "actions-helper.h"
20#include "desktop.h"
22#include "document-undo.h"
23#include "selection.h"
24#include "selection-chemistry.h"
25
26#include "object/sp-guide.h"
27#include "ui/icon-names.h"
28#include "ui/tools/node-tool.h"
29#include "ui/tools/text-tool.h"
30
31namespace ActionsEdit {
32
33void
35{
36 auto selection = app->get_active_selection();
37
38 // Objects to Pattern
39 selection->tile();
40}
41
42void
44{
45 auto selection = app->get_active_selection();
46
47 // Pattern to Objects
48 selection->untile();
49}
50
51void
53{
54 auto selection = app->get_active_selection();
55
56 // Objects to Marker
57 selection->toMarker();
58}
59
60void
62{
63 auto selection = app->get_active_selection();
64
65 // Objects to Guides
66 selection->toGuides();
67}
68
69void
71{
72 auto selection = app->get_active_selection();
73
74 // Cut
75 selection->cut();
76}
77
78void
80{
81 auto selection = app->get_active_selection();
82
83 // Copy
84 selection->copy();
85}
86
87void
89{
90 auto selection = app->get_active_selection();
91
92 // Paste Style
93 selection->pasteStyle();
94}
95
96void
98{
99 auto selection = app->get_active_selection();
100
101 // Paste Size
102 selection->pasteSize(true,true);
103}
104
105void
107{
108 auto selection = app->get_active_selection();
109
110 // Paste Width
111 selection->pasteSize(true, false);
112}
113
114void
116{
117 auto selection = app->get_active_selection();
118
119 // Paste Height
120 selection->pasteSize(false, true);
121}
122
123void
125{
126 auto selection = app->get_active_selection();
127
128 // Paste Size Separately
129 selection->pasteSizeSeparately(true, true);
130}
131
132void
134{
135 auto selection = app->get_active_selection();
136
137 // Paste Width Separately
138 selection->pasteSizeSeparately(true, false);
139}
140
141void
143{
144 auto selection = app->get_active_selection();
145
146 // Paste Height Separately
147 selection->pasteSizeSeparately(false, true);
148}
149
150void
152{
153 auto selection = app->get_active_selection();
154
155 // Duplicate
156 selection->duplicate();
157}
158
160{
161 auto selection = app->get_active_selection();
162 selection->duplicate(true);
163 selection->reapplyAffine();
164 Inkscape::DocumentUndo::done(app->get_active_document(), _("Duplicate and Transform"),
165 INKSCAPE_ICON("edit-duplicate"));
166}
167
168void
170{
171 auto selection = app->get_active_selection();
172
173 // Create Clone
174 selection->clone();
175}
176
177void
179{
180 auto selection = app->get_active_selection();
181
182 // Unlink Clone
183 selection->unlink();
184}
185
186void
188{
189 auto selection = app->get_active_selection();
190
191 // Unlink Clones recursively
192 selection->unlinkRecursive(false, true);
193}
194
195void
197{
198 auto selection = app->get_active_selection();
199
200 // Relink to Copied
201 selection->relink();
202}
203
204void
206{
207 auto selection = app->get_active_selection();
208
209 // Select Original
210 selection->cloneOriginal();
211}
212
213void
215{
216 auto selection = app->get_active_selection();
217
218 // Clone original path (LPE)
219 selection->cloneOriginalPathLPE();
220}
221
222void
224{
225 auto selection = app->get_active_selection();
226
227 // For text and node too special handling.
228 if (auto desktop = selection->desktop()) {
229 if (auto const text_tool = dynamic_cast<Inkscape::UI::Tools::TextTool *>(desktop->getTool())) {
230 text_tool->deleteSelected();
231 return;
232 }
233 if (auto const node_tool = dynamic_cast<Inkscape::UI::Tools::NodeTool *>(desktop->getTool())) {
234 // This means we delete items is no nodes are selected.
235 if (node_tool->_selected_nodes) {
236 node_tool->deleteSelected();
237 return;
238 }
239 }
240 }
241
242 // Delete select objects only.
243 selection->deleteItems();
244}
245
246void
248{
249 auto selection = app->get_active_selection();
250 selection->deleteItems();
251}
252
253void
255{
256 auto selection = app->get_active_selection();
257
258 // Paste Path Effect
259 selection->pastePathEffect();
260}
261
262void
264{
265 auto selection = app->get_active_selection();
266
267 // Remove Path Effect
268 selection->removeLPE();
269}
270
271void
273{
274 auto selection = app->get_active_selection();
275
276 // Swap fill and Stroke
277 selection->swapFillStroke();
278}
279
280void
282{
283 auto selection = app->get_active_selection();
284
285 // Fit Page to Selection
286 selection->fitCanvas(true);
287}
288
289void
294
295const Glib::ustring SECTION = NC_("Action Section", "Edit");
296
297std::vector<std::vector<Glib::ustring>> raw_data_edit = {
298 // clang-format off
299 {"app.object-to-pattern", N_("Objects to Pattern"), SECTION, N_("Convert selection to a rectangle with tiled pattern fill")},
300 {"app.pattern-to-object", N_("Pattern to Objects"), SECTION, N_("Extract objects from a tiled pattern fill")},
301 {"app.object-to-marker", N_("Objects to Marker"), SECTION, N_("Convert selection to a line marker")},
302 {"app.object-to-guides", N_("Objects to Guides"), SECTION, N_("Convert selected objects to a collection of guidelines aligned with their edges")},
303 {"app.cut", N_("Cut"), SECTION, N_("Cut selection to clipboard")},
304 {"app.copy", N_("Copy"), SECTION, N_("Copy selection to clipboard")},
305 {"app.paste-style", N_("Paste Style"), SECTION, N_("Apply the style of the copied object to selection")},
306 {"app.paste-size", N_("Paste Size"), SECTION, N_("Scale selection to match the size of the copied object")},
307 {"app.paste-width", N_("Paste Width"), SECTION, N_("Scale selection horizontally to match the width of the copied object")},
308 {"app.paste-height", N_("Paste Height"), SECTION, N_("Scale selection vertically to match the height of the copied object")},
309 {"app.paste-size-separately", N_("Paste Size Separately"), SECTION, N_("Scale each selected object to match the size of the copied object")},
310 {"app.paste-width-separately", N_("Paste Width Separately"), SECTION, N_("Scale each selected object horizontally to match the width of the copied object")},
311 {"app.paste-height-separately", N_("Paste Height Separately"), SECTION, N_("Scale each selected object vertically to match the height of the copied object")},
312 {"app.duplicate", N_("Duplicate"), SECTION, N_("Duplicate Selected Objects")},
313 {"app.duplicate-transform", N_("Duplicate and Transform"), SECTION, N_("Duplicate selected objects and reapply last transformation")},
314 {"app.clone", N_("Create Clone"), SECTION, N_("Create a clone (a copy linked to the original) of selected object")},
315 {"app.clone-unlink", N_("Unlink Clone"), SECTION, N_("Cut the selected clones' links to the originals, turning them into standalone objects")},
316 {"app.clone-unlink-recursively", N_("Unlink Clones recursively"), SECTION, N_("Unlink all clones in the selection, even if they are in groups.")},
317 {"app.clone-link", N_("Relink to Copied"), SECTION, N_("Relink the selected clones to the object currently on the clipboard")},
318 {"app.select-original", N_("Select Original"), SECTION, N_("Select the object to which the selected clone is linked")},
319 {"app.clone-link-lpe", N_("Clone original path (LPE)"), SECTION, N_("Creates a new path, applies the Clone original LPE, and refers it to the selected path")},
320 {"app.delete", N_("Delete"), SECTION, N_("Delete selected items, nodes or text.")},
321 {"app.delete-selection", N_("Delete Items"), SECTION, N_("Delete selected items")},
322 {"app.paste-path-effect", N_("Paste Path Effect"), SECTION, N_("Apply the path effect of the copied object to selection")},
323 {"app.remove-path-effect", N_("Remove Path Effect"), SECTION, N_("Remove any path effects from selected objects")},
324 {"app.swap-fill-and-stroke", N_("Swap fill and stroke"), SECTION, N_("Swap fill and stroke of an object")},
325 {"app.fit-canvas-to-selection", N_("Fit Page to Selection"), SECTION, N_("Fit the page to the current selection")},
326 {"app.chameleon-fill", N_("Chameleon Fill"), SECTION, N_("Set each object's color to the average of all colors inside that shape.")}
327 // clang-format on
328};
329
330} // namespace ActionsEdit
331
332using namespace ActionsEdit;
333
334void
336{
337 auto *gapp = app->gio_app();
338
339 // clang-format off
340 gapp->add_action( "object-to-pattern", sigc::bind(sigc::ptr_fun(&object_to_pattern), app));
341 gapp->add_action( "pattern-to-object", sigc::bind(sigc::ptr_fun(&pattern_to_object), app));
342 gapp->add_action( "object-to-marker", sigc::bind(sigc::ptr_fun(&object_to_marker), app));
343 gapp->add_action( "object-to-guides", sigc::bind(sigc::ptr_fun(&object_to_guides), app));
344 gapp->add_action( "cut", sigc::bind(sigc::ptr_fun(&cut), app));
345 gapp->add_action( "copy", sigc::bind(sigc::ptr_fun(&copy), app));
346 gapp->add_action( "paste-style", sigc::bind(sigc::ptr_fun(&paste_style), app));
347 gapp->add_action( "paste-size", sigc::bind(sigc::ptr_fun(&paste_size), app));
348 gapp->add_action( "paste-width", sigc::bind(sigc::ptr_fun(&paste_width), app));
349 gapp->add_action( "paste-height", sigc::bind(sigc::ptr_fun(&paste_height), app));
350 gapp->add_action( "paste-size-separately", sigc::bind(sigc::ptr_fun(&paste_size_separately), app));
351 gapp->add_action( "paste-width-separately", sigc::bind(sigc::ptr_fun(&paste_width_separately), app));
352 gapp->add_action( "paste-height-separately", sigc::bind(sigc::ptr_fun(&paste_height_separately), app));
353 gapp->add_action( "duplicate", sigc::bind(sigc::ptr_fun(&duplicate), app));
354 gapp->add_action( "duplicate-transform", sigc::bind(sigc::ptr_fun(&duplicate_transform), app));
355 // explicit namespace reference added because NetBSD provides a conflicting clone() function in its libc headers
356 gapp->add_action( "clone", sigc::bind(sigc::ptr_fun(&ActionsEdit::clone), app));
357 gapp->add_action( "clone-unlink", sigc::bind(sigc::ptr_fun(&clone_unlink), app));
358 gapp->add_action( "clone-unlink-recursively", sigc::bind(sigc::ptr_fun(&clone_unlink_recursively), app));
359 gapp->add_action( "clone-link", sigc::bind(sigc::ptr_fun(&clone_link), app));
360 gapp->add_action( "select-original", sigc::bind(sigc::ptr_fun(&select_original), app));
361 gapp->add_action( "clone-link-lpe", sigc::bind(sigc::ptr_fun(&clone_link_lpe), app));
362 gapp->add_action( "delete", sigc::bind(sigc::ptr_fun(&edit_delete), app));
363 gapp->add_action( "delete-selection", sigc::bind(sigc::ptr_fun(&edit_delete_selection), app));
364 gapp->add_action( "paste-path-effect", sigc::bind(sigc::ptr_fun(&paste_path_effect), app));
365 gapp->add_action( "remove-path-effect", sigc::bind(sigc::ptr_fun(&remove_path_effect), app));
366 gapp->add_action( "swap-fill-and-stroke", sigc::bind(sigc::ptr_fun(&swap_fill_and_stroke), app));
367 gapp->add_action( "fit-canvas-to-selection", sigc::bind(sigc::ptr_fun(&fit_canvas_to_selection), app));
368 gapp->add_action( "chameleon-fill", sigc::bind(sigc::ptr_fun(&chameleon_fill), app));
369 // clang-format on
370
371 if (!app) {
372 show_output("add_actions_edit: no app!");
373 return;
374 }
376}
void add_actions_edit(InkscapeApplication *app)
Authors: Sushant A A sushant.co19@gmail.com
void show_output(Glib::ustring const &data, bool const is_cerr)
void add_data(std::vector< std::vector< Glib::ustring > > const &raw_data)
InkActionExtraData & get_action_extra_data()
Gio::Application * gio_app()
The Gio application instance, never NULL.
SPDocument * get_active_document()
Inkscape::Selection * get_active_selection()
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
void pasteSize(bool apply_x, bool apply_y)
void pasteSizeSeparately(bool apply_x, bool apply_y)
bool unlink(const bool skip_undo=false, const bool silent=false)
Unlink all directly selected clones.
void cloneOriginalPathLPE(bool allow_transforms=false, bool sync=false, bool skip_undo=false)
This applies the Fill Between Many LPE, and has it refer to the selection.
void duplicate(bool suppressDone=false, bool duplicateLayer=false)
void toMarker(bool apply=true)
void deleteItems(bool skip_undo=false)
void tile(bool apply=true)
bool unlinkRecursive(const bool skip_undo=false, const bool force=false, const bool silent=false)
Recursively unlink any clones present in the current selection, including clones which are used to cl...
void clone(bool skip_undo=false)
bool fitCanvas(bool with_margins, bool skip_undo=false)
Inkscape::UI::Tools::ToolBase * getTool() const
Definition desktop.h:187
Editable view implementation.
TODO: insert short description here.
Macro for icon names used in Inkscape.
void copy(InkscapeApplication *app)
void paste_width(InkscapeApplication *app)
void clone_unlink(InkscapeApplication *app)
void clone_link(InkscapeApplication *app)
void edit_delete_selection(InkscapeApplication *app)
void object_to_pattern(InkscapeApplication *app)
void paste_height_separately(InkscapeApplication *app)
void swap_fill_and_stroke(InkscapeApplication *app)
void duplicate_transform(InkscapeApplication *app)
std::vector< std::vector< Glib::ustring > > raw_data_edit
void clone(InkscapeApplication *app)
void paste_path_effect(InkscapeApplication *app)
void paste_size_separately(InkscapeApplication *app)
const Glib::ustring SECTION
void paste_style(InkscapeApplication *app)
void select_original(InkscapeApplication *app)
void cut(InkscapeApplication *app)
void object_to_guides(InkscapeApplication *app)
void chameleon_fill(InkscapeApplication *app)
void paste_height(InkscapeApplication *app)
void clone_unlink_recursively(InkscapeApplication *app)
void pattern_to_object(InkscapeApplication *app)
void clone_link_lpe(InkscapeApplication *app)
void object_to_marker(InkscapeApplication *app)
void fit_canvas_to_selection(InkscapeApplication *app)
void paste_width_separately(InkscapeApplication *app)
void duplicate(InkscapeApplication *app)
void paste_size(InkscapeApplication *app)
void edit_delete(InkscapeApplication *app)
void remove_path_effect(InkscapeApplication *app)
New node tool with support for multiple path editing.
SPGuide – a guideline.
SPDesktop * desktop
TextTool.