editor_file_dialog.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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/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/separator.h"
  39. #include "scene/gui/split_container.h"
  40. #include "scene/gui/texture_rect.h"
  41. #include "scene/gui/tool_button.h"
  42. class DependencyRemoveDialog;
  43. class EditorFileDialog : public ConfirmationDialog {
  44. GDCLASS(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. enum ItemMenu {
  70. ITEM_MENU_COPY_PATH,
  71. ITEM_MENU_DELETE,
  72. ITEM_MENU_REFRESH,
  73. ITEM_MENU_NEW_FOLDER,
  74. ITEM_MENU_SHOW_IN_EXPLORER
  75. };
  76. ConfirmationDialog *makedialog;
  77. LineEdit *makedirname;
  78. Button *makedir;
  79. Access access;
  80. //Button *action;
  81. VBoxContainer *vbox;
  82. Mode mode;
  83. bool can_create_dir;
  84. LineEdit *dir;
  85. ToolButton *dir_prev;
  86. ToolButton *dir_next;
  87. ToolButton *dir_up;
  88. HBoxContainer *drives_container;
  89. HBoxContainer *shortcuts_container;
  90. OptionButton *drives;
  91. ItemList *item_list;
  92. PopupMenu *item_menu;
  93. TextureRect *preview;
  94. VBoxContainer *preview_vb;
  95. HSplitContainer *list_hb;
  96. HBoxContainer *file_box;
  97. LineEdit *file;
  98. OptionButton *filter;
  99. AcceptDialog *mkdirerr;
  100. DirAccess *dir_access;
  101. ConfirmationDialog *confirm_save;
  102. DependencyRemoveDialog *remove_dialog;
  103. ToolButton *mode_thumbnails;
  104. ToolButton *mode_list;
  105. ToolButton *refresh;
  106. ToolButton *favorite;
  107. ToolButton *show_hidden;
  108. ToolButton *fav_up;
  109. ToolButton *fav_down;
  110. ItemList *favorites;
  111. ItemList *recent;
  112. Vector<String> local_history;
  113. int local_history_pos;
  114. void _push_history();
  115. Vector<String> filters;
  116. bool preview_waiting;
  117. int preview_wheel_index;
  118. float preview_wheel_timeout;
  119. static bool default_show_hidden_files;
  120. static DisplayMode default_display_mode;
  121. bool show_hidden_files;
  122. DisplayMode display_mode;
  123. bool disable_overwrite_warning;
  124. bool invalidated;
  125. void update_dir();
  126. void update_file_name();
  127. void update_file_list();
  128. void update_filters();
  129. void _update_favorites();
  130. void _favorite_pressed();
  131. void _favorite_selected(int p_idx);
  132. void _favorite_move_up();
  133. void _favorite_move_down();
  134. void _recent_selected(int p_idx);
  135. void _item_selected(int p_item);
  136. void _multi_selected(int p_item, bool p_selected);
  137. void _items_clear_selection();
  138. void _item_dc_selected(int p_item);
  139. void _item_list_item_rmb_selected(int p_item, const Vector2 &p_pos);
  140. void _item_list_rmb_clicked(const Vector2 &p_pos);
  141. void _item_menu_id_pressed(int p_option);
  142. void _select_drive(int p_idx);
  143. void _dir_entered(String p_dir);
  144. void _file_entered(const String &p_file);
  145. void _action_pressed();
  146. void _save_confirm_pressed();
  147. void _cancel_pressed();
  148. void _filter_selected(int);
  149. void _make_dir();
  150. void _make_dir_confirm();
  151. void _delete_items();
  152. void _update_drives(bool p_select = true);
  153. void _go_up();
  154. void _go_back();
  155. void _go_forward();
  156. virtual void _post_popup();
  157. void _save_to_recent();
  158. //callback function is callback(String p_path,Ref<Texture> preview,Variant udata) preview null if could not load
  159. void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  160. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  161. void _request_single_thumbnail(const String &p_path);
  162. void _unhandled_input(const Ref<InputEvent> &p_event);
  163. bool _is_open_should_be_disabled();
  164. protected:
  165. void _notification(int p_what);
  166. static void _bind_methods();
  167. //bind helpers
  168. public:
  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_mode(Mode p_mode);
  182. Mode get_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. class EditorLineEditFileChooser : public HBoxContainer {
  198. GDCLASS(EditorLineEditFileChooser, HBoxContainer);
  199. Button *button;
  200. LineEdit *line_edit;
  201. EditorFileDialog *dialog;
  202. void _chosen(const String &p_text);
  203. void _browse();
  204. protected:
  205. void _notification(int p_what);
  206. static void _bind_methods();
  207. public:
  208. Button *get_button() { return button; }
  209. LineEdit *get_line_edit() { return line_edit; }
  210. EditorFileDialog *get_file_dialog() { return dialog; }
  211. EditorLineEditFileChooser();
  212. };
  213. VARIANT_ENUM_CAST(EditorFileDialog::Mode);
  214. VARIANT_ENUM_CAST(EditorFileDialog::Access);
  215. VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
  216. #endif // EDITOR_FILE_DIALOG_H