create_dialog.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*************************************************************************/
  2. /* create_dialog.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "create_dialog.h"
  31. #include "core/class_db.h"
  32. #include "core/os/keyboard.h"
  33. #include "core/print_string.h"
  34. #include "editor_help.h"
  35. #include "editor_node.h"
  36. #include "editor_settings.h"
  37. #include "scene/gui/box_container.h"
  38. void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode) {
  39. type_list.clear();
  40. ClassDB::get_class_list(&type_list);
  41. ScriptServer::get_global_class_list(&type_list);
  42. type_list.sort_custom<StringName::AlphCompare>();
  43. recent->clear();
  44. FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ);
  45. if (f) {
  46. TreeItem *root = recent->create_item();
  47. while (!f->eof_reached()) {
  48. String l = f->get_line().strip_edges();
  49. String name = l.split(" ")[0];
  50. if (ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) {
  51. TreeItem *ti = recent->create_item(root);
  52. ti->set_text(0, l);
  53. ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type));
  54. }
  55. }
  56. memdelete(f);
  57. }
  58. favorites->clear();
  59. f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::READ);
  60. favorite_list.clear();
  61. if (f) {
  62. while (!f->eof_reached()) {
  63. String l = f->get_line().strip_edges();
  64. if (l != String()) {
  65. favorite_list.push_back(l);
  66. }
  67. }
  68. memdelete(f);
  69. }
  70. _save_and_update_favorite_list();
  71. // Restore valid window bounds or pop up at default size.
  72. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", Rect2());
  73. if (saved_size != Rect2()) {
  74. popup(saved_size);
  75. } else {
  76. Size2 popup_size = Size2(900, 700) * editor_get_scale();
  77. Size2 window_size = get_viewport_rect().size;
  78. popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
  79. popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
  80. popup_centered(popup_size);
  81. }
  82. if (p_dont_clear) {
  83. search_box->select_all();
  84. } else {
  85. search_box->clear();
  86. }
  87. search_box->grab_focus();
  88. _update_search();
  89. bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines");
  90. Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color");
  91. if (enable_rl) {
  92. search_options->add_constant_override("draw_relationship_lines", 1);
  93. search_options->add_color_override("relationship_line_color", rl_color);
  94. search_options->add_constant_override("draw_guides", 0);
  95. } else {
  96. search_options->add_constant_override("draw_relationship_lines", 0);
  97. search_options->add_constant_override("draw_guides", 1);
  98. }
  99. is_replace_mode = p_replace_mode;
  100. if (p_replace_mode) {
  101. set_title(vformat(TTR("Change %s Type"), base_type));
  102. get_ok()->set_text(TTR("Change"));
  103. } else {
  104. set_title(vformat(TTR("Create New %s"), base_type));
  105. get_ok()->set_text(TTR("Create"));
  106. }
  107. }
  108. void CreateDialog::_text_changed(const String &p_newtext) {
  109. _update_search();
  110. }
  111. void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
  112. Ref<InputEventKey> k = p_ie;
  113. if (k.is_valid() && (k->get_scancode() == KEY_UP ||
  114. k->get_scancode() == KEY_DOWN ||
  115. k->get_scancode() == KEY_PAGEUP ||
  116. k->get_scancode() == KEY_PAGEDOWN)) {
  117. search_options->call("_gui_input", k);
  118. search_box->accept_event();
  119. }
  120. }
  121. void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) {
  122. if (p_types.has(p_type))
  123. return;
  124. bool cpp_type = ClassDB::class_exists(p_type);
  125. EditorData &ed = EditorNode::get_editor_data();
  126. if (p_type == base_type)
  127. return;
  128. if (cpp_type) {
  129. if (!ClassDB::is_parent_class(p_type, base_type))
  130. return;
  131. } else {
  132. if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type))
  133. return;
  134. String script_path = ScriptServer::get_global_class_path(p_type);
  135. if (script_path.find("res://addons/", 0) != -1) {
  136. if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3)))
  137. return;
  138. }
  139. }
  140. String inherits = cpp_type ? ClassDB::get_parent_class(p_type) : ed.script_class_get_base(p_type);
  141. TreeItem *parent = p_root;
  142. if (inherits.length()) {
  143. if (!p_types.has(inherits)) {
  144. add_type(inherits, p_types, p_root, to_select);
  145. }
  146. if (p_types.has(inherits))
  147. parent = p_types[inherits];
  148. else if (ScriptServer::is_global_class(inherits))
  149. return;
  150. }
  151. bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);
  152. TreeItem *item = search_options->create_item(parent);
  153. if (cpp_type) {
  154. item->set_text(0, p_type);
  155. } else {
  156. item->set_metadata(0, p_type);
  157. item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
  158. }
  159. if (!can_instance) {
  160. item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
  161. item->set_selectable(0, false);
  162. } else {
  163. bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type);
  164. String to_select_type = *to_select ? (*to_select)->get_text(0) : "";
  165. to_select_type = to_select_type.split(" ")[0];
  166. bool current_item_is_preferred;
  167. if (cpp_type) {
  168. String cpp_to_select_type = to_select_type;
  169. if (ScriptServer::is_global_class(to_select_type))
  170. cpp_to_select_type = ScriptServer::get_global_class_base(to_select_type);
  171. current_item_is_preferred = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(cpp_to_select_type, preferred_search_result_type);
  172. } else {
  173. current_item_is_preferred = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type) && search_box->get_text() != to_select_type;
  174. }
  175. if (*to_select && p_type.length() < (*to_select)->get_text(0).length()) {
  176. current_item_is_preferred = true;
  177. }
  178. if (((!*to_select || current_item_is_preferred) && is_search_subsequence) || search_box->get_text() == p_type) {
  179. *to_select = item;
  180. }
  181. }
  182. if (bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) {
  183. item->set_collapsed(false);
  184. } else {
  185. // don't collapse search results
  186. bool collapse = (search_box->get_text() == "");
  187. // don't collapse the root node
  188. collapse &= (item != p_root);
  189. // don't collapse abstract nodes on the first tree level
  190. collapse &= ((parent != p_root) || (can_instance));
  191. item->set_collapsed(collapse);
  192. }
  193. const String &description = EditorHelp::get_doc_data()->class_list[p_type].brief_description;
  194. item->set_tooltip(0, description);
  195. item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, base_type));
  196. p_types[p_type] = item;
  197. }
  198. void CreateDialog::_update_search() {
  199. search_options->clear();
  200. favorite->set_disabled(true);
  201. help_bit->set_text("");
  202. /*
  203. TreeItem *root = search_options->create_item();
  204. _parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
  205. */
  206. HashMap<String, TreeItem *> types;
  207. TreeItem *root = search_options->create_item();
  208. EditorData &ed = EditorNode::get_editor_data();
  209. root->set_text(0, base_type);
  210. if (has_icon(base_type, "EditorIcons")) {
  211. root->set_icon(0, get_icon(base_type, "EditorIcons"));
  212. }
  213. TreeItem *to_select = search_box->get_text() == base_type ? root : NULL;
  214. for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {
  215. String type = I->get();
  216. bool cpp_type = ClassDB::class_exists(type);
  217. if (base_type == "Node" && type.begins_with("Editor"))
  218. continue; // do not show editor nodes
  219. if (cpp_type && !ClassDB::can_instance(type))
  220. continue; // can't create what can't be instanced
  221. bool skip = false;
  222. if (cpp_type) {
  223. for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
  224. if (ClassDB::is_parent_class(type, E->get()))
  225. skip = true;
  226. }
  227. if (skip)
  228. continue;
  229. }
  230. if (search_box->get_text() == "") {
  231. add_type(type, types, root, &to_select);
  232. } else {
  233. bool found = false;
  234. String type = I->get();
  235. while (type != "" && (cpp_type ? ClassDB::is_parent_class(type, base_type) : ed.script_class_is_parent(type, base_type)) && type != base_type) {
  236. if (search_box->get_text().is_subsequence_ofi(type)) {
  237. found = true;
  238. break;
  239. }
  240. type = cpp_type ? ClassDB::get_parent_class(type) : ed.script_class_get_base(type);
  241. }
  242. if (found)
  243. add_type(I->get(), types, root, &to_select);
  244. }
  245. if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) {
  246. //there are custom types based on this... cool.
  247. const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
  248. for (int i = 0; i < ct.size(); i++) {
  249. bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);
  250. if (!show)
  251. continue;
  252. if (!types.has(type))
  253. add_type(type, types, root, &to_select);
  254. TreeItem *ti;
  255. if (types.has(type))
  256. ti = types[type];
  257. else
  258. ti = search_options->get_root();
  259. TreeItem *item = search_options->create_item(ti);
  260. item->set_metadata(0, type);
  261. item->set_text(0, ct[i].name);
  262. if (ct[i].icon.is_valid()) {
  263. item->set_icon(0, ct[i].icon);
  264. }
  265. if (!to_select || ct[i].name == search_box->get_text()) {
  266. to_select = item;
  267. }
  268. }
  269. }
  270. }
  271. if (search_box->get_text() == "") {
  272. to_select = root;
  273. }
  274. if (to_select) {
  275. to_select->select(0);
  276. search_options->scroll_to_item(to_select);
  277. favorite->set_disabled(false);
  278. favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1);
  279. }
  280. get_ok()->set_disabled(root->get_children() == NULL);
  281. }
  282. void CreateDialog::_confirmed() {
  283. TreeItem *ti = search_options->get_selected();
  284. if (!ti)
  285. return;
  286. FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE);
  287. if (f) {
  288. f->store_line(get_selected_type());
  289. TreeItem *t = recent->get_root();
  290. if (t)
  291. t = t->get_children();
  292. int count = 0;
  293. while (t) {
  294. if (t->get_text(0) != get_selected_type()) {
  295. f->store_line(t->get_text(0));
  296. }
  297. if (count > 32) {
  298. //limit it to 32 entries..
  299. break;
  300. }
  301. t = t->get_next();
  302. count++;
  303. }
  304. memdelete(f);
  305. }
  306. emit_signal("create");
  307. hide();
  308. }
  309. void CreateDialog::_notification(int p_what) {
  310. switch (p_what) {
  311. case NOTIFICATION_ENTER_TREE: {
  312. connect("confirmed", this, "_confirmed");
  313. search_box->set_right_icon(get_icon("Search", "EditorIcons"));
  314. search_box->set_clear_button_enabled(true);
  315. favorite->set_icon(get_icon("Favorites", "EditorIcons"));
  316. } break;
  317. case NOTIFICATION_EXIT_TREE: {
  318. disconnect("confirmed", this, "_confirmed");
  319. } break;
  320. case NOTIFICATION_VISIBILITY_CHANGED: {
  321. if (is_visible_in_tree()) {
  322. search_box->call_deferred("grab_focus"); // still not visible
  323. search_box->select_all();
  324. }
  325. } break;
  326. case NOTIFICATION_POPUP_HIDE: {
  327. EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", get_rect());
  328. } break;
  329. }
  330. }
  331. void CreateDialog::set_base_type(const String &p_base) {
  332. base_type = p_base;
  333. if (is_replace_mode)
  334. set_title(vformat(TTR("Change %s Type"), p_base));
  335. else
  336. set_title(vformat(TTR("Create New %s"), p_base));
  337. _update_search();
  338. }
  339. String CreateDialog::get_base_type() const {
  340. return base_type;
  341. }
  342. void CreateDialog::set_preferred_search_result_type(const String &p_preferred_type) {
  343. preferred_search_result_type = p_preferred_type;
  344. }
  345. String CreateDialog::get_preferred_search_result_type() {
  346. return preferred_search_result_type;
  347. }
  348. String CreateDialog::get_selected_type() {
  349. TreeItem *selected = search_options->get_selected();
  350. if (selected)
  351. return selected->get_text(0);
  352. else
  353. return String();
  354. }
  355. Object *CreateDialog::instance_selected() {
  356. TreeItem *selected = search_options->get_selected();
  357. if (selected) {
  358. Variant md = selected->get_metadata(0);
  359. String custom;
  360. if (md.get_type() != Variant::NIL)
  361. custom = md;
  362. if (custom != String()) {
  363. if (ScriptServer::is_global_class(custom)) {
  364. Object *obj = EditorNode::get_editor_data().script_class_instance(custom);
  365. Node *n = Object::cast_to<Node>(obj);
  366. if (n)
  367. n->set_name(custom);
  368. return obj;
  369. }
  370. return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom);
  371. } else {
  372. return ClassDB::instance(selected->get_text(0));
  373. }
  374. }
  375. return NULL;
  376. }
  377. void CreateDialog::_item_selected() {
  378. TreeItem *item = search_options->get_selected();
  379. if (!item)
  380. return;
  381. String name = item->get_text(0);
  382. favorite->set_disabled(false);
  383. favorite->set_pressed(favorite_list.find(name) != -1);
  384. if (!EditorHelp::get_doc_data()->class_list.has(name))
  385. return;
  386. help_bit->set_text(EditorHelp::get_doc_data()->class_list[name].brief_description);
  387. get_ok()->set_disabled(false);
  388. }
  389. void CreateDialog::_favorite_toggled() {
  390. TreeItem *item = search_options->get_selected();
  391. if (!item)
  392. return;
  393. String name = item->get_text(0);
  394. if (favorite_list.find(name) == -1) {
  395. favorite_list.push_back(name);
  396. favorite->set_pressed(true);
  397. } else {
  398. favorite_list.erase(name);
  399. favorite->set_pressed(false);
  400. }
  401. _save_and_update_favorite_list();
  402. }
  403. void CreateDialog::_save_favorite_list() {
  404. FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::WRITE);
  405. if (f) {
  406. for (int i = 0; i < favorite_list.size(); i++) {
  407. String l = favorite_list[i];
  408. String name = l.split(" ")[0];
  409. if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name)))
  410. continue;
  411. f->store_line(l);
  412. }
  413. memdelete(f);
  414. }
  415. }
  416. void CreateDialog::_update_favorite_list() {
  417. favorites->clear();
  418. TreeItem *root = favorites->create_item();
  419. for (int i = 0; i < favorite_list.size(); i++) {
  420. String l = favorite_list[i];
  421. String name = l.split(" ")[0];
  422. if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name)))
  423. continue;
  424. TreeItem *ti = favorites->create_item(root);
  425. ti->set_text(0, l);
  426. ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type));
  427. }
  428. emit_signal("favorites_updated");
  429. }
  430. void CreateDialog::_history_selected() {
  431. TreeItem *item = recent->get_selected();
  432. if (!item)
  433. return;
  434. search_box->set_text(item->get_text(0).get_slicec(' ', 0));
  435. favorites->deselect_all();
  436. _update_search();
  437. }
  438. void CreateDialog::_favorite_selected() {
  439. TreeItem *item = favorites->get_selected();
  440. if (!item)
  441. return;
  442. search_box->set_text(item->get_text(0).get_slicec(' ', 0));
  443. recent->deselect_all();
  444. _update_search();
  445. }
  446. void CreateDialog::_history_activated() {
  447. _history_selected();
  448. _confirmed();
  449. }
  450. void CreateDialog::_favorite_activated() {
  451. _favorite_selected();
  452. _confirmed();
  453. }
  454. Variant CreateDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  455. TreeItem *ti = favorites->get_item_at_position(p_point);
  456. if (ti) {
  457. Dictionary d;
  458. d["type"] = "create_favorite_drag";
  459. d["class"] = ti->get_text(0);
  460. ToolButton *tb = memnew(ToolButton);
  461. tb->set_icon(ti->get_icon(0));
  462. tb->set_text(ti->get_text(0));
  463. set_drag_preview(tb);
  464. return d;
  465. }
  466. return Variant();
  467. }
  468. bool CreateDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  469. Dictionary d = p_data;
  470. if (d.has("type") && String(d["type"]) == "create_favorite_drag") {
  471. favorites->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  472. return true;
  473. }
  474. return false;
  475. }
  476. void CreateDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  477. Dictionary d = p_data;
  478. TreeItem *ti = favorites->get_item_at_position(p_point);
  479. if (!ti)
  480. return;
  481. String drop_at = ti->get_text(0);
  482. int ds = favorites->get_drop_section_at_position(p_point);
  483. int drop_idx = favorite_list.find(drop_at);
  484. if (drop_idx < 0)
  485. return;
  486. String type = d["class"];
  487. int from_idx = favorite_list.find(type);
  488. if (from_idx < 0)
  489. return;
  490. if (drop_idx == from_idx) {
  491. ds = -1; //cause it will be gone
  492. } else if (drop_idx > from_idx) {
  493. drop_idx--;
  494. }
  495. favorite_list.remove(from_idx);
  496. if (ds < 0) {
  497. favorite_list.insert(drop_idx, type);
  498. } else {
  499. if (drop_idx >= favorite_list.size() - 1) {
  500. favorite_list.push_back(type);
  501. } else {
  502. favorite_list.insert(drop_idx + 1, type);
  503. }
  504. }
  505. _save_and_update_favorite_list();
  506. }
  507. void CreateDialog::_save_and_update_favorite_list() {
  508. _save_favorite_list();
  509. _update_favorite_list();
  510. }
  511. void CreateDialog::_bind_methods() {
  512. ClassDB::bind_method(D_METHOD("_text_changed"), &CreateDialog::_text_changed);
  513. ClassDB::bind_method(D_METHOD("_confirmed"), &CreateDialog::_confirmed);
  514. ClassDB::bind_method(D_METHOD("_sbox_input"), &CreateDialog::_sbox_input);
  515. ClassDB::bind_method(D_METHOD("_item_selected"), &CreateDialog::_item_selected);
  516. ClassDB::bind_method(D_METHOD("_favorite_toggled"), &CreateDialog::_favorite_toggled);
  517. ClassDB::bind_method(D_METHOD("_history_selected"), &CreateDialog::_history_selected);
  518. ClassDB::bind_method(D_METHOD("_favorite_selected"), &CreateDialog::_favorite_selected);
  519. ClassDB::bind_method(D_METHOD("_history_activated"), &CreateDialog::_history_activated);
  520. ClassDB::bind_method(D_METHOD("_favorite_activated"), &CreateDialog::_favorite_activated);
  521. ClassDB::bind_method(D_METHOD("_save_and_update_favorite_list"), &CreateDialog::_save_and_update_favorite_list);
  522. ClassDB::bind_method("get_drag_data_fw", &CreateDialog::get_drag_data_fw);
  523. ClassDB::bind_method("can_drop_data_fw", &CreateDialog::can_drop_data_fw);
  524. ClassDB::bind_method("drop_data_fw", &CreateDialog::drop_data_fw);
  525. ADD_SIGNAL(MethodInfo("create"));
  526. ADD_SIGNAL(MethodInfo("favorites_updated"));
  527. }
  528. CreateDialog::CreateDialog() {
  529. is_replace_mode = false;
  530. set_resizable(true);
  531. HSplitContainer *hsc = memnew(HSplitContainer);
  532. add_child(hsc);
  533. VSplitContainer *vsc = memnew(VSplitContainer);
  534. hsc->add_child(vsc);
  535. VBoxContainer *fav_vb = memnew(VBoxContainer);
  536. vsc->add_child(fav_vb);
  537. fav_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
  538. fav_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  539. favorites = memnew(Tree);
  540. fav_vb->add_margin_child(TTR("Favorites:"), favorites, true);
  541. favorites->set_hide_root(true);
  542. favorites->set_hide_folding(true);
  543. favorites->connect("cell_selected", this, "_favorite_selected");
  544. favorites->connect("item_activated", this, "_favorite_activated");
  545. favorites->set_drag_forwarding(this);
  546. VBoxContainer *rec_vb = memnew(VBoxContainer);
  547. vsc->add_child(rec_vb);
  548. rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
  549. rec_vb->set_v_size_flags(SIZE_EXPAND_FILL);
  550. recent = memnew(Tree);
  551. rec_vb->add_margin_child(TTR("Recent:"), recent, true);
  552. recent->set_hide_root(true);
  553. recent->set_hide_folding(true);
  554. recent->connect("cell_selected", this, "_history_selected");
  555. recent->connect("item_activated", this, "_history_activated");
  556. VBoxContainer *vbc = memnew(VBoxContainer);
  557. hsc->add_child(vbc);
  558. vbc->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
  559. vbc->set_h_size_flags(SIZE_EXPAND_FILL);
  560. HBoxContainer *search_hb = memnew(HBoxContainer);
  561. search_box = memnew(LineEdit);
  562. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  563. search_hb->add_child(search_box);
  564. favorite = memnew(Button);
  565. favorite->set_flat(true);
  566. favorite->set_toggle_mode(true);
  567. search_hb->add_child(favorite);
  568. favorite->connect("pressed", this, "_favorite_toggled");
  569. vbc->add_margin_child(TTR("Search:"), search_hb);
  570. search_box->connect("text_changed", this, "_text_changed");
  571. search_box->connect("gui_input", this, "_sbox_input");
  572. search_options = memnew(Tree);
  573. vbc->add_margin_child(TTR("Matches:"), search_options, true);
  574. get_ok()->set_disabled(true);
  575. register_text_enter(search_box);
  576. set_hide_on_ok(false);
  577. search_options->connect("item_activated", this, "_confirmed");
  578. search_options->connect("cell_selected", this, "_item_selected");
  579. base_type = "Object";
  580. preferred_search_result_type = "";
  581. help_bit = memnew(EditorHelpBit);
  582. vbc->add_margin_child(TTR("Description:"), help_bit);
  583. help_bit->connect("request_hide", this, "_closed");
  584. type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here
  585. type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix.
  586. EDITOR_DEF("interface/editors/derive_script_globals_by_name", true);
  587. }