editor_file_dialog.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*************************************************************************/
  2. /* editor_file_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 EDITORFILEDIALOG_H
  31. #define EDITORFILEDIALOG_H
  32. #include "os/dir_access.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/item_list.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/option_button.h"
  38. #include "scene/gui/split_container.h"
  39. #include "scene/gui/texture_rect.h"
  40. #include "scene/gui/tool_button.h"
  41. /**
  42. @author Juan Linietsky <reduzio@gmail.com>
  43. */
  44. class EditorFileDialog : public ConfirmationDialog {
  45. GDCLASS(EditorFileDialog, ConfirmationDialog);
  46. public:
  47. enum DisplayMode {
  48. DISPLAY_THUMBNAILS,
  49. DISPLAY_LIST
  50. };
  51. enum Access {
  52. ACCESS_RESOURCES,
  53. ACCESS_USERDATA,
  54. ACCESS_FILESYSTEM
  55. };
  56. enum Mode {
  57. MODE_OPEN_FILE,
  58. MODE_OPEN_FILES,
  59. MODE_OPEN_DIR,
  60. MODE_OPEN_ANY,
  61. MODE_SAVE_FILE
  62. };
  63. typedef Ref<Texture> (*GetIconFunc)(const String &);
  64. typedef void (*RegisterFunc)(EditorFileDialog *);
  65. static GetIconFunc get_icon_func;
  66. static GetIconFunc get_large_icon_func;
  67. static RegisterFunc register_func;
  68. static RegisterFunc unregister_func;
  69. private:
  70. ConfirmationDialog *makedialog;
  71. LineEdit *makedirname;
  72. Button *makedir;
  73. Access access;
  74. //Button *action;
  75. VBoxContainer *vbox;
  76. Mode mode;
  77. LineEdit *dir;
  78. ToolButton *dir_prev;
  79. ToolButton *dir_next;
  80. ToolButton *dir_up;
  81. OptionButton *drives;
  82. ItemList *item_list;
  83. TextureRect *preview;
  84. VBoxContainer *preview_vb;
  85. HSplitContainer *list_hb;
  86. LineEdit *file;
  87. AcceptDialog *mkdirerr;
  88. AcceptDialog *exterr;
  89. OptionButton *filter;
  90. DirAccess *dir_access;
  91. ConfirmationDialog *confirm_save;
  92. ToolButton *mode_thumbnails;
  93. ToolButton *mode_list;
  94. ToolButton *refresh;
  95. ToolButton *favorite;
  96. ToolButton *fav_up;
  97. ToolButton *fav_down;
  98. ToolButton *fav_rm;
  99. ItemList *favorites;
  100. ItemList *recent;
  101. Vector<String> local_history;
  102. int local_history_pos;
  103. void _push_history();
  104. Vector<String> filters;
  105. bool preview_waiting;
  106. int preview_wheel_index;
  107. float preview_wheel_timeout;
  108. static bool default_show_hidden_files;
  109. static DisplayMode default_display_mode;
  110. bool show_hidden_files;
  111. DisplayMode display_mode;
  112. bool disable_overwrite_warning;
  113. bool invalidated;
  114. void update_dir();
  115. void update_file_list();
  116. void update_filters();
  117. void _update_favorites();
  118. void _favorite_toggled(bool p_toggle);
  119. void _favorite_selected(int p_idx);
  120. void _favorite_move_up();
  121. void _favorite_move_down();
  122. void _recent_selected(int p_idx);
  123. void _item_selected(int p_item);
  124. void _item_dc_selected(int p_item);
  125. void _select_drive(int p_idx);
  126. void _dir_entered(String p_dir);
  127. void _file_entered(const String &p_file);
  128. void _action_pressed();
  129. void _save_confirm_pressed();
  130. void _cancel_pressed();
  131. void _filter_selected(int);
  132. void _make_dir();
  133. void _make_dir_confirm();
  134. void _update_drives();
  135. void _go_up();
  136. void _go_back();
  137. void _go_forward();
  138. virtual void _post_popup();
  139. void _save_to_recent();
  140. //callback function is callback(String p_path,Ref<Texture> preview,Variant udata) preview null if could not load
  141. void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
  142. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
  143. void _request_single_thumbnail(const String &p_path);
  144. void _unhandled_input(const Ref<InputEvent> &p_event);
  145. protected:
  146. void _notification(int p_what);
  147. static void _bind_methods();
  148. //bind helpers
  149. public:
  150. void clear_filters();
  151. void add_filter(const String &p_filter);
  152. void set_enable_multiple_selection(bool p_enable);
  153. Vector<String> get_selected_files() const;
  154. String get_current_dir() const;
  155. String get_current_file() const;
  156. String get_current_path() const;
  157. void set_current_dir(const String &p_dir);
  158. void set_current_file(const String &p_file);
  159. void set_current_path(const String &p_path);
  160. void set_display_mode(DisplayMode p_mode);
  161. DisplayMode get_display_mode() const;
  162. void set_mode(Mode p_mode);
  163. Mode get_mode() const;
  164. VBoxContainer *get_vbox();
  165. LineEdit *get_line_edit() { return file; }
  166. void set_access(Access p_access);
  167. Access get_access() const;
  168. void set_show_hidden_files(bool p_show);
  169. bool is_showing_hidden_files() const;
  170. static void set_default_show_hidden_files(bool p_show);
  171. static void set_default_display_mode(DisplayMode p_mode);
  172. void invalidate();
  173. void set_disable_overwrite_warning(bool p_disable);
  174. bool is_overwrite_warning_disabled() const;
  175. EditorFileDialog();
  176. ~EditorFileDialog();
  177. };
  178. class EditorLineEditFileChooser : public HBoxContainer {
  179. GDCLASS(EditorLineEditFileChooser, HBoxContainer);
  180. Button *button;
  181. LineEdit *line_edit;
  182. EditorFileDialog *dialog;
  183. void _chosen(const String &p_text);
  184. void _browse();
  185. protected:
  186. static void _bind_methods();
  187. public:
  188. Button *get_button() { return button; }
  189. LineEdit *get_line_edit() { return line_edit; }
  190. EditorFileDialog *get_file_dialog() { return dialog; }
  191. EditorLineEditFileChooser();
  192. };
  193. VARIANT_ENUM_CAST(EditorFileDialog::Mode);
  194. VARIANT_ENUM_CAST(EditorFileDialog::Access);
  195. VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
  196. #endif // EDITORFILEDIALOG_H