1 | /**************************************************************************/ |
2 | /* file_dialog.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef FILE_DIALOG_H |
32 | #define FILE_DIALOG_H |
33 | |
34 | #include "box_container.h" |
35 | #include "core/io/dir_access.h" |
36 | #include "scene/gui/dialogs.h" |
37 | #include "scene/gui/line_edit.h" |
38 | #include "scene/gui/option_button.h" |
39 | #include "scene/gui/tree.h" |
40 | |
41 | class FileDialog : public ConfirmationDialog { |
42 | GDCLASS(FileDialog, ConfirmationDialog); |
43 | |
44 | public: |
45 | enum Access { |
46 | ACCESS_RESOURCES, |
47 | ACCESS_USERDATA, |
48 | ACCESS_FILESYSTEM |
49 | }; |
50 | |
51 | enum FileMode { |
52 | FILE_MODE_OPEN_FILE, |
53 | FILE_MODE_OPEN_FILES, |
54 | FILE_MODE_OPEN_DIR, |
55 | FILE_MODE_OPEN_ANY, |
56 | FILE_MODE_SAVE_FILE |
57 | }; |
58 | |
59 | typedef Ref<Texture2D> (*GetIconFunc)(const String &); |
60 | typedef void (*RegisterFunc)(FileDialog *); |
61 | |
62 | static GetIconFunc get_icon_func; |
63 | static RegisterFunc register_func; |
64 | static RegisterFunc unregister_func; |
65 | |
66 | private: |
67 | ConfirmationDialog *makedialog = nullptr; |
68 | LineEdit *makedirname = nullptr; |
69 | |
70 | Button *makedir = nullptr; |
71 | Access access = ACCESS_RESOURCES; |
72 | VBoxContainer *vbox = nullptr; |
73 | FileMode mode; |
74 | LineEdit *dir = nullptr; |
75 | HBoxContainer *drives_container = nullptr; |
76 | HBoxContainer *shortcuts_container = nullptr; |
77 | OptionButton *drives = nullptr; |
78 | Tree *tree = nullptr; |
79 | HBoxContainer *file_box = nullptr; |
80 | LineEdit *file = nullptr; |
81 | OptionButton *filter = nullptr; |
82 | AcceptDialog *mkdirerr = nullptr; |
83 | AcceptDialog *exterr = nullptr; |
84 | Ref<DirAccess> dir_access; |
85 | ConfirmationDialog *confirm_save = nullptr; |
86 | |
87 | Label *message = nullptr; |
88 | |
89 | Button *dir_prev = nullptr; |
90 | Button *dir_next = nullptr; |
91 | Button *dir_up = nullptr; |
92 | |
93 | Button *refresh = nullptr; |
94 | Button *show_hidden = nullptr; |
95 | |
96 | Vector<String> filters; |
97 | |
98 | Vector<String> local_history; |
99 | int local_history_pos = 0; |
100 | void _push_history(); |
101 | |
102 | bool mode_overrides_title = true; |
103 | String root_subfolder; |
104 | String root_prefix; |
105 | |
106 | static bool default_show_hidden_files; |
107 | bool show_hidden_files = false; |
108 | bool use_native_dialog = false; |
109 | |
110 | bool is_invalidating = false; |
111 | |
112 | struct ThemeCache { |
113 | Ref<Texture2D> parent_folder; |
114 | Ref<Texture2D> forward_folder; |
115 | Ref<Texture2D> back_folder; |
116 | Ref<Texture2D> reload; |
117 | Ref<Texture2D> toggle_hidden; |
118 | Ref<Texture2D> folder; |
119 | Ref<Texture2D> file; |
120 | |
121 | Color folder_icon_color; |
122 | Color file_icon_color; |
123 | Color file_disabled_color; |
124 | |
125 | Color icon_normal_color; |
126 | Color icon_hover_color; |
127 | Color icon_focus_color; |
128 | Color icon_pressed_color; |
129 | } theme_cache; |
130 | |
131 | void update_dir(); |
132 | void update_file_name(); |
133 | void update_file_list(); |
134 | void update_filters(); |
135 | |
136 | void _focus_file_text(); |
137 | |
138 | void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected); |
139 | void _tree_selected(); |
140 | |
141 | void _select_drive(int p_idx); |
142 | void _tree_item_activated(); |
143 | void _dir_submitted(String p_dir); |
144 | void _file_submitted(const String &p_file); |
145 | void _action_pressed(); |
146 | void _save_confirm_pressed(); |
147 | void _cancel_pressed(); |
148 | void _filter_selected(int); |
149 | void _make_dir(); |
150 | void _make_dir_confirm(); |
151 | void _go_up(); |
152 | void _go_back(); |
153 | void _go_forward(); |
154 | |
155 | void _change_dir(const String &p_new_dir); |
156 | void _update_drives(bool p_select = true); |
157 | |
158 | void _invalidate(); |
159 | |
160 | virtual void shortcut_input(const Ref<InputEvent> &p_event) override; |
161 | |
162 | void _native_dialog_cb(bool p_ok, const Vector<String> &p_files); |
163 | |
164 | bool _is_open_should_be_disabled(); |
165 | |
166 | virtual void () override; |
167 | |
168 | protected: |
169 | void _validate_property(PropertyInfo &p_property) const; |
170 | void _notification(int p_what); |
171 | static void _bind_methods(); |
172 | |
173 | public: |
174 | virtual void (const Rect2i &p_rect = Rect2i()) override; |
175 | |
176 | void (); |
177 | void clear_filters(); |
178 | void add_filter(const String &p_filter, const String &p_description = "" ); |
179 | void set_filters(const Vector<String> &p_filters); |
180 | Vector<String> get_filters() const; |
181 | |
182 | void set_enable_multiple_selection(bool p_enable); |
183 | Vector<String> get_selected_files() const; |
184 | |
185 | String get_current_dir() const; |
186 | String get_current_file() const; |
187 | String get_current_path() const; |
188 | void set_current_dir(const String &p_dir); |
189 | void set_current_file(const String &p_file); |
190 | void set_current_path(const String &p_path); |
191 | |
192 | void set_root_subfolder(const String &p_root); |
193 | String get_root_subfolder() const; |
194 | |
195 | void set_mode_overrides_title(bool p_override); |
196 | bool is_mode_overriding_title() const; |
197 | |
198 | void set_use_native_dialog(bool p_native); |
199 | bool get_use_native_dialog() const; |
200 | |
201 | void set_file_mode(FileMode p_mode); |
202 | FileMode get_file_mode() const; |
203 | |
204 | VBoxContainer *get_vbox(); |
205 | LineEdit *get_line_edit() { return file; } |
206 | |
207 | void set_access(Access p_access); |
208 | Access get_access() const; |
209 | |
210 | void set_show_hidden_files(bool p_show); |
211 | bool is_showing_hidden_files() const; |
212 | |
213 | static void set_default_show_hidden_files(bool p_show); |
214 | |
215 | void invalidate(); |
216 | |
217 | void deselect_all(); |
218 | |
219 | FileDialog(); |
220 | ~FileDialog(); |
221 | }; |
222 | |
223 | VARIANT_ENUM_CAST(FileDialog::FileMode); |
224 | VARIANT_ENUM_CAST(FileDialog::Access); |
225 | |
226 | #endif // FILE_DIALOG_H |
227 | |