Code

Extensions. Notebooks now work with internal extensions.
authorJazzyNico <nicoduf@yahoo.fr>
Fri, 3 Dec 2010 18:56:12 +0000 (19:56 +0100)
committerJazzyNico <nicoduf@yahoo.fr>
Fri, 3 Dec 2010 18:56:12 +0000 (19:56 +0100)
src/extension/extension.cpp
src/extension/extension.h
src/extension/param/notebook.cpp
src/extension/param/notebook.h
src/extension/param/parameter.cpp
src/extension/param/parameter.h

index caed62735d1da0a4797b4b05ce4467e194f6b691..e67a4b95f65c84acfa2d864272dcba50cc2648c0 100644 (file)
@@ -44,7 +44,7 @@ namespace Extension {
 std::vector<const gchar *> Extension::search_path;
 std::ofstream Extension::error_file;
 
-Parameter * param_shared (const gchar * name, GSList * list);
+Parameter * get_param (const gchar * name);
 
 /**
     \return  none
@@ -372,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<Parameter *>(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<Parameter*>(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();
 }
 
 /**
@@ -428,22 +428,21 @@ 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)
+gchar const *
+Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node)
 {
-    Parameter* param = param_shared(name, parameters);
+    Parameter* param = get_param(name);
     return param->get_optiongroup(doc, node);
 }
 
@@ -463,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);
 }
 
@@ -483,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);
 }
 
@@ -503,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);
 }
 
@@ -521,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);
 }
 
@@ -541,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);
 }
 
@@ -561,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);
 }
 
@@ -581,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);
 }
 
@@ -601,13 +598,14 @@ 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)
+gchar const *
+Extension::set_param_optiongroup(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node)
 {
-    Parameter * param = param_shared(name, parameters);
+    Parameter * param = get_param(name);
     return param->set_optiongroup(value, doc, node);
 }
 
@@ -627,7 +625,7 @@ gchar const * Extension::set_param_optiongroup(gchar const * name, gchar const *
 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);
 }
 
index c71ae59b42ec7481e94b22a730ed4d1257036bb8..936d2a907e44ae7777e53ba8bf624b49d0da843c 100644 (file)
@@ -169,10 +169,9 @@ public:
 
 private:
     void             make_param       (Inkscape::XML::Node * paramrepr);
-#if 0
-    inline param_t * param_shared     (const gchar * name,
-                                       GSList * list);
-#endif
+    
+    Parameter *      get_param        (const gchar * name);
+
 public:
     bool             get_param_bool   (const gchar * name,
                                        const SPDocument *   doc = NULL,
index 86e3cefe61651058b54ac01ceb2305a25938795d..e1ab1de6d6d33437918be0456738dc8be411bc78 100644 (file)
@@ -57,7 +57,7 @@ public:
     Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal);
     void paramString (std::list <std::string> &list);
     gchar * get_guitext (void) {return _text;};
-
+    Parameter * get_param (const gchar * name);
 }; /* class ParamNotebookPage */
 
 
@@ -381,7 +381,45 @@ ParamNotebookWdg::changed_page(GtkNotebookPage */*page*/,
     return;
 }
 
+/** \brief  Search the parameter's name in the notebook content */
+Parameter *
+ParamNotebook::get_param(const gchar * name)
+{
+    if (name == NULL) {
+        throw Extension::param_not_exist();
+    }
+    for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) {
+        ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data);
+        Parameter * subparam = page->get_param(name);
+        if (subparam) {
+            return subparam;
+        }
+    }
+
+    return NULL;
+}
 
+/** \brief  Search the parameter's name in the page content */
+Parameter *
+ParamNotebookPage::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;
+        }
+    }
+
+    return NULL;
+}
 
 /**
     \brief  Creates a Notebook widget for a notebook parameter
index 24d4ebfc138f3fca2474560fe61503978ba506c6..fb21c9b637459b3858df1edb366b9e85670d736d 100644 (file)
@@ -43,6 +43,8 @@ public:
     Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal);
     void string (std::list <std::string> &list);
 
+    Parameter * get_param (const gchar * name);
+
     const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; }
     const gchar * set (const int in, SPDocument * doc, Inkscape::XML::Node * node);
 }; /* class ParamNotebook */
index 1347653a2bd1e5aec2a65a23bd1a6c9fe013d840..94260cc56523e59ed3bdd0416d86a952e21c6e5f 100644 (file)
@@ -155,8 +155,6 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension *
     return param;
 }
 
-
-
 /** \brief  Wrapper to cast to the object and use it's function.  */
 bool
 Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node)
@@ -409,6 +407,13 @@ Parameter::string (std::list <std::string> &list)
     return;
 }
 
+/** \brief  All the code in Notebook::get_param to get the notebook content */
+Parameter *
+Parameter::get_param(const gchar * name)
+{
+    return NULL;
+}
+
 Glib::ustring const extension_pref_root = "/extensions/";
 
 }  /* namespace Extension */
index beddf5936da9bc1bd6a6aba6c924add0a5cdc3d1..d8ed6843951249069c68290efadac062a4b4d798 100644 (file)
@@ -85,6 +85,7 @@ public:
                       Parameter(name, guitext, NULL, Parameter::SCOPE_USER, false, NULL, ext);
                   };
     virtual      ~Parameter  (void);
+
     bool          get_bool   (const SPDocument * doc,
                               const Inkscape::XML::Node * node);
     int           get_int    (const SPDocument * doc,
@@ -120,6 +121,8 @@ public:
 
     virtual void string (std::list <std::string> &list);
     virtual void string (std::string &string);
+
+    virtual Parameter *  get_param  (const gchar * name);
 };
 
 }  /* namespace Extension */