editor_file_dialog.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/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. /**
  44. @author Juan Linietsky <reduzio@gmail.com>
  45. */
  46. class EditorFileDialog : public ConfirmationDialog {
  47. GDCLASS(EditorFileDialog, ConfirmationDialog);
  48. public:
  49. enum DisplayMode {
  50. DISPLAY_THUMBNAILS,
  51. DISPLAY_LIST
  52. };
  53. enum Access {
  54. ACCESS_RESOURCES,
  55. ACCESS_USERDATA,
  56. ACCESS_FILESYSTEM
  57. };
  58. enum Mode {
  59. MODE_OPEN_FILE,
  60. MODE_OPEN_FILES,
  61. MODE_OPEN_DIR,
  62. MODE_OPEN_ANY,
  63. MODE_SAVE_FILE
  64. };
  65. typedef Ref<Texture> (*GetIconFunc)(const String &);
  66. typedef void (*RegisterFunc)(EditorFileDialog *);
  67. static GetIconFunc get_icon_func;
  68. static GetIconFunc get_large_icon_func;
  69. static RegisterFunc register_func;
  70. static RegisterFunc unregister_func;
  71. private:
  72. enum ItemMenu {
  73. ITEM_MENU_COPY_PATH,
  74. ITEM_MENU_DELETE,
  75. ITEM_MENU_REFRESH,
  76. ITEM_MENU_NEW_FOLDER,
  77. ITEM_MENU_SHOW_IN_EXPLORER
  78. };
  79. ConfirmationDialog *makedialog;
  80. LineEdit *makedirname;
  81. Button *makedir;
  82. Access access;
  83. //Button *action;
  84. VBoxContainer *vbox;
  85. Mode mode;
  86. bool can_create_dir;
  87. LineEdit *dir;
  88. ToolButton *dir_prev;
  89. ToolButton *dir_next;
  90. ToolButton *dir_up;
  91. OptionButton *drives;
  92. ItemList *item_list;
  93. PopupMenu *item_menu;
  94. TextureRect *preview;
  95. VBoxContainer *preview_vb;
  96. HSplitContainer *list_hb;
  97. LineEdit *file;
  98. AcceptDialog *mkdirerr;
  99. AcceptDialog *exterr;
  100. OptionButton *filter;
  101. DirAccess *dir_access;
  102. ConfirmationDialog *confirm_save;
  103. DependencyRemoveDialog *remove_dialog;
  104. ToolButton *mode_thumbnails;
  105. ToolButton *mode_list;
  106. ToolButton *refresh;
  107. ToolButton *favorite;
  108. ToolButton *fav_up;
  109. ToolButton *fav_down;
  110. ToolButton *fav_rm;
  111. ItemList *favorites;
  112. ItemList *recent;
  113. Vector<String> local_history;
  114. int local_history_pos;
  115. void _push_history();
  116. Vector<String> filters;
  117. bool preview_waiting;
  118. int preview_wheel_index;
  119. float preview_wheel_timeout;
  120. static bool default_show_hidden_files;
  121. static DisplayMode default_display_mode;
  122. bool show_hidden_files;
  123. DisplayMode display_mode;
  124. bool disable_overwrite_warning;
  125. bool invalidated;
  126. void update_dir();
  127. void update_file_list();
  128. void update_filters();
  129. void _update_favorites();
  130. void _favorite_toggled(bool p_toggle);
  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();
  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 // EDITORFILEDIALOG_H