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

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:37 2016 by Doxygen 1.6.3