inspector_dock.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /**************************************************************************/
  2. /* inspector_dock.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "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::_prepare_menu() {
  35. PopupMenu *menu = object_menu->get_popup();
  36. for (int i = EditorPropertyNameProcessor::STYLE_RAW; i <= EditorPropertyNameProcessor::STYLE_LOCALIZED; i++) {
  37. menu->set_item_checked(menu->get_item_index(PROPERTY_NAME_STYLE_RAW + i), i == property_name_style);
  38. }
  39. }
  40. void InspectorDock::_menu_option(int p_option) {
  41. switch (p_option) {
  42. case EXPAND_ALL: {
  43. _menu_expandall();
  44. } break;
  45. case COLLAPSE_ALL: {
  46. _menu_collapseall();
  47. } break;
  48. case RESOURCE_SAVE: {
  49. _save_resource(false);
  50. } break;
  51. case RESOURCE_SAVE_AS: {
  52. _save_resource(true);
  53. } break;
  54. case RESOURCE_MAKE_BUILT_IN: {
  55. _unref_resource();
  56. } break;
  57. case RESOURCE_COPY: {
  58. _copy_resource();
  59. } break;
  60. case RESOURCE_EDIT_CLIPBOARD: {
  61. _paste_resource();
  62. } break;
  63. case OBJECT_REQUEST_HELP: {
  64. if (current) {
  65. editor->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  66. emit_signal("request_help", current->get_class());
  67. }
  68. } break;
  69. case OBJECT_COPY_PARAMS: {
  70. editor_data->apply_changes_in_editors();
  71. if (current) {
  72. editor_data->copy_object_params(current);
  73. }
  74. } break;
  75. case OBJECT_PASTE_PARAMS: {
  76. editor_data->apply_changes_in_editors();
  77. if (current) {
  78. editor_data->paste_object_params(current);
  79. }
  80. } break;
  81. case OBJECT_UNIQUE_RESOURCES: {
  82. editor_data->apply_changes_in_editors();
  83. if (current) {
  84. List<PropertyInfo> props;
  85. current->get_property_list(&props);
  86. Map<RES, RES> duplicates;
  87. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  88. if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
  89. continue;
  90. }
  91. Variant v = current->get(E->get().name);
  92. if (v.is_ref()) {
  93. REF ref = v;
  94. if (ref.is_valid()) {
  95. RES res = ref;
  96. if (res.is_valid()) {
  97. if (!duplicates.has(res)) {
  98. duplicates[res] = res->duplicate();
  99. }
  100. res = duplicates[res];
  101. current->set(E->get().name, res);
  102. editor->get_inspector()->update_property(E->get().name);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. editor_data->get_undo_redo().clear_history();
  109. editor->get_editor_plugins_over()->edit(nullptr);
  110. editor->get_editor_plugins_over()->edit(current);
  111. } break;
  112. case PROPERTY_NAME_STYLE_RAW:
  113. case PROPERTY_NAME_STYLE_CAPITALIZED:
  114. case PROPERTY_NAME_STYLE_LOCALIZED: {
  115. property_name_style = (EditorPropertyNameProcessor::Style)(p_option - PROPERTY_NAME_STYLE_RAW);
  116. inspector->set_property_name_style(property_name_style);
  117. } break;
  118. default: {
  119. if (p_option >= OBJECT_METHOD_BASE) {
  120. ERR_FAIL_COND(!current);
  121. int idx = p_option - OBJECT_METHOD_BASE;
  122. List<MethodInfo> methods;
  123. current->get_method_list(&methods);
  124. ERR_FAIL_INDEX(idx, methods.size());
  125. String name = methods[idx].name;
  126. current->call(name);
  127. }
  128. }
  129. }
  130. }
  131. void InspectorDock::_new_resource() {
  132. new_resource_dialog->popup_create(true);
  133. }
  134. void InspectorDock::_load_resource(const String &p_type) {
  135. load_resource_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  136. List<String> extensions;
  137. ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions);
  138. load_resource_dialog->clear_filters();
  139. for (int i = 0; i < extensions.size(); i++) {
  140. load_resource_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  141. }
  142. load_resource_dialog->popup_centered_ratio();
  143. }
  144. void InspectorDock::_resource_file_selected(String p_file) {
  145. RES res = ResourceLoader::load(p_file);
  146. if (res.is_null()) {
  147. warning_dialog->set_text(TTR("Failed to load resource."));
  148. return;
  149. };
  150. editor->push_item(res.operator->());
  151. }
  152. void InspectorDock::_save_resource(bool save_as) const {
  153. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  154. Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : nullptr;
  155. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  156. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  157. if (save_as) {
  158. editor->save_resource_as(current_res);
  159. } else {
  160. editor->save_resource(current_res);
  161. }
  162. }
  163. void InspectorDock::_unref_resource() const {
  164. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  165. Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : nullptr;
  166. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  167. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  168. current_res->set_path("");
  169. editor->edit_current();
  170. }
  171. void InspectorDock::_copy_resource() const {
  172. uint32_t current = EditorNode::get_singleton()->get_editor_history()->get_current();
  173. Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : nullptr;
  174. ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
  175. RES current_res = RES(Object::cast_to<Resource>(current_obj));
  176. EditorSettings::get_singleton()->set_resource_clipboard(current_res);
  177. }
  178. void InspectorDock::_paste_resource() const {
  179. RES r = EditorSettings::get_singleton()->get_resource_clipboard();
  180. if (r.is_valid()) {
  181. editor->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String());
  182. }
  183. }
  184. void InspectorDock::_prepare_resource_extra_popup() {
  185. RES r = EditorSettings::get_singleton()->get_resource_clipboard();
  186. PopupMenu *popup = resource_extra_button->get_popup();
  187. popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null());
  188. }
  189. void InspectorDock::_prepare_history() {
  190. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  191. int history_to = MAX(0, editor_history->get_history_len() - 25);
  192. history_menu->get_popup()->clear();
  193. Ref<Texture> base_icon = get_icon("Object", "EditorIcons");
  194. Set<ObjectID> already;
  195. for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) {
  196. ObjectID id = editor_history->get_history_obj(i);
  197. Object *obj = ObjectDB::get_instance(id);
  198. if (!obj || already.has(id)) {
  199. if (history_to > 0) {
  200. history_to--;
  201. }
  202. continue;
  203. }
  204. already.insert(id);
  205. Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj, "");
  206. if (icon.is_null()) {
  207. icon = base_icon;
  208. }
  209. String text;
  210. if (Object::cast_to<Resource>(obj)) {
  211. Resource *r = Object::cast_to<Resource>(obj);
  212. if (r->get_path().is_resource_file()) {
  213. text = r->get_path().get_file();
  214. } else if (r->get_name() != String()) {
  215. text = r->get_name();
  216. } else {
  217. text = r->get_class();
  218. }
  219. } else if (Object::cast_to<Node>(obj)) {
  220. text = Object::cast_to<Node>(obj)->get_name();
  221. } else if (obj->is_class("ScriptEditorDebuggerInspectedObject")) {
  222. text = obj->call("get_title");
  223. } else {
  224. text = obj->get_class();
  225. }
  226. if (i == editor_history->get_history_pos() && current) {
  227. text = "[" + text + "]";
  228. }
  229. history_menu->get_popup()->add_icon_item(icon, text, i);
  230. }
  231. }
  232. void InspectorDock::_select_history(int p_idx) const {
  233. //push it to the top, it is not correct, but it's more useful
  234. ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx);
  235. Object *obj = ObjectDB::get_instance(id);
  236. if (!obj) {
  237. return;
  238. }
  239. editor->push_item(obj);
  240. }
  241. void InspectorDock::_resource_created() const {
  242. Variant c = new_resource_dialog->instance_selected();
  243. ERR_FAIL_COND(!c);
  244. Resource *r = Object::cast_to<Resource>(c);
  245. ERR_FAIL_COND(!r);
  246. editor->push_item(r);
  247. }
  248. void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) const {
  249. if (p_res.is_null()) {
  250. return;
  251. }
  252. RES r = p_res;
  253. editor->push_item(r.operator->(), p_property);
  254. }
  255. void InspectorDock::_edit_forward() {
  256. if (EditorNode::get_singleton()->get_editor_history()->next()) {
  257. editor->edit_current();
  258. }
  259. }
  260. void InspectorDock::_edit_back() {
  261. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  262. if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
  263. editor->edit_current();
  264. }
  265. }
  266. void InspectorDock::_menu_collapseall() {
  267. inspector->collapse_all_folding();
  268. }
  269. void InspectorDock::_menu_expandall() {
  270. inspector->expand_all_folding();
  271. }
  272. void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance) {
  273. AnimationPlayerEditor::singleton->get_track_editor()->insert_value_key(p_keyed, p_value, p_advance);
  274. }
  275. void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) {
  276. Spatial *s = Object::cast_to<Spatial>(sp);
  277. if (!s) {
  278. return;
  279. }
  280. AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key);
  281. }
  282. void InspectorDock::_warning_pressed() {
  283. warning_dialog->popup_centered_minsize();
  284. }
  285. Container *InspectorDock::get_addon_area() {
  286. return this;
  287. }
  288. void InspectorDock::_notification(int p_what) {
  289. switch (p_what) {
  290. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  291. set_theme(editor->get_gui_base()->get_theme());
  292. resource_new_button->set_icon(get_icon("New", "EditorIcons"));
  293. resource_load_button->set_icon(get_icon("Load", "EditorIcons"));
  294. resource_save_button->set_icon(get_icon("Save", "EditorIcons"));
  295. resource_extra_button->set_icon(get_icon("GuiTabMenuHl", "EditorIcons"));
  296. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  297. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_icon("ActionPaste", "EditorIcons"));
  298. resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_icon("ActionCopy", "EditorIcons"));
  299. backward_button->set_icon(get_icon("Back", "EditorIcons"));
  300. forward_button->set_icon(get_icon("Forward", "EditorIcons"));
  301. history_menu->set_icon(get_icon("History", "EditorIcons"));
  302. object_menu->set_icon(get_icon("Tools", "EditorIcons"));
  303. warning->set_icon(get_icon("NodeWarning", "EditorIcons"));
  304. warning->add_color_override("font_color", get_color("warning_color", "Editor"));
  305. } break;
  306. }
  307. }
  308. void InspectorDock::_bind_methods() {
  309. ClassDB::bind_method("_prepare_menu", &InspectorDock::_prepare_menu);
  310. ClassDB::bind_method("_menu_option", &InspectorDock::_menu_option);
  311. ClassDB::bind_method("update_keying", &InspectorDock::update_keying);
  312. ClassDB::bind_method("_property_keyed", &InspectorDock::_property_keyed);
  313. ClassDB::bind_method("_transform_keyed", &InspectorDock::_transform_keyed);
  314. ClassDB::bind_method("_new_resource", &InspectorDock::_new_resource);
  315. ClassDB::bind_method("_resource_file_selected", &InspectorDock::_resource_file_selected);
  316. ClassDB::bind_method("_open_resource_selector", &InspectorDock::_open_resource_selector);
  317. ClassDB::bind_method("_unref_resource", &InspectorDock::_unref_resource);
  318. ClassDB::bind_method("_paste_resource", &InspectorDock::_paste_resource);
  319. ClassDB::bind_method("_copy_resource", &InspectorDock::_copy_resource);
  320. ClassDB::bind_method("_prepare_resource_extra_popup", &InspectorDock::_prepare_resource_extra_popup);
  321. ClassDB::bind_method("_select_history", &InspectorDock::_select_history);
  322. ClassDB::bind_method("_prepare_history", &InspectorDock::_prepare_history);
  323. ClassDB::bind_method("_resource_created", &InspectorDock::_resource_created);
  324. ClassDB::bind_method("_resource_selected", &InspectorDock::_resource_selected, DEFVAL(""));
  325. ClassDB::bind_method("_menu_collapseall", &InspectorDock::_menu_collapseall);
  326. ClassDB::bind_method("_menu_expandall", &InspectorDock::_menu_expandall);
  327. ClassDB::bind_method("_warning_pressed", &InspectorDock::_warning_pressed);
  328. ClassDB::bind_method("_edit_forward", &InspectorDock::_edit_forward);
  329. ClassDB::bind_method("_edit_back", &InspectorDock::_edit_back);
  330. ClassDB::bind_method("store_script_properties", &InspectorDock::store_script_properties);
  331. ClassDB::bind_method("apply_script_properties", &InspectorDock::apply_script_properties);
  332. ADD_SIGNAL(MethodInfo("request_help"));
  333. }
  334. void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
  335. _resource_selected(p_resource, "");
  336. }
  337. void InspectorDock::open_resource(const String &p_type) {
  338. _load_resource(p_type);
  339. }
  340. void InspectorDock::set_warning(const String &p_message) {
  341. warning->hide();
  342. if (p_message != String()) {
  343. warning->show();
  344. warning_dialog->set_text(p_message);
  345. }
  346. }
  347. void InspectorDock::clear() {
  348. }
  349. void InspectorDock::update(Object *p_object) {
  350. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  351. backward_button->set_disabled(editor_history->is_at_beginning());
  352. forward_button->set_disabled(editor_history->is_at_end());
  353. history_menu->set_disabled(true);
  354. if (editor_history->get_history_len() > 0) {
  355. history_menu->set_disabled(false);
  356. }
  357. editor_path->update_path();
  358. current = p_object;
  359. const bool is_object = p_object != nullptr;
  360. const bool is_resource = is_object && p_object->is_class("Resource");
  361. const bool is_node = is_object && p_object->is_class("Node");
  362. object_menu->set_disabled(!is_object);
  363. search->set_editable(is_object);
  364. resource_save_button->set_disabled(!is_resource);
  365. open_docs_button->set_disabled(!is_resource && !is_node);
  366. PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
  367. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
  368. resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource);
  369. if (!is_object) {
  370. warning->hide();
  371. editor_path->clear_path();
  372. return;
  373. }
  374. editor_path->enable_path();
  375. PopupMenu *p = object_menu->get_popup();
  376. p->clear();
  377. p->add_icon_shortcut(get_icon("GuiTreeArrowDown", "EditorIcons"), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL);
  378. p->add_icon_shortcut(get_icon("GuiTreeArrowRight", "EditorIcons"), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL);
  379. p->add_separator(TTR("Property Name Style"));
  380. p->add_radio_check_item(TTR("Raw"), PROPERTY_NAME_STYLE_RAW);
  381. p->add_radio_check_item(TTR("Capitalized"), PROPERTY_NAME_STYLE_CAPITALIZED);
  382. p->add_radio_check_item(TTR("Localized"), PROPERTY_NAME_STYLE_LOCALIZED);
  383. if (!EditorPropertyNameProcessor::is_localization_available()) {
  384. const int index = p->get_item_index(PROPERTY_NAME_STYLE_LOCALIZED);
  385. p->set_item_disabled(index, true);
  386. p->set_item_tooltip(index, TTR("Localization not available for current language."));
  387. }
  388. p->add_separator();
  389. p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Properties")), OBJECT_COPY_PARAMS);
  390. p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Properties")), OBJECT_PASTE_PARAMS);
  391. if (is_resource || is_node) {
  392. p->add_separator();
  393. p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
  394. }
  395. List<MethodInfo> methods;
  396. p_object->get_method_list(&methods);
  397. if (!methods.empty()) {
  398. bool found = false;
  399. List<MethodInfo>::Element *I = methods.front();
  400. int i = 0;
  401. while (I) {
  402. if (I->get().flags & METHOD_FLAG_EDITOR) {
  403. if (!found) {
  404. p->add_separator();
  405. found = true;
  406. }
  407. p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
  408. }
  409. i++;
  410. I = I->next();
  411. }
  412. }
  413. }
  414. void InspectorDock::go_back() {
  415. _edit_back();
  416. }
  417. void InspectorDock::update_keying() {
  418. bool valid = false;
  419. if (AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
  420. EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
  421. if (editor_history->get_path_size() >= 1) {
  422. Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0));
  423. if (Object::cast_to<Node>(obj)) {
  424. valid = true;
  425. }
  426. }
  427. }
  428. inspector->set_keying(valid);
  429. }
  430. EditorPropertyNameProcessor::Style InspectorDock::get_property_name_style() const {
  431. return property_name_style;
  432. }
  433. void InspectorDock::store_script_properties(Object *p_object) {
  434. ERR_FAIL_NULL(p_object);
  435. ScriptInstance *si = p_object->get_script_instance();
  436. if (!si) {
  437. return;
  438. }
  439. si->get_property_state(stored_properties);
  440. }
  441. void InspectorDock::apply_script_properties(Object *p_object) {
  442. ERR_FAIL_NULL(p_object);
  443. ScriptInstance *si = p_object->get_script_instance();
  444. if (!si) {
  445. return;
  446. }
  447. for (List<Pair<StringName, Variant>>::Element *E = stored_properties.front(); E; E = E->next()) {
  448. const Pair<StringName, Variant> &p = E->get();
  449. Variant current;
  450. if (si->get(p.first, current) && current.get_type() == p.second.get_type()) {
  451. si->set(p.first, p.second);
  452. }
  453. }
  454. stored_properties.clear();
  455. }
  456. InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
  457. set_name("Inspector");
  458. set_theme(p_editor->get_gui_base()->get_theme());
  459. editor = p_editor;
  460. editor_data = &p_editor_data;
  461. property_name_style = EditorPropertyNameProcessor::get_default_inspector_style();
  462. HBoxContainer *general_options_hb = memnew(HBoxContainer);
  463. add_child(general_options_hb);
  464. resource_new_button = memnew(ToolButton);
  465. resource_new_button->set_tooltip(TTR("Create a new resource in memory and edit it."));
  466. resource_new_button->set_icon(get_icon("New", "EditorIcons"));
  467. general_options_hb->add_child(resource_new_button);
  468. resource_new_button->connect("pressed", this, "_new_resource");
  469. resource_new_button->set_focus_mode(Control::FOCUS_NONE);
  470. resource_load_button = memnew(ToolButton);
  471. resource_load_button->set_tooltip(TTR("Load an existing resource from disk and edit it."));
  472. resource_load_button->set_icon(get_icon("Load", "EditorIcons"));
  473. general_options_hb->add_child(resource_load_button);
  474. resource_load_button->connect("pressed", this, "_open_resource_selector");
  475. resource_load_button->set_focus_mode(Control::FOCUS_NONE);
  476. resource_save_button = memnew(MenuButton);
  477. resource_save_button->set_tooltip(TTR("Save the currently edited resource."));
  478. resource_save_button->set_icon(get_icon("Save", "EditorIcons"));
  479. general_options_hb->add_child(resource_save_button);
  480. resource_save_button->get_popup()->add_item(TTR("Save"), RESOURCE_SAVE);
  481. resource_save_button->get_popup()->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
  482. resource_save_button->get_popup()->connect("id_pressed", this, "_menu_option");
  483. resource_save_button->set_focus_mode(Control::FOCUS_NONE);
  484. resource_save_button->set_disabled(true);
  485. resource_extra_button = memnew(MenuButton);
  486. resource_extra_button->set_icon(get_icon("GuiTabMenuHl", "EditorIcons"));
  487. resource_extra_button->set_tooltip(TTR("Extra resource options."));
  488. general_options_hb->add_child(resource_extra_button);
  489. resource_extra_button->connect("about_to_show", this, "_prepare_resource_extra_popup");
  490. 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);
  491. resource_extra_button->get_popup()->add_icon_shortcut(get_icon("ActionCopy", "EditorIcons"), ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
  492. resource_extra_button->get_popup()->set_item_disabled(1, true);
  493. resource_extra_button->get_popup()->add_separator();
  494. resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Resource Built-In")), RESOURCE_MAKE_BUILT_IN);
  495. resource_extra_button->get_popup()->set_item_disabled(3, true);
  496. resource_extra_button->get_popup()->connect("id_pressed", this, "_menu_option");
  497. general_options_hb->add_spacer();
  498. backward_button = memnew(ToolButton);
  499. general_options_hb->add_child(backward_button);
  500. backward_button->set_icon(get_icon("Back", "EditorIcons"));
  501. backward_button->set_flat(true);
  502. backward_button->set_tooltip(TTR("Go to the previous edited object in history."));
  503. backward_button->set_disabled(true);
  504. backward_button->connect("pressed", this, "_edit_back");
  505. forward_button = memnew(ToolButton);
  506. general_options_hb->add_child(forward_button);
  507. forward_button->set_icon(get_icon("Forward", "EditorIcons"));
  508. forward_button->set_flat(true);
  509. forward_button->set_tooltip(TTR("Go to the next edited object in history."));
  510. forward_button->set_disabled(true);
  511. forward_button->connect("pressed", this, "_edit_forward");
  512. history_menu = memnew(MenuButton);
  513. history_menu->set_tooltip(TTR("History of recently edited objects."));
  514. history_menu->set_icon(get_icon("History", "EditorIcons"));
  515. general_options_hb->add_child(history_menu);
  516. history_menu->connect("about_to_show", this, "_prepare_history");
  517. history_menu->get_popup()->connect("id_pressed", this, "_select_history");
  518. HBoxContainer *subresource_hb = memnew(HBoxContainer);
  519. add_child(subresource_hb);
  520. editor_path = memnew(EditorPath(editor->get_editor_history()));
  521. editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  522. subresource_hb->add_child(editor_path);
  523. open_docs_button = memnew(Button);
  524. open_docs_button->set_flat(true);
  525. open_docs_button->set_disabled(true);
  526. open_docs_button->set_tooltip(TTR("Open documentation for this object."));
  527. open_docs_button->set_icon(get_icon("HelpSearch", "EditorIcons"));
  528. open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation")));
  529. subresource_hb->add_child(open_docs_button);
  530. open_docs_button->connect("pressed", this, "_menu_option", varray(OBJECT_REQUEST_HELP));
  531. new_resource_dialog = memnew(CreateDialog);
  532. editor->get_gui_base()->add_child(new_resource_dialog);
  533. new_resource_dialog->set_base_type("Resource");
  534. new_resource_dialog->connect("create", this, "_resource_created");
  535. HBoxContainer *property_tools_hb = memnew(HBoxContainer);
  536. add_child(property_tools_hb);
  537. search = memnew(LineEdit);
  538. search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  539. search->set_placeholder(TTR("Filter properties"));
  540. search->set_right_icon(get_icon("Search", "EditorIcons"));
  541. search->set_clear_button_enabled(true);
  542. property_tools_hb->add_child(search);
  543. object_menu = memnew(MenuButton);
  544. object_menu->set_icon(get_icon("Tools", "EditorIcons"));
  545. property_tools_hb->add_child(object_menu);
  546. object_menu->set_tooltip(TTR("Manage object properties."));
  547. object_menu->get_popup()->connect("about_to_show", this, "_prepare_menu");
  548. object_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  549. warning = memnew(Button);
  550. add_child(warning);
  551. warning->set_text(TTR("Changes may be lost!"));
  552. warning->set_icon(get_icon("NodeWarning", "EditorIcons"));
  553. warning->add_color_override("font_color", get_color("warning_color", "Editor"));
  554. warning->set_clip_text(true);
  555. warning->hide();
  556. warning->connect("pressed", this, "_warning_pressed");
  557. warning_dialog = memnew(AcceptDialog);
  558. editor->get_gui_base()->add_child(warning_dialog);
  559. load_resource_dialog = memnew(EditorFileDialog);
  560. add_child(load_resource_dialog);
  561. load_resource_dialog->set_current_dir("res://");
  562. load_resource_dialog->connect("file_selected", this, "_resource_file_selected");
  563. inspector = memnew(EditorInspector);
  564. add_child(inspector);
  565. inspector->set_autoclear(true);
  566. inspector->set_show_categories(true);
  567. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  568. inspector->set_use_doc_hints(true);
  569. inspector->set_hide_script(false);
  570. inspector->set_property_name_style(EditorPropertyNameProcessor::get_default_inspector_style());
  571. inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
  572. inspector->register_text_enter(search);
  573. inspector->set_undo_redo(&editor_data->get_undo_redo());
  574. inspector->set_use_filter(true); // TODO: check me
  575. inspector->connect("resource_selected", this, "_resource_selected");
  576. inspector->connect("property_keyed", this, "_property_keyed");
  577. }
  578. InspectorDock::~InspectorDock() {
  579. }