editor_help.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. /*************************************************************************/
  2. /* editor_help.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "editor_help.h"
  31. #include "doc_data_compressed.gen.h"
  32. #include "editor/plugins/script_editor_plugin.h"
  33. #include "editor_node.h"
  34. #include "editor_settings.h"
  35. #include "os/keyboard.h"
  36. #define CONTRIBUTE_URL "http://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html"
  37. void EditorHelpSearch::popup() {
  38. popup_centered(Size2(700, 600) * EDSCALE);
  39. if (search_box->get_text() != "") {
  40. search_box->select_all();
  41. _update_search();
  42. }
  43. search_box->grab_focus();
  44. }
  45. void EditorHelpSearch::popup(const String &p_term) {
  46. popup_centered(Size2(700, 600) * EDSCALE);
  47. if (p_term != "") {
  48. search_box->set_text(p_term);
  49. search_box->select_all();
  50. _update_search();
  51. } else
  52. search_box->clear();
  53. search_box->grab_focus();
  54. }
  55. void EditorHelpSearch::_text_changed(const String &p_newtext) {
  56. _update_search();
  57. }
  58. void EditorHelpSearch::_sbox_input(const Ref<InputEvent> &p_ie) {
  59. Ref<InputEventKey> k = p_ie;
  60. if (k.is_valid() && (k->get_scancode() == KEY_UP ||
  61. k->get_scancode() == KEY_DOWN ||
  62. k->get_scancode() == KEY_PAGEUP ||
  63. k->get_scancode() == KEY_PAGEDOWN)) {
  64. search_options->call("_gui_input", k);
  65. search_box->accept_event();
  66. }
  67. }
  68. void EditorHelpSearch::_update_search() {
  69. search_options->clear();
  70. search_options->set_hide_root(true);
  71. /*
  72. TreeItem *root = search_options->create_item();
  73. _parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
  74. */
  75. List<StringName> type_list;
  76. ClassDB::get_class_list(&type_list);
  77. DocData *doc = EditorHelp::get_doc_data();
  78. String term = search_box->get_text();
  79. if (term.length() < 2)
  80. return;
  81. TreeItem *root = search_options->create_item();
  82. Ref<Texture> def_icon = get_icon("Node", "EditorIcons");
  83. //classes first
  84. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  85. if (E->key().findn(term) != -1) {
  86. TreeItem *item = search_options->create_item(root);
  87. item->set_metadata(0, "class_name:" + E->key());
  88. item->set_text(0, E->key() + " (Class)");
  89. if (has_icon(E->key(), "EditorIcons"))
  90. item->set_icon(0, get_icon(E->key(), "EditorIcons"));
  91. else
  92. item->set_icon(0, def_icon);
  93. }
  94. }
  95. //class methods, etc second
  96. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  97. DocData::ClassDoc &c = E->get();
  98. Ref<Texture> cicon;
  99. if (has_icon(E->key(), "EditorIcons"))
  100. cicon = get_icon(E->key(), "EditorIcons");
  101. else
  102. cicon = def_icon;
  103. for (int i = 0; i < c.methods.size(); i++) {
  104. if ((term.begins_with(".") && c.methods[i].name.begins_with(term.right(1))) || (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length() - 1).strip_edges())) || (term.begins_with(".") && term.ends_with("(") && c.methods[i].name == term.substr(1, term.length() - 2).strip_edges()) || c.methods[i].name.findn(term) != -1) {
  105. TreeItem *item = search_options->create_item(root);
  106. item->set_metadata(0, "class_method:" + E->key() + ":" + c.methods[i].name);
  107. item->set_text(0, E->key() + "." + c.methods[i].name + " (Method)");
  108. item->set_icon(0, cicon);
  109. }
  110. }
  111. for (int i = 0; i < c.signals.size(); i++) {
  112. if (c.signals[i].name.findn(term) != -1) {
  113. TreeItem *item = search_options->create_item(root);
  114. item->set_metadata(0, "class_signal:" + E->key() + ":" + c.signals[i].name);
  115. item->set_text(0, E->key() + "." + c.signals[i].name + " (Signal)");
  116. item->set_icon(0, cicon);
  117. }
  118. }
  119. for (int i = 0; i < c.constants.size(); i++) {
  120. if (c.constants[i].name.findn(term) != -1) {
  121. TreeItem *item = search_options->create_item(root);
  122. item->set_metadata(0, "class_constant:" + E->key() + ":" + c.constants[i].name);
  123. item->set_text(0, E->key() + "." + c.constants[i].name + " (Constant)");
  124. item->set_icon(0, cicon);
  125. }
  126. }
  127. for (int i = 0; i < c.properties.size(); i++) {
  128. if (c.properties[i].name.findn(term) != -1) {
  129. TreeItem *item = search_options->create_item(root);
  130. item->set_metadata(0, "class_property:" + E->key() + ":" + c.properties[i].name);
  131. item->set_text(0, E->key() + "." + c.properties[i].name + " (Property)");
  132. item->set_icon(0, cicon);
  133. }
  134. }
  135. for (int i = 0; i < c.theme_properties.size(); i++) {
  136. if (c.theme_properties[i].name.findn(term) != -1) {
  137. TreeItem *item = search_options->create_item(root);
  138. item->set_metadata(0, "class_theme_item:" + E->key() + ":" + c.theme_properties[i].name);
  139. item->set_text(0, E->key() + "." + c.theme_properties[i].name + " (Theme Item)");
  140. item->set_icon(0, cicon);
  141. }
  142. }
  143. }
  144. //same but descriptions
  145. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  146. DocData::ClassDoc &c = E->get();
  147. Ref<Texture> cicon;
  148. if (has_icon(E->key(), "EditorIcons"))
  149. cicon = get_icon(E->key(), "EditorIcons");
  150. else
  151. cicon = def_icon;
  152. if (c.description.findn(term) != -1) {
  153. TreeItem *item = search_options->create_item(root);
  154. item->set_metadata(0, "class_desc:" + E->key());
  155. item->set_text(0, E->key() + " (Class Description)");
  156. item->set_icon(0, cicon);
  157. }
  158. for (int i = 0; i < c.methods.size(); i++) {
  159. if (c.methods[i].description.findn(term) != -1) {
  160. TreeItem *item = search_options->create_item(root);
  161. item->set_metadata(0, "class_method_desc:" + E->key() + ":" + c.methods[i].name);
  162. item->set_text(0, E->key() + "." + c.methods[i].name + " (Method Description)");
  163. item->set_icon(0, cicon);
  164. }
  165. }
  166. for (int i = 0; i < c.signals.size(); i++) {
  167. if (c.signals[i].description.findn(term) != -1) {
  168. TreeItem *item = search_options->create_item(root);
  169. item->set_metadata(0, "class_signal:" + E->key() + ":" + c.signals[i].name);
  170. item->set_text(0, E->key() + "." + c.signals[i].name + " (Signal Description)");
  171. item->set_icon(0, cicon);
  172. }
  173. }
  174. for (int i = 0; i < c.constants.size(); i++) {
  175. if (c.constants[i].description.findn(term) != -1) {
  176. TreeItem *item = search_options->create_item(root);
  177. item->set_metadata(0, "class_constant:" + E->key() + ":" + c.constants[i].name);
  178. item->set_text(0, E->key() + "." + c.constants[i].name + " (Constant Description)");
  179. item->set_icon(0, cicon);
  180. }
  181. }
  182. for (int i = 0; i < c.properties.size(); i++) {
  183. if (c.properties[i].description.findn(term) != -1) {
  184. TreeItem *item = search_options->create_item(root);
  185. item->set_metadata(0, "class_property_desc:" + E->key() + ":" + c.properties[i].name);
  186. item->set_text(0, E->key() + "." + c.properties[i].name + " (Property Description)");
  187. item->set_icon(0, cicon);
  188. }
  189. }
  190. }
  191. get_ok()->set_disabled(root->get_children() == NULL);
  192. }
  193. void EditorHelpSearch::_confirmed() {
  194. TreeItem *ti = search_options->get_selected();
  195. if (!ti)
  196. return;
  197. String mdata = ti->get_metadata(0);
  198. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  199. emit_signal("go_to_help", mdata);
  200. // go to that
  201. hide();
  202. }
  203. void EditorHelpSearch::_notification(int p_what) {
  204. if (p_what == NOTIFICATION_ENTER_TREE) {
  205. //_update_icons
  206. search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
  207. connect("confirmed", this, "_confirmed");
  208. _update_search();
  209. } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  210. if (is_visible_in_tree()) {
  211. search_box->call_deferred("grab_focus"); // still not visible
  212. search_box->select_all();
  213. }
  214. } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  215. //_update_icons
  216. search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
  217. }
  218. }
  219. void EditorHelpSearch::_bind_methods() {
  220. ClassDB::bind_method(D_METHOD("_text_changed"), &EditorHelpSearch::_text_changed);
  221. ClassDB::bind_method(D_METHOD("_confirmed"), &EditorHelpSearch::_confirmed);
  222. ClassDB::bind_method(D_METHOD("_sbox_input"), &EditorHelpSearch::_sbox_input);
  223. ClassDB::bind_method(D_METHOD("_update_search"), &EditorHelpSearch::_update_search);
  224. ADD_SIGNAL(MethodInfo("go_to_help"));
  225. }
  226. EditorHelpSearch::EditorHelpSearch() {
  227. VBoxContainer *vbc = memnew(VBoxContainer);
  228. add_child(vbc);
  229. search_box = memnew(LineEdit);
  230. vbc->add_child(search_box);
  231. search_box->connect("text_changed", this, "_text_changed");
  232. search_box->connect("gui_input", this, "_sbox_input");
  233. search_options = memnew(Tree);
  234. vbc->add_margin_child(TTR("Matches:"), search_options, true);
  235. get_ok()->set_text(TTR("Open"));
  236. get_ok()->set_disabled(true);
  237. register_text_enter(search_box);
  238. set_hide_on_ok(false);
  239. search_options->connect("item_activated", this, "_confirmed");
  240. set_title(TTR("Search Help"));
  241. //search_options->set_hide_root(true);
  242. }
  243. /////////////////////////////////
  244. ////////////////////////////////////
  245. /// /////////////////////////////////
  246. void EditorHelpIndex::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root) {
  247. if (p_types.has(p_type))
  248. return;
  249. /*
  250. if (!ClassDB::is_type(p_type,base) || p_type==base)
  251. return;
  252. */
  253. String inherits = EditorHelp::get_doc_data()->class_list[p_type].inherits;
  254. TreeItem *parent = p_root;
  255. if (inherits.length()) {
  256. if (!p_types.has(inherits)) {
  257. add_type(inherits, p_types, p_root);
  258. }
  259. if (p_types.has(inherits))
  260. parent = p_types[inherits];
  261. }
  262. TreeItem *item = class_list->create_item(parent);
  263. item->set_metadata(0, p_type);
  264. item->set_tooltip(0, EditorHelp::get_doc_data()->class_list[p_type].brief_description);
  265. item->set_text(0, p_type);
  266. if (has_icon(p_type, "EditorIcons")) {
  267. item->set_icon(0, get_icon(p_type, "EditorIcons"));
  268. }
  269. p_types[p_type] = item;
  270. }
  271. void EditorHelpIndex::_tree_item_selected() {
  272. TreeItem *s = class_list->get_selected();
  273. if (!s)
  274. return;
  275. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  276. emit_signal("open_class", s->get_text(0));
  277. hide();
  278. //_goto_desc(s->get_text(0));
  279. }
  280. void EditorHelpIndex::select_class(const String &p_class) {
  281. if (!tree_item_map.has(p_class))
  282. return;
  283. tree_item_map[p_class]->select(0);
  284. class_list->ensure_cursor_is_visible();
  285. }
  286. void EditorHelpIndex::popup() {
  287. popup_centered(Size2(500, 600) * EDSCALE);
  288. search_box->set_text("");
  289. _update_class_list();
  290. }
  291. void EditorHelpIndex::_notification(int p_what) {
  292. if (p_what == NOTIFICATION_ENTER_TREE) {
  293. //_update_icons
  294. search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
  295. _update_class_list();
  296. connect("confirmed", this, "_tree_item_selected");
  297. } else if (p_what == NOTIFICATION_POST_POPUP) {
  298. search_box->call_deferred("grab_focus");
  299. } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  300. //_update_icons
  301. search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
  302. }
  303. }
  304. void EditorHelpIndex::_text_changed(const String &p_text) {
  305. _update_class_list();
  306. }
  307. void EditorHelpIndex::_update_class_list() {
  308. class_list->clear();
  309. tree_item_map.clear();
  310. TreeItem *root = class_list->create_item();
  311. class_list->set_hide_root(true);
  312. String filter = search_box->get_text().strip_edges();
  313. String to_select = "";
  314. for (Map<String, DocData::ClassDoc>::Element *E = EditorHelp::get_doc_data()->class_list.front(); E; E = E->next()) {
  315. if (filter == "") {
  316. add_type(E->key(), tree_item_map, root);
  317. } else {
  318. bool found = false;
  319. String type = E->key();
  320. while (type != "") {
  321. if (filter.is_subsequence_ofi(type)) {
  322. if (to_select.empty()) {
  323. to_select = type;
  324. }
  325. found = true;
  326. break;
  327. }
  328. type = EditorHelp::get_doc_data()->class_list[type].inherits;
  329. }
  330. if (found) {
  331. add_type(E->key(), tree_item_map, root);
  332. }
  333. }
  334. }
  335. if (tree_item_map.has(filter)) {
  336. select_class(filter);
  337. } else if (to_select != "") {
  338. select_class(to_select);
  339. }
  340. }
  341. void EditorHelpIndex::_sbox_input(const Ref<InputEvent> &p_ie) {
  342. Ref<InputEventKey> k = p_ie;
  343. if (k.is_valid() && (k->get_scancode() == KEY_UP ||
  344. k->get_scancode() == KEY_DOWN ||
  345. k->get_scancode() == KEY_PAGEUP ||
  346. k->get_scancode() == KEY_PAGEDOWN)) {
  347. class_list->call("_gui_input", k);
  348. search_box->accept_event();
  349. }
  350. }
  351. void EditorHelpIndex::_bind_methods() {
  352. ClassDB::bind_method("_tree_item_selected", &EditorHelpIndex::_tree_item_selected);
  353. ClassDB::bind_method("_text_changed", &EditorHelpIndex::_text_changed);
  354. ClassDB::bind_method("_sbox_input", &EditorHelpIndex::_sbox_input);
  355. ClassDB::bind_method("select_class", &EditorHelpIndex::select_class);
  356. ADD_SIGNAL(MethodInfo("open_class"));
  357. }
  358. EditorHelpIndex::EditorHelpIndex() {
  359. VBoxContainer *vbc = memnew(VBoxContainer);
  360. add_child(vbc);
  361. search_box = memnew(LineEdit);
  362. vbc->add_child(search_box);
  363. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  364. register_text_enter(search_box);
  365. search_box->connect("text_changed", this, "_text_changed");
  366. search_box->connect("gui_input", this, "_sbox_input");
  367. class_list = memnew(Tree);
  368. vbc->add_margin_child(TTR("Class List:") + " ", class_list, true);
  369. class_list->set_v_size_flags(SIZE_EXPAND_FILL);
  370. class_list->connect("item_activated", this, "_tree_item_selected");
  371. get_ok()->set_text(TTR("Open"));
  372. set_title(TTR("Search Classes"));
  373. }
  374. /////////////////////////////////
  375. ////////////////////////////////////
  376. /// /////////////////////////////////
  377. DocData *EditorHelp::doc = NULL;
  378. void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
  379. if (!is_visible_in_tree())
  380. return;
  381. Ref<InputEventKey> k = p_ev;
  382. if (k.is_valid() && k->get_control() && k->get_scancode() == KEY_F) {
  383. search->grab_focus();
  384. search->select_all();
  385. }
  386. }
  387. void EditorHelp::_search(const String &) {
  388. if (search->get_text() == "")
  389. return;
  390. String stext = search->get_text();
  391. bool keep = prev_search == stext;
  392. bool ret = class_desc->search(stext, keep);
  393. if (!ret) {
  394. class_desc->search(stext, false);
  395. }
  396. prev_search = stext;
  397. }
  398. void EditorHelp::_class_list_select(const String &p_select) {
  399. _goto_desc(p_select);
  400. }
  401. void EditorHelp::_class_desc_select(const String &p_select) {
  402. //print_line("LINK: "+p_select);
  403. if (p_select.begins_with("$")) { //enum
  404. //_goto_desc(p_select.substr(1,p_select.length()));
  405. String select = p_select.substr(1, p_select.length());
  406. String class_name;
  407. if (select.find(".") != -1) {
  408. class_name = select.get_slice(".", 0);
  409. } else {
  410. class_name = "@Global Scope";
  411. }
  412. emit_signal("go_to_help", "class_enum:" + class_name + ":" + select);
  413. return;
  414. } else if (p_select.begins_with("#")) {
  415. //_goto_desc(p_select.substr(1,p_select.length()));
  416. emit_signal("go_to_help", "class_name:" + p_select.substr(1, p_select.length()));
  417. return;
  418. } else if (p_select.begins_with("@")) {
  419. String m = p_select.substr(1, p_select.length());
  420. if (m.find(".") != -1) {
  421. //must go somewhere else
  422. emit_signal("go_to_help", "class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0));
  423. } else {
  424. if (!method_line.has(m))
  425. return;
  426. class_desc->scroll_to_line(method_line[m]);
  427. }
  428. } else if (p_select.begins_with("http")) {
  429. OS::get_singleton()->shell_open(p_select);
  430. }
  431. }
  432. void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) {
  433. Ref<InputEventMouseButton> mb = p_input;
  434. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
  435. class_desc->set_selection_enabled(false);
  436. class_desc->set_selection_enabled(true);
  437. }
  438. set_focused();
  439. }
  440. void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
  441. String t = p_type;
  442. if (t == "")
  443. t = "void";
  444. bool can_ref = (t != "int" && t != "real" && t != "bool" && t != "void") || p_enum != String();
  445. if (p_enum != String()) {
  446. if (p_enum.get_slice_count(".") > 1) {
  447. t = p_enum.get_slice(".", 1);
  448. } else {
  449. t = p_enum.get_slice(".", 0);
  450. }
  451. }
  452. const Color text_color = get_color("default_color", "RichTextLabel");
  453. const Color type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
  454. class_desc->push_color(type_color);
  455. if (can_ref) {
  456. if (p_enum == "") {
  457. class_desc->push_meta("#" + t); //class
  458. } else {
  459. class_desc->push_meta("$" + p_enum); //class
  460. }
  461. }
  462. class_desc->add_text(t);
  463. if (can_ref)
  464. class_desc->pop();
  465. class_desc->pop();
  466. }
  467. Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
  468. //ERR_FAIL_COND(!doc->class_list.has(p_class));
  469. if (!doc->class_list.has(p_class))
  470. return ERR_DOES_NOT_EXIST;
  471. //if (tree_item_map.has(p_class)) {
  472. select_locked = true;
  473. //}
  474. class_desc->show();
  475. //tabs->set_current_tab(PAGE_CLASS_DESC);
  476. description_line = 0;
  477. if (p_class == edited_class)
  478. return OK; //already there
  479. scroll_locked = true;
  480. class_desc->clear();
  481. method_line.clear();
  482. section_line.clear();
  483. edited_class = p_class;
  484. //edited_class->show();
  485. // Colors
  486. const Color title_color = get_color("accent_color", "Editor");
  487. const Color text_color = get_color("default_color", "RichTextLabel");
  488. const Color headline_color = get_color("headline_color", "EditorHelp");
  489. const Color base_type_color = title_color.linear_interpolate(text_color, 0.5);
  490. const Color comment_color = Color(text_color.r, text_color.g, text_color.b, 0.6);
  491. const Color symbol_color = comment_color;
  492. const Color value_color = Color(text_color.r, text_color.g, text_color.b, 0.4);
  493. const Color qualifier_color = Color(text_color.r, text_color.g, text_color.b, 0.8);
  494. DocData::ClassDoc cd = doc->class_list[p_class]; //make a copy, so we can sort without worrying
  495. Ref<Font> doc_font = get_font("doc", "EditorFonts");
  496. Ref<Font> doc_title_font = get_font("doc_title", "EditorFonts");
  497. Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts");
  498. String link_color_text = title_color.to_html(false);
  499. section_line.push_back(Pair<String, int>(TTR("Top"), 0));
  500. class_desc->push_font(doc_title_font);
  501. class_desc->push_color(title_color);
  502. class_desc->add_text(TTR("Class:") + " ");
  503. class_desc->push_color(headline_color);
  504. _add_text(p_class);
  505. class_desc->pop();
  506. class_desc->pop();
  507. class_desc->pop();
  508. class_desc->add_newline();
  509. if (cd.inherits != "") {
  510. class_desc->push_color(title_color);
  511. class_desc->push_font(doc_title_font);
  512. class_desc->add_text(TTR("Inherits:") + " ");
  513. class_desc->pop();
  514. class_desc->pop();
  515. String inherits = cd.inherits;
  516. class_desc->push_font(doc_font);
  517. while (inherits != "") {
  518. _add_type(inherits);
  519. inherits = doc->class_list[inherits].inherits;
  520. if (inherits != "") {
  521. class_desc->add_text(" < ");
  522. }
  523. }
  524. class_desc->pop();
  525. class_desc->add_newline();
  526. }
  527. if (ClassDB::class_exists(cd.name)) {
  528. bool found = false;
  529. bool prev = false;
  530. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  531. if (E->get().inherits == cd.name) {
  532. if (!found) {
  533. class_desc->push_color(title_color);
  534. class_desc->push_font(doc_title_font);
  535. class_desc->add_text(TTR("Inherited by:") + " ");
  536. class_desc->pop();
  537. class_desc->pop();
  538. found = true;
  539. class_desc->push_font(doc_font);
  540. }
  541. if (prev) {
  542. class_desc->add_text(" , ");
  543. prev = false;
  544. }
  545. _add_type(E->get().name);
  546. prev = true;
  547. }
  548. }
  549. if (found)
  550. class_desc->pop();
  551. class_desc->add_newline();
  552. }
  553. class_desc->add_newline();
  554. class_desc->add_newline();
  555. if (cd.brief_description != "") {
  556. class_desc->push_color(title_color);
  557. class_desc->push_font(doc_title_font);
  558. class_desc->add_text(TTR("Brief Description:"));
  559. class_desc->pop();
  560. class_desc->pop();
  561. //class_desc->add_newline();
  562. class_desc->add_newline();
  563. class_desc->push_color(text_color);
  564. class_desc->push_font(doc_font);
  565. class_desc->push_indent(1);
  566. _add_text(cd.brief_description);
  567. class_desc->pop();
  568. class_desc->pop();
  569. class_desc->pop();
  570. class_desc->add_newline();
  571. class_desc->add_newline();
  572. class_desc->add_newline();
  573. }
  574. Set<String> skip_methods;
  575. bool property_descr = false;
  576. if (cd.properties.size()) {
  577. section_line.push_back(Pair<String, int>(TTR("Members"), class_desc->get_line_count() - 2));
  578. class_desc->push_color(title_color);
  579. class_desc->push_font(doc_title_font);
  580. class_desc->add_text(TTR("Members:"));
  581. class_desc->pop();
  582. class_desc->pop();
  583. //class_desc->add_newline();
  584. class_desc->push_indent(1);
  585. class_desc->push_table(2);
  586. class_desc->set_table_column_expand(1, 1);
  587. for (int i = 0; i < cd.properties.size(); i++) {
  588. property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  589. class_desc->push_cell();
  590. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  591. class_desc->push_font(doc_code_font);
  592. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  593. class_desc->pop();
  594. class_desc->pop();
  595. class_desc->pop();
  596. bool describe = false;
  597. if (cd.properties[i].setter != "") {
  598. skip_methods.insert(cd.properties[i].setter);
  599. describe = true;
  600. }
  601. if (cd.properties[i].getter != "") {
  602. skip_methods.insert(cd.properties[i].getter);
  603. describe = true;
  604. }
  605. if (cd.properties[i].description != "") {
  606. describe = true;
  607. }
  608. class_desc->push_cell();
  609. if (describe) {
  610. class_desc->push_meta("@" + cd.properties[i].name);
  611. }
  612. class_desc->push_font(doc_code_font);
  613. class_desc->push_color(headline_color);
  614. _add_text(cd.properties[i].name);
  615. if (describe) {
  616. class_desc->pop();
  617. property_descr = true;
  618. }
  619. class_desc->pop();
  620. class_desc->pop();
  621. class_desc->pop();
  622. }
  623. class_desc->pop(); //table
  624. class_desc->pop();
  625. class_desc->add_newline();
  626. class_desc->add_newline();
  627. }
  628. bool method_descr = false;
  629. bool sort_methods = EditorSettings::get_singleton()->get("text_editor/help/sort_functions_alphabetically");
  630. Vector<DocData::MethodDoc> methods;
  631. for (int i = 0; i < cd.methods.size(); i++) {
  632. if (skip_methods.has(cd.methods[i].name))
  633. continue;
  634. methods.push_back(cd.methods[i]);
  635. }
  636. if (methods.size()) {
  637. if (sort_methods)
  638. methods.sort();
  639. section_line.push_back(Pair<String, int>(TTR("Public Methods"), class_desc->get_line_count() - 2));
  640. class_desc->push_color(title_color);
  641. class_desc->push_font(doc_title_font);
  642. class_desc->add_text(TTR("Public Methods:"));
  643. class_desc->pop();
  644. class_desc->pop();
  645. //class_desc->add_newline();
  646. //class_desc->add_newline();
  647. class_desc->push_indent(1);
  648. class_desc->push_table(2);
  649. class_desc->set_table_column_expand(1, 1);
  650. for (int i = 0; i < methods.size(); i++) {
  651. bool is_vararg = methods[i].qualifiers.find("vararg") != -1;
  652. method_line[methods[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  653. class_desc->push_cell();
  654. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  655. class_desc->push_font(doc_code_font);
  656. _add_type(methods[i].return_type, methods[i].return_enum);
  657. //class_desc->add_text(" ");
  658. class_desc->pop(); //align
  659. class_desc->pop(); //font
  660. class_desc->pop(); //cell
  661. class_desc->push_cell();
  662. class_desc->push_font(doc_code_font);
  663. if (methods[i].description != "") {
  664. method_descr = true;
  665. class_desc->push_meta("@" + methods[i].name);
  666. }
  667. class_desc->push_color(headline_color);
  668. _add_text(methods[i].name);
  669. class_desc->pop();
  670. if (methods[i].description != "")
  671. class_desc->pop(); // pop meta
  672. class_desc->push_color(symbol_color);
  673. class_desc->add_text(methods[i].arguments.size() || is_vararg ? "( " : "(");
  674. class_desc->pop();
  675. for (int j = 0; j < methods[i].arguments.size(); j++) {
  676. class_desc->push_color(text_color);
  677. if (j > 0)
  678. class_desc->add_text(", ");
  679. _add_type(methods[i].arguments[j].type, methods[i].arguments[j].enumeration);
  680. class_desc->add_text(" ");
  681. _add_text(methods[i].arguments[j].name);
  682. if (methods[i].arguments[j].default_value != "") {
  683. class_desc->push_color(symbol_color);
  684. class_desc->add_text("=");
  685. class_desc->pop();
  686. _add_text(methods[i].arguments[j].default_value);
  687. }
  688. class_desc->pop();
  689. }
  690. if (is_vararg) {
  691. class_desc->push_color(text_color);
  692. if (methods[i].arguments.size())
  693. class_desc->add_text(", ");
  694. class_desc->push_color(symbol_color);
  695. class_desc->add_text("...");
  696. class_desc->pop();
  697. class_desc->pop();
  698. }
  699. class_desc->push_color(symbol_color);
  700. class_desc->add_text(methods[i].arguments.size() || is_vararg ? " )" : ")");
  701. class_desc->pop();
  702. if (methods[i].qualifiers != "") {
  703. class_desc->push_color(qualifier_color);
  704. class_desc->add_text(" ");
  705. _add_text(methods[i].qualifiers);
  706. class_desc->pop();
  707. }
  708. class_desc->pop(); //monofont
  709. //class_desc->add_newline();
  710. class_desc->pop(); //cell
  711. }
  712. class_desc->pop(); //table
  713. class_desc->pop();
  714. class_desc->add_newline();
  715. class_desc->add_newline();
  716. }
  717. if (cd.theme_properties.size()) {
  718. section_line.push_back(Pair<String, int>(TTR("GUI Theme Items"), class_desc->get_line_count() - 2));
  719. class_desc->push_color(title_color);
  720. class_desc->push_font(doc_title_font);
  721. class_desc->add_text(TTR("GUI Theme Items:"));
  722. class_desc->pop();
  723. class_desc->pop();
  724. // class_desc->add_newline();
  725. class_desc->push_indent(1);
  726. class_desc->push_table(2);
  727. class_desc->set_table_column_expand(1, 1);
  728. //class_desc->add_newline();
  729. for (int i = 0; i < cd.theme_properties.size(); i++) {
  730. theme_property_line[cd.theme_properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  731. class_desc->push_cell();
  732. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  733. class_desc->push_font(doc_code_font);
  734. _add_type(cd.theme_properties[i].type);
  735. class_desc->pop();
  736. class_desc->pop();
  737. class_desc->pop();
  738. class_desc->push_cell();
  739. class_desc->push_font(doc_code_font);
  740. class_desc->push_color(headline_color);
  741. _add_text(cd.theme_properties[i].name);
  742. class_desc->pop();
  743. class_desc->pop();
  744. if (cd.theme_properties[i].description != "") {
  745. class_desc->push_font(doc_font);
  746. class_desc->add_text(" ");
  747. class_desc->push_color(comment_color);
  748. _add_text(cd.theme_properties[i].description);
  749. class_desc->pop();
  750. class_desc->pop();
  751. }
  752. class_desc->pop(); // cell
  753. }
  754. class_desc->pop(); // table
  755. class_desc->pop();
  756. class_desc->add_newline();
  757. class_desc->add_newline();
  758. }
  759. if (cd.signals.size()) {
  760. if (sort_methods) {
  761. cd.signals.sort();
  762. }
  763. section_line.push_back(Pair<String, int>(TTR("Signals"), class_desc->get_line_count() - 2));
  764. class_desc->push_color(title_color);
  765. class_desc->push_font(doc_title_font);
  766. class_desc->add_text(TTR("Signals:"));
  767. class_desc->pop();
  768. class_desc->pop();
  769. class_desc->add_newline();
  770. //class_desc->add_newline();
  771. class_desc->push_indent(1);
  772. for (int i = 0; i < cd.signals.size(); i++) {
  773. signal_line[cd.signals[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  774. class_desc->push_font(doc_code_font); // monofont
  775. //_add_type("void");
  776. //class_desc->add_text(" ");
  777. class_desc->push_color(headline_color);
  778. _add_text(cd.signals[i].name);
  779. class_desc->pop();
  780. class_desc->push_color(symbol_color);
  781. class_desc->add_text(cd.signals[i].arguments.size() ? "( " : "(");
  782. class_desc->pop();
  783. for (int j = 0; j < cd.signals[i].arguments.size(); j++) {
  784. class_desc->push_color(text_color);
  785. if (j > 0)
  786. class_desc->add_text(", ");
  787. _add_type(cd.signals[i].arguments[j].type);
  788. class_desc->add_text(" ");
  789. _add_text(cd.signals[i].arguments[j].name);
  790. if (cd.signals[i].arguments[j].default_value != "") {
  791. class_desc->push_color(symbol_color);
  792. class_desc->add_text("=");
  793. class_desc->pop();
  794. _add_text(cd.signals[i].arguments[j].default_value);
  795. }
  796. class_desc->pop();
  797. }
  798. class_desc->push_color(symbol_color);
  799. class_desc->add_text(cd.signals[i].arguments.size() ? " )" : ")");
  800. class_desc->pop();
  801. class_desc->pop(); // end monofont
  802. if (cd.signals[i].description != "") {
  803. class_desc->push_font(doc_font);
  804. class_desc->push_color(comment_color);
  805. class_desc->push_indent(1);
  806. // class_desc->add_text(" ");
  807. _add_text(cd.signals[i].description);
  808. class_desc->pop(); // indent
  809. class_desc->pop();
  810. class_desc->pop(); // font
  811. }
  812. class_desc->add_newline();
  813. class_desc->add_newline();
  814. }
  815. class_desc->pop();
  816. class_desc->add_newline();
  817. }
  818. if (cd.constants.size()) {
  819. Map<String, Vector<DocData::ConstantDoc> > enums;
  820. Vector<DocData::ConstantDoc> constants;
  821. for (int i = 0; i < cd.constants.size(); i++) {
  822. if (cd.constants[i].enumeration != String()) {
  823. if (!enums.has(cd.constants[i].enumeration)) {
  824. enums[cd.constants[i].enumeration] = Vector<DocData::ConstantDoc>();
  825. }
  826. enums[cd.constants[i].enumeration].push_back(cd.constants[i]);
  827. } else {
  828. constants.push_back(cd.constants[i]);
  829. }
  830. }
  831. if (enums.size()) {
  832. section_line.push_back(Pair<String, int>(TTR("Enumerations"), class_desc->get_line_count() - 2));
  833. class_desc->push_color(title_color);
  834. class_desc->push_font(doc_title_font);
  835. class_desc->add_text(TTR("Enumerations:"));
  836. class_desc->pop();
  837. class_desc->pop();
  838. class_desc->push_indent(1);
  839. class_desc->add_newline();
  840. //class_desc->add_newline();
  841. for (Map<String, Vector<DocData::ConstantDoc> >::Element *E = enums.front(); E; E = E->next()) {
  842. enum_line[E->key()] = class_desc->get_line_count() - 2;
  843. class_desc->push_color(title_color);
  844. class_desc->add_text(TTR("enum "));
  845. class_desc->pop();
  846. class_desc->push_font(doc_code_font);
  847. String e = E->key();
  848. if (e.get_slice_count(".")) {
  849. e = e.get_slice(".", 1);
  850. }
  851. class_desc->push_color(headline_color);
  852. class_desc->add_text(e);
  853. class_desc->pop();
  854. class_desc->pop();
  855. class_desc->push_color(symbol_color);
  856. class_desc->add_text(":");
  857. class_desc->pop();
  858. class_desc->add_newline();
  859. class_desc->push_indent(1);
  860. Vector<DocData::ConstantDoc> enum_list = E->get();
  861. for (int i = 0; i < enum_list.size(); i++) {
  862. class_desc->push_font(doc_code_font);
  863. class_desc->push_color(headline_color);
  864. _add_text(enum_list[i].name);
  865. class_desc->pop();
  866. class_desc->push_color(symbol_color);
  867. class_desc->add_text(" = ");
  868. class_desc->pop();
  869. class_desc->push_color(value_color);
  870. _add_text(enum_list[i].value);
  871. class_desc->pop();
  872. class_desc->pop();
  873. if (enum_list[i].description != "") {
  874. class_desc->push_font(doc_font);
  875. //class_desc->add_text(" ");
  876. class_desc->push_indent(1);
  877. class_desc->push_color(comment_color);
  878. _add_text(enum_list[i].description);
  879. class_desc->pop();
  880. class_desc->pop();
  881. class_desc->pop(); // indent
  882. class_desc->add_newline();
  883. }
  884. class_desc->add_newline();
  885. }
  886. class_desc->pop();
  887. class_desc->add_newline();
  888. }
  889. class_desc->pop();
  890. class_desc->add_newline();
  891. }
  892. if (constants.size()) {
  893. section_line.push_back(Pair<String, int>(TTR("Constants"), class_desc->get_line_count() - 2));
  894. class_desc->push_color(title_color);
  895. class_desc->push_font(doc_title_font);
  896. class_desc->add_text(TTR("Constants:"));
  897. class_desc->pop();
  898. class_desc->pop();
  899. class_desc->push_indent(1);
  900. class_desc->add_newline();
  901. //class_desc->add_newline();
  902. for (int i = 0; i < constants.size(); i++) {
  903. constant_line[constants[i].name] = class_desc->get_line_count() - 2;
  904. class_desc->push_font(doc_code_font);
  905. class_desc->push_color(headline_color);
  906. _add_text(constants[i].name);
  907. class_desc->pop();
  908. class_desc->push_color(symbol_color);
  909. class_desc->add_text(" = ");
  910. class_desc->pop();
  911. class_desc->push_color(value_color);
  912. _add_text(constants[i].value);
  913. class_desc->pop();
  914. class_desc->pop();
  915. if (constants[i].description != "") {
  916. class_desc->push_font(doc_font);
  917. class_desc->push_indent(1);
  918. //class_desc->add_text(" ");
  919. class_desc->push_color(comment_color);
  920. _add_text(constants[i].description);
  921. class_desc->pop();
  922. class_desc->pop();
  923. class_desc->pop(); // indent
  924. class_desc->add_newline();
  925. }
  926. class_desc->add_newline();
  927. }
  928. class_desc->pop();
  929. class_desc->add_newline();
  930. }
  931. }
  932. if (cd.description != "") {
  933. section_line.push_back(Pair<String, int>(TTR("Description"), class_desc->get_line_count() - 2));
  934. description_line = class_desc->get_line_count() - 2;
  935. class_desc->push_color(title_color);
  936. class_desc->push_font(doc_title_font);
  937. class_desc->add_text(TTR("Description:"));
  938. class_desc->pop();
  939. class_desc->pop();
  940. class_desc->add_newline();
  941. class_desc->push_color(text_color);
  942. class_desc->push_font(doc_font);
  943. class_desc->push_indent(1);
  944. _add_text(cd.description);
  945. class_desc->pop();
  946. class_desc->pop();
  947. class_desc->pop();
  948. class_desc->add_newline();
  949. class_desc->add_newline();
  950. class_desc->add_newline();
  951. }
  952. if (property_descr) {
  953. section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_line_count() - 2));
  954. class_desc->push_color(title_color);
  955. class_desc->push_font(doc_title_font);
  956. class_desc->add_text(TTR("Property Description:"));
  957. class_desc->pop();
  958. class_desc->pop();
  959. class_desc->add_newline();
  960. class_desc->add_newline();
  961. for (int i = 0; i < cd.properties.size(); i++) {
  962. method_line[cd.properties[i].name] = class_desc->get_line_count() - 2;
  963. class_desc->push_table(2);
  964. class_desc->set_table_column_expand(1, 1);
  965. class_desc->push_cell();
  966. class_desc->push_font(doc_code_font);
  967. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  968. class_desc->add_text(" ");
  969. class_desc->pop(); // font
  970. class_desc->pop(); // cell
  971. class_desc->push_cell();
  972. class_desc->push_font(doc_code_font);
  973. class_desc->push_color(headline_color);
  974. _add_text(cd.properties[i].name);
  975. class_desc->pop(); // color
  976. class_desc->pop(); // font
  977. class_desc->pop(); // cell
  978. //class_desc->add_text(" ");
  979. if (cd.properties[i].setter != "") {
  980. class_desc->push_cell();
  981. class_desc->pop(); // cell
  982. class_desc->push_cell();
  983. class_desc->push_font(doc_code_font);
  984. class_desc->push_color(text_color);
  985. class_desc->add_text(cd.properties[i].setter + "(value)");
  986. class_desc->pop(); // color
  987. class_desc->push_color(comment_color);
  988. class_desc->add_text(" setter");
  989. class_desc->pop(); // color
  990. class_desc->pop(); // font
  991. class_desc->pop(); // cell
  992. }
  993. if (cd.properties[i].getter != "") {
  994. class_desc->push_cell();
  995. class_desc->pop(); // cell
  996. class_desc->push_cell();
  997. class_desc->push_font(doc_code_font);
  998. class_desc->push_color(text_color);
  999. class_desc->add_text(cd.properties[i].getter + "()");
  1000. class_desc->pop(); //color
  1001. class_desc->push_color(comment_color);
  1002. class_desc->add_text(" getter");
  1003. class_desc->pop(); //color
  1004. class_desc->pop(); //font
  1005. class_desc->pop(); //cell
  1006. }
  1007. class_desc->pop(); // table
  1008. class_desc->add_newline();
  1009. class_desc->push_color(text_color);
  1010. class_desc->push_font(doc_font);
  1011. class_desc->push_indent(1);
  1012. if (cd.properties[i].description.strip_edges() != String()) {
  1013. _add_text(cd.properties[i].description);
  1014. } else {
  1015. class_desc->add_image(get_icon("Error", "EditorIcons"));
  1016. class_desc->add_text(" ");
  1017. class_desc->push_color(comment_color);
  1018. class_desc->append_bbcode(TTR("There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
  1019. class_desc->pop();
  1020. }
  1021. class_desc->pop();
  1022. class_desc->pop();
  1023. class_desc->pop();
  1024. class_desc->add_newline();
  1025. class_desc->add_newline();
  1026. class_desc->add_newline();
  1027. }
  1028. }
  1029. if (method_descr) {
  1030. section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_line_count() - 2));
  1031. class_desc->push_color(title_color);
  1032. class_desc->push_font(doc_title_font);
  1033. class_desc->add_text(TTR("Method Description:"));
  1034. class_desc->pop();
  1035. class_desc->pop();
  1036. class_desc->add_newline();
  1037. class_desc->add_newline();
  1038. for (int i = 0; i < methods.size(); i++) {
  1039. bool is_vararg = methods[i].qualifiers.find("vararg") != -1;
  1040. method_line[methods[i].name] = class_desc->get_line_count() - 2;
  1041. class_desc->push_font(doc_code_font);
  1042. _add_type(methods[i].return_type, methods[i].return_enum);
  1043. class_desc->add_text(" ");
  1044. class_desc->push_color(headline_color);
  1045. _add_text(methods[i].name);
  1046. class_desc->pop();
  1047. class_desc->push_color(symbol_color);
  1048. class_desc->add_text(methods[i].arguments.size() || is_vararg ? "( " : "(");
  1049. class_desc->pop();
  1050. for (int j = 0; j < methods[i].arguments.size(); j++) {
  1051. class_desc->push_color(text_color);
  1052. if (j > 0)
  1053. class_desc->add_text(", ");
  1054. _add_type(methods[i].arguments[j].type, methods[i].arguments[j].enumeration);
  1055. class_desc->add_text(" ");
  1056. _add_text(methods[i].arguments[j].name);
  1057. if (methods[i].arguments[j].default_value != "") {
  1058. class_desc->push_color(symbol_color);
  1059. class_desc->add_text("=");
  1060. class_desc->pop();
  1061. _add_text(methods[i].arguments[j].default_value);
  1062. }
  1063. class_desc->pop();
  1064. }
  1065. if (is_vararg) {
  1066. class_desc->push_color(text_color);
  1067. if (methods[i].arguments.size())
  1068. class_desc->add_text(", ");
  1069. class_desc->push_color(symbol_color);
  1070. class_desc->add_text("...");
  1071. class_desc->pop();
  1072. class_desc->pop();
  1073. }
  1074. class_desc->push_color(symbol_color);
  1075. class_desc->add_text(methods[i].arguments.size() || is_vararg ? " )" : ")");
  1076. class_desc->pop();
  1077. if (methods[i].qualifiers != "") {
  1078. class_desc->push_color(qualifier_color);
  1079. class_desc->add_text(" ");
  1080. _add_text(methods[i].qualifiers);
  1081. class_desc->pop();
  1082. }
  1083. class_desc->pop();
  1084. class_desc->add_newline();
  1085. class_desc->push_color(text_color);
  1086. class_desc->push_font(doc_font);
  1087. class_desc->push_indent(1);
  1088. if (methods[i].description.strip_edges() != String()) {
  1089. _add_text(methods[i].description);
  1090. } else {
  1091. class_desc->add_image(get_icon("Error", "EditorIcons"));
  1092. class_desc->add_text(" ");
  1093. class_desc->push_color(comment_color);
  1094. class_desc->append_bbcode(TTR("There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
  1095. class_desc->pop();
  1096. }
  1097. class_desc->pop();
  1098. class_desc->pop();
  1099. class_desc->pop();
  1100. class_desc->add_newline();
  1101. class_desc->add_newline();
  1102. class_desc->add_newline();
  1103. }
  1104. }
  1105. scroll_locked = false;
  1106. return OK;
  1107. }
  1108. void EditorHelp::_request_help(const String &p_string) {
  1109. Error err = _goto_desc(p_string);
  1110. if (err == OK) {
  1111. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  1112. }
  1113. //100 palabras
  1114. }
  1115. void EditorHelp::_help_callback(const String &p_topic) {
  1116. String what = p_topic.get_slice(":", 0);
  1117. String clss = p_topic.get_slice(":", 1);
  1118. String name;
  1119. if (p_topic.get_slice_count(":") == 3)
  1120. name = p_topic.get_slice(":", 2);
  1121. _request_help(clss); //first go to class
  1122. int line = 0;
  1123. if (what == "class_desc") {
  1124. line = description_line;
  1125. } else if (what == "class_signal") {
  1126. if (signal_line.has(name))
  1127. line = signal_line[name];
  1128. } else if (what == "class_method" || what == "class_method_desc") {
  1129. if (method_line.has(name))
  1130. line = method_line[name];
  1131. } else if (what == "class_property") {
  1132. if (property_line.has(name))
  1133. line = property_line[name];
  1134. } else if (what == "class_enum") {
  1135. print_line("go to enum:");
  1136. if (enum_line.has(name))
  1137. line = enum_line[name];
  1138. } else if (what == "class_theme_item") {
  1139. if (theme_property_line.has(name))
  1140. line = theme_property_line[name];
  1141. } else if (what == "class_constant") {
  1142. if (constant_line.has(name))
  1143. line = constant_line[name];
  1144. }
  1145. class_desc->call_deferred("scroll_to_line", line);
  1146. }
  1147. static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
  1148. DocData *doc = EditorHelp::get_doc_data();
  1149. String base_path;
  1150. Ref<Font> doc_font = p_rt->get_font("doc", "EditorFonts");
  1151. Ref<Font> doc_code_font = p_rt->get_font("doc_source", "EditorFonts");
  1152. Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp");
  1153. Color link_color = p_rt->get_color("accent_color", "Editor").linear_interpolate(font_color_hl, 0.8);
  1154. String bbcode = p_bbcode.replace("\t", " ").replace("\r", " ").strip_edges();
  1155. List<String> tag_stack;
  1156. int pos = 0;
  1157. while (pos < bbcode.length()) {
  1158. int brk_pos = bbcode.find("[", pos);
  1159. if (brk_pos < 0)
  1160. brk_pos = bbcode.length();
  1161. if (brk_pos > pos) {
  1162. p_rt->add_text(bbcode.substr(pos, brk_pos - pos));
  1163. }
  1164. if (brk_pos == bbcode.length())
  1165. break; //nothing else o add
  1166. int brk_end = bbcode.find("]", brk_pos + 1);
  1167. if (brk_end == -1) {
  1168. p_rt->add_text(bbcode.substr(brk_pos, bbcode.length() - brk_pos));
  1169. break;
  1170. }
  1171. String tag = bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
  1172. if (tag.begins_with("/")) {
  1173. bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
  1174. if (tag_stack.size()) {
  1175. }
  1176. if (!tag_ok) {
  1177. p_rt->add_text("[");
  1178. pos++;
  1179. continue;
  1180. }
  1181. tag_stack.pop_front();
  1182. pos = brk_end + 1;
  1183. if (tag != "/img")
  1184. p_rt->pop();
  1185. } else if (tag.begins_with("method ")) {
  1186. String m = tag.substr(7, tag.length());
  1187. p_rt->push_color(link_color);
  1188. p_rt->push_meta("@" + m);
  1189. p_rt->add_text(m + "()");
  1190. p_rt->pop();
  1191. p_rt->pop();
  1192. pos = brk_end + 1;
  1193. } else if (doc->class_list.has(tag)) {
  1194. p_rt->push_color(link_color);
  1195. p_rt->push_meta("#" + tag);
  1196. p_rt->add_text(tag);
  1197. p_rt->pop();
  1198. p_rt->pop();
  1199. pos = brk_end + 1;
  1200. } else if (tag == "b") {
  1201. //use bold font
  1202. p_rt->push_font(doc_code_font);
  1203. pos = brk_end + 1;
  1204. tag_stack.push_front(tag);
  1205. } else if (tag == "i") {
  1206. //use italics font
  1207. p_rt->push_color(font_color_hl);
  1208. pos = brk_end + 1;
  1209. tag_stack.push_front(tag);
  1210. } else if (tag == "code" || tag == "codeblock") {
  1211. //use monospace font
  1212. p_rt->push_font(doc_code_font);
  1213. pos = brk_end + 1;
  1214. tag_stack.push_front(tag);
  1215. } else if (tag == "center") {
  1216. //use monospace font
  1217. p_rt->push_align(RichTextLabel::ALIGN_CENTER);
  1218. pos = brk_end + 1;
  1219. tag_stack.push_front(tag);
  1220. } else if (tag == "br") {
  1221. //use monospace font
  1222. p_rt->add_newline();
  1223. pos = brk_end + 1;
  1224. } else if (tag == "u") {
  1225. //use underline
  1226. p_rt->push_underline();
  1227. pos = brk_end + 1;
  1228. tag_stack.push_front(tag);
  1229. } else if (tag == "s") {
  1230. //use strikethrough (not supported underline instead)
  1231. p_rt->push_underline();
  1232. pos = brk_end + 1;
  1233. tag_stack.push_front(tag);
  1234. } else if (tag == "url") {
  1235. //use strikethrough (not supported underline instead)
  1236. int end = bbcode.find("[", brk_end);
  1237. if (end == -1)
  1238. end = bbcode.length();
  1239. String url = bbcode.substr(brk_end + 1, end - brk_end - 1);
  1240. p_rt->push_meta(url);
  1241. pos = brk_end + 1;
  1242. tag_stack.push_front(tag);
  1243. } else if (tag.begins_with("url=")) {
  1244. String url = tag.substr(4, tag.length());
  1245. p_rt->push_meta(url);
  1246. pos = brk_end + 1;
  1247. tag_stack.push_front("url");
  1248. } else if (tag == "img") {
  1249. //use strikethrough (not supported underline instead)
  1250. int end = bbcode.find("[", brk_end);
  1251. if (end == -1)
  1252. end = bbcode.length();
  1253. String image = bbcode.substr(brk_end + 1, end - brk_end - 1);
  1254. Ref<Texture> texture = ResourceLoader::load(base_path + "/" + image, "Texture");
  1255. if (texture.is_valid())
  1256. p_rt->add_image(texture);
  1257. pos = end;
  1258. tag_stack.push_front(tag);
  1259. } else if (tag.begins_with("color=")) {
  1260. String col = tag.substr(6, tag.length());
  1261. Color color;
  1262. if (col.begins_with("#"))
  1263. color = Color::html(col);
  1264. else if (col == "aqua")
  1265. color = Color::html("#00FFFF");
  1266. else if (col == "black")
  1267. color = Color::html("#000000");
  1268. else if (col == "blue")
  1269. color = Color::html("#0000FF");
  1270. else if (col == "fuchsia")
  1271. color = Color::html("#FF00FF");
  1272. else if (col == "gray" || col == "grey")
  1273. color = Color::html("#808080");
  1274. else if (col == "green")
  1275. color = Color::html("#008000");
  1276. else if (col == "lime")
  1277. color = Color::html("#00FF00");
  1278. else if (col == "maroon")
  1279. color = Color::html("#800000");
  1280. else if (col == "navy")
  1281. color = Color::html("#000080");
  1282. else if (col == "olive")
  1283. color = Color::html("#808000");
  1284. else if (col == "purple")
  1285. color = Color::html("#800080");
  1286. else if (col == "red")
  1287. color = Color::html("#FF0000");
  1288. else if (col == "silver")
  1289. color = Color::html("#C0C0C0");
  1290. else if (col == "teal")
  1291. color = Color::html("#008008");
  1292. else if (col == "white")
  1293. color = Color::html("#FFFFFF");
  1294. else if (col == "yellow")
  1295. color = Color::html("#FFFF00");
  1296. else
  1297. color = Color(0, 0, 0, 1); //base_color;
  1298. p_rt->push_color(color);
  1299. pos = brk_end + 1;
  1300. tag_stack.push_front("color");
  1301. } else if (tag.begins_with("font=")) {
  1302. String fnt = tag.substr(5, tag.length());
  1303. Ref<Font> font = ResourceLoader::load(base_path + "/" + fnt, "Font");
  1304. if (font.is_valid())
  1305. p_rt->push_font(font);
  1306. else {
  1307. p_rt->push_font(doc_font);
  1308. }
  1309. pos = brk_end + 1;
  1310. tag_stack.push_front("font");
  1311. } else {
  1312. p_rt->add_text("["); //ignore
  1313. pos = brk_pos + 1;
  1314. }
  1315. }
  1316. /*p_rt->pop();
  1317. p_rt->pop();
  1318. p_rt->pop();*/
  1319. }
  1320. void EditorHelp::_add_text(const String &p_bbcode) {
  1321. _add_text_to_rt(p_bbcode, class_desc);
  1322. }
  1323. void EditorHelp::_update_doc() {
  1324. }
  1325. void EditorHelp::generate_doc() {
  1326. doc = memnew(DocData);
  1327. doc->generate(true);
  1328. DocData compdoc;
  1329. compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
  1330. doc->merge_from(compdoc); //ensure all is up to date
  1331. }
  1332. void EditorHelp::_notification(int p_what) {
  1333. switch (p_what) {
  1334. case NOTIFICATION_READY: {
  1335. //forward->set_icon(get_icon("Forward","EditorIcons"));
  1336. //back->set_icon(get_icon("Back","EditorIcons"));
  1337. _update_doc();
  1338. } break;
  1339. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1340. class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor"));
  1341. } break;
  1342. default: break;
  1343. }
  1344. }
  1345. void EditorHelp::go_to_help(const String &p_help) {
  1346. _help_callback(p_help);
  1347. }
  1348. void EditorHelp::go_to_class(const String &p_class, int p_scroll) {
  1349. _goto_desc(p_class, p_scroll);
  1350. }
  1351. Vector<Pair<String, int> > EditorHelp::get_sections() {
  1352. Vector<Pair<String, int> > sections;
  1353. for (int i = 0; i < section_line.size(); i++) {
  1354. sections.push_back(Pair<String, int>(section_line[i].first, i));
  1355. }
  1356. return sections;
  1357. }
  1358. void EditorHelp::scroll_to_section(int p_section_index) {
  1359. int line = section_line[p_section_index].second;
  1360. class_desc->scroll_to_line(line);
  1361. }
  1362. void EditorHelp::popup_search() {
  1363. search_dialog->popup_centered(Size2(250, 80) * EDSCALE);
  1364. search->grab_focus();
  1365. }
  1366. void EditorHelp::_search_cbk() {
  1367. _search(search->get_text());
  1368. }
  1369. String EditorHelp::get_class() {
  1370. return edited_class;
  1371. }
  1372. void EditorHelp::search_again() {
  1373. _search(prev_search);
  1374. }
  1375. int EditorHelp::get_scroll() const {
  1376. return class_desc->get_v_scroll()->get_value();
  1377. }
  1378. void EditorHelp::set_scroll(int p_scroll) {
  1379. class_desc->get_v_scroll()->set_value(p_scroll);
  1380. }
  1381. void EditorHelp::_bind_methods() {
  1382. ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
  1383. ClassDB::bind_method("_class_desc_select", &EditorHelp::_class_desc_select);
  1384. ClassDB::bind_method("_class_desc_input", &EditorHelp::_class_desc_input);
  1385. //ClassDB::bind_method("_button_pressed",&EditorHelp::_button_pressed);
  1386. ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
  1387. ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input);
  1388. ClassDB::bind_method("_search", &EditorHelp::_search);
  1389. ClassDB::bind_method("_search_cbk", &EditorHelp::_search_cbk);
  1390. ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);
  1391. ADD_SIGNAL(MethodInfo("go_to_help"));
  1392. }
  1393. EditorHelp::EditorHelp() {
  1394. VBoxContainer *vbc = this;
  1395. EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true);
  1396. //class_list->connect("meta_clicked",this,"_class_list_select");
  1397. //class_list->set_selection_enabled(true);
  1398. {
  1399. class_desc = memnew(RichTextLabel);
  1400. vbc->add_child(class_desc);
  1401. class_desc->set_v_size_flags(SIZE_EXPAND_FILL);
  1402. class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor"));
  1403. class_desc->connect("meta_clicked", this, "_class_desc_select");
  1404. class_desc->connect("gui_input", this, "_class_desc_input");
  1405. }
  1406. class_desc->set_selection_enabled(true);
  1407. scroll_locked = false;
  1408. select_locked = false;
  1409. set_process_unhandled_key_input(true);
  1410. class_desc->hide();
  1411. search_dialog = memnew(ConfirmationDialog);
  1412. add_child(search_dialog);
  1413. VBoxContainer *search_vb = memnew(VBoxContainer);
  1414. search_dialog->add_child(search_vb);
  1415. search = memnew(LineEdit);
  1416. search_dialog->register_text_enter(search);
  1417. search_vb->add_margin_child(TTR("Search Text"), search);
  1418. search_dialog->get_ok()->set_text(TTR("Find"));
  1419. search_dialog->connect("confirmed", this, "_search_cbk");
  1420. search_dialog->set_hide_on_ok(false);
  1421. /*class_search = memnew( EditorHelpSearch(editor) );
  1422. editor->get_gui_base()->add_child(class_search);
  1423. class_search->connect("go_to_help",this,"_help_callback");*/
  1424. //prev_search_page=-1;
  1425. }
  1426. EditorHelp::~EditorHelp() {
  1427. }
  1428. /////////////
  1429. void EditorHelpBit::_go_to_help(String p_what) {
  1430. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  1431. ScriptEditor::get_singleton()->goto_help(p_what);
  1432. emit_signal("request_hide");
  1433. }
  1434. void EditorHelpBit::_meta_clicked(String p_select) {
  1435. print_line("got meta " + p_select);
  1436. //print_line("LINK: "+p_select);
  1437. if (p_select.begins_with("$")) { //enum
  1438. //_goto_desc(p_select.substr(1,p_select.length()));
  1439. String select = p_select.substr(1, p_select.length());
  1440. String class_name;
  1441. if (select.find(".") != -1) {
  1442. class_name = select.get_slice(".", 0);
  1443. } else {
  1444. class_name = "@Global";
  1445. }
  1446. _go_to_help("class_enum:" + class_name + ":" + select);
  1447. return;
  1448. } else if (p_select.begins_with("#")) {
  1449. //_goto_desc(p_select.substr(1,p_select.length()));
  1450. _go_to_help("class_name:" + p_select.substr(1, p_select.length()));
  1451. return;
  1452. } else if (p_select.begins_with("@")) {
  1453. String m = p_select.substr(1, p_select.length());
  1454. if (m.find(".") != -1) {
  1455. //must go somewhere else
  1456. _go_to_help("class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0));
  1457. } else {
  1458. /*
  1459. if (!method_line.has(m))
  1460. return;
  1461. class_desc->scroll_to_line(method_line[m]);
  1462. */
  1463. }
  1464. }
  1465. }
  1466. void EditorHelpBit::_bind_methods() {
  1467. ClassDB::bind_method("_meta_clicked", &EditorHelpBit::_meta_clicked);
  1468. ADD_SIGNAL(MethodInfo("request_hide"));
  1469. }
  1470. void EditorHelpBit::_notification(int p_what) {
  1471. switch (p_what) {
  1472. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1473. rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor"));
  1474. } break;
  1475. default: break;
  1476. }
  1477. }
  1478. void EditorHelpBit::set_text(const String &p_text) {
  1479. rich_text->clear();
  1480. _add_text_to_rt(p_text, rich_text);
  1481. }
  1482. EditorHelpBit::EditorHelpBit() {
  1483. rich_text = memnew(RichTextLabel);
  1484. add_child(rich_text);
  1485. rich_text->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1486. rich_text->connect("meta_clicked", this, "_meta_clicked");
  1487. rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor"));
  1488. rich_text->set_override_selected_font_color(false);
  1489. set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  1490. }