Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FileInputControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_FileInputControl_h_
00003 #define INCLUDED_FileInputControl_h_
00004 
00005 #include "FileBrowserControl.h"
00006 #include <string>
00007 
00008 //! Upon activation, allows user to browse files and select one; stores path in a string
00009 class FileInputControl : public FileBrowserControl {
00010  public:
00011   //! Constructor
00012   FileInputControl()
00013     : FileBrowserControl("Select file","Select a file","/"), file(NULL), myfile(), acceptNonExistant(false)
00014   {}
00015 
00016   //! Constructor
00017   FileInputControl(const std::string& nm, const std::string& desc, const std::string& path, std::string* store=NULL)
00018     : FileBrowserControl(nm,desc,path), file(store), myfile(), acceptNonExistant(false)
00019   {}
00020 
00021   //! returns the path to file last selected; use takeInput() to assign to this
00022   virtual const std::string& getLastInput() { return myfile; }
00023 
00024   //! clears the last input (i.e. so you can easily tell later if new input is entered)
00025   virtual void clearLastInput() { selectedFile(""); }
00026 
00027   //! pass pointer to an external string you wish to have set when a file is selected; NULL otherwise
00028   virtual void setStore(std::string* store) { file=store; }
00029   
00030   //! sets #acceptNonExistant
00031   virtual void setAcceptNonExistant(bool b) { acceptNonExistant=b; }
00032   //! returns #acceptNonExistant
00033   virtual bool getAcceptNonExistant() const { return acceptNonExistant; }
00034   
00035 protected:
00036   virtual ControlBase* selectedFile(const std::string& f) {
00037     myfile=f;
00038     if(file!=NULL)
00039       *file=f;
00040     return NULL;
00041   }
00042   virtual ControlBase* invalidInput(const std::string& msg, bool ambiguous) {
00043     if(!acceptNonExistant)
00044       return FileBrowserControl::invalidInput(msg,ambiguous);
00045     return selectedFile(makePath(msg));
00046   }
00047 
00048   std::string* file;  //!< if we're supposed to store in an external string, this will point to it, otherwise NULL
00049   std::string myfile; //!< stores last file selected
00050   bool acceptNonExistant; //!< if true, will set #file and #myfile to "invalid" inputs as well -- i.e. inputs that don't correspond to any current file (so user can request a new one)
00051 
00052 private:
00053   FileInputControl(const FileInputControl& ); //!< don't call
00054   FileInputControl& operator=(const FileInputControl& ); //!< don't call
00055 };
00056 
00057 /*! @file
00058  * @brief Defines FileInputControl, which allows the user to browse files and select one, which is then stored in a string
00059  * @author ejt (Creator)
00060  */
00061 
00062 #endif

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