diff options
Diffstat (limited to 'src/Fl_Tree.cxx')
| -rw-r--r-- | src/Fl_Tree.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx index 25d509c97..54b56ee63 100644 --- a/src/Fl_Tree.cxx +++ b/src/Fl_Tree.cxx @@ -7,6 +7,7 @@ #include <string.h> #include <FL/Fl_Tree.H> +#include <FL/Fl_Preferences.H> #define SCROLL_W 15 @@ -426,6 +427,56 @@ int Fl_Tree::select_only(Fl_Tree_Item *selitem, int docallback) { return(changed); } +/** + * Read a preferences database into the tree widget. + * A preferences database is a hierarchical collection of data which can be + * directly loaded into the tree view for inspection. + * \param[in] prefs the Fl_Preferences database + */ +void Fl_Tree::load(Fl_Preferences &prefs) +{ + int i, j, n, pn = strlen(prefs.path()); + char *p; + const char *path = prefs.path(); + if (strcmp(path, ".")==0) + path += 1; // root path is empty + else + path += 2; // child path starts with "./" + n = prefs.groups(); + for (i=0; i<n; i++) { + Fl_Preferences prefsChild(prefs, i); + add(prefsChild.path()+2); // children always start with "./" + load(prefsChild); + } + n = prefs.entries(); + for (i=0; i<n; i++) { + // We must remove all fwd slashes in the key and value strings. Replace with backslash. + char *key = strdup(prefs.entry(i)); + int kn = strlen(key); + for (j=0; j<kn; j++) { + if (key[j]=='/') key[j]='\\'; + } + char *val; prefs.get(key, val, ""); + int vn = strlen(val); + for (j=0; j<vn; j++) { + if (val[j]=='/') val[j]='\\'; + } + if (vn<40) { + int sze = pn + strlen(key) + vn; + p = (char*)malloc(sze+5); + sprintf(p, "%s/%s = %s", path, key, val); + } else { + int sze = pn + strlen(key) + 40; + p = (char*)malloc(sze+5); + sprintf(p, "%s/%s = %.40s...", path, key, val); + } + add(p[0]=='/'?p+1:p); + free(p); + free(val); + free(key); + } +} + // // End of "$Id$". // |
