Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-selection-object.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
14/*
15 * Note: Actions must be app level as different windows can have different selections
16 * and selections must also work from the command line (without GUI).
17 */
18
19#include <giomm.h>
20#include <glibmm/i18n.h>
21
23#include "actions-helper.h"
24#include "document-undo.h"
26#include "page-manager.h"
27#include "selection.h"
28
29#include "ui/dialog/dialog-container.h" // Used by select_object_link() to open dialog to add hyperlink.
30#include "ui/icon-names.h"
31
32void
34{
35 Inkscape::Selection *selection = app->get_active_selection();
36 selection->group();
37 Inkscape::DocumentUndo::done(selection->document(), C_("Verb", "Group"), INKSCAPE_ICON("object-group"));
38}
39
40void
42{
43 Inkscape::Selection *selection = app->get_active_selection();
44
45 selection->ungroup();
46 Inkscape::DocumentUndo::done(selection->document(), _("Ungroup"), INKSCAPE_ICON("object-ungroup"));
47}
48
49void
51{
52 Inkscape::Selection *selection = app->get_active_selection();
53
54 // Pop Selected Objects out of Group
55 selection->popFromGroup();
56}
57
58void
60{
61 Inkscape::Selection *selection = app->get_active_selection();
62
63 // Group with <a>
64 auto anchor = selection->group(true);
65 selection->set(anchor);
66
67 // Open dialog to set link.
68 selection->desktop()->getContainer()->new_dialog("ObjectProperties");
69 Inkscape::DocumentUndo::done(selection->document(), _("Anchor"), INKSCAPE_ICON("object-group"));
70}
71
72void
74{
75 Inkscape::Selection *selection = app->get_active_selection();
76
77 // Raise to Top
78 selection->raiseToTop();
79}
80
81void
83{
84 Inkscape::Selection *selection = app->get_active_selection();
85
86 // Raise
87 selection->raise();
88}
89
90void
92{
93 Inkscape::Selection *selection = app->get_active_selection();
94
95 // Lower
96 selection->lower();
97}
98
99void
101{
102 Inkscape::Selection *selection = app->get_active_selection();
103
104 // Lower to Bottom
105 selection->lowerToBottom();
106}
107
108void
110{
111 auto selection = app->get_active_selection();
112 selection->stackUp();
113}
114
115void
117{
118 auto selection = app->get_active_selection();
119 selection->stackDown();
120}
121
122void
124{
125 auto selection = app->get_active_selection();
126
127 // Make a Bitmap Copy
128 selection->createBitmapCopy();
129}
130
131void
133{
134 SPDocument* document = nullptr;
135 Inkscape::Selection* selection = nullptr;
136 if (!get_document_and_selection(app, &document, &selection)) {
137 return;
138 }
139
140 document->getPageManager().fitToSelection(selection);
141 Inkscape::DocumentUndo::done(document, _("Resize page to fit"), INKSCAPE_ICON("tool-pages"));
142}
143
144const Glib::ustring SECTION_SELECT = NC_("Action Section", "Select");
145const Glib::ustring SECTION_PAGE = NC_("Action Section", "Page");
146
147std::vector<std::vector<Glib::ustring>> raw_data_selection_object =
148{
149 // clang-format off
150 { "app.selection-group", NC_("Verb", "Group"), SECTION_SELECT, N_("Group selected objects")},
151 { "app.selection-ungroup", N_("Ungroup"), SECTION_SELECT, N_("Ungroup selected objects")},
152 { "app.selection-ungroup-pop", N_("Pop Selected Objects out of Group"), SECTION_SELECT, N_("Pop selected objects out of group")},
153 { "app.selection-link", NC_("Hyperlink|Verb", "Link"), SECTION_SELECT, N_("Add an anchor to selected objects")},
154
155 { "app.selection-top", N_("Raise to Top"), SECTION_SELECT, N_("Raise selection to top")},
156 { "app.selection-raise", N_("Raise"), SECTION_SELECT, N_("Raise selection one step")},
157 { "app.selection-lower", N_("Lower"), SECTION_SELECT, N_("Lower selection one step")},
158 { "app.selection-bottom", N_("Lower to Bottom"), SECTION_SELECT, N_("Lower selection to bottom")},
159
160 { "app.selection-stack-up", N_("Move up the Stack"), SECTION_SELECT, N_("Move the selection up in the stack order")},
161 { "app.selection-stack-down", N_("Move down the Stack"), SECTION_SELECT, N_("Move the selection down in the stack order")},
162
163 { "app.selection-make-bitmap-copy", N_("Make a Bitmap Copy"), SECTION_SELECT, N_("Export selection to a bitmap and insert it into document")},
164 { "app.page-fit-to-selection", N_("Resize Page to Selection"), SECTION_PAGE, N_("Fit the page to the current selection or the drawing if there is no selection")}
165 // clang-format on
166};
167
168void
170{
171 auto *gapp = app->gio_app();
172
173 // clang-format off
174 // See actions-layer.cpp for "enter-group" and "exit-group".
175 gapp->add_action( "selection-group", sigc::bind(sigc::ptr_fun(&select_object_group), app));
176 gapp->add_action( "selection-ungroup", sigc::bind(sigc::ptr_fun(&select_object_ungroup), app));
177 gapp->add_action( "selection-ungroup-pop", sigc::bind(sigc::ptr_fun(&select_object_ungroup_pop), app));
178 gapp->add_action( "selection-link", sigc::bind(sigc::ptr_fun(&select_object_link), app));
179
180 gapp->add_action( "selection-top", sigc::bind(sigc::ptr_fun(&selection_top), app));
181 gapp->add_action( "selection-raise", sigc::bind(sigc::ptr_fun(&selection_raise), app));
182 gapp->add_action( "selection-lower", sigc::bind(sigc::ptr_fun(&selection_lower), app));
183 gapp->add_action( "selection-bottom", sigc::bind(sigc::ptr_fun(&selection_bottom), app));
184
185 gapp->add_action( "selection-stack-up", sigc::bind(sigc::ptr_fun(&selection_stack_up), app));
186 gapp->add_action( "selection-stack-down", sigc::bind(sigc::ptr_fun(&selection_stack_down), app));
187
188 gapp->add_action( "selection-make-bitmap-copy", sigc::bind(sigc::ptr_fun(&selection_make_bitmap_copy), app));
189 gapp->add_action( "page-fit-to-selection", sigc::bind(sigc::ptr_fun(&page_fit_to_selection), app));
190 // clang-format on
191
193}
bool get_document_and_selection(InkscapeApplication *app, SPDocument **document, Inkscape::Selection **selection)
void selection_make_bitmap_copy(InkscapeApplication *app)
void selection_stack_up(InkscapeApplication *app)
void selection_stack_down(InkscapeApplication *app)
const Glib::ustring SECTION_SELECT
void selection_lower(InkscapeApplication *app)
void selection_raise(InkscapeApplication *app)
void add_actions_selection_object(InkscapeApplication *app)
void select_object_ungroup_pop(InkscapeApplication *app)
void select_object_ungroup(InkscapeApplication *app)
void selection_bottom(InkscapeApplication *app)
void select_object_link(InkscapeApplication *app)
void selection_top(InkscapeApplication *app)
const Glib::ustring SECTION_PAGE
std::vector< std::vector< Glib::ustring > > raw_data_selection_object
void select_object_group(InkscapeApplication *app)
void page_fit_to_selection(InkscapeApplication *app)
Authors: Sushant A A sushant.co19@gmail.com
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.
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)
Inkscape::XML::Node * group(bool is_anchor=false)
void stackDown(bool skip_undo=false)
SPDesktop * desktop()
Returns the desktop the selection is bound to.
Definition object-set.h:390
void raiseToTop(bool skip_undo=false)
void stackUp(bool skip_undo=false)
void ungroup(bool skip_undo=false)
SPDocument * document()
Returns the document the selection is bound to.
Definition object-set.h:397
void raise(bool skip_undo=false)
void lowerToBottom(bool skip_undo=false)
void lower(bool skip_undo=false)
void fitToSelection(ObjectSet *selection, bool add_margins=true)
Resize the page to the given selection.
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
void set(XML::Node *repr)
Set the selection to an XML node's SPObject.
Definition selection.h:118
void new_dialog(const Glib::ustring &dialog_type)
Add new dialog to the current container or in a floating window, based on preferences.
Inkscape::UI::Dialog::DialogContainer * getContainer()
Definition desktop.cpp:335
Typed SVG document implementation.
Definition document.h:101
Inkscape::PageManager & getPageManager()
Definition document.h:162
A widget that manages DialogNotebook's and other widgets inside a horizontal DialogMultipaned.
TODO: insert short description here.
Macro for icon names used in Inkscape.