]> git.mxchange.org Git - flightgear.git/blob - src/GUI/FileDialog.hxx
Initial work on native file dialog support.
[flightgear.git] / src / GUI / FileDialog.hxx
1 // FileDialog.hxx - abstract inteface for a file open/save dialog
2
3 #ifndef FG_GUI_FILE_DIALOG_HXX
4 #define FG_GUI_FILE_DIALOG_HXX 1
5
6 #include <memory> // for std::auto_ptr
7
8 #include <simgear/misc/strutils.hxx> // for string_list
9 #include <simgear/misc/sg_path.hxx>
10
11 #include <simgear/nasal/cppbind/Ghost.hxx>
12
13 // forward decls
14 class SGPropertyNode;
15
16 class FGFileDialog
17 {
18 public:
19     typedef enum {
20         USE_OPEN_FILE,
21         USE_SAVE_FILE,
22         USE_CHOOSE_DIR
23     } Usage;
24     
25     std::string getButton() const
26     { return _buttonText; }
27     
28     void setButton(const std::string& aText);
29
30     SGPath getDirectory() const
31     { return _initialPath; }
32     
33     void setDirectory(const SGPath& aPath);
34     
35     string_list filterPatterns() const
36     { return _filterPatterns; }
37     
38     void setFilterPatterns(const string_list& patterns);
39     
40     /// for saving
41     std::string getPlaceholder() const
42     { return _placeholder; }
43     
44     void setPlaceholderName(const std::string& aName);
45
46     bool showHidden() const
47     { return _showHidden; }
48     void setShowHidden(bool show);
49     
50     /**
51      * Destructor.
52      */
53     virtual ~FGFileDialog ();
54
55      virtual void exec() = 0;
56
57      class Callback
58      {
59      public:
60          virtual ~Callback() { }
61          virtual void onFileDialogDone(FGFileDialog* ins, const SGPath& result) = 0;
62      };
63
64      virtual void setCallback(Callback* aCB);
65
66     naRef openFromNasal(const nasal::CallContext& ctx);
67     naRef setCallbackFromNasal(const nasal::CallContext& ctx);
68 protected:
69     FGFileDialog(const std::string& aTitle, Usage use);
70     
71     const Usage _usage;
72     std::string _title, _buttonText;
73     SGPath _initialPath;
74     string_list _filterPatterns;
75     std::string _placeholder;
76     bool _showHidden;
77     std::auto_ptr<Callback> _callback;
78 };
79
80 #endif // FG_GUI_FILE_DIALOG_HXX