create_dialog.cpp 22 KB

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