Virtual Testbed
Ship dynamics simulator for extreme conditions
FileDialog.hh
1 #ifndef VTESTBED_GUI_FILEDIALOG_HH
2 #define VTESTBED_GUI_FILEDIALOG_HH
3 
4 #include <filesystem>
5 #include <string>
6 #include <unordered_set>
7 
8 #include <Corrade/Utility/Directory.h>
9 
10 namespace vtb {
11 
12  namespace gui {
13 
14  class FileDialog {
15 
16  private:
17  typedef Corrade::Utility::Directory::Flag Flag;
18  typedef Corrade::Containers::EnumSet<Flag> FlagSet;
19  enum struct State {
20  Listing,
21  Opening,
22  Error
23  };
24  using path_type = std::filesystem::path;
25 
26  private:
27  FlagSet _flags = Flag::SkipDirectories | Flag::SkipSpecial |
28  Flag::SkipDotAndDotDot | Flag::SortAscending;
31  path_type _directory;
32  std::vector<path_type> _components;
33  std::string _title, _buttonText, _errorText;
34  State _state = State::Listing;
35  int _selected_index = -1;
36  bool _visible = false;
37  bool _breadcrumbs = true;
38 
39  public:
40 
41  FileDialog();
42 
43  inline void
44  title(const std::string& rhs) {
45  this->_title = rhs;
46  }
47 
48  inline void
49  buttonText(const std::string& rhs) {
50  this->_buttonText = rhs;
51  }
52 
53  inline void
54  error(const std::string& message) {
55  this->_state = State::Error;
56  this->_errorText = message;
57  }
58 
59  inline void
60  extensions(std::vector<std::string> rhs) {
61  this->_extensions.clear();
62  this->_extensions.insert(rhs.begin(), rhs.end());
63  }
64 
65  inline void
66  visible(bool b) {
67  this->_visible = b;
68  }
69 
70  inline bool
71  visible() const {
72  return this->_visible;
73  }
74 
75  inline bool
76  invisible() const {
77  return !this->_visible;
78  }
79 
80  inline bool
81  hasSelectedFile() const {
82  return this->_selected_index != -1;
83  }
84 
85  inline const std::string&
86  selectedFile() const {
87  return this->_files[this->_selected_index];
88  }
89 
90  bool
91  draw();
92 
93  void
94  list();
95 
96  void directory(const path_type& rhs);
97  void next_directory(const path_type& rhs);
98 
99  };
100 
101  }
102 
103 }
104 
105 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9