TDME2  1.9.200
FileDialogScreenController.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <unordered_map>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
18 
19 using std::string;
20 using std::unique_ptr;
21 using std::unordered_map;
22 using std::vector;
23 
37 
38 /**
39  * File dialog screen controller
40  * @author Andreas Drewke
41  */
43  : public ScreenController
44  , public virtual GUIActionListener
45  , public virtual GUIChangeListener
46  , public virtual GUIFocusListener
47  , public virtual GUITooltipRequestListener
48 {
49 
50 private:
51  PopUps* popUps { nullptr };
52  GUIScreenNode* screenNode { nullptr };
53  string cwd;
54  vector<string> extensions;
55  string captionText;
57  GUIElementNode* pathNode { nullptr };
59  GUIElementNode* filesNode { nullptr };
62  GUIElementNode* drivesNode { nullptr };
64  unique_ptr<Action> applyAction;
65  unique_ptr<Action> cancelAction;
66  vector<string> fileList;
67  bool enableFilter { false };
68  bool filtered { false };
69  vector<string> favorites;
70  vector<string> recents;
71  string defaultCwd;
72  unordered_map<string, string> defaultCwdByExtensions;
75 
76  /**
77  * Set up files
78  * @return success
79  */
80  bool setupFiles();
81 
82  /**
83  * Set up files
84  * @param fileNameList file name list
85  * @param selectedFileName selected file name
86  */
87  void setupFiles(const vector<string>& fileNameList, const string& selectedFileName = string());
88 
89  /**
90  * Set up favorites
91  */
92  void setupFavorites();
93 
94  /**
95  * Set up recent
96  */
97  void setupRecents();
98 
99  /**
100  * Set up drives
101  */
102  void setupDrives();
103 
104  /**
105  * @return extension hash
106  */
107  inline const string getExtensionHash() {
108  string extensionHash = "|";
109  for (const auto& extension: extensions) extensionHash+= extension + "|";
110  if (extensions.empty() == true) extensionHash+= "|";
111  return extensionHash;
112  }
113 
114 public:
115  // forbid class copy
117 
118  /**
119  * Public constructor
120  * @param popUps pop ups
121  */
123 
124  /**
125  * Destructor
126  */
127  virtual ~FileDialogScreenController();
128 
129  // overridden methods
130  inline GUIScreenNode* getScreenNode() override {
131  return screenNode;
132  }
133 
134  /**
135  * @return default current working directory
136  */
137  inline const string& getDefaultCWD() {
138  return defaultCwd;
139  }
140 
141  /**
142  * Set default current working directory
143  * @param defaultCWD default current working directory
144  */
145  inline void setDefaultCWD(const string& defaultCwd) {
146  this->defaultCwd = defaultCwd;
147  }
148 
149  /**
150  * @return path name
151  */
152  inline const string& getPathName() {
153  return cwd;
154  }
155 
156  /**
157  * @return file name
158  */
159  const string getFileName();
160 
161  /**
162  * Shows the file dialog pop up
163  * @param cwd current working directory
164  * @param captionText caption text
165  * @param extensions extensions
166  * @param fileName file name
167  * @param enableFilter enable filter
168  * @param applyAction apply action
169  * @param cancelAction cancel action
170  * @param settingsFileName settings file name
171  * @param settingsPathName settings path name
172  * @throws IOException
173  */
174  void show(const string& cwd, const string& captionText, const vector<string>& extensions, const string& fileName, bool enableFilter, Action* applyAction, Action* cancelAction = nullptr, const string& settingsFileName = ".filedialog.properties", const string& settingsPathName = string());
175 
176  /**
177  * Abort the file dialog pop up
178  */
179  void close();
180 
181  // overridden methods
182  void initialize() override;
183  void dispose() override;
184  void onChange(GUIElementNode* node) override;
185  void onAction(GUIActionListenerType type, GUIElementNode* node) override;
186  void onFocus(GUIElementNode* node) override;
187  void onUnfocus(GUIElementNode* node) override;
188  void onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) override;
189  void onTooltipCloseRequest() override;
190 
191  /**
192  * Load settings
193  */
194  void loadSettings();
195 
196  /**
197  * Save settings
198  */
199  void saveSettings();
200 
201  /**
202  * Get file image name
203  * @param fileName file name
204  * @return file image name
205  */
206  static const string getFileImageName(const string& fileName);
207 
208 };
GUI node base class.
Definition: GUINode.h:64
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void show(const string &cwd, const string &captionText, const vector< string > &extensions, const string &fileName, bool enableFilter, Action *applyAction, Action *cancelAction=nullptr, const string &settingsFileName=".filedialog.properties", const string &settingsPathName=string())
Shows the file dialog pop up.
void setDefaultCWD(const string &defaultCwd)
Set default current working directory.
static const string getFileImageName(const string &fileName)
Get file image name.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
Pop ups controller accessor class.
Definition: PopUps.h:29
Mutable utf8 aware string class.
Definition: MutableString.h:23
GUI action listener interface.
GUI change listener interface.
GUI focus listener interface.
Screen controller, which connects GUI screen definition with code.
Action Interface.
Definition: Action.h:11
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6