diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-11 19:14:07 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:39 +0000 |
| commit | 8521b08ed46742684e6de7de085a9c4228b66881 (patch) | |
| tree | 3af08ba11eacc95844b36268ac5df71d2daf99f2 /src/extension | |
| parent | Templates: Improve translatability for "More info" dialog (diff) | |
| download | inkscape-8521b08ed46742684e6de7de085a9c4228b66881.tar.gz inkscape-8521b08ed46742684e6de7de085a9c4228b66881.zip | |
Add base_directory for extensions loaded from a file.
Diffstat (limited to 'src/extension')
| -rw-r--r-- | src/extension/effect.cpp | 10 | ||||
| -rw-r--r-- | src/extension/effect.h | 13 | ||||
| -rw-r--r-- | src/extension/extension.cpp | 9 | ||||
| -rw-r--r-- | src/extension/extension.h | 9 | ||||
| -rw-r--r-- | src/extension/input.cpp | 3 | ||||
| -rw-r--r-- | src/extension/input.h | 9 | ||||
| -rw-r--r-- | src/extension/output.cpp | 3 | ||||
| -rw-r--r-- | src/extension/output.h | 9 | ||||
| -rw-r--r-- | src/extension/patheffect.cpp | 4 | ||||
| -rw-r--r-- | src/extension/patheffect.h | 6 | ||||
| -rw-r--r-- | src/extension/print.cpp | 4 | ||||
| -rw-r--r-- | src/extension/print.h | 8 | ||||
| -rw-r--r-- | src/extension/system.cpp | 14 |
13 files changed, 57 insertions, 44 deletions
diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 976c26192..db00a77a9 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -34,11 +34,11 @@ Inkscape::XML::Node * Effect::_filters_list = nullptr; #define EFFECTS_LIST "effects-list" #define FILTERS_LIST "filters-list" -Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) - : Extension(in_repr, in_imp), - _verb(get_id(), get_name(), nullptr, nullptr, this, true), - _menu_node(nullptr), _workingDialog(true), - _prefDialog(nullptr) +Effect::Effect (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) + : Extension(in_repr, in_imp, base_directory) + , _verb(get_id(), get_name(), nullptr, nullptr, this, true) + , _menu_node(nullptr), _workingDialog(true) + , _prefDialog(nullptr) { Inkscape::XML::Node * local_effects_menu = nullptr; diff --git a/src/extension/effect.h b/src/extension/effect.h index 2312bb838..39412dda5 100644 --- a/src/extension/effect.h +++ b/src/extension/effect.h @@ -68,7 +68,7 @@ class Effect : public Extension { Effect * effect, bool showPrefs) : Verb(id, _(name), _(tip), image, _("Extensions")), - _effect(effect), + _effect(effect), _showPrefs(showPrefs), _elip_name(nullptr) { /* No clue why, but this is required */ @@ -78,7 +78,7 @@ class Effect : public Extension { set_name(_elip_name); } } - + /** \brief Destructor */ ~EffectVerb() override { if (_elip_name != nullptr) { @@ -97,10 +97,11 @@ class Effect : public Extension { /** \brief The preference dialog if it is shown */ PrefDialog * _prefDialog; public: - Effect (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - ~Effect () override; - bool check () override; + Effect(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + ~Effect () override; + + bool check() override; + bool prefs (Inkscape::UI::View::View * doc); void effect (Inkscape::UI::View::View * doc); /** \brief Accessor function for a pointer to the verb */ diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 68a697a8c..7836a8479 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -48,7 +48,8 @@ std::ofstream Extension::error_file; /** \return none \brief Constructs an Extension from a Inkscape::XML::Node - \param in_repr The repr that should be used to build it + \param in_repr The repr that should be used to build it + \param base_directory Base directory of extension that were loaded from a file (.inx file's location) This function is the basis of building an extension for Inkscape. It currently extracts the fields from the Repr that are used in the @@ -56,7 +57,7 @@ std::ofstream Extension::error_file; not related to the module directly. If the Repr does not include a name and an ID the module will be left in an errored state. */ -Extension::Extension (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp) +Extension::Extension(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) : _gui(true) , execution_env(nullptr) { @@ -70,6 +71,10 @@ Extension::Extension (Inkscape::XML::Node *in_repr, Implementation::Implementati imp = in_imp; } + if (base_directory) { + _base_directory = *base_directory; + } + // get name of the translation catalog ("gettext textdomain") that the extension wants to use for translations const char *translationdomain = repr->attribute("translationdomain"); if (translationdomain) { diff --git a/src/extension/extension.h b/src/extension/extension.h index 6adcf15a7..d28ba2efc 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -121,15 +121,16 @@ protected: Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */ ExecutionEnv * execution_env; /**< Execution environment of the extension * (currently only used by Effects) */ + std::string _base_directory; /**< Directory containing the .inx file, + * relative paths in the extension should usually be relative to it */ ExpirationTimer * timer = nullptr; /**< Timeout to unload after a given time */ bool _translation_enabled = true; /**< Attempt translation of strings provided by the extension? */ const char *_translationdomain = nullptr; /**< Domainname of gettext textdomain that should * be used for translation of the extension's strings */ public: - Extension (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - virtual ~Extension (); + Extension(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + virtual ~Extension(); void set_state (state_t in_state); state_t get_state (); @@ -144,6 +145,8 @@ public: Implementation::Implementation * get_imp () { return imp; }; void set_execution_env (ExecutionEnv * env) { execution_env = env; }; ExecutionEnv *get_execution_env () { return execution_env; }; + std::string get_base_directory() { return _base_directory; }; + void set_base_directory(std::string base_directory) { _base_directory = base_directory; }; const char *get_translation(const char* msgid, const char *msgctxt=nullptr); /* Parameter Stuff */ diff --git a/src/extension/input.cpp b/src/extension/input.cpp index 762aee35b..ef3a9a5b5 100644 --- a/src/extension/input.cpp +++ b/src/extension/input.cpp @@ -40,7 +40,8 @@ namespace Extension { Overall, there are many levels of indentation, just to handle the levels of indentation in the XML file. */ -Input::Input (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp) +Input::Input (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) + : Extension(in_repr, in_imp, base_directory) { mimetype = nullptr; extension = nullptr; diff --git a/src/extension/input.h b/src/extension/input.h index 6d5e8a2f3..5952c3c04 100644 --- a/src/extension/input.h +++ b/src/extension/input.h @@ -44,10 +44,11 @@ public: const char *what() const noexcept override { return "Open was cancelled"; } }; - Input (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - ~Input () override; - bool check () override; + Input(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + ~Input() override; + + bool check() override; + SPDocument * open (gchar const *uri); gchar * get_mimetype (); gchar * get_extension (); diff --git a/src/extension/output.cpp b/src/extension/output.cpp index 0977b9576..07c1120e7 100644 --- a/src/extension/output.cpp +++ b/src/extension/output.cpp @@ -41,7 +41,8 @@ namespace Extension { Overall, there are many levels of indentation, just to handle the levels of indentation in the XML file. */ -Output::Output (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp) +Output::Output (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) + : Extension(in_repr, in_imp, base_directory) { mimetype = nullptr; extension = nullptr; diff --git a/src/extension/output.h b/src/extension/output.h index 157a3f72d..8210858ea 100644 --- a/src/extension/output.h +++ b/src/extension/output.h @@ -38,10 +38,11 @@ public: export_id_not_found(const gchar * const id = nullptr) : id{id} {}; }; - Output (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - ~Output () override; - bool check () override; + Output(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + ~Output () override; + + bool check() override; + void save (SPDocument *doc, gchar const *filename, bool detachbase = false); diff --git a/src/extension/patheffect.cpp b/src/extension/patheffect.cpp index 6a347881f..3ed53e74e 100644 --- a/src/extension/patheffect.cpp +++ b/src/extension/patheffect.cpp @@ -21,8 +21,8 @@ namespace Inkscape { namespace Extension { -PathEffect::PathEffect (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) - : Extension(in_repr, in_imp) +PathEffect::PathEffect (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) + : Extension(in_repr, in_imp, base_directory) { } diff --git a/src/extension/patheffect.h b/src/extension/patheffect.h index 734f0c58a..b2dd7a029 100644 --- a/src/extension/patheffect.h +++ b/src/extension/patheffect.h @@ -20,9 +20,9 @@ namespace Extension { class PathEffect : public Extension { public: - PathEffect (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - ~PathEffect () override; + PathEffect(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + ~PathEffect() override; + void processPath (SPDocument * doc, Inkscape::XML::Node * path, Inkscape::XML::Node * def); diff --git a/src/extension/print.cpp b/src/extension/print.cpp index 32fb5ea2c..d9f7406ae 100644 --- a/src/extension/print.cpp +++ b/src/extension/print.cpp @@ -16,8 +16,8 @@ namespace Inkscape { namespace Extension { -Print::Print (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp) - : Extension(in_repr, in_imp) +Print::Print (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory) + : Extension(in_repr, in_imp, base_directory) , base(nullptr) , drawing(nullptr) , root(nullptr) diff --git a/src/extension/print.h b/src/extension/print.h index aaad3cf4e..56ec36700 100644 --- a/src/extension/print.h +++ b/src/extension/print.h @@ -33,10 +33,10 @@ public: /* TODO: These are public for the short term, but this should be fixed * unsigned int dkey; public: - Print (Inkscape::XML::Node * in_repr, - Implementation::Implementation * in_imp); - ~Print () override; - bool check () override; + Print(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory); + ~Print() override; + + bool check() override; /* FALSE means user hit cancel */ unsigned int setup (); diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 370e30f00..e81a7f973 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -511,28 +511,28 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation try { switch (module_functional_type) { case MODULE_INPUT: { - module = new Input(repr, imp); + module = new Input(repr, imp, baseDir); break; } case MODULE_OUTPUT: { - module = new Output(repr, imp); + module = new Output(repr, imp, baseDir); break; } case MODULE_FILTER: { - module = new Effect(repr, imp); + module = new Effect(repr, imp, baseDir); break; } case MODULE_PRINT: { - module = new Print(repr, imp); + module = new Print(repr, imp, baseDir); break; } case MODULE_PATH_EFFECT: { - module = new PathEffect(repr, imp); + module = new PathEffect(repr, imp, baseDir); break; } default: { - g_warning("Extension of unkonw type!"); // TODO: Should not happen! Is this even useful? - module = new Extension(repr, imp); + g_warning("Extension of unknown type!"); // TODO: Should not happen! Is this even useful? + module = new Extension(repr, imp, baseDir); break; } } |
