Hello,
I'm currently trying to use a 3 tabs notebook in an internal extension (a filter with some options and two color selectors), but Inkscape crashes as soon as an ext->get_param_xxx function is called from the filter's code. Everything works fine if I remove the notebook from the filter UI code.
These functions use the parameters list of the extension (see extension/extension.cpp, line 427+) to return the requested value. The problem is that this list, which is also used to create the UI, only contains the first level parameters, and when using a notebook, the notebook's parameters only (but not what's inside it). ParamNotebook (extension/param/notebook.cpp, line 64+) has it's own lists (one for each page), which are also used to create the pages' UI, and contain all the parameters that should be (but currently are not) accessible from the extension's get_param functions in order to make notebooks work as expected.
Since it's not possible to add the notebook's pages parameters to the extension's ones (it would break the UI), I plan to add a new private merged list in Extension::Extension and a public Extension::add_param function to allow parameters addition from the notebook code.
Could an extension expert (Ted, Johan?) advise me?
Regards. -- Nicolas
-----Original Message----- From: Nicolas Dufour [mailto:nicoduf@...48...] Sent: Tuesday, November 30, 2010 15:02 To: Inkscape Devel List Subject: [Inkscape-devel] Notebooks in internal extensions
Hello,
I'm currently trying to use a 3 tabs notebook in an internal extension (a filter with some options and two color selectors), but Inkscape crashes as soon as an ext->get_param_xxx function is called from the filter's code. Everything ext->works fine if I remove the notebook from the filter UI code.
These functions use the parameters list of the extension (see extension/extension.cpp, line 427+) to return the requested value. The problem is that this list, which is also used to create the UI, only contains the first level parameters, and when using a notebook, the notebook's parameters only (but not what's inside it). ParamNotebook (extension/param/notebook.cpp, line 64+) has it's own lists (one for each page), which are also used to create the pages' UI, and contain all the parameters that should be (but currently are not) accessible from the extension's get_param functions in order to make notebooks work as expected.
Since it's not possible to add the notebook's pages parameters to the extension's ones (it would break the UI), I plan to add a new private merged list in Extension::Extension and a public Extension::add_param function to allow parameters addition from the notebook code.
Could an extension expert (Ted, Johan?) advise me?
Hi Nicolas, Perhaps I can have a look at it this evening. I think the fix would be to have the get_param functions do something like a notebookparam->get_param if the extension's parameter is a ParamNotebook. (right?)
Ciao, Johan
Hi Johan,
Thanks for your answer!
De : "J.B.C.Engelen@...1578..." <J.B.C.Engelen@...1578...> Perhaps I can have a look at it this evening. I think the fix would be to have the get_param functions do something like a notebookparam->get_param if the extension's parameter is a ParamNotebook. (right?)
It was my first guess, but how do you find the parameter's type from its name (there's no "get_param_type" function or public "type" var in parameter.cpp and notebook.cpp)?
Regards, -- Nicolas
-----Original Message----- From: Nicolas Dufour [mailto:nicoduf@...48...] Sent: Wednesday, December 01, 2010 11:29 To: Engelen, J.B.C. (Johan); inkscape-devel@lists.sourceforge.net Subject: [Inkscape-devel] Re : Notebooks in internal extensions
Hi Johan,
Thanks for your answer!
De : "J.B.C.Engelen@...1578..." <J.B.C.Engelen@...1578...> Perhaps I can have a look at it this evening. I think
the fix would
be to have the get_param functions do something like a notebookparam->get_param if the extension's parameter is a ParamNotebook. (right?)
It was my first guess, but how do you find the parameter's type from its name (there's no "get_param_type" function or public "type" var in parameter.cpp and notebook.cpp)?
From the top of my head I can think up two solutions:
- Make a virtual get_sub_param function in Extension::Parameter that does nothing. And override that method in Extension::ParamNotebook. - Or (ugly) do dynamic type cast to check for param type ("dynamic_cast<>")
I'd go for the first option, and rewrite Extension::param_shared (and rename to get_param). I find the method somewhat strange. Seems better to me, to rewrite it without using recursion: (not my best piece of code, but I hope the idea is clear)
Parameter * Extension::get_param (const gchar * name) { if (name == NULL) { throw Extension::param_not_exist(); } if (this->parameters == NULL) { // the list of parameters is empty throw Extension::param_not_exist(); }
for (GSList * list = this->parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = static_cast<Parameter*>(list->data); if (!strcmp(param->name(), name)) { return param; } else { Parameter * subparam = param->get_param(name); if (subparam) { return subparam; } } }
// if execution reaches here, no parameter matching 'name' was found throw Extension::param_not_exist(); }
Then for example get_param_string would become: const gchar * Extension::get_param_string (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) { Parameter * param;
param = get_param(name); return param->get_string(doc, node); }
Extension::Parameter::get_param(const gchar * /*name*/) { return NULL; }
Extension::ParamNotebook::get_param(const gchar * /*name*/) { here a loop similar to Extension::get_param }
Hope these pieces of (pseudo)code help, Johan
Hi,
De : "J.B.C.Engelen@...1578..." <J.B.C.Engelen@...1578...>
- Make a virtual get_sub_param function in Extension::Parameter that
does nothing. And override that method in Extension::ParamNotebook.
Thanks Johan! Internal extensions (and thus internal filters) now support notebooks in the trunk (as of revision 9933).
Hope these pieces of (pseudo)code help,
There was almost nothing to change. I've just added a Extension::ParamNotebookPage::get_param function because the notebook parameters are not in the notebook itself, but spread in its different pages.
Thanks again for your help! -- Nicolas
participants (2)
-
unknown@example.com
-
Nicolas Dufour