| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  file_dialog.h                                                        */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #ifndef FILE_DIALOG_H
 | 
					
						
							|  |  |  | #define FILE_DIALOG_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "box_container.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/dir_access.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/gui/dialogs.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "scene/gui/line_edit.h"
 | 
					
						
							|  |  |  | #include "scene/gui/option_button.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/gui/tree.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-10 07:28:17 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | class FileDialog : public ConfirmationDialog { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	GDCLASS(FileDialog, ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | public: | 
					
						
							|  |  |  | 	enum Access { | 
					
						
							|  |  |  | 		ACCESS_RESOURCES, | 
					
						
							|  |  |  | 		ACCESS_USERDATA, | 
					
						
							|  |  |  | 		ACCESS_FILESYSTEM | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	enum FileMode { | 
					
						
							|  |  |  | 		FILE_MODE_OPEN_FILE, | 
					
						
							|  |  |  | 		FILE_MODE_OPEN_FILES, | 
					
						
							|  |  |  | 		FILE_MODE_OPEN_DIR, | 
					
						
							|  |  |  | 		FILE_MODE_OPEN_ANY, | 
					
						
							|  |  |  | 		FILE_MODE_SAVE_FILE | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	typedef Ref<Texture2D> (*GetIconFunc)(const String &); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	typedef void (*RegisterFunc)(FileDialog *); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	static GetIconFunc get_icon_func; | 
					
						
							|  |  |  | 	static GetIconFunc get_large_icon_func; | 
					
						
							|  |  |  | 	static RegisterFunc register_func; | 
					
						
							|  |  |  | 	static RegisterFunc unregister_func; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	ConfirmationDialog *makedialog; | 
					
						
							|  |  |  | 	LineEdit *makedirname; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Button *makedir; | 
					
						
							| 
									
										
										
										
											2021-02-09 18:24:36 +01:00
										 |  |  | 	Access access = ACCESS_RESOURCES; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//Button *action;
 | 
					
						
							|  |  |  | 	VBoxContainer *vbox; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	FileMode mode; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	LineEdit *dir; | 
					
						
							| 
									
										
										
										
											2020-02-10 09:19:29 +01:00
										 |  |  | 	HBoxContainer *drives_container; | 
					
						
							|  |  |  | 	HBoxContainer *shortcuts_container; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	OptionButton *drives; | 
					
						
							|  |  |  | 	Tree *tree; | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	HBoxContainer *file_box; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	LineEdit *file; | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	OptionButton *filter; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	AcceptDialog *mkdirerr; | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 	AcceptDialog *exterr; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	DirAccess *dir_access; | 
					
						
							|  |  |  | 	ConfirmationDialog *confirm_save; | 
					
						
							| 
									
										
										
										
											2015-12-04 19:33:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 14:01:03 +02:00
										 |  |  | 	Label *message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Button *dir_prev; | 
					
						
							|  |  |  | 	Button *dir_next; | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	Button *dir_up; | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	Button *refresh; | 
					
						
							|  |  |  | 	Button *show_hidden; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	Vector<String> filters; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 14:01:03 +02:00
										 |  |  | 	Vector<String> local_history; | 
					
						
							|  |  |  | 	int local_history_pos = 0; | 
					
						
							|  |  |  | 	void _push_history(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 18:24:36 +01:00
										 |  |  | 	bool mode_overrides_title = true; | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 	static bool default_show_hidden_files; | 
					
						
							| 
									
										
										
										
											2021-02-09 18:24:36 +01:00
										 |  |  | 	bool show_hidden_files = false; | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 18:24:36 +01:00
										 |  |  | 	bool invalidated = true; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void update_dir(); | 
					
						
							| 
									
										
										
										
											2019-06-28 10:29:50 +03:00
										 |  |  | 	void update_file_name(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void update_file_list(); | 
					
						
							|  |  |  | 	void update_filters(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 17:45:16 +02:00
										 |  |  | 	void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _tree_selected(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _select_drive(int p_idx); | 
					
						
							| 
									
										
										
										
											2018-02-15 00:44:11 -02:00
										 |  |  | 	void _tree_item_activated(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _dir_entered(String p_dir); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void _file_entered(const String &p_file); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _action_pressed(); | 
					
						
							|  |  |  | 	void _save_confirm_pressed(); | 
					
						
							|  |  |  | 	void _cancel_pressed(); | 
					
						
							|  |  |  | 	void _filter_selected(int); | 
					
						
							|  |  |  | 	void _make_dir(); | 
					
						
							|  |  |  | 	void _make_dir_confirm(); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 	void _go_up(); | 
					
						
							| 
									
										
										
										
											2021-03-19 14:01:03 +02:00
										 |  |  | 	void _go_back(); | 
					
						
							|  |  |  | 	void _go_forward(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void _update_drives(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	void _unhandled_input(const Ref<InputEvent> &p_event); | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 	bool _is_open_should_be_disabled(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-10 11:34:39 +01:00
										 |  |  | 	virtual void _post_popup() override; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	void _theme_changed(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _notification(int p_what); | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 	//bind helpers
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | 	void popup_file_dialog(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void clear_filters(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void add_filter(const String &p_filter); | 
					
						
							|  |  |  | 	void set_filters(const Vector<String> &p_filters); | 
					
						
							| 
									
										
										
										
											2016-07-17 01:58:28 +02:00
										 |  |  | 	Vector<String> get_filters() const; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void set_enable_multiple_selection(bool p_enable); | 
					
						
							|  |  |  | 	Vector<String> get_selected_files() const; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	String get_current_dir() const; | 
					
						
							|  |  |  | 	String get_current_file() const; | 
					
						
							|  |  |  | 	String get_current_path() const; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void set_current_dir(const String &p_dir); | 
					
						
							|  |  |  | 	void set_current_file(const String &p_file); | 
					
						
							|  |  |  | 	void set_current_path(const String &p_path); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 	void set_mode_overrides_title(bool p_override); | 
					
						
							|  |  |  | 	bool is_mode_overriding_title() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	void set_file_mode(FileMode p_mode); | 
					
						
							|  |  |  | 	FileMode get_file_mode() const; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	VBoxContainer *get_vbox(); | 
					
						
							|  |  |  | 	LineEdit *get_line_edit() { return file; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_access(Access p_access); | 
					
						
							|  |  |  | 	Access get_access() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 	void set_show_hidden_files(bool p_show); | 
					
						
							|  |  |  | 	bool is_showing_hidden_files() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static void set_default_show_hidden_files(bool p_show); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void invalidate(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | 	void deselect_all(); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	FileDialog(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	~FileDialog(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | VARIANT_ENUM_CAST(FileDialog::FileMode); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | VARIANT_ENUM_CAST(FileDialog::Access); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 |