file_dialog.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. /**************************************************************************/
  2. /* file_dialog.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "file_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/os/keyboard.h"
  33. #include "core/string/print_string.h"
  34. #include "scene/gui/check_box.h"
  35. #include "scene/gui/grid_container.h"
  36. #include "scene/gui/label.h"
  37. #include "scene/gui/option_button.h"
  38. #include "scene/theme/theme_db.h"
  39. FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr;
  40. FileDialog::RegisterFunc FileDialog::register_func = nullptr;
  41. FileDialog::RegisterFunc FileDialog::unregister_func = nullptr;
  42. void FileDialog::popup_file_dialog() {
  43. popup_centered_clamped(Size2i(700, 500), 0.8f);
  44. _focus_file_text();
  45. }
  46. void FileDialog::_focus_file_text() {
  47. int lp = file->get_text().rfind(".");
  48. if (lp != -1) {
  49. file->select(0, lp);
  50. if (file->is_inside_tree() && !is_part_of_edited_scene()) {
  51. file->grab_focus();
  52. }
  53. }
  54. }
  55. void FileDialog::_native_popup() {
  56. // Show native dialog directly.
  57. String root;
  58. if (access == ACCESS_RESOURCES) {
  59. root = ProjectSettings::get_singleton()->get_resource_path();
  60. } else if (access == ACCESS_USERDATA) {
  61. root = OS::get_singleton()->get_user_data_dir();
  62. }
  63. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
  64. DisplayServer::get_singleton()->file_dialog_with_options_show(get_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
  65. } else {
  66. DisplayServer::get_singleton()->file_dialog_show(get_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), filters, callable_mp(this, &FileDialog::_native_dialog_cb));
  67. }
  68. }
  69. bool FileDialog::_can_use_native_popup() {
  70. if (access == ACCESS_RESOURCES || access == ACCESS_USERDATA || options.size() > 0) {
  71. return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA);
  72. }
  73. return DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE);
  74. }
  75. void FileDialog::popup(const Rect2i &p_rect) {
  76. _update_option_controls();
  77. #ifdef TOOLS_ENABLED
  78. if (is_part_of_edited_scene()) {
  79. ConfirmationDialog::popup(p_rect);
  80. return;
  81. }
  82. #endif
  83. if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
  84. _native_popup();
  85. } else {
  86. ConfirmationDialog::popup(p_rect);
  87. }
  88. }
  89. void FileDialog::set_visible(bool p_visible) {
  90. if (p_visible) {
  91. _update_option_controls();
  92. }
  93. #ifdef TOOLS_ENABLED
  94. if (is_part_of_edited_scene()) {
  95. ConfirmationDialog::set_visible(p_visible);
  96. return;
  97. }
  98. #endif
  99. if (_can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
  100. if (p_visible) {
  101. _native_popup();
  102. }
  103. } else {
  104. ConfirmationDialog::set_visible(p_visible);
  105. }
  106. }
  107. void FileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter) {
  108. _native_dialog_cb_with_options(p_ok, p_files, p_filter, Dictionary());
  109. }
  110. void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options) {
  111. if (!p_ok) {
  112. file->set_text("");
  113. emit_signal(SNAME("canceled"));
  114. return;
  115. }
  116. if (p_files.is_empty()) {
  117. return;
  118. }
  119. Vector<String> files = p_files;
  120. if (access != ACCESS_FILESYSTEM) {
  121. for (String &file_name : files) {
  122. file_name = ProjectSettings::get_singleton()->localize_path(file_name);
  123. }
  124. }
  125. selected_options = p_selected_options;
  126. String f = files[0];
  127. if (mode == FILE_MODE_OPEN_FILES) {
  128. emit_signal(SNAME("files_selected"), files);
  129. } else {
  130. if (mode == FILE_MODE_SAVE_FILE) {
  131. if (p_filter >= 0 && p_filter < filters.size()) {
  132. bool valid = false;
  133. String flt = filters[p_filter].get_slice(";", 0);
  134. int filter_slice_count = flt.get_slice_count(",");
  135. for (int j = 0; j < filter_slice_count; j++) {
  136. String str = (flt.get_slice(",", j).strip_edges());
  137. if (f.match(str)) {
  138. valid = true;
  139. break;
  140. }
  141. }
  142. if (!valid && filter_slice_count > 0) {
  143. String str = (flt.get_slice(",", 0).strip_edges());
  144. f += str.substr(1, str.length() - 1);
  145. }
  146. }
  147. emit_signal(SNAME("file_selected"), f);
  148. } else if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) {
  149. emit_signal(SNAME("file_selected"), f);
  150. } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) {
  151. emit_signal(SNAME("dir_selected"), f);
  152. }
  153. }
  154. file->set_text(f);
  155. dir->set_text(f.get_base_dir());
  156. filter->select(p_filter);
  157. }
  158. VBoxContainer *FileDialog::get_vbox() {
  159. return vbox;
  160. }
  161. void FileDialog::_validate_property(PropertyInfo &p_property) const {
  162. if (p_property.name == "dialog_text") {
  163. // File dialogs have a custom layout, and dialog nodes can't have both a text and a layout.
  164. p_property.usage = PROPERTY_USAGE_NONE;
  165. }
  166. }
  167. void FileDialog::_notification(int p_what) {
  168. switch (p_what) {
  169. case NOTIFICATION_READY: {
  170. #ifdef TOOLS_ENABLED
  171. if (is_part_of_edited_scene()) {
  172. return;
  173. }
  174. #endif
  175. // Replace the built-in dialog with the native one if it started visible.
  176. if (is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
  177. ConfirmationDialog::set_visible(false);
  178. _native_popup();
  179. }
  180. } break;
  181. case NOTIFICATION_VISIBILITY_CHANGED: {
  182. if (!is_visible()) {
  183. set_process_shortcut_input(false);
  184. }
  185. invalidate(); // Put it here to preview in the editor.
  186. } break;
  187. case NOTIFICATION_THEME_CHANGED: {
  188. dir_up->set_button_icon(theme_cache.parent_folder);
  189. if (vbox->is_layout_rtl()) {
  190. dir_prev->set_button_icon(theme_cache.forward_folder);
  191. dir_next->set_button_icon(theme_cache.back_folder);
  192. } else {
  193. dir_prev->set_button_icon(theme_cache.back_folder);
  194. dir_next->set_button_icon(theme_cache.forward_folder);
  195. }
  196. refresh->set_button_icon(theme_cache.reload);
  197. show_hidden->set_button_icon(theme_cache.toggle_hidden);
  198. makedir->set_button_icon(theme_cache.create_folder);
  199. show_filename_filter_button->set_button_icon(theme_cache.toggle_filename_filter);
  200. dir_up->begin_bulk_theme_override();
  201. dir_up->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  202. dir_up->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  203. dir_up->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  204. dir_up->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
  205. dir_up->end_bulk_theme_override();
  206. dir_prev->begin_bulk_theme_override();
  207. dir_prev->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  208. dir_prev->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  209. dir_prev->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  210. dir_prev->add_theme_color_override("icon_color_pressed", theme_cache.icon_pressed_color);
  211. dir_prev->end_bulk_theme_override();
  212. dir_next->begin_bulk_theme_override();
  213. dir_next->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  214. dir_next->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  215. dir_next->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  216. dir_next->add_theme_color_override("icon_color_pressed", theme_cache.icon_pressed_color);
  217. dir_next->end_bulk_theme_override();
  218. refresh->begin_bulk_theme_override();
  219. refresh->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  220. refresh->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  221. refresh->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  222. refresh->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
  223. refresh->end_bulk_theme_override();
  224. show_hidden->begin_bulk_theme_override();
  225. show_hidden->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  226. show_hidden->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  227. show_hidden->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  228. show_hidden->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
  229. show_hidden->end_bulk_theme_override();
  230. makedir->begin_bulk_theme_override();
  231. makedir->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  232. makedir->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  233. makedir->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  234. makedir->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
  235. makedir->end_bulk_theme_override();
  236. show_filename_filter_button->begin_bulk_theme_override();
  237. show_filename_filter_button->add_theme_color_override("icon_normal_color", theme_cache.icon_normal_color);
  238. show_filename_filter_button->add_theme_color_override("icon_hover_color", theme_cache.icon_hover_color);
  239. show_filename_filter_button->add_theme_color_override("icon_focus_color", theme_cache.icon_focus_color);
  240. show_filename_filter_button->add_theme_color_override("icon_pressed_color", theme_cache.icon_pressed_color);
  241. show_filename_filter_button->end_bulk_theme_override();
  242. invalidate();
  243. } break;
  244. case NOTIFICATION_TRANSLATION_CHANGED: {
  245. update_filters();
  246. } break;
  247. }
  248. }
  249. void FileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
  250. ERR_FAIL_COND(p_event.is_null());
  251. Ref<InputEventKey> k = p_event;
  252. if (k.is_valid() && has_focus()) {
  253. if (k->is_pressed()) {
  254. bool handled = true;
  255. switch (k->get_keycode()) {
  256. case Key::H: {
  257. if (k->is_command_or_control_pressed()) {
  258. set_show_hidden_files(!show_hidden_files);
  259. } else {
  260. handled = false;
  261. }
  262. } break;
  263. case Key::F: {
  264. if (k->is_command_or_control_pressed()) {
  265. show_filename_filter_button->set_pressed(!show_filename_filter_button->is_pressed());
  266. } else {
  267. handled = false;
  268. }
  269. } break;
  270. case Key::F5: {
  271. invalidate();
  272. } break;
  273. case Key::BACKSPACE: {
  274. _dir_submitted("..");
  275. } break;
  276. #ifdef MACOS_ENABLED
  277. // Cmd + Shift + G (matches Finder's "Go To" shortcut).
  278. case Key::G: {
  279. if (k->is_command_or_control_pressed() && k->is_shift_pressed()) {
  280. dir->grab_focus();
  281. dir->select_all();
  282. } else {
  283. handled = false;
  284. }
  285. } break;
  286. #endif
  287. // Ctrl + L (matches most Windows/Linux file managers' "focus on path bar" shortcut,
  288. // plus macOS Safari's "focus on address bar" shortcut).
  289. case Key::L: {
  290. if (k->is_command_or_control_pressed()) {
  291. dir->grab_focus();
  292. dir->select_all();
  293. } else {
  294. handled = false;
  295. }
  296. } break;
  297. default: {
  298. handled = false;
  299. }
  300. }
  301. if (handled) {
  302. set_input_as_handled();
  303. }
  304. }
  305. }
  306. }
  307. void FileDialog::set_enable_multiple_selection(bool p_enable) {
  308. tree->set_select_mode(p_enable ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE);
  309. }
  310. Vector<String> FileDialog::get_selected_files() const {
  311. Vector<String> list;
  312. TreeItem *item = tree->get_root();
  313. item = tree->get_next_selected(item);
  314. while (item) {
  315. list.push_back(dir_access->get_current_dir().path_join(item->get_text(0)));
  316. item = tree->get_next_selected(item);
  317. }
  318. return list;
  319. }
  320. void FileDialog::update_dir() {
  321. if (root_prefix.is_empty()) {
  322. dir->set_text(dir_access->get_current_dir(false));
  323. } else {
  324. dir->set_text(dir_access->get_current_dir(false).trim_prefix(root_prefix).trim_prefix("/"));
  325. }
  326. if (drives->is_visible()) {
  327. if (dir_access->get_current_dir().is_network_share_path()) {
  328. _update_drives(false);
  329. drives->add_item(ETR("Network"));
  330. drives->set_item_disabled(-1, true);
  331. drives->select(drives->get_item_count() - 1);
  332. } else {
  333. drives->select(dir_access->get_current_drive());
  334. }
  335. }
  336. // Deselect any item, to make "Select Current Folder" button text by default.
  337. deselect_all();
  338. }
  339. void FileDialog::_dir_submitted(String p_dir) {
  340. _change_dir(root_prefix.path_join(p_dir));
  341. file->set_text("");
  342. _push_history();
  343. }
  344. void FileDialog::_file_submitted(const String &p_file) {
  345. _action_pressed();
  346. }
  347. void FileDialog::_save_confirm_pressed() {
  348. String f = dir_access->get_current_dir().path_join(file->get_text());
  349. emit_signal(SNAME("file_selected"), f);
  350. hide();
  351. }
  352. void FileDialog::_post_popup() {
  353. ConfirmationDialog::_post_popup();
  354. if (mode == FILE_MODE_SAVE_FILE) {
  355. file->grab_focus();
  356. } else {
  357. tree->grab_focus();
  358. }
  359. set_process_shortcut_input(true);
  360. // For open dir mode, deselect all items on file dialog open.
  361. if (mode == FILE_MODE_OPEN_DIR) {
  362. deselect_all();
  363. file_box->set_visible(false);
  364. } else {
  365. file_box->set_visible(true);
  366. }
  367. local_history.clear();
  368. local_history_pos = -1;
  369. _push_history();
  370. }
  371. void FileDialog::_push_history() {
  372. local_history.resize(local_history_pos + 1);
  373. String new_path = dir_access->get_current_dir();
  374. if (local_history.size() == 0 || new_path != local_history[local_history_pos]) {
  375. local_history.push_back(new_path);
  376. local_history_pos++;
  377. dir_prev->set_disabled(local_history_pos == 0);
  378. dir_next->set_disabled(true);
  379. }
  380. }
  381. void FileDialog::_action_pressed() {
  382. if (mode == FILE_MODE_OPEN_FILES) {
  383. TreeItem *ti = tree->get_next_selected(nullptr);
  384. String fbase = dir_access->get_current_dir();
  385. Vector<String> files;
  386. while (ti) {
  387. files.push_back(fbase.path_join(ti->get_text(0)));
  388. ti = tree->get_next_selected(ti);
  389. }
  390. if (files.size()) {
  391. emit_signal(SNAME("files_selected"), files);
  392. hide();
  393. }
  394. return;
  395. }
  396. String file_text = file->get_text();
  397. String f = file_text.is_absolute_path() ? file_text : dir_access->get_current_dir().path_join(file_text);
  398. if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) {
  399. emit_signal(SNAME("file_selected"), f);
  400. hide();
  401. } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) {
  402. String path = dir_access->get_current_dir();
  403. path = path.replace("\\", "/");
  404. TreeItem *item = tree->get_selected();
  405. if (item) {
  406. Dictionary d = item->get_metadata(0);
  407. if (d["dir"] && d["name"] != "..") {
  408. path = path.path_join(d["name"]);
  409. }
  410. }
  411. emit_signal(SNAME("dir_selected"), path);
  412. hide();
  413. }
  414. if (mode == FILE_MODE_SAVE_FILE) {
  415. bool valid = false;
  416. if (filter->get_selected() == filter->get_item_count() - 1) {
  417. valid = true; // match none
  418. } else if (filters.size() > 1 && filter->get_selected() == 0) {
  419. // match all filters
  420. for (int i = 0; i < filters.size(); i++) {
  421. String flt = filters[i].get_slice(";", 0);
  422. for (int j = 0; j < flt.get_slice_count(","); j++) {
  423. String str = flt.get_slice(",", j).strip_edges();
  424. if (f.match(str)) {
  425. valid = true;
  426. break;
  427. }
  428. }
  429. if (valid) {
  430. break;
  431. }
  432. }
  433. } else {
  434. int idx = filter->get_selected();
  435. if (filters.size() > 1) {
  436. idx--;
  437. }
  438. if (idx >= 0 && idx < filters.size()) {
  439. String flt = filters[idx].get_slice(";", 0);
  440. int filterSliceCount = flt.get_slice_count(",");
  441. for (int j = 0; j < filterSliceCount; j++) {
  442. String str = (flt.get_slice(",", j).strip_edges());
  443. if (f.match(str)) {
  444. valid = true;
  445. break;
  446. }
  447. }
  448. if (!valid && filterSliceCount > 0) {
  449. String str = (flt.get_slice(",", 0).strip_edges());
  450. f += str.substr(1, str.length() - 1);
  451. file->set_text(f.get_file());
  452. valid = true;
  453. }
  454. } else {
  455. valid = true;
  456. }
  457. }
  458. String file_name = file_text.strip_edges().get_file();
  459. if (!valid || file_name.is_empty()) {
  460. exterr->popup_centered(Size2(250, 80));
  461. return;
  462. }
  463. if (dir_access->file_exists(f)) {
  464. confirm_save->set_text(vformat(atr(ETR("File \"%s\" already exists.\nDo you want to overwrite it?")), f));
  465. confirm_save->popup_centered(Size2(250, 80));
  466. } else {
  467. emit_signal(SNAME("file_selected"), f);
  468. hide();
  469. }
  470. }
  471. }
  472. void FileDialog::_cancel_pressed() {
  473. file->set_text("");
  474. invalidate();
  475. hide();
  476. }
  477. bool FileDialog::_is_open_should_be_disabled() {
  478. if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) {
  479. return false;
  480. }
  481. TreeItem *ti = tree->get_next_selected(tree->get_root());
  482. while (ti) {
  483. TreeItem *prev_ti = ti;
  484. ti = tree->get_next_selected(tree->get_root());
  485. if (ti == prev_ti) {
  486. break;
  487. }
  488. }
  489. // We have something that we can't select?
  490. if (!ti) {
  491. return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
  492. }
  493. Dictionary d = ti->get_metadata(0);
  494. // Opening a file, but selected a folder? Forbidden.
  495. return ((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden.
  496. (mode == FILE_MODE_OPEN_DIR && !d["dir"]);
  497. }
  498. void FileDialog::_go_up() {
  499. _change_dir("..");
  500. _push_history();
  501. }
  502. void FileDialog::_go_back() {
  503. if (local_history_pos <= 0) {
  504. return;
  505. }
  506. local_history_pos--;
  507. _change_dir(local_history[local_history_pos]);
  508. dir_prev->set_disabled(local_history_pos == 0);
  509. dir_next->set_disabled(local_history_pos == local_history.size() - 1);
  510. }
  511. void FileDialog::_go_forward() {
  512. if (local_history_pos >= local_history.size() - 1) {
  513. return;
  514. }
  515. local_history_pos++;
  516. _change_dir(local_history[local_history_pos]);
  517. dir_prev->set_disabled(local_history_pos == 0);
  518. dir_next->set_disabled(local_history_pos == local_history.size() - 1);
  519. }
  520. void FileDialog::deselect_all() {
  521. // Clear currently selected items in file manager.
  522. tree->deselect_all();
  523. // And change get_ok title.
  524. if (!tree->is_anything_selected()) {
  525. get_ok_button()->set_disabled(_is_open_should_be_disabled());
  526. switch (mode) {
  527. case FILE_MODE_OPEN_FILE:
  528. case FILE_MODE_OPEN_FILES:
  529. set_ok_button_text(ETR("Open"));
  530. break;
  531. case FILE_MODE_OPEN_DIR:
  532. set_ok_button_text(ETR("Select Current Folder"));
  533. break;
  534. case FILE_MODE_OPEN_ANY:
  535. case FILE_MODE_SAVE_FILE:
  536. // FIXME: Implement, or refactor to avoid duplication with set_mode
  537. break;
  538. }
  539. }
  540. }
  541. void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selected) {
  542. _tree_selected();
  543. }
  544. void FileDialog::_tree_selected() {
  545. TreeItem *ti = tree->get_selected();
  546. if (!ti) {
  547. return;
  548. }
  549. Dictionary d = ti->get_metadata(0);
  550. if (!d["dir"]) {
  551. file->set_text(d["name"]);
  552. } else if (mode == FILE_MODE_OPEN_DIR) {
  553. set_ok_button_text(ETR("Select This Folder"));
  554. }
  555. get_ok_button()->set_disabled(_is_open_should_be_disabled());
  556. }
  557. void FileDialog::_tree_item_activated() {
  558. TreeItem *ti = tree->get_selected();
  559. if (!ti) {
  560. return;
  561. }
  562. Dictionary d = ti->get_metadata(0);
  563. if (d["dir"]) {
  564. _change_dir(d["name"]);
  565. if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
  566. file->set_text("");
  567. }
  568. _push_history();
  569. } else {
  570. _action_pressed();
  571. }
  572. }
  573. void FileDialog::update_file_name() {
  574. int idx = filter->get_selected() - 1;
  575. if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
  576. if (idx == -1) {
  577. idx += 1;
  578. }
  579. String filter_str = filters[idx];
  580. String file_str = file->get_text();
  581. String base_name = file_str.get_basename();
  582. Vector<String> filter_substr = filter_str.split(";");
  583. if (filter_substr.size() >= 2) {
  584. file_str = base_name + "." + filter_substr[0].strip_edges().get_extension().to_lower();
  585. } else {
  586. file_str = base_name + "." + filter_str.strip_edges().get_extension().to_lower();
  587. }
  588. file->set_text(file_str);
  589. }
  590. }
  591. void FileDialog::update_file_list() {
  592. tree->clear();
  593. // Scroll back to the top after opening a directory
  594. tree->get_vscroll_bar()->set_value(0);
  595. dir_access->list_dir_begin();
  596. if (dir_access->is_readable(dir_access->get_current_dir().utf8().get_data())) {
  597. message->hide();
  598. } else {
  599. message->set_text(ETR("You don't have permission to access contents of this folder."));
  600. message->show();
  601. }
  602. TreeItem *root = tree->create_item();
  603. List<String> files;
  604. List<String> dirs;
  605. bool is_hidden;
  606. String item = dir_access->get_next();
  607. while (!item.is_empty()) {
  608. if (item == "." || item == "..") {
  609. item = dir_access->get_next();
  610. continue;
  611. }
  612. is_hidden = dir_access->current_is_hidden();
  613. if (show_hidden_files || !is_hidden) {
  614. if (!dir_access->current_is_dir()) {
  615. files.push_back(item);
  616. } else {
  617. dirs.push_back(item);
  618. }
  619. }
  620. item = dir_access->get_next();
  621. }
  622. dirs.sort_custom<FileNoCaseComparator>();
  623. files.sort_custom<FileNoCaseComparator>();
  624. String filename_filter_lower = file_name_filter.to_lower();
  625. while (!dirs.is_empty()) {
  626. const String &dir_name = dirs.front()->get();
  627. if (filename_filter_lower.is_empty() || dir_name.to_lower().contains(filename_filter_lower)) {
  628. TreeItem *ti = tree->create_item(root);
  629. ti->set_text(0, dir_name);
  630. ti->set_icon(0, theme_cache.folder);
  631. ti->set_icon_modulate(0, theme_cache.folder_icon_color);
  632. Dictionary d;
  633. d["name"] = dir_name;
  634. d["dir"] = true;
  635. ti->set_metadata(0, d);
  636. }
  637. dirs.pop_front();
  638. }
  639. List<String> patterns;
  640. // build filter
  641. if (filter->get_selected() == filter->get_item_count() - 1) {
  642. // match all
  643. } else if (filters.size() > 1 && filter->get_selected() == 0) {
  644. // match all filters
  645. for (int i = 0; i < filters.size(); i++) {
  646. String f = filters[i].get_slice(";", 0);
  647. for (int j = 0; j < f.get_slice_count(","); j++) {
  648. patterns.push_back(f.get_slice(",", j).strip_edges());
  649. }
  650. }
  651. } else {
  652. int idx = filter->get_selected();
  653. if (filters.size() > 1) {
  654. idx--;
  655. }
  656. if (idx >= 0 && idx < filters.size()) {
  657. String f = filters[idx].get_slice(";", 0);
  658. for (int j = 0; j < f.get_slice_count(","); j++) {
  659. patterns.push_back(f.get_slice(",", j).strip_edges());
  660. }
  661. }
  662. }
  663. String base_dir = dir_access->get_current_dir();
  664. while (!files.is_empty()) {
  665. bool match = patterns.is_empty();
  666. String match_str;
  667. for (const String &E : patterns) {
  668. if (files.front()->get().matchn(E)) {
  669. match_str = E;
  670. match = true;
  671. break;
  672. }
  673. }
  674. if (match && (filename_filter_lower.is_empty() || files.front()->get().to_lower().contains(filename_filter_lower))) {
  675. TreeItem *ti = tree->create_item(root);
  676. ti->set_text(0, files.front()->get());
  677. if (get_icon_func) {
  678. Ref<Texture2D> icon = get_icon_func(base_dir.path_join(files.front()->get()));
  679. ti->set_icon(0, icon);
  680. } else {
  681. ti->set_icon(0, theme_cache.file);
  682. }
  683. ti->set_icon_modulate(0, theme_cache.file_icon_color);
  684. if (mode == FILE_MODE_OPEN_DIR) {
  685. ti->set_custom_color(0, theme_cache.file_disabled_color);
  686. ti->set_selectable(0, false);
  687. }
  688. Dictionary d;
  689. d["name"] = files.front()->get();
  690. d["dir"] = false;
  691. ti->set_metadata(0, d);
  692. if (file->get_text() == files.front()->get() || match_str == files.front()->get()) {
  693. ti->select(0);
  694. }
  695. }
  696. files.pop_front();
  697. }
  698. if (mode != FILE_MODE_SAVE_FILE && mode != FILE_MODE_OPEN_DIR) {
  699. // Select the first file from list if nothing is selected.
  700. if (tree->get_root() && tree->get_root()->get_first_child() && tree->get_selected() == nullptr) {
  701. tree->get_root()->get_first_child()->select(0);
  702. }
  703. }
  704. }
  705. void FileDialog::_filter_selected(int) {
  706. update_file_name();
  707. update_file_list();
  708. }
  709. void FileDialog::_filename_filter_changed() {
  710. update_filename_filter();
  711. update_file_list();
  712. callable_mp(this, &FileDialog::_tree_select_first).call_deferred();
  713. }
  714. void FileDialog::_tree_select_first() {
  715. if (tree->get_root() && tree->get_root()->get_first_child()) {
  716. tree->get_root()->get_first_child()->select(0);
  717. }
  718. }
  719. void FileDialog::_filename_filter_selected() {
  720. TreeItem *item = tree->get_selected();
  721. if (item) {
  722. file->set_text(item->get_text(0));
  723. file->emit_signal("text_submitted", file->get_text());
  724. }
  725. }
  726. void FileDialog::update_filters() {
  727. filter->clear();
  728. if (filters.size() > 1) {
  729. String all_filters;
  730. const int max_filters = 5;
  731. for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
  732. String flt = filters[i].get_slice(";", 0).strip_edges();
  733. if (i > 0) {
  734. all_filters += ", ";
  735. }
  736. all_filters += flt;
  737. }
  738. if (max_filters < filters.size()) {
  739. all_filters += ", ...";
  740. }
  741. filter->add_item(atr(ETR("All Recognized")) + " (" + all_filters + ")");
  742. }
  743. for (int i = 0; i < filters.size(); i++) {
  744. String flt = filters[i].get_slice(";", 0).strip_edges();
  745. String desc = filters[i].get_slice(";", 1).strip_edges();
  746. if (desc.length()) {
  747. filter->add_item(String(tr(desc)) + " (" + flt + ")");
  748. } else {
  749. filter->add_item("(" + flt + ")");
  750. }
  751. }
  752. filter->add_item(atr(ETR("All Files")) + " (*)");
  753. }
  754. void FileDialog::clear_filename_filter() {
  755. set_filename_filter("");
  756. update_filename_filter_gui();
  757. invalidate();
  758. }
  759. void FileDialog::update_filename_filter_gui() {
  760. filename_filter_box->set_visible(show_filename_filter);
  761. if (!show_filename_filter) {
  762. file_name_filter.clear();
  763. }
  764. if (filename_filter->get_text() == file_name_filter) {
  765. return;
  766. }
  767. filename_filter->set_text(file_name_filter);
  768. }
  769. void FileDialog::update_filename_filter() {
  770. if (filename_filter->get_text() == file_name_filter) {
  771. return;
  772. }
  773. set_filename_filter(filename_filter->get_text());
  774. }
  775. void FileDialog::clear_filters() {
  776. filters.clear();
  777. update_filters();
  778. invalidate();
  779. }
  780. void FileDialog::add_filter(const String &p_filter, const String &p_description) {
  781. ERR_FAIL_COND_MSG(p_filter.begins_with("."), "Filter must be \"filename.extension\", can't start with dot.");
  782. if (p_description.is_empty()) {
  783. filters.push_back(p_filter);
  784. } else {
  785. filters.push_back(vformat("%s ; %s", p_filter, p_description));
  786. }
  787. update_filters();
  788. invalidate();
  789. }
  790. void FileDialog::set_filters(const Vector<String> &p_filters) {
  791. if (filters == p_filters) {
  792. return;
  793. }
  794. filters = p_filters;
  795. update_filters();
  796. invalidate();
  797. }
  798. void FileDialog::set_filename_filter(const String &p_filename_filter) {
  799. if (file_name_filter == p_filename_filter) {
  800. return;
  801. }
  802. file_name_filter = p_filename_filter;
  803. update_filename_filter_gui();
  804. emit_signal(SNAME("filename_filter_changed"), filter);
  805. invalidate();
  806. }
  807. Vector<String> FileDialog::get_filters() const {
  808. return filters;
  809. }
  810. String FileDialog::get_filename_filter() const {
  811. return file_name_filter;
  812. }
  813. String FileDialog::get_current_dir() const {
  814. return dir->get_text();
  815. }
  816. String FileDialog::get_current_file() const {
  817. return file->get_text();
  818. }
  819. String FileDialog::get_current_path() const {
  820. return dir->get_text().path_join(file->get_text());
  821. }
  822. void FileDialog::set_current_dir(const String &p_dir) {
  823. _change_dir(p_dir);
  824. _push_history();
  825. }
  826. void FileDialog::set_current_file(const String &p_file) {
  827. if (file->get_text() == p_file) {
  828. return;
  829. }
  830. file->set_text(p_file);
  831. update_dir();
  832. invalidate();
  833. _focus_file_text();
  834. }
  835. void FileDialog::set_current_path(const String &p_path) {
  836. if (!p_path.size()) {
  837. return;
  838. }
  839. int pos = MAX(p_path.rfind("/"), p_path.rfind("\\"));
  840. if (pos == -1) {
  841. set_current_file(p_path);
  842. } else {
  843. String path_dir = p_path.substr(0, pos);
  844. String path_file = p_path.substr(pos + 1, p_path.length());
  845. set_current_dir(path_dir);
  846. set_current_file(path_file);
  847. }
  848. }
  849. void FileDialog::set_root_subfolder(const String &p_root) {
  850. root_subfolder = p_root;
  851. ERR_FAIL_COND_MSG(!dir_access->dir_exists(p_root), "root_subfolder must be an existing sub-directory.");
  852. local_history.clear();
  853. local_history_pos = -1;
  854. dir_access->change_dir(root_subfolder);
  855. if (root_subfolder.is_empty()) {
  856. root_prefix = "";
  857. } else {
  858. root_prefix = dir_access->get_current_dir();
  859. }
  860. invalidate();
  861. update_dir();
  862. }
  863. String FileDialog::get_root_subfolder() const {
  864. return root_subfolder;
  865. }
  866. void FileDialog::set_mode_overrides_title(bool p_override) {
  867. mode_overrides_title = p_override;
  868. }
  869. bool FileDialog::is_mode_overriding_title() const {
  870. return mode_overrides_title;
  871. }
  872. void FileDialog::set_file_mode(FileMode p_mode) {
  873. ERR_FAIL_INDEX((int)p_mode, 5);
  874. if (mode == p_mode) {
  875. return;
  876. }
  877. mode = p_mode;
  878. switch (mode) {
  879. case FILE_MODE_OPEN_FILE:
  880. set_ok_button_text(ETR("Open"));
  881. if (mode_overrides_title) {
  882. set_title(ETR("Open a File"));
  883. }
  884. makedir->hide();
  885. break;
  886. case FILE_MODE_OPEN_FILES:
  887. set_ok_button_text(ETR("Open"));
  888. if (mode_overrides_title) {
  889. set_title(ETR("Open File(s)"));
  890. }
  891. makedir->hide();
  892. break;
  893. case FILE_MODE_OPEN_DIR:
  894. set_ok_button_text(ETR("Select Current Folder"));
  895. if (mode_overrides_title) {
  896. set_title(ETR("Open a Directory"));
  897. }
  898. makedir->show();
  899. break;
  900. case FILE_MODE_OPEN_ANY:
  901. set_ok_button_text(ETR("Open"));
  902. if (mode_overrides_title) {
  903. set_title(ETR("Open a File or Directory"));
  904. }
  905. makedir->show();
  906. break;
  907. case FILE_MODE_SAVE_FILE:
  908. set_ok_button_text(ETR("Save"));
  909. if (mode_overrides_title) {
  910. set_title(ETR("Save a File"));
  911. }
  912. makedir->show();
  913. break;
  914. }
  915. if (mode == FILE_MODE_OPEN_FILES) {
  916. tree->set_select_mode(Tree::SELECT_MULTI);
  917. } else {
  918. tree->set_select_mode(Tree::SELECT_SINGLE);
  919. }
  920. get_ok_button()->set_disabled(_is_open_should_be_disabled());
  921. }
  922. FileDialog::FileMode FileDialog::get_file_mode() const {
  923. return mode;
  924. }
  925. void FileDialog::set_access(Access p_access) {
  926. ERR_FAIL_INDEX(p_access, 3);
  927. if (access == p_access) {
  928. return;
  929. }
  930. switch (p_access) {
  931. case ACCESS_FILESYSTEM: {
  932. dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  933. } break;
  934. case ACCESS_RESOURCES: {
  935. dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  936. } break;
  937. case ACCESS_USERDATA: {
  938. dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA);
  939. } break;
  940. }
  941. access = p_access;
  942. root_prefix = "";
  943. root_subfolder = "";
  944. _update_drives();
  945. invalidate();
  946. update_filters();
  947. update_dir();
  948. }
  949. void FileDialog::invalidate() {
  950. if (!is_visible() || is_invalidating) {
  951. return;
  952. }
  953. is_invalidating = true;
  954. callable_mp(this, &FileDialog::_invalidate).call_deferred();
  955. }
  956. void FileDialog::_invalidate() {
  957. if (!is_invalidating) {
  958. return;
  959. }
  960. update_file_list();
  961. is_invalidating = false;
  962. }
  963. FileDialog::Access FileDialog::get_access() const {
  964. return access;
  965. }
  966. void FileDialog::_make_dir_confirm() {
  967. Error err = dir_access->make_dir(makedirname->get_text().strip_edges());
  968. if (err == OK) {
  969. _change_dir(makedirname->get_text().strip_edges());
  970. update_filters();
  971. _push_history();
  972. } else {
  973. mkdirerr->popup_centered(Size2(250, 50));
  974. }
  975. makedirname->set_text(""); // reset label
  976. }
  977. void FileDialog::_make_dir() {
  978. makedialog->popup_centered(Size2(250, 80));
  979. makedirname->grab_focus();
  980. }
  981. void FileDialog::_select_drive(int p_idx) {
  982. String d = drives->get_item_text(p_idx);
  983. _change_dir(d);
  984. file->set_text("");
  985. _push_history();
  986. }
  987. void FileDialog::_change_dir(const String &p_new_dir) {
  988. if (root_prefix.is_empty()) {
  989. dir_access->change_dir(p_new_dir);
  990. } else {
  991. String old_dir = dir_access->get_current_dir();
  992. dir_access->change_dir(p_new_dir);
  993. if (!dir_access->get_current_dir(false).begins_with(root_prefix)) {
  994. dir_access->change_dir(old_dir);
  995. return;
  996. }
  997. }
  998. invalidate();
  999. update_dir();
  1000. }
  1001. void FileDialog::_update_drives(bool p_select) {
  1002. int dc = dir_access->get_drive_count();
  1003. if (dc == 0 || access != ACCESS_FILESYSTEM) {
  1004. drives->hide();
  1005. } else {
  1006. drives->clear();
  1007. Node *dp = drives->get_parent();
  1008. if (dp) {
  1009. dp->remove_child(drives);
  1010. }
  1011. dp = dir_access->drives_are_shortcuts() ? shortcuts_container : drives_container;
  1012. dp->add_child(drives);
  1013. drives->show();
  1014. for (int i = 0; i < dir_access->get_drive_count(); i++) {
  1015. drives->add_item(dir_access->get_drive(i));
  1016. }
  1017. if (p_select) {
  1018. drives->select(dir_access->get_current_drive());
  1019. }
  1020. }
  1021. }
  1022. bool FileDialog::default_show_hidden_files = false;
  1023. TypedArray<Dictionary> FileDialog::_get_options() const {
  1024. TypedArray<Dictionary> out;
  1025. for (const FileDialog::Option &opt : options) {
  1026. Dictionary dict;
  1027. dict["name"] = opt.name;
  1028. dict["values"] = opt.values;
  1029. dict["default"] = (int)selected_options.get(opt.name, opt.default_idx);
  1030. out.push_back(dict);
  1031. }
  1032. return out;
  1033. }
  1034. void FileDialog::_option_changed_checkbox_toggled(bool p_pressed, const String &p_name) {
  1035. if (selected_options.has(p_name)) {
  1036. selected_options[p_name] = p_pressed;
  1037. }
  1038. }
  1039. void FileDialog::_option_changed_item_selected(int p_idx, const String &p_name) {
  1040. if (selected_options.has(p_name)) {
  1041. selected_options[p_name] = p_idx;
  1042. }
  1043. }
  1044. void FileDialog::_update_option_controls() {
  1045. if (!options_dirty) {
  1046. return;
  1047. }
  1048. options_dirty = false;
  1049. while (grid_options->get_child_count() > 0) {
  1050. Node *child = grid_options->get_child(0);
  1051. grid_options->remove_child(child);
  1052. child->queue_free();
  1053. }
  1054. selected_options.clear();
  1055. for (const FileDialog::Option &opt : options) {
  1056. Label *lbl = memnew(Label);
  1057. lbl->set_text(opt.name);
  1058. grid_options->add_child(lbl);
  1059. if (opt.values.is_empty()) {
  1060. CheckBox *cb = memnew(CheckBox);
  1061. cb->set_pressed(opt.default_idx);
  1062. grid_options->add_child(cb);
  1063. cb->connect(SceneStringName(toggled), callable_mp(this, &FileDialog::_option_changed_checkbox_toggled).bind(opt.name));
  1064. selected_options[opt.name] = (bool)opt.default_idx;
  1065. } else {
  1066. OptionButton *ob = memnew(OptionButton);
  1067. for (const String &val : opt.values) {
  1068. ob->add_item(val);
  1069. }
  1070. ob->select(opt.default_idx);
  1071. grid_options->add_child(ob);
  1072. ob->connect(SceneStringName(item_selected), callable_mp(this, &FileDialog::_option_changed_item_selected).bind(opt.name));
  1073. selected_options[opt.name] = opt.default_idx;
  1074. }
  1075. }
  1076. }
  1077. Dictionary FileDialog::get_selected_options() const {
  1078. return selected_options;
  1079. }
  1080. String FileDialog::get_option_name(int p_option) const {
  1081. ERR_FAIL_INDEX_V(p_option, options.size(), String());
  1082. return options[p_option].name;
  1083. }
  1084. Vector<String> FileDialog::get_option_values(int p_option) const {
  1085. ERR_FAIL_INDEX_V(p_option, options.size(), Vector<String>());
  1086. return options[p_option].values;
  1087. }
  1088. int FileDialog::get_option_default(int p_option) const {
  1089. ERR_FAIL_INDEX_V(p_option, options.size(), -1);
  1090. return options[p_option].default_idx;
  1091. }
  1092. void FileDialog::set_option_name(int p_option, const String &p_name) {
  1093. if (p_option < 0) {
  1094. p_option += get_option_count();
  1095. }
  1096. ERR_FAIL_INDEX(p_option, options.size());
  1097. options.write[p_option].name = p_name;
  1098. options_dirty = true;
  1099. if (is_visible()) {
  1100. _update_option_controls();
  1101. }
  1102. }
  1103. void FileDialog::set_option_values(int p_option, const Vector<String> &p_values) {
  1104. if (p_option < 0) {
  1105. p_option += get_option_count();
  1106. }
  1107. ERR_FAIL_INDEX(p_option, options.size());
  1108. options.write[p_option].values = p_values;
  1109. if (p_values.is_empty()) {
  1110. options.write[p_option].default_idx = CLAMP(options[p_option].default_idx, 0, 1);
  1111. } else {
  1112. options.write[p_option].default_idx = CLAMP(options[p_option].default_idx, 0, options[p_option].values.size() - 1);
  1113. }
  1114. options_dirty = true;
  1115. if (is_visible()) {
  1116. _update_option_controls();
  1117. }
  1118. }
  1119. void FileDialog::set_option_default(int p_option, int p_index) {
  1120. if (p_option < 0) {
  1121. p_option += get_option_count();
  1122. }
  1123. ERR_FAIL_INDEX(p_option, options.size());
  1124. if (options[p_option].values.is_empty()) {
  1125. options.write[p_option].default_idx = CLAMP(p_index, 0, 1);
  1126. } else {
  1127. options.write[p_option].default_idx = CLAMP(p_index, 0, options[p_option].values.size() - 1);
  1128. }
  1129. options_dirty = true;
  1130. if (is_visible()) {
  1131. _update_option_controls();
  1132. }
  1133. }
  1134. void FileDialog::add_option(const String &p_name, const Vector<String> &p_values, int p_index) {
  1135. Option opt;
  1136. opt.name = p_name;
  1137. opt.values = p_values;
  1138. if (opt.values.is_empty()) {
  1139. opt.default_idx = CLAMP(p_index, 0, 1);
  1140. } else {
  1141. opt.default_idx = CLAMP(p_index, 0, opt.values.size() - 1);
  1142. }
  1143. options.push_back(opt);
  1144. options_dirty = true;
  1145. if (is_visible()) {
  1146. _update_option_controls();
  1147. }
  1148. }
  1149. void FileDialog::set_option_count(int p_count) {
  1150. ERR_FAIL_COND(p_count < 0);
  1151. if (options.size() == p_count) {
  1152. return;
  1153. }
  1154. options.resize(p_count);
  1155. options_dirty = true;
  1156. notify_property_list_changed();
  1157. if (is_visible()) {
  1158. _update_option_controls();
  1159. }
  1160. }
  1161. int FileDialog::get_option_count() const {
  1162. return options.size();
  1163. }
  1164. void FileDialog::_bind_methods() {
  1165. ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed);
  1166. ClassDB::bind_method(D_METHOD("clear_filters"), &FileDialog::clear_filters);
  1167. ClassDB::bind_method(D_METHOD("add_filter", "filter", "description"), &FileDialog::add_filter, DEFVAL(""));
  1168. ClassDB::bind_method(D_METHOD("set_filters", "filters"), &FileDialog::set_filters);
  1169. ClassDB::bind_method(D_METHOD("get_filters"), &FileDialog::get_filters);
  1170. ClassDB::bind_method(D_METHOD("clear_filename_filter"), &FileDialog::clear_filename_filter);
  1171. ClassDB::bind_method(D_METHOD("set_filename_filter", "filter"), &FileDialog::set_filename_filter);
  1172. ClassDB::bind_method(D_METHOD("get_filename_filter"), &FileDialog::get_filename_filter);
  1173. ClassDB::bind_method(D_METHOD("get_option_name", "option"), &FileDialog::get_option_name);
  1174. ClassDB::bind_method(D_METHOD("get_option_values", "option"), &FileDialog::get_option_values);
  1175. ClassDB::bind_method(D_METHOD("get_option_default", "option"), &FileDialog::get_option_default);
  1176. ClassDB::bind_method(D_METHOD("set_option_name", "option", "name"), &FileDialog::set_option_name);
  1177. ClassDB::bind_method(D_METHOD("set_option_values", "option", "values"), &FileDialog::set_option_values);
  1178. ClassDB::bind_method(D_METHOD("set_option_default", "option", "default_value_index"), &FileDialog::set_option_default);
  1179. ClassDB::bind_method(D_METHOD("set_option_count", "count"), &FileDialog::set_option_count);
  1180. ClassDB::bind_method(D_METHOD("get_option_count"), &FileDialog::get_option_count);
  1181. ClassDB::bind_method(D_METHOD("add_option", "name", "values", "default_value_index"), &FileDialog::add_option);
  1182. ClassDB::bind_method(D_METHOD("get_selected_options"), &FileDialog::get_selected_options);
  1183. ClassDB::bind_method(D_METHOD("get_current_dir"), &FileDialog::get_current_dir);
  1184. ClassDB::bind_method(D_METHOD("get_current_file"), &FileDialog::get_current_file);
  1185. ClassDB::bind_method(D_METHOD("get_current_path"), &FileDialog::get_current_path);
  1186. ClassDB::bind_method(D_METHOD("set_current_dir", "dir"), &FileDialog::set_current_dir);
  1187. ClassDB::bind_method(D_METHOD("set_current_file", "file"), &FileDialog::set_current_file);
  1188. ClassDB::bind_method(D_METHOD("set_current_path", "path"), &FileDialog::set_current_path);
  1189. ClassDB::bind_method(D_METHOD("set_mode_overrides_title", "override"), &FileDialog::set_mode_overrides_title);
  1190. ClassDB::bind_method(D_METHOD("is_mode_overriding_title"), &FileDialog::is_mode_overriding_title);
  1191. ClassDB::bind_method(D_METHOD("set_file_mode", "mode"), &FileDialog::set_file_mode);
  1192. ClassDB::bind_method(D_METHOD("get_file_mode"), &FileDialog::get_file_mode);
  1193. ClassDB::bind_method(D_METHOD("get_vbox"), &FileDialog::get_vbox);
  1194. ClassDB::bind_method(D_METHOD("get_line_edit"), &FileDialog::get_line_edit);
  1195. ClassDB::bind_method(D_METHOD("set_access", "access"), &FileDialog::set_access);
  1196. ClassDB::bind_method(D_METHOD("get_access"), &FileDialog::get_access);
  1197. ClassDB::bind_method(D_METHOD("set_root_subfolder", "dir"), &FileDialog::set_root_subfolder);
  1198. ClassDB::bind_method(D_METHOD("get_root_subfolder"), &FileDialog::get_root_subfolder);
  1199. ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &FileDialog::set_show_hidden_files);
  1200. ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &FileDialog::is_showing_hidden_files);
  1201. ClassDB::bind_method(D_METHOD("set_use_native_dialog", "native"), &FileDialog::set_use_native_dialog);
  1202. ClassDB::bind_method(D_METHOD("get_use_native_dialog"), &FileDialog::get_use_native_dialog);
  1203. ClassDB::bind_method(D_METHOD("deselect_all"), &FileDialog::deselect_all);
  1204. ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate);
  1205. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mode_overrides_title"), "set_mode_overrides_title", "is_mode_overriding_title");
  1206. 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");
  1207. ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User Data,File System"), "set_access", "get_access");
  1208. ADD_PROPERTY(PropertyInfo(Variant::STRING, "root_subfolder"), "set_root_subfolder", "get_root_subfolder");
  1209. ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters");
  1210. ADD_PROPERTY(PropertyInfo(Variant::STRING, "filename_filter"), "set_filename_filter", "get_filename_filter");
  1211. ADD_ARRAY_COUNT("Options", "option_count", "set_option_count", "get_option_count", "option_");
  1212. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_hidden_files"), "set_show_hidden_files", "is_showing_hidden_files");
  1213. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_native_dialog"), "set_use_native_dialog", "get_use_native_dialog");
  1214. ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir", PROPERTY_HINT_DIR, "", PROPERTY_USAGE_NONE), "set_current_dir", "get_current_dir");
  1215. ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");
  1216. ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_current_path", "get_current_path");
  1217. ADD_SIGNAL(MethodInfo("file_selected", PropertyInfo(Variant::STRING, "path")));
  1218. ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths")));
  1219. ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir")));
  1220. ADD_SIGNAL(MethodInfo("filename_filter_changed", PropertyInfo(Variant::STRING, "filter")));
  1221. BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILE);
  1222. BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILES);
  1223. BIND_ENUM_CONSTANT(FILE_MODE_OPEN_DIR);
  1224. BIND_ENUM_CONSTANT(FILE_MODE_OPEN_ANY);
  1225. BIND_ENUM_CONSTANT(FILE_MODE_SAVE_FILE);
  1226. BIND_ENUM_CONSTANT(ACCESS_RESOURCES);
  1227. BIND_ENUM_CONSTANT(ACCESS_USERDATA);
  1228. BIND_ENUM_CONSTANT(ACCESS_FILESYSTEM);
  1229. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, parent_folder);
  1230. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, forward_folder);
  1231. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, back_folder);
  1232. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, reload);
  1233. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, toggle_hidden);
  1234. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, folder);
  1235. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, toggle_filename_filter);
  1236. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, file);
  1237. BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, create_folder);
  1238. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, FileDialog, folder_icon_color);
  1239. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, FileDialog, file_icon_color);
  1240. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, FileDialog, file_disabled_color);
  1241. // TODO: Define own colors?
  1242. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, FileDialog, icon_normal_color, "font_color", "Button");
  1243. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, FileDialog, icon_hover_color, "font_hover_color", "Button");
  1244. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, FileDialog, icon_focus_color, "font_focus_color", "Button");
  1245. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, FileDialog, icon_pressed_color, "font_pressed_color", "Button");
  1246. Option defaults;
  1247. base_property_helper.set_prefix("option_");
  1248. base_property_helper.set_array_length_getter(&FileDialog::get_option_count);
  1249. base_property_helper.register_property(PropertyInfo(Variant::STRING, "name"), defaults.name, &FileDialog::set_option_name, &FileDialog::get_option_name);
  1250. base_property_helper.register_property(PropertyInfo(Variant::PACKED_STRING_ARRAY, "values"), defaults.values, &FileDialog::set_option_values, &FileDialog::get_option_values);
  1251. base_property_helper.register_property(PropertyInfo(Variant::INT, "default"), defaults.default_idx, &FileDialog::set_option_default, &FileDialog::get_option_default);
  1252. PropertyListHelper::register_base_helper(&base_property_helper);
  1253. }
  1254. void FileDialog::set_show_hidden_files(bool p_show) {
  1255. if (show_hidden_files == p_show) {
  1256. return;
  1257. }
  1258. show_hidden_files = p_show;
  1259. invalidate();
  1260. }
  1261. void FileDialog::set_show_filename_filter(bool p_show) {
  1262. if (p_show == show_filename_filter) {
  1263. return;
  1264. }
  1265. if (p_show) {
  1266. filename_filter->grab_focus();
  1267. } else {
  1268. if (filename_filter->has_focus()) {
  1269. tree->call_deferred("grab_focus");
  1270. }
  1271. }
  1272. show_filename_filter = p_show;
  1273. update_filename_filter_gui();
  1274. invalidate();
  1275. }
  1276. bool FileDialog::get_show_filename_filter() const {
  1277. return show_filename_filter;
  1278. }
  1279. bool FileDialog::is_showing_hidden_files() const {
  1280. return show_hidden_files;
  1281. }
  1282. void FileDialog::set_default_show_hidden_files(bool p_show) {
  1283. default_show_hidden_files = p_show;
  1284. }
  1285. void FileDialog::set_use_native_dialog(bool p_native) {
  1286. use_native_dialog = p_native;
  1287. #ifdef TOOLS_ENABLED
  1288. if (is_part_of_edited_scene()) {
  1289. return;
  1290. }
  1291. #endif
  1292. // Replace the built-in dialog with the native one if it's currently visible.
  1293. if (is_inside_tree() && is_visible() && _can_use_native_popup() && (use_native_dialog || OS::get_singleton()->is_sandboxed())) {
  1294. ConfirmationDialog::set_visible(false);
  1295. _native_popup();
  1296. }
  1297. }
  1298. bool FileDialog::get_use_native_dialog() const {
  1299. return use_native_dialog;
  1300. }
  1301. FileDialog::FileDialog() {
  1302. show_hidden_files = default_show_hidden_files;
  1303. vbox = memnew(VBoxContainer);
  1304. add_child(vbox, false, INTERNAL_MODE_FRONT);
  1305. mode = FILE_MODE_SAVE_FILE;
  1306. set_title(TTRC("Save a File"));
  1307. HBoxContainer *hbc = memnew(HBoxContainer);
  1308. dir_prev = memnew(Button);
  1309. dir_prev->set_theme_type_variation("FlatButton");
  1310. dir_prev->set_tooltip_text(ETR("Go to previous folder."));
  1311. dir_next = memnew(Button);
  1312. dir_next->set_theme_type_variation("FlatButton");
  1313. dir_next->set_tooltip_text(ETR("Go to next folder."));
  1314. dir_up = memnew(Button);
  1315. dir_up->set_theme_type_variation("FlatButton");
  1316. dir_up->set_tooltip_text(ETR("Go to parent folder."));
  1317. hbc->add_child(dir_prev);
  1318. hbc->add_child(dir_next);
  1319. hbc->add_child(dir_up);
  1320. dir_prev->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_back));
  1321. dir_next->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_forward));
  1322. dir_up->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_up));
  1323. hbc->add_child(memnew(Label(ETR("Path:"))));
  1324. drives_container = memnew(HBoxContainer);
  1325. hbc->add_child(drives_container);
  1326. drives = memnew(OptionButton);
  1327. drives->connect(SceneStringName(item_selected), callable_mp(this, &FileDialog::_select_drive));
  1328. hbc->add_child(drives);
  1329. dir = memnew(LineEdit);
  1330. dir->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  1331. hbc->add_child(dir);
  1332. dir->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1333. refresh = memnew(Button);
  1334. refresh->set_theme_type_variation("FlatButton");
  1335. refresh->set_tooltip_text(ETR("Refresh files."));
  1336. refresh->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::update_file_list));
  1337. hbc->add_child(refresh);
  1338. show_hidden = memnew(Button);
  1339. show_hidden->set_theme_type_variation("FlatButton");
  1340. show_hidden->set_toggle_mode(true);
  1341. show_hidden->set_pressed(is_showing_hidden_files());
  1342. show_hidden->set_tooltip_text(ETR("Toggle the visibility of hidden files."));
  1343. show_hidden->connect(SceneStringName(toggled), callable_mp(this, &FileDialog::set_show_hidden_files));
  1344. hbc->add_child(show_hidden);
  1345. show_filename_filter_button = memnew(Button);
  1346. show_filename_filter_button->set_theme_type_variation("FlatButton");
  1347. show_filename_filter_button->set_toggle_mode(true);
  1348. show_filename_filter_button->set_pressed(false);
  1349. show_filename_filter_button->set_tooltip_text(RTR("Toggle the visibility of the filter for file names."));
  1350. show_filename_filter_button->connect(SceneStringName(toggled), callable_mp(this, &FileDialog::set_show_filename_filter));
  1351. hbc->add_child(show_filename_filter_button);
  1352. shortcuts_container = memnew(HBoxContainer);
  1353. hbc->add_child(shortcuts_container);
  1354. makedir = memnew(Button);
  1355. makedir->set_theme_type_variation("FlatButton");
  1356. makedir->set_tooltip_text(ETR("Create a new folder."));
  1357. makedir->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_make_dir));
  1358. hbc->add_child(makedir);
  1359. vbox->add_child(hbc);
  1360. tree = memnew(Tree);
  1361. tree->set_hide_root(true);
  1362. vbox->add_margin_child(ETR("Directories & Files:"), tree, true);
  1363. message = memnew(Label);
  1364. message->hide();
  1365. message->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  1366. message->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1367. message->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  1368. tree->add_child(message);
  1369. filename_filter_box = memnew(HBoxContainer);
  1370. filename_filter_box->add_child(memnew(Label(RTR("Filter:"))));
  1371. filename_filter = memnew(LineEdit);
  1372. filename_filter->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  1373. filename_filter->set_stretch_ratio(4);
  1374. filename_filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1375. filename_filter->set_clear_button_enabled(true);
  1376. filename_filter_box->add_child(filename_filter);
  1377. filename_filter_box->set_visible(false);
  1378. vbox->add_child(filename_filter_box);
  1379. file_box = memnew(HBoxContainer);
  1380. file_box->add_child(memnew(Label(ETR("File:"))));
  1381. file = memnew(LineEdit);
  1382. file->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  1383. file->set_stretch_ratio(4);
  1384. file->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1385. file_box->add_child(file);
  1386. filter = memnew(OptionButton);
  1387. filter->set_stretch_ratio(3);
  1388. filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1389. filter->set_clip_text(true); // too many extensions overflows it
  1390. file_box->add_child(filter);
  1391. vbox->add_child(file_box);
  1392. grid_options = memnew(GridContainer);
  1393. grid_options->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  1394. grid_options->set_columns(2);
  1395. vbox->add_child(grid_options);
  1396. dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1397. _update_drives();
  1398. connect(SceneStringName(confirmed), callable_mp(this, &FileDialog::_action_pressed));
  1399. tree->connect("multi_selected", callable_mp(this, &FileDialog::_tree_multi_selected), CONNECT_DEFERRED);
  1400. tree->connect("cell_selected", callable_mp(this, &FileDialog::_tree_selected), CONNECT_DEFERRED);
  1401. tree->connect("item_activated", callable_mp(this, &FileDialog::_tree_item_activated));
  1402. tree->connect("nothing_selected", callable_mp(this, &FileDialog::deselect_all));
  1403. dir->connect("text_submitted", callable_mp(this, &FileDialog::_dir_submitted));
  1404. filename_filter->connect(SceneStringName(text_changed), callable_mp(this, &FileDialog::_filename_filter_changed).unbind(1));
  1405. filename_filter->connect("text_submitted", callable_mp(this, &FileDialog::_filename_filter_selected).unbind(1));
  1406. file->connect("text_submitted", callable_mp(this, &FileDialog::_file_submitted));
  1407. filter->connect(SceneStringName(item_selected), callable_mp(this, &FileDialog::_filter_selected));
  1408. confirm_save = memnew(ConfirmationDialog);
  1409. add_child(confirm_save, false, INTERNAL_MODE_FRONT);
  1410. confirm_save->connect(SceneStringName(confirmed), callable_mp(this, &FileDialog::_save_confirm_pressed));
  1411. makedialog = memnew(ConfirmationDialog);
  1412. makedialog->set_title(ETR("Create Folder"));
  1413. VBoxContainer *makevb = memnew(VBoxContainer);
  1414. makedialog->add_child(makevb);
  1415. makedirname = memnew(LineEdit);
  1416. makedirname->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
  1417. makevb->add_margin_child(ETR("Name:"), makedirname);
  1418. add_child(makedialog, false, INTERNAL_MODE_FRONT);
  1419. makedialog->register_text_enter(makedirname);
  1420. makedialog->connect(SceneStringName(confirmed), callable_mp(this, &FileDialog::_make_dir_confirm));
  1421. mkdirerr = memnew(AcceptDialog);
  1422. mkdirerr->set_text(ETR("Could not create folder."));
  1423. add_child(mkdirerr, false, INTERNAL_MODE_FRONT);
  1424. exterr = memnew(AcceptDialog);
  1425. exterr->set_text(ETR("Invalid extension, or empty filename."));
  1426. add_child(exterr, false, INTERNAL_MODE_FRONT);
  1427. update_filters();
  1428. update_filename_filter_gui();
  1429. update_dir();
  1430. set_hide_on_ok(false);
  1431. set_size(Size2(640, 360));
  1432. if (register_func) {
  1433. register_func(this);
  1434. }
  1435. property_helper.setup_for_instance(base_property_helper, this);
  1436. }
  1437. FileDialog::~FileDialog() {
  1438. if (unregister_func) {
  1439. unregister_func(this);
  1440. }
  1441. }