editor_reimport_dialog.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*************************************************************************/
  2. /* editor_reimport_dialog.cpp */
  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. #include "editor_reimport_dialog.h"
  30. #include "editor_file_system.h"
  31. #include "editor_node.h"
  32. void EditorReImportDialog::popup_reimport() {
  33. if (EditorFileSystem::get_singleton()->is_scanning()) {
  34. error->set_text("Please wait for scan to complete");
  35. error->popup_centered(Size2(250,100));
  36. return;
  37. }
  38. tree->clear();
  39. items.clear();
  40. List<String> ril;
  41. EditorFileSystem::get_singleton()->get_changed_sources(&ril);
  42. scene_must_save=false;
  43. TreeItem *root = tree->create_item();
  44. for(List<String>::Element *E=ril.front();E;E=E->next()) {
  45. TreeItem *item = tree->create_item(root);
  46. item->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
  47. item->set_metadata(0,E->get());
  48. item->set_text(0,E->get().replace_first("res://",""));
  49. item->set_tooltip(0,E->get());
  50. item->set_checked(0,true);
  51. item->set_editable(0,true);
  52. items.push_back(item);
  53. String name = E->get();
  54. if (EditorFileSystem::get_singleton()->get_file_type(name)=="PackedScene" && EditorNode::get_singleton()->is_scene_in_use(name)) {
  55. scene_must_save=true;
  56. }
  57. }
  58. if (scene_must_save) {
  59. if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->get_filename()=="") {
  60. error->set_text("Current scene must be saved to re-import.");
  61. error->popup_centered(Size2(250,100));
  62. get_ok()->set_text("Re-Import");
  63. get_ok()->set_disabled(true);
  64. return;
  65. }
  66. get_ok()->set_disabled(false);
  67. get_ok()->set_text("Save & Re-Import");
  68. } else {
  69. get_ok()->set_text("Re-Import");
  70. get_ok()->set_disabled(false);
  71. }
  72. popup_centered(Size2(600,400));
  73. }
  74. void EditorReImportDialog::ok_pressed() {
  75. if (EditorFileSystem::get_singleton()->is_scanning()) {
  76. error->set_text("Please wait for scan to complete");
  77. error->popup_centered(Size2(250,100));
  78. return;
  79. }
  80. EditorProgress ep("reimport","Re-Importing",items.size());
  81. String reload_fname;
  82. if (scene_must_save && EditorNode::get_singleton()->get_edited_scene()) {
  83. reload_fname = EditorNode::get_singleton()->get_edited_scene()->get_filename();
  84. EditorNode::get_singleton()->save_scene(reload_fname);
  85. EditorNode::get_singleton()->clear_scene();
  86. }
  87. for(int i=0;i<items.size();i++) {
  88. String it = items[i]->get_metadata(0);
  89. ep.step(items[i]->get_text(0),i);
  90. print_line("reload import from: "+it);
  91. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(it);
  92. ERR_CONTINUE(rimd.is_null());
  93. String editor = rimd->get_editor();
  94. Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor);
  95. ERR_CONTINUE(eip.is_null());
  96. Error err = eip->import(it,rimd);
  97. if (err!=OK) {
  98. EditorNode::add_io_error("Error Importing:\n "+it);
  99. }
  100. }
  101. if (reload_fname!="") {
  102. EditorNode::get_singleton()->load_scene(reload_fname);
  103. }
  104. EditorFileSystem::get_singleton()->scan_sources();
  105. }
  106. EditorReImportDialog::EditorReImportDialog() {
  107. tree = memnew( Tree );
  108. add_child(tree);
  109. tree->set_hide_root(true);
  110. set_child_rect(tree);
  111. set_title("Re-Import Changed Resources");
  112. error = memnew( AcceptDialog);
  113. add_child(error);
  114. scene_must_save=false;
  115. }