editor_file_dialog.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /**************************************************************************/
  2. /* editor_file_dialog.h */
  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. #ifndef EDITOR_FILE_DIALOG_H
  31. #define EDITOR_FILE_DIALOG_H
  32. #include "core/io/dir_access.h"
  33. #include "scene/gui/dialogs.h"
  34. class DependencyRemoveDialog;
  35. class HSplitContainer;
  36. class ItemList;
  37. class OptionButton;
  38. class PopupMenu;
  39. class TextureRect;
  40. class EditorFileDialog : public ConfirmationDialog {
  41. GDCLASS(EditorFileDialog, ConfirmationDialog);
  42. public:
  43. enum DisplayMode {
  44. DISPLAY_THUMBNAILS,
  45. DISPLAY_LIST
  46. };
  47. enum Access {
  48. ACCESS_RESOURCES,
  49. ACCESS_USERDATA,
  50. ACCESS_FILESYSTEM
  51. };
  52. enum FileMode {
  53. FILE_MODE_OPEN_FILE,
  54. FILE_MODE_OPEN_FILES,
  55. FILE_MODE_OPEN_DIR,
  56. FILE_MODE_OPEN_ANY,
  57. FILE_MODE_SAVE_FILE
  58. };
  59. typedef Ref<Texture2D> (*GetIconFunc)(const String &);
  60. typedef void (*RegisterFunc)(EditorFileDialog *);
  61. static GetIconFunc get_icon_func;
  62. static GetIconFunc get_thumbnail_func;
  63. static RegisterFunc register_func;
  64. static RegisterFunc unregister_func;
  65. private:
  66. enum ItemMenu {
  67. ITEM_MENU_COPY_PATH,
  68. ITEM_MENU_DELETE,
  69. ITEM_MENU_REFRESH,
  70. ITEM_MENU_NEW_FOLDER,
  71. ITEM_MENU_SHOW_IN_EXPLORER
  72. };
  73. ConfirmationDialog *makedialog = nullptr;
  74. LineEdit *makedirname = nullptr;
  75. Button *makedir = nullptr;
  76. Access access = ACCESS_RESOURCES;
  77. VBoxContainer *vbox = nullptr;
  78. FileMode mode = FILE_MODE_SAVE_FILE;
  79. bool can_create_dir = false;
  80. LineEdit *dir = nullptr;
  81. Button *dir_prev = nullptr;
  82. Button *dir_next = nullptr;
  83. Button *dir_up = nullptr;
  84. HBoxContainer *drives_container = nullptr;
  85. HBoxContainer *shortcuts_container = nullptr;
  86. OptionButton *drives = nullptr;
  87. ItemList *item_list = nullptr;
  88. PopupMenu *item_menu = nullptr;
  89. TextureRect *preview = nullptr;
  90. VBoxContainer *preview_vb = nullptr;
  91. HSplitContainer *list_hb = nullptr;
  92. HBoxContainer *file_box = nullptr;
  93. LineEdit *file = nullptr;
  94. OptionButton *filter = nullptr;
  95. AcceptDialog *error_dialog = nullptr;
  96. Ref<DirAccess> dir_access;
  97. ConfirmationDialog *confirm_save = nullptr;
  98. DependencyRemoveDialog *dep_remove_dialog = nullptr;
  99. ConfirmationDialog *global_remove_dialog = nullptr;
  100. Button *mode_thumbnails = nullptr;
  101. Button *mode_list = nullptr;
  102. Button *refresh = nullptr;
  103. Button *favorite = nullptr;
  104. Button *show_hidden = nullptr;
  105. Button *fav_up = nullptr;
  106. Button *fav_down = nullptr;
  107. ItemList *favorites = nullptr;
  108. ItemList *recent = nullptr;
  109. Vector<String> local_history;
  110. int local_history_pos = 0;
  111. void _push_history();
  112. Vector<String> filters;
  113. bool previews_enabled = true;
  114. bool preview_waiting = false;
  115. int preview_wheel_index = 0;
  116. float preview_wheel_timeout = 0.0f;
  117. static bool default_show_hidden_files;
  118. static DisplayMode default_display_mode;
  119. bool show_hidden_files;
  120. DisplayMode display_mode;
  121. bool disable_overwrite_warning = false;
  122. bool is_invalidating = false;
  123. struct ThemeCache {
  124. Ref<Texture2D> parent_folder;
  125. Ref<Texture2D> forward_folder;
  126. Ref<Texture2D> back_folder;
  127. Ref<Texture2D> reload;
  128. Ref<Texture2D> toggle_hidden;
  129. Ref<Texture2D> favorite;
  130. Ref<Texture2D> mode_thumbnails;
  131. Ref<Texture2D> mode_list;
  132. Ref<Texture2D> favorites_up;
  133. Ref<Texture2D> favorites_down;
  134. Ref<Texture2D> folder;
  135. Color folder_icon_color;
  136. Ref<Texture2D> action_copy;
  137. Ref<Texture2D> action_delete;
  138. Ref<Texture2D> filesystem;
  139. Ref<Texture2D> folder_medium_thumbnail;
  140. Ref<Texture2D> file_medium_thumbnail;
  141. Ref<Texture2D> folder_big_thumbnail;
  142. Ref<Texture2D> file_big_thumbnail;
  143. Ref<Texture2D> progress[8]{};
  144. } theme_cache;
  145. void update_dir();
  146. void update_file_name();
  147. void update_file_list();
  148. void update_filters();
  149. void _focus_file_text();
  150. void _update_favorites();
  151. void _favorite_pressed();
  152. void _favorite_selected(int p_idx);
  153. void _favorite_move_up();
  154. void _favorite_move_down();
  155. void _update_recent();
  156. void _recent_selected(int p_idx);
  157. void _item_selected(int p_item);
  158. void _multi_selected(int p_item, bool p_selected);
  159. void _items_clear_selection(const Vector2 &p_pos, MouseButton p_mouse_button_index);
  160. void _item_dc_selected(int p_item);
  161. void _item_list_item_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
  162. void _item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
  163. void _item_menu_id_pressed(int p_option);
  164. void _select_drive(int p_idx);
  165. void _dir_submitted(String p_dir);
  166. void _action_pressed();
  167. void _save_confirm_pressed();
  168. void _cancel_pressed();
  169. void _filter_selected(int);
  170. void _make_dir();
  171. void _make_dir_confirm();
  172. void _delete_items();
  173. void _delete_files_global();
  174. void _update_drives(bool p_select = true);
  175. void _update_icons();
  176. void _go_up();
  177. void _go_back();
  178. void _go_forward();
  179. void _invalidate();
  180. virtual void _post_popup() override;
  181. void _save_to_recent();
  182. // Callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load.
  183. void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  184. void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  185. void _request_single_thumbnail(const String &p_path);
  186. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  187. bool _is_open_should_be_disabled();
  188. protected:
  189. virtual void _update_theme_item_cache() override;
  190. void _notification(int p_what);
  191. static void _bind_methods();
  192. public:
  193. // Public for use with callable_mp.
  194. void _file_submitted(const String &p_file);
  195. void popup_file_dialog();
  196. void clear_filters();
  197. void add_filter(const String &p_filter, const String &p_description = "");
  198. void set_filters(const Vector<String> &p_filters);
  199. Vector<String> get_filters() const;
  200. void set_enable_multiple_selection(bool p_enable);
  201. Vector<String> get_selected_files() const;
  202. String get_current_dir() const;
  203. String get_current_file() const;
  204. String get_current_path() const;
  205. void set_current_dir(const String &p_dir);
  206. void set_current_file(const String &p_file);
  207. void set_current_path(const String &p_path);
  208. void set_display_mode(DisplayMode p_mode);
  209. DisplayMode get_display_mode() const;
  210. void set_file_mode(FileMode p_mode);
  211. FileMode get_file_mode() const;
  212. VBoxContainer *get_vbox();
  213. LineEdit *get_line_edit() { return file; }
  214. void set_access(Access p_access);
  215. Access get_access() const;
  216. static void set_default_show_hidden_files(bool p_show);
  217. static void set_default_display_mode(DisplayMode p_mode);
  218. void set_show_hidden_files(bool p_show);
  219. bool is_showing_hidden_files() const;
  220. void invalidate();
  221. void set_disable_overwrite_warning(bool p_disable);
  222. bool is_overwrite_warning_disabled() const;
  223. void set_previews_enabled(bool p_enabled);
  224. bool are_previews_enabled();
  225. EditorFileDialog();
  226. ~EditorFileDialog();
  227. };
  228. VARIANT_ENUM_CAST(EditorFileDialog::FileMode);
  229. VARIANT_ENUM_CAST(EditorFileDialog::Access);
  230. VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
  231. #endif // EDITOR_FILE_DIALOG_H