Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FileBrowserControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_FileBrowserControl_h_
00003 #define INCLUDED_FileBrowserControl_h_
00004 
00005 #include "ControlBase.h"
00006 #include <string>
00007 #include <vector>
00008 
00009 //! Displays the contents of a directory in a control menu, probably useful as a baseclass for other controls
00010 /*! Causes the selectedFile() function to be called on the root FileBrowserControl with the selected file */
00011 class FileBrowserControl : public ControlBase {
00012 public:
00013   //!@name Constructors/Destructors
00014   //!constructor
00015   FileBrowserControl() : ControlBase(), recurse(true), root(), paths(), filter("*") {init("");}
00016   //!constructor pass name and root path
00017   FileBrowserControl(const std::string& nm, const std::string& desc, const std::string& path) : ControlBase(nm,desc), recurse(true), root(), paths(), filter("*") { init(path); }
00018   //@}
00019   
00020   //!@name ControlBase Inheritance
00021   virtual ControlBase * activate(MC_ID display, Socket * gui);
00022   virtual ControlBase* doSelect();
00023   virtual ControlBase * takeInput(const std::string& msg);
00024   //@}
00025 
00026   //!@name Accessors
00027   void setRecurse(bool r) { recurse=r; }                 //!< sets #recurse
00028   bool getRecurse() const { return recurse; }            //!< returns #recurse
00029 
00030   void setRoot(const std::string& path);                 //!< sets #root, clears #paths
00031   std::string getRoot() const { return root; }           //!< returns #root
00032 
00033   void appendPath(const std::string& path);                 //!< adds entries to #paths (location relative to #root)
00034   
00035   void setFilter(const std::string& filt) {filter=filt;} //!< sets #filter; remember can only use one wildcard, e.g. *.ext or filename.ext or filename*
00036   //@}
00037   
00038 protected:
00039 
00040   //! the big money function - by default calls the parent if it exists, otherwise nothing
00041   /*! returning NULL means deactivate, this (default) to stay put, or a different Control if you want a submenu */
00042   virtual ControlBase* selectedFile(const std::string&) { return this; }
00043   
00044   //! returns the path from root as a string, with no trailing '/'
00045   std::string makePath();
00046   
00047   //! returns the path from root as a string, appends filename
00048   std::string makePath(const std::string& filename);
00049   
00050   //! returns true if @a file matches @a filt
00051   static bool match(const std::string& file, const std::string& filt);
00052 
00053   //!rescans current directory and builds menus
00054   void rebuildmenu();
00055 
00056   //!sets a junk menu item to mark this as having submenus, and sets root to path
00057   void init(std::string path) { pushSlot(NULL); setRoot(path); }
00058 
00059   bool recurse;                   //!< if true (default), will show directories; if false, subdirectories are hidden
00060   std::string root;               //!< the path to browse, default "/"
00061   std::vector<std::string> paths; //!< list of directories from root
00062   
00063   std::string filter;             //!< default "*", only display matching files; only can use one wildcard, e.g. *.ext or filename.ext or filename*
00064 
00065 private:
00066 //  FileBrowserControl(const FileBrowserControl& ); //!< don't call
00067 //  FileBrowserControl& operator=(const FileBrowserControl& ); //!< don't call
00068 };
00069 
00070 /*! @file
00071  * @brief Describes FileBrowserControl, which displays the contents of a directory
00072  * @author ejt (Creator)
00073  */
00074 
00075 #endif

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