17#include <glibmm/fileutils.h>
18#include <glibmm/miscutils.h>
41 :
Extension(in_repr,
std::move(implementation), base_directory)
43 , _prefDialog(nullptr)
58 if (!strcmp(this->
get_id(),
"org.inkscape.filter.dropshadow"))
68 if (
repr !=
nullptr) {
71 if (strcmp(
child->name(), INKSCAPE_EXTENSION_NS
"effect"))
continue;
73 if (
child->attribute(
"needs-document") && !strcmp(
child->attribute(
"needs-document"),
"false")) {
76 if (
child->attribute(
"needs-live-preview") && !strcmp(
child->attribute(
"needs-live-preview"),
"false")) {
79 if (
child->attribute(
"implements-custom-gui") && !strcmp(
child->attribute(
"implements-custom-gui"),
"true")) {
83 for (
auto effect_child =
child->firstChild(); effect_child !=
nullptr; effect_child = effect_child->next()) {
84 if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"effects-menu")) {
86 if (effect_child->attribute(
"hidden") && !strcmp(effect_child->attribute(
"hidden"),
"true")) {
90 if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"menu-tip") ||
91 !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS
"_menu-tip")) {
92 _menu_tip = effect_child->firstChild()->content();
94 if (
streq(effect_child->name(), INKSCAPE_EXTENSION_NS
"icon")) {
95 _icon_path = effect_child->firstChild()->content();
110 std::string
id =
get_id();
111 auto allowed = [] (
char ch) {
113 if (
'A' <= ch && ch <=
'Z')
return true;
114 if (
'a' <= ch && ch <=
'z')
return true;
115 if (
'0' <= ch && ch <=
'9')
return true;
116 if (ch ==
'.' || ch ==
'-')
return true;
121 std::replace(
id.begin(),
id.
end(),
'_',
'-');
124 bool errored =
false;
125 for (
auto &ch :
id) {
128 auto message = std::string{
"Invalid extension action ID found: \""} +
id +
"\".";
129 g_warn_message(
"Inkscape", __FILE__, __LINE__,
"Effect::_sanitizeId()", message.c_str());
145 Glib::ustring merge_name;
147 gchar
const *menu_name = pattern->
attribute(
"name");
158 merge_name = _(menu_name);
162 sub_menu_list.push_back(merge_name);
208 if (!
loaded())
return false;
210 Glib::ustring name = this->
get_name();
239 if (executionEnv.
wait()) {
266 if (menustruct ==
nullptr)
return nullptr;
270 if (!strcmp(
child->name(), name)) {
274 if (firstchild !=
nullptr) {
314 auto path = Glib::build_filename(dir,
_icon_path);
324 auto path = Glib::build_filename(dir, filename +
".svg");
330 std::string
id =
get_id();
331 auto path = Glib::build_filename(dir,
"icons",
id +
".svg");
338 return std::string();
358 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, if it exists (will not create it)
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
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)
ExecutionEnv * execution_env
Execution environment of the extension (currently only used by Effects)
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 * 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 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)
bool file_test(char const *utf8name, GFileTest test)
CMYK to sRGB conversion routines.
TODO: insert short description here.
bool streq(char const *a, char const *b)
Convenience/readability wrapper for strcmp(a,b)==0.