file_dialog.h 5.4 KB

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