file_dialog.h
1 /*************************************************************************/
2 /* file_dialog.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef FILE_DIALOG_H
30 #define FILE_DIALOG_H
31 
32 #include "scene/gui/dialogs.h"
33 #include "scene/gui/tree.h"
34 #include "scene/gui/line_edit.h"
35 #include "scene/gui/option_button.h"
36 #include "scene/gui/dialogs.h"
37 #include "scene/gui/tool_button.h"
38 #include "os/dir_access.h"
39 #include "box_container.h"
44 
45  OBJ_TYPE( FileDialog, ConfirmationDialog );
46 
47 public:
48 
49  enum Access {
50  ACCESS_RESOURCES,
51  ACCESS_USERDATA,
52  ACCESS_FILESYSTEM
53  };
54 
55 
56  enum Mode {
57  MODE_OPEN_FILE,
58  MODE_OPEN_FILES,
59  MODE_OPEN_DIR,
60  MODE_SAVE_FILE,
61  };
62 
63  typedef Ref<Texture> (*GetIconFunc)(const String&);
64  typedef void (*RegisterFunc)(FileDialog*);
65 
66  static GetIconFunc get_icon_func;
67  static GetIconFunc get_large_icon_func;
68  static RegisterFunc register_func;
69  static RegisterFunc unregister_func;
70 
71 private:
72 
73  ConfirmationDialog *makedialog;
74  LineEdit *makedirname;
75 
76  Button *makedir;
77  Access access;
78  //Button *action;
79  VBoxContainer *vbox;
80  Mode mode;
81  LineEdit *dir;
82  OptionButton *drives;
83  Tree *tree;
84  LineEdit *file;
85  AcceptDialog *mkdirerr;
86  AcceptDialog *exterr;
87  OptionButton *filter;
88  DirAccess *dir_access;
89  ConfirmationDialog *confirm_save;
90 
91  ToolButton *refresh;
92 
93  Vector<String> filters;
94 
95 
96  static bool default_show_hidden_files;
97  bool show_hidden_files;
98 
99  bool invalidated;
100 
101  void update_dir();
102  void update_file_list();
103  void update_filters();
104 
105  void _tree_selected();
106 
107  void _select_drive(int p_idx);
108  void _tree_dc_selected();
109  void _dir_entered(String p_dir);
110  void _file_entered(const String& p_file);
111  void _action_pressed();
112  void _save_confirm_pressed();
113  void _cancel_pressed();
114  void _filter_selected(int);
115  void _make_dir();
116  void _make_dir_confirm();
117 
118  void _update_drives();
119 
120  void _unhandled_input(const InputEvent& p_event);
121 
122  virtual void _post_popup();
123 
124 protected:
125 
126  void _notification(int p_what);
127  static void _bind_methods();
128  //bind helpers
129 public:
130 
131  void clear_filters();
132  void add_filter(const String& p_filter);
133 
134  void set_enable_multiple_selection(bool p_enable);
135  Vector<String> get_selected_files() const;
136 
137  String get_current_dir() const;
138  String get_current_file() const;
139  String get_current_path() const;
140  void set_current_dir(const String& p_dir);
141  void set_current_file(const String& p_file);
142  void set_current_path(const String& p_path);
143 
144  void set_mode(Mode p_mode);
145  Mode get_mode() const;
146 
147  VBoxContainer *get_vbox();
148  LineEdit *get_line_edit() { return file; }
149 
150  void set_access(Access p_access);
151  Access get_access() const;
152 
153  void set_show_hidden_files(bool p_show);
154  bool is_showing_hidden_files() const;
155 
156  static void set_default_show_hidden_files(bool p_show);
157 
158  void invalidate();
159 
160  FileDialog();
161  ~FileDialog();
162 
163 };
164 
166 
167  OBJ_TYPE( LineEditFileChooser, HBoxContainer );
168  Button *button;
169  LineEdit *line_edit;
170  FileDialog *dialog;
171 
172  void _chosen(const String& p_text);
173  void _browse();
174 protected:
175  static void _bind_methods();
176 public:
177 
178  Button *get_button() { return button; }
179  LineEdit *get_line_edit() { return line_edit; }
180  FileDialog *get_file_dialog() { return dialog; }
181 
183 };
184 
185 VARIANT_ENUM_CAST( FileDialog::Mode );
186 VARIANT_ENUM_CAST( FileDialog::Access );
187 
188 #endif
Definition: file_dialog.h:43
Definition: box_container.h:69
Definition: dialogs.h:144
Definition: box_container.h:80
Definition: input_event.h:263
Definition: dialogs.h:88
Definition: tree.h:247
Definition: tool_button.h:34
Definition: ustring.h:64
Definition: file_dialog.h:165
Definition: button.h:36
Definition: option_button.h:37
Definition: dir_access.h:41
Definition: line_edit.h:36