file_dialog.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*************************************************************************/
  2. /* file_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef FILE_DIALOG_H
  31. #define FILE_DIALOG_H
  32. #include "box_container.h"
  33. #include "core/os/dir_access.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/line_edit.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/tool_button.h"
  38. #include "scene/gui/tree.h"
  39. class FileDialog : public ConfirmationDialog {
  40. GDCLASS(FileDialog, ConfirmationDialog);
  41. public:
  42. enum Access {
  43. ACCESS_RESOURCES,
  44. ACCESS_USERDATA,
  45. ACCESS_FILESYSTEM
  46. };
  47. enum Mode {
  48. MODE_OPEN_FILE,
  49. MODE_OPEN_FILES,
  50. MODE_OPEN_DIR,
  51. MODE_OPEN_ANY,
  52. MODE_SAVE_FILE
  53. };
  54. typedef Ref<Texture> (*GetIconFunc)(const String &);
  55. typedef void (*RegisterFunc)(FileDialog *);
  56. static GetIconFunc get_icon_func;
  57. static GetIconFunc get_large_icon_func;
  58. static RegisterFunc register_func;
  59. static RegisterFunc unregister_func;
  60. private:
  61. ConfirmationDialog *makedialog;
  62. LineEdit *makedirname;
  63. Button *makedir;
  64. Access access;
  65. //Button *action;
  66. VBoxContainer *vbox;
  67. Mode mode;
  68. LineEdit *dir;
  69. HBoxContainer *drives_container;
  70. HBoxContainer *shortcuts_container;
  71. OptionButton *drives;
  72. Tree *tree;
  73. HBoxContainer *file_box;
  74. LineEdit *file;
  75. OptionButton *filter;
  76. AcceptDialog *mkdirerr;
  77. AcceptDialog *exterr;
  78. DirAccess *dir_access;
  79. ConfirmationDialog *confirm_save;
  80. ToolButton *dir_up;
  81. ToolButton *refresh;
  82. ToolButton *show_hidden;
  83. Vector<String> filters;
  84. bool mode_overrides_title;
  85. static bool default_show_hidden_files;
  86. bool show_hidden_files;
  87. bool invalidated;
  88. void update_dir();
  89. void update_file_name();
  90. void update_file_list();
  91. void update_filters();
  92. void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected);
  93. void _tree_selected();
  94. void _select_drive(int p_idx);
  95. void _tree_item_activated();
  96. void _dir_entered(String p_dir);
  97. void _file_entered(const String &p_file);
  98. void _action_pressed();
  99. void _save_confirm_pressed();
  100. void _cancel_pressed();
  101. void _filter_selected(int);
  102. void _make_dir();
  103. void _make_dir_confirm();
  104. void _go_up();
  105. void _update_drives();
  106. void _unhandled_input(const Ref<InputEvent> &p_event);
  107. bool _is_open_should_be_disabled();
  108. virtual void _post_popup();
  109. protected:
  110. void _notification(int p_what);
  111. static void _bind_methods();
  112. //bind helpers
  113. public:
  114. void clear_filters();
  115. void add_filter(const String &p_filter);
  116. void set_filters(const Vector<String> &p_filters);
  117. Vector<String> get_filters() const;
  118. void set_enable_multiple_selection(bool p_enable);
  119. Vector<String> get_selected_files() const;
  120. String get_current_dir() const;
  121. String get_current_file() const;
  122. String get_current_path() const;
  123. void set_current_dir(const String &p_dir);
  124. void set_current_file(const String &p_file);
  125. void set_current_path(const String &p_path);
  126. void set_mode_overrides_title(bool p_override);
  127. bool is_mode_overriding_title() const;
  128. void set_mode(Mode p_mode);
  129. Mode get_mode() const;
  130. VBoxContainer *get_vbox();
  131. LineEdit *get_line_edit() { return file; }
  132. void set_access(Access p_access);
  133. Access get_access() const;
  134. void set_show_hidden_files(bool p_show);
  135. bool is_showing_hidden_files() const;
  136. static void set_default_show_hidden_files(bool p_show);
  137. void invalidate();
  138. void deselect_items();
  139. FileDialog();
  140. ~FileDialog();
  141. };
  142. class LineEditFileChooser : public HBoxContainer {
  143. GDCLASS(LineEditFileChooser, HBoxContainer);
  144. Button *button;
  145. LineEdit *line_edit;
  146. FileDialog *dialog;
  147. void _chosen(const String &p_text);
  148. void _browse();
  149. protected:
  150. static void _bind_methods();
  151. public:
  152. Button *get_button() { return button; }
  153. LineEdit *get_line_edit() { return line_edit; }
  154. FileDialog *get_file_dialog() { return dialog; }
  155. LineEditFileChooser();
  156. };
  157. VARIANT_ENUM_CAST(FileDialog::Mode);
  158. VARIANT_ENUM_CAST(FileDialog::Access);
  159. #endif