dependency_editor.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #pragma once
  31. #include "scene/gui/box_container.h"
  32. #include "scene/gui/dialogs.h"
  33. #include "scene/gui/item_list.h"
  34. #include "scene/gui/tree.h"
  35. class EditorFileDialog;
  36. class EditorFileSystemDirectory;
  37. class DependencyEditor : public AcceptDialog {
  38. GDCLASS(DependencyEditor, AcceptDialog);
  39. Tree *tree = nullptr;
  40. Button *fixdeps = nullptr;
  41. EditorFileDialog *search = nullptr;
  42. String replacing;
  43. String editing;
  44. List<String> missing;
  45. void _fix_and_find(EditorFileSystemDirectory *efsd, HashMap<String, HashMap<String, String>> &candidates);
  46. void _searched(const String &p_path);
  47. void _load_pressed(Object *p_item, int p_cell, int p_button, MouseButton p_mouse_button);
  48. void _fix_all();
  49. void _update_list();
  50. void _update_file();
  51. public:
  52. void edit(const String &p_path);
  53. DependencyEditor();
  54. };
  55. class DependencyEditorOwners : public AcceptDialog {
  56. GDCLASS(DependencyEditorOwners, AcceptDialog);
  57. ItemList *owners = nullptr;
  58. PopupMenu *file_options = nullptr;
  59. String editing;
  60. void _fill_owners(EditorFileSystemDirectory *efsd);
  61. void _list_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
  62. void _select_file(int p_idx);
  63. void _empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
  64. void _file_option(int p_option);
  65. private:
  66. enum FileMenu {
  67. FILE_MENU_OPEN,
  68. };
  69. public:
  70. void show(const String &p_path);
  71. DependencyEditorOwners();
  72. };
  73. class DependencyRemoveDialog : public ConfirmationDialog {
  74. GDCLASS(DependencyRemoveDialog, ConfirmationDialog);
  75. Label *text = nullptr;
  76. Tree *owners = nullptr;
  77. VBoxContainer *vb_owners = nullptr;
  78. ItemList *files_to_delete_list = nullptr;
  79. HashMap<String, String> all_remove_files;
  80. Vector<String> dirs_to_delete;
  81. Vector<String> files_to_delete;
  82. struct RemovedDependency {
  83. String file;
  84. String file_type;
  85. String dependency;
  86. String dependency_folder;
  87. bool operator<(const RemovedDependency &p_other) const {
  88. if (dependency_folder.is_empty() != p_other.dependency_folder.is_empty()) {
  89. return p_other.dependency_folder.is_empty();
  90. } else {
  91. return dependency < p_other.dependency;
  92. }
  93. }
  94. };
  95. LocalVector<StringName> path_project_settings;
  96. void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder);
  97. void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed);
  98. void _find_localization_remaps_of_removed_files(Vector<RemovedDependency> &p_removed);
  99. void _build_removed_dependency_tree(const Vector<RemovedDependency> &p_removed);
  100. void _show_files_to_delete_list();
  101. void ok_pressed() override;
  102. static void _bind_methods();
  103. public:
  104. void show(const Vector<String> &p_folders, const Vector<String> &p_files);
  105. DependencyRemoveDialog();
  106. };
  107. class DependencyErrorDialog : public ConfirmationDialog {
  108. GDCLASS(DependencyErrorDialog, ConfirmationDialog);
  109. private:
  110. String for_file;
  111. Mode mode;
  112. Button *fdep = nullptr;
  113. Label *text = nullptr;
  114. Tree *files = nullptr;
  115. void ok_pressed() override;
  116. void custom_action(const String &) override;
  117. public:
  118. void show(const String &p_for_file, const Vector<String> &report);
  119. DependencyErrorDialog();
  120. };
  121. class OrphanResourcesDialog : public ConfirmationDialog {
  122. GDCLASS(OrphanResourcesDialog, ConfirmationDialog);
  123. DependencyEditor *dep_edit = nullptr;
  124. Tree *files = nullptr;
  125. ConfirmationDialog *delete_confirm = nullptr;
  126. void ok_pressed() override;
  127. bool _fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent);
  128. List<String> paths;
  129. void _find_to_delete(TreeItem *p_item, List<String> &r_paths);
  130. void _delete_confirm();
  131. void _button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
  132. void refresh();
  133. public:
  134. void show();
  135. OrphanResourcesDialog();
  136. };