summaryrefslogtreecommitdiff
path: root/src/Fl_Tree.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-07-10 09:44:45 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-07-10 09:44:45 +0000
commit32716d6b1e8a90cbe61b60994323029ec6abe85c (patch)
tree9c047f9cbf6a6581ef408dfabdab0aebde240a1b /src/Fl_Tree.cxx
parent8306c3d0b31d4e60a9ba9c4d0ca4ed6a32226de1 (diff)
Updated the Fluid IDE support for the current source file structure. Changed the Fl_Tree rendering code around a bit to make the tree more like MSWindows on Windows and more like Apple on Apple machines. I hope you guys like it. I also moved the function to load Fl_Preferences into an Fl_Tree into the Fl_Tree class where it belongs.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7672 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tree.cxx')
-rw-r--r--src/Fl_Tree.cxx51
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$".
//