editor_data.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /**************************************************************************/
  2. /* editor_data.cpp */
  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. #include "editor_data.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/extension/gdextension_manager.h"
  33. #include "core/io/file_access.h"
  34. #include "core/io/image_loader.h"
  35. #include "core/io/resource_loader.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_plugin.h"
  38. #include "editor/editor_scale.h"
  39. #include "editor/editor_undo_redo_manager.h"
  40. #include "editor/multi_node_edit.h"
  41. #include "editor/plugins/script_editor_plugin.h"
  42. #include "scene/resources/packed_scene.h"
  43. void EditorSelectionHistory::cleanup_history() {
  44. for (int i = 0; i < history.size(); i++) {
  45. bool fail = false;
  46. for (int j = 0; j < history[i].path.size(); j++) {
  47. if (!history[i].path[j].ref.is_null()) {
  48. // If the node is a MultiNodeEdit node, examine it and see if anything is missing from it.
  49. Ref<MultiNodeEdit> multi_node_edit = history[i].path[j].ref;
  50. if (multi_node_edit.is_valid()) {
  51. Node *root = EditorNode::get_singleton()->get_edited_scene();
  52. if (root) {
  53. for (int k = 0; k < multi_node_edit->get_node_count(); k++) {
  54. NodePath np = multi_node_edit->get_node(k);
  55. Node *multi_node_selected_node = root->get_node_or_null(np);
  56. if (!multi_node_selected_node) {
  57. fail = true;
  58. break;
  59. }
  60. }
  61. } else {
  62. fail = true;
  63. }
  64. } else {
  65. // Reference is not null - object still alive.
  66. continue;
  67. }
  68. }
  69. if (!fail) {
  70. Object *obj = ObjectDB::get_instance(history[i].path[j].object);
  71. if (obj) {
  72. Node *n = Object::cast_to<Node>(obj);
  73. if (n && n->is_inside_tree()) {
  74. // Node valid and inside tree - object still alive.
  75. continue;
  76. }
  77. if (!n) {
  78. // Node possibly still alive.
  79. continue;
  80. }
  81. } // Else: object not valid - not alive.
  82. fail = true;
  83. }
  84. if (fail) {
  85. break;
  86. }
  87. }
  88. if (fail) {
  89. history.remove_at(i);
  90. i--;
  91. }
  92. }
  93. if (current_elem_idx >= history.size()) {
  94. current_elem_idx = history.size() - 1;
  95. }
  96. }
  97. void EditorSelectionHistory::add_object(ObjectID p_object, const String &p_property, bool p_inspector_only) {
  98. Object *obj = ObjectDB::get_instance(p_object);
  99. ERR_FAIL_COND(!obj);
  100. RefCounted *r = Object::cast_to<RefCounted>(obj);
  101. _Object o;
  102. if (r) {
  103. o.ref = Ref<RefCounted>(r);
  104. }
  105. o.object = p_object;
  106. o.property = p_property;
  107. o.inspector_only = p_inspector_only;
  108. bool has_prev = current_elem_idx >= 0 && current_elem_idx < history.size();
  109. if (has_prev) {
  110. history.resize(current_elem_idx + 1); // Clip history to next.
  111. }
  112. HistoryElement h;
  113. if (!p_property.is_empty() && has_prev) {
  114. // Add a sub property.
  115. HistoryElement &prev_element = history.write[current_elem_idx];
  116. h = prev_element;
  117. h.path.resize(h.level + 1);
  118. h.path.push_back(o);
  119. h.level++;
  120. } else {
  121. // Create a new history item.
  122. h.path.push_back(o);
  123. h.level = 0;
  124. }
  125. history.push_back(h);
  126. current_elem_idx++;
  127. }
  128. int EditorSelectionHistory::get_history_len() {
  129. return history.size();
  130. }
  131. int EditorSelectionHistory::get_history_pos() {
  132. return current_elem_idx;
  133. }
  134. ObjectID EditorSelectionHistory::get_history_obj(int p_obj) const {
  135. ERR_FAIL_INDEX_V(p_obj, history.size(), ObjectID());
  136. ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), ObjectID());
  137. return history[p_obj].path[history[p_obj].level].object;
  138. }
  139. bool EditorSelectionHistory::is_at_beginning() const {
  140. return current_elem_idx <= 0;
  141. }
  142. bool EditorSelectionHistory::is_at_end() const {
  143. return ((current_elem_idx + 1) >= history.size());
  144. }
  145. bool EditorSelectionHistory::next() {
  146. cleanup_history();
  147. if ((current_elem_idx + 1) < history.size()) {
  148. current_elem_idx++;
  149. } else {
  150. return false;
  151. }
  152. return true;
  153. }
  154. bool EditorSelectionHistory::previous() {
  155. cleanup_history();
  156. if (current_elem_idx > 0) {
  157. current_elem_idx--;
  158. } else {
  159. return false;
  160. }
  161. return true;
  162. }
  163. bool EditorSelectionHistory::is_current_inspector_only() const {
  164. if (current_elem_idx < 0 || current_elem_idx >= history.size()) {
  165. return false;
  166. }
  167. const HistoryElement &h = history[current_elem_idx];
  168. return h.path[h.level].inspector_only;
  169. }
  170. ObjectID EditorSelectionHistory::get_current() {
  171. if (current_elem_idx < 0 || current_elem_idx >= history.size()) {
  172. return ObjectID();
  173. }
  174. Object *obj = ObjectDB::get_instance(get_history_obj(current_elem_idx));
  175. return obj ? obj->get_instance_id() : ObjectID();
  176. }
  177. int EditorSelectionHistory::get_path_size() const {
  178. if (current_elem_idx < 0 || current_elem_idx >= history.size()) {
  179. return 0;
  180. }
  181. return history[current_elem_idx].path.size();
  182. }
  183. ObjectID EditorSelectionHistory::get_path_object(int p_index) const {
  184. if (current_elem_idx < 0 || current_elem_idx >= history.size()) {
  185. return ObjectID();
  186. }
  187. ERR_FAIL_INDEX_V(p_index, history[current_elem_idx].path.size(), ObjectID());
  188. Object *obj = ObjectDB::get_instance(history[current_elem_idx].path[p_index].object);
  189. return obj ? obj->get_instance_id() : ObjectID();
  190. }
  191. String EditorSelectionHistory::get_path_property(int p_index) const {
  192. if (current_elem_idx < 0 || current_elem_idx >= history.size()) {
  193. return "";
  194. }
  195. ERR_FAIL_INDEX_V(p_index, history[current_elem_idx].path.size(), "");
  196. return history[current_elem_idx].path[p_index].property;
  197. }
  198. void EditorSelectionHistory::clear() {
  199. history.clear();
  200. current_elem_idx = -1;
  201. }
  202. EditorSelectionHistory::EditorSelectionHistory() {
  203. current_elem_idx = -1;
  204. }
  205. ////////////////////////////////////////////////////////////
  206. EditorPlugin *EditorData::get_editor(Object *p_object) {
  207. // We need to iterate backwards so that we can check user-created plugins first.
  208. // Otherwise, it would not be possible for plugins to handle CanvasItem and Spatial nodes.
  209. for (int i = editor_plugins.size() - 1; i > -1; i--) {
  210. if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
  211. return editor_plugins[i];
  212. }
  213. }
  214. return nullptr;
  215. }
  216. Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) {
  217. Vector<EditorPlugin *> sub_plugins;
  218. for (int i = editor_plugins.size() - 1; i > -1; i--) {
  219. if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
  220. sub_plugins.push_back(editor_plugins[i]);
  221. }
  222. }
  223. return sub_plugins;
  224. }
  225. EditorPlugin *EditorData::get_editor(String p_name) {
  226. for (int i = editor_plugins.size() - 1; i > -1; i--) {
  227. if (editor_plugins[i]->get_name() == p_name) {
  228. return editor_plugins[i];
  229. }
  230. }
  231. return nullptr;
  232. }
  233. void EditorData::copy_object_params(Object *p_object) {
  234. clipboard.clear();
  235. List<PropertyInfo> pinfo;
  236. p_object->get_property_list(&pinfo);
  237. for (const PropertyInfo &E : pinfo) {
  238. if (!(E.usage & PROPERTY_USAGE_EDITOR) || E.name == "script" || E.name == "scripts") {
  239. continue;
  240. }
  241. PropertyData pd;
  242. pd.name = E.name;
  243. pd.value = p_object->get(pd.name);
  244. clipboard.push_back(pd);
  245. }
  246. }
  247. void EditorData::get_editor_breakpoints(List<String> *p_breakpoints) {
  248. for (int i = 0; i < editor_plugins.size(); i++) {
  249. editor_plugins[i]->get_breakpoints(p_breakpoints);
  250. }
  251. }
  252. Dictionary EditorData::get_editor_states() const {
  253. Dictionary metadata;
  254. for (int i = 0; i < editor_plugins.size(); i++) {
  255. Dictionary state = editor_plugins[i]->get_state();
  256. if (state.is_empty()) {
  257. continue;
  258. }
  259. metadata[editor_plugins[i]->get_name()] = state;
  260. }
  261. return metadata;
  262. }
  263. Dictionary EditorData::get_scene_editor_states(int p_idx) const {
  264. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Dictionary());
  265. EditedScene es = edited_scene[p_idx];
  266. return es.editor_states;
  267. }
  268. void EditorData::set_editor_states(const Dictionary &p_states) {
  269. if (p_states.is_empty()) {
  270. for (EditorPlugin *ep : editor_plugins) {
  271. ep->clear();
  272. }
  273. return;
  274. }
  275. List<Variant> keys;
  276. p_states.get_key_list(&keys);
  277. List<Variant>::Element *E = keys.front();
  278. for (; E; E = E->next()) {
  279. String name = E->get();
  280. int idx = -1;
  281. for (int i = 0; i < editor_plugins.size(); i++) {
  282. if (editor_plugins[i]->get_name() == name) {
  283. idx = i;
  284. break;
  285. }
  286. }
  287. if (idx == -1) {
  288. continue;
  289. }
  290. editor_plugins[idx]->set_state(p_states[name]);
  291. }
  292. }
  293. void EditorData::notify_edited_scene_changed() {
  294. for (int i = 0; i < editor_plugins.size(); i++) {
  295. editor_plugins[i]->edited_scene_changed();
  296. editor_plugins[i]->notify_scene_changed(get_edited_scene_root());
  297. }
  298. }
  299. void EditorData::notify_resource_saved(const Ref<Resource> &p_resource) {
  300. for (int i = 0; i < editor_plugins.size(); i++) {
  301. editor_plugins[i]->notify_resource_saved(p_resource);
  302. }
  303. }
  304. void EditorData::clear_editor_states() {
  305. for (int i = 0; i < editor_plugins.size(); i++) {
  306. editor_plugins[i]->clear();
  307. }
  308. }
  309. void EditorData::save_editor_external_data() {
  310. for (int i = 0; i < editor_plugins.size(); i++) {
  311. editor_plugins[i]->save_external_data();
  312. }
  313. }
  314. void EditorData::apply_changes_in_editors() {
  315. for (int i = 0; i < editor_plugins.size(); i++) {
  316. editor_plugins[i]->apply_changes();
  317. }
  318. }
  319. void EditorData::paste_object_params(Object *p_object) {
  320. ERR_FAIL_NULL(p_object);
  321. undo_redo_manager->create_action(TTR("Paste Params"));
  322. for (const PropertyData &E : clipboard) {
  323. String name = E.name;
  324. undo_redo_manager->add_do_property(p_object, name, E.value);
  325. undo_redo_manager->add_undo_property(p_object, name, p_object->get(name));
  326. }
  327. undo_redo_manager->commit_action();
  328. }
  329. bool EditorData::call_build() {
  330. bool result = true;
  331. for (int i = 0; i < editor_plugins.size() && result; i++) {
  332. result &= editor_plugins[i]->build();
  333. }
  334. return result;
  335. }
  336. void EditorData::set_scene_as_saved(int p_idx) {
  337. if (p_idx == -1) {
  338. p_idx = current_edited_scene;
  339. }
  340. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  341. undo_redo_manager->set_history_as_saved(edited_scene[p_idx].history_id);
  342. }
  343. bool EditorData::is_scene_changed(int p_idx) {
  344. if (p_idx == -1) {
  345. p_idx = current_edited_scene;
  346. }
  347. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false);
  348. uint64_t current_scene_version = undo_redo_manager->get_or_create_history(edited_scene[p_idx].history_id).undo_redo->get_version();
  349. bool is_changed = edited_scene[p_idx].last_checked_version != current_scene_version;
  350. edited_scene.write[p_idx].last_checked_version = current_scene_version;
  351. return is_changed;
  352. }
  353. int EditorData::get_scene_history_id_from_path(const String &p_path) const {
  354. for (const EditedScene &E : edited_scene) {
  355. if (E.path == p_path) {
  356. return E.history_id;
  357. }
  358. }
  359. return 0;
  360. }
  361. int EditorData::get_current_edited_scene_history_id() const {
  362. if (current_edited_scene != -1) {
  363. return edited_scene[current_edited_scene].history_id;
  364. }
  365. return 0;
  366. }
  367. int EditorData::get_scene_history_id(int p_idx) const {
  368. return edited_scene[p_idx].history_id;
  369. }
  370. void EditorData::add_undo_redo_inspector_hook_callback(Callable p_callable) {
  371. undo_redo_callbacks.push_back(p_callable);
  372. }
  373. void EditorData::remove_undo_redo_inspector_hook_callback(Callable p_callable) {
  374. undo_redo_callbacks.erase(p_callable);
  375. }
  376. const Vector<Callable> EditorData::get_undo_redo_inspector_hook_callback() {
  377. return undo_redo_callbacks;
  378. }
  379. void EditorData::add_move_array_element_function(const StringName &p_class, Callable p_callable) {
  380. move_element_functions.insert(p_class, p_callable);
  381. }
  382. void EditorData::remove_move_array_element_function(const StringName &p_class) {
  383. move_element_functions.erase(p_class);
  384. }
  385. Callable EditorData::get_move_array_element_function(const StringName &p_class) const {
  386. if (move_element_functions.has(p_class)) {
  387. return move_element_functions[p_class];
  388. }
  389. return Callable();
  390. }
  391. void EditorData::remove_editor_plugin(EditorPlugin *p_plugin) {
  392. editor_plugins.erase(p_plugin);
  393. }
  394. void EditorData::add_editor_plugin(EditorPlugin *p_plugin) {
  395. editor_plugins.push_back(p_plugin);
  396. }
  397. int EditorData::get_editor_plugin_count() const {
  398. return editor_plugins.size();
  399. }
  400. EditorPlugin *EditorData::get_editor_plugin(int p_idx) {
  401. ERR_FAIL_INDEX_V(p_idx, editor_plugins.size(), nullptr);
  402. return editor_plugins[p_idx];
  403. }
  404. void EditorData::add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon) {
  405. ERR_FAIL_COND_MSG(p_script.is_null(), "It's not a reference to a valid Script object.");
  406. CustomType ct;
  407. ct.name = p_type;
  408. ct.icon = p_icon;
  409. ct.script = p_script;
  410. if (!custom_types.has(p_inherits)) {
  411. custom_types[p_inherits] = Vector<CustomType>();
  412. }
  413. custom_types[p_inherits].push_back(ct);
  414. }
  415. Variant EditorData::instantiate_custom_type(const String &p_type, const String &p_inherits) {
  416. if (get_custom_types().has(p_inherits)) {
  417. for (int i = 0; i < get_custom_types()[p_inherits].size(); i++) {
  418. if (get_custom_types()[p_inherits][i].name == p_type) {
  419. Ref<Script> script = get_custom_types()[p_inherits][i].script;
  420. Variant ob = ClassDB::instantiate(p_inherits);
  421. ERR_FAIL_COND_V(!ob, Variant());
  422. Node *n = Object::cast_to<Node>(ob);
  423. if (n) {
  424. n->set_name(p_type);
  425. }
  426. ((Object *)ob)->set_script(script);
  427. return ob;
  428. }
  429. }
  430. }
  431. return Variant();
  432. }
  433. const EditorData::CustomType *EditorData::get_custom_type_by_name(const String &p_type) const {
  434. for (const KeyValue<String, Vector<CustomType>> &E : custom_types) {
  435. for (const CustomType &F : E.value) {
  436. if (F.name == p_type) {
  437. return &F;
  438. }
  439. }
  440. }
  441. return nullptr;
  442. }
  443. const EditorData::CustomType *EditorData::get_custom_type_by_path(const String &p_path) const {
  444. for (const KeyValue<String, Vector<CustomType>> &E : custom_types) {
  445. for (const CustomType &F : E.value) {
  446. if (F.script->get_path() == p_path) {
  447. return &F;
  448. }
  449. }
  450. }
  451. return nullptr;
  452. }
  453. bool EditorData::is_type_recognized(const String &p_type) const {
  454. return ClassDB::class_exists(p_type) || ScriptServer::is_global_class(p_type) || get_custom_type_by_name(p_type);
  455. }
  456. void EditorData::remove_custom_type(const String &p_type) {
  457. for (KeyValue<String, Vector<CustomType>> &E : custom_types) {
  458. for (int i = 0; i < E.value.size(); i++) {
  459. if (E.value[i].name == p_type) {
  460. E.value.remove_at(i);
  461. if (E.value.is_empty()) {
  462. custom_types.erase(E.key);
  463. }
  464. return;
  465. }
  466. }
  467. }
  468. }
  469. void EditorData::instantiate_object_properties(Object *p_object) {
  470. ERR_FAIL_NULL(p_object);
  471. // Check if any Object-type property should be instantiated.
  472. List<PropertyInfo> pinfo;
  473. p_object->get_property_list(&pinfo);
  474. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  475. PropertyInfo pi = E->get();
  476. if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) {
  477. Object *prop = ClassDB::instantiate(pi.class_name);
  478. p_object->set(pi.name, prop);
  479. }
  480. }
  481. }
  482. int EditorData::add_edited_scene(int p_at_pos) {
  483. if (p_at_pos < 0) {
  484. p_at_pos = edited_scene.size();
  485. }
  486. EditedScene es;
  487. es.root = nullptr;
  488. es.path = String();
  489. es.file_modified_time = 0;
  490. es.history_current = -1;
  491. es.live_edit_root = NodePath(String("/root"));
  492. es.history_id = last_created_scene++;
  493. if (p_at_pos == edited_scene.size()) {
  494. edited_scene.push_back(es);
  495. } else {
  496. edited_scene.insert(p_at_pos, es);
  497. }
  498. if (current_edited_scene < 0) {
  499. current_edited_scene = 0;
  500. }
  501. return p_at_pos;
  502. }
  503. void EditorData::move_edited_scene_index(int p_idx, int p_to_idx) {
  504. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  505. ERR_FAIL_INDEX(p_to_idx, edited_scene.size());
  506. SWAP(edited_scene.write[p_idx], edited_scene.write[p_to_idx]);
  507. }
  508. void EditorData::remove_scene(int p_idx) {
  509. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  510. if (edited_scene[p_idx].root) {
  511. for (int i = 0; i < editor_plugins.size(); i++) {
  512. editor_plugins[i]->notify_scene_closed(edited_scene[p_idx].root->get_scene_file_path());
  513. }
  514. memdelete(edited_scene[p_idx].root);
  515. edited_scene.write[p_idx].root = nullptr;
  516. }
  517. if (current_edited_scene > p_idx) {
  518. current_edited_scene--;
  519. } else if (current_edited_scene == p_idx && current_edited_scene > 0) {
  520. current_edited_scene--;
  521. }
  522. if (!edited_scene[p_idx].path.is_empty()) {
  523. ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(edited_scene[p_idx].path);
  524. }
  525. undo_redo_manager->discard_history(edited_scene[p_idx].history_id);
  526. edited_scene.remove_at(p_idx);
  527. }
  528. bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, HashSet<String> &checked_paths) {
  529. Ref<SceneState> ss;
  530. if (p_node == p_root) {
  531. ss = p_node->get_scene_inherited_state();
  532. } else if (!p_node->get_scene_file_path().is_empty()) {
  533. ss = p_node->get_scene_instance_state();
  534. }
  535. if (ss.is_valid()) {
  536. String path = ss->get_path();
  537. if (!checked_paths.has(path)) {
  538. uint64_t modified_time = FileAccess::get_modified_time(path);
  539. if (modified_time != ss->get_last_modified_time()) {
  540. return true; //external scene changed
  541. }
  542. checked_paths.insert(path);
  543. }
  544. }
  545. for (int i = 0; i < p_node->get_child_count(); i++) {
  546. bool found = _find_updated_instances(p_root, p_node->get_child(i), checked_paths);
  547. if (found) {
  548. return true;
  549. }
  550. }
  551. return false;
  552. }
  553. bool EditorData::check_and_update_scene(int p_idx) {
  554. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false);
  555. if (!edited_scene[p_idx].root) {
  556. return false;
  557. }
  558. HashSet<String> checked_scenes;
  559. bool must_reload = _find_updated_instances(edited_scene[p_idx].root, edited_scene[p_idx].root, checked_scenes);
  560. if (must_reload) {
  561. Ref<PackedScene> pscene;
  562. pscene.instantiate();
  563. EditorProgress ep("update_scene", TTR("Updating Scene"), 2);
  564. ep.step(TTR("Storing local changes..."), 0);
  565. // Pack first, so it stores diffs to previous version of saved scene.
  566. Error err = pscene->pack(edited_scene[p_idx].root);
  567. ERR_FAIL_COND_V(err != OK, false);
  568. ep.step(TTR("Updating scene..."), 1);
  569. Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN);
  570. ERR_FAIL_COND_V(!new_scene, false);
  571. // Transfer selection.
  572. List<Node *> new_selection;
  573. for (const Node *E : edited_scene.write[p_idx].selection) {
  574. NodePath p = edited_scene[p_idx].root->get_path_to(E);
  575. Node *new_node = new_scene->get_node(p);
  576. if (new_node) {
  577. new_selection.push_back(new_node);
  578. }
  579. }
  580. new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path());
  581. memdelete(edited_scene[p_idx].root);
  582. edited_scene.write[p_idx].root = new_scene;
  583. if (!new_scene->get_scene_file_path().is_empty()) {
  584. edited_scene.write[p_idx].path = new_scene->get_scene_file_path();
  585. }
  586. edited_scene.write[p_idx].selection = new_selection;
  587. return true;
  588. }
  589. return false;
  590. }
  591. int EditorData::get_edited_scene() const {
  592. return current_edited_scene;
  593. }
  594. void EditorData::set_edited_scene(int p_idx) {
  595. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  596. current_edited_scene = p_idx;
  597. }
  598. Node *EditorData::get_edited_scene_root(int p_idx) {
  599. if (p_idx < 0) {
  600. ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), nullptr);
  601. return edited_scene[current_edited_scene].root;
  602. } else {
  603. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), nullptr);
  604. return edited_scene[p_idx].root;
  605. }
  606. }
  607. void EditorData::set_edited_scene_root(Node *p_root) {
  608. ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
  609. edited_scene.write[current_edited_scene].root = p_root;
  610. if (p_root) {
  611. if (!p_root->get_scene_file_path().is_empty()) {
  612. edited_scene.write[current_edited_scene].path = p_root->get_scene_file_path();
  613. } else {
  614. p_root->set_scene_file_path(edited_scene[current_edited_scene].path);
  615. }
  616. }
  617. if (!edited_scene[current_edited_scene].path.is_empty()) {
  618. edited_scene.write[current_edited_scene].file_modified_time = FileAccess::get_modified_time(edited_scene[current_edited_scene].path);
  619. }
  620. }
  621. int EditorData::get_edited_scene_count() const {
  622. return edited_scene.size();
  623. }
  624. Vector<EditorData::EditedScene> EditorData::get_edited_scenes() const {
  625. Vector<EditedScene> out_edited_scenes_list = Vector<EditedScene>();
  626. for (int i = 0; i < edited_scene.size(); i++) {
  627. out_edited_scenes_list.push_back(edited_scene[i]);
  628. }
  629. return out_edited_scenes_list;
  630. }
  631. void EditorData::set_scene_modified_time(int p_idx, uint64_t p_time) {
  632. if (p_idx == -1) {
  633. p_idx = current_edited_scene;
  634. }
  635. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  636. edited_scene.write[p_idx].file_modified_time = p_time;
  637. }
  638. uint64_t EditorData::get_scene_modified_time(int p_idx) const {
  639. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), 0);
  640. return edited_scene[p_idx].file_modified_time;
  641. }
  642. String EditorData::get_scene_type(int p_idx) const {
  643. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
  644. if (!edited_scene[p_idx].root) {
  645. return "";
  646. }
  647. return edited_scene[p_idx].root->get_class();
  648. }
  649. void EditorData::move_edited_scene_to_index(int p_idx) {
  650. ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
  651. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  652. EditedScene es = edited_scene[current_edited_scene];
  653. edited_scene.remove_at(current_edited_scene);
  654. edited_scene.insert(p_idx, es);
  655. current_edited_scene = p_idx;
  656. }
  657. Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
  658. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Ref<Script>());
  659. if (!edited_scene[p_idx].root) {
  660. return Ref<Script>();
  661. }
  662. Ref<Script> s = edited_scene[p_idx].root->get_script();
  663. if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) {
  664. Node *n = edited_scene[p_idx].root->get_child(0);
  665. while (!s.is_valid() && n && n->get_scene_file_path().is_empty()) {
  666. s = n->get_script();
  667. n = n->get_parent();
  668. }
  669. }
  670. return s;
  671. }
  672. String EditorData::get_scene_title(int p_idx, bool p_always_strip_extension) const {
  673. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
  674. if (!edited_scene[p_idx].root) {
  675. return TTR("[empty]");
  676. }
  677. if (edited_scene[p_idx].root->get_scene_file_path().is_empty()) {
  678. return TTR("[unsaved]");
  679. }
  680. const String filename = edited_scene[p_idx].root->get_scene_file_path().get_file();
  681. const String basename = filename.get_basename();
  682. if (p_always_strip_extension) {
  683. return basename;
  684. }
  685. // Return the filename including the extension if there's ambiguity (e.g. both `foo.tscn` and `foo.scn` are being edited).
  686. for (int i = 0; i < edited_scene.size(); i++) {
  687. if (i == p_idx) {
  688. // Don't compare the edited scene against itself.
  689. continue;
  690. }
  691. if (edited_scene[i].root && basename == edited_scene[i].root->get_scene_file_path().get_file().get_basename()) {
  692. return filename;
  693. }
  694. }
  695. // Else, return just the basename as there's no ambiguity.
  696. return basename;
  697. }
  698. void EditorData::set_scene_path(int p_idx, const String &p_path) {
  699. ERR_FAIL_INDEX(p_idx, edited_scene.size());
  700. edited_scene.write[p_idx].path = p_path;
  701. if (!edited_scene[p_idx].root) {
  702. return;
  703. }
  704. edited_scene[p_idx].root->set_scene_file_path(p_path);
  705. }
  706. String EditorData::get_scene_path(int p_idx) const {
  707. ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
  708. if (edited_scene[p_idx].root) {
  709. if (edited_scene[p_idx].root->get_scene_file_path().is_empty()) {
  710. edited_scene[p_idx].root->set_scene_file_path(edited_scene[p_idx].path);
  711. } else {
  712. return edited_scene[p_idx].root->get_scene_file_path();
  713. }
  714. }
  715. return edited_scene[p_idx].path;
  716. }
  717. void EditorData::set_edited_scene_live_edit_root(const NodePath &p_root) {
  718. ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
  719. edited_scene.write[current_edited_scene].live_edit_root = p_root;
  720. }
  721. NodePath EditorData::get_edited_scene_live_edit_root() {
  722. ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), String());
  723. return edited_scene[current_edited_scene].live_edit_root;
  724. }
  725. void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history, const Dictionary &p_custom) {
  726. ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
  727. EditedScene &es = edited_scene.write[current_edited_scene];
  728. es.selection = p_selection->get_full_selected_node_list();
  729. es.history_current = p_history->current_elem_idx;
  730. es.history_stored = p_history->history;
  731. es.editor_states = get_editor_states();
  732. es.custom_state = p_custom;
  733. }
  734. Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history) {
  735. ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), Dictionary());
  736. const EditedScene &es = edited_scene.write[current_edited_scene];
  737. p_history->current_elem_idx = es.history_current;
  738. p_history->history = es.history_stored;
  739. p_selection->clear();
  740. for (Node *E : es.selection) {
  741. p_selection->add_node(E);
  742. }
  743. set_editor_states(es.editor_states);
  744. return es.custom_state;
  745. }
  746. void EditorData::clear_edited_scenes() {
  747. for (int i = 0; i < edited_scene.size(); i++) {
  748. if (edited_scene[i].root) {
  749. memdelete(edited_scene[i].root);
  750. }
  751. }
  752. edited_scene.clear();
  753. }
  754. void EditorData::set_plugin_window_layout(Ref<ConfigFile> p_layout) {
  755. for (int i = 0; i < editor_plugins.size(); i++) {
  756. editor_plugins[i]->set_window_layout(p_layout);
  757. }
  758. }
  759. void EditorData::get_plugin_window_layout(Ref<ConfigFile> p_layout) {
  760. for (int i = 0; i < editor_plugins.size(); i++) {
  761. editor_plugins[i]->get_window_layout(p_layout);
  762. }
  763. }
  764. bool EditorData::script_class_is_parent(const String &p_class, const String &p_inherits) {
  765. if (!ScriptServer::is_global_class(p_class)) {
  766. return false;
  767. }
  768. String base = p_class;
  769. while (base != p_inherits) {
  770. if (ClassDB::class_exists(base)) {
  771. return ClassDB::is_parent_class(base, p_inherits);
  772. } else if (ScriptServer::is_global_class(base)) {
  773. base = ScriptServer::get_global_class_base(base);
  774. } else {
  775. return false;
  776. }
  777. }
  778. return true;
  779. }
  780. StringName EditorData::script_class_get_base(const String &p_class) const {
  781. Ref<Script> script = script_class_load_script(p_class);
  782. if (script.is_null()) {
  783. return StringName();
  784. }
  785. Ref<Script> base_script = script->get_base_script();
  786. if (base_script.is_null()) {
  787. return ScriptServer::get_global_class_base(p_class);
  788. }
  789. return script->get_language()->get_global_class_name(base_script->get_path());
  790. }
  791. Variant EditorData::script_class_instance(const String &p_class) {
  792. if (ScriptServer::is_global_class(p_class)) {
  793. Ref<Script> script = script_class_load_script(p_class);
  794. if (script.is_valid()) {
  795. // Store in a variant to initialize the refcount if needed.
  796. Variant obj = ClassDB::instantiate(script->get_instance_base_type());
  797. if (obj) {
  798. obj.operator Object *()->set_script(script);
  799. }
  800. return obj;
  801. }
  802. }
  803. return Variant();
  804. }
  805. Ref<Script> EditorData::script_class_load_script(const String &p_class) const {
  806. if (!ScriptServer::is_global_class(p_class)) {
  807. return Ref<Script>();
  808. }
  809. String path = ScriptServer::get_global_class_path(p_class);
  810. return ResourceLoader::load(path, "Script");
  811. }
  812. void EditorData::script_class_set_icon_path(const String &p_class, const String &p_icon_path) {
  813. _script_class_icon_paths[p_class] = p_icon_path;
  814. }
  815. String EditorData::script_class_get_icon_path(const String &p_class) const {
  816. if (!ScriptServer::is_global_class(p_class)) {
  817. return String();
  818. }
  819. String current = p_class;
  820. String ret = _script_class_icon_paths[current];
  821. while (ret.is_empty()) {
  822. current = script_class_get_base(current);
  823. if (!ScriptServer::is_global_class(current)) {
  824. return String();
  825. }
  826. ret = _script_class_icon_paths.has(current) ? _script_class_icon_paths[current] : String();
  827. }
  828. return ret;
  829. }
  830. StringName EditorData::script_class_get_name(const String &p_path) const {
  831. return _script_class_file_to_path.has(p_path) ? _script_class_file_to_path[p_path] : StringName();
  832. }
  833. void EditorData::script_class_set_name(const String &p_path, const StringName &p_class) {
  834. _script_class_file_to_path[p_path] = p_class;
  835. }
  836. void EditorData::script_class_save_icon_paths() {
  837. Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
  838. Dictionary d;
  839. for (const KeyValue<StringName, String> &E : _script_class_icon_paths) {
  840. if (ScriptServer::is_global_class(E.key)) {
  841. d[E.key] = E.value;
  842. }
  843. }
  844. for (int i = 0; i < script_classes.size(); i++) {
  845. Dictionary d2 = script_classes[i];
  846. if (!d2.has("class")) {
  847. continue;
  848. }
  849. d2["icon"] = d.get(d2["class"], "");
  850. }
  851. ProjectSettings::get_singleton()->store_global_class_list(script_classes);
  852. }
  853. void EditorData::script_class_load_icon_paths() {
  854. script_class_clear_icon_paths();
  855. #ifndef DISABLE_DEPRECATED
  856. if (ProjectSettings::get_singleton()->has_setting("_global_script_class_icons")) {
  857. Dictionary d = GLOBAL_GET("_global_script_class_icons");
  858. List<Variant> keys;
  859. d.get_key_list(&keys);
  860. for (const Variant &E : keys) {
  861. String name = E.operator String();
  862. _script_class_icon_paths[name] = d[name];
  863. String path = ScriptServer::get_global_class_path(name);
  864. script_class_set_name(path, name);
  865. }
  866. ProjectSettings::get_singleton()->clear("_global_script_class_icons");
  867. }
  868. #endif
  869. Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
  870. for (int i = 0; i < script_classes.size(); i++) {
  871. Dictionary d = script_classes[i];
  872. if (!d.has("class") || !d.has("path") || !d.has("icon")) {
  873. continue;
  874. }
  875. String name = d["class"];
  876. _script_class_icon_paths[name] = d["icon"];
  877. script_class_set_name(d["path"], name);
  878. }
  879. }
  880. Ref<Texture2D> EditorData::extension_class_get_icon(const String &p_class) const {
  881. if (GDExtensionManager::get_singleton()->class_has_icon_path(p_class)) {
  882. String icon_path = GDExtensionManager::get_singleton()->class_get_icon_path(p_class);
  883. Ref<Texture2D> icon = _load_script_icon(icon_path);
  884. if (icon.is_valid()) {
  885. return icon;
  886. }
  887. }
  888. return nullptr;
  889. }
  890. Ref<Texture2D> EditorData::_load_script_icon(const String &p_path) const {
  891. if (!p_path.is_empty() && ResourceLoader::exists(p_path)) {
  892. Ref<Texture2D> icon = ResourceLoader::load(p_path);
  893. if (icon.is_valid()) {
  894. return icon;
  895. }
  896. }
  897. return nullptr;
  898. }
  899. Ref<Texture2D> EditorData::get_script_icon(const Ref<Script> &p_script) {
  900. // Take from the local cache, if available.
  901. if (_script_icon_cache.has(p_script) && _script_icon_cache[p_script].is_valid()) {
  902. return _script_icon_cache[p_script];
  903. }
  904. Ref<Script> base_scr = p_script;
  905. while (base_scr.is_valid()) {
  906. // Check for scripted classes.
  907. StringName class_name = script_class_get_name(base_scr->get_path());
  908. String icon_path = script_class_get_icon_path(class_name);
  909. Ref<Texture2D> icon = _load_script_icon(icon_path);
  910. if (icon.is_valid()) {
  911. _script_icon_cache[p_script] = icon;
  912. return icon;
  913. }
  914. // Check for legacy custom classes defined by plugins.
  915. // TODO: Should probably be deprecated in 4.x
  916. const EditorData::CustomType *ctype = get_custom_type_by_path(base_scr->get_path());
  917. if (ctype && ctype->icon.is_valid()) {
  918. _script_icon_cache[p_script] = ctype->icon;
  919. return ctype->icon;
  920. }
  921. // Move to the base class.
  922. base_scr = base_scr->get_base_script();
  923. }
  924. // If no icon found, cache it as null.
  925. _script_icon_cache[p_script] = Ref<Texture>();
  926. return nullptr;
  927. }
  928. void EditorData::clear_script_icon_cache() {
  929. _script_icon_cache.clear();
  930. }
  931. EditorData::EditorData() {
  932. undo_redo_manager = memnew(EditorUndoRedoManager);
  933. script_class_load_icon_paths();
  934. }
  935. EditorData::~EditorData() {
  936. memdelete(undo_redo_manager);
  937. }
  938. ///////////////////////////////////////////////////////////////////////////////
  939. void EditorSelection::_node_removed(Node *p_node) {
  940. if (!selection.has(p_node)) {
  941. return;
  942. }
  943. Object *meta = selection[p_node];
  944. if (meta) {
  945. memdelete(meta);
  946. }
  947. selection.erase(p_node);
  948. changed = true;
  949. node_list_changed = true;
  950. }
  951. void EditorSelection::add_node(Node *p_node) {
  952. ERR_FAIL_NULL(p_node);
  953. ERR_FAIL_COND(!p_node->is_inside_tree());
  954. if (selection.has(p_node)) {
  955. return;
  956. }
  957. changed = true;
  958. node_list_changed = true;
  959. Object *meta = nullptr;
  960. for (Object *E : editor_plugins) {
  961. meta = E->call("_get_editor_data", p_node);
  962. if (meta) {
  963. break;
  964. }
  965. }
  966. selection[p_node] = meta;
  967. p_node->connect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed).bind(p_node), CONNECT_ONE_SHOT);
  968. }
  969. void EditorSelection::remove_node(Node *p_node) {
  970. ERR_FAIL_NULL(p_node);
  971. if (!selection.has(p_node)) {
  972. return;
  973. }
  974. changed = true;
  975. node_list_changed = true;
  976. Object *meta = selection[p_node];
  977. if (meta) {
  978. memdelete(meta);
  979. }
  980. selection.erase(p_node);
  981. p_node->disconnect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed));
  982. }
  983. bool EditorSelection::is_selected(Node *p_node) const {
  984. return selection.has(p_node);
  985. }
  986. void EditorSelection::_bind_methods() {
  987. ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
  988. ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
  989. ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
  990. ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
  991. ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes);
  992. ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change);
  993. ADD_SIGNAL(MethodInfo("selection_changed"));
  994. }
  995. void EditorSelection::add_editor_plugin(Object *p_object) {
  996. editor_plugins.push_back(p_object);
  997. }
  998. void EditorSelection::_update_node_list() {
  999. if (!node_list_changed) {
  1000. return;
  1001. }
  1002. selected_node_list.clear();
  1003. // If the selection does not have the parent of the selected node, then add the node to the node list.
  1004. // However, if the parent is already selected, then adding this node is redundant as
  1005. // it is included with the parent, so skip it.
  1006. for (const KeyValue<Node *, Object *> &E : selection) {
  1007. Node *parent = E.key;
  1008. parent = parent->get_parent();
  1009. bool skip = false;
  1010. while (parent) {
  1011. if (selection.has(parent)) {
  1012. skip = true;
  1013. break;
  1014. }
  1015. parent = parent->get_parent();
  1016. }
  1017. if (skip) {
  1018. continue;
  1019. }
  1020. selected_node_list.push_back(E.key);
  1021. }
  1022. node_list_changed = true;
  1023. }
  1024. void EditorSelection::update() {
  1025. _update_node_list();
  1026. if (!changed) {
  1027. return;
  1028. }
  1029. changed = false;
  1030. if (!emitted) {
  1031. emitted = true;
  1032. call_deferred(SNAME("_emit_change"));
  1033. }
  1034. }
  1035. void EditorSelection::_emit_change() {
  1036. emit_signal(SNAME("selection_changed"));
  1037. emitted = false;
  1038. }
  1039. TypedArray<Node> EditorSelection::_get_transformable_selected_nodes() {
  1040. TypedArray<Node> ret;
  1041. for (const Node *E : selected_node_list) {
  1042. ret.push_back(E);
  1043. }
  1044. return ret;
  1045. }
  1046. TypedArray<Node> EditorSelection::get_selected_nodes() {
  1047. TypedArray<Node> ret;
  1048. for (const KeyValue<Node *, Object *> &E : selection) {
  1049. ret.push_back(E.key);
  1050. }
  1051. return ret;
  1052. }
  1053. List<Node *> &EditorSelection::get_selected_node_list() {
  1054. if (changed) {
  1055. update();
  1056. } else {
  1057. _update_node_list();
  1058. }
  1059. return selected_node_list;
  1060. }
  1061. List<Node *> EditorSelection::get_full_selected_node_list() {
  1062. List<Node *> node_list;
  1063. for (const KeyValue<Node *, Object *> &E : selection) {
  1064. node_list.push_back(E.key);
  1065. }
  1066. return node_list;
  1067. }
  1068. void EditorSelection::clear() {
  1069. while (!selection.is_empty()) {
  1070. remove_node(selection.begin()->key);
  1071. }
  1072. changed = true;
  1073. node_list_changed = true;
  1074. }
  1075. EditorSelection::EditorSelection() {
  1076. }
  1077. EditorSelection::~EditorSelection() {
  1078. clear();
  1079. }