diff options
| author | Aubanel Monnier <aubanel@gmail.com> | 2008-03-19 15:40:00 +0000 |
|---|---|---|
| committer | o__b <o__b@users.sourceforge.net> | 2008-03-19 15:40:00 +0000 |
| commit | e65a88bdb1ff93f1f2ba8e07a3d17e970670677f (patch) | |
| tree | 14033a41c5be8a7c7bac829ca45e0572f8900bc7 /src/prefs-utils.cpp | |
| parent | Add option to treat grups as single objects when converting to guides. (diff) | |
| download | inkscape-e65a88bdb1ff93f1f2ba8e07a3d17e970670677f.tar.gz inkscape-e65a88bdb1ff93f1f2ba8e07a3d17e970670677f.zip | |
More woke on calligraaphic presets:
Added a No Preset entry
Made save button and save functionality
Changing settings swithces back the preset combo to No Preset
Internals:
added several functions in pref-utils: add child-pref, get list of children, number of children
added a function to retrieve the model from egeActioSelectOne
Todos:
when a profile is selected, the save button should be a delete button that deletes the current profile
find a way to (re)name new profiles
find a way to get unique ids (are ids mandatory in preferences anyway ?)
(bzr r5125)
Diffstat (limited to 'src/prefs-utils.cpp')
| -rw-r--r-- | src/prefs-utils.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/prefs-utils.cpp b/src/prefs-utils.cpp index 5e01b1903..b2b3efeb7 100644 --- a/src/prefs-utils.cpp +++ b/src/prefs-utils.cpp @@ -24,6 +24,61 @@ bool pref_path_exists(gchar const *path){ Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path); return (repr != NULL); } + +/** +\brief returns the number of sub-prefs +*/ +unsigned int pref_path_number_of_children(gchar const *path){ + Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path); + Inkscape::XML::Node *child_repr = sp_repr_children(repr); + int nb_child = 0; + while (child_repr) { + nb_child ++; + child_repr = sp_repr_next(child_repr); + } + return nb_child; +} + +/** +\brief creates a new preference and returns its key on success. +*/ +gchar * create_pref(gchar const *father_path, gchar const *child){ + Inkscape::XML::Node *father = inkscape_get_repr(INKSCAPE, father_path); + if (! father ) return NULL; + Inkscape::XML::Node *repr = father->document()->createElement("group"); + sp_repr_set_attr(repr, "id", child); + father->appendChild(repr); + return g_strdup_printf("%s.%s", father_path,child); +} +/** +\brief gets the list of children from a pref. Please free all that stuff after use. +*/ +bool get_pref_children(gchar const *father_path, GSList ** children){ + Inkscape::XML::Node *father = inkscape_get_repr(INKSCAPE, father_path); + if (! father ) return false; + Inkscape::XML::Node *child_repr = sp_repr_children(father); + while (child_repr) { + *children = g_slist_prepend(*children, g_strdup_printf("%s.%s",father_path,child_repr->attribute("id"))); + child_repr = sp_repr_next(child_repr); + } + +} +/** +\brief gets the nth children of a pref, starting from one (first child <=> n=1). returns NULL if out of bounds or father does not exist. Please free all that stuff after use. +*/ +gchar *get_pref_nth_child(gchar const *father_path, unsigned int n){ + if (n <= 0) return NULL; + Inkscape::XML::Node *father = inkscape_get_repr(INKSCAPE, father_path); + if (! father ) return NULL; + Inkscape::XML::Node *child_repr = sp_repr_children(father); + unsigned int index = 0; + while (child_repr && (++index < n)) { + child_repr = sp_repr_next(child_repr); + } + if (child_repr) return g_strdup_printf("%s.%s",father_path,child_repr->attribute("id")); + return NULL; +} + void prefs_set_int_attribute(gchar const *path, gchar const *attr, long long int value) { |
