14#include <glibmm/i18n.h>
15#include <glibmm/fileutils.h>
16#include <glibmm/miscutils.h>
17#include <glibmm/regex.h>
40 , _visibility(mod->get_visibility())
44 _icon = mod->get_icon();
49 std::string
name = g_quark_to_string(iter.key);
50 std::string value = std::string(iter.value);
52 _name = value.empty() ?
"?" : value;
53 else if (
name ==
"label")
55 else if (
name ==
"desc")
57 else if (
name ==
"icon")
59 else if (
name ==
"priority")
61 else if (
name ==
"visibility") {
69 _key = std::string(mod->get_id()) +
"." +
_name;
70 transform(
_key.begin(),
_key.end(),
_key.begin(), ::tolower);
84 return filename.empty() ? default_icon : filename;
89 auto filename =
name +
".svg";
91 auto const filepath = Glib::build_filename(
"icons", filename);
93 if (!fullpath.empty())
return fullpath;
97 auto base_icon = Glib::build_filename(base,
"icons", filename);
98 if (Glib::file_test(base_icon, Glib::FileTest::EXISTS)) {
120 for (
auto pref :
_prefs) {
135 for (
auto pref : prefs) {
187 :
Extension(in_repr,
std::move(implementation), base_directory)
202 for (
const auto &iter : t_node->attributeList()) {
203 std::string
name = g_quark_to_string(iter.key);
204 std::string value = std::string(iter.value);
205 if (
name ==
"icon") {
207 }
else if (
name ==
"visibility") {
209 }
else if (
name ==
"priority") {
230 [](std::shared_ptr<TemplatePreset>
const &a,
231 std::shared_ptr<TemplatePreset>
const &b) {
232 return a->get_sort_priority() < b->get_sort_priority();
242 auto values = Glib::Regex::split_simple(
"," , value.c_str());
243 for (
auto const &val : values) {
283 auto doc =
imp->new_from_template(
this);
285 doc->setModifiedSinceSave(
false);
303 imp->resize_to_template(
this, doc,
page);
312 imp->get_template_presets(
this, all_presets);
315 for (
auto preset : all_presets) {
316 if (preset->is_visible(visibility)) {
317 ret.push_back(preset);
329 if (preset->get_key() ==
key) {
356 for (
auto tmod : extensions) {
357 if (
auto preset = tmod->get_preset(
key)) {
371 for (
auto tmod : extensions) {
372 if (!tmod->can_resize())
374 if (
auto preset = tmod->get_preset(
width,
height)) {
386 Glib::RefPtr<Gio::File> file;
390 file = Gio::File::create_for_path(filename);
395 file = Gio::File::create_for_path(filename);
398 g_error(
"Can not find default.svg template!");
TODO: insert short description here.
static void clearUndo(SPDocument *document)
TemplateList & get_template_list(TemplateList &ou_list)
Create a list of all the Template extensions.
std::list< Template * > TemplateList
An error class for when a parameter is looked for that just simply doesn't exist.
The object that is the basis for the Extension system.
@ STATE_LOADED
The extension has been loaded successfully.
Inkscape::XML::Node * repr
The XML description of the Extension.
ImplementationHolder imp
An Implementation object provides the actual implementation of the Extension.
virtual bool check()
A function to check the validity of the extension.
int get_sort_priority() const
void set_state(state_t in_state)
A function to set whether the extension should be loaded or unloaded.
auto const & get_base_directory() const
void set_param_hidden(char const *name, bool hidden)
bool loaded()
A quick function to test the state of the extension.
void set_sort_priority(int priority)
virtual bool prefs()
Create a dialog for preference for this extension.
void set_param_any(char const *name, std::string const &value)
Parses the given string value and sets a parameter identified by name.
TemplatePreset(Template *mod, const Inkscape::XML::Node *repr, TemplatePrefs prefs={}, int priority=0)
Parse the inx xml node for preset information.
void _add_prefs(const TemplatePrefs &prefs)
Called by setup_prefs to save the given prefs into this extension.
std::string _get_icon_path(std::string const &name) const
bool setup_prefs(const TemplatePrefs &others={})
Setup the preferences and ask the user to fill in the remaineder.
std::unique_ptr< SPDocument > new_from_template(TemplatePrefs const &others={})
Generate a new document from this preset.
std::string get_icon_path() const
void resize_to_template(SPDocument *doc, SPPage *page, const TemplatePrefs &others={})
Resize the given page to however the page format requires it to be.
bool match_size(double width, double height, const TemplatePrefs &others={})
Reverse match for templates, allowing page duplication and labeling.
bool is_visible(TemplateShow mode)
static std::shared_ptr< TemplatePreset > get_any_preset(const std::string &key)
Return the template preset based on the key from any template class (static method).
void resize_to_template(SPDocument *doc, SPPage *page)
Takes an existing page and resizes it to the required dimentions.
Glib::RefPtr< Gio::File > get_template_filename() const
Get the template filename, or return the default template.
friend class TemplatePreset
Template(Inkscape::XML::Node *in_repr, ImplementationHolder implementation, std::string *base_directory)
Builds a Template object from a XML description.
bool check() override
Validate this extension.
std::unique_ptr< SPDocument > new_from_template()
This function creates a document from a template.
std::shared_ptr< TemplatePreset > get_preset(const std::string &key)
Return the template preset based on the key from this template class.
static int parse_visibility(const std::string &value)
Parse the expected value for the visibility value, turn into enum.
std::unique_ptr< SPDocument > get_template_document() const
Get the raw document svg for this template (pre-processing).
TemplatePresets get_presets(TemplateShow visibility=TEMPLATE_ANY) const
Return a list of all template presets.
Interface for refcounted XML nodes.
virtual const AttributeVector & attributeList() const =0
Get a list of the node's attributes.
Typed SVG document implementation.
TODO: insert short description here.
std::unique_ptr< SPDocument > ink_file_new(std::string const &Template)
Create a blank document, remove any template data.
DB db
This is the actual database object.
std::map< std::string, std::string > TemplatePrefs
std::vector< std::shared_ptr< TemplatePreset > > TemplatePresets
std::string get_filename(Type type, char const *filename, bool localized, bool silent)
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
std::vector< Inkscape::XML::Node const * > sp_repr_lookup_name_many(Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth)
Glib::ustring sp_repr_lookup_content(Inkscape::XML::Node const *repr, gchar const *name, Glib::ustring otherwise)
Inkscape::XML::Node const * sp_repr_lookup_name(Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth)
C facade to Inkscape::XML::Node.
Inkscape::IO::Resource - simple resource API.