file_dialog.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2014 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 "os/dir_access.h"
  37. #include "box_container.h"
  38. /**
  39. @author Juan Linietsky <[email protected]>
  40. */
  41. class FileDialog : public ConfirmationDialog {
  42. OBJ_TYPE( FileDialog, ConfirmationDialog );
  43. public:
  44. enum Access {
  45. ACCESS_RESOURCES,
  46. ACCESS_USERDATA,
  47. ACCESS_FILESYSTEM
  48. };
  49. enum Mode {
  50. MODE_OPEN_FILE,
  51. MODE_OPEN_FILES,
  52. MODE_OPEN_DIR,
  53. MODE_SAVE_FILE,
  54. };
  55. typedef Ref<Texture> (*GetIconFunc)(const String&);
  56. typedef void (*RegisterFunc)(FileDialog*);
  57. static GetIconFunc get_icon_func;
  58. static GetIconFunc get_large_icon_func;
  59. static RegisterFunc register_func;
  60. static RegisterFunc unregister_func;
  61. private:
  62. ConfirmationDialog *makedialog;
  63. LineEdit *makedirname;
  64. Button *makedir;
  65. Access access;
  66. //Button *action;
  67. VBoxContainer *vbox;
  68. Mode mode;
  69. LineEdit *dir;
  70. OptionButton *drives;
  71. Tree *tree;
  72. LineEdit *file;
  73. AcceptDialog *mkdirerr;
  74. AcceptDialog *exterr;
  75. OptionButton *filter;
  76. DirAccess *dir_access;
  77. ConfirmationDialog *confirm_save;
  78. Vector<String> filters;
  79. bool invalidated;
  80. void update_dir();
  81. void update_file_list();
  82. void update_filters();
  83. void _tree_selected();
  84. void _select_drive(int p_idx);
  85. void _tree_dc_selected();
  86. void _dir_entered(String p_dir);
  87. void _file_entered(const String& p_file);
  88. void _action_pressed();
  89. void _save_confirm_pressed();
  90. void _cancel_pressed();
  91. void _filter_selected(int);
  92. void _make_dir();
  93. void _make_dir_confirm();
  94. void _update_drives();
  95. virtual void _post_popup();
  96. protected:
  97. void _notification(int p_what);
  98. static void _bind_methods();
  99. //bind helpers
  100. public:
  101. void clear_filters();
  102. void add_filter(const String& p_filter);
  103. void set_enable_multiple_selection(bool p_enable);
  104. Vector<String> get_selected_files() const;
  105. String get_current_dir() const;
  106. String get_current_file() const;
  107. String get_current_path() const;
  108. void set_current_dir(const String& p_dir);
  109. void set_current_file(const String& p_file);
  110. void set_current_path(const String& p_path);
  111. void set_mode(Mode p_mode);
  112. Mode get_mode() const;
  113. VBoxContainer *get_vbox();
  114. LineEdit *get_line_edit() { return file; }
  115. void set_access(Access p_access);
  116. Access get_access() const;
  117. void invalidate();
  118. FileDialog();
  119. ~FileDialog();
  120. };
  121. class LineEditFileChooser : public HBoxContainer {
  122. OBJ_TYPE( LineEditFileChooser, HBoxContainer );
  123. Button *button;
  124. LineEdit *line_edit;
  125. FileDialog *dialog;
  126. void _chosen(const String& p_text);
  127. void _browse();
  128. protected:
  129. static void _bind_methods();
  130. public:
  131. Button *get_button() { return button; }
  132. LineEdit *get_line_edit() { return line_edit; }
  133. FileDialog *get_file_dialog() { return dialog; }
  134. LineEditFileChooser();
  135. };
  136. VARIANT_ENUM_CAST( FileDialog::Mode );
  137. VARIANT_ENUM_CAST( FileDialog::Access );
  138. #endif