editor_file_dialog.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "core/io/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/separator.h"
  39. #include "scene/gui/split_container.h"
  40. #include "scene/gui/texture_rect.h"
  41. class DependencyRemoveDialog;
  42. class EditorFileDialog : public ConfirmationDialog {
  43. GDCLASS(EditorFileDialog, ConfirmationDialog);
  44. public:
  45. enum DisplayMode {
  46. DISPLAY_THUMBNAILS,
  47. DISPLAY_LIST
  48. };
  49. enum Access {
  50. ACCESS_RESOURCES,
  51. ACCESS_USERDATA,
  52. ACCESS_FILESYSTEM
  53. };
  54. enum FileMode {
  55. FILE_MODE_OPEN_FILE,
  56. FILE_MODE_OPEN_FILES,
  57. FILE_MODE_OPEN_DIR,
  58. FILE_MODE_OPEN_ANY,
  59. FILE_MODE_SAVE_FILE
  60. };
  61. typedef Ref<Texture2D> (*GetIconFunc)(const String &);
  62. typedef void (*RegisterFunc)(EditorFileDialog *);
  63. static GetIconFunc get_icon_func;
  64. static GetIconFunc get_large_icon_func;
  65. static RegisterFunc register_func;
  66. static RegisterFunc unregister_func;
  67. private:
  68. enum ItemMenu {
  69. ITEM_MENU_COPY_PATH,
  70. ITEM_MENU_DELETE,
  71. ITEM_MENU_REFRESH,
  72. ITEM_MENU_NEW_FOLDER,
  73. ITEM_MENU_SHOW_IN_EXPLORER
  74. };
  75. ConfirmationDialog *makedialog;
  76. LineEdit *makedirname;
  77. Button *makedir;
  78. Access access;
  79. //Button *action;
  80. VBoxContainer *vbox;
  81. FileMode mode;
  82. bool can_create_dir;
  83. LineEdit *dir;
  84. Button *dir_prev;
  85. Button *dir_next;
  86. Button *dir_up;
  87. HBoxContainer *drives_container;
  88. HBoxContainer *shortcuts_container;
  89. OptionButton *drives;
  90. ItemList *item_list;
  91. PopupMenu *item_menu;
  92. TextureRect *preview;
  93. VBoxContainer *preview_vb;
  94. HSplitContainer *list_hb;
  95. HBoxContainer *file_box;
  96. LineEdit *file;
  97. OptionButton *filter;
  98. AcceptDialog *mkdirerr;
  99. DirAccess *dir_access;
  100. ConfirmationDialog *confirm_save;
  101. DependencyRemoveDialog *remove_dialog;
  102. Button *mode_thumbnails;
  103. Button *mode_list;
  104. Button *refresh;
  105. Button *favorite;
  106. Button *show_hidden;
  107. Button *fav_up;
  108. Button *fav_down;
  109. ItemList *favorites;
  110. ItemList *recent;
  111. Vector<String> local_history;
  112. int local_history_pos;
  113. void _push_history();
  114. Vector<String> filters;
  115. bool preview_waiting;
  116. int preview_wheel_index;
  117. float preview_wheel_timeout;
  118. static bool default_show_hidden_files;
  119. static DisplayMode default_display_mode;
  120. bool show_hidden_files;
  121. DisplayMode display_mode;
  122. bool disable_overwrite_warning;
  123. bool invalidated;
  124. void update_dir();
  125. void update_file_name();
  126. void update_file_list();
  127. void update_filters();
  128. void _update_favorites();
  129. void _favorite_pressed();
  130. void _favorite_selected(int p_idx);
  131. void _favorite_move_up();
  132. void _favorite_move_down();
  133. void _recent_selected(int p_idx);
  134. void _item_selected(int p_item);
  135. void _multi_selected(int p_item, bool p_selected);
  136. void _items_clear_selection();
  137. void _item_dc_selected(int p_item);
  138. void _item_list_item_rmb_selected(int p_item, const Vector2 &p_pos);
  139. void _item_list_rmb_clicked(const Vector2 &p_pos);
  140. void _item_menu_id_pressed(int p_option);
  141. void _select_drive(int p_idx);
  142. void _dir_entered(String p_dir);
  143. void _file_entered(const String &p_file);
  144. void _action_pressed();
  145. void _save_confirm_pressed();
  146. void _cancel_pressed();
  147. void _filter_selected(int);
  148. void _make_dir();
  149. void _make_dir_confirm();
  150. void _delete_items();
  151. void _update_drives();
  152. void _go_up();
  153. void _go_back();
  154. void _go_forward();
  155. virtual void _post_popup() override;
  156. void _save_to_recent();
  157. //callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load
  158. void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  159. void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  160. void _request_single_thumbnail(const String &p_path);
  161. void _unhandled_input(const Ref<InputEvent> &p_event);
  162. bool _is_open_should_be_disabled();
  163. protected:
  164. void _notification(int p_what);
  165. static void _bind_methods();
  166. //bind helpers
  167. public:
  168. void popup_file_dialog();
  169. void clear_filters();
  170. void add_filter(const String &p_filter);
  171. void set_enable_multiple_selection(bool p_enable);
  172. Vector<String> get_selected_files() const;
  173. String get_current_dir() const;
  174. String get_current_file() const;
  175. String get_current_path() const;
  176. void set_current_dir(const String &p_dir);
  177. void set_current_file(const String &p_file);
  178. void set_current_path(const String &p_path);
  179. void set_display_mode(DisplayMode p_mode);
  180. DisplayMode get_display_mode() const;
  181. void set_file_mode(FileMode p_mode);
  182. FileMode get_file_mode() const;
  183. VBoxContainer *get_vbox();
  184. LineEdit *get_line_edit() { return file; }
  185. void set_access(Access p_access);
  186. Access get_access() const;
  187. void set_show_hidden_files(bool p_show);
  188. bool is_showing_hidden_files() const;
  189. static void set_default_show_hidden_files(bool p_show);
  190. static void set_default_display_mode(DisplayMode p_mode);
  191. void invalidate();
  192. void set_disable_overwrite_warning(bool p_disable);
  193. bool is_overwrite_warning_disabled() const;
  194. EditorFileDialog();
  195. ~EditorFileDialog();
  196. };
  197. VARIANT_ENUM_CAST(EditorFileDialog::FileMode);
  198. VARIANT_ENUM_CAST(EditorFileDialog::Access);
  199. VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
  200. #endif // EDITORFILEDIALOG_H