inspector_dock.cpp 27 KB

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