file_dialog.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*************************************************************************/
  2. /* file_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef FILE_DIALOG_H
  30. #define FILE_DIALOG_H
  31. #include "scene/gui/dialogs.h"
  32. #include "scene/gui/tree.h"
  33. #include "scene/gui/line_edit.h"
  34. #include "scene/gui/option_button.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/tool_button.h"
  37. #include "os/dir_access.h"
  38. #include "box_container.h"
  39. /**
  40. @author Juan Linietsky <[email protected]>
  41. */
  42. class FileDialog : public ConfirmationDialog {
  43. OBJ_TYPE( 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_SAVE_FILE,
  55. };
  56. typedef Ref<Texture> (*GetIconFunc)(const String&);
  57. typedef void (*RegisterFunc)(FileDialog*);
  58. static GetIconFunc get_icon_func;
  59. static GetIconFunc get_large_icon_func;
  60. static RegisterFunc register_func;
  61. static RegisterFunc unregister_func;
  62. private:
  63. ConfirmationDialog *makedialog;
  64. LineEdit *makedirname;
  65. Button *makedir;
  66. Access access;
  67. //Button *action;
  68. VBoxContainer *vbox;
  69. Mode mode;
  70. LineEdit *dir;
  71. OptionButton *drives;
  72. Tree *tree;
  73. LineEdit *file;
  74. AcceptDialog *mkdirerr;
  75. AcceptDialog *exterr;
  76. OptionButton *filter;
  77. DirAccess *dir_access;
  78. ConfirmationDialog *confirm_save;
  79. ToolButton *refresh;
  80. Vector<String> filters;
  81. static bool default_show_hidden_files;
  82. bool show_hidden_files;
  83. bool invalidated;
  84. void update_dir();
  85. void update_file_list();
  86. void update_filters();
  87. void _tree_selected();
  88. void _select_drive(int p_idx);
  89. void _tree_dc_selected();
  90. void _dir_entered(String p_dir);
  91. void _file_entered(const String& p_file);
  92. void _action_pressed();
  93. void _save_confirm_pressed();
  94. void _cancel_pressed();
  95. void _filter_selected(int);
  96. void _make_dir();
  97. void _make_dir_confirm();
  98. void _update_drives();
  99. virtual void _post_popup();
  100. protected:
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. //bind helpers
  104. public:
  105. void clear_filters();
  106. void add_filter(const String& p_filter);
  107. void set_enable_multiple_selection(bool p_enable);
  108. Vector<String> get_selected_files() const;
  109. String get_current_dir() const;
  110. String get_current_file() const;
  111. String get_current_path() const;
  112. void set_current_dir(const String& p_dir);
  113. void set_current_file(const String& p_file);
  114. void set_current_path(const String& p_path);
  115. void set_mode(Mode p_mode);
  116. Mode get_mode() const;
  117. VBoxContainer *get_vbox();
  118. LineEdit *get_line_edit() { return file; }
  119. void set_access(Access p_access);
  120. Access get_access() const;
  121. void set_show_hidden_files(bool p_show);
  122. bool is_showing_hidden_files() const;
  123. static void set_default_show_hidden_files(bool p_show);
  124. void invalidate();
  125. FileDialog();
  126. ~FileDialog();
  127. };
  128. class LineEditFileChooser : public HBoxContainer {
  129. OBJ_TYPE( LineEditFileChooser, HBoxContainer );
  130. Button *button;
  131. LineEdit *line_edit;
  132. FileDialog *dialog;
  133. void _chosen(const String& p_text);
  134. void _browse();
  135. protected:
  136. static void _bind_methods();
  137. public:
  138. Button *get_button() { return button; }
  139. LineEdit *get_line_edit() { return line_edit; }
  140. FileDialog *get_file_dialog() { return dialog; }
  141. LineEditFileChooser();
  142. };
  143. VARIANT_ENUM_CAST( FileDialog::Mode );
  144. VARIANT_ENUM_CAST( FileDialog::Access );
  145. #endif