editor_help.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. /*************************************************************************/
  2. /* editor_help.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 "editor_help.h"
  31. #include "core/os/keyboard.h"
  32. #include "doc_data_compressed.gen.h"
  33. #include "editor/plugins/script_editor_plugin.h"
  34. #include "editor_node.h"
  35. #include "editor_settings.h"
  36. #define CONTRIBUTE_URL "https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html"
  37. #define CONTRIBUTE2_URL "https://github.com/godotengine/godot-docs"
  38. #define REQUEST_URL "https://github.com/godotengine/godot-docs/issues/new"
  39. DocData *EditorHelp::doc = NULL;
  40. void EditorHelp::_init_colors() {
  41. title_color = get_color("accent_color", "Editor");
  42. text_color = get_color("default_color", "RichTextLabel");
  43. headline_color = get_color("headline_color", "EditorHelp");
  44. base_type_color = title_color.linear_interpolate(text_color, 0.5);
  45. comment_color = text_color * Color(1, 1, 1, 0.6);
  46. symbol_color = comment_color;
  47. value_color = text_color * Color(1, 1, 1, 0.4);
  48. qualifier_color = text_color * Color(1, 1, 1, 0.8);
  49. type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
  50. class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  51. }
  52. void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
  53. if (!is_visible_in_tree())
  54. return;
  55. Ref<InputEventKey> k = p_ev;
  56. if (k.is_valid() && k->get_control() && k->get_scancode() == KEY_F) {
  57. search->grab_focus();
  58. search->select_all();
  59. }
  60. }
  61. void EditorHelp::_search(const String &) {
  62. find_bar->search_next();
  63. }
  64. void EditorHelp::_class_list_select(const String &p_select) {
  65. _goto_desc(p_select);
  66. }
  67. void EditorHelp::_class_desc_select(const String &p_select) {
  68. if (p_select.begins_with("$")) { //enum
  69. String select = p_select.substr(1, p_select.length());
  70. String class_name;
  71. if (select.find(".") != -1) {
  72. class_name = select.get_slice(".", 0);
  73. select = select.get_slice(".", 1);
  74. } else {
  75. class_name = "@GlobalScope";
  76. }
  77. emit_signal("go_to_help", "class_enum:" + class_name + ":" + select);
  78. return;
  79. } else if (p_select.begins_with("#")) {
  80. emit_signal("go_to_help", "class_name:" + p_select.substr(1, p_select.length()));
  81. return;
  82. } else if (p_select.begins_with("@")) {
  83. String tag = p_select.substr(1, 6);
  84. String link = p_select.substr(7, p_select.length());
  85. String topic;
  86. Map<String, int> *table = NULL;
  87. if (tag == "method") {
  88. topic = "class_method";
  89. table = &this->method_line;
  90. } else if (tag == "member") {
  91. topic = "class_property";
  92. table = &this->property_line;
  93. } else if (tag == "enum ") {
  94. topic = "class_enum";
  95. table = &this->enum_line;
  96. } else if (tag == "signal") {
  97. topic = "class_signal";
  98. table = &this->signal_line;
  99. } else {
  100. return;
  101. }
  102. if (link.find(".") != -1) {
  103. emit_signal("go_to_help", topic + ":" + link.get_slice(".", 0) + ":" + link.get_slice(".", 1));
  104. } else {
  105. if (!table->has(link))
  106. return;
  107. class_desc->scroll_to_line((*table)[link]);
  108. }
  109. } else if (p_select.begins_with("http")) {
  110. OS::get_singleton()->shell_open(p_select);
  111. }
  112. }
  113. void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) {
  114. }
  115. void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
  116. String t = p_type;
  117. if (t == "")
  118. t = "void";
  119. bool can_ref = (t != "int" && t != "real" && t != "bool" && t != "void") || p_enum != String();
  120. if (p_enum != String()) {
  121. if (p_enum.get_slice_count(".") > 1) {
  122. t = p_enum.get_slice(".", 1);
  123. } else {
  124. t = p_enum.get_slice(".", 0);
  125. }
  126. }
  127. const Color text_color = get_color("default_color", "RichTextLabel");
  128. const Color type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
  129. class_desc->push_color(type_color);
  130. if (can_ref) {
  131. if (p_enum == "") {
  132. class_desc->push_meta("#" + t); //class
  133. } else {
  134. class_desc->push_meta("$" + p_enum); //class
  135. }
  136. }
  137. class_desc->add_text(t);
  138. if (can_ref)
  139. class_desc->pop();
  140. class_desc->pop();
  141. }
  142. String EditorHelp::_fix_constant(const String &p_constant) const {
  143. if (p_constant.strip_edges() == "4294967295") {
  144. return "0xFFFFFFFF";
  145. }
  146. if (p_constant.strip_edges() == "2147483647") {
  147. return "0x7FFFFFFF";
  148. }
  149. if (p_constant.strip_edges() == "1048575") {
  150. return "0xFFFFF";
  151. }
  152. return p_constant;
  153. }
  154. void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview) {
  155. method_line[p_method.name] = class_desc->get_line_count() - 2; //gets overridden if description
  156. const bool is_vararg = p_method.qualifiers.find("vararg") != -1;
  157. if (p_overview) {
  158. class_desc->push_cell();
  159. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  160. }
  161. _add_type(p_method.return_type, p_method.return_enum);
  162. if (p_overview) {
  163. class_desc->pop(); //align
  164. class_desc->pop(); //cell
  165. class_desc->push_cell();
  166. } else {
  167. class_desc->add_text(" ");
  168. }
  169. if (p_overview && p_method.description != "") {
  170. class_desc->push_meta("@method" + p_method.name);
  171. }
  172. class_desc->push_color(headline_color);
  173. _add_text(p_method.name);
  174. class_desc->pop();
  175. if (p_overview && p_method.description != "") {
  176. class_desc->pop(); //meta
  177. }
  178. class_desc->push_color(symbol_color);
  179. class_desc->add_text(p_method.arguments.size() || is_vararg ? "( " : "(");
  180. class_desc->pop();
  181. for (int j = 0; j < p_method.arguments.size(); j++) {
  182. class_desc->push_color(text_color);
  183. if (j > 0)
  184. class_desc->add_text(", ");
  185. _add_type(p_method.arguments[j].type, p_method.arguments[j].enumeration);
  186. class_desc->add_text(" ");
  187. _add_text(p_method.arguments[j].name);
  188. if (p_method.arguments[j].default_value != "") {
  189. class_desc->push_color(symbol_color);
  190. class_desc->add_text("=");
  191. class_desc->pop();
  192. _add_text(_fix_constant(p_method.arguments[j].default_value));
  193. }
  194. class_desc->pop();
  195. }
  196. if (is_vararg) {
  197. class_desc->push_color(text_color);
  198. if (p_method.arguments.size())
  199. class_desc->add_text(", ");
  200. class_desc->push_color(symbol_color);
  201. class_desc->add_text("...");
  202. class_desc->pop();
  203. class_desc->pop();
  204. }
  205. class_desc->push_color(symbol_color);
  206. class_desc->add_text(p_method.arguments.size() || is_vararg ? " )" : ")");
  207. class_desc->pop();
  208. if (p_method.qualifiers != "") {
  209. class_desc->push_color(qualifier_color);
  210. class_desc->add_text(" ");
  211. _add_text(p_method.qualifiers);
  212. class_desc->pop();
  213. }
  214. if (p_overview)
  215. class_desc->pop(); //cell
  216. }
  217. Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
  218. if (!doc->class_list.has(p_class))
  219. return ERR_DOES_NOT_EXIST;
  220. select_locked = true;
  221. class_desc->show();
  222. description_line = 0;
  223. if (p_class == edited_class)
  224. return OK; //already there
  225. edited_class = p_class;
  226. _update_doc();
  227. return OK;
  228. }
  229. void EditorHelp::_update_doc() {
  230. if (!doc->class_list.has(edited_class))
  231. return;
  232. scroll_locked = true;
  233. class_desc->clear();
  234. method_line.clear();
  235. section_line.clear();
  236. _init_colors();
  237. DocData::ClassDoc cd = doc->class_list[edited_class]; //make a copy, so we can sort without worrying
  238. Ref<Font> doc_font = get_font("doc", "EditorFonts");
  239. Ref<Font> doc_title_font = get_font("doc_title", "EditorFonts");
  240. Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts");
  241. String link_color_text = title_color.to_html(false);
  242. // Class name
  243. section_line.push_back(Pair<String, int>(TTR("Top"), 0));
  244. class_desc->push_font(doc_title_font);
  245. class_desc->push_color(title_color);
  246. class_desc->add_text(TTR("Class:") + " ");
  247. class_desc->push_color(headline_color);
  248. _add_text(edited_class);
  249. class_desc->pop();
  250. class_desc->pop();
  251. class_desc->pop();
  252. class_desc->add_newline();
  253. // Inheritance tree
  254. // Ascendents
  255. if (cd.inherits != "") {
  256. class_desc->push_color(title_color);
  257. class_desc->push_font(doc_font);
  258. class_desc->add_text(TTR("Inherits:") + " ");
  259. class_desc->pop();
  260. String inherits = cd.inherits;
  261. while (inherits != "") {
  262. _add_type(inherits);
  263. inherits = doc->class_list[inherits].inherits;
  264. if (inherits != "") {
  265. class_desc->add_text(" < ");
  266. }
  267. }
  268. class_desc->pop();
  269. class_desc->add_newline();
  270. }
  271. // Descendents
  272. if (ClassDB::class_exists(cd.name)) {
  273. bool found = false;
  274. bool prev = false;
  275. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  276. if (E->get().inherits == cd.name) {
  277. if (!found) {
  278. class_desc->push_color(title_color);
  279. class_desc->push_font(doc_font);
  280. class_desc->add_text(TTR("Inherited by:") + " ");
  281. class_desc->pop();
  282. found = true;
  283. }
  284. if (prev) {
  285. class_desc->add_text(" , ");
  286. prev = false;
  287. }
  288. _add_type(E->get().name);
  289. prev = true;
  290. }
  291. }
  292. if (found)
  293. class_desc->pop();
  294. class_desc->add_newline();
  295. }
  296. class_desc->add_newline();
  297. class_desc->add_newline();
  298. // Brief description
  299. if (cd.brief_description != "") {
  300. class_desc->push_color(title_color);
  301. class_desc->push_font(doc_title_font);
  302. class_desc->add_text(TTR("Brief Description:"));
  303. class_desc->pop();
  304. class_desc->pop();
  305. class_desc->add_newline();
  306. class_desc->push_color(text_color);
  307. class_desc->push_font(doc_font);
  308. class_desc->push_indent(1);
  309. _add_text(cd.brief_description);
  310. class_desc->pop();
  311. class_desc->pop();
  312. class_desc->pop();
  313. class_desc->add_newline();
  314. class_desc->add_newline();
  315. class_desc->add_newline();
  316. }
  317. // Properties overview
  318. Set<String> skip_methods;
  319. bool property_descr = false;
  320. if (cd.properties.size()) {
  321. section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_line_count() - 2));
  322. class_desc->push_color(title_color);
  323. class_desc->push_font(doc_title_font);
  324. class_desc->add_text(TTR("Properties:"));
  325. class_desc->pop();
  326. class_desc->pop();
  327. class_desc->push_indent(1);
  328. class_desc->push_table(2);
  329. class_desc->set_table_column_expand(1, 1);
  330. for (int i = 0; i < cd.properties.size(); i++) {
  331. property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  332. class_desc->push_cell();
  333. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  334. class_desc->push_font(doc_code_font);
  335. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  336. class_desc->pop();
  337. class_desc->pop();
  338. class_desc->pop();
  339. bool describe = false;
  340. if (cd.properties[i].setter != "") {
  341. skip_methods.insert(cd.properties[i].setter);
  342. describe = true;
  343. }
  344. if (cd.properties[i].getter != "") {
  345. skip_methods.insert(cd.properties[i].getter);
  346. describe = true;
  347. }
  348. if (cd.properties[i].description != "") {
  349. describe = true;
  350. }
  351. class_desc->push_cell();
  352. if (describe) {
  353. class_desc->push_meta("@member" + cd.properties[i].name);
  354. }
  355. class_desc->push_font(doc_code_font);
  356. class_desc->push_color(headline_color);
  357. _add_text(cd.properties[i].name);
  358. if (describe) {
  359. class_desc->pop();
  360. property_descr = true;
  361. }
  362. class_desc->pop();
  363. class_desc->pop();
  364. class_desc->pop();
  365. }
  366. class_desc->pop(); //table
  367. class_desc->pop();
  368. class_desc->add_newline();
  369. class_desc->add_newline();
  370. }
  371. // Methods overview
  372. bool method_descr = false;
  373. bool sort_methods = EditorSettings::get_singleton()->get("text_editor/help/sort_functions_alphabetically");
  374. Vector<DocData::MethodDoc> methods;
  375. for (int i = 0; i < cd.methods.size(); i++) {
  376. if (skip_methods.has(cd.methods[i].name))
  377. continue;
  378. methods.push_back(cd.methods[i]);
  379. }
  380. if (methods.size()) {
  381. if (sort_methods)
  382. methods.sort();
  383. section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_line_count() - 2));
  384. class_desc->push_color(title_color);
  385. class_desc->push_font(doc_title_font);
  386. class_desc->add_text(TTR("Methods:"));
  387. class_desc->pop();
  388. class_desc->pop();
  389. class_desc->push_font(doc_code_font);
  390. class_desc->push_indent(1);
  391. class_desc->push_table(2);
  392. class_desc->set_table_column_expand(1, 1);
  393. bool any_previous = false;
  394. for (int pass = 0; pass < 2; pass++) {
  395. Vector<DocData::MethodDoc> m;
  396. for (int i = 0; i < methods.size(); i++) {
  397. const String &q = methods[i].qualifiers;
  398. if ((pass == 0 && q.find("virtual") != -1) || (pass == 1 && q.find("virtual") == -1)) {
  399. m.push_back(methods[i]);
  400. }
  401. }
  402. if (any_previous && !m.empty()) {
  403. class_desc->push_cell();
  404. class_desc->pop(); //cell
  405. class_desc->push_cell();
  406. class_desc->pop(); //cell
  407. any_previous = false;
  408. }
  409. String group_prefix;
  410. for (int i = 0; i < m.size(); i++) {
  411. const String new_prefix = m[i].name.substr(0, 3);
  412. bool is_new_group = false;
  413. if (i < m.size() - 1 && new_prefix == m[i + 1].name.substr(0, 3) && new_prefix != group_prefix) {
  414. is_new_group = i > 0;
  415. group_prefix = new_prefix;
  416. } else if (group_prefix != "" && new_prefix != group_prefix) {
  417. is_new_group = true;
  418. group_prefix = "";
  419. }
  420. if (is_new_group && pass == 1) {
  421. class_desc->push_cell();
  422. class_desc->pop(); //cell
  423. class_desc->push_cell();
  424. class_desc->pop(); //cell
  425. }
  426. if (m[i].description != "") {
  427. method_descr = true;
  428. }
  429. _add_method(m[i], true);
  430. }
  431. any_previous = !m.empty();
  432. }
  433. class_desc->pop(); //table
  434. class_desc->pop();
  435. class_desc->pop(); // font
  436. class_desc->add_newline();
  437. class_desc->add_newline();
  438. }
  439. // Theme properties
  440. if (cd.theme_properties.size()) {
  441. section_line.push_back(Pair<String, int>(TTR("Theme Properties"), class_desc->get_line_count() - 2));
  442. class_desc->push_color(title_color);
  443. class_desc->push_font(doc_title_font);
  444. class_desc->add_text(TTR("Theme Properties:"));
  445. class_desc->pop();
  446. class_desc->pop();
  447. class_desc->push_indent(1);
  448. class_desc->push_table(2);
  449. class_desc->set_table_column_expand(1, 1);
  450. for (int i = 0; i < cd.theme_properties.size(); i++) {
  451. theme_property_line[cd.theme_properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  452. class_desc->push_cell();
  453. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  454. class_desc->push_font(doc_code_font);
  455. _add_type(cd.theme_properties[i].type);
  456. class_desc->pop();
  457. class_desc->pop();
  458. class_desc->pop();
  459. class_desc->push_cell();
  460. class_desc->push_font(doc_code_font);
  461. class_desc->push_color(headline_color);
  462. _add_text(cd.theme_properties[i].name);
  463. class_desc->pop();
  464. class_desc->pop();
  465. if (cd.theme_properties[i].description != "") {
  466. class_desc->push_font(doc_font);
  467. class_desc->add_text(" ");
  468. class_desc->push_color(comment_color);
  469. _add_text(cd.theme_properties[i].description);
  470. class_desc->pop();
  471. class_desc->pop();
  472. }
  473. class_desc->pop(); // cell
  474. }
  475. class_desc->pop(); // table
  476. class_desc->pop();
  477. class_desc->add_newline();
  478. class_desc->add_newline();
  479. }
  480. // Signals
  481. if (cd.signals.size()) {
  482. if (sort_methods) {
  483. cd.signals.sort();
  484. }
  485. section_line.push_back(Pair<String, int>(TTR("Signals"), class_desc->get_line_count() - 2));
  486. class_desc->push_color(title_color);
  487. class_desc->push_font(doc_title_font);
  488. class_desc->add_text(TTR("Signals:"));
  489. class_desc->pop();
  490. class_desc->pop();
  491. class_desc->add_newline();
  492. class_desc->add_newline();
  493. class_desc->push_indent(1);
  494. for (int i = 0; i < cd.signals.size(); i++) {
  495. signal_line[cd.signals[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
  496. class_desc->push_font(doc_code_font); // monofont
  497. class_desc->push_color(headline_color);
  498. _add_text(cd.signals[i].name);
  499. class_desc->pop();
  500. class_desc->push_color(symbol_color);
  501. class_desc->add_text(cd.signals[i].arguments.size() ? "( " : "(");
  502. class_desc->pop();
  503. for (int j = 0; j < cd.signals[i].arguments.size(); j++) {
  504. class_desc->push_color(text_color);
  505. if (j > 0)
  506. class_desc->add_text(", ");
  507. _add_type(cd.signals[i].arguments[j].type);
  508. class_desc->add_text(" ");
  509. _add_text(cd.signals[i].arguments[j].name);
  510. if (cd.signals[i].arguments[j].default_value != "") {
  511. class_desc->push_color(symbol_color);
  512. class_desc->add_text("=");
  513. class_desc->pop();
  514. _add_text(cd.signals[i].arguments[j].default_value);
  515. }
  516. class_desc->pop();
  517. }
  518. class_desc->push_color(symbol_color);
  519. class_desc->add_text(cd.signals[i].arguments.size() ? " )" : ")");
  520. class_desc->pop();
  521. class_desc->pop(); // end monofont
  522. if (cd.signals[i].description != "") {
  523. class_desc->push_font(doc_font);
  524. class_desc->push_color(comment_color);
  525. class_desc->push_indent(1);
  526. _add_text(cd.signals[i].description);
  527. class_desc->pop(); // indent
  528. class_desc->pop();
  529. class_desc->pop(); // font
  530. }
  531. class_desc->add_newline();
  532. class_desc->add_newline();
  533. }
  534. class_desc->pop();
  535. class_desc->add_newline();
  536. }
  537. // Constants and enums
  538. if (cd.constants.size()) {
  539. Map<String, Vector<DocData::ConstantDoc> > enums;
  540. Vector<DocData::ConstantDoc> constants;
  541. for (int i = 0; i < cd.constants.size(); i++) {
  542. if (cd.constants[i].enumeration != String()) {
  543. if (!enums.has(cd.constants[i].enumeration)) {
  544. enums[cd.constants[i].enumeration] = Vector<DocData::ConstantDoc>();
  545. }
  546. enums[cd.constants[i].enumeration].push_back(cd.constants[i]);
  547. } else {
  548. constants.push_back(cd.constants[i]);
  549. }
  550. }
  551. // Enums
  552. if (enums.size()) {
  553. section_line.push_back(Pair<String, int>(TTR("Enumerations"), class_desc->get_line_count() - 2));
  554. class_desc->push_color(title_color);
  555. class_desc->push_font(doc_title_font);
  556. class_desc->add_text(TTR("Enumerations:"));
  557. class_desc->pop();
  558. class_desc->pop();
  559. class_desc->push_indent(1);
  560. class_desc->add_newline();
  561. for (Map<String, Vector<DocData::ConstantDoc> >::Element *E = enums.front(); E; E = E->next()) {
  562. enum_line[E->key()] = class_desc->get_line_count() - 2;
  563. class_desc->push_color(title_color);
  564. class_desc->add_text(TTR("enum "));
  565. class_desc->pop();
  566. class_desc->push_font(doc_code_font);
  567. String e = E->key();
  568. if (e.get_slice_count(".")) {
  569. e = e.get_slice(".", 1);
  570. }
  571. class_desc->push_color(headline_color);
  572. class_desc->add_text(e);
  573. class_desc->pop();
  574. class_desc->pop();
  575. class_desc->push_color(symbol_color);
  576. class_desc->add_text(":");
  577. class_desc->pop();
  578. class_desc->add_newline();
  579. class_desc->push_indent(1);
  580. Vector<DocData::ConstantDoc> enum_list = E->get();
  581. Map<String, int> enumValuesContainer;
  582. int enumStartingLine = enum_line[E->key()];
  583. for (int i = 0; i < enum_list.size(); i++) {
  584. if (cd.name == "@GlobalScope")
  585. enumValuesContainer[enum_list[i].name] = enumStartingLine;
  586. class_desc->push_font(doc_code_font);
  587. class_desc->push_color(headline_color);
  588. _add_text(enum_list[i].name);
  589. class_desc->pop();
  590. class_desc->push_color(symbol_color);
  591. class_desc->add_text(" = ");
  592. class_desc->pop();
  593. class_desc->push_color(value_color);
  594. _add_text(enum_list[i].value);
  595. class_desc->pop();
  596. class_desc->pop();
  597. if (enum_list[i].description != "") {
  598. class_desc->push_font(doc_font);
  599. //class_desc->add_text(" ");
  600. class_desc->push_indent(1);
  601. class_desc->push_color(comment_color);
  602. _add_text(enum_list[i].description);
  603. class_desc->pop();
  604. class_desc->pop();
  605. class_desc->pop(); // indent
  606. class_desc->add_newline();
  607. }
  608. class_desc->add_newline();
  609. }
  610. if (cd.name == "@GlobalScope")
  611. enum_values_line[E->key()] = enumValuesContainer;
  612. class_desc->pop();
  613. class_desc->add_newline();
  614. }
  615. class_desc->pop();
  616. class_desc->add_newline();
  617. }
  618. // Constants
  619. if (constants.size()) {
  620. section_line.push_back(Pair<String, int>(TTR("Constants"), class_desc->get_line_count() - 2));
  621. class_desc->push_color(title_color);
  622. class_desc->push_font(doc_title_font);
  623. class_desc->add_text(TTR("Constants:"));
  624. class_desc->pop();
  625. class_desc->pop();
  626. class_desc->push_indent(1);
  627. class_desc->add_newline();
  628. for (int i = 0; i < constants.size(); i++) {
  629. constant_line[constants[i].name] = class_desc->get_line_count() - 2;
  630. class_desc->push_font(doc_code_font);
  631. if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) {
  632. String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", "");
  633. Vector<float> color = stripped.split_floats(",");
  634. if (color.size() >= 3) {
  635. class_desc->push_color(Color(color[0], color[1], color[2]));
  636. static const CharType prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
  637. class_desc->add_text(String(prefix));
  638. class_desc->pop();
  639. }
  640. }
  641. class_desc->push_color(headline_color);
  642. _add_text(constants[i].name);
  643. class_desc->pop();
  644. class_desc->push_color(symbol_color);
  645. class_desc->add_text(" = ");
  646. class_desc->pop();
  647. class_desc->push_color(value_color);
  648. _add_text(constants[i].value);
  649. class_desc->pop();
  650. class_desc->pop();
  651. if (constants[i].description != "") {
  652. class_desc->push_font(doc_font);
  653. class_desc->push_indent(1);
  654. class_desc->push_color(comment_color);
  655. _add_text(constants[i].description);
  656. class_desc->pop();
  657. class_desc->pop();
  658. class_desc->pop(); // indent
  659. class_desc->add_newline();
  660. }
  661. class_desc->add_newline();
  662. }
  663. class_desc->pop();
  664. class_desc->add_newline();
  665. }
  666. }
  667. // Class description
  668. if (cd.description != "") {
  669. section_line.push_back(Pair<String, int>(TTR("Class Description"), class_desc->get_line_count() - 2));
  670. description_line = class_desc->get_line_count() - 2;
  671. class_desc->push_color(title_color);
  672. class_desc->push_font(doc_title_font);
  673. class_desc->add_text(TTR("Class Description:"));
  674. class_desc->pop();
  675. class_desc->pop();
  676. class_desc->add_newline();
  677. class_desc->push_color(text_color);
  678. class_desc->push_font(doc_font);
  679. class_desc->push_indent(1);
  680. _add_text(cd.description);
  681. class_desc->pop();
  682. class_desc->pop();
  683. class_desc->pop();
  684. class_desc->add_newline();
  685. class_desc->add_newline();
  686. class_desc->add_newline();
  687. }
  688. // Online tutorials
  689. {
  690. class_desc->push_color(title_color);
  691. class_desc->push_font(doc_title_font);
  692. class_desc->add_text(TTR("Online Tutorials:"));
  693. class_desc->pop();
  694. class_desc->pop();
  695. class_desc->push_indent(1);
  696. class_desc->push_font(doc_code_font);
  697. class_desc->add_newline();
  698. // class_desc->add_newline();
  699. if (cd.tutorials.size() != 0) {
  700. for (int i = 0; i < cd.tutorials.size(); i++) {
  701. String link = cd.tutorials[i];
  702. String linktxt = link;
  703. int seppos = linktxt.find("//");
  704. if (seppos != -1) {
  705. linktxt = link.right(seppos + 2);
  706. }
  707. class_desc->push_color(symbol_color);
  708. class_desc->append_bbcode("[url=" + link + "]" + linktxt + "[/url]");
  709. class_desc->pop();
  710. class_desc->add_newline();
  711. }
  712. } else {
  713. class_desc->push_color(comment_color);
  714. class_desc->append_bbcode(TTR("There are currently no tutorials for this class, you can [color=$color][url=$url]contribute one[/url][/color] or [color=$color][url=$url2]request one[/url][/color].").replace("$url2", REQUEST_URL).replace("$url", CONTRIBUTE2_URL).replace("$color", link_color_text));
  715. class_desc->pop();
  716. }
  717. class_desc->pop();
  718. class_desc->pop();
  719. class_desc->add_newline();
  720. class_desc->add_newline();
  721. }
  722. // Property descriptions
  723. if (property_descr) {
  724. section_line.push_back(Pair<String, int>(TTR("Property Descriptions"), class_desc->get_line_count() - 2));
  725. class_desc->push_color(title_color);
  726. class_desc->push_font(doc_title_font);
  727. class_desc->add_text(TTR("Property Descriptions:"));
  728. class_desc->pop();
  729. class_desc->pop();
  730. class_desc->add_newline();
  731. class_desc->add_newline();
  732. for (int i = 0; i < cd.properties.size(); i++) {
  733. property_line[cd.properties[i].name] = class_desc->get_line_count() - 2;
  734. class_desc->push_table(2);
  735. class_desc->set_table_column_expand(1, 1);
  736. class_desc->push_cell();
  737. class_desc->push_font(doc_code_font);
  738. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  739. class_desc->add_text(" ");
  740. class_desc->pop(); // font
  741. class_desc->pop(); // cell
  742. class_desc->push_cell();
  743. class_desc->push_font(doc_code_font);
  744. class_desc->push_color(headline_color);
  745. _add_text(cd.properties[i].name);
  746. class_desc->pop(); // color
  747. class_desc->pop(); // font
  748. class_desc->pop(); // cell
  749. if (cd.properties[i].setter != "") {
  750. class_desc->push_cell();
  751. class_desc->pop(); // cell
  752. class_desc->push_cell();
  753. class_desc->push_font(doc_code_font);
  754. class_desc->push_color(text_color);
  755. class_desc->add_text(cd.properties[i].setter + "(value)");
  756. class_desc->pop(); // color
  757. class_desc->push_color(comment_color);
  758. class_desc->add_text(" setter");
  759. class_desc->pop(); // color
  760. class_desc->pop(); // font
  761. class_desc->pop(); // cell
  762. }
  763. if (cd.properties[i].getter != "") {
  764. class_desc->push_cell();
  765. class_desc->pop(); // cell
  766. class_desc->push_cell();
  767. class_desc->push_font(doc_code_font);
  768. class_desc->push_color(text_color);
  769. class_desc->add_text(cd.properties[i].getter + "()");
  770. class_desc->pop(); //color
  771. class_desc->push_color(comment_color);
  772. class_desc->add_text(" getter");
  773. class_desc->pop(); //color
  774. class_desc->pop(); //font
  775. class_desc->pop(); //cell
  776. }
  777. class_desc->pop(); // table
  778. class_desc->add_newline();
  779. class_desc->push_color(text_color);
  780. class_desc->push_font(doc_font);
  781. class_desc->push_indent(1);
  782. if (cd.properties[i].description.strip_edges() != String()) {
  783. _add_text(cd.properties[i].description);
  784. } else {
  785. class_desc->add_image(get_icon("Error", "EditorIcons"));
  786. class_desc->add_text(" ");
  787. class_desc->push_color(comment_color);
  788. 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));
  789. class_desc->pop();
  790. }
  791. class_desc->pop();
  792. class_desc->pop();
  793. class_desc->pop();
  794. class_desc->add_newline();
  795. class_desc->add_newline();
  796. class_desc->add_newline();
  797. }
  798. }
  799. // Method descriptions
  800. if (method_descr) {
  801. section_line.push_back(Pair<String, int>(TTR("Method Descriptions"), class_desc->get_line_count() - 2));
  802. class_desc->push_color(title_color);
  803. class_desc->push_font(doc_title_font);
  804. class_desc->add_text(TTR("Method Descriptions:"));
  805. class_desc->pop();
  806. class_desc->pop();
  807. class_desc->add_newline();
  808. class_desc->add_newline();
  809. for (int i = 0; i < methods.size(); i++) {
  810. class_desc->push_font(doc_code_font);
  811. _add_method(methods[i], false);
  812. class_desc->pop();
  813. class_desc->add_newline();
  814. class_desc->push_color(text_color);
  815. class_desc->push_font(doc_font);
  816. class_desc->push_indent(1);
  817. if (methods[i].description.strip_edges() != String()) {
  818. _add_text(methods[i].description);
  819. } else {
  820. class_desc->add_image(get_icon("Error", "EditorIcons"));
  821. class_desc->add_text(" ");
  822. class_desc->push_color(comment_color);
  823. 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));
  824. class_desc->pop();
  825. }
  826. class_desc->pop();
  827. class_desc->pop();
  828. class_desc->pop();
  829. class_desc->add_newline();
  830. class_desc->add_newline();
  831. class_desc->add_newline();
  832. }
  833. }
  834. scroll_locked = false;
  835. }
  836. void EditorHelp::_request_help(const String &p_string) {
  837. Error err = _goto_desc(p_string);
  838. if (err == OK) {
  839. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  840. }
  841. //100 palabras
  842. }
  843. void EditorHelp::_help_callback(const String &p_topic) {
  844. String what = p_topic.get_slice(":", 0);
  845. String clss = p_topic.get_slice(":", 1);
  846. String name;
  847. if (p_topic.get_slice_count(":") == 3)
  848. name = p_topic.get_slice(":", 2);
  849. _request_help(clss); //first go to class
  850. int line = 0;
  851. if (what == "class_desc") {
  852. line = description_line;
  853. } else if (what == "class_signal") {
  854. if (signal_line.has(name))
  855. line = signal_line[name];
  856. } else if (what == "class_method" || what == "class_method_desc") {
  857. if (method_line.has(name))
  858. line = method_line[name];
  859. } else if (what == "class_property") {
  860. if (property_line.has(name))
  861. line = property_line[name];
  862. } else if (what == "class_enum") {
  863. if (enum_line.has(name))
  864. line = enum_line[name];
  865. } else if (what == "class_theme_item") {
  866. if (theme_property_line.has(name))
  867. line = theme_property_line[name];
  868. } else if (what == "class_constant") {
  869. if (constant_line.has(name))
  870. line = constant_line[name];
  871. } else if (what == "class_global") {
  872. if (constant_line.has(name))
  873. line = constant_line[name];
  874. else {
  875. Map<String, Map<String, int> >::Element *iter = enum_values_line.front();
  876. while (true) {
  877. if (iter->value().has(name)) {
  878. line = iter->value()[name];
  879. break;
  880. } else if (iter == enum_values_line.back())
  881. break;
  882. else
  883. iter = iter->next();
  884. }
  885. }
  886. }
  887. class_desc->call_deferred("scroll_to_line", line);
  888. }
  889. static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
  890. DocData *doc = EditorHelp::get_doc_data();
  891. String base_path;
  892. Ref<Font> doc_font = p_rt->get_font("doc", "EditorFonts");
  893. Ref<Font> doc_code_font = p_rt->get_font("doc_source", "EditorFonts");
  894. Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp");
  895. Color link_color = p_rt->get_color("accent_color", "Editor").linear_interpolate(font_color_hl, 0.8);
  896. String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges();
  897. List<String> tag_stack;
  898. bool code_tag = false;
  899. int pos = 0;
  900. while (pos < bbcode.length()) {
  901. int brk_pos = bbcode.find("[", pos);
  902. if (brk_pos < 0)
  903. brk_pos = bbcode.length();
  904. if (brk_pos > pos) {
  905. String text = bbcode.substr(pos, brk_pos - pos);
  906. if (!code_tag)
  907. text = text.replace("\n", "\n\n");
  908. p_rt->add_text(text);
  909. }
  910. if (brk_pos == bbcode.length())
  911. break; //nothing else to add
  912. int brk_end = bbcode.find("]", brk_pos + 1);
  913. if (brk_end == -1) {
  914. String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos);
  915. if (!code_tag)
  916. text = text.replace("\n", "\n\n");
  917. p_rt->add_text(text);
  918. break;
  919. }
  920. String tag = bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
  921. if (tag.begins_with("/")) {
  922. bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
  923. if (!tag_ok) {
  924. p_rt->add_text("[");
  925. pos = brk_pos + 1;
  926. continue;
  927. }
  928. tag_stack.pop_front();
  929. pos = brk_end + 1;
  930. code_tag = false;
  931. if (tag != "/img")
  932. p_rt->pop();
  933. } else if (code_tag) {
  934. p_rt->add_text("[");
  935. pos = brk_pos + 1;
  936. } else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ")) {
  937. String link_target = tag.substr(tag.find(" ") + 1, tag.length());
  938. String link_tag = tag.substr(0, tag.find(" ")).rpad(6);
  939. p_rt->push_color(link_color);
  940. p_rt->push_meta("@" + link_tag + link_target);
  941. p_rt->add_text(link_target + (tag.begins_with("method ") ? "()" : ""));
  942. p_rt->pop();
  943. p_rt->pop();
  944. pos = brk_end + 1;
  945. } else if (doc->class_list.has(tag)) {
  946. p_rt->push_color(link_color);
  947. p_rt->push_meta("#" + tag);
  948. p_rt->add_text(tag);
  949. p_rt->pop();
  950. p_rt->pop();
  951. pos = brk_end + 1;
  952. } else if (tag == "b") {
  953. //use bold font
  954. p_rt->push_font(doc_code_font);
  955. pos = brk_end + 1;
  956. tag_stack.push_front(tag);
  957. } else if (tag == "i") {
  958. //use italics font
  959. p_rt->push_color(font_color_hl);
  960. pos = brk_end + 1;
  961. tag_stack.push_front(tag);
  962. } else if (tag == "code" || tag == "codeblock") {
  963. //use monospace font
  964. p_rt->push_font(doc_code_font);
  965. code_tag = true;
  966. pos = brk_end + 1;
  967. tag_stack.push_front(tag);
  968. } else if (tag == "center") {
  969. //use monospace font
  970. p_rt->push_align(RichTextLabel::ALIGN_CENTER);
  971. pos = brk_end + 1;
  972. tag_stack.push_front(tag);
  973. } else if (tag == "br") {
  974. //use monospace font
  975. p_rt->add_newline();
  976. pos = brk_end + 1;
  977. } else if (tag == "u") {
  978. //use underline
  979. p_rt->push_underline();
  980. pos = brk_end + 1;
  981. tag_stack.push_front(tag);
  982. } else if (tag == "s") {
  983. //use strikethrough (not supported underline instead)
  984. p_rt->push_underline();
  985. pos = brk_end + 1;
  986. tag_stack.push_front(tag);
  987. } else if (tag == "url") {
  988. //use strikethrough (not supported underline instead)
  989. int end = bbcode.find("[", brk_end);
  990. if (end == -1)
  991. end = bbcode.length();
  992. String url = bbcode.substr(brk_end + 1, end - brk_end - 1);
  993. p_rt->push_meta(url);
  994. pos = brk_end + 1;
  995. tag_stack.push_front(tag);
  996. } else if (tag.begins_with("url=")) {
  997. String url = tag.substr(4, tag.length());
  998. p_rt->push_meta(url);
  999. pos = brk_end + 1;
  1000. tag_stack.push_front("url");
  1001. } else if (tag == "img") {
  1002. //use strikethrough (not supported underline instead)
  1003. int end = bbcode.find("[", brk_end);
  1004. if (end == -1)
  1005. end = bbcode.length();
  1006. String image = bbcode.substr(brk_end + 1, end - brk_end - 1);
  1007. Ref<Texture> texture = ResourceLoader::load(base_path + "/" + image, "Texture");
  1008. if (texture.is_valid())
  1009. p_rt->add_image(texture);
  1010. pos = end;
  1011. tag_stack.push_front(tag);
  1012. } else if (tag.begins_with("color=")) {
  1013. String col = tag.substr(6, tag.length());
  1014. Color color;
  1015. if (col.begins_with("#"))
  1016. color = Color::html(col);
  1017. else if (col == "aqua")
  1018. color = Color::html("#00FFFF");
  1019. else if (col == "black")
  1020. color = Color::html("#000000");
  1021. else if (col == "blue")
  1022. color = Color::html("#0000FF");
  1023. else if (col == "fuchsia")
  1024. color = Color::html("#FF00FF");
  1025. else if (col == "gray" || col == "grey")
  1026. color = Color::html("#808080");
  1027. else if (col == "green")
  1028. color = Color::html("#008000");
  1029. else if (col == "lime")
  1030. color = Color::html("#00FF00");
  1031. else if (col == "maroon")
  1032. color = Color::html("#800000");
  1033. else if (col == "navy")
  1034. color = Color::html("#000080");
  1035. else if (col == "olive")
  1036. color = Color::html("#808000");
  1037. else if (col == "purple")
  1038. color = Color::html("#800080");
  1039. else if (col == "red")
  1040. color = Color::html("#FF0000");
  1041. else if (col == "silver")
  1042. color = Color::html("#C0C0C0");
  1043. else if (col == "teal")
  1044. color = Color::html("#008008");
  1045. else if (col == "white")
  1046. color = Color::html("#FFFFFF");
  1047. else if (col == "yellow")
  1048. color = Color::html("#FFFF00");
  1049. else
  1050. color = Color(0, 0, 0, 1); //base_color;
  1051. p_rt->push_color(color);
  1052. pos = brk_end + 1;
  1053. tag_stack.push_front("color");
  1054. } else if (tag.begins_with("font=")) {
  1055. String fnt = tag.substr(5, tag.length());
  1056. Ref<Font> font = ResourceLoader::load(base_path + "/" + fnt, "Font");
  1057. if (font.is_valid())
  1058. p_rt->push_font(font);
  1059. else {
  1060. p_rt->push_font(doc_font);
  1061. }
  1062. pos = brk_end + 1;
  1063. tag_stack.push_front("font");
  1064. } else {
  1065. p_rt->add_text("["); //ignore
  1066. pos = brk_pos + 1;
  1067. }
  1068. }
  1069. }
  1070. void EditorHelp::_add_text(const String &p_bbcode) {
  1071. _add_text_to_rt(p_bbcode, class_desc);
  1072. }
  1073. void EditorHelp::generate_doc() {
  1074. doc = memnew(DocData);
  1075. doc->generate(true);
  1076. DocData compdoc;
  1077. compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
  1078. doc->merge_from(compdoc); //ensure all is up to date
  1079. }
  1080. void EditorHelp::_notification(int p_what) {
  1081. switch (p_what) {
  1082. case NOTIFICATION_READY:
  1083. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1084. _update_doc();
  1085. } break;
  1086. default: break;
  1087. }
  1088. }
  1089. void EditorHelp::go_to_help(const String &p_help) {
  1090. _help_callback(p_help);
  1091. }
  1092. void EditorHelp::go_to_class(const String &p_class, int p_scroll) {
  1093. _goto_desc(p_class, p_scroll);
  1094. }
  1095. Vector<Pair<String, int> > EditorHelp::get_sections() {
  1096. Vector<Pair<String, int> > sections;
  1097. for (int i = 0; i < section_line.size(); i++) {
  1098. sections.push_back(Pair<String, int>(section_line[i].first, i));
  1099. }
  1100. return sections;
  1101. }
  1102. void EditorHelp::scroll_to_section(int p_section_index) {
  1103. int line = section_line[p_section_index].second;
  1104. class_desc->scroll_to_line(line);
  1105. }
  1106. void EditorHelp::popup_search() {
  1107. find_bar->popup_search();
  1108. }
  1109. String EditorHelp::get_class() {
  1110. return edited_class;
  1111. }
  1112. void EditorHelp::search_again() {
  1113. _search(prev_search);
  1114. }
  1115. int EditorHelp::get_scroll() const {
  1116. return class_desc->get_v_scroll()->get_value();
  1117. }
  1118. void EditorHelp::set_scroll(int p_scroll) {
  1119. class_desc->get_v_scroll()->set_value(p_scroll);
  1120. }
  1121. void EditorHelp::_bind_methods() {
  1122. ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
  1123. ClassDB::bind_method("_class_desc_select", &EditorHelp::_class_desc_select);
  1124. ClassDB::bind_method("_class_desc_input", &EditorHelp::_class_desc_input);
  1125. ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
  1126. ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input);
  1127. ClassDB::bind_method("_search", &EditorHelp::_search);
  1128. ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);
  1129. ADD_SIGNAL(MethodInfo("go_to_help"));
  1130. }
  1131. EditorHelp::EditorHelp() {
  1132. set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  1133. EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true);
  1134. class_desc = memnew(RichTextLabel);
  1135. add_child(class_desc);
  1136. class_desc->set_v_size_flags(SIZE_EXPAND_FILL);
  1137. class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1138. class_desc->connect("meta_clicked", this, "_class_desc_select");
  1139. class_desc->connect("gui_input", this, "_class_desc_input");
  1140. // Added second so it opens at the bottom so it won't offset the entire widget.
  1141. find_bar = memnew(FindBar);
  1142. add_child(find_bar);
  1143. find_bar->hide();
  1144. find_bar->set_rich_text_label(class_desc);
  1145. class_desc->set_selection_enabled(true);
  1146. scroll_locked = false;
  1147. select_locked = false;
  1148. class_desc->hide();
  1149. }
  1150. EditorHelp::~EditorHelp() {
  1151. }
  1152. void EditorHelpBit::_go_to_help(String p_what) {
  1153. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  1154. ScriptEditor::get_singleton()->goto_help(p_what);
  1155. emit_signal("request_hide");
  1156. }
  1157. void EditorHelpBit::_meta_clicked(String p_select) {
  1158. if (p_select.begins_with("$")) { //enum
  1159. String select = p_select.substr(1, p_select.length());
  1160. String class_name;
  1161. if (select.find(".") != -1) {
  1162. class_name = select.get_slice(".", 0);
  1163. } else {
  1164. class_name = "@Global";
  1165. }
  1166. _go_to_help("class_enum:" + class_name + ":" + select);
  1167. return;
  1168. } else if (p_select.begins_with("#")) {
  1169. _go_to_help("class_name:" + p_select.substr(1, p_select.length()));
  1170. return;
  1171. } else if (p_select.begins_with("@")) {
  1172. String m = p_select.substr(1, p_select.length());
  1173. if (m.find(".") != -1)
  1174. _go_to_help("class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0)); //must go somewhere else
  1175. }
  1176. }
  1177. void EditorHelpBit::_bind_methods() {
  1178. ClassDB::bind_method("_meta_clicked", &EditorHelpBit::_meta_clicked);
  1179. ClassDB::bind_method(D_METHOD("set_text", "text"), &EditorHelpBit::set_text);
  1180. ADD_SIGNAL(MethodInfo("request_hide"));
  1181. }
  1182. void EditorHelpBit::_notification(int p_what) {
  1183. switch (p_what) {
  1184. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1185. rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1186. } break;
  1187. default: break;
  1188. }
  1189. }
  1190. void EditorHelpBit::set_text(const String &p_text) {
  1191. rich_text->clear();
  1192. _add_text_to_rt(p_text, rich_text);
  1193. }
  1194. EditorHelpBit::EditorHelpBit() {
  1195. rich_text = memnew(RichTextLabel);
  1196. add_child(rich_text);
  1197. rich_text->connect("meta_clicked", this, "_meta_clicked");
  1198. rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1199. rich_text->set_override_selected_font_color(false);
  1200. set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  1201. }
  1202. FindBar::FindBar() {
  1203. search_text = memnew(LineEdit);
  1204. add_child(search_text);
  1205. search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1206. search_text->set_h_size_flags(SIZE_EXPAND_FILL);
  1207. search_text->connect("text_changed", this, "_search_text_changed");
  1208. search_text->connect("text_entered", this, "_search_text_entered");
  1209. find_prev = memnew(ToolButton);
  1210. add_child(find_prev);
  1211. find_prev->set_focus_mode(FOCUS_NONE);
  1212. find_prev->connect("pressed", this, "_search_prev");
  1213. find_next = memnew(ToolButton);
  1214. add_child(find_next);
  1215. find_next->set_focus_mode(FOCUS_NONE);
  1216. find_next->connect("pressed", this, "_search_next");
  1217. error_label = memnew(Label);
  1218. add_child(error_label);
  1219. error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  1220. hide_button = memnew(TextureButton);
  1221. add_child(hide_button);
  1222. hide_button->set_focus_mode(FOCUS_NONE);
  1223. hide_button->set_expand(true);
  1224. hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1225. hide_button->connect("pressed", this, "_hide_pressed");
  1226. }
  1227. void FindBar::popup_search() {
  1228. show();
  1229. bool grabbed_focus = false;
  1230. if (!search_text->has_focus()) {
  1231. search_text->grab_focus();
  1232. grabbed_focus = true;
  1233. }
  1234. if (!search_text->get_text().empty()) {
  1235. search_text->select_all();
  1236. search_text->set_cursor_position(search_text->get_text().length());
  1237. if (grabbed_focus) {
  1238. _search();
  1239. }
  1240. }
  1241. }
  1242. void FindBar::_notification(int p_what) {
  1243. if (p_what == NOTIFICATION_READY) {
  1244. find_prev->set_icon(get_icon("MoveUp", "EditorIcons"));
  1245. find_next->set_icon(get_icon("MoveDown", "EditorIcons"));
  1246. hide_button->set_normal_texture(get_icon("Close", "EditorIcons"));
  1247. hide_button->set_hover_texture(get_icon("Close", "EditorIcons"));
  1248. hide_button->set_pressed_texture(get_icon("Close", "EditorIcons"));
  1249. hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
  1250. } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  1251. set_process_unhandled_input(is_visible_in_tree());
  1252. } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  1253. find_prev->set_icon(get_icon("MoveUp", "EditorIcons"));
  1254. find_next->set_icon(get_icon("MoveDown", "EditorIcons"));
  1255. hide_button->set_normal_texture(get_icon("Close", "EditorIcons"));
  1256. hide_button->set_hover_texture(get_icon("Close", "EditorIcons"));
  1257. hide_button->set_pressed_texture(get_icon("Close", "EditorIcons"));
  1258. hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
  1259. }
  1260. }
  1261. void FindBar::_bind_methods() {
  1262. ClassDB::bind_method("_unhandled_input", &FindBar::_unhandled_input);
  1263. ClassDB::bind_method("_search_text_changed", &FindBar::_search_text_changed);
  1264. ClassDB::bind_method("_search_text_entered", &FindBar::_search_text_entered);
  1265. ClassDB::bind_method("_search_next", &FindBar::search_next);
  1266. ClassDB::bind_method("_search_prev", &FindBar::search_prev);
  1267. ClassDB::bind_method("_hide_pressed", &FindBar::_hide_bar);
  1268. ADD_SIGNAL(MethodInfo("search"));
  1269. }
  1270. void FindBar::set_rich_text_label(RichTextLabel *p_rich_text_label) {
  1271. rich_text_label = p_rich_text_label;
  1272. }
  1273. bool FindBar::search_next() {
  1274. return _search();
  1275. }
  1276. bool FindBar::search_prev() {
  1277. return _search(true);
  1278. }
  1279. bool FindBar::_search(bool p_search_previous) {
  1280. String stext = search_text->get_text();
  1281. bool keep = prev_search == stext;
  1282. bool ret = rich_text_label->search(stext, keep, p_search_previous);
  1283. if (!ret) {
  1284. ret = rich_text_label->search(stext, false, p_search_previous);
  1285. }
  1286. prev_search = stext;
  1287. if (ret) {
  1288. set_error("");
  1289. } else {
  1290. set_error(stext.empty() ? "" : TTR("No Matches"));
  1291. }
  1292. return ret;
  1293. }
  1294. void FindBar::set_error(const String &p_label) {
  1295. error_label->set_text(p_label);
  1296. }
  1297. void FindBar::_hide_bar() {
  1298. if (search_text->has_focus())
  1299. rich_text_label->grab_focus();
  1300. hide();
  1301. }
  1302. void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) {
  1303. Ref<InputEventKey> k = p_event;
  1304. if (k.is_valid()) {
  1305. if (k->is_pressed() && (rich_text_label->has_focus() || is_a_parent_of(get_focus_owner()))) {
  1306. bool accepted = true;
  1307. switch (k->get_scancode()) {
  1308. case KEY_ESCAPE: {
  1309. _hide_bar();
  1310. } break;
  1311. default: {
  1312. accepted = false;
  1313. } break;
  1314. }
  1315. if (accepted) {
  1316. accept_event();
  1317. }
  1318. }
  1319. }
  1320. }
  1321. void FindBar::_search_text_changed(const String &p_text) {
  1322. search_next();
  1323. }
  1324. void FindBar::_search_text_entered(const String &p_text) {
  1325. search_next();
  1326. }