index 79f06359166c3ea62b115d10d0ac890945cb92d8..b4cf06bda3b513490631118270c61b17cd5a7f78 100644 (file)
#include "db.h"
#include "dependency.h"
#include "timer.h"
-#include "parameter.h"
+#include "param/parameter.h"
namespace Inkscape {
namespace Extension {
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);
/* 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")) {
@@ -91,15 +96,15 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat
if (!strcmp(chname, "help")) {
_help = g_strdup (sp_repr_children(child_repr)->content());
} /* name */
- if (!strcmp(chname, "param")) {
+ if (!strcmp(chname, "param") || !strcmp(chname, "_param")) {
Parameter * param;
param = Parameter::make(child_repr, this);
if (param != NULL)
parameters = g_slist_append(parameters, param);
- } /* param */
+ } /* param || _param */
if (!strcmp(chname, "dependency")) {
_deps.push_back(new Dependency(child_repr));
- } /* param */
+ } /* dependency */
child_repr = sp_repr_next(child_repr);
}
delete timer;
timer = NULL;
/** \todo Need to do parameters here */
-
+
+ // delete parameters:
+ for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) {
+ Parameter * param = reinterpret_cast<Parameter *>(list->data);
+ delete param;
+ }
+ g_slist_free(parameters);
+
+
for (unsigned int i = 0 ; i < _deps.size(); i++) {
delete _deps[i];
}
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;
}
/**
found parameter.
*/
const gchar *
-Extension::get_param_string (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
{
Parameter * param;
@@ -420,6 +433,21 @@ Extension::get_param_string (const gchar * name, const Inkscape::XML::Document *
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);
+ 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 = param_shared(name, parameters);
+ 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
@@ -432,7 +460,7 @@ Extension::get_param_string (const gchar * name, const Inkscape::XML::Document *
found parameter.
*/
bool
-Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_bool (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
{
Parameter * param;
@@ -452,7 +480,7 @@ Extension::get_param_bool (const gchar * name, const Inkscape::XML::Document * d
found parameter.
*/
int
-Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_int (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
{
Parameter * param;
@@ -472,13 +500,31 @@ Extension::get_param_int (const gchar * name, const Inkscape::XML::Document * do
found parameter.
*/
float
-Extension::get_param_float (const gchar * name, const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
+Extension::get_param_float (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
{
Parameter * param;
param = param_shared(name, parameters);
return param->get_float(doc, node);
}
+/**
+ \return The string value for the parameter specified
+ \brief Gets a parameter identified by name with the float placed
+ in value.
+ \param name The name of the parameter to get
+ \param doc The document to look in for document specific parameters
+ \param node The node to look in for a specific parameter
+
+ Look up in the parameters list, then execute the function on that
+ found parameter.
+*/
+guint32
+Extension::get_param_color (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node)
+{
+ Parameter* param = param_shared(name, parameters);
+ return param->get_color(doc, node);
+}
+
/**
\return The passed in value
\brief Sets a parameter identified by name with the boolean
found parameter.
*/
bool
-Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_bool (const gchar * name, bool value, SPDocument * doc, Inkscape::XML::Node * node)
{
Parameter * param;
param = param_shared(name, parameters);
@@ -512,7 +558,7 @@ Extension::set_param_bool (const gchar * name, bool value, Inkscape::XML::Docume
found parameter.
*/
int
-Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_int (const gchar * name, int value, SPDocument * doc, Inkscape::XML::Node * node)
{
Parameter * param;
param = param_shared(name, parameters);
@@ -532,7 +578,7 @@ Extension::set_param_int (const gchar * name, int value, Inkscape::XML::Document
found parameter.
*/
float
-Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_float (const gchar * name, float value, SPDocument * doc, Inkscape::XML::Node * node)
{
Parameter * param;
param = param_shared(name, parameters);
@@ -552,13 +598,39 @@ Extension::set_param_float (const gchar * name, float value, Inkscape::XML::Docu
found parameter.
*/
const gchar *
-Extension::set_param_string (const gchar * name, const gchar * value, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
+Extension::set_param_string (const gchar * name, const gchar * value, SPDocument * doc, Inkscape::XML::Node * node)
{
Parameter * param;
param = param_shared(name, parameters);
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 = param_shared(name, parameters);
+ return param->set_optiongroup(value, doc, node);
+}
+
+
+/**
+ \return The passed in value
+ \brief Sets a parameter identified by name with the string
+ in the parameter value.
+ \param name The name of the parameter to set
+ \param value The value to set the parameter to
+ \param doc The document to look in for document specific parameters
+ \param node The node to look in for a specific parameter
+
+ Look up in the parameters list, then execute the function on that
+ found parameter.
+*/
+guint32
+Extension::set_param_color (const gchar * name, guint32 color, SPDocument * doc, Inkscape::XML::Node * node)
+{
+ Parameter* param = param_shared(name, parameters);
+ return param->set_color(color, doc, node);
+}
+
/** \brief A function to open the error log file. */
void
Extension::error_file_open (void)
*/
void addWidget (Gtk::Widget * widg, gchar const * tooltip) {
if (widg == NULL) return;
- this->pack_start(*widg, true, true);
+ this->pack_start(*widg, true, true, 2);
if (tooltip != NULL) {
_tooltips.set_tip(*widg, Glib::ustring(tooltip));
- // printf("Setting tooltip: %s\n", tooltip);
}
return;
};
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 (void)
+Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * 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<Parameter *>(list->data);
- Gtk::Widget * widg = param->get_widget();
+ 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;
};
/**
\brief A function to get the parameters in a string form
- \return A string with all the parameters as command line arguements
+ \return An array with all the parameters in it.
- I don't really like this function, but it works for now.
-
- \todo Do this better.
*/
-Glib::ustring *
-Extension::paramString (void)
+void
+Extension::paramListString (std::list <std::string> &retlist)
{
- Glib::ustring * param_string = new Glib::ustring("");
-
for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) {
Parameter * param = reinterpret_cast<Parameter *>(list->data);
-
- *param_string += " --";
- *param_string += param->name();
- *param_string += "=";
- Glib::ustring * paramstr = param->string();
- *param_string += *paramstr;
- delete paramstr;
+ param->string(retlist);
}
- return param_string;
+ return;
}
/* Extension editor dialog stuff */
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();
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<Parameter *>(list->data);
+ if (!param->get_gui_hidden()) _visible_count++;
+ }
+ return _visible_count;
+}
+
} /* namespace Extension */
} /* namespace Inkscape */