17#include <glibmm/fileutils.h>
18#include <glibmm/miscutils.h>
42 :
Extension(in_repr,
std::move(implementation), base_directory)
44 , _prefDialog(nullptr)
59 if (!strcmp(this->
get_id(),
"org.inkscape.filter.dropshadow"))
69 if (
repr !=
nullptr) {
72 if (strcmp(
child->name(), INKSCAPE_EXTENSION_NS
"effect"))
continue;
74 if (
child->attribute(
"needs-document") && !strcmp(
child->attribute(
"needs-document"),
"false")) {
77 if (
child->attribute(
"needs-live-preview") && !strcmp(
child->attribute(
"needs-live-preview"),
"false")) {
80 if (
child->attribute(
"implements-custom-gui") && !strcmp(
child->attribute(
"implements-custom-gui"),
"true")) {
82 if (!(
child->attribute(
"show-stderr") && !strcmp(
child->attribute(
"show-stderr"),
"true"))) {
85 if (
child->attribute(
"pipe-diffs") && !strcmp(
child->attribute(
"pipe-diffs"),
"true")) {
89 for (
auto effect_child =
child->firstChild(); effect_child !=
nullptr; effect_child = effect_child->next()) {
90 if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"effects-menu")) {
92 if (effect_child->attribute(
"hidden") && !strcmp(effect_child->attribute(
"hidden"),
"true")) {
96 if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"menu-tip") ||
97 !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"_menu-tip")) {
100 if (
streq(effect_child->name(), INKSCAPE_EXTENSION_NS
"icon")) {
101 _icon_path = effect_child->firstChild()->content();
116 std::string
id =
get_id();
117 auto allowed = [] (
char ch) {
119 if (
'A' <= ch && ch <=
'Z')
return true;
120 if (
'a' <= ch && ch <=
'z')
return true;
121 if (
'0' <= ch && ch <=
'9')
return true;
122 if (ch ==
'.' || ch ==
'-')
return true;
127 std::replace(
id.begin(),
id.
end(),
'_',
'-');
130 bool errored =
false;
131 for (
auto &ch : id) {
134 auto message = std::string{
"Invalid extension action ID found: \""} +
id +
"\".";
135 g_warn_message(
"Inkscape", __FILE__, __LINE__,
"Effect::_sanitizeId()", message.c_str());
151 Glib::ustring merge_name;
153 gchar
const *menu_name = pattern->
attribute(
"name");
164 merge_name = _(menu_name);
168 sub_menu_list.push_back(merge_name);
214 if (!
loaded())
return false;
245 if (executionEnv.
wait()) {
272 if (menustruct ==
nullptr)
return nullptr;
280 if (firstchild !=
nullptr) {
320 auto path = Glib::build_filename(dir,
_icon_path);
321 if (Glib::file_test(path, Glib::FileTest::IS_REGULAR)) {
330 auto path = Glib::build_filename(dir, filename +
".svg");
331 if (Glib::file_test(path, Glib::FileTest::IS_REGULAR)) {
336 std::string
id =
get_id();
337 auto path = Glib::build_filename(dir,
"icons",
id +
".svg");
338 if (Glib::file_test(path, Glib::FileTest::IS_REGULAR)) {
344 return std::string();
364 std::list<Glib::ustring> menu;
void enable_effect_actions(InkscapeApplication *app, bool enabled)
Authors: Sushant A A sushant.co19@gmail.com
static InkscapeApplication * instance()
Singleton instance.
static bool exists()
Checks whether the current Inkscape::Application global object exists.
Effects are extensions that take a document and do something to it in place.
bool ignore_stderr
If stderr log should be shown, when process return code is 0.
Effect(Inkscape::XML::Node *in_repr, ImplementationHolder implementation, std::string *base_directory, std::string *file_name)
void set_pref_dialog(PrefDialog *prefdialog)
PrefDialog * _prefDialog
The preference dialog if it is shown.
static void set_last_effect(Effect *in_effect)
Sets which effect was called last.
void get_menu(Inkscape::XML::Node *pattern, std::list< Glib::ustring > &sub_menu_list) const
bool hidden_from_menu() const
void deactivate() override
This function diactivates the extension (which makes it unusable, but not deleted)
Inkscape::XML::Node * _menu_node
Menu node created for this effect.
Inkscape::XML::Node * find_menu(Inkscape::XML::Node *menustruct, const gchar *name)
Inkscape::XML::Node * _local_effects_menu
PrefDialog * get_pref_dialog()
std::string find_icon_file(const std::string &default_dir) const
const Glib::ustring & get_menu_tip() const
bool pipe_diffs
If changesets should be piped in via stdin.
static Effect * get_last_effect()
Static function to get the last effect used.
bool apply_filter(SPItem *item)
bool is_filter_effect() const
static Effect * _last_effect
This is the last effect that was used.
std::string get_sanitized_id() const
Sanitizes the id and returns.
std::list< Glib::ustring > get_menu_list() const
void effect(SPDesktop *desktop, SPDocument *document=nullptr)
The function that 'does' the effect itself.
Gtk::Box * get_info_widget()
bool _workingDialog
Whether a working dialog should be shown.
bool wait()
Wait for the effect to complete if it hasn't.
void set_document(SPDocument *document)
void commit()
Commit the changes to the document.
void cancel()
Cancel the execution of the effect.
void run()
Starts the execution of the effect.
The object that is the basis for the Extension system.
virtual void deactivate()
This function diactivates the extension (which makes it unusable, but not deleted)
char const * get_translation(char const *msgid, char const *msgctxt=nullptr) const
Gets a translation within the context of the current extension.
std::unique_ptr< ExpirationTimer > timer
Timeout to unload after a given time.
@ STATE_LOADED
The extension has been loaded successfully.
unsigned int widget_visible_count() const
A function to get the number of visible parameters of the extension.
char const * get_name() const
Get the name of this extension - not a copy don't delete!
Implementation::Implementation * get_imp()
Inkscape::XML::Node * repr
The XML description of the Extension.
ImplementationHolder imp
An Implementation object provides the actual implementation of the Extension.
char const * get_id() const
Get the ID of this extension - not a copy don't delete!
void set_state(state_t in_state)
A function to set whether the extension should be loaded or unloaded.
bool _translation_enabled
Attempt translation of strings provided by the extension?
bool loaded()
A quick function to test the state of the extension.
std::string _base_directory
Directory containing the .inx file, relative paths in the extension should usually be relative to it.
Gtk::Box * get_info_widget()
virtual bool prefs()
Create a dialog for preference for this extension.
virtual bool apply_filter(Inkscape::Extension::Effect *module, SPItem *item)
A class to represent the preferences for an extension.
Interface for refcounted XML nodes.
virtual Node * parent()=0
Get the parent of this node.
virtual Node * next()=0
Get the next sibling of this node.
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
virtual char const * content() const =0
Get the content of a text or comment node.
virtual void removeChild(Node *child)=0
Remove a child of this node.
To do: update description of desktop.
Typed SVG document implementation.
Base class for visual SVG elements.
static R & release(R &r)
Decrements the reference count of a anchored object.
Glib::ustring get_file_extension(Glib::ustring const &path)
Helper class to stream background task notifications as a series of messages.
TODO: insert short description here.
bool streq(char const *a, char const *b)
Convenience/readability wrapper for strcmp(a,b)==0.
Document was closed during execution of async extension.