file_dialog.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*************************************************************************/
  2. /* 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 FILE_DIALOG_H
  31. #define FILE_DIALOG_H
  32. #include "box_container.h"
  33. #include "core/os/dir_access.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/line_edit.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/tool_button.h"
  38. #include "scene/gui/tree.h"
  39. /**
  40. @author Juan Linietsky <reduzio@gmail.com>
  41. */
  42. class FileDialog : public ConfirmationDialog {
  43. GDCLASS(FileDialog, ConfirmationDialog);
  44. public:
  45. enum Access {
  46. ACCESS_RESOURCES,
  47. ACCESS_USERDATA,
  48. ACCESS_FILESYSTEM
  49. };
  50. enum Mode {
  51. MODE_OPEN_FILE,
  52. MODE_OPEN_FILES,
  53. MODE_OPEN_DIR,
  54. MODE_OPEN_ANY,
  55. MODE_SAVE_FILE
  56. };
  57. typedef Ref<Texture> (*GetIconFunc)(const String &);
  58. typedef void (*RegisterFunc)(FileDialog *);
  59. static GetIconFunc get_icon_func;
  60. static GetIconFunc get_large_icon_func;
  61. static RegisterFunc register_func;
  62. static RegisterFunc unregister_func;
  63. private:
  64. ConfirmationDialog *makedialog;
  65. LineEdit *makedirname;
  66. Button *makedir;
  67. Access access;
  68. //Button *action;
  69. VBoxContainer *vbox;
  70. Mode mode;
  71. LineEdit *dir;
  72. OptionButton *drives;
  73. Tree *tree;
  74. LineEdit *file;
  75. AcceptDialog *mkdirerr;
  76. AcceptDialog *exterr;
  77. OptionButton *filter;
  78. DirAccess *dir_access;
  79. ConfirmationDialog *confirm_save;
  80. ToolButton *dir_up;
  81. ToolButton *refresh;
  82. Vector<String> filters;
  83. bool mode_overrides_title;
  84. static bool default_show_hidden_files;
  85. bool show_hidden_files;
  86. bool invalidated;
  87. void update_dir();
  88. void update_file_list();
  89. void update_filters();
  90. void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected);
  91. void _tree_selected();
  92. void _select_drive(int p_idx);
  93. void _tree_item_activated();
  94. void _dir_entered(String p_dir);
  95. void _file_entered(const String &p_file);
  96. void _action_pressed();
  97. void _save_confirm_pressed();
  98. void _cancel_pressed();
  99. void _filter_selected(int);
  100. void _make_dir();
  101. void _make_dir_confirm();
  102. void _go_up();
  103. void _update_drives();
  104. void _unhandled_input(const Ref<InputEvent> &p_event);
  105. bool _is_open_should_be_disabled();
  106. virtual void _post_popup();
  107. protected:
  108. void _notification(int p_what);
  109. static void _bind_methods();
  110. //bind helpers
  111. public:
  112. void clear_filters();
  113. void add_filter(const String &p_filter);
  114. void set_filters(const Vector<String> &p_filters);
  115. Vector<String> get_filters() const;
  116. void set_enable_multiple_selection(bool p_enable);
  117. Vector<String> get_selected_files() const;
  118. String get_current_dir() const;
  119. String get_current_file() const;
  120. String get_current_path() const;
  121. void set_current_dir(const String &p_dir);
  122. void set_current_file(const String &p_file);
  123. void set_current_path(const String &p_path);
  124. void set_mode_overrides_title(bool p_override);
  125. bool is_mode_overriding_title() const;
  126. void set_mode(Mode p_mode);
  127. Mode get_mode() const;
  128. VBoxContainer *get_vbox();
  129. LineEdit *get_line_edit() { return file; }
  130. void set_access(Access p_access);
  131. Access get_access() const;
  132. void set_show_hidden_files(bool p_show);
  133. bool is_showing_hidden_files() const;
  134. static void set_default_show_hidden_files(bool p_show);
  135. void invalidate();
  136. void deselect_items();
  137. FileDialog();
  138. ~FileDialog();
  139. };
  140. class LineEditFileChooser : public HBoxContainer {
  141. GDCLASS(LineEditFileChooser, HBoxContainer);
  142. Button *button;
  143. LineEdit *line_edit;
  144. FileDialog *dialog;
  145. void _chosen(const String &p_text);
  146. void _browse();
  147. protected:
  148. static void _bind_methods();
  149. public:
  150. Button *get_button() { return button; }
  151. LineEdit *get_line_edit() { return line_edit; }
  152. FileDialog *get_file_dialog() { return dialog; }
  153. LineEditFileChooser();
  154. };
  155. VARIANT_ENUM_CAST(FileDialog::Mode);
  156. VARIANT_ENUM_CAST(FileDialog::Access);
  157. #endif