inspector_dock.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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_SAVE: {
  43. _save_resource(false);
  44. } break;
  45. case RESOURCE_SAVE_AS: {
  46. _save_resource(true);
  47. } break;
  48. case RESOURCE_MAKE_BUILT_IN: {
  49. _unref_resource();
  50. } break;
  51. case RESOURCE_COPY: {
  52. _copy_resource();
  53. } break;
  54. case RESOURCE_EDIT_CLIPBOARD: {
  55. _paste_resource();
  56. } break;
  57. case OBJECT_REQUEST_HELP: {
  58. if (current) {
  59. editor->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  60. emit_signal(SNAME("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 (const PropertyInfo &E : props) {
  82. if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
  83. continue;
  84. }
  85. Variant v = current->get(E.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.name, res);
  96. editor->get_inspector()->update_property(E.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(SNAME("Object"), SNAME("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 Transform3D &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(SNAME("New"), SNAME("EditorIcons")));
  278. resource_load_button->set_icon(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")));
  279. resource_save_button->set_icon(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")));
  280. resource_extra_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
  281. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  282. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_theme_icon(SNAME("ActionPaste"), SNAME("EditorIcons")));
  283. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")));
  284. if (is_layout_rtl()) {
  285. backward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons")));
  286. forward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons")));
  287. } else {
  288. backward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons")));
  289. forward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons")));
  290. }
  291. history_menu->set_icon(get_theme_icon(SNAME("History"), SNAME("EditorIcons")));
  292. object_menu->set_icon(get_theme_icon(SNAME("Tools"), SNAME("EditorIcons")));
  293. warning->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")));
  294. warning->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  295. } break;
  296. }
  297. }
  298. void InspectorDock::_bind_methods() {
  299. ClassDB::bind_method("update_keying", &InspectorDock::update_keying);
  300. ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed); // Still used by some connect_compat.
  301. ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource);
  302. ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource);
  303. ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource);
  304. ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall);
  305. ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall);
  306. ADD_SIGNAL(MethodInfo("request_help"));
  307. }
  308. void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
  309. _resource_selected(p_resource, "");
  310. }
  311. void InspectorDock::open_resource(const String &p_type) {
  312. _load_resource(p_type);
  313. }
  314. void InspectorDock::set_warning(const String &p_message) {
  315. warning->hide();
  316. if (p_message != String()) {
  317. warning->show();
  318. warning_dialog->set_text(p_message);
  319. }
  320. }
  321. void InspectorDock::clear() {
  322. }
  323. void InspectorDock::update(Object *p_object) {
  324. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  325. backward_button->set_disabled(editor_history->is_at_beginning());
  326. forward_button->set_disabled(editor_history->is_at_end());
  327. history_menu->set_disabled(true);
  328. if (editor_history->get_history_len() > 0) {
  329. history_menu->set_disabled(false);
  330. }
  331. editor_path->update_path();
  332. current = p_object;
  333. const bool is_object = p_object != nullptr;
  334. const bool is_resource = is_object && p_object->is_class("Resource");
  335. const bool is_node = is_object && p_object->is_class("Node");
  336. object_menu->set_disabled(!is_object);
  337. search->set_editable(is_object);
  338. resource_save_button->set_disabled(!is_resource);
  339. open_docs_button->set_disabled(!is_resource && !is_node);
  340. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  341. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
  342. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource);
  343. if (!is_object) {
  344. warning->hide();
  345. editor_path->clear_path();
  346. return;
  347. }
  348. editor_path->enable_path();
  349. PopupMenu *p = object_menu->get_popup();
  350. p->clear();
  351. p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL);
  352. p->add_icon_shortcut(get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL);
  353. p->add_separator();
  354. p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Properties")), OBJECT_COPY_PARAMS);
  355. p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Properties")), OBJECT_PASTE_PARAMS);
  356. if (is_resource || is_node) {
  357. p->add_separator();
  358. p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
  359. }
  360. List<MethodInfo> methods;
  361. p_object->get_method_list(&methods);
  362. if (!methods.is_empty()) {
  363. bool found = false;
  364. List<MethodInfo>::Element *I = methods.front();
  365. int i = 0;
  366. while (I) {
  367. if (I->get().flags & METHOD_FLAG_EDITOR) {
  368. if (!found) {
  369. p->add_separator();
  370. found = true;
  371. }
  372. p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
  373. }
  374. i++;
  375. I = I->next();
  376. }
  377. }
  378. }
  379. void InspectorDock::go_back() {
  380. _edit_back();
  381. }
  382. void InspectorDock::update_keying() {
  383. bool valid = false;
  384. if (AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
  385. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  386. if (editor_history->get_path_size() >= 1) {
  387. Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0));
  388. if (Object::cast_to<Node>(obj)) {
  389. valid = true;
  390. }
  391. }
  392. }
  393. inspector->set_keying(valid);
  394. }
  395. InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
  396. set_name("Inspector");
  397. set_theme(p_editor->get_gui_base()->get_theme());
  398. editor = p_editor;
  399. editor_data = &p_editor_data;
  400. HBoxContainer *general_options_hb = memnew(HBoxContainer);
  401. add_child(general_options_hb);
  402. resource_new_button = memnew(Button);
  403. resource_new_button->set_flat(true);
  404. resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it."));
  405. resource_new_button->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons")));
  406. general_options_hb->add_child(resource_new_button);
  407. resource_new_button->connect("pressed", callable_mp(this, &InspectorDock::_new_resource));
  408. resource_new_button->set_focus_mode(Control::FOCUS_NONE);
  409. resource_load_button = memnew(Button);
  410. resource_load_button->set_flat(true);
  411. resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it."));
  412. resource_load_button->set_icon(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")));
  413. general_options_hb->add_child(resource_load_button);
  414. resource_load_button->connect("pressed", callable_mp(this, &InspectorDock::_open_resource_selector));
  415. resource_load_button->set_focus_mode(Control::FOCUS_NONE);
  416. resource_save_button = memnew(MenuButton);
  417. resource_save_button->set_tooltip(TTR("Save the currently edited resource."));
  418. resource_save_button->set_icon(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")));
  419. general_options_hb->add_child(resource_save_button);
  420. resource_save_button->get_popup()->add_item(TTR("Save"), RESOURCE_SAVE);
  421. resource_save_button->get_popup()->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
  422. resource_save_button->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
  423. resource_save_button->set_focus_mode(Control::FOCUS_NONE);
  424. resource_save_button->set_disabled(true);
  425. resource_extra_button = memnew(MenuButton);
  426. resource_extra_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
  427. resource_extra_button->set_tooltip(TTR("Extra resource options."));
  428. general_options_hb->add_child(resource_extra_button);
  429. resource_extra_button->get_popup()->add_icon_shortcut(get_theme_icon(SNAME("ActionPaste"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource from Clipboard")), RESOURCE_EDIT_CLIPBOARD);
  430. resource_extra_button->get_popup()->add_icon_shortcut(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
  431. resource_extra_button->get_popup()->set_item_disabled(1, true);
  432. resource_extra_button->get_popup()->add_separator();
  433. resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Resource Built-In")), RESOURCE_MAKE_BUILT_IN);
  434. resource_extra_button->get_popup()->set_item_disabled(3, true);
  435. resource_extra_button->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
  436. general_options_hb->add_spacer();
  437. backward_button = memnew(Button);
  438. backward_button->set_flat(true);
  439. general_options_hb->add_child(backward_button);
  440. if (is_layout_rtl()) {
  441. backward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons")));
  442. } else {
  443. backward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons")));
  444. }
  445. backward_button->set_tooltip(TTR("Go to the previous edited object in history."));
  446. backward_button->set_disabled(true);
  447. backward_button->connect("pressed", callable_mp(this, &InspectorDock::_edit_back));
  448. forward_button = memnew(Button);
  449. forward_button->set_flat(true);
  450. general_options_hb->add_child(forward_button);
  451. if (is_layout_rtl()) {
  452. forward_button->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons")));
  453. } else {
  454. forward_button->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons")));
  455. }
  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(SNAME("History"), SNAME("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 *subresource_hb = memnew(HBoxContainer);
  466. add_child(subresource_hb);
  467. editor_path = memnew(EditorPath(editor->get_editor_history()));
  468. editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  469. subresource_hb->add_child(editor_path);
  470. open_docs_button = memnew(Button);
  471. open_docs_button->set_flat(true);
  472. open_docs_button->set_disabled(true);
  473. open_docs_button->set_tooltip(TTR("Open documentation for this object."));
  474. open_docs_button->set_icon(get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons")));
  475. open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation")));
  476. subresource_hb->add_child(open_docs_button);
  477. open_docs_button->connect("pressed", callable_mp(this, &InspectorDock::_menu_option), varray(OBJECT_REQUEST_HELP));
  478. new_resource_dialog = memnew(CreateDialog);
  479. editor->get_gui_base()->add_child(new_resource_dialog);
  480. new_resource_dialog->set_base_type("Resource");
  481. new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created));
  482. HBoxContainer *property_tools_hb = memnew(HBoxContainer);
  483. add_child(property_tools_hb);
  484. search = memnew(LineEdit);
  485. search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  486. search->set_placeholder(TTR("Filter properties"));
  487. search->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
  488. search->set_clear_button_enabled(true);
  489. property_tools_hb->add_child(search);
  490. object_menu = memnew(MenuButton);
  491. object_menu->set_shortcut_context(this);
  492. object_menu->set_icon(get_theme_icon(SNAME("Tools"), SNAME("EditorIcons")));
  493. property_tools_hb->add_child(object_menu);
  494. object_menu->set_tooltip(TTR("Manage object properties."));
  495. object_menu->get_popup()->connect("id_pressed", callable_mp(this, &InspectorDock::_menu_option));
  496. warning = memnew(Button);
  497. add_child(warning);
  498. warning->set_text(TTR("Changes may be lost!"));
  499. warning->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")));
  500. warning->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  501. warning->set_clip_text(true);
  502. warning->hide();
  503. warning->connect("pressed", callable_mp(this, &InspectorDock::_warning_pressed));
  504. warning_dialog = memnew(AcceptDialog);
  505. editor->get_gui_base()->add_child(warning_dialog);
  506. load_resource_dialog = memnew(EditorFileDialog);
  507. add_child(load_resource_dialog);
  508. load_resource_dialog->set_current_dir("res://");
  509. load_resource_dialog->connect("file_selected", callable_mp(this, &InspectorDock::_resource_file_selected));
  510. inspector = memnew(EditorInspector);
  511. add_child(inspector);
  512. inspector->set_autoclear(true);
  513. inspector->set_show_categories(true);
  514. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  515. inspector->set_use_doc_hints(true);
  516. inspector->set_hide_script(false);
  517. inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
  518. inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
  519. inspector->register_text_enter(search);
  520. inspector->set_undo_redo(&editor_data->get_undo_redo());
  521. inspector->set_use_filter(true); // TODO: check me
  522. inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected));
  523. inspector->connect("property_keyed", callable_mp(this, &InspectorDock::_property_keyed));
  524. }
  525. InspectorDock::~InspectorDock() {
  526. }