Logo Search packages:      
Sourcecode: inkscape version File versions

Parameter * Inkscape::Extension::Parameter::make ( Inkscape::XML::Node in_repr,
Inkscape::Extension::Extension in_ext 
) [static]

This function creates a parameter that can be used later. This is typically done in the creation of the extension and defined in the XML file describing the extension (it's private so people have to use the system) :).

Returns:
None
Parameters:
in_repr The XML describing the parameter
This function first grabs all of the data out of the Repr and puts it into local variables. Actually, these are just pointers, and the data is not duplicated so we need to be careful with it. If there isn't a name or a type in the XML, then no parameter is created as the function just returns.

From this point on, we're pretty committed as we've allocated an object and we're starting to fill it. The name is set first, and is created with a strdup to actually allocate memory for it. Then there is a case statement (roughly because strcmp requires 'ifs') based on what type of parameter this is. Depending which type it is, the value is interpreted differently, but they are relatively straight forward. In all cases the value is set to the default value from the XML and the type is set to the interpreted type.

Definition at line 72 of file parameter.cpp.

References Inkscape::XML::Node::attribute(), SCOPE_DOCUMENT, SCOPE_NODE, and SCOPE_USER.

Referenced by Inkscape::Extension::Extension::Extension(), and Inkscape::Extension::PrefDialog::PrefDialog().

{
    const char * name;
    const char * type;
    const char * guitext;
    const char * desc;
    const char * scope_str;
    Parameter::_scope_t scope = Parameter::SCOPE_USER;
      bool gui_hidden = false;
      const char * gui_hide;
      const char * gui_tip;

    name = in_repr->attribute("name");
    type = in_repr->attribute("type");
    guitext = in_repr->attribute("gui-text");
    if (guitext == NULL)
        guitext = in_repr->attribute("_gui-text");
    gui_tip = in_repr->attribute("gui-tip");
    if (gui_tip == NULL)
        gui_tip = in_repr->attribute("_gui-tip");
    desc = in_repr->attribute("gui-description");
    if (desc == NULL)
        desc = in_repr->attribute("_gui-description");
    scope_str = in_repr->attribute("scope");
      gui_hide = in_repr->attribute("gui-hidden");
      if (gui_hide != NULL) {
            if (strcmp(gui_hide, "1") == 0 ||
                  strcmp(gui_hide, "true") == 0) {
                  gui_hidden = true;
            }
            /* else stays false */
      }
    const gchar* appearance = in_repr->attribute("appearance");

    /* In this case we just don't have enough information */
    if (name == NULL || type == NULL) {
        return NULL;
    }

    if (scope_str != NULL) {
        if (!strcmp(scope_str, "user")) {
            scope = Parameter::SCOPE_USER;
        } else if (!strcmp(scope_str, "document")) {
            scope = Parameter::SCOPE_DOCUMENT;
        } else if (!strcmp(scope_str, "node")) {
            scope = Parameter::SCOPE_NODE;
        }
    }

    Parameter * param = NULL;
    if (!strcmp(type, "boolean")) {
        param = new ParamBool(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "int")) {
        param = new ParamInt(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "float")) {
        param = new ParamFloat(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "string")) {
        param = new ParamString(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
        const gchar * max_length = in_repr->attribute("max_length");
        if (max_length != NULL) {
            ParamString * ps = dynamic_cast<ParamString *>(param);
            ps->setMaxLength(atoi(max_length));
        }
    } else if (!strcmp(type, "description")) {
        param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "enum")) {
        param = new ParamComboBox(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "notebook")) {
        param = new ParamNotebook(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    } else if (!strcmp(type, "optiongroup")) {
        if (appearance && !strcmp(appearance, "minimal")) {
            param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::MINIMAL);
        } else {
            param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::FULL);
        }
    } else if (!strcmp(type, "color")) {
        param = new ParamColor(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr);
    }

    /* Note: param could equal NULL */
    return param;
}


Generated by  Doxygen 1.6.0   Back to index