Logo Search packages:      
Sourcecode: inkscape version File versions

void Inkscape::Extension::Extension::make_param ( SPRepr *  paramrepr  )  [private]

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) :).

paramrepr 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.

Finally the allocated parameter is put into the GSList that is called parameteres.

This function should pull up parameters that are stored in the preferences somewhere. This needs to be figured out.

Definition at line 377 of file extension.cpp.

References Inkscape::Extension::Extension::param_t::name, name, PARAM_BOOL, PARAM_FLOAT, PARAM_INT, PARAM_STRING, parameters, Inkscape::Extension::Extension::param_switch_t::t_bool, Inkscape::Extension::Extension::param_switch_t::t_float, Inkscape::Extension::Extension::param_switch_t::t_int, Inkscape::Extension::Extension::param_switch_t::t_string, Inkscape::Extension::Extension::param_t::type, and Inkscape::Extension::Extension::param_t::val.

Referenced by Extension().

    const char * name;
    const char * type;
    const char * defaultval;
      gchar * param_name;
    Extension::param_t * param;

    name = sp_repr_attr(paramrepr, "name");
    type = sp_repr_attr(paramrepr, "type");
    // defaultval = sp_repr_content(paramrepr);
    defaultval = sp_repr_content(sp_repr_children(paramrepr));

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

    param = new param_t();
    param->name = g_strdup(name);
      param_name = g_strdup_printf("%s.%s", id, name);
    if (!strcmp(type, "boolean")) {
        param->type = Extension::PARAM_BOOL;
        if (defaultval != NULL && !strcmp(defaultval, "TRUE")) {
            param->val.t_bool = TRUE;
        } else {
            param->val.t_bool = FALSE;
            param->val.t_bool = prefs_get_int_attribute("extensions", param_name, (gint)param->val.t_bool);
    } else if (!strcmp(type, "int")) { 
        param->type = Extension::PARAM_INT;
        if (defaultval != NULL) {
            param->val.t_int = atoi(defaultval);
        } else {
            param->val.t_int = 0;
            param->val.t_int = prefs_get_int_attribute("extensions", param_name, (gint)param->val.t_int);
    } else if (!strcmp(type, "float")) { 
        param->type = Extension::PARAM_FLOAT;
            // std::cout << "Float value: " << defaultval;
        if (defaultval != NULL) {
            param->val.t_float = atof(defaultval);
        } else {
            param->val.t_float = 0.0;
            param->val.t_float = prefs_get_double_attribute("extensions", param_name, (gfloat)param->val.t_float);
            // std::cout << " after: " << param->val.t_float << std::endl;
    } else if (!strcmp(type, "string")) { 
            const gchar * temp_str;
        param->type = Extension::PARAM_STRING;

            temp_str = prefs_get_string_attribute("extensions", param_name);
            if (temp_str == NULL)
                  temp_str = defaultval;

        param->val.t_string = g_strdup(temp_str);
    } else {

    parameters = g_slist_append(parameters, param);

Generated by  Doxygen 1.6.0   Back to index