Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ConfigurationEditor.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_ConfigurationEditor_h
00003 #define INCLUDED_ConfigurationEditor_h
00004 
00005 #include "Behaviors/Controls/ControlBase.h"
00006 #include "Behaviors/Controls/FileInputControl.h"
00007 #include "Behaviors/Controls/StringInputControl.h"
00008 
00009 //! Provides interactive editing and loading/saving of a plist::Collection
00010 class ConfigurationEditor : public ControlBase {
00011 
00012   // **************************** //
00013   // ******* CONSTRUCTORS ******* //
00014   // **************************** //
00015 public:
00016   //! default constructor
00017   ConfigurationEditor(plist::Collection * rootCollection=NULL)
00018     : ControlBase("ConfigurationEditor","Provides interactive editing and loading/saving of a plist::Collection"),
00019     root(rootCollection), path(), load(rootCollection), save(rootCollection)
00020   {init();}
00021   //! constructor which allows a custom name
00022   ConfigurationEditor(const std::string& n, plist::Collection * rootCollection=NULL)
00023     : ControlBase(n,"Provides interactive editing and loading/saving of a plist::Collection"),
00024     root(rootCollection), path(), load(rootCollection), save(rootCollection)
00025   {init();}
00026   //! constructor which allows a custom name and tooltip
00027   ConfigurationEditor(const std::string& n, const std::string& d, plist::Collection * rootCollection=NULL)
00028     : ControlBase(n,d), root(rootCollection), path(), load(rootCollection), save(rootCollection)
00029   {init();}
00030 
00031   //! destructor, have to do our custom clearSlots before the superclass tries to
00032   virtual ~ConfigurationEditor() { clearSlots(); }
00033 
00034 protected:
00035   //! common initialization regardless of constructor
00036   virtual void init();
00037 
00038 
00039   
00040   // **************************** //
00041   // ********* METHODS ********** //
00042   // **************************** //
00043 public:
00044   //! called when a child has deactivated and this control should refresh its display, or some other event (such as the user pressing the refresh button) has happened to cause a refresh to be needed
00045   virtual void refresh();
00046   
00047   //! need to override clearing so we don't delete #load and #save
00048   virtual void clearSlots();
00049   
00050   //! sets the root of the collection being managed
00051   virtual void setRootCollection(plist::Collection* rootCollection);
00052   
00053   //! sets the path to the sub-collection being managed
00054   virtual void setPath(const std::string& p);
00055   
00056   //! returns a dictionary of plist objects which may be added as new entries to collections being edited
00057   static plist::Dictionary& getObjectTemplates();
00058   
00059   
00060   // **************************** //
00061   // ********* MEMBERS ********** //
00062   // **************************** //
00063 protected:
00064   plist::Collection * root; //!< the root of collection being edited (i.e. may be the parent or other ancestor of the collection this editor is targeting, see #path)
00065   std::string path; //!< the names of the sub-collections  from #root to get to the collection this instance is actually targeting
00066   
00067   //! provides a file browser to load a plist from the file system
00068   class LoadSettings : public FileInputControl {
00069   public:
00070     //! constructor, if rootCollection is NULL, you must call setRootCollection() with a non-NULL value at some point before user tries to activate the control
00071     LoadSettings(plist::Collection * rootCollection) : FileInputControl("Load...","Load settings from disk","config"), rootcol(rootCollection) {}
00072     //! assigns #rootcol
00073     virtual void setRootCollection(plist::Collection* rootCollection) { rootcol=rootCollection; }
00074   protected:
00075     virtual ControlBase* selectedFile(const std::string& f);
00076     plist::Collection * rootcol; //!< the collection to be saved (generally the top level of the collection, even if currently editing within a sub-collection)
00077   private:
00078     LoadSettings(const LoadSettings&); //!< not supported
00079     LoadSettings& operator=(const LoadSettings&); //!< not supported
00080   };
00081   LoadSettings load; //!< reuse the same load instance instead of regenerating a new one each refresh (saves user's "working directory")
00082   
00083   //! provides a file browser to save a plist from the file system
00084   class SaveSettings : public FileInputControl {
00085   public:
00086     //! constructor, if rootCollection is NULL, you must call setRootCollection() with a non-NULL value at some point before user tries to activate the control
00087     SaveSettings(plist::Collection * rootCollection) : FileInputControl("Save...","Save settings to disk","config"), rootcol(rootCollection) { setAcceptNonExistant(true); }
00088     //! assigns #rootcol
00089     virtual void setRootCollection(plist::Collection* rootCollection) { rootcol=rootCollection; }
00090   protected:
00091     virtual ControlBase* selectedFile(const std::string& f);
00092     plist::Collection * rootcol; //!< the collection to be saved (generally the top level of the collection, even if currently editing within a sub-collection)
00093   private:
00094     SaveSettings(const SaveSettings&); //!< not supported
00095     SaveSettings& operator=(const SaveSettings&); //!< not supported
00096   };
00097   SaveSettings save; //!< reuse the same save instance instead of regenerating a new one each refresh (saves user's "working directory")
00098   
00099   //! displays a list of template objects (see ConfigurationEditor::getObjectTemplates()) which can be added to a target collection
00100   class AddCollectionEntry : public ControlBase {
00101   public:
00102     AddCollectionEntry(plist::Collection& target) : ControlBase("Add New Entry"), tgt(&target) {}
00103     virtual void refresh();
00104     virtual void deactivate() { clearSlots(); ControlBase::deactivate(); }
00105   protected:
00106     plist::Collection * tgt;
00107   private:
00108     AddCollectionEntry(const AddCollectionEntry&); //!< not supported
00109     AddCollectionEntry& operator=(const AddCollectionEntry&); //!< not supported
00110   };
00111   
00112   //! provides interface to set up a new collection entry before inserting it
00113   class NewCollectionEntry : public ControlBase {
00114   public:
00115     NewCollectionEntry(const std::string& n, plist::Collection& target, plist::ObjectBase& templ) : ControlBase(n), tgt(&target), obj(&templ) {}
00116     virtual void refresh();
00117     virtual void deactivate() { clearSlots(); ControlBase::deactivate(); }
00118     virtual ControlBase * doSelect();
00119   protected:
00120     plist::Collection * tgt;
00121     plist::ObjectBase * obj;
00122   private:
00123     NewCollectionEntry(const NewCollectionEntry&); //!< not supported
00124     NewCollectionEntry& operator=(const NewCollectionEntry&); //!< not supported
00125   };
00126   
00127   //! based on a string input control for easier mixing with other primitives (which just use a basic string input control as an editor)
00128   /*! If selected, provides a submenu with symbolic options to better prompt the user with valid values */
00129   class NamedEnumerationEditor : public StringInputControl {
00130   public:
00131     //! constructor
00132     NamedEnumerationEditor(const std::string& n, const std::string& prompt, plist::NamedEnumerationBase& target) : StringInputControl(n,prompt), tgt(&target) {}
00133     virtual void refresh();
00134     //! purposely clearing slots on deactivate to avoid having sub-menus -- don't want to appear as a collection
00135     virtual void deactivate() { clearSlots(); StringInputControl::deactivate(); }
00136     //! handles selecting one of the symbolic values
00137     virtual ControlBase * doSelect();
00138     //! override to only allow one hilight (first in the list)
00139     virtual void setHilights(const std::vector<unsigned int>& hi) {
00140       if(hi.empty())
00141         StringInputControl::setHilights(hi);
00142       else // go straight to control base
00143         ControlBase::setHilights(std::vector<unsigned int>(1,hi.front()));
00144     }
00145   protected:
00146     plist::NamedEnumerationBase * tgt; //!< the value being edited
00147   private:
00148     NamedEnumerationEditor(const NamedEnumerationEditor&); //!< not supported
00149     NamedEnumerationEditor& operator=(const NamedEnumerationEditor&); //!< not supported
00150   };
00151   
00152 
00153   // **************************** //
00154   // ********** OTHER *********** //
00155   // **************************** //
00156 private:
00157   ConfigurationEditor(const ConfigurationEditor&); //!< you can override, but don't call this...
00158   ConfigurationEditor& operator=(const ConfigurationEditor&); //!< you can override, but don't call this...
00159 };
00160 
00161 /*! @file
00162  * @brief Defines ConfigurationEditor, which provides interactive editing and loading/saving of a plist::Collection
00163  * @author Ethan Tira-Thompson (ejt) (Creator)
00164  *
00165  * $Author: ejt $
00166  * $Name: tekkotsu-4_0 $
00167  * $Revision: 1.1 $
00168  * $State: Exp $
00169  * $Date: 2007/01/30 22:56:18 $
00170  */
00171 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:52 2007 by Doxygen 1.5.4