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