Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actions-edit-document.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
15
16#include <glibmm/i18n.h>
17
18#include "document.h"
19#include "document-undo.h"
21#include "selection-chemistry.h"
22
24#include "object/sp-guide.h"
25#include "object/sp-namedview.h"
26#include "xml/node.h"
27
28void
30{
31 // Create Guides Around the Page
33}
34
35void
37{
38 document->getNamedView()->toggleLockGuides();
39}
40
41void
43{
44 document->getNamedView()->toggleShowGuides();
45}
46
47void
49{
50 // Delete All Guides
52}
53
54void
56{
57 // Fit Page to Drawing
58 if (fit_canvas_to_drawing(document)) {
59 Inkscape::DocumentUndo::done(document, _("Fit Page to Drawing"), "");
60 }
61}
62
63void
64set_display_unit(Glib::ustring abbr, SPDocument* document)
65{
66 // This does not modify the scale of the document, just the units
67 Inkscape::XML::Node *repr = document->getNamedView()->getRepr();
68 repr->setAttribute("inkscape:document-units", abbr);
69 document->setModifiedSinceSave();
70 Inkscape::DocumentUndo::done(document, _("Changed default display unit"), "");
71}
72
74 if (!document || !document->getNamedView()) return;
75
76 auto clip = !document->getNamedView()->clip_to_page;
78 document->setModifiedSinceSave();
79 Inkscape::DocumentUndo::done(document, _("Clip to page"), "");
80}
81
82void
84{
85 document->getNamedView()->toggleShowGrids();
86}
87
88const Glib::ustring SECTION = NC_("Action Section", "Edit Document");
89
90std::vector<std::vector<Glib::ustring>> raw_data_edit_document = {
91 // clang-format off
92 {"doc.create-guides-around-page", N_("Create Guides Around the Current Page"), SECTION, N_("Create four guides aligned with the page borders of the current page")},
93 {"doc.lock-all-guides", N_("Lock All Guides"), SECTION, N_("Toggle lock of all guides in the document")},
94 {"doc.show-all-guides", N_("Show All Guides"), SECTION, N_("Toggle visibility of all guides in the document")},
95 {"doc.delete-all-guides", N_("Delete All Guides"), SECTION, N_("Delete all the guides in the document")},
96 {"doc.fit-canvas-to-drawing", N_("Fit Page to Drawing"), SECTION, N_("Fit the page to the drawing")},
97 {"doc.clip-to-page", N_("Toggle Clip to Page"), SECTION, N_("Toggle between clipped to page and complete rendering")},
98 {"doc.show-grids", N_("Show Grids"), SECTION, N_("Toggle the visibility of grids")},
99 // clang-format on
100};
101
102void
104{
105 Glib::RefPtr<Gio::SimpleActionGroup> map = document->getActionGroup();
106
107 // clang-format off
108 map->add_action( "create-guides-around-page", sigc::bind(sigc::ptr_fun(&create_guides_around_page), document));
109 map->add_action( "delete-all-guides", sigc::bind(sigc::ptr_fun(&delete_all_guides), document));
110 map->add_action( "fit-canvas-to-drawing", sigc::bind(sigc::ptr_fun(&fit_canvas_drawing), document));
111 map->add_action_bool( "lock-all-guides", sigc::bind(sigc::ptr_fun(&lock_all_guides), document));
112 map->add_action_bool( "show-all-guides", sigc::bind(sigc::ptr_fun(&show_all_guides), document));
113 map->add_action_bool( "show-grids", sigc::bind(sigc::ptr_fun(&show_grids), document));
114
115 map->add_action_radio_string("set-display-unit", sigc::bind(sigc::ptr_fun(&set_display_unit), document), "px");
116 map->add_action("clip-to-page", [=](){ toggle_clip_to_page(document); });
117 // clang-format on
118
119 // Check if there is already an application instance (GUI or non-GUI).
121 if (!app) { // i.e. Inkview
122 return;
123 }
124 app->get_action_extra_data().add_data(raw_data_edit_document);
125}
std::vector< std::vector< Glib::ustring > > raw_data_edit_document
void show_all_guides(SPDocument *document)
const Glib::ustring SECTION
void fit_canvas_drawing(SPDocument *document)
void delete_all_guides(SPDocument *document)
void create_guides_around_page(SPDocument *document)
void show_grids(SPDocument *document)
void toggle_clip_to_page(SPDocument *document)
void add_actions_edit_document(SPDocument *document)
void lock_all_guides(SPDocument *document)
void set_display_unit(Glib::ustring abbr, SPDocument *document)
Authors: Sushant A A sushant.co19@gmail.com
@ INKSCAPE_CLIP_TO_PAGE_RENDERING
static InkscapeApplication * instance()
Singleton instance.
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
Interface for refcounted XML nodes.
Definition node.h:80
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
Typed SVG document implementation.
Definition document.h:101
Glib::RefPtr< Gio::SimpleActionGroup > getActionGroup()
Definition document.h:371
void setModifiedSinceSave(bool const modified=true)
Indicate to the user if the document has been modified since the last save by displaying a "*" in fro...
SPNamedView * getNamedView()
Get the namedview for this document, creates it if it's not found.
Definition document.cpp:234
void toggleLockGuides()
void toggleShowGuides()
void toggleShowGrids()
SVGBool clip_to_page
void change_bool_setting(SPAttr key, bool value)
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
TODO: insert short description here.
static T clip(T const &v, T const &a, T const &b)
bool fit_canvas_to_drawing(SPDocument *doc, bool with_margins)
void sp_guide_create_guides_around_page(SPDocument *doc)
Definition sp-guide.cpp:275
void sp_guide_delete_all_guides(SPDocument *doc)
Definition sp-guide.cpp:290
SPGuide – a guideline.
Interface for XML nodes.