| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  file_dialog.cpp                                                      */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       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
										 |  |  | #include "file_dialog.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-11 11:30:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-07 19:33:38 -03:00
										 |  |  | #include "core/string/print_string.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/gui/label.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr; | 
					
						
							|  |  |  | FileDialog::GetIconFunc FileDialog::get_large_icon_func = nullptr; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | FileDialog::RegisterFunc FileDialog::register_func = nullptr; | 
					
						
							|  |  |  | FileDialog::RegisterFunc FileDialog::unregister_func = nullptr; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 18:45:19 +02:00
										 |  |  | void FileDialog::popup_file_dialog() { | 
					
						
							|  |  |  | 	popup_centered_clamped(Size2i(700, 500), 0.8f); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | VBoxContainer *FileDialog::get_vbox() { | 
					
						
							|  |  |  | 	return vbox; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | void FileDialog::_theme_changed() { | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	Color font_color = vbox->get_theme_color("font_color", "Button"); | 
					
						
							|  |  |  | 	Color font_color_hover = vbox->get_theme_color("font_color_hover", "Button"); | 
					
						
							|  |  |  | 	Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "Button"); | 
					
						
							| 
									
										
										
										
											2015-12-04 19:33:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	dir_up->add_theme_color_override("icon_color_normal", font_color); | 
					
						
							|  |  |  | 	dir_up->add_theme_color_override("icon_color_hover", font_color_hover); | 
					
						
							|  |  |  | 	dir_up->add_theme_color_override("icon_color_pressed", font_color_pressed); | 
					
						
							| 
									
										
										
										
											2019-10-14 14:00:45 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	refresh->add_theme_color_override("icon_color_normal", font_color); | 
					
						
							|  |  |  | 	refresh->add_theme_color_override("icon_color_hover", font_color_hover); | 
					
						
							|  |  |  | 	refresh->add_theme_color_override("icon_color_pressed", font_color_pressed); | 
					
						
							| 
									
										
										
										
											2019-10-14 14:00:45 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	show_hidden->add_theme_color_override("icon_color_normal", font_color); | 
					
						
							|  |  |  | 	show_hidden->add_theme_color_override("icon_color_hover", font_color_hover); | 
					
						
							|  |  |  | 	show_hidden->add_theme_color_override("icon_color_pressed", font_color_pressed); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-14 14:00:45 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | void FileDialog::_notification(int p_what) { | 
					
						
							|  |  |  | 	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { | 
					
						
							|  |  |  | 		if (!is_visible()) { | 
					
						
							|  |  |  | 			set_process_unhandled_input(false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2020-04-04 16:18:43 +05:30
										 |  |  | 		dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog")); | 
					
						
							|  |  |  | 		refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog")); | 
					
						
							|  |  |  | 		show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog")); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		_theme_changed(); | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { | 
					
						
							|  |  |  | 	Ref<InputEventKey> k = p_event; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (k.is_valid() && has_focus()) { | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (k->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			bool handled = true; | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 20:59:35 +03:00
										 |  |  | 			switch (k->get_keycode()) { | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 				case KEY_H: { | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (k->get_command()) { | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 						set_show_hidden_files(!show_hidden_files); | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						handled = false; | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2016-01-15 21:19:16 +01:00
										 |  |  | 				case KEY_F5: { | 
					
						
							|  |  |  | 					invalidate(); | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 				case KEY_BACKSPACE: { | 
					
						
							|  |  |  | 					_dir_entered(".."); | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2019-04-09 17:08:36 +02:00
										 |  |  | 				default: { | 
					
						
							|  |  |  | 					handled = false; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (handled) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 				set_input_as_handled(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::set_enable_multiple_selection(bool p_enable) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tree->set_select_mode(p_enable ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Vector<String> FileDialog::get_selected_files() const { | 
					
						
							|  |  |  | 	Vector<String> list; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	TreeItem *item = tree->get_root(); | 
					
						
							|  |  |  | 	while ((item = tree->get_next_selected(item))) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		list.push_back(dir_access->get_current_dir().plus_file(item->get_text(0))); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return list; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::update_dir() { | 
					
						
							| 
									
										
										
										
											2020-02-10 09:19:29 +01:00
										 |  |  | 	dir->set_text(dir_access->get_current_dir(false)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 21:59:43 +07:00
										 |  |  | 	if (drives->is_visible()) { | 
					
						
							|  |  |  | 		drives->select(dir_access->get_current_drive()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Deselect any item, to make "Select Current Folder" button text by default.
 | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | 	deselect_all(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_dir_entered(String p_dir) { | 
					
						
							|  |  |  | 	dir_access->change_dir(p_dir); | 
					
						
							|  |  |  | 	file->set_text(""); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::_file_entered(const String &p_file) { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	_action_pressed(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_save_confirm_pressed() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	String f = dir_access->get_current_dir().plus_file(file->get_text()); | 
					
						
							|  |  |  | 	emit_signal("file_selected", f); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	hide(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_post_popup() { | 
					
						
							|  |  |  | 	ConfirmationDialog::_post_popup(); | 
					
						
							|  |  |  | 	if (invalidated) { | 
					
						
							|  |  |  | 		update_file_list(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		invalidated = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == FILE_MODE_SAVE_FILE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		file->grab_focus(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		tree->grab_focus(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 00:36:48 +01:00
										 |  |  | 	set_process_unhandled_input(true); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// For open dir mode, deselect all items on file dialog open.
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (mode == FILE_MODE_OPEN_DIR) { | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | 		deselect_all(); | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 		file_box->set_visible(false); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		file_box->set_visible(true); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_action_pressed() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (mode == FILE_MODE_OPEN_FILES) { | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 		TreeItem *ti = tree->get_next_selected(nullptr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String fbase = dir_access->get_current_dir(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 		Vector<String> files; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (ti) { | 
					
						
							|  |  |  | 			files.push_back(fbase.plus_file(ti->get_text(0))); | 
					
						
							|  |  |  | 			ti = tree->get_next_selected(ti); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (files.size()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			emit_signal("files_selected", files); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	String f = dir_access->get_current_dir().plus_file(file->get_text()); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		emit_signal("file_selected", f); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		hide(); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	} else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String path = dir_access->get_current_dir(); | 
					
						
							| 
									
										
										
										
											2016-09-19 11:27:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		path = path.replace("\\", "/"); | 
					
						
							| 
									
										
										
										
											2017-09-06 23:50:18 +02:00
										 |  |  | 		TreeItem *item = tree->get_selected(); | 
					
						
							|  |  |  | 		if (item) { | 
					
						
							| 
									
										
										
										
											2016-09-19 11:27:53 +08:00
										 |  |  | 			Dictionary d = item->get_metadata(0); | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 			if (d["dir"] && d["name"] != "..") { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				path = path.plus_file(d["name"]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-19 11:27:53 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		emit_signal("dir_selected", path); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (mode == FILE_MODE_SAVE_FILE) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool valid = false; | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (filter->get_selected() == filter->get_item_count() - 1) { | 
					
						
							| 
									
										
										
										
											2018-02-15 00:44:11 -02:00
										 |  |  | 			valid = true; // match none
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else if (filters.size() > 1 && filter->get_selected() == 0) { | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 			// match all filters
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (int i = 0; i < filters.size(); i++) { | 
					
						
							|  |  |  | 				String flt = filters[i].get_slice(";", 0); | 
					
						
							|  |  |  | 				for (int j = 0; j < flt.get_slice_count(","); j++) { | 
					
						
							|  |  |  | 					String str = flt.get_slice(",", j).strip_edges(); | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 					if (f.match(str)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						valid = true; | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (valid) { | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int idx = filter->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (filters.size() > 1) { | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 				idx--; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (idx >= 0 && idx < filters.size()) { | 
					
						
							|  |  |  | 				String flt = filters[idx].get_slice(";", 0); | 
					
						
							|  |  |  | 				int filterSliceCount = flt.get_slice_count(","); | 
					
						
							|  |  |  | 				for (int j = 0; j < filterSliceCount; j++) { | 
					
						
							|  |  |  | 					String str = (flt.get_slice(",", j).strip_edges()); | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 					if (f.match(str)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						valid = true; | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-01-14 18:02:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (!valid && filterSliceCount > 0) { | 
					
						
							|  |  |  | 					String str = (flt.get_slice(",", 0).strip_edges()); | 
					
						
							|  |  |  | 					f += str.substr(1, str.length() - 1); | 
					
						
							| 
									
										
										
										
											2015-01-16 07:48:28 -05:00
										 |  |  | 					file->set_text(f.get_file()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					valid = true; | 
					
						
							| 
									
										
										
										
											2015-01-14 18:02:51 -05:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				valid = true; | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!valid) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			exterr->popup_centered(Size2(250, 80)); | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (dir_access->file_exists(f)) { | 
					
						
							| 
									
										
										
										
											2020-04-21 15:02:36 -03:00
										 |  |  | 			confirm_save->set_text(RTR("File exists, overwrite?")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			confirm_save->popup_centered(Size2(200, 80)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			emit_signal("file_selected", f); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_cancel_pressed() { | 
					
						
							|  |  |  | 	file->set_text(""); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | 	hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | bool FileDialog::_is_open_should_be_disabled() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) { | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 17:45:16 +02:00
										 |  |  | 	TreeItem *ti = tree->get_next_selected(tree->get_root()); | 
					
						
							|  |  |  | 	while (ti) { | 
					
						
							|  |  |  | 		TreeItem *prev_ti = ti; | 
					
						
							|  |  |  | 		ti = tree->get_next_selected(tree->get_root()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (ti == prev_ti) { | 
					
						
							| 
									
										
										
										
											2018-08-20 17:45:16 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-20 17:45:16 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 	// We have something that we can't select?
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!ti) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = ti->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Opening a file, but selected a folder? Forbidden.
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	return ((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden.
 | 
					
						
							|  |  |  | 		   (mode == FILE_MODE_OPEN_DIR && !d["dir"]); | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | void FileDialog::_go_up() { | 
					
						
							|  |  |  | 	dir_access->change_dir(".."); | 
					
						
							|  |  |  | 	update_file_list(); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | void FileDialog::deselect_all() { | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 	// Clear currently selected items in file manager.
 | 
					
						
							|  |  |  | 	tree->deselect_all(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// And change get_ok title.
 | 
					
						
							|  |  |  | 	if (!tree->is_anything_selected()) { | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 		get_ok_button()->set_disabled(_is_open_should_be_disabled()); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		switch (mode) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			case FILE_MODE_OPEN_FILE: | 
					
						
							|  |  |  | 			case FILE_MODE_OPEN_FILES: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 				get_ok_button()->set_text(RTR("Open")); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			case FILE_MODE_OPEN_DIR: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 				get_ok_button()->set_text(RTR("Select Current Folder")); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			case FILE_MODE_OPEN_ANY: | 
					
						
							|  |  |  | 			case FILE_MODE_SAVE_FILE: | 
					
						
							| 
									
										
										
										
											2018-09-26 13:13:56 +02:00
										 |  |  | 				// FIXME: Implement, or refactor to avoid duplication with set_mode
 | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-15 00:44:11 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 17:45:16 +02:00
										 |  |  | void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selected) { | 
					
						
							|  |  |  | 	_tree_selected(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void FileDialog::_tree_selected() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	TreeItem *ti = tree->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!ti) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Dictionary d = ti->get_metadata(0); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!d["dir"]) { | 
					
						
							|  |  |  | 		file->set_text(d["name"]); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	} else if (mode == FILE_MODE_OPEN_DIR) { | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 		get_ok_button()->set_text(RTR("Select This Folder")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-24 21:12:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 	get_ok_button()->set_disabled(_is_open_should_be_disabled()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-15 00:44:11 -02:00
										 |  |  | void FileDialog::_tree_item_activated() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	TreeItem *ti = tree->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!ti) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Dictionary d = ti->get_metadata(0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (d["dir"]) { | 
					
						
							|  |  |  | 		dir_access->change_dir(d["name"]); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			file->set_text(""); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		call_deferred("_update_file_list"); | 
					
						
							|  |  |  | 		call_deferred("_update_dir"); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		_action_pressed(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-28 10:29:50 +03:00
										 |  |  | void FileDialog::update_file_name() { | 
					
						
							|  |  |  | 	int idx = filter->get_selected() - 1; | 
					
						
							|  |  |  | 	if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (idx == -1) { | 
					
						
							| 
									
										
										
										
											2020-05-10 12:56:01 +02:00
										 |  |  | 			idx += 1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-06-28 10:29:50 +03:00
										 |  |  | 		String filter_str = filters[idx]; | 
					
						
							|  |  |  | 		String file_str = file->get_text(); | 
					
						
							|  |  |  | 		String base_name = file_str.get_basename(); | 
					
						
							|  |  |  | 		file_str = base_name + "." + filter_str.strip_edges().to_lower(); | 
					
						
							|  |  |  | 		file->set_text(file_str); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void FileDialog::update_file_list() { | 
					
						
							|  |  |  | 	tree->clear(); | 
					
						
							| 
									
										
										
										
											2019-10-24 15:31:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Scroll back to the top after opening a directory
 | 
					
						
							|  |  |  | 	tree->get_vscroll_bar()->set_value(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	dir_access->list_dir_begin(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	TreeItem *root = tree->create_item(); | 
					
						
							| 
									
										
										
										
											2020-04-04 16:18:43 +05:30
										 |  |  | 	Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog"); | 
					
						
							| 
									
										
										
										
											2020-06-08 09:41:45 -03:00
										 |  |  | 	Ref<Texture2D> file_icon = vbox->get_theme_icon("file", "FileDialog"); | 
					
						
							| 
									
										
										
										
											2020-04-04 16:18:43 +05:30
										 |  |  | 	const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog"); | 
					
						
							| 
									
										
										
										
											2020-06-08 09:41:45 -03:00
										 |  |  | 	const Color file_color = vbox->get_theme_color("file_icon_modulate", "FileDialog"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	List<String> files; | 
					
						
							|  |  |  | 	List<String> dirs; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-10 00:20:24 -03:00
										 |  |  | 	bool is_hidden; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	String item; | 
					
						
							| 
									
										
										
										
											2015-03-21 18:33:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 11:09:57 +02:00
										 |  |  | 	while ((item = dir_access->get_next()) != "") { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (item == "." || item == "..") { | 
					
						
							| 
									
										
										
										
											2017-11-21 02:58:07 +03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-21 02:58:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-10 00:20:24 -03:00
										 |  |  | 		is_hidden = dir_access->current_is_hidden(); | 
					
						
							| 
									
										
										
										
											2015-03-21 18:33:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-10 00:20:24 -03:00
										 |  |  | 		if (show_hidden_files || !is_hidden) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!dir_access->current_is_dir()) { | 
					
						
							| 
									
										
										
										
											2015-03-21 18:33:32 +01:00
										 |  |  | 				files.push_back(item); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2015-03-21 18:33:32 +01:00
										 |  |  | 				dirs.push_back(item); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-03-21 18:33:32 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-11 20:07:59 +01:00
										 |  |  | 	dirs.sort_custom<NaturalNoCaseComparator>(); | 
					
						
							|  |  |  | 	files.sort_custom<NaturalNoCaseComparator>(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	while (!dirs.is_empty()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String &dir_name = dirs.front()->get(); | 
					
						
							|  |  |  | 		TreeItem *ti = tree->create_item(root); | 
					
						
							| 
									
										
										
										
											2017-11-21 02:58:07 +03:00
										 |  |  | 		ti->set_text(0, dir_name); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ti->set_icon(0, folder); | 
					
						
							| 
									
										
										
										
											2019-08-24 17:13:48 +02:00
										 |  |  | 		ti->set_icon_modulate(0, folder_color); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-19 11:27:53 +08:00
										 |  |  | 		Dictionary d; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		d["name"] = dir_name; | 
					
						
							|  |  |  | 		d["dir"] = true; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ti->set_metadata(0, d); | 
					
						
							| 
									
										
										
										
											2016-09-19 11:27:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		dirs.pop_front(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	List<String> patterns; | 
					
						
							|  |  |  | 	// build filter
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (filter->get_selected() == filter->get_item_count() - 1) { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 		// match all
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (filters.size() > 1 && filter->get_selected() == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		// match all filters
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < filters.size(); i++) { | 
					
						
							|  |  |  | 			String f = filters[i].get_slice(";", 0); | 
					
						
							|  |  |  | 			for (int j = 0; j < f.get_slice_count(","); j++) { | 
					
						
							|  |  |  | 				patterns.push_back(f.get_slice(",", j).strip_edges()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int idx = filter->get_selected(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (filters.size() > 1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			idx--; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (idx >= 0 && idx < filters.size()) { | 
					
						
							|  |  |  | 			String f = filters[idx].get_slice(";", 0); | 
					
						
							|  |  |  | 			for (int j = 0; j < f.get_slice_count(","); j++) { | 
					
						
							|  |  |  | 				patterns.push_back(f.get_slice(",", j).strip_edges()); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String base_dir = dir_access->get_current_dir(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	while (!files.is_empty()) { | 
					
						
							|  |  |  | 		bool match = patterns.is_empty(); | 
					
						
							| 
									
										
										
										
											2016-11-15 22:36:41 +09:00
										 |  |  | 		String match_str; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (List<String>::Element *E = patterns.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			if (files.front()->get().matchn(E->get())) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				match_str = E->get(); | 
					
						
							|  |  |  | 				match = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (match) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			TreeItem *ti = tree->create_item(root); | 
					
						
							|  |  |  | 			ti->set_text(0, files.front()->get()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (get_icon_func) { | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 				Ref<Texture2D> icon = get_icon_func(base_dir.plus_file(files.front()->get())); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				ti->set_icon(0, icon); | 
					
						
							| 
									
										
										
										
											2020-06-08 09:41:45 -03:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				ti->set_icon(0, file_icon); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-06-08 09:41:45 -03:00
										 |  |  | 			ti->set_icon_modulate(0, file_color); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 			if (mode == FILE_MODE_OPEN_DIR) { | 
					
						
							| 
									
										
										
										
											2020-04-04 16:18:43 +05:30
										 |  |  | 				ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				ti->set_selectable(0, false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			Dictionary d; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			d["name"] = files.front()->get(); | 
					
						
							|  |  |  | 			d["dir"] = false; | 
					
						
							|  |  |  | 			ti->set_metadata(0, d); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (file->get_text() == files.front()->get() || match_str == files.front()->get()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				ti->select(0); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		files.pop_front(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		tree->get_root()->get_children()->select(0); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_filter_selected(int) { | 
					
						
							| 
									
										
										
										
											2019-06-28 10:29:50 +03:00
										 |  |  | 	update_file_name(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update_file_list(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::update_filters() { | 
					
						
							|  |  |  | 	filter->clear(); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (filters.size() > 1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		String all_filters; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const int max_filters = 5; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < MIN(max_filters, filters.size()); i++) { | 
					
						
							| 
									
										
										
										
											2019-12-06 22:40:59 -03:00
										 |  |  | 			String flt = filters[i].get_slice(";", 0).strip_edges(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (i > 0) { | 
					
						
							| 
									
										
										
										
											2019-12-06 22:40:59 -03:00
										 |  |  | 				all_filters += ", "; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			all_filters += flt; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (max_filters < filters.size()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			all_filters += ", ..."; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-06 07:31:42 -03:00
										 |  |  | 		filter->add_item(RTR("All Recognized") + " (" + all_filters + ")"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < filters.size(); i++) { | 
					
						
							|  |  |  | 		String flt = filters[i].get_slice(";", 0).strip_edges(); | 
					
						
							|  |  |  | 		String desc = filters[i].get_slice(";", 1).strip_edges(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (desc.length()) { | 
					
						
							| 
									
										
										
										
											2019-12-06 07:31:42 -03:00
										 |  |  | 			filter->add_item(String(tr(desc)) + " (" + flt + ")"); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2019-12-06 07:31:42 -03:00
										 |  |  | 			filter->add_item("(" + flt + ")"); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	filter->add_item(RTR("All Files (*)")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::clear_filters() { | 
					
						
							|  |  |  | 	filters.clear(); | 
					
						
							|  |  |  | 	update_filters(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::add_filter(const String &p_filter) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	filters.push_back(p_filter); | 
					
						
							|  |  |  | 	update_filters(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::set_filters(const Vector<String> &p_filters) { | 
					
						
							|  |  |  | 	filters = p_filters; | 
					
						
							| 
									
										
										
										
											2016-07-17 01:58:28 +02:00
										 |  |  | 	update_filters(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Vector<String> FileDialog::get_filters() const { | 
					
						
							| 
									
										
										
										
											2016-07-17 01:58:28 +02:00
										 |  |  | 	return filters; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | String FileDialog::get_current_dir() const { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	return dir->get_text(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | String FileDialog::get_current_file() const { | 
					
						
							|  |  |  | 	return file->get_text(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | String FileDialog::get_current_path() const { | 
					
						
							|  |  |  | 	return dir->get_text().plus_file(file->get_text()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::set_current_dir(const String &p_dir) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	dir_access->change_dir(p_dir); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::set_current_file(const String &p_file) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	file->set_text(p_file); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							| 
									
										
										
										
											2020-07-03 15:26:22 +02:00
										 |  |  | 	int lp = p_file.rfind("."); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (lp != -1) { | 
					
						
							|  |  |  | 		file->select(0, lp); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) { | 
					
						
							| 
									
										
										
										
											2018-08-18 16:04:58 +02:00
										 |  |  | 			file->grab_focus(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void FileDialog::set_current_path(const String &p_path) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!p_path.size()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-07-03 15:26:22 +02:00
										 |  |  | 	int pos = MAX(p_path.rfind("/"), p_path.rfind("\\")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (pos == -1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		set_current_file(p_path); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String dir = p_path.substr(0, pos); | 
					
						
							|  |  |  | 		String file = p_path.substr(pos + 1, p_path.length()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		set_current_dir(dir); | 
					
						
							|  |  |  | 		set_current_file(file); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | void FileDialog::set_mode_overrides_title(bool p_override) { | 
					
						
							|  |  |  | 	mode_overrides_title = p_override; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FileDialog::is_mode_overriding_title() const { | 
					
						
							|  |  |  | 	return mode_overrides_title; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | void FileDialog::set_file_mode(FileMode p_mode) { | 
					
						
							| 
									
										
										
										
											2019-10-05 19:17:07 +02:00
										 |  |  | 	ERR_FAIL_INDEX((int)p_mode, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mode = p_mode; | 
					
						
							|  |  |  | 	switch (mode) { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		case FILE_MODE_OPEN_FILE: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			get_ok_button()->set_text(RTR("Open")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (mode_overrides_title) { | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 				set_title(RTR("Open a File")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			makedir->hide(); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		case FILE_MODE_OPEN_FILES: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			get_ok_button()->set_text(RTR("Open")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (mode_overrides_title) { | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 				set_title(RTR("Open File(s)")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			makedir->hide(); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		case FILE_MODE_OPEN_DIR: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			get_ok_button()->set_text(RTR("Select Current Folder")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (mode_overrides_title) { | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 				set_title(RTR("Open a Directory")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			makedir->show(); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		case FILE_MODE_OPEN_ANY: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			get_ok_button()->set_text(RTR("Open")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (mode_overrides_title) { | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 				set_title(RTR("Open a File or Directory")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			makedir->show(); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		case FILE_MODE_SAVE_FILE: | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 			get_ok_button()->set_text(RTR("Save")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (mode_overrides_title) { | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 				set_title(RTR("Save a File")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			makedir->show(); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (mode == FILE_MODE_OPEN_FILES) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		tree->set_select_mode(Tree::SELECT_MULTI); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		tree->set_select_mode(Tree::SELECT_SINGLE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | FileDialog::FileMode FileDialog::get_file_mode() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::set_access(Access p_access) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_INDEX(p_access, 3); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (access == p_access) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	memdelete(dir_access); | 
					
						
							|  |  |  | 	switch (p_access) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case ACCESS_FILESYSTEM: { | 
					
						
							|  |  |  | 			dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case ACCESS_RESOURCES: { | 
					
						
							|  |  |  | 			dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case ACCESS_USERDATA: { | 
					
						
							|  |  |  | 			dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	access = p_access; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_update_drives(); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | 	update_filters(); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::invalidate() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	if (is_visible()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		update_file_list(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		invalidated = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		invalidated = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | FileDialog::Access FileDialog::get_access() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return access; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_make_dir_confirm() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Error err = dir_access->make_dir(makedirname->get_text()); | 
					
						
							|  |  |  | 	if (err == OK) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		dir_access->change_dir(makedirname->get_text()); | 
					
						
							|  |  |  | 		invalidate(); | 
					
						
							|  |  |  | 		update_filters(); | 
					
						
							|  |  |  | 		update_dir(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		mkdirerr->popup_centered(Size2(250, 50)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-01 11:38:24 +02:00
										 |  |  | 	makedirname->set_text(""); // reset label
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_make_dir() { | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	makedialog->popup_centered(Size2(250, 80)); | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 	makedirname->grab_focus(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_select_drive(int p_idx) { | 
					
						
							|  |  |  | 	String d = drives->get_item_text(p_idx); | 
					
						
							|  |  |  | 	dir_access->change_dir(d); | 
					
						
							|  |  |  | 	file->set_text(""); | 
					
						
							|  |  |  | 	invalidate(); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::_update_drives() { | 
					
						
							|  |  |  | 	int dc = dir_access->get_drive_count(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (dc == 0 || access != ACCESS_FILESYSTEM) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		drives->hide(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		drives->clear(); | 
					
						
							| 
									
										
										
										
											2020-02-10 09:19:29 +01:00
										 |  |  | 		Node *dp = drives->get_parent(); | 
					
						
							|  |  |  | 		if (dp) { | 
					
						
							|  |  |  | 			dp->remove_child(drives); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		dp = dir_access->drives_are_shortcuts() ? shortcuts_container : drives_container; | 
					
						
							|  |  |  | 		dp->add_child(drives); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		drives->show(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < dir_access->get_drive_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			drives->add_item(dir_access->get_drive(i)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 21:36:35 -03:00
										 |  |  | 		drives->select(dir_access->get_current_drive()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | bool FileDialog::default_show_hidden_files = false; | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void FileDialog::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("clear_filters"), &FileDialog::clear_filters); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("add_filter", "filter"), &FileDialog::add_filter); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_filters", "filters"), &FileDialog::set_filters); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_filters"), &FileDialog::get_filters); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_current_dir"), &FileDialog::get_current_dir); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_current_file"), &FileDialog::get_current_file); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_current_path"), &FileDialog::get_current_path); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_current_dir", "dir"), &FileDialog::set_current_dir); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_current_file", "file"), &FileDialog::set_current_file); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_current_path", "path"), &FileDialog::set_current_path); | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_mode_overrides_title", "override"), &FileDialog::set_mode_overrides_title); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_mode_overriding_title"), &FileDialog::is_mode_overriding_title); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_file_mode", "mode"), &FileDialog::set_file_mode); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_file_mode"), &FileDialog::get_file_mode); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_vbox"), &FileDialog::get_vbox); | 
					
						
							| 
									
										
										
										
											2018-06-06 01:19:24 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_line_edit"), &FileDialog::get_line_edit); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_access", "access"), &FileDialog::set_access); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_access"), &FileDialog::get_access); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &FileDialog::set_show_hidden_files); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &FileDialog::is_showing_hidden_files); | 
					
						
							| 
									
										
										
										
											2019-06-28 10:29:50 +03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir); | 
					
						
							| 
									
										
										
										
											2020-02-29 21:11:03 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list); | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("deselect_all"), &FileDialog::deselect_all); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mode_overrides_title"), "set_mode_overrides_title", "is_mode_overriding_title"); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "file_mode", PROPERTY_HINT_ENUM, "Open File,Open Files,Open Folder,Open Any,Save"), "set_file_mode", "get_file_mode"); | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"), "set_access", "get_access"); | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters"); | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_hidden_files"), "set_show_hidden_files", "is_showing_hidden_files"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir"), "set_current_dir", "get_current_dir"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file"), "set_current_file", "get_current_file"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_path"), "set_current_path", "get_current_path"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("file_selected", PropertyInfo(Variant::STRING, "path"))); | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths"))); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir"))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILE); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILES); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(FILE_MODE_OPEN_DIR); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(FILE_MODE_OPEN_ANY); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(FILE_MODE_SAVE_FILE); | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ACCESS_RESOURCES); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ACCESS_USERDATA); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ACCESS_FILESYSTEM); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | void FileDialog::set_show_hidden_files(bool p_show) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	show_hidden_files = p_show; | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 	invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FileDialog::is_showing_hidden_files() const { | 
					
						
							|  |  |  | 	return show_hidden_files; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FileDialog::set_default_show_hidden_files(bool p_show) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	default_show_hidden_files = p_show; | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | FileDialog::FileDialog() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	show_hidden_files = default_show_hidden_files; | 
					
						
							| 
									
										
										
										
											2015-03-23 11:31:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 23:54:06 -02:00
										 |  |  | 	mode_overrides_title = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 14:58:57 +05:30
										 |  |  | 	vbox = memnew(VBoxContainer); | 
					
						
							|  |  |  | 	add_child(vbox); | 
					
						
							|  |  |  | 	vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed)); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	mode = FILE_MODE_SAVE_FILE; | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	set_title(RTR("Save a File")); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	HBoxContainer *hbc = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	dir_up = memnew(Button); | 
					
						
							|  |  |  | 	dir_up->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-03-05 03:55:08 -03:00
										 |  |  | 	dir_up->set_tooltip(RTR("Go to parent folder.")); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 	hbc->add_child(dir_up); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	dir_up->connect("pressed", callable_mp(this, &FileDialog::_go_up)); | 
					
						
							| 
									
										
										
										
											2017-11-27 18:58:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 09:19:29 +01:00
										 |  |  | 	hbc->add_child(memnew(Label(RTR("Path:")))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drives_container = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	hbc->add_child(drives_container); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	drives = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive)); | 
					
						
							| 
									
										
										
										
											2020-04-06 20:07:08 +02:00
										 |  |  | 	hbc->add_child(drives); | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	dir = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	dir->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	hbc->add_child(dir); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	refresh = memnew(Button); | 
					
						
							|  |  |  | 	refresh->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-07-26 11:11:09 -03:00
										 |  |  | 	refresh->set_tooltip(RTR("Refresh files.")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	hbc->add_child(refresh); | 
					
						
							| 
									
										
										
										
											2015-12-04 19:33:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	show_hidden = memnew(Button); | 
					
						
							|  |  |  | 	show_hidden->set_flat(true); | 
					
						
							| 
									
										
										
										
											2019-06-10 00:20:24 -03:00
										 |  |  | 	show_hidden->set_toggle_mode(true); | 
					
						
							|  |  |  | 	show_hidden->set_pressed(is_showing_hidden_files()); | 
					
						
							| 
									
										
										
										
											2019-07-26 11:11:09 -03:00
										 |  |  | 	show_hidden->set_tooltip(RTR("Toggle the visibility of hidden files.")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	show_hidden->connect("toggled", callable_mp(this, &FileDialog::set_show_hidden_files)); | 
					
						
							| 
									
										
										
										
											2019-06-10 00:20:24 -03:00
										 |  |  | 	hbc->add_child(show_hidden); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 09:19:29 +01:00
										 |  |  | 	shortcuts_container = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	hbc->add_child(shortcuts_container); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	makedir = memnew(Button); | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	makedir->set_text(RTR("Create Folder")); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir)); | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	hbc->add_child(makedir); | 
					
						
							| 
									
										
										
										
											2020-04-04 14:58:57 +05:30
										 |  |  | 	vbox->add_child(hbc); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	tree = memnew(Tree); | 
					
						
							|  |  |  | 	tree->set_hide_root(true); | 
					
						
							| 
									
										
										
										
											2020-04-04 14:58:57 +05:30
										 |  |  | 	vbox->add_margin_child(RTR("Directories & Files:"), tree, true); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	file_box = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	file_box->add_child(memnew(Label(RTR("File:")))); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	file = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	file->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	file->set_stretch_ratio(4); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	file->set_h_size_flags(Control::SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	file_box->add_child(file); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	filter = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2017-10-06 21:01:54 +07:00
										 |  |  | 	filter->set_stretch_ratio(3); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 	filter->set_h_size_flags(Control::SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2018-02-15 00:44:11 -02:00
										 |  |  | 	filter->set_clip_text(true); // too many extensions overflows it
 | 
					
						
							| 
									
										
										
										
											2019-10-26 17:29:22 +02:00
										 |  |  | 	file_box->add_child(filter); | 
					
						
							| 
									
										
										
										
											2020-04-04 14:58:57 +05:30
										 |  |  | 	vbox->add_child(file_box); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	access = ACCESS_RESOURCES; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_update_drives(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	connect("confirmed", callable_mp(this, &FileDialog::_action_pressed)); | 
					
						
							|  |  |  | 	tree->connect("multi_selected", callable_mp(this, &FileDialog::_tree_multi_selected), varray(), CONNECT_DEFERRED); | 
					
						
							|  |  |  | 	tree->connect("cell_selected", callable_mp(this, &FileDialog::_tree_selected), varray(), CONNECT_DEFERRED); | 
					
						
							|  |  |  | 	tree->connect("item_activated", callable_mp(this, &FileDialog::_tree_item_activated), varray()); | 
					
						
							| 
									
										
										
										
											2020-12-21 10:26:41 +00:00
										 |  |  | 	tree->connect("nothing_selected", callable_mp(this, &FileDialog::deselect_all)); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	dir->connect("text_entered", callable_mp(this, &FileDialog::_dir_entered)); | 
					
						
							|  |  |  | 	file->connect("text_entered", callable_mp(this, &FileDialog::_file_entered)); | 
					
						
							|  |  |  | 	filter->connect("item_selected", callable_mp(this, &FileDialog::_filter_selected)); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	confirm_save = memnew(ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2020-10-02 17:03:52 -04:00
										 |  |  | 	//	confirm_save->set_as_top_level(true);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(confirm_save); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	confirm_save->connect("confirmed", callable_mp(this, &FileDialog::_save_confirm_pressed)); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	makedialog = memnew(ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	makedialog->set_title(RTR("Create Folder")); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VBoxContainer *makevb = memnew(VBoxContainer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	makedialog->add_child(makevb); | 
					
						
							| 
									
										
										
										
											2017-01-10 01:49:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	makedirname = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	makedirname->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	makevb->add_margin_child(RTR("Name:"), makedirname); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(makedialog); | 
					
						
							|  |  |  | 	makedialog->register_text_enter(makedirname); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	makedialog->connect("confirmed", callable_mp(this, &FileDialog::_make_dir_confirm)); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mkdirerr = memnew(AcceptDialog); | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	mkdirerr->set_text(RTR("Could not create folder.")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(mkdirerr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	exterr = memnew(AcceptDialog); | 
					
						
							| 
									
										
										
										
											2016-06-07 23:24:32 +03:00
										 |  |  | 	exterr->set_text(RTR("Must use a valid extension.")); | 
					
						
							| 
									
										
										
										
											2014-04-10 00:18:27 -03:00
										 |  |  | 	add_child(exterr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update_filters(); | 
					
						
							|  |  |  | 	update_dir(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	set_hide_on_ok(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	invalidated = true; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (register_func) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		register_func(this); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FileDialog::~FileDialog() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (unregister_func) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		unregister_func(this); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	memdelete(dir_access); | 
					
						
							|  |  |  | } |