editor_help.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  1. /**************************************************************************/
  2. /* editor_help.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_help.h"
  31. #include "core/os/input.h"
  32. #include "core/os/keyboard.h"
  33. #include "core/version_generated.gen.h"
  34. #include "doc_data_compressed.gen.h"
  35. #include "editor/plugins/script_editor_plugin.h"
  36. #include "editor_node.h"
  37. #include "editor_scale.h"
  38. #include "editor_settings.h"
  39. #define CONTRIBUTE_URL vformat("%s/community/contributing/updating_the_class_reference.html", VERSION_DOCS_URL)
  40. DocData *EditorHelp::doc = nullptr;
  41. void EditorHelp::_init_colors() {
  42. title_color = get_color("accent_color", "Editor");
  43. text_color = get_color("default_color", "RichTextLabel");
  44. headline_color = get_color("headline_color", "EditorHelp");
  45. base_type_color = title_color.linear_interpolate(text_color, 0.5);
  46. comment_color = text_color * Color(1, 1, 1, 0.6);
  47. symbol_color = comment_color;
  48. value_color = text_color * Color(1, 1, 1, 0.6);
  49. qualifier_color = text_color * Color(1, 1, 1, 0.8);
  50. type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
  51. class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  52. class_desc->add_constant_override("line_separation", Math::round(5 * EDSCALE));
  53. }
  54. void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
  55. if (!is_visible_in_tree()) {
  56. return;
  57. }
  58. Ref<InputEventKey> k = p_ev;
  59. if (k.is_valid() && k->get_control() && k->get_scancode() == KEY_F) {
  60. search->grab_focus();
  61. search->select_all();
  62. }
  63. }
  64. void EditorHelp::_search(bool p_search_previous) {
  65. if (p_search_previous) {
  66. find_bar->search_prev();
  67. } else {
  68. find_bar->search_next();
  69. }
  70. }
  71. void EditorHelp::_class_list_select(const String &p_select) {
  72. _goto_desc(p_select);
  73. }
  74. void EditorHelp::_class_desc_select(const String &p_select) {
  75. if (p_select.begins_with("$")) { // enum
  76. String select = p_select.substr(1, p_select.length());
  77. String class_name;
  78. if (select.find(".") != -1) {
  79. class_name = select.get_slice(".", 0);
  80. select = select.get_slice(".", 1);
  81. } else {
  82. class_name = "@GlobalScope";
  83. }
  84. emit_signal("go_to_help", "class_enum:" + class_name + ":" + select);
  85. return;
  86. } else if (p_select.begins_with("#")) {
  87. emit_signal("go_to_help", "class_name:" + p_select.substr(1, p_select.length()));
  88. return;
  89. } else if (p_select.begins_with("@")) {
  90. int tag_end = p_select.find(" ");
  91. String tag = p_select.substr(1, tag_end - 1);
  92. String link = p_select.substr(tag_end + 1, p_select.length()).lstrip(" ");
  93. String topic;
  94. Map<String, int> *table = nullptr;
  95. if (tag == "method") {
  96. topic = "class_method";
  97. table = &this->method_line;
  98. } else if (tag == "member") {
  99. topic = "class_property";
  100. table = &this->property_line;
  101. } else if (tag == "enum") {
  102. topic = "class_enum";
  103. table = &this->enum_line;
  104. } else if (tag == "signal") {
  105. topic = "class_signal";
  106. table = &this->signal_line;
  107. } else if (tag == "constant") {
  108. topic = "class_constant";
  109. table = &this->constant_line;
  110. } else {
  111. return;
  112. }
  113. // Case order is important here to correctly handle edge cases like Variant.Type in @GlobalScope.
  114. if (table->has(link)) {
  115. // Found in the current page.
  116. class_desc->scroll_to_line((*table)[link]);
  117. } else {
  118. // Look for link in @GlobalScope
  119. // Note that a link like @GlobalScope.enum_name won't be found in this section, only enum_name will be
  120. if (topic == "class_enum") {
  121. const DocData::ClassDoc &cd = doc->class_list["@GlobalScope"];
  122. for (int i = 0; i < cd.constants.size(); i++) {
  123. if (cd.constants[i].enumeration == link) {
  124. // Found in @GlobalScope.
  125. emit_signal("go_to_help", topic + ":@GlobalScope:" + link);
  126. return;
  127. }
  128. }
  129. } else if (topic == "class_constant") {
  130. const DocData::ClassDoc &cd = doc->class_list["@GlobalScope"];
  131. for (int i = 0; i < cd.constants.size(); i++) {
  132. if (cd.constants[i].name == link) {
  133. // Found in @GlobalScope.
  134. emit_signal("go_to_help", topic + ":@GlobalScope:" + link);
  135. return;
  136. }
  137. }
  138. }
  139. if (link.find(".") != -1) {
  140. // Parse the link as Class.X.
  141. int class_end = link.find(".");
  142. emit_signal("go_to_help", topic + ":" + link.substr(0, class_end) + ":" + link.substr(class_end + 1, link.length()));
  143. }
  144. }
  145. } else if (p_select.begins_with("http")) {
  146. OS::get_singleton()->shell_open(p_select);
  147. }
  148. }
  149. void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) {
  150. }
  151. void EditorHelp::_class_desc_resized() {
  152. // Add extra horizontal margins for better readability.
  153. // The margins increase as the width of the editor help container increases.
  154. Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts");
  155. real_t char_width = doc_code_font->get_char_size('x').width;
  156. const int display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - char_width * 120 * EDSCALE) * 0.5;
  157. Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_stylebox("normal", "RichTextLabel")->duplicate();
  158. class_desc_stylebox->set_default_margin(MARGIN_LEFT, display_margin);
  159. class_desc_stylebox->set_default_margin(MARGIN_RIGHT, display_margin);
  160. class_desc->add_style_override("normal", class_desc_stylebox);
  161. }
  162. void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
  163. String t = p_type;
  164. if (t.empty()) {
  165. t = "void";
  166. }
  167. bool can_ref = (t != "void") || !p_enum.empty();
  168. if (!p_enum.empty()) {
  169. if (p_enum.get_slice_count(".") > 1) {
  170. t = p_enum.get_slice(".", 1);
  171. } else {
  172. t = p_enum.get_slice(".", 0);
  173. }
  174. }
  175. const Color text_color = get_color("default_color", "RichTextLabel");
  176. const Color type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
  177. class_desc->push_color(type_color);
  178. if (can_ref) {
  179. if (p_enum.empty()) {
  180. class_desc->push_meta("#" + t); // class
  181. } else {
  182. class_desc->push_meta("$" + p_enum); // class
  183. }
  184. }
  185. class_desc->add_text(t);
  186. if (can_ref) {
  187. class_desc->pop();
  188. }
  189. class_desc->pop();
  190. }
  191. void EditorHelp::_add_type_icon(const String &p_type, int p_size) {
  192. Ref<Texture> icon;
  193. if (has_icon(p_type, "EditorIcons")) {
  194. icon = get_icon(p_type, "EditorIcons");
  195. } else if (ClassDB::class_exists(p_type) && ClassDB::is_parent_class(p_type, "Object")) {
  196. icon = get_icon("Object", "EditorIcons");
  197. } else {
  198. icon = get_icon("ArrowRight", "EditorIcons");
  199. }
  200. Vector2i size = Vector2i(icon->get_width(), icon->get_height());
  201. if (p_size > 0) {
  202. // Ensures icon scales proportionally on both axis, based on icon height.
  203. float ratio = p_size / float(size.height);
  204. size.width *= ratio;
  205. size.height *= ratio;
  206. }
  207. class_desc->add_image(icon, size.width, size.height, RichTextLabel::INLINE_ALIGN_CENTER);
  208. }
  209. String EditorHelp::_fix_constant(const String &p_constant) const {
  210. if (p_constant.strip_edges() == "4294967295") {
  211. return "0xFFFFFFFF";
  212. }
  213. if (p_constant.strip_edges() == "2147483647") {
  214. return "0x7FFFFFFF";
  215. }
  216. if (p_constant.strip_edges() == "1048575") {
  217. return "0xFFFFF";
  218. }
  219. return p_constant;
  220. }
  221. void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview) {
  222. method_line[p_method.name] = class_desc->get_line_count() - 2; // Gets overridden if description.
  223. const bool is_vararg = p_method.qualifiers.find("vararg") != -1;
  224. if (p_overview) {
  225. class_desc->push_cell();
  226. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  227. } else {
  228. _add_bulletpoint();
  229. }
  230. _add_type(p_method.return_type, p_method.return_enum);
  231. if (p_overview) {
  232. class_desc->pop(); //align
  233. class_desc->pop(); //cell
  234. class_desc->push_cell();
  235. } else {
  236. class_desc->add_text(" ");
  237. }
  238. if (p_overview && p_method.description != "") {
  239. class_desc->push_meta("@method " + p_method.name);
  240. }
  241. class_desc->push_color(headline_color);
  242. _add_text(p_method.name);
  243. class_desc->pop();
  244. if (p_overview && p_method.description != "") {
  245. class_desc->pop(); //meta
  246. }
  247. class_desc->push_color(symbol_color);
  248. class_desc->add_text("(");
  249. class_desc->pop();
  250. for (int j = 0; j < p_method.arguments.size(); j++) {
  251. class_desc->push_color(text_color);
  252. if (j > 0) {
  253. class_desc->add_text(", ");
  254. }
  255. _add_text(p_method.arguments[j].name);
  256. class_desc->add_text(": ");
  257. _add_type(p_method.arguments[j].type, p_method.arguments[j].enumeration);
  258. if (p_method.arguments[j].default_value != "") {
  259. class_desc->push_color(symbol_color);
  260. class_desc->add_text(" = ");
  261. class_desc->pop();
  262. class_desc->push_color(value_color);
  263. _add_text(_fix_constant(p_method.arguments[j].default_value));
  264. class_desc->pop();
  265. }
  266. class_desc->pop();
  267. }
  268. if (is_vararg) {
  269. class_desc->push_color(text_color);
  270. if (p_method.arguments.size()) {
  271. class_desc->add_text(", ");
  272. }
  273. class_desc->push_color(symbol_color);
  274. class_desc->add_text("...");
  275. class_desc->pop();
  276. class_desc->pop();
  277. }
  278. class_desc->push_color(symbol_color);
  279. class_desc->add_text(")");
  280. class_desc->pop();
  281. if (p_method.qualifiers != "") {
  282. class_desc->push_color(qualifier_color);
  283. class_desc->add_text(" ");
  284. _add_text(p_method.qualifiers);
  285. class_desc->pop();
  286. }
  287. if (p_overview) {
  288. class_desc->pop(); //cell
  289. }
  290. }
  291. void EditorHelp::_add_bulletpoint() {
  292. static const CharType prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
  293. class_desc->add_text(String(prefix));
  294. }
  295. Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
  296. if (!doc->class_list.has(p_class)) {
  297. return ERR_DOES_NOT_EXIST;
  298. }
  299. select_locked = true;
  300. class_desc->show();
  301. description_line = 0;
  302. if (p_class == edited_class) {
  303. return OK; // Already there.
  304. }
  305. edited_class = p_class;
  306. _update_doc();
  307. return OK;
  308. }
  309. void EditorHelp::_update_doc() {
  310. if (!doc->class_list.has(edited_class)) {
  311. return;
  312. }
  313. scroll_locked = true;
  314. class_desc->clear();
  315. method_line.clear();
  316. section_line.clear();
  317. _init_colors();
  318. DocData::ClassDoc cd = doc->class_list[edited_class]; // Make a copy, so we can sort without worrying.
  319. Ref<Font> doc_font = get_font("doc", "EditorFonts");
  320. Ref<Font> doc_bold_font = get_font("doc_bold", "EditorFonts");
  321. Ref<Font> doc_title_font = get_font("doc_title", "EditorFonts");
  322. Ref<Font> doc_code_font = get_font("doc_source", "EditorFonts");
  323. String link_color_text = title_color.to_html(false);
  324. // Class name
  325. section_line.push_back(Pair<String, int>(TTR("Top"), 0));
  326. class_desc->push_font(doc_title_font);
  327. class_desc->push_color(title_color);
  328. class_desc->add_text(TTR("Class:") + " ");
  329. _add_type_icon(edited_class, doc_title_font->get_height());
  330. class_desc->add_text(" ");
  331. class_desc->push_color(headline_color);
  332. _add_text(edited_class);
  333. class_desc->pop();
  334. class_desc->pop();
  335. class_desc->pop();
  336. class_desc->add_newline();
  337. const String non_breaking_space = String::chr(160);
  338. // Inheritance tree
  339. // Ascendents
  340. if (cd.inherits != "") {
  341. class_desc->push_color(title_color);
  342. class_desc->push_font(doc_font);
  343. class_desc->add_text(TTR("Inherits:") + " ");
  344. String inherits = cd.inherits;
  345. while (inherits != "") {
  346. _add_type_icon(inherits);
  347. class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type().
  348. _add_type(inherits);
  349. inherits = doc->class_list[inherits].inherits;
  350. if (inherits != "") {
  351. class_desc->add_text(" < ");
  352. }
  353. }
  354. class_desc->pop();
  355. class_desc->pop();
  356. class_desc->add_newline();
  357. }
  358. // Descendents
  359. if (ClassDB::class_exists(cd.name)) {
  360. bool found = false;
  361. bool prev = false;
  362. class_desc->push_font(doc_font);
  363. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  364. if (E->get().inherits == cd.name) {
  365. if (!found) {
  366. class_desc->push_color(title_color);
  367. class_desc->add_text(TTR("Inherited by:") + " ");
  368. found = true;
  369. }
  370. if (prev) {
  371. class_desc->add_text(" , ");
  372. }
  373. _add_type_icon(E->get().name);
  374. class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type().
  375. _add_type(E->get().name);
  376. prev = true;
  377. }
  378. }
  379. class_desc->pop();
  380. if (found) {
  381. class_desc->pop();
  382. class_desc->add_newline();
  383. }
  384. }
  385. class_desc->add_newline();
  386. class_desc->add_newline();
  387. // Brief description
  388. if (cd.brief_description != "") {
  389. class_desc->push_color(text_color);
  390. class_desc->push_font(doc_bold_font);
  391. class_desc->push_indent(1);
  392. _add_text(DTR(cd.brief_description));
  393. class_desc->pop();
  394. class_desc->pop();
  395. class_desc->pop();
  396. class_desc->add_newline();
  397. class_desc->add_newline();
  398. class_desc->add_newline();
  399. }
  400. // Class description
  401. if (cd.description != "") {
  402. section_line.push_back(Pair<String, int>(TTR("Description"), class_desc->get_line_count() - 2));
  403. description_line = class_desc->get_line_count() - 2;
  404. class_desc->push_color(title_color);
  405. class_desc->push_font(doc_title_font);
  406. class_desc->add_text(TTR("Description"));
  407. class_desc->pop();
  408. class_desc->pop();
  409. class_desc->add_newline();
  410. class_desc->add_newline();
  411. class_desc->push_color(text_color);
  412. class_desc->push_font(doc_font);
  413. class_desc->push_indent(1);
  414. _add_text(DTR(cd.description));
  415. class_desc->pop();
  416. class_desc->pop();
  417. class_desc->pop();
  418. class_desc->add_newline();
  419. class_desc->add_newline();
  420. class_desc->add_newline();
  421. }
  422. // Online tutorials
  423. if (cd.tutorials.size()) {
  424. class_desc->push_color(title_color);
  425. class_desc->push_font(doc_title_font);
  426. class_desc->add_text(TTR("Online Tutorials"));
  427. class_desc->pop();
  428. class_desc->pop();
  429. class_desc->push_indent(1);
  430. class_desc->push_font(doc_code_font);
  431. class_desc->add_newline();
  432. for (int i = 0; i < cd.tutorials.size(); i++) {
  433. const String link = DTR(cd.tutorials[i].link);
  434. String linktxt = (cd.tutorials[i].title.empty()) ? link : DTR(cd.tutorials[i].title);
  435. const int seppos = linktxt.find("//");
  436. if (seppos != -1) {
  437. linktxt = link.right(seppos + 2);
  438. }
  439. class_desc->push_color(symbol_color);
  440. class_desc->append_bbcode("[url=" + link + "]" + linktxt + "[/url]");
  441. class_desc->pop();
  442. class_desc->add_newline();
  443. }
  444. class_desc->pop();
  445. class_desc->pop();
  446. class_desc->add_newline();
  447. class_desc->add_newline();
  448. }
  449. // Properties overview
  450. Set<String> skip_methods;
  451. bool property_descr = false;
  452. if (cd.properties.size()) {
  453. section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_line_count() - 2));
  454. class_desc->push_color(title_color);
  455. class_desc->push_font(doc_title_font);
  456. class_desc->add_text(TTR("Properties"));
  457. class_desc->pop();
  458. class_desc->pop();
  459. class_desc->add_newline();
  460. class_desc->push_font(doc_code_font);
  461. class_desc->push_indent(1);
  462. class_desc->push_table(3);
  463. class_desc->set_table_column_expand(1, true);
  464. for (int i = 0; i < cd.properties.size(); i++) {
  465. property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; // Gets overridden if description.
  466. // Property type.
  467. class_desc->push_cell();
  468. class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
  469. class_desc->push_font(doc_code_font);
  470. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  471. class_desc->pop();
  472. class_desc->pop();
  473. class_desc->pop(); // Cell
  474. bool describe = false;
  475. if (cd.properties[i].setter != "") {
  476. skip_methods.insert(cd.properties[i].setter);
  477. describe = true;
  478. }
  479. if (cd.properties[i].getter != "") {
  480. skip_methods.insert(cd.properties[i].getter);
  481. describe = true;
  482. }
  483. if (cd.properties[i].description != "") {
  484. describe = true;
  485. }
  486. if (cd.properties[i].overridden) {
  487. describe = false;
  488. }
  489. // Property name.
  490. class_desc->push_cell();
  491. class_desc->push_font(doc_code_font);
  492. class_desc->push_color(headline_color);
  493. if (describe) {
  494. class_desc->push_meta("@member " + cd.properties[i].name);
  495. }
  496. _add_text(cd.properties[i].name);
  497. if (describe) {
  498. class_desc->pop();
  499. property_descr = true;
  500. }
  501. class_desc->pop();
  502. class_desc->pop();
  503. class_desc->pop(); // Cell
  504. // Property value.
  505. class_desc->push_cell();
  506. class_desc->push_font(doc_code_font);
  507. if (cd.properties[i].default_value != "") {
  508. class_desc->push_color(symbol_color);
  509. if (cd.properties[i].overridden) {
  510. class_desc->add_text(" [");
  511. class_desc->push_meta("@member " + cd.properties[i].overrides + "." + cd.properties[i].name);
  512. _add_text(vformat(TTR("overrides %s:"), cd.properties[i].overrides));
  513. class_desc->pop();
  514. class_desc->add_text(" ");
  515. } else {
  516. class_desc->add_text(" [" + TTR("default:") + " ");
  517. }
  518. class_desc->pop();
  519. class_desc->push_color(value_color);
  520. _add_text(_fix_constant(cd.properties[i].default_value));
  521. class_desc->pop();
  522. class_desc->push_color(symbol_color);
  523. class_desc->add_text("]");
  524. class_desc->pop();
  525. }
  526. class_desc->pop();
  527. class_desc->pop(); // Cell
  528. }
  529. class_desc->pop(); // Table
  530. class_desc->pop();
  531. class_desc->pop(); // Font
  532. class_desc->add_newline();
  533. class_desc->add_newline();
  534. }
  535. // Methods overview
  536. bool method_descr = false;
  537. bool sort_methods = EditorSettings::get_singleton()->get("text_editor/help/sort_functions_alphabetically");
  538. Vector<DocData::MethodDoc> methods;
  539. for (int i = 0; i < cd.methods.size(); i++) {
  540. if (skip_methods.has(cd.methods[i].name)) {
  541. if (cd.methods[i].arguments.size() == 0 /* getter */ || (cd.methods[i].arguments.size() == 1 && cd.methods[i].return_type == "void" /* setter */)) {
  542. continue;
  543. }
  544. }
  545. methods.push_back(cd.methods[i]);
  546. }
  547. if (methods.size()) {
  548. if (sort_methods) {
  549. methods.sort();
  550. }
  551. section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_line_count() - 2));
  552. class_desc->push_color(title_color);
  553. class_desc->push_font(doc_title_font);
  554. class_desc->add_text(TTR("Methods"));
  555. class_desc->pop();
  556. class_desc->pop();
  557. class_desc->add_newline();
  558. class_desc->push_font(doc_code_font);
  559. class_desc->push_indent(1);
  560. class_desc->push_table(2);
  561. class_desc->set_table_column_expand(1, true);
  562. bool any_previous = false;
  563. for (int pass = 0; pass < 2; pass++) {
  564. Vector<DocData::MethodDoc> m;
  565. for (int i = 0; i < methods.size(); i++) {
  566. const String &q = methods[i].qualifiers;
  567. if ((pass == 0 && q.find("virtual") != -1) || (pass == 1 && q.find("virtual") == -1)) {
  568. m.push_back(methods[i]);
  569. }
  570. }
  571. if (any_previous && !m.empty()) {
  572. class_desc->push_cell();
  573. class_desc->pop(); // Cell
  574. class_desc->push_cell();
  575. class_desc->pop(); // Cell
  576. }
  577. String group_prefix;
  578. for (int i = 0; i < m.size(); i++) {
  579. const String new_prefix = m[i].name.substr(0, 3);
  580. bool is_new_group = false;
  581. if (i < m.size() - 1 && new_prefix == m[i + 1].name.substr(0, 3) && new_prefix != group_prefix) {
  582. is_new_group = i > 0;
  583. group_prefix = new_prefix;
  584. } else if (group_prefix != "" && new_prefix != group_prefix) {
  585. is_new_group = true;
  586. group_prefix = "";
  587. }
  588. if (is_new_group && pass == 1) {
  589. class_desc->push_cell();
  590. class_desc->pop(); //cell
  591. class_desc->push_cell();
  592. class_desc->pop(); //cell
  593. }
  594. if (m[i].description != "") {
  595. method_descr = true;
  596. }
  597. _add_method(m[i], true);
  598. }
  599. any_previous = !m.empty();
  600. }
  601. class_desc->pop(); //table
  602. class_desc->pop();
  603. class_desc->pop(); // font
  604. class_desc->add_newline();
  605. class_desc->add_newline();
  606. }
  607. // Theme properties
  608. if (cd.theme_properties.size()) {
  609. section_line.push_back(Pair<String, int>(TTR("Theme Properties"), class_desc->get_line_count() - 2));
  610. class_desc->push_color(title_color);
  611. class_desc->push_font(doc_title_font);
  612. class_desc->add_text(TTR("Theme Properties"));
  613. class_desc->pop();
  614. class_desc->pop();
  615. class_desc->add_newline();
  616. class_desc->add_newline();
  617. class_desc->push_indent(1);
  618. String theme_data_type;
  619. Map<String, String> data_type_names;
  620. data_type_names["color"] = TTR("Colors");
  621. data_type_names["constant"] = TTR("Constants");
  622. data_type_names["font"] = TTR("Fonts");
  623. data_type_names["icon"] = TTR("Icons");
  624. data_type_names["style"] = TTR("Styles");
  625. for (int i = 0; i < cd.theme_properties.size(); i++) {
  626. theme_property_line[cd.theme_properties[i].name] = class_desc->get_line_count() - 2; // Gets overridden if description.
  627. if (theme_data_type != cd.theme_properties[i].data_type) {
  628. theme_data_type = cd.theme_properties[i].data_type;
  629. class_desc->push_color(title_color);
  630. class_desc->push_font(doc_bold_font);
  631. if (data_type_names.has(theme_data_type)) {
  632. class_desc->add_text(data_type_names[theme_data_type]);
  633. } else {
  634. class_desc->add_text("");
  635. }
  636. class_desc->pop();
  637. class_desc->pop();
  638. class_desc->add_newline();
  639. class_desc->add_newline();
  640. }
  641. // Theme item header.
  642. class_desc->push_font(doc_code_font);
  643. _add_bulletpoint();
  644. // Theme item object type.
  645. _add_type(cd.theme_properties[i].type);
  646. // Theme item name.
  647. class_desc->push_color(headline_color);
  648. class_desc->add_text(" ");
  649. _add_text(cd.theme_properties[i].name);
  650. class_desc->pop();
  651. // Theme item default value.
  652. if (cd.theme_properties[i].default_value != "") {
  653. class_desc->push_color(symbol_color);
  654. class_desc->add_text(" [" + TTR("default:") + " ");
  655. class_desc->pop();
  656. class_desc->push_color(value_color);
  657. _add_text(_fix_constant(cd.theme_properties[i].default_value));
  658. class_desc->pop();
  659. class_desc->push_color(symbol_color);
  660. class_desc->add_text("]");
  661. class_desc->pop();
  662. }
  663. class_desc->pop(); // monofont
  664. // Theme item description.
  665. if (cd.theme_properties[i].description != "") {
  666. class_desc->push_font(doc_font);
  667. class_desc->push_color(comment_color);
  668. class_desc->push_indent(1);
  669. _add_text(DTR(cd.theme_properties[i].description));
  670. class_desc->pop(); // indent
  671. class_desc->pop(); // color
  672. class_desc->pop(); // font
  673. }
  674. class_desc->add_newline();
  675. class_desc->add_newline();
  676. }
  677. class_desc->pop();
  678. class_desc->add_newline();
  679. }
  680. // Signals
  681. if (cd.signals.size()) {
  682. if (sort_methods) {
  683. cd.signals.sort();
  684. }
  685. section_line.push_back(Pair<String, int>(TTR("Signals"), class_desc->get_line_count() - 2));
  686. class_desc->push_color(title_color);
  687. class_desc->push_font(doc_title_font);
  688. class_desc->add_text(TTR("Signals"));
  689. class_desc->pop();
  690. class_desc->pop();
  691. class_desc->add_newline();
  692. class_desc->add_newline();
  693. class_desc->push_indent(1);
  694. for (int i = 0; i < cd.signals.size(); i++) {
  695. signal_line[cd.signals[i].name] = class_desc->get_line_count() - 2; // Gets overridden if description.
  696. class_desc->push_font(doc_code_font); // monofont
  697. class_desc->push_color(headline_color);
  698. _add_bulletpoint();
  699. _add_text(cd.signals[i].name);
  700. class_desc->pop();
  701. class_desc->push_color(symbol_color);
  702. class_desc->add_text("(");
  703. class_desc->pop();
  704. for (int j = 0; j < cd.signals[i].arguments.size(); j++) {
  705. class_desc->push_color(text_color);
  706. if (j > 0) {
  707. class_desc->add_text(", ");
  708. }
  709. _add_text(cd.signals[i].arguments[j].name);
  710. class_desc->add_text(": ");
  711. _add_type(cd.signals[i].arguments[j].type);
  712. if (cd.signals[i].arguments[j].default_value != "") {
  713. class_desc->push_color(symbol_color);
  714. class_desc->add_text(" = ");
  715. class_desc->pop();
  716. _add_text(cd.signals[i].arguments[j].default_value);
  717. }
  718. class_desc->pop();
  719. }
  720. class_desc->push_color(symbol_color);
  721. class_desc->add_text(")");
  722. class_desc->pop();
  723. class_desc->pop(); // End monofont
  724. if (cd.signals[i].description != "") {
  725. class_desc->push_font(doc_font);
  726. class_desc->push_color(comment_color);
  727. class_desc->push_indent(1);
  728. _add_text(DTR(cd.signals[i].description));
  729. class_desc->pop(); // indent
  730. class_desc->pop();
  731. class_desc->pop(); // font
  732. }
  733. class_desc->add_newline();
  734. class_desc->add_newline();
  735. }
  736. class_desc->pop();
  737. class_desc->add_newline();
  738. }
  739. // Constants and enums
  740. if (cd.constants.size()) {
  741. Map<String, Vector<DocData::ConstantDoc>> enums;
  742. Vector<DocData::ConstantDoc> constants;
  743. for (int i = 0; i < cd.constants.size(); i++) {
  744. if (cd.constants[i].enumeration != String()) {
  745. if (!enums.has(cd.constants[i].enumeration)) {
  746. enums[cd.constants[i].enumeration] = Vector<DocData::ConstantDoc>();
  747. }
  748. enums[cd.constants[i].enumeration].push_back(cd.constants[i]);
  749. } else {
  750. constants.push_back(cd.constants[i]);
  751. }
  752. }
  753. // Enums
  754. if (enums.size()) {
  755. section_line.push_back(Pair<String, int>(TTR("Enumerations"), class_desc->get_line_count() - 2));
  756. class_desc->push_color(title_color);
  757. class_desc->push_font(doc_title_font);
  758. class_desc->add_text(TTR("Enumerations"));
  759. class_desc->pop();
  760. class_desc->pop();
  761. class_desc->push_indent(1);
  762. class_desc->add_newline();
  763. for (Map<String, Vector<DocData::ConstantDoc>>::Element *E = enums.front(); E; E = E->next()) {
  764. enum_line[E->key()] = class_desc->get_line_count() - 2;
  765. class_desc->push_font(doc_code_font);
  766. class_desc->push_color(title_color);
  767. class_desc->add_text("enum ");
  768. class_desc->pop();
  769. String e = E->key();
  770. if ((e.get_slice_count(".") > 1) && (e.get_slice(".", 0) == edited_class)) {
  771. e = e.get_slice(".", 1);
  772. }
  773. class_desc->push_color(headline_color);
  774. class_desc->add_text(e);
  775. class_desc->pop();
  776. class_desc->pop();
  777. class_desc->push_color(symbol_color);
  778. class_desc->add_text(":");
  779. class_desc->pop();
  780. class_desc->add_newline();
  781. class_desc->add_newline();
  782. class_desc->push_indent(1);
  783. Vector<DocData::ConstantDoc> enum_list = E->get();
  784. Map<String, int> enumValuesContainer;
  785. int enumStartingLine = enum_line[E->key()];
  786. for (int i = 0; i < enum_list.size(); i++) {
  787. if (cd.name == "@GlobalScope") {
  788. enumValuesContainer[enum_list[i].name] = enumStartingLine;
  789. }
  790. // Add the enum constant line to the constant_line map so we can locate it as a constant.
  791. constant_line[enum_list[i].name] = class_desc->get_line_count() - 2;
  792. class_desc->push_font(doc_code_font);
  793. class_desc->push_color(headline_color);
  794. _add_bulletpoint();
  795. _add_text(enum_list[i].name);
  796. class_desc->pop();
  797. class_desc->push_color(symbol_color);
  798. class_desc->add_text(" = ");
  799. class_desc->pop();
  800. class_desc->push_color(value_color);
  801. _add_text(_fix_constant(enum_list[i].value));
  802. class_desc->pop();
  803. class_desc->pop();
  804. class_desc->add_newline();
  805. if (enum_list[i].description.strip_edges() != "") {
  806. class_desc->push_font(doc_font);
  807. class_desc->push_color(comment_color);
  808. _add_text(DTR(enum_list[i].description));
  809. class_desc->pop();
  810. class_desc->pop();
  811. if (DTR(enum_list[i].description).find("\n") > 0) {
  812. class_desc->add_newline();
  813. }
  814. }
  815. class_desc->add_newline();
  816. }
  817. if (cd.name == "@GlobalScope") {
  818. enum_values_line[E->key()] = enumValuesContainer;
  819. }
  820. class_desc->pop();
  821. class_desc->add_newline();
  822. }
  823. class_desc->pop();
  824. class_desc->add_newline();
  825. }
  826. // Constants
  827. if (constants.size()) {
  828. section_line.push_back(Pair<String, int>(TTR("Constants"), class_desc->get_line_count() - 2));
  829. class_desc->push_color(title_color);
  830. class_desc->push_font(doc_title_font);
  831. class_desc->add_text(TTR("Constants"));
  832. class_desc->pop();
  833. class_desc->pop();
  834. class_desc->push_indent(1);
  835. class_desc->add_newline();
  836. for (int i = 0; i < constants.size(); i++) {
  837. constant_line[constants[i].name] = class_desc->get_line_count() - 2;
  838. class_desc->push_font(doc_code_font);
  839. if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) {
  840. String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", "");
  841. Vector<float> color = stripped.split_floats(",");
  842. if (color.size() >= 3) {
  843. class_desc->push_color(Color(color[0], color[1], color[2]));
  844. _add_bulletpoint();
  845. class_desc->pop();
  846. }
  847. } else {
  848. _add_bulletpoint();
  849. }
  850. class_desc->push_color(headline_color);
  851. _add_text(constants[i].name);
  852. class_desc->pop();
  853. class_desc->push_color(symbol_color);
  854. class_desc->add_text(" = ");
  855. class_desc->pop();
  856. class_desc->push_color(value_color);
  857. _add_text(_fix_constant(constants[i].value));
  858. class_desc->pop();
  859. class_desc->pop();
  860. class_desc->add_newline();
  861. if (constants[i].description != "") {
  862. class_desc->push_font(doc_font);
  863. class_desc->push_color(comment_color);
  864. _add_text(DTR(constants[i].description));
  865. class_desc->pop();
  866. class_desc->pop();
  867. if (DTR(constants[i].description).find("\n") > 0) {
  868. class_desc->add_newline();
  869. }
  870. }
  871. class_desc->add_newline();
  872. }
  873. class_desc->pop();
  874. class_desc->add_newline();
  875. }
  876. }
  877. // Property descriptions
  878. if (property_descr) {
  879. section_line.push_back(Pair<String, int>(TTR("Property Descriptions"), class_desc->get_line_count() - 2));
  880. class_desc->push_color(title_color);
  881. class_desc->push_font(doc_title_font);
  882. class_desc->add_text(TTR("Property Descriptions"));
  883. class_desc->pop();
  884. class_desc->pop();
  885. class_desc->add_newline();
  886. class_desc->add_newline();
  887. for (int i = 0; i < cd.properties.size(); i++) {
  888. if (cd.properties[i].overridden) {
  889. continue;
  890. }
  891. property_line[cd.properties[i].name] = class_desc->get_line_count() - 2;
  892. class_desc->push_table(2);
  893. class_desc->set_table_column_expand(1, true);
  894. class_desc->push_cell();
  895. class_desc->push_font(doc_code_font);
  896. _add_bulletpoint();
  897. _add_type(cd.properties[i].type, cd.properties[i].enumeration);
  898. class_desc->add_text(" ");
  899. class_desc->pop(); // font
  900. class_desc->pop(); // cell
  901. class_desc->push_cell();
  902. class_desc->push_font(doc_code_font);
  903. class_desc->push_color(headline_color);
  904. _add_text(cd.properties[i].name);
  905. class_desc->pop(); // color
  906. if (cd.properties[i].default_value != "") {
  907. class_desc->push_color(symbol_color);
  908. class_desc->add_text(" [" + TTR("default:") + " ");
  909. class_desc->pop(); // color
  910. class_desc->push_color(value_color);
  911. _add_text(_fix_constant(cd.properties[i].default_value));
  912. class_desc->pop(); // color
  913. class_desc->push_color(symbol_color);
  914. class_desc->add_text("]");
  915. class_desc->pop(); // color
  916. }
  917. class_desc->pop(); // font
  918. class_desc->pop(); // cell
  919. Map<String, DocData::MethodDoc> method_map;
  920. for (int j = 0; j < methods.size(); j++) {
  921. method_map[methods[j].name] = methods[j];
  922. }
  923. if (cd.properties[i].setter != "") {
  924. class_desc->push_cell();
  925. class_desc->pop(); // cell
  926. class_desc->push_cell();
  927. class_desc->push_font(doc_code_font);
  928. class_desc->push_color(text_color);
  929. if (method_map[cd.properties[i].setter].arguments.size() > 1) {
  930. // Setters with additional arguments are exposed in the method list, so we link them here for quick access.
  931. class_desc->push_meta("@method " + cd.properties[i].setter);
  932. class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
  933. class_desc->pop();
  934. } else {
  935. class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
  936. }
  937. class_desc->pop(); // color
  938. class_desc->push_color(comment_color);
  939. class_desc->add_text(" setter");
  940. class_desc->pop(); // color
  941. class_desc->pop(); // font
  942. class_desc->pop(); // cell
  943. method_line[cd.properties[i].setter] = property_line[cd.properties[i].name];
  944. }
  945. if (cd.properties[i].getter != "") {
  946. class_desc->push_cell();
  947. class_desc->pop(); // cell
  948. class_desc->push_cell();
  949. class_desc->push_font(doc_code_font);
  950. class_desc->push_color(text_color);
  951. if (method_map[cd.properties[i].getter].arguments.size() > 0) {
  952. // Getters with additional arguments are exposed in the method list, so we link them here for quick access.
  953. class_desc->push_meta("@method " + cd.properties[i].getter);
  954. class_desc->add_text(cd.properties[i].getter + "()");
  955. class_desc->pop();
  956. } else {
  957. class_desc->add_text(cd.properties[i].getter + "()");
  958. }
  959. class_desc->pop(); //color
  960. class_desc->push_color(comment_color);
  961. class_desc->add_text(" getter");
  962. class_desc->pop(); //color
  963. class_desc->pop(); //font
  964. class_desc->pop(); //cell
  965. method_line[cd.properties[i].getter] = property_line[cd.properties[i].name];
  966. }
  967. class_desc->pop(); // table
  968. class_desc->add_newline();
  969. class_desc->add_newline();
  970. class_desc->push_color(text_color);
  971. class_desc->push_font(doc_font);
  972. class_desc->push_indent(1);
  973. if (cd.properties[i].description.strip_edges() != String()) {
  974. _add_text(DTR(cd.properties[i].description));
  975. } else {
  976. class_desc->add_image(get_icon("Error", "EditorIcons"));
  977. class_desc->add_text(" ");
  978. class_desc->push_color(comment_color);
  979. 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));
  980. class_desc->pop();
  981. }
  982. class_desc->pop();
  983. class_desc->pop();
  984. class_desc->pop();
  985. class_desc->add_newline();
  986. class_desc->add_newline();
  987. class_desc->add_newline();
  988. }
  989. }
  990. // Method descriptions
  991. if (method_descr) {
  992. section_line.push_back(Pair<String, int>(TTR("Method Descriptions"), class_desc->get_line_count() - 2));
  993. class_desc->push_color(title_color);
  994. class_desc->push_font(doc_title_font);
  995. class_desc->add_text(TTR("Method Descriptions"));
  996. class_desc->pop();
  997. class_desc->pop();
  998. class_desc->add_newline();
  999. class_desc->add_newline();
  1000. for (int pass = 0; pass < 2; pass++) {
  1001. Vector<DocData::MethodDoc> methods_filtered;
  1002. for (int i = 0; i < methods.size(); i++) {
  1003. const String &q = methods[i].qualifiers;
  1004. if ((pass == 0 && q.find("virtual") != -1) || (pass == 1 && q.find("virtual") == -1)) {
  1005. methods_filtered.push_back(methods[i]);
  1006. }
  1007. }
  1008. for (int i = 0; i < methods_filtered.size(); i++) {
  1009. class_desc->push_font(doc_code_font);
  1010. _add_method(methods_filtered[i], false);
  1011. class_desc->pop();
  1012. class_desc->add_newline();
  1013. class_desc->add_newline();
  1014. class_desc->push_color(text_color);
  1015. class_desc->push_font(doc_font);
  1016. class_desc->push_indent(1);
  1017. if (methods_filtered[i].description.strip_edges() != String()) {
  1018. _add_text(DTR(methods_filtered[i].description));
  1019. } else {
  1020. class_desc->add_image(get_icon("Error", "EditorIcons"));
  1021. class_desc->add_text(" ");
  1022. class_desc->push_color(comment_color);
  1023. 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));
  1024. class_desc->pop();
  1025. }
  1026. class_desc->pop();
  1027. class_desc->pop();
  1028. class_desc->pop();
  1029. class_desc->add_newline();
  1030. class_desc->add_newline();
  1031. class_desc->add_newline();
  1032. }
  1033. }
  1034. }
  1035. scroll_locked = false;
  1036. }
  1037. void EditorHelp::_request_help(const String &p_string) {
  1038. Error err = _goto_desc(p_string);
  1039. if (err == OK) {
  1040. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  1041. }
  1042. // 100 palabras
  1043. }
  1044. void EditorHelp::_help_callback(const String &p_topic) {
  1045. String what = p_topic.get_slice(":", 0);
  1046. String clss = p_topic.get_slice(":", 1);
  1047. String name;
  1048. if (p_topic.get_slice_count(":") == 3) {
  1049. name = p_topic.get_slice(":", 2);
  1050. }
  1051. _request_help(clss); // First go to class.
  1052. int line = 0;
  1053. if (what == "class_desc") {
  1054. line = description_line;
  1055. } else if (what == "class_signal") {
  1056. if (signal_line.has(name)) {
  1057. line = signal_line[name];
  1058. }
  1059. } else if (what == "class_method" || what == "class_method_desc") {
  1060. if (method_line.has(name)) {
  1061. line = method_line[name];
  1062. }
  1063. } else if (what == "class_property") {
  1064. if (property_line.has(name)) {
  1065. line = property_line[name];
  1066. }
  1067. } else if (what == "class_enum") {
  1068. if (enum_line.has(name)) {
  1069. line = enum_line[name];
  1070. }
  1071. } else if (what == "class_theme_item") {
  1072. if (theme_property_line.has(name)) {
  1073. line = theme_property_line[name];
  1074. }
  1075. } else if (what == "class_constant") {
  1076. if (constant_line.has(name)) {
  1077. line = constant_line[name];
  1078. }
  1079. } else if (what == "class_global") {
  1080. if (constant_line.has(name)) {
  1081. line = constant_line[name];
  1082. } else {
  1083. Map<String, Map<String, int>>::Element *iter = enum_values_line.front();
  1084. while (true) {
  1085. if (iter->value().has(name)) {
  1086. line = iter->value()[name];
  1087. break;
  1088. } else if (iter == enum_values_line.back()) {
  1089. break;
  1090. } else {
  1091. iter = iter->next();
  1092. }
  1093. }
  1094. }
  1095. }
  1096. class_desc->call_deferred("scroll_to_line", line);
  1097. }
  1098. static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
  1099. DocData *doc = EditorHelp::get_doc_data();
  1100. String base_path;
  1101. Ref<Font> doc_font = p_rt->get_font("doc", "EditorFonts");
  1102. Ref<Font> doc_bold_font = p_rt->get_font("doc_bold", "EditorFonts");
  1103. Ref<Font> doc_code_font = p_rt->get_font("doc_source", "EditorFonts");
  1104. Ref<Font> doc_kbd_font = p_rt->get_font("doc_keyboard", "EditorFonts");
  1105. Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp");
  1106. Color accent_color = p_rt->get_color("accent_color", "Editor");
  1107. Color property_color = p_rt->get_color("property_color", "Editor");
  1108. Color link_color = accent_color.linear_interpolate(font_color_hl, 0.8);
  1109. Color code_color = accent_color.linear_interpolate(font_color_hl, 0.6);
  1110. Color kbd_color = accent_color.linear_interpolate(property_color, 0.6);
  1111. String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges();
  1112. // Remove extra new lines around code blocks.
  1113. bbcode = bbcode.replace("[codeblock]\n", "[codeblock]");
  1114. bbcode = bbcode.replace("\n[/codeblock]", "[/codeblock]");
  1115. List<String> tag_stack;
  1116. bool code_tag = false;
  1117. int pos = 0;
  1118. while (pos < bbcode.length()) {
  1119. int brk_pos = bbcode.find("[", pos);
  1120. if (brk_pos < 0) {
  1121. brk_pos = bbcode.length();
  1122. }
  1123. if (brk_pos > pos) {
  1124. String text = bbcode.substr(pos, brk_pos - pos);
  1125. if (!code_tag) {
  1126. text = text.replace("\n", "\n\n");
  1127. }
  1128. p_rt->add_text(text);
  1129. }
  1130. if (brk_pos == bbcode.length()) {
  1131. break; // Nothing else to add.
  1132. }
  1133. int brk_end = bbcode.find("]", brk_pos + 1);
  1134. if (brk_end == -1) {
  1135. String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos);
  1136. if (!code_tag) {
  1137. text = text.replace("\n", "\n\n");
  1138. }
  1139. p_rt->add_text(text);
  1140. break;
  1141. }
  1142. String tag = bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
  1143. if (tag.begins_with("/")) {
  1144. bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
  1145. if (!tag_ok) {
  1146. p_rt->add_text("[");
  1147. pos = brk_pos + 1;
  1148. continue;
  1149. }
  1150. tag_stack.pop_front();
  1151. pos = brk_end + 1;
  1152. if (tag != "/img") {
  1153. p_rt->pop();
  1154. if (code_tag) {
  1155. p_rt->pop();
  1156. }
  1157. }
  1158. code_tag = false;
  1159. } else if (code_tag) {
  1160. p_rt->add_text("[");
  1161. pos = brk_pos + 1;
  1162. } else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ")) {
  1163. const int tag_end = tag.find(" ");
  1164. const String link_tag = tag.substr(0, tag_end);
  1165. const String link_target = tag.substr(tag_end + 1, tag.length()).lstrip(" ");
  1166. p_rt->push_font(doc_code_font);
  1167. p_rt->push_color(link_color);
  1168. p_rt->push_meta("@" + link_tag + " " + link_target);
  1169. p_rt->add_text(link_target + (tag.begins_with("method ") ? "()" : ""));
  1170. p_rt->pop();
  1171. p_rt->pop();
  1172. p_rt->pop();
  1173. pos = brk_end + 1;
  1174. } else if (doc->class_list.has(tag)) {
  1175. // Class reference tag such as [Node2D] or [SceneTree].
  1176. p_rt->push_font(doc_code_font);
  1177. p_rt->push_color(link_color);
  1178. p_rt->push_meta("#" + tag);
  1179. p_rt->add_text(tag);
  1180. p_rt->pop();
  1181. p_rt->pop();
  1182. p_rt->pop();
  1183. pos = brk_end + 1;
  1184. } else if (tag == "b") {
  1185. // Use bold font.
  1186. p_rt->push_font(doc_bold_font);
  1187. pos = brk_end + 1;
  1188. tag_stack.push_front(tag);
  1189. } else if (tag == "i") {
  1190. // Use italics font.
  1191. p_rt->push_color(font_color_hl);
  1192. pos = brk_end + 1;
  1193. tag_stack.push_front(tag);
  1194. } else if (tag == "code" || tag == "codeblock") {
  1195. // Use monospace font.
  1196. p_rt->push_font(doc_code_font);
  1197. p_rt->push_color(code_color);
  1198. code_tag = true;
  1199. pos = brk_end + 1;
  1200. tag_stack.push_front(tag);
  1201. } else if (tag == "kbd") {
  1202. // Use keyboard font with custom color.
  1203. p_rt->push_font(doc_kbd_font);
  1204. p_rt->push_color(kbd_color);
  1205. code_tag = true; // Though not strictly a code tag, logic is similar.
  1206. pos = brk_end + 1;
  1207. tag_stack.push_front(tag);
  1208. } else if (tag == "center") {
  1209. // Align to center.
  1210. p_rt->push_align(RichTextLabel::ALIGN_CENTER);
  1211. pos = brk_end + 1;
  1212. tag_stack.push_front(tag);
  1213. } else if (tag == "br") {
  1214. // Force a line break.
  1215. p_rt->add_newline();
  1216. pos = brk_end + 1;
  1217. } else if (tag == "u") {
  1218. // Use underline.
  1219. p_rt->push_underline();
  1220. pos = brk_end + 1;
  1221. tag_stack.push_front(tag);
  1222. } else if (tag == "s") {
  1223. // Use strikethrough.
  1224. p_rt->push_strikethrough();
  1225. pos = brk_end + 1;
  1226. tag_stack.push_front(tag);
  1227. } else if (tag == "url") {
  1228. int end = bbcode.find("[", brk_end);
  1229. if (end == -1) {
  1230. end = bbcode.length();
  1231. }
  1232. String url = bbcode.substr(brk_end + 1, end - brk_end - 1);
  1233. p_rt->push_meta(url);
  1234. pos = brk_end + 1;
  1235. tag_stack.push_front(tag);
  1236. } else if (tag.begins_with("url=")) {
  1237. String url = tag.substr(4, tag.length());
  1238. p_rt->push_meta(url);
  1239. pos = brk_end + 1;
  1240. tag_stack.push_front("url");
  1241. } else if (tag == "img") {
  1242. int end = bbcode.find("[", brk_end);
  1243. if (end == -1) {
  1244. end = bbcode.length();
  1245. }
  1246. String image = bbcode.substr(brk_end + 1, end - brk_end - 1);
  1247. Ref<Texture> texture = ResourceLoader::load(base_path.plus_file(image), "Texture");
  1248. if (texture.is_valid()) {
  1249. p_rt->add_image(texture);
  1250. }
  1251. pos = end;
  1252. tag_stack.push_front(tag);
  1253. } else if (tag.begins_with("color=")) {
  1254. String col = tag.substr(6, tag.length());
  1255. Color color;
  1256. if (col.begins_with("#")) {
  1257. color = Color::html(col);
  1258. } else if (col == "aqua") {
  1259. color = Color(0, 1, 1);
  1260. } else if (col == "black") {
  1261. color = Color(0, 0, 0);
  1262. } else if (col == "blue") {
  1263. color = Color(0, 0, 1);
  1264. } else if (col == "fuchsia") {
  1265. color = Color(1, 0, 1);
  1266. } else if (col == "gray" || col == "grey") {
  1267. color = Color(0.5, 0.5, 0.5);
  1268. } else if (col == "green") {
  1269. color = Color(0, 0.5, 0);
  1270. } else if (col == "lime") {
  1271. color = Color(0, 1, 0);
  1272. } else if (col == "maroon") {
  1273. color = Color(0.5, 0, 0);
  1274. } else if (col == "navy") {
  1275. color = Color(0, 0, 0.5);
  1276. } else if (col == "olive") {
  1277. color = Color(0.5, 0.5, 0);
  1278. } else if (col == "purple") {
  1279. color = Color(0.5, 0, 0.5);
  1280. } else if (col == "red") {
  1281. color = Color(1, 0, 0);
  1282. } else if (col == "silver") {
  1283. color = Color(0.75, 0.75, 0.75);
  1284. } else if (col == "teal") {
  1285. color = Color(0, 0.5, 0.5);
  1286. } else if (col == "white") {
  1287. color = Color(1, 1, 1);
  1288. } else if (col == "yellow") {
  1289. color = Color(1, 1, 0);
  1290. } else {
  1291. color = Color(0, 0, 0); // base_color;
  1292. }
  1293. p_rt->push_color(color);
  1294. pos = brk_end + 1;
  1295. tag_stack.push_front("color");
  1296. } else if (tag.begins_with("font=")) {
  1297. String fnt = tag.substr(5, tag.length());
  1298. Ref<Font> font = ResourceLoader::load(base_path.plus_file(fnt), "Font");
  1299. if (font.is_valid()) {
  1300. p_rt->push_font(font);
  1301. } else {
  1302. p_rt->push_font(doc_font);
  1303. }
  1304. pos = brk_end + 1;
  1305. tag_stack.push_front("font");
  1306. } else {
  1307. p_rt->add_text("["); // ignore
  1308. pos = brk_pos + 1;
  1309. }
  1310. }
  1311. }
  1312. void EditorHelp::_add_text(const String &p_bbcode) {
  1313. _add_text_to_rt(p_bbcode, class_desc);
  1314. }
  1315. void EditorHelp::generate_doc() {
  1316. doc = memnew(DocData);
  1317. doc->generate(true);
  1318. DocData compdoc;
  1319. compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
  1320. doc->merge_from(compdoc); // Ensure all is up to date.
  1321. }
  1322. void EditorHelp::_notification(int p_what) {
  1323. switch (p_what) {
  1324. case NOTIFICATION_READY:
  1325. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1326. _update_doc();
  1327. } break;
  1328. case NOTIFICATION_THEME_CHANGED: {
  1329. if (is_inside_tree()) {
  1330. _class_desc_resized();
  1331. }
  1332. } break;
  1333. default:
  1334. break;
  1335. }
  1336. }
  1337. void EditorHelp::go_to_help(const String &p_help) {
  1338. _help_callback(p_help);
  1339. }
  1340. void EditorHelp::go_to_class(const String &p_class, int p_scroll) {
  1341. _goto_desc(p_class, p_scroll);
  1342. }
  1343. Vector<Pair<String, int>> EditorHelp::get_sections() {
  1344. Vector<Pair<String, int>> sections;
  1345. for (int i = 0; i < section_line.size(); i++) {
  1346. sections.push_back(Pair<String, int>(section_line[i].first, i));
  1347. }
  1348. return sections;
  1349. }
  1350. void EditorHelp::scroll_to_section(int p_section_index) {
  1351. int line = section_line[p_section_index].second;
  1352. class_desc->scroll_to_line(line);
  1353. }
  1354. void EditorHelp::popup_search() {
  1355. find_bar->popup_search();
  1356. }
  1357. String EditorHelp::get_class() {
  1358. return edited_class;
  1359. }
  1360. void EditorHelp::search_again(bool p_search_previous) {
  1361. _search(p_search_previous);
  1362. }
  1363. int EditorHelp::get_scroll() const {
  1364. return class_desc->get_v_scroll()->get_value();
  1365. }
  1366. void EditorHelp::set_scroll(int p_scroll) {
  1367. class_desc->get_v_scroll()->set_value(p_scroll);
  1368. }
  1369. void EditorHelp::_bind_methods() {
  1370. ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
  1371. ClassDB::bind_method("_class_desc_select", &EditorHelp::_class_desc_select);
  1372. ClassDB::bind_method("_class_desc_input", &EditorHelp::_class_desc_input);
  1373. ClassDB::bind_method("_class_desc_resized", &EditorHelp::_class_desc_resized);
  1374. ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
  1375. ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input);
  1376. ClassDB::bind_method("_search", &EditorHelp::_search);
  1377. ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);
  1378. ADD_SIGNAL(MethodInfo("go_to_help"));
  1379. }
  1380. EditorHelp::EditorHelp() {
  1381. set_custom_minimum_size(Size2(150 * EDSCALE, 0));
  1382. EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true);
  1383. class_desc = memnew(RichTextLabel);
  1384. add_child(class_desc);
  1385. class_desc->set_v_size_flags(SIZE_EXPAND_FILL);
  1386. class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1387. class_desc->connect("meta_clicked", this, "_class_desc_select");
  1388. class_desc->connect("gui_input", this, "_class_desc_input");
  1389. class_desc->connect("resized", this, "_class_desc_resized");
  1390. _class_desc_resized();
  1391. // Added second so it opens at the bottom so it won't offset the entire widget.
  1392. find_bar = memnew(FindBar);
  1393. add_child(find_bar);
  1394. find_bar->hide();
  1395. find_bar->set_rich_text_label(class_desc);
  1396. class_desc->set_selection_enabled(true);
  1397. scroll_locked = false;
  1398. select_locked = false;
  1399. class_desc->hide();
  1400. }
  1401. EditorHelp::~EditorHelp() {
  1402. }
  1403. void EditorHelpBit::_go_to_help(String p_what) {
  1404. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  1405. ScriptEditor::get_singleton()->goto_help(p_what);
  1406. emit_signal("request_hide");
  1407. }
  1408. void EditorHelpBit::_meta_clicked(String p_select) {
  1409. if (p_select.begins_with("$")) { // enum
  1410. String select = p_select.substr(1, p_select.length());
  1411. String class_name;
  1412. if (select.find(".") != -1) {
  1413. class_name = select.get_slice(".", 0);
  1414. } else {
  1415. class_name = "@Global";
  1416. }
  1417. _go_to_help("class_enum:" + class_name + ":" + select);
  1418. return;
  1419. } else if (p_select.begins_with("#")) {
  1420. _go_to_help("class_name:" + p_select.substr(1, p_select.length()));
  1421. return;
  1422. } else if (p_select.begins_with("@")) {
  1423. String m = p_select.substr(1, p_select.length());
  1424. if (m.find(".") != -1) {
  1425. _go_to_help("class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0)); // Must go somewhere else.
  1426. }
  1427. }
  1428. }
  1429. void EditorHelpBit::_bind_methods() {
  1430. ClassDB::bind_method("_meta_clicked", &EditorHelpBit::_meta_clicked);
  1431. ClassDB::bind_method(D_METHOD("set_text", "text"), &EditorHelpBit::set_text);
  1432. ADD_SIGNAL(MethodInfo("request_hide"));
  1433. }
  1434. void EditorHelpBit::_notification(int p_what) {
  1435. switch (p_what) {
  1436. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1437. rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1438. } break;
  1439. default:
  1440. break;
  1441. }
  1442. }
  1443. void EditorHelpBit::set_text(const String &p_text) {
  1444. rich_text->clear();
  1445. _add_text_to_rt(p_text, rich_text);
  1446. }
  1447. EditorHelpBit::EditorHelpBit() {
  1448. rich_text = memnew(RichTextLabel);
  1449. add_child(rich_text);
  1450. rich_text->connect("meta_clicked", this, "_meta_clicked");
  1451. rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4));
  1452. rich_text->set_override_selected_font_color(false);
  1453. set_custom_minimum_size(Size2(0, 70 * EDSCALE));
  1454. }
  1455. FindBar::FindBar() {
  1456. results_count = 0;
  1457. search_text = memnew(LineEdit);
  1458. add_child(search_text);
  1459. search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1460. search_text->set_h_size_flags(SIZE_EXPAND_FILL);
  1461. search_text->connect("text_changed", this, "_search_text_changed");
  1462. search_text->connect("text_entered", this, "_search_text_entered");
  1463. matches_label = memnew(Label);
  1464. add_child(matches_label);
  1465. matches_label->hide();
  1466. find_prev = memnew(ToolButton);
  1467. add_child(find_prev);
  1468. find_prev->set_focus_mode(FOCUS_NONE);
  1469. find_prev->connect("pressed", this, "_search_prev");
  1470. find_next = memnew(ToolButton);
  1471. add_child(find_next);
  1472. find_next->set_focus_mode(FOCUS_NONE);
  1473. find_next->connect("pressed", this, "_search_next");
  1474. Control *space = memnew(Control);
  1475. add_child(space);
  1476. space->set_custom_minimum_size(Size2(4, 0) * EDSCALE);
  1477. hide_button = memnew(TextureButton);
  1478. add_child(hide_button);
  1479. hide_button->set_focus_mode(FOCUS_NONE);
  1480. hide_button->set_expand(true);
  1481. hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
  1482. hide_button->connect("pressed", this, "_hide_pressed");
  1483. }
  1484. void FindBar::popup_search() {
  1485. show();
  1486. bool grabbed_focus = false;
  1487. if (!search_text->has_focus()) {
  1488. search_text->grab_focus();
  1489. grabbed_focus = true;
  1490. }
  1491. if (!search_text->get_text().empty()) {
  1492. search_text->select_all();
  1493. search_text->set_cursor_position(search_text->get_text().length());
  1494. if (grabbed_focus) {
  1495. _search();
  1496. }
  1497. }
  1498. }
  1499. void FindBar::_notification(int p_what) {
  1500. switch (p_what) {
  1501. case NOTIFICATION_ENTER_TREE:
  1502. case NOTIFICATION_THEME_CHANGED: {
  1503. find_prev->set_icon(get_icon("MoveUp", "EditorIcons"));
  1504. find_next->set_icon(get_icon("MoveDown", "EditorIcons"));
  1505. hide_button->set_normal_texture(get_icon("Close", "EditorIcons"));
  1506. hide_button->set_hover_texture(get_icon("Close", "EditorIcons"));
  1507. hide_button->set_pressed_texture(get_icon("Close", "EditorIcons"));
  1508. hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
  1509. matches_label->add_color_override("font_color", results_count > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor"));
  1510. } break;
  1511. case NOTIFICATION_VISIBILITY_CHANGED: {
  1512. set_process_unhandled_input(is_visible_in_tree());
  1513. } break;
  1514. }
  1515. }
  1516. void FindBar::_bind_methods() {
  1517. ClassDB::bind_method("_unhandled_input", &FindBar::_unhandled_input);
  1518. ClassDB::bind_method("_search_text_changed", &FindBar::_search_text_changed);
  1519. ClassDB::bind_method("_search_text_entered", &FindBar::_search_text_entered);
  1520. ClassDB::bind_method("_search_next", &FindBar::search_next);
  1521. ClassDB::bind_method("_search_prev", &FindBar::search_prev);
  1522. ClassDB::bind_method("_hide_pressed", &FindBar::_hide_bar);
  1523. ADD_SIGNAL(MethodInfo("search"));
  1524. }
  1525. void FindBar::set_rich_text_label(RichTextLabel *p_rich_text_label) {
  1526. rich_text_label = p_rich_text_label;
  1527. }
  1528. bool FindBar::search_next() {
  1529. return _search();
  1530. }
  1531. bool FindBar::search_prev() {
  1532. return _search(true);
  1533. }
  1534. bool FindBar::_search(bool p_search_previous) {
  1535. String stext = search_text->get_text();
  1536. bool keep = prev_search == stext;
  1537. bool ret = rich_text_label->search(stext, keep, p_search_previous);
  1538. if (!ret) {
  1539. ret = rich_text_label->search(stext, false, p_search_previous);
  1540. }
  1541. prev_search = stext;
  1542. if (ret) {
  1543. _update_results_count();
  1544. } else {
  1545. results_count = 0;
  1546. }
  1547. _update_matches_label();
  1548. return ret;
  1549. }
  1550. void FindBar::_update_results_count() {
  1551. results_count = 0;
  1552. String searched = search_text->get_text();
  1553. if (searched.empty()) {
  1554. return;
  1555. }
  1556. String full_text = rich_text_label->get_text();
  1557. int from_pos = 0;
  1558. while (true) {
  1559. int pos = full_text.findn(searched, from_pos);
  1560. if (pos == -1) {
  1561. break;
  1562. }
  1563. results_count++;
  1564. from_pos = pos + searched.length();
  1565. }
  1566. }
  1567. void FindBar::_update_matches_label() {
  1568. if (search_text->get_text().empty() || results_count == -1) {
  1569. matches_label->hide();
  1570. } else {
  1571. matches_label->show();
  1572. matches_label->add_color_override("font_color", results_count > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor"));
  1573. matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count));
  1574. }
  1575. }
  1576. void FindBar::_hide_bar() {
  1577. if (search_text->has_focus()) {
  1578. rich_text_label->grab_focus();
  1579. }
  1580. hide();
  1581. }
  1582. void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) {
  1583. Ref<InputEventKey> k = p_event;
  1584. if (k.is_valid()) {
  1585. if (k->is_pressed() && (rich_text_label->has_focus() || is_a_parent_of(get_focus_owner()))) {
  1586. bool accepted = true;
  1587. switch (k->get_scancode()) {
  1588. case KEY_ESCAPE: {
  1589. _hide_bar();
  1590. } break;
  1591. default: {
  1592. accepted = false;
  1593. } break;
  1594. }
  1595. if (accepted) {
  1596. accept_event();
  1597. }
  1598. }
  1599. }
  1600. }
  1601. void FindBar::_search_text_changed(const String &p_text) {
  1602. search_next();
  1603. }
  1604. void FindBar::_search_text_entered(const String &p_text) {
  1605. if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
  1606. search_prev();
  1607. } else {
  1608. search_next();
  1609. }
  1610. }