diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2010-01-10 22:37:56 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2010-01-10 22:37:56 +0000 |
| commit | 3d5d2b54f23901ccd11641f4df95b5c6a4c10664 (patch) | |
| tree | 1e6a7cfd363d39733e9d50776e9c42c829c08959 | |
| parent | a0eb792209e5d597ce350ef16d430352b6fdcfc1 (diff) | |
Added a function to copy an entire Fl_Preferences database into an Fl_Tree view. This will break IDEs that do not have Fl_Tree and Fl_Table added yet!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6992 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | FL/Fl_Preferences.H | 5 | ||||
| -rw-r--r-- | FL/Fl_Tree.H | 2 | ||||
| -rw-r--r-- | src/Fl_Preferences.cxx | 29 |
3 files changed, 34 insertions, 2 deletions
diff --git a/FL/Fl_Preferences.H b/FL/Fl_Preferences.H index e16ff64d3..a5f56c1e6 100644 --- a/FL/Fl_Preferences.H +++ b/FL/Fl_Preferences.H @@ -146,6 +146,8 @@ public: // char export( const char *filename, Type fileFormat ); // char import( const char *filename ); + + char copyTo(class Fl_Tree*); /** 'Name' provides a simple method to create numerical or more complex @@ -206,12 +208,14 @@ private: public: Node( const char *path ); ~Node(); + char copyTo(class Fl_Tree*, class Fl_Tree_Item*); // node methods int write( FILE *f ); const char *name(); const char *path() { return path_; } Node *find( const char *path ); Node *search( const char *path, int offset=0 ); + Node *childNode( int ix ); Node *addChild( const char *path ); void setParent( Node *parent ); Node *parent() { return top_?0L:parent_; } @@ -222,7 +226,6 @@ private: // entry methods int nChildren(); const char *child( int ix ); - Node *childNode( int ix ); void set( const char *name, const char *value ); void set( const char *line ); void add( const char *line ); diff --git a/FL/Fl_Tree.H b/FL/Fl_Tree.H index 7404d8936..db9f46f60 100644 --- a/FL/Fl_Tree.H +++ b/FL/Fl_Tree.H @@ -94,7 +94,7 @@ /// Fl_Tree_Item::closeicon(), /// Fl_Tree_Item::usericon(). /// -/// Various default preferences can be manipulated vi Fl_Tree_Prefs, including +/// Various default preferences can be manipulated via Fl_Tree_Prefs, including /// colors, margins, connection lines. /// /// \image html tree-elements.png diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 2a58adf40..c7588d96d 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -28,6 +28,7 @@ #include <FL/Fl.H> #include <FL/Fl_Preferences.H> +#include <FL/Fl_Tree.H> #include <FL/filename.H> #include <stdio.h> @@ -334,6 +335,15 @@ Fl_Preferences::~Fl_Preferences() /** + Copy the databse hierarchy to an Fl_Tree browser from this node down. + */ +char Fl_Preferences::copyTo(Fl_Tree *tree) +{ + return node->copyTo(tree, tree->root()); +} + + +/** Returns the number of groups that are contained within a group. \return 0 for no groups at all @@ -1601,6 +1611,25 @@ char Fl_Preferences::Node::remove() return ( nd != 0 ); } +char Fl_Preferences::Node::copyTo(Fl_Tree *tree, Fl_Tree_Item *ti) +{ + ti->label(name()); + ti->user_data(this); + Node *nd = child_; + for ( ; nd; nd = nd->next_) { + Fl_Tree_Item *tic = tree->insert(ti, 0, 0); + nd->copyTo(tree, tic); + tic->close(); + } + int i, n = nEntry; + for (i=0; i<n; i++) { + char buf[80]; + const char *name = entry[i].name; + const char *value = entry[i].value; + fl_snprintf(buf, 80, "%s: %s", name, value); + Fl_Tree_Item *tic = tree->add(ti, buf); + } +} // // End of "$Id$". |
