inspector_dock.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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("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_mode(EditorFileDialog::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_centered_ratio();
  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) const {
  141. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  142. Object *current_obj = current > 0 ? 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() const {
  152. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  153. Object *current_obj = current > 0 ? 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() const {
  160. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  161. Object *current_obj = current > 0 ? 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() const {
  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_resource_extra_popup() {
  173. RES r = EditorSettings::get_singleton()->get_resource_clipboard();
  174. PopupMenu *popup = resource_extra_button->get_popup();
  175. popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null());
  176. }
  177. void InspectorDock::_prepare_history() {
  178. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  179. int history_to = MAX(0, editor_history->get_history_len() - 25);
  180. history_menu->get_popup()->clear();
  181. Ref<Texture> base_icon = get_icon("Object", "EditorIcons");
  182. Set<ObjectID> already;
  183. for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) {
  184. ObjectID id = editor_history->get_history_obj(i);
  185. Object *obj = ObjectDB::get_instance(id);
  186. if (!obj || already.has(id)) {
  187. if (history_to > 0) {
  188. history_to--;
  189. }
  190. continue;
  191. }
  192. already.insert(id);
  193. Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj, "");
  194. if (icon.is_null()) {
  195. icon = base_icon;
  196. }
  197. String text;
  198. if (Object::cast_to<Resource>(obj)) {
  199. Resource *r = Object::cast_to<Resource>(obj);
  200. if (r->get_path().is_resource_file()) {
  201. text = r->get_path().get_file();
  202. } else if (r->get_name() != String()) {
  203. text = r->get_name();
  204. } else {
  205. text = r->get_class();
  206. }
  207. } else if (Object::cast_to<Node>(obj)) {
  208. text = Object::cast_to<Node>(obj)->get_name();
  209. } else if (obj->is_class("ScriptEditorDebuggerInspectedObject")) {
  210. text = obj->call("get_title");
  211. } else {
  212. text = obj->get_class();
  213. }
  214. if (i == editor_history->get_history_pos() && current) {
  215. text = "[" + text + "]";
  216. }
  217. history_menu->get_popup()->add_icon_item(icon, text, i);
  218. }
  219. }
  220. void InspectorDock::_select_history(int p_idx) const {
  221. //push it to the top, it is not correct, but it's more useful
  222. ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx);
  223. Object *obj = ObjectDB::get_instance(id);
  224. if (!obj) {
  225. return;
  226. }
  227. editor->push_item(obj);
  228. }
  229. void InspectorDock::_resource_created() const {
  230. Variant c = new_resource_dialog->instance_selected();
  231. ERR_FAIL_COND(!c);
  232. Resource *r = Object::cast_to<Resource>(c);
  233. ERR_FAIL_COND(!r);
  234. editor->push_item(r);
  235. }
  236. void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) const {
  237. if (p_res.is_null()) {
  238. return;
  239. }
  240. RES r = p_res;
  241. editor->push_item(r.operator->(), p_property);
  242. }
  243. void InspectorDock::_edit_forward() {
  244. if (EditorNode::get_singleton()->get_editor_history()->next()) {
  245. editor->edit_current();
  246. }
  247. }
  248. void InspectorDock::_edit_back() {
  249. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  250. if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
  251. editor->edit_current();
  252. }
  253. }
  254. void InspectorDock::_menu_collapseall() {
  255. inspector->collapse_all_folding();
  256. }
  257. void InspectorDock::_menu_expandall() {
  258. inspector->expand_all_folding();
  259. }
  260. void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance) {
  261. AnimationPlayerEditor::singleton->get_track_editor()->insert_value_key(p_keyed, p_value, p_advance);
  262. }
  263. void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) {
  264. Spatial *s = Object::cast_to<Spatial>(sp);
  265. if (!s) {
  266. return;
  267. }
  268. AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key);
  269. }
  270. void InspectorDock::_warning_pressed() {
  271. warning_dialog->popup_centered_minsize();
  272. }
  273. Container *InspectorDock::get_addon_area() {
  274. return this;
  275. }
  276. void InspectorDock::_notification(int p_what) {
  277. switch (p_what) {
  278. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  279. set_theme(editor->get_gui_base()->get_theme());
  280. resource_new_button->set_icon(get_icon("New", "EditorIcons"));
  281. resource_load_button->set_icon(get_icon("Load", "EditorIcons"));
  282. resource_save_button->set_icon(get_icon("Save", "EditorIcons"));
  283. resource_extra_button->set_icon(get_icon("GuiTabMenuHl", "EditorIcons"));
  284. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  285. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_icon("ActionPaste", "EditorIcons"));
  286. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_icon("ActionCopy", "EditorIcons"));
  287. backward_button->set_icon(get_icon("Back", "EditorIcons"));
  288. forward_button->set_icon(get_icon("Forward", "EditorIcons"));
  289. history_menu->set_icon(get_icon("History", "EditorIcons"));
  290. object_menu->set_icon(get_icon("Tools", "EditorIcons"));
  291. warning->set_icon(get_icon("NodeWarning", "EditorIcons"));
  292. warning->add_color_override("font_color", get_color("warning_color", "Editor"));
  293. } break;
  294. }
  295. }
  296. void InspectorDock::_bind_methods() {
  297. ClassDB::bind_method("_menu_option", &InspectorDock::_menu_option);
  298. ClassDB::bind_method("update_keying", &InspectorDock::update_keying);
  299. ClassDB::bind_method("_property_keyed", &InspectorDock::_property_keyed);
  300. ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed);
  301. ClassDB::bind_method("_new_resource", &InspectorDock::_new_resource);
  302. ClassDB::bind_method("_resource_file_selected", &InspectorDock::_resource_file_selected);
  303. ClassDB::bind_method("_open_resource_selector", &InspectorDock::_open_resource_selector);
  304. ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource);
  305. ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource);
  306. ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource);
  307. ClassDB::bind_method("_prepare_resource_extra_popup", &InspectorDock::_prepare_resource_extra_popup);
  308. ClassDB::bind_method("_select_history", &InspectorDock::_select_history);
  309. ClassDB::bind_method("_prepare_history", &InspectorDock::_prepare_history);
  310. ClassDB::bind_method("_resource_created", &InspectorDock::_resource_created);
  311. ClassDB::bind_method("_resource_selected", &InspectorDock::_resource_selected, DEFVAL(""));
  312. ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall);
  313. ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall);
  314. ClassDB::bind_method("_warning_pressed", &InspectorDock::_warning_pressed);
  315. ClassDB::bind_method("_edit_forward", &InspectorDock::_edit_forward);
  316. ClassDB::bind_method("_edit_back", &InspectorDock::_edit_back);
  317. ADD_SIGNAL(MethodInfo("request_help"));
  318. }
  319. void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
  320. _resource_selected(p_resource, "");
  321. }
  322. void InspectorDock::open_resource(const String &p_type) {
  323. _load_resource(p_type);
  324. }
  325. void InspectorDock::set_warning(const String &p_message) {
  326. warning->hide();
  327. if (p_message != String()) {
  328. warning->show();
  329. warning_dialog->set_text(p_message);
  330. }
  331. }
  332. void InspectorDock::clear() {
  333. }
  334. void InspectorDock::update(Object *p_object) {
  335. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  336. backward_button->set_disabled(editor_history->is_at_beginning());
  337. forward_button->set_disabled(editor_history->is_at_end());
  338. history_menu->set_disabled(true);
  339. if (editor_history->get_history_len() > 0) {
  340. history_menu->set_disabled(false);
  341. }
  342. editor_path->update_path();
  343. current = p_object;
  344. const bool is_object = p_object != nullptr;
  345. const bool is_resource = is_object && p_object->is_class("Resource");
  346. const bool is_node = is_object && p_object->is_class("Node");
  347. object_menu->set_disabled(!is_object);
  348. search->set_editable(is_object);
  349. resource_save_button->set_disabled(!is_resource);
  350. open_docs_button->set_disabled(!is_resource && !is_node);
  351. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  352. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
  353. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource);
  354. if (!is_object) {
  355. warning->hide();
  356. editor_path->clear_path();
  357. return;
  358. }
  359. editor_path->enable_path();
  360. PopupMenu *p = object_menu->get_popup();
  361. p->clear();
  362. p->add_icon_shortcut(get_icon("GuiTreeArrowDown", "EditorIcons"), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL);
  363. p->add_icon_shortcut(get_icon("GuiTreeArrowRight", "EditorIcons"), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL);
  364. p->add_separator();
  365. p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Properties")), OBJECT_COPY_PARAMS);
  366. p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Properties")), OBJECT_PASTE_PARAMS);
  367. if (is_resource || is_node) {
  368. p->add_separator();
  369. p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
  370. }
  371. List<MethodInfo> methods;
  372. p_object->get_method_list(&methods);
  373. if (!methods.empty()) {
  374. bool found = false;
  375. List<MethodInfo>::Element *I = methods.front();
  376. int i = 0;
  377. while (I) {
  378. if (I->get().flags & METHOD_FLAG_EDITOR) {
  379. if (!found) {
  380. p->add_separator();
  381. found = true;
  382. }
  383. p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
  384. }
  385. i++;
  386. I = I->next();
  387. }
  388. }
  389. }
  390. void InspectorDock::go_back() {
  391. _edit_back();
  392. }
  393. void InspectorDock::update_keying() {
  394. bool valid = false;
  395. if (AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
  396. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  397. if (editor_history->get_path_size() >= 1) {
  398. Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0));
  399. if (Object::cast_to<Node>(obj)) {
  400. valid = true;
  401. }
  402. }
  403. }
  404. inspector->set_keying(valid);
  405. }
  406. InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
  407. set_name("Inspector");
  408. set_theme(p_editor->get_gui_base()->get_theme());
  409. editor = p_editor;
  410. editor_data = &p_editor_data;
  411. HBoxContainer *general_options_hb = memnew(HBoxContainer);
  412. add_child(general_options_hb);
  413. resource_new_button = memnew(ToolButton);
  414. resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it."));
  415. resource_new_button->set_icon(get_icon("New", "EditorIcons"));
  416. general_options_hb->add_child(resource_new_button);
  417. resource_new_button->connect("pressed", this, "_new_resource");
  418. resource_new_button->set_focus_mode(Control::FOCUS_NONE);
  419. resource_load_button = memnew(ToolButton);
  420. resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it."));
  421. resource_load_button->set_icon(get_icon("Load", "EditorIcons"));
  422. general_options_hb->add_child(resource_load_button);
  423. resource_load_button->connect("pressed", this, "_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_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", this, "_menu_option");
  432. resource_save_button->set_focus_mode(Control::FOCUS_NONE);
  433. resource_save_button->set_disabled(true);
  434. resource_extra_button = memnew(MenuButton);
  435. resource_extra_button->set_icon(get_icon("GuiTabMenuHl", "EditorIcons"));
  436. resource_extra_button->set_tooltip(TTR("Extra resource options."));
  437. general_options_hb->add_child(resource_extra_button);
  438. resource_extra_button->connect("about_to_show", this, "_prepare_resource_extra_popup");
  439. resource_extra_button->get_popup()->add_icon_shortcut(get_icon("ActionPaste", "EditorIcons"), ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource from Clipboard")), RESOURCE_EDIT_CLIPBOARD);
  440. resource_extra_button->get_popup()->add_icon_shortcut(get_icon("ActionCopy", "EditorIcons"), ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
  441. resource_extra_button->get_popup()->set_item_disabled(1, true);
  442. resource_extra_button->get_popup()->add_separator();
  443. resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Resource Built-In")), RESOURCE_MAKE_BUILT_IN);
  444. resource_extra_button->get_popup()->set_item_disabled(3, true);
  445. resource_extra_button->get_popup()->connect("id_pressed", this, "_menu_option");
  446. general_options_hb->add_spacer();
  447. backward_button = memnew(ToolButton);
  448. general_options_hb->add_child(backward_button);
  449. backward_button->set_icon(get_icon("Back", "EditorIcons"));
  450. backward_button->set_flat(true);
  451. backward_button->set_tooltip(TTR("Go to the previous edited object in history."));
  452. backward_button->set_disabled(true);
  453. backward_button->connect("pressed", this, "_edit_back");
  454. forward_button = memnew(ToolButton);
  455. general_options_hb->add_child(forward_button);
  456. forward_button->set_icon(get_icon("Forward", "EditorIcons"));
  457. forward_button->set_flat(true);
  458. forward_button->set_tooltip(TTR("Go to the next edited object in history."));
  459. forward_button->set_disabled(true);
  460. forward_button->connect("pressed", this, "_edit_forward");
  461. history_menu = memnew(MenuButton);
  462. history_menu->set_tooltip(TTR("History of recently edited objects."));
  463. history_menu->set_icon(get_icon("History", "EditorIcons"));
  464. general_options_hb->add_child(history_menu);
  465. history_menu->connect("about_to_show", this, "_prepare_history");
  466. history_menu->get_popup()->connect("id_pressed", this, "_select_history");
  467. HBoxContainer *subresource_hb = memnew(HBoxContainer);
  468. add_child(subresource_hb);
  469. editor_path = memnew(EditorPath(editor->get_editor_history()));
  470. editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  471. subresource_hb->add_child(editor_path);
  472. open_docs_button = memnew(Button);
  473. open_docs_button->set_flat(true);
  474. open_docs_button->set_disabled(true);
  475. open_docs_button->set_tooltip(TTR("Open documentation for this object."));
  476. open_docs_button->set_icon(get_icon("HelpSearch", "EditorIcons"));
  477. open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation")));
  478. subresource_hb->add_child(open_docs_button);
  479. open_docs_button->connect("pressed", this, "_menu_option", varray(OBJECT_REQUEST_HELP));
  480. new_resource_dialog = memnew(CreateDialog);
  481. editor->get_gui_base()->add_child(new_resource_dialog);
  482. new_resource_dialog->set_base_type("Resource");
  483. new_resource_dialog->connect("create", this, "_resource_created");
  484. HBoxContainer *property_tools_hb = memnew(HBoxContainer);
  485. add_child(property_tools_hb);
  486. search = memnew(LineEdit);
  487. search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  488. search->set_placeholder(TTR("Filter properties"));
  489. search->set_right_icon(get_icon("Search", "EditorIcons"));
  490. search->set_clear_button_enabled(true);
  491. property_tools_hb->add_child(search);
  492. object_menu = memnew(MenuButton);
  493. object_menu->set_icon(get_icon("Tools", "EditorIcons"));
  494. property_tools_hb->add_child(object_menu);
  495. object_menu->set_tooltip(TTR("Manage object properties."));
  496. object_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  497. warning = memnew(Button);
  498. add_child(warning);
  499. warning->set_text(TTR("Changes may be lost!"));
  500. warning->set_icon(get_icon("NodeWarning", "EditorIcons"));
  501. warning->add_color_override("font_color", get_color("warning_color", "Editor"));
  502. warning->set_clip_text(true);
  503. warning->hide();
  504. warning->connect("pressed", this, "_warning_pressed");
  505. warning_dialog = memnew(AcceptDialog);
  506. editor->get_gui_base()->add_child(warning_dialog);
  507. load_resource_dialog = memnew(EditorFileDialog);
  508. add_child(load_resource_dialog);
  509. load_resource_dialog->set_current_dir("res://");
  510. load_resource_dialog->connect("file_selected", this, "_resource_file_selected");
  511. inspector = memnew(EditorInspector);
  512. add_child(inspector);
  513. inspector->set_autoclear(true);
  514. inspector->set_show_categories(true);
  515. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  516. inspector->set_use_doc_hints(true);
  517. inspector->set_hide_script(false);
  518. inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
  519. inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
  520. inspector->register_text_enter(search);
  521. inspector->set_undo_redo(&editor_data->get_undo_redo());
  522. inspector->set_use_filter(true); // TODO: check me
  523. inspector->connect("resource_selected", this, "_resource_selected");
  524. inspector->connect("property_keyed", this, "_property_keyed");
  525. }
  526. InspectorDock::~InspectorDock() {
  527. }