X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Fextension.cpp;h=e67a4b95f65c84acfa2d864272dcba50cc2648c0;hb=9e3c85629496fe7ebe4296acb751b5b900c10e5b;hp=84f09aedb37b644f44f79a43606f84160ea8a97b;hpb=ff20ae64b6f76bc64725c72cbf7744eb2c25eb33;p=inkscape.git diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 84f09aedb..e67a4b95f 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -34,7 +34,7 @@ #include "db.h" #include "dependency.h" #include "timer.h" -#include "parameter.h" +#include "param/parameter.h" namespace Inkscape { namespace Extension { @@ -44,7 +44,7 @@ namespace Extension { std::vector Extension::search_path; std::ofstream Extension::error_file; -Parameter * param_shared (const gchar * name, GSList * list); +Parameter * get_param (const gchar * name); /** \return none @@ -57,7 +57,9 @@ Parameter * param_shared (const gchar * name, GSList * list); 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) : _help(NULL) +Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) + : _help(NULL) + , _gui(true) { repr = in_repr; Inkscape::GC::anchor(in_repr); @@ -79,6 +81,9 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat /* TODO: Handle what happens if we don't have these two */ while (child_repr != NULL) { char const * chname = child_repr->name(); + if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { + chname += strlen(INKSCAPE_EXTENSION_NS); + } if (chname[0] == '_') /* Allow _ for translation of tags */ chname++; if (!strcmp(chname, "id")) { @@ -288,10 +293,10 @@ Extension::check (void) void Extension::printFailure (Glib::ustring reason) { - error_file << _("Extension \"") << name << _("\" failed to load because "); - error_file << reason.raw(); - error_file << std::endl; - return; + error_file << _("Extension \"") << name << _("\" failed to load because "); + error_file << reason.raw(); + error_file << std::endl; + return; } /** @@ -367,45 +372,45 @@ Extension::deactivated (void) \brief This function looks through the linked list for a parameter structure with the name of the passed in name \param name The name to search for - \param list The list to look for This is an inline function that is used by all the get_param and set_param functions to find a param_t in the linked list with - the passed in name. It is done as an inline so that it will be - optimized into a 'jump' by the compiler. + the passed in name. This function can throw a 'param_not_exist' exception if the name is not found. The first thing that this function checks is if the list is NULL. It could be NULL because there are no parameters for this extension - or because all of them have been checked (I'll spoil the ending and - tell you that this function is called recursively). If the list + or because all of them have been checked. If the list is NULL then the 'param_not_exist' exception is thrown. - - Otherwise, the function looks at the current param_t that the element - list points to. If the name of that param_t matches the passed in - name then that param_t is returned. Otherwise, this function is - called again with g_slist_next as a parameter. */ Parameter * -param_shared (const gchar * name, GSList * list) +Extension::get_param (const gchar * name) { - Parameter * output; - if (name == NULL) { throw Extension::param_not_exist(); } - if (list == NULL) { + if (this->parameters == NULL) { + // the list of parameters is empty throw Extension::param_not_exist(); } - output = static_cast(list->data); - if (!strcmp(output->name(), name)) { - return output; + for (GSList * list = this->parameters; list != NULL; list = +g_slist_next(list)) { + Parameter * param = static_cast(list->data); + if (!strcmp(param->name(), name)) { + return param; + } else { + Parameter * subparam = param->get_param(name); + if (subparam) { + return subparam; + } + } } - return param_shared(name, g_slist_next(list)); + // if execution reaches here, no parameter matching 'name' was found + throw Extension::param_not_exist(); } /** @@ -423,18 +428,25 @@ const gchar * Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param; - - param = param_shared(name, parameters); + param = get_param(name); return param->get_string(doc, node); } const gchar * Extension::get_param_enum (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { - Parameter* param = param_shared(name, parameters); + Parameter* param = get_param(name); return param->get_enum(doc, node); } +gchar const * +Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node) +{ + Parameter* param = get_param(name); + return param->get_optiongroup(doc, node); +} + + /** \return The value of the parameter identified by the name \brief Gets a parameter identified by name with the bool placed @@ -450,8 +462,7 @@ bool Extension::get_param_bool (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param; - - param = param_shared(name, parameters); + param = get_param(name); return param->get_bool(doc, node); } @@ -470,8 +481,7 @@ int Extension::get_param_int (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param; - - param = param_shared(name, parameters); + param = get_param(name); return param->get_int(doc, node); } @@ -490,7 +500,7 @@ float Extension::get_param_float (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param; - param = param_shared(name, parameters); + param = get_param(name); return param->get_float(doc, node); } @@ -508,7 +518,7 @@ Extension::get_param_float (const gchar * name, const SPDocument * doc, const In guint32 Extension::get_param_color (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { - Parameter* param = param_shared(name, parameters); + Parameter* param = get_param(name); return param->get_color(doc, node); } @@ -528,7 +538,7 @@ bool Extension::set_param_bool (const gchar * name, bool value, SPDocument * doc, Inkscape::XML::Node * node) { Parameter * param; - param = param_shared(name, parameters); + param = get_param(name); return param->set_bool(value, doc, node); } @@ -548,7 +558,7 @@ int Extension::set_param_int (const gchar * name, int value, SPDocument * doc, Inkscape::XML::Node * node) { Parameter * param; - param = param_shared(name, parameters); + param = get_param(name); return param->set_int(value, doc, node); } @@ -568,7 +578,7 @@ float Extension::set_param_float (const gchar * name, float value, SPDocument * doc, Inkscape::XML::Node * node) { Parameter * param; - param = param_shared(name, parameters); + param = get_param(name); return param->set_float(value, doc, node); } @@ -588,10 +598,18 @@ const gchar * Extension::set_param_string (const gchar * name, const gchar * value, SPDocument * doc, Inkscape::XML::Node * node) { Parameter * param; - param = param_shared(name, parameters); + param = get_param(name); return param->set_string(value, doc, node); } +gchar const * +Extension::set_param_optiongroup(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) +{ + Parameter * param = get_param(name); + return param->set_optiongroup(value, doc, node); +} + + /** \return The passed in value \brief Sets a parameter identified by name with the string @@ -607,7 +625,7 @@ Extension::set_param_string (const gchar * name, const gchar * value, SPDocument guint32 Extension::set_param_color (const gchar * name, guint32 color, SPDocument * doc, Inkscape::XML::Node * node) { - Parameter* param = param_shared(name, parameters); + Parameter* param = get_param(name); return param->set_color(color, doc, node); } @@ -649,9 +667,9 @@ public: */ void addWidget (Gtk::Widget * widg, gchar const * tooltip) { if (widg == NULL) return; - this->pack_start(*widg, true, true, 2); + this->pack_start(*widg, false, false, 2); if (tooltip != NULL) { - _tooltips.set_tip(*widg, Glib::ustring(tooltip)); + _tooltips.set_tip(*widg, Glib::ustring(_(tooltip))); } return; }; @@ -664,22 +682,25 @@ public: function to get each widget. Then, each of those is placed into a Gtk::VBox, which is then returned to the calling function. - If there are no parameters, this function just returns NULL. + If there are no visible parameters, this function just returns NULL. + If all parameters are gui_visible = false NULL is returned as well. */ Gtk::Widget * Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) { - if (g_slist_length(parameters) == 0) return NULL; + if (!_gui || param_visible_count() == 0) return NULL; AutoGUI * agui = Gtk::manage(new AutoGUI()); + //go through the list of parameters to see if there are any non-hidden ones for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast(list->data); + if (param->get_gui_hidden()) continue; //Ignore hidden parameters Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); gchar const * tip = param->get_tooltip(); agui->addWidget(widg, tip); - } - + } + agui->show(); return agui; }; @@ -692,23 +713,9 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal &retlist) { - //std::list retarray; - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast(list->data); - - std::string param_string; - param_string += "--"; - param_string += param->name(); - param_string += "="; - Glib::ustring * out = param->string(); - param_string += *out; - delete out; - - retlist.insert(retlist.end(), param_string); - - // insert parameters subparameters if any (for example notebook parameter has subparams) - param->insert_subparam_strings(retlist); + param->string(retlist); } return; @@ -761,7 +768,7 @@ Extension::get_help_widget(void) Gtk::VBox * retval = Gtk::manage(new Gtk::VBox()); if (_help == NULL) { - Gtk::Label * content = Gtk::manage(new Gtk::Label("Currently there is no help available for this Extension. Please look on the Inkscape website or ask on the mailing lists if you have questions regarding this extension.")); + Gtk::Label * content = Gtk::manage(new Gtk::Label(_("Currently there is no help available for this Extension. Please look on the Inkscape website or ask on the mailing lists if you have questions regarding this extension."))); retval->pack_start(*content, true, true, 5); content->set_line_wrap(true); content->show(); @@ -786,6 +793,16 @@ Extension::get_params_widget(void) return retval; } +unsigned int Extension::param_visible_count ( ) +{ + unsigned int _visible_count = 0; + for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { + Parameter * param = reinterpret_cast(list->data); + if (!param->get_gui_hidden()) _visible_count++; + } + return _visible_count; +} + } /* namespace Extension */ } /* namespace Inkscape */