dependency_editor.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**************************************************************************/
  2. /* dependency_editor.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 DEPENDENCY_EDITOR_H
  31. #define DEPENDENCY_EDITOR_H
  32. #include "scene/gui/dialogs.h"
  33. #include "scene/gui/item_list.h"
  34. #include "scene/gui/tab_container.h"
  35. #include "scene/gui/tree.h"
  36. class EditorFileDialog;
  37. class EditorFileSystemDirectory;
  38. class DependencyEditor : public AcceptDialog {
  39. GDCLASS(DependencyEditor, AcceptDialog);
  40. Tree *tree = nullptr;
  41. Button *fixdeps = nullptr;
  42. EditorFileDialog *search = nullptr;
  43. String replacing;
  44. String editing;
  45. List<String> missing;
  46. void _fix_and_find(EditorFileSystemDirectory *efsd, HashMap<String, HashMap<String, String>> &candidates);
  47. void _searched(const String &p_path);
  48. void _load_pressed(Object *p_item, int p_cell, int p_button, MouseButton p_mouse_button);
  49. void _fix_all();
  50. void _update_list();
  51. void _update_file();
  52. protected:
  53. static void _bind_methods();
  54. public:
  55. void edit(const String &p_path);
  56. DependencyEditor();
  57. };
  58. #ifdef MINGW_ENABLED
  59. #undef FILE_OPEN
  60. #endif
  61. class DependencyEditorOwners : public AcceptDialog {
  62. GDCLASS(DependencyEditorOwners, AcceptDialog);
  63. ItemList *owners = nullptr;
  64. PopupMenu *file_options = nullptr;
  65. String editing;
  66. void _fill_owners(EditorFileSystemDirectory *efsd);
  67. static void _bind_methods();
  68. void _list_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
  69. void _select_file(int p_idx);
  70. void _empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
  71. void _file_option(int p_option);
  72. private:
  73. enum FileMenu {
  74. FILE_OPEN
  75. };
  76. public:
  77. void show(const String &p_path);
  78. DependencyEditorOwners();
  79. };
  80. class DependencyRemoveDialog : public ConfirmationDialog {
  81. GDCLASS(DependencyRemoveDialog, ConfirmationDialog);
  82. Label *text = nullptr;
  83. Tree *owners = nullptr;
  84. HashMap<String, String> all_remove_files;
  85. Vector<String> dirs_to_delete;
  86. Vector<String> files_to_delete;
  87. struct RemovedDependency {
  88. String file;
  89. String file_type;
  90. String dependency;
  91. String dependency_folder;
  92. bool operator<(const RemovedDependency &p_other) const {
  93. if (dependency_folder.is_empty() != p_other.dependency_folder.is_empty()) {
  94. return p_other.dependency_folder.is_empty();
  95. } else {
  96. return dependency < p_other.dependency;
  97. }
  98. }
  99. };
  100. void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder);
  101. void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed);
  102. void _find_localization_remaps_of_removed_files(Vector<RemovedDependency> &p_removed);
  103. void _build_removed_dependency_tree(const Vector<RemovedDependency> &p_removed);
  104. void ok_pressed() override;
  105. static void _bind_methods();
  106. public:
  107. void show(const Vector<String> &p_folders, const Vector<String> &p_files);
  108. DependencyRemoveDialog();
  109. };
  110. class DependencyErrorDialog : public ConfirmationDialog {
  111. GDCLASS(DependencyErrorDialog, ConfirmationDialog);
  112. public:
  113. enum Mode {
  114. MODE_SCENE,
  115. MODE_RESOURCE,
  116. };
  117. private:
  118. String for_file;
  119. Mode mode;
  120. Button *fdep = nullptr;
  121. Label *text = nullptr;
  122. Tree *files = nullptr;
  123. void ok_pressed() override;
  124. void custom_action(const String &) override;
  125. public:
  126. void show(Mode p_mode, const String &p_for_file, const Vector<String> &report);
  127. DependencyErrorDialog();
  128. };
  129. class OrphanResourcesDialog : public ConfirmationDialog {
  130. GDCLASS(OrphanResourcesDialog, ConfirmationDialog);
  131. DependencyEditor *dep_edit = nullptr;
  132. Tree *files = nullptr;
  133. ConfirmationDialog *delete_confirm = nullptr;
  134. void ok_pressed() override;
  135. bool _fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent);
  136. List<String> paths;
  137. void _find_to_delete(TreeItem *p_item, List<String> &r_paths);
  138. void _delete_confirm();
  139. void _button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
  140. void refresh();
  141. static void _bind_methods();
  142. public:
  143. void show();
  144. OrphanResourcesDialog();
  145. };
  146. #endif // DEPENDENCY_EDITOR_H