inspector_dock.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*************************************************************************/
  2. /* inspector_dock.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "inspector_dock.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_settings.h"
  33. #include "editor/plugins/animation_player_editor_plugin.h"
  34. void InspectorDock::_menu_option(int p_option) {
  35. switch (p_option) {
  36. case EXPAND_ALL: {
  37. _menu_expandall();
  38. } break;
  39. case COLLAPSE_ALL: {
  40. _menu_collapseall();
  41. } break;
  42. case RESOURCE_MAKE_BUILT_IN: {
  43. _unref_resource();
  44. } break;
  45. case RESOURCE_COPY: {
  46. _copy_resource();
  47. } break;
  48. case RESOURCE_EDIT_CLIPBOARD: {
  49. _paste_resource();
  50. } break;
  51. case RESOURCE_SAVE: {
  52. _save_resource(false);
  53. } break;
  54. case RESOURCE_SAVE_AS: {
  55. _save_resource(true);
  56. } break;
  57. case OBJECT_REQUEST_HELP: {
  58. if (current) {
  59. editor->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  60. emit_signal("request_help", current->get_class());
  61. }
  62. } break;
  63. case OBJECT_COPY_PARAMS: {
  64. editor_data->apply_changes_in_editors();
  65. if (current) {
  66. editor_data->copy_object_params(current);
  67. }
  68. } break;
  69. case OBJECT_PASTE_PARAMS: {
  70. editor_data->apply_changes_in_editors();
  71. if (current) {
  72. editor_data->paste_object_params(current);
  73. }
  74. } break;
  75. case OBJECT_UNIQUE_RESOURCES: {
  76. editor_data->apply_changes_in_editors();
  77. if (current) {
  78. List<PropertyInfo> props;
  79. current->get_property_list(&props);
  80. Map<RES, RES> duplicates;
  81. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  82. if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
  83. continue;
  84. }
  85. Variant v = current->get(E->get().name);
  86. if (v.is_ref()) {
  87. REF ref = v;
  88. if (ref.is_valid()) {
  89. RES res = ref;
  90. if (res.is_valid()) {
  91. if (!duplicates.has(res)) {
  92. duplicates[res] = res->duplicate();
  93. }
  94. res = duplicates[res];
  95. current->set(E->get().name, res);
  96. editor->get_inspector()->update_property(E->get().name);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. editor_data->get_undo_redo().clear_history();
  103. editor->get_editor_plugins_over()->edit(nullptr);
  104. editor->get_editor_plugins_over()->edit(current);
  105. } break;
  106. default: {
  107. if (p_option >= OBJECT_METHOD_BASE) {
  108. ERR_FAIL_COND(!current);
  109. int idx = p_option - OBJECT_METHOD_BASE;
  110. List<MethodInfo> methods;
  111. current->get_method_list(&methods);
  112. ERR_FAIL_INDEX(idx, methods.size());
  113. String name = methods[idx].name;
  114. current->call(name);
  115. }
  116. }
  117. }
  118. }
  119. void InspectorDock::_new_resource() {
  120. new_resource_dialog->popup_create(true);
  121. }
  122. void InspectorDock::_load_resource(const String &p_type) {
  123. load_resource_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  124. List<String> extensions;
  125. ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions);
  126. load_resource_dialog->clear_filters();
  127. for (int i = 0; i < extensions.size(); i++) {
  128. load_resource_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  129. }
  130. load_resource_dialog->popup_file_dialog();
  131. }
  132. void InspectorDock::_resource_file_selected(String p_file) {
  133. RES res = ResourceLoader::load(p_file);
  134. if (res.is_null()) {
  135. warning_dialog->set_text(TTR("Failed to load resource."));
  136. return;
  137. };
  138. editor->push_item(res.operator->());
  139. }
  140. void InspectorDock::_save_resource(bool save_as) {
  141. ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
  142. Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
  143. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  144. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  145. if (save_as) {
  146. editor->save_resource_as(current_res);
  147. } else {
  148. editor->save_resource(current_res);
  149. }
  150. }
  151. void InspectorDock::_unref_resource() {
  152. ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
  153. Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
  154. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  155. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  156. current_res->set_path("");
  157. editor->edit_current();
  158. }
  159. void InspectorDock::_copy_resource() {
  160. ObjectID current = EditorNode::get_singleton()->get_editor_history()->get_current();
  161. Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr;
  162. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  163. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  164. EditorSettings::get_singleton()->set_resource_clipboard(current_res);
  165. }
  166. void InspectorDock::_paste_resource() {
  167. RES r = EditorSettings::get_singleton()->get_resource_clipboard();
  168. if (r.is_valid()) {
  169. editor->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String());
  170. }
  171. }
  172. void InspectorDock::_prepare_history() {
  173. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  174. int history_to = MAX(0, editor_history->get_history_len() - 25);
  175. history_menu->get_popup()->clear();
  176. Ref<Texture2D> base_icon = get_theme_icon("Object", "EditorIcons");
  177. Set<ObjectID> already;
  178. for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) {
  179. ObjectID id = editor_history->get_history_obj(i);
  180. Object *obj = ObjectDB::get_instance(id);
  181. if (!obj || already.has(id)) {
  182. if (history_to > 0) {
  183. history_to--;
  184. }
  185. continue;
  186. }
  187. already.insert(id);
  188. Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, "");
  189. if (icon.is_null()) {
  190. icon = base_icon;
  191. }
  192. String text;
  193. if (Object::cast_to<Resource>(obj)) {
  194. Resource *r = Object::cast_to<Resource>(obj);
  195. if (r->get_path().is_resource_file()) {
  196. text = r->get_path().get_file();
  197. } else if (r->get_name() != String()) {
  198. text = r->get_name();
  199. } else {
  200. text = r->get_class();
  201. }
  202. } else if (Object::cast_to<Node>(obj)) {
  203. text = Object::cast_to<Node>(obj)->get_name();
  204. } else if (obj->is_class("EditorDebuggerRemoteObject")) {
  205. text = obj->call("get_title");
  206. } else {
  207. text = obj->get_class();
  208. }
  209. if (i == editor_history->get_history_pos() && current) {
  210. text = "[" + text + "]";
  211. }
  212. history_menu->get_popup()->add_icon_item(icon, text, i);
  213. }
  214. }
  215. void InspectorDock::_select_history(int p_idx) {
  216. //push it to the top, it is not correct, but it's more useful
  217. ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx);
  218. Object *obj = ObjectDB::get_instance(id);
  219. if (!obj) {
  220. return;
  221. }
  222. editor->push_item(obj);
  223. }
  224. void InspectorDock::_resource_created() {
  225. Variant c = new_resource_dialog->instance_selected();
  226. ERR_FAIL_COND(!c);
  227. Resource *r = Object::cast_to<Resource>(c);
  228. ERR_FAIL_COND(!r);
  229. editor->push_item(r);
  230. }
  231. void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) {
  232. if (p_res.is_null()) {
  233. return;
  234. }
  235. RES r = p_res;
  236. editor->push_item(r.operator->(), p_property);
  237. }
  238. void InspectorDock::_edit_forward() {
  239. if (EditorNode::get_singleton()->get_editor_history()->next()) {
  240. editor->edit_current();
  241. }
  242. }
  243. void InspectorDock::_edit_back() {
  244. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  245. if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
  246. editor->edit_current();
  247. }
  248. }
  249. void InspectorDock::_menu_collapseall() {
  250. inspector->collapse_all_folding();
  251. }
  252. void InspectorDock::_menu_expandall() {
  253. inspector->expand_all_folding();
  254. }
  255. void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance) {
  256. AnimationPlayerEditor::singleton->get_track_editor()->insert_value_key(p_keyed, p_value, p_advance);
  257. }
  258. void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) {
  259. Node3D *s = Object::cast_to<Node3D>(sp);
  260. if (!s) {
  261. return;
  262. }
  263. AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key);
  264. }
  265. void InspectorDock::_warning_pressed() {
  266. warning_dialog->popup_centered();
  267. }
  268. Container *InspectorDock::get_addon_area() {
  269. return this;
  270. }
  271. void InspectorDock::_notification(int p_what) {
  272. switch (p_what) {
  273. case NOTIFICATION_TRANSLATION_CHANGED:
  274. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
  275. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  276. set_theme(editor->get_gui_base()->get_theme());
  277. resource_new_button->set_icon(get_theme_icon("New", "EditorIcons"));
  278. resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons"));
  279. resource_save_button->set_icon(get_theme_icon("Save", "EditorIcons"));
  280. if (is_layout_rtl()) {
  281. backward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
  282. forward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
  283. } else {
  284. backward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
  285. forward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
  286. }
  287. history_menu->set_icon(get_theme_icon("History", "EditorIcons"));
  288. object_menu->set_icon(get_theme_icon("Tools", "EditorIcons"));
  289. warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons"));
  290. warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
  291. } break;
  292. }
  293. }
  294. void InspectorDock::_bind_methods() {
  295. ClassDB::bind_method("update_keying", &InspectorDock::update_keying);
  296. ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); // Still used by some connect_compat.
  297. ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource);
  298. ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource);
  299. ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource);
  300. ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall);
  301. ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall);
  302. ADD_SIGNAL(MethodInfo("request_help"));
  303. }
  304. void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
  305. _resource_selected(p_resource, "");
  306. }
  307. void InspectorDock::open_resource(const String &p_type) {
  308. _load_resource(p_type);
  309. }
  310. void InspectorDock::set_warning(const String &p_message) {
  311. warning->hide();
  312. if (p_message != String()) {
  313. warning->show();
  314. warning_dialog->set_text(p_message);
  315. }
  316. }
  317. void InspectorDock::clear() {
  318. }
  319. void InspectorDock::update(Object *p_object) {
  320. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  321. backward_button->set_disabled(editor_history->is_at_beginning());
  322. forward_button->set_disabled(editor_history->is_at_end());
  323. history_menu->set_disabled(true);
  324. if (editor_history->get_history_len() > 0) {
  325. history_menu->set_disabled(false);
  326. }
  327. editor_path->update_path();
  328. current = p_object;
  329. if (!p_object) {
  330. object_menu->set_disabled(true);
  331. warning->hide();
  332. search->set_editable(false);
  333. editor_path->set_disabled(true);
  334. editor_path->set_text("");
  335. editor_path->set_tooltip("");
  336. editor_path->set_icon(nullptr);
  337. return;
  338. }
  339. bool is_resource = p_object->is_class("Resource");
  340. bool is_node = p_object->is_class("Node");
  341. object_menu->set_disabled(false);
  342. search->set_editable(true);
  343. editor_path->set_disabled(false);
  344. resource_save_button->set_disabled(!is_resource);
  345. PopupMenu *p = object_menu->get_popup();
  346. p->clear();
  347. p->add_shortcut(ED_SHORTCUT("property_editor/expand_all", TTR("Expand All Properties")), EXPAND_ALL);
  348. p->add_shortcut(ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All Properties")), COLLAPSE_ALL);
  349. p->add_separator();
  350. if (is_resource) {
  351. p->add_item(TTR("Save"), RESOURCE_SAVE);
  352. p->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
  353. p->add_separator();
  354. }
  355. p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Params")), OBJECT_COPY_PARAMS);
  356. p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Params")), OBJECT_PASTE_PARAMS);
  357. p->add_separator();
  358. p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource Clipboard")), RESOURCE_EDIT_CLIPBOARD);
  359. if (is_resource) {
  360. p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
  361. p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Built-In")), RESOURCE_MAKE_BUILT_IN);
  362. }
  363. if (is_resource || is_node) {
  364. p->add_separator();
  365. p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
  366. p->add_separator();
  367. p->add_icon_shortcut(get_theme_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("property_editor/open_help", TTR("Open in Help")), OBJECT_REQUEST_HELP);
  368. }
  369. List<MethodInfo> methods;
  370. p_object->get_method_list(&methods);
  371. if (!methods.is_empty()) {
  372. bool found = false;
  373. List<MethodInfo>::Element *I = methods.front();
  374. int i = 0;
  375. while (I) {
  376. if (I->get().flags & METHOD_FLAG_EDITOR) {
  377. if (!found) {
  378. p->add_separator();
  379. found = true;
  380. }
  381. p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
  382. }
  383. i++;
  384. I = I->next();
  385. }
  386. }
  387. }
  388. void InspectorDock::go_back() {
  389. _edit_back();
  390. }
  391. void InspectorDock::update_keying() {
  392. bool valid = false;
  393. if (AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
  394. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  395. if (editor_history->get_path_size() >= 1) {
  396. Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0));
  397. if (Object::cast_to<Node>(obj)) {
  398. valid = true;
  399. }
  400. }
  401. }
  402. inspector->set_keying(valid);
  403. }
  404. InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
  405. set_name("Inspector");
  406. set_theme(p_editor->get_gui_base()->get_theme());
  407. editor = p_editor;
  408. editor_data = &p_editor_data;
  409. HBoxContainer *general_options_hb = memnew(HBoxContainer);
  410. add_child(general_options_hb);
  411. resource_new_button = memnew(Button);
  412. resource_new_button->set_flat(true);
  413. resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it."));
  414. resource_new_button->set_icon(get_theme_icon("New", "EditorIcons"));
  415. general_options_hb->add_child(resource_new_button);
  416. resource_new_button->connect("pressed", callable_mp(this, &InspectorDock::_new_resource));
  417. resource_new_button->set_focus_mode(Control::FOCUS_NONE);
  418. resource_load_button = memnew(Button);
  419. resource_load_button->set_flat(true);
  420. resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it."));
  421. resource_load_button->set_icon(get_theme_icon("Load", "EditorIcons"));
  422. general_options_hb->add_child(resource_load_button);
  423. resource_load_button->connect("pressed", callable_mp(this, &InspectorDock::_open_resource_selector));
  424. resource_load_button->set_focus_mode(Control::FOCUS_NONE);
  425. resource_save_button = memnew(MenuButton);
  426. resource_save_button->set_tooltip(TTR("Save the currently edited resource."));
  427. resource_save_button->set_icon(get_theme_icon("Save", "EditorIcons"));
  428. general_options_hb->add_child(resource_save_button);
  429. resource_save_button->get_popup()->add_item(TTR("Save"), RESOURCE_SAVE);
  430. resource_save_button->get_popup()->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
  431. resource_save_button->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
  432. resource_save_button->set_focus_mode(Control::FOCUS_NONE);
  433. resource_save_button->set_disabled(true);
  434. general_options_hb->add_spacer();
  435. backward_button = memnew(Button);
  436. backward_button->set_flat(true);
  437. general_options_hb->add_child(backward_button);
  438. if (is_layout_rtl()) {
  439. backward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
  440. } else {
  441. backward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
  442. }
  443. backward_button->set_flat(true);
  444. backward_button->set_tooltip(TTR("Go to the previous edited object in history."));
  445. backward_button->set_disabled(true);
  446. backward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_back));
  447. forward_button = memnew(Button);
  448. forward_button->set_flat(true);
  449. general_options_hb->add_child(forward_button);
  450. if (is_layout_rtl()) {
  451. forward_button->set_icon(get_theme_icon("Back", "EditorIcons"));
  452. } else {
  453. forward_button->set_icon(get_theme_icon("Forward", "EditorIcons"));
  454. }
  455. forward_button->set_flat(true);
  456. forward_button->set_tooltip(TTR("Go to the next edited object in history."));
  457. forward_button->set_disabled(true);
  458. forward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_forward));
  459. history_menu = memnew(MenuButton);
  460. history_menu->set_tooltip(TTR("History of recently edited objects."));
  461. history_menu->set_icon(get_theme_icon("History", "EditorIcons"));
  462. general_options_hb->add_child(history_menu);
  463. history_menu->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_history));
  464. history_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_select_history));
  465. HBoxContainer *node_info_hb = memnew(HBoxContainer);
  466. add_child(node_info_hb);
  467. editor_path = memnew(EditorPath(editor->get_editor_history()));
  468. editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  469. node_info_hb->add_child(editor_path);
  470. object_menu = memnew(MenuButton);
  471. object_menu->set_shortcut_context(this);
  472. object_menu->set_icon(get_theme_icon("Tools", "EditorIcons"));
  473. node_info_hb->add_child(object_menu);
  474. object_menu->set_tooltip(TTR("Object properties."));
  475. object_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
  476. new_resource_dialog = memnew(CreateDialog);
  477. editor->get_gui_base()->add_child(new_resource_dialog);
  478. new_resource_dialog->set_base_type("Resource");
  479. new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created));
  480. search = memnew(LineEdit);
  481. search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  482. search->set_placeholder(TTR("Filter properties"));
  483. search->set_right_icon(get_theme_icon("Search", "EditorIcons"));
  484. search->set_clear_button_enabled(true);
  485. add_child(search);
  486. warning = memnew(Button);
  487. add_child(warning);
  488. warning->set_text(TTR("Changes may be lost!"));
  489. warning->set_icon(get_theme_icon("NodeWarning", "EditorIcons"));
  490. warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
  491. warning->set_clip_text(true);
  492. warning->hide();
  493. warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed));
  494. warning_dialog = memnew(AcceptDialog);
  495. editor->get_gui_base()->add_child(warning_dialog);
  496. load_resource_dialog = memnew(EditorFileDialog);
  497. add_child(load_resource_dialog);
  498. load_resource_dialog->set_current_dir("res://");
  499. load_resource_dialog->connect("file_selected", callable_mp(this, &InspectorDock::_resource_file_selected));
  500. inspector = memnew(EditorInspector);
  501. add_child(inspector);
  502. inspector->set_autoclear(true);
  503. inspector->set_show_categories(true);
  504. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  505. inspector->set_use_doc_hints(true);
  506. inspector->set_hide_script(false);
  507. inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
  508. inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
  509. inspector->register_text_enter(search);
  510. inspector->set_undo_redo(&editor_data->get_undo_redo());
  511. inspector->set_use_filter(true); // TODO: check me
  512. inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected));
  513. inspector->connect("property_keyed", callable_mp(this, &InspectorDock::_property_keyed));
  514. }
  515. InspectorDock::~InspectorDock() {
  516. }