ubit
ufilebox.hpp
1 /************************************************************************
2  *
3  * ufilebox.hpp: File Box Element
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _ufilebox_hpp_
18 #define _ufilebox_hpp_ 1
19 #include <ubit/ubox.hpp>
20 #include <ubit/uchoice.hpp>
21 namespace ubit {
22 
23 /* File chooser.
24 * A UFilebox can be included into a UDialog or a UMenu as follows:
25 * examples:
26 * <pre>
27 * class Demo {
28 * public:
29 * void openFile(UEvent& e) {...} // the UEvent& parameter is optional
30 * ...
31 * };
32 *
33 * Demo* d = new Demo();
34 *
35 * // NB: ufilebox(...) is a shortcut for *new UFilebox(...)
36 * UBox& fbox = ufilebox( utitle("Open File")
37 * + UOn::action / ucall(this, &Demo::openFile)
38 * );
39 * UDialog& fdialog = udialog(fbox)
40 * // and/or:
41 * UMenu& fmenu = umenu(fbox)
42 * </pre>
43 *
44 * this->openFile() is called when a file is double clicked or when
45 * the OK button of the filebox is clicked.
46 *
47 * @see: UCall for more info on callback methods/functions and their parameters
48 */
49 class UFilebox : public UBox {
50 public:
51  UCLASS(UFilebox)
52 
53  UFilebox(const UArgs& arglist = UArgs::none);
59  virtual ~UFilebox();
60 
61  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 
63  const UStr& getDir() const {return *fdir2;}
65 
66  const UStr& getName() const {return *fname;}
68 
69  const UStr& getPath() const {return *fpath;}
70  UStr& path() {return *fpath;}
72 
73  const UStr& getFilter() const {return *ffilter;}
75 
76  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 
78  virtual void setDir(const UStr&);
80 
81  virtual void setName(const UStr&);
82 
83  virtual void setFilter(const UStr&);
85 
86  virtual void showList(bool);
87  virtual void showHiddenFiles(bool);
88 
89  virtual void rescan();
91 
92  void setAutoClose(bool stat) {autoclose = stat;}
93 
94  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 protected:
96  UStr fspec;
97  uptr<UStr> fname, fdir2, ffilter, fpath;
98  //UScrollpane* scrollpane;
99  UBox *mainbox;
100  UBox *show_list, *show_hidden_files;
101  URadioSelect new_sel;
102  bool autoclose;
103 
104  virtual void cancelBehavior(UInputEvent&);
105  virtual void okBehavior(UInputEvent&);
106  virtual void selectBehavior(UEvent&, UStr* pathname);
107  virtual void setDirImpl(UStr*);
108  virtual void changeDirImpl(UStr*);
109  /* sets the directory in a relative way.
110  * - goes to the parent directory if arg is ".."
111  * - goes to subdirectory "xxx" if arg is "xxx"
112  */
113 };
114 
115 UFilebox& ufilebox(const UArgs& arglist = UArgs::none);
117 
118 }
119 #endif
120 
121 
122 
Box container.
Definition: ubox.hpp:64
UFilebox(const UArgs &arglist=UArgs::none)
create a new file box (
Definition: ufilebox.cpp:39
Ubit Event class.
Definition: uevent.hpp:30
virtual void setDir(const UStr &)
note that setDir and setFilter reload the directory.
Definition: ufilebox.cpp:364
virtual void rescan()
rescans the directory and updates the display.
Definition: ufilebox.cpp:219
virtual void setFilter(const UStr &)
syntax: "C++ Files (*.cpp; *.hpp)" or "*.cc; *.hh" or "*.*"
Definition: ufilebox.cpp:375
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
UStr & path()
returns the full pathname: getDir()/getName().
Definition: ufilebox.hpp:70
Definition: uhardfont.hpp:31
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
static const UArgs none
the empty arglist.
Definition: uargs.hpp:45
const UStr & getDir() const
returns the directory of the file (without the file name).
Definition: ufilebox.hpp:63
Definition: ufilebox.hpp:49
Makes widgets (exclusively) selectable.
Definition: uchoice.hpp:153
const UStr & getFilter() const
returns the extension filter.
Definition: ufilebox.hpp:73
Ubit String.
Definition: ustr.hpp:72
const UStr & getName() const
returns the name of the file (without the directory).
Definition: ufilebox.hpp:66