editor_help.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. /*************************************************************************/
  2. /* editor_help.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "editor_help.h"
  30. #include "editor_node.h"
  31. #include "editor_settings.h"
  32. #include "os/keyboard.h"
  33. #include "doc_data_compressed.h"
  34. #include "os/keyboard.h"
  35. void EditorHelpSearch::popup(const String& p_term) {
  36. popup_centered_ratio(0.6);
  37. if (p_term!="") {
  38. search_box->set_text(p_term);
  39. search_box->select_all();
  40. _update_search();
  41. } else
  42. search_box->clear();
  43. search_box->grab_focus();
  44. }
  45. void EditorHelpSearch::_text_changed(const String& p_newtext) {
  46. _update_search();
  47. }
  48. void EditorHelpSearch::_sbox_input(const InputEvent& p_ie) {
  49. if (p_ie.type==InputEvent::KEY && (
  50. p_ie.key.scancode == KEY_UP ||
  51. p_ie.key.scancode == KEY_DOWN ||
  52. p_ie.key.scancode == KEY_PAGEUP ||
  53. p_ie.key.scancode == KEY_PAGEDOWN ) ) {
  54. search_options->call("_input_event",p_ie);
  55. search_box->accept_event();
  56. }
  57. }
  58. void EditorHelpSearch::_update_search() {
  59. search_options->clear();
  60. search_options->set_hide_root(true);
  61. /*
  62. TreeItem *root = search_options->create_item();
  63. _parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
  64. */
  65. List<String> type_list;
  66. ObjectTypeDB::get_type_list(&type_list);
  67. DocData *doc=EditorHelp::get_doc_data();
  68. String term = search_box->get_text();
  69. if (term.length()<3)
  70. return;
  71. TreeItem *root = search_options->create_item();
  72. Ref<Texture> def_icon = get_icon("Node","EditorIcons");
  73. //classes first
  74. for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {
  75. if (E->key().findn(term)!=-1) {
  76. TreeItem *item = search_options->create_item(root);
  77. item->set_metadata(0,"class_name:"+E->key());
  78. item->set_text(0,E->key()+" (Class)");
  79. if (has_icon(E->key(),"EditorIcons"))
  80. item->set_icon(0,get_icon(E->key(),"EditorIcons"));
  81. else
  82. item->set_icon(0,def_icon);
  83. }
  84. }
  85. //class methods, etc second
  86. for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {
  87. DocData::ClassDoc & c = E->get();
  88. Ref<Texture> cicon;
  89. if (has_icon(E->key(),"EditorIcons"))
  90. cicon=get_icon(E->key(),"EditorIcons");
  91. else
  92. cicon=def_icon;
  93. for(int i=0;i<c.methods.size();i++) {
  94. if( (term.begins_with(".") && c.methods[i].name.begins_with(term.right(1)))
  95. || (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length()-1).strip_edges()))
  96. || (term.begins_with(".") && term.ends_with("(") && c.methods[i].name==term.substr(1,term.length()-2).strip_edges())
  97. || c.methods[i].name.findn(term)!=-1) {
  98. TreeItem *item = search_options->create_item(root);
  99. item->set_metadata(0,"class_method:"+E->key()+":"+c.methods[i].name);
  100. item->set_text(0,E->key()+"."+c.methods[i].name+" (Method)");
  101. item->set_icon(0,cicon);
  102. }
  103. }
  104. for(int i=0;i<c.signals.size();i++) {
  105. if (c.signals[i].name.findn(term)!=-1) {
  106. TreeItem *item = search_options->create_item(root);
  107. item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
  108. item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal)");
  109. item->set_icon(0,cicon);
  110. }
  111. }
  112. for(int i=0;i<c.constants.size();i++) {
  113. if (c.constants[i].name.findn(term)!=-1) {
  114. TreeItem *item = search_options->create_item(root);
  115. item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
  116. item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant)");
  117. item->set_icon(0,cicon);
  118. }
  119. }
  120. for(int i=0;i<c.properties.size();i++) {
  121. if (c.properties[i].name.findn(term)!=-1) {
  122. TreeItem *item = search_options->create_item(root);
  123. item->set_metadata(0,"class_property:"+E->key()+":"+c.properties[i].name);
  124. item->set_text(0,E->key()+"."+c.properties[i].name+" (Property)");
  125. item->set_icon(0,cicon);
  126. }
  127. }
  128. for(int i=0;i<c.theme_properties.size();i++) {
  129. if (c.theme_properties[i].name.findn(term)!=-1) {
  130. TreeItem *item = search_options->create_item(root);
  131. item->set_metadata(0,"class_theme_item:"+E->key()+":"+c.theme_properties[i].name);
  132. item->set_text(0,E->key()+"."+c.theme_properties[i].name+" (Theme Item)");
  133. item->set_icon(0,cicon);
  134. }
  135. }
  136. }
  137. //same but descriptions
  138. for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {
  139. DocData::ClassDoc & c = E->get();
  140. Ref<Texture> cicon;
  141. if (has_icon(E->key(),"EditorIcons"))
  142. cicon=get_icon(E->key(),"EditorIcons");
  143. else
  144. cicon=def_icon;
  145. if (c.description.findn(term)!=-1) {
  146. TreeItem *item = search_options->create_item(root);
  147. item->set_metadata(0,"class_desc:"+E->key());
  148. item->set_text(0,E->key()+" (Class Description)");
  149. item->set_icon(0,cicon);
  150. }
  151. for(int i=0;i<c.methods.size();i++) {
  152. if (c.methods[i].description.findn(term)!=-1) {
  153. TreeItem *item = search_options->create_item(root);
  154. item->set_metadata(0,"class_method_desc:"+E->key()+":"+c.methods[i].name);
  155. item->set_text(0,E->key()+"."+c.methods[i].name+" (Method Description)");
  156. item->set_icon(0,cicon);
  157. }
  158. }
  159. for(int i=0;i<c.signals.size();i++) {
  160. if (c.signals[i].description.findn(term)!=-1) {
  161. TreeItem *item = search_options->create_item(root);
  162. item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
  163. item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal Description)");
  164. item->set_icon(0,cicon);
  165. }
  166. }
  167. for(int i=0;i<c.constants.size();i++) {
  168. if (c.constants[i].description.findn(term)!=-1) {
  169. TreeItem *item = search_options->create_item(root);
  170. item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
  171. item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant Description)");
  172. item->set_icon(0,cicon);
  173. }
  174. }
  175. for(int i=0;i<c.properties.size();i++) {
  176. if (c.properties[i].description.findn(term)!=-1) {
  177. TreeItem *item = search_options->create_item(root);
  178. item->set_metadata(0,"class_property_desc:"+E->key()+":"+c.properties[i].name);
  179. item->set_text(0,E->key()+"."+c.properties[i].name+" (Property Description)");
  180. item->set_icon(0,cicon);
  181. }
  182. }
  183. }
  184. get_ok()->set_disabled(root->get_children()==NULL);
  185. }
  186. void EditorHelpSearch::_confirmed() {
  187. TreeItem *ti = search_options->get_selected();
  188. if (!ti)
  189. return;
  190. String mdata=ti->get_metadata(0);
  191. emit_signal("go_to_help",mdata);
  192. editor->call("_editor_select",3); // in case EditorHelpSearch beeen invoked on top of other editor window
  193. // go to that
  194. hide();
  195. }
  196. void EditorHelpSearch::_notification(int p_what) {
  197. if (p_what==NOTIFICATION_ENTER_SCENE) {
  198. connect("confirmed",this,"_confirmed");
  199. _update_search();
  200. }
  201. if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
  202. if (is_visible()) {
  203. search_box->call_deferred("grab_focus"); // still not visible
  204. search_box->select_all();
  205. }
  206. }
  207. }
  208. void EditorHelpSearch::_bind_methods() {
  209. ObjectTypeDB::bind_method(_MD("_text_changed"),&EditorHelpSearch::_text_changed);
  210. ObjectTypeDB::bind_method(_MD("_confirmed"),&EditorHelpSearch::_confirmed);
  211. ObjectTypeDB::bind_method(_MD("_sbox_input"),&EditorHelpSearch::_sbox_input);
  212. ObjectTypeDB::bind_method(_MD("_update_search"),&EditorHelpSearch::_sbox_input);
  213. ADD_SIGNAL(MethodInfo("go_to_help"));
  214. }
  215. EditorHelpSearch::EditorHelpSearch(EditorNode *p_editor) {
  216. editor=p_editor;
  217. VBoxContainer *vbc = memnew( VBoxContainer );
  218. add_child(vbc);
  219. set_child_rect(vbc);
  220. HBoxContainer *sb_hb = memnew( HBoxContainer);
  221. search_box = memnew( LineEdit );
  222. sb_hb->add_child(search_box);
  223. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  224. Button *sb = memnew( Button("Search"));
  225. sb->connect("pressed",this,"_update_search");
  226. sb_hb->add_child(sb);
  227. vbc->add_margin_child("Search:",sb_hb);
  228. search_box->connect("text_changed",this,"_text_changed");
  229. search_box->connect("input_event",this,"_sbox_input");
  230. search_options = memnew( Tree );
  231. vbc->add_margin_child("Matches:",search_options,true);
  232. get_ok()->set_text("View");
  233. get_ok()->set_disabled(true);
  234. register_text_enter(search_box);
  235. set_hide_on_ok(false);
  236. search_options->connect("item_activated",this,"_confirmed");
  237. set_title("Search Classes");
  238. // search_options->set_hide_root(true);
  239. }
  240. DocData *EditorHelp::doc=NULL;
  241. void EditorHelp::_unhandled_key_input(const InputEvent& p_ev) {
  242. if (!is_visible())
  243. return;
  244. if ( p_ev.key.mod.control && p_ev.key.scancode==KEY_F) {
  245. search->grab_focus();
  246. search->select_all();
  247. } else if (p_ev.key.mod.shift && p_ev.key.scancode==KEY_F1) {
  248. class_search->popup();
  249. }
  250. }
  251. void EditorHelp::_search(const String&) {
  252. if (search->get_text()=="")
  253. return;
  254. String stext=search->get_text();
  255. bool keep = prev_search==stext && class_list->get_selected() && prev_search_page==class_list->get_selected()->get_text(0);
  256. class_desc->search(stext);
  257. prev_search=stext;
  258. if (class_list->get_selected())
  259. prev_search_page=class_list->get_selected()->get_text(0);
  260. }
  261. void EditorHelp::_button_pressed(int p_idx) {
  262. if (p_idx==PAGE_CLASS_LIST) {
  263. // edited_class->set_pressed(false);
  264. // class_list_button->set_pressed(true);
  265. // tabs->set_current_tab(PAGE_CLASS_LIST);
  266. } else if (p_idx==PAGE_CLASS_DESC) {
  267. // edited_class->set_pressed(true);
  268. // class_list_button->set_pressed(false);
  269. // tabs->set_current_tab(PAGE_CLASS_DESC);
  270. } else if (p_idx==PAGE_CLASS_PREV) {
  271. if (history_pos<2)
  272. return;
  273. history_pos--;
  274. ERR_FAIL_INDEX(history_pos-1,history.size());
  275. _goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
  276. _update_history_buttons();
  277. } else if (p_idx==PAGE_CLASS_NEXT) {
  278. if (history_pos>=history.size())
  279. return;
  280. history_pos++;
  281. ERR_FAIL_INDEX(history_pos-1,history.size());
  282. _goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
  283. _update_history_buttons();
  284. } else if (p_idx==PAGE_SEARCH) {
  285. _search("");
  286. } else if (p_idx==CLASS_SEARCH) {
  287. class_search->popup();
  288. }
  289. }
  290. void EditorHelp::_class_list_select(const String& p_select) {
  291. _goto_desc(p_select);
  292. }
  293. void EditorHelp::_class_desc_select(const String& p_select) {
  294. if (p_select.begins_with("#")) {
  295. _goto_desc(p_select.substr(1,p_select.length()));
  296. return;
  297. } else if (p_select.begins_with("@")) {
  298. String m = p_select.substr(1,p_select.length());
  299. if (!method_line.has(m))
  300. return;
  301. class_desc->scroll_to_line(method_line[m]);
  302. return;
  303. }
  304. }
  305. void EditorHelp::_add_type(const String& p_type) {
  306. String t = p_type;
  307. if (t=="")
  308. t="void";
  309. bool can_ref = (t!="int" && t!="real" && t!="bool" && t!="void");
  310. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color"));
  311. if (can_ref)
  312. class_desc->push_meta("#"+t); //class
  313. class_desc->add_text(t);
  314. if (can_ref)
  315. class_desc->pop();
  316. class_desc->pop();
  317. }
  318. void EditorHelp::_update_history_buttons() {
  319. back->set_disabled(history_pos<2);
  320. forward->set_disabled(history_pos>=history.size());
  321. }
  322. void EditorHelp::_scroll_changed(double p_scroll) {
  323. if (scroll_locked)
  324. return;
  325. int p = history_pos -1;
  326. if (p<0 || p>=history.size())
  327. return;
  328. if (class_desc->get_v_scroll()->is_hidden())
  329. p_scroll=0;
  330. history[p].scroll=p_scroll;
  331. }
  332. Error EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vscr) {
  333. //ERR_FAIL_COND(!doc->class_list.has(p_class));
  334. if (!doc->class_list.has(p_class))
  335. return ERR_DOES_NOT_EXIST;
  336. if (tree_item_map.has(p_class)) {
  337. tree_item_map[p_class]->select(0);
  338. class_list->ensure_cursor_is_visible();
  339. }
  340. class_desc->show();
  341. //tabs->set_current_tab(PAGE_CLASS_DESC);
  342. edited_class->set_pressed(true);
  343. class_list_button->set_pressed(false);
  344. description_line=0;
  345. if (p_class==edited_class->get_text())
  346. return OK; //already there
  347. scroll_locked=true;
  348. if (p_update_history) {
  349. history.resize(history_pos);
  350. history_pos++;
  351. History h;
  352. h.c=p_class;
  353. h.scroll=0;
  354. history.push_back(h);
  355. _update_history_buttons();
  356. class_desc->get_v_scroll()->set_val(0);
  357. }
  358. class_desc->clear();
  359. method_line.clear();
  360. edited_class->set_text(p_class);
  361. //edited_class->show();
  362. DocData::ClassDoc &cd=doc->class_list[p_class];
  363. Color h_color;
  364. Ref<Font> doc_font = get_font("normal","Fonts");
  365. Ref<Font> doc_code_font = get_font("source","Fonts");
  366. Ref<Font> doc_title_font = get_font("large","Fonts");
  367. h_color=Color(1,1,1,1);
  368. class_desc->push_font(doc_title_font);
  369. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  370. class_desc->add_text("Class: ");
  371. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color"));
  372. class_desc->add_text(p_class);
  373. class_desc->pop();
  374. class_desc->pop();
  375. class_desc->pop();
  376. class_desc->add_newline();
  377. if (cd.inherits!="") {
  378. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  379. class_desc->push_font(doc_title_font);
  380. class_desc->add_text("Inherits: ");
  381. class_desc->pop();
  382. class_desc->pop();
  383. class_desc->push_font(doc_font);
  384. _add_type(cd.inherits);
  385. class_desc->pop();
  386. class_desc->add_newline();
  387. class_desc->add_newline();
  388. }
  389. if (cd.brief_description!="") {
  390. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  391. class_desc->push_font(doc_title_font);
  392. class_desc->add_text("Brief Description:");
  393. class_desc->pop();
  394. class_desc->pop();
  395. //class_desc->add_newline();
  396. class_desc->add_newline();
  397. _add_text(cd.brief_description);
  398. class_desc->add_newline();
  399. class_desc->add_newline();
  400. }
  401. bool method_descr=false;
  402. if (cd.methods.size()) {
  403. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  404. class_desc->push_font(doc_title_font);
  405. class_desc->add_text("Public Methods:");
  406. class_desc->pop();
  407. class_desc->pop();
  408. //class_desc->add_newline();
  409. class_desc->add_newline();
  410. class_desc->push_indent(1);
  411. for(int i=0;i<cd.methods.size();i++) {
  412. method_line[cd.methods[i].name]=class_desc->get_line_count()-2; //gets overriden if description
  413. class_desc->push_font(doc_code_font);
  414. _add_type(cd.methods[i].return_type);
  415. class_desc->add_text(" ");
  416. if (cd.methods[i].description!="") {
  417. method_descr=true;
  418. class_desc->push_meta("@"+cd.methods[i].name);
  419. }
  420. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  421. class_desc->add_text(cd.methods[i].name);
  422. class_desc->pop();
  423. if (cd.methods[i].description!="")
  424. class_desc->pop();
  425. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  426. class_desc->add_text(cd.methods[i].arguments.size()?"( ":"(");
  427. class_desc->pop();
  428. for(int j=0;j<cd.methods[i].arguments.size();j++) {
  429. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  430. if (j>0)
  431. class_desc->add_text(", ");
  432. _add_type(cd.methods[i].arguments[j].type);
  433. class_desc->add_text(" "+cd.methods[i].arguments[j].name);
  434. if (cd.methods[i].arguments[j].default_value!="") {
  435. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  436. class_desc->add_text("=");
  437. class_desc->pop();
  438. class_desc->add_text(cd.methods[i].arguments[j].default_value);
  439. }
  440. class_desc->pop();
  441. }
  442. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  443. class_desc->add_text(cd.methods[i].arguments.size()?" )":")");
  444. class_desc->pop();
  445. if (cd.methods[i].qualifiers!="") {
  446. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  447. class_desc->add_text(" "+cd.methods[i].qualifiers);
  448. class_desc->pop();
  449. }
  450. class_desc->pop();//monofont
  451. class_desc->add_newline();
  452. }
  453. class_desc->pop();
  454. class_desc->add_newline();
  455. }
  456. if (cd.properties.size()) {
  457. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  458. class_desc->push_font(doc_title_font);
  459. class_desc->add_text("Members:");
  460. class_desc->pop();
  461. class_desc->pop();
  462. class_desc->add_newline();
  463. class_desc->push_indent(1);
  464. //class_desc->add_newline();
  465. for(int i=0;i<cd.properties.size();i++) {
  466. property_line[cd.properties[i].name]=class_desc->get_line_count()-2; //gets overriden if description
  467. class_desc->push_font(doc_code_font);
  468. _add_type(cd.properties[i].type);
  469. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  470. class_desc->add_text(" "+cd.properties[i].name);
  471. class_desc->pop();
  472. class_desc->pop();
  473. if (cd.properties[i].description!="") {
  474. class_desc->push_font(doc_font);
  475. class_desc->add_text(" ");
  476. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
  477. class_desc->add_text(cd.properties[i].description);
  478. class_desc->pop();
  479. class_desc->pop();
  480. }
  481. class_desc->add_newline();
  482. }
  483. class_desc->add_newline();
  484. class_desc->pop();
  485. }
  486. if (cd.theme_properties.size()) {
  487. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  488. class_desc->push_font(doc_title_font);
  489. class_desc->add_text("GUI Theme Items:");
  490. class_desc->pop();
  491. class_desc->pop();
  492. class_desc->add_newline();
  493. class_desc->push_indent(1);
  494. //class_desc->add_newline();
  495. for(int i=0;i<cd.theme_properties.size();i++) {
  496. theme_property_line[cd.theme_properties[i].name]=class_desc->get_line_count()-2; //gets overriden if description
  497. class_desc->push_font(doc_code_font);
  498. _add_type(cd.theme_properties[i].type);
  499. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  500. class_desc->add_text(" "+cd.theme_properties[i].name);
  501. class_desc->pop();
  502. class_desc->pop();
  503. if (cd.theme_properties[i].description!="") {
  504. class_desc->push_font(doc_font);
  505. class_desc->add_text(" ");
  506. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
  507. class_desc->add_text(cd.theme_properties[i].description);
  508. class_desc->pop();
  509. class_desc->pop();
  510. }
  511. class_desc->add_newline();
  512. }
  513. class_desc->add_newline();
  514. class_desc->pop();
  515. }
  516. if (cd.signals.size()) {
  517. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  518. class_desc->push_font(doc_title_font);
  519. class_desc->add_text("Signals:");
  520. class_desc->pop();
  521. class_desc->pop();
  522. class_desc->add_newline();
  523. //class_desc->add_newline();
  524. class_desc->push_indent(1);
  525. for(int i=0;i<cd.signals.size();i++) {
  526. signal_line[cd.signals[i].name]=class_desc->get_line_count()-2; //gets overriden if description
  527. class_desc->push_font(doc_code_font);
  528. //_add_type("void");
  529. //class_desc->add_text(" ");
  530. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  531. class_desc->add_text(cd.signals[i].name);
  532. class_desc->pop();
  533. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  534. class_desc->add_text(cd.signals[i].arguments.size()?"( ":"(");
  535. class_desc->pop();
  536. for(int j=0;j<cd.signals[i].arguments.size();j++) {
  537. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  538. if (j>0)
  539. class_desc->add_text(", ");
  540. _add_type(cd.signals[i].arguments[j].type);
  541. class_desc->add_text(" "+cd.signals[i].arguments[j].name);
  542. if (cd.signals[i].arguments[j].default_value!="") {
  543. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  544. class_desc->add_text("=");
  545. class_desc->pop();
  546. class_desc->add_text(cd.signals[i].arguments[j].default_value);
  547. }
  548. class_desc->pop();
  549. }
  550. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  551. class_desc->add_text(cd.signals[i].arguments.size()?" )":")");
  552. class_desc->pop();
  553. if (cd.signals[i].description!="") {
  554. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
  555. class_desc->add_text(" "+cd.signals[i].description);
  556. class_desc->pop();
  557. }
  558. class_desc->pop();//monofont
  559. class_desc->add_newline();
  560. }
  561. class_desc->pop();
  562. class_desc->add_newline();
  563. }
  564. if (cd.constants.size()) {
  565. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  566. class_desc->push_font(doc_title_font);
  567. class_desc->add_text("Constants:");
  568. class_desc->pop();
  569. class_desc->pop();
  570. class_desc->push_indent(1);
  571. class_desc->add_newline();
  572. //class_desc->add_newline();
  573. for(int i=0;i<cd.constants.size();i++) {
  574. constant_line[cd.constants[i].name]=class_desc->get_line_count()-2;
  575. class_desc->push_font(doc_code_font);
  576. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color"));
  577. class_desc->add_text(cd.constants[i].name);
  578. class_desc->pop();
  579. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  580. class_desc->add_text(" = ");
  581. class_desc->pop();
  582. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  583. class_desc->add_text(cd.constants[i].value);
  584. class_desc->pop();
  585. class_desc->pop();
  586. if (cd.constants[i].description!="") {
  587. class_desc->push_font(doc_font);
  588. class_desc->add_text(" ");
  589. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/comment_color"));
  590. class_desc->add_text(cd.constants[i].description);
  591. class_desc->pop();
  592. class_desc->pop();
  593. }
  594. class_desc->add_newline();
  595. }
  596. class_desc->pop();
  597. class_desc->add_newline();
  598. }
  599. if (cd.description!="") {
  600. description_line=class_desc->get_line_count()-2;
  601. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  602. class_desc->push_font(doc_title_font);
  603. class_desc->add_text("Description:");
  604. class_desc->pop();
  605. class_desc->pop();
  606. class_desc->add_newline();
  607. class_desc->add_newline();
  608. _add_text(cd.description);
  609. class_desc->add_newline();
  610. class_desc->add_newline();
  611. }
  612. if (method_descr) {
  613. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  614. class_desc->push_font(doc_title_font);
  615. class_desc->add_text("Method Description:");
  616. class_desc->pop();
  617. class_desc->pop();
  618. class_desc->add_newline();
  619. class_desc->add_newline();
  620. for(int i=0;i<cd.methods.size();i++) {
  621. method_line[cd.methods[i].name]=class_desc->get_line_count()-2;
  622. class_desc->push_font(doc_code_font);
  623. _add_type(cd.methods[i].return_type);
  624. class_desc->add_text(" ");
  625. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  626. class_desc->add_text(cd.methods[i].name);
  627. class_desc->pop();
  628. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  629. class_desc->add_text(cd.methods[i].arguments.size()?"( ":"(");
  630. class_desc->pop();
  631. for(int j=0;j<cd.methods[i].arguments.size();j++) {
  632. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  633. if (j>0)
  634. class_desc->add_text(", ");
  635. _add_type(cd.methods[i].arguments[j].type);
  636. class_desc->add_text(" "+cd.methods[i].arguments[j].name);
  637. if (cd.methods[i].arguments[j].default_value!="") {
  638. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  639. class_desc->add_text("=");
  640. class_desc->pop();
  641. class_desc->add_text(cd.methods[i].arguments[j].default_value);
  642. }
  643. class_desc->pop();
  644. }
  645. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/symbol_color"));
  646. class_desc->add_text(cd.methods[i].arguments.size()?" )":")");
  647. class_desc->pop();
  648. if (cd.methods[i].qualifiers!="") {
  649. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
  650. class_desc->add_text(" "+cd.methods[i].qualifiers);
  651. class_desc->pop();
  652. }
  653. class_desc->pop();
  654. class_desc->add_newline();
  655. class_desc->add_newline();
  656. _add_text(cd.methods[i].description);
  657. class_desc->add_newline();
  658. class_desc->add_newline();
  659. }
  660. }
  661. if (!p_update_history) {
  662. class_desc->get_v_scroll()->set_val(history[history_pos-1].scroll);
  663. }
  664. scroll_locked=false;
  665. return OK;
  666. }
  667. void EditorHelp::_request_help(const String& p_string) {
  668. Error err = _goto_desc(p_string);
  669. if (err==OK) {
  670. editor->call("_editor_select",3);
  671. } else {
  672. class_search->popup(p_string);
  673. }
  674. //100 palabras
  675. }
  676. void EditorHelp::_help_callback(const String& p_topic) {
  677. String what = p_topic.get_slice(":",0);
  678. String clss = p_topic.get_slice(":",1);
  679. String name;
  680. if (p_topic.get_slice_count(":")==3)
  681. name=p_topic.get_slice(":",2);
  682. _request_help(clss); //first go to class
  683. int line=0;
  684. if (what=="class_desc") {
  685. line=description_line;
  686. } else if (what=="class_signal") {
  687. if (signal_line.has(name))
  688. line=signal_line[name];
  689. } else if (what=="class_method" || what=="class_method_desc") {
  690. if (method_line.has(name))
  691. line=method_line[name];
  692. } else if (what=="class_property") {
  693. if (property_line.has(name))
  694. line=property_line[name];
  695. } else if (what=="class_theme_item") {
  696. if (theme_property_line.has(name))
  697. line=theme_property_line[name];
  698. } else if (what=="class_constant") {
  699. if (constant_line.has(name))
  700. line=constant_line[name];
  701. }
  702. class_desc->scroll_to_line(line);
  703. }
  704. void EditorHelp::_add_text(const String& p_bbcode) {
  705. class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
  706. class_desc->push_font( get_font("normal","Fonts") );
  707. class_desc->push_indent(1);
  708. int pos = 0;
  709. List<String> tag_stack;
  710. while(pos < p_bbcode.length()) {
  711. int brk_pos = p_bbcode.find("[",pos);
  712. if (brk_pos<0)
  713. brk_pos=p_bbcode.length();
  714. if (brk_pos > pos) {
  715. class_desc->add_text(p_bbcode.substr(pos,brk_pos-pos));
  716. }
  717. if (brk_pos==p_bbcode.length())
  718. break; //nothing else o add
  719. int brk_end = p_bbcode.find("]",brk_pos+1);
  720. if (brk_end==-1) {
  721. //no close, add the rest
  722. class_desc->add_text(p_bbcode.substr(brk_pos,p_bbcode.length()-brk_pos));
  723. break;
  724. }
  725. String tag = p_bbcode.substr(brk_pos+1,brk_end-brk_pos-1);
  726. if (tag.begins_with("/")) {
  727. bool tag_ok = tag_stack.size() && tag_stack.front()->get()==tag.substr(1,tag.length());
  728. if (tag_stack.size()) {
  729. }
  730. if (!tag_ok) {
  731. class_desc->add_text("[");
  732. pos++;
  733. continue;
  734. }
  735. tag_stack.pop_front();
  736. pos=brk_end+1;
  737. if (tag!="/img")
  738. class_desc->pop();
  739. } else if (tag.begins_with("method ")) {
  740. String m = tag.substr(7,tag.length());
  741. class_desc->push_meta("@"+m);
  742. class_desc->add_text(m+"()");
  743. class_desc->pop();
  744. pos=brk_end+1;
  745. } else if (doc->class_list.has(tag)) {
  746. class_desc->push_meta("#"+tag);
  747. class_desc->add_text(tag);
  748. class_desc->pop();
  749. pos=brk_end+1;
  750. } else if (tag=="b") {
  751. //use bold font
  752. class_desc->push_font(get_font("source","Fonts"));
  753. pos=brk_end+1;
  754. tag_stack.push_front(tag);
  755. } else if (tag=="i") {
  756. //use italics font
  757. //class_desc->push_font(get_font("italic","Fonts"));
  758. pos=brk_end+1;
  759. tag_stack.push_front(tag);
  760. } else if (tag=="code") {
  761. //use monospace font
  762. class_desc->push_font(get_font("source","EditorFonts"));
  763. pos=brk_end+1;
  764. tag_stack.push_front(tag);
  765. } else if (tag=="center") {
  766. //use monospace font
  767. class_desc->push_align(RichTextLabel::ALIGN_CENTER);
  768. pos=brk_end+1;
  769. tag_stack.push_front(tag);
  770. } else if (tag=="br") {
  771. //use monospace font
  772. class_desc->add_newline();
  773. pos=brk_end+1;
  774. } else if (tag=="u") {
  775. //use underline
  776. class_desc->push_underline();
  777. pos=brk_end+1;
  778. tag_stack.push_front(tag);
  779. } else if (tag=="s") {
  780. //use strikethrough (not supported underline instead)
  781. class_desc->push_underline();
  782. pos=brk_end+1;
  783. tag_stack.push_front(tag);
  784. } else if (tag=="url") {
  785. //use strikethrough (not supported underline instead)
  786. int end=p_bbcode.find("[",brk_end);
  787. if (end==-1)
  788. end=p_bbcode.length();
  789. String url = p_bbcode.substr(brk_end+1,end-brk_end-1);
  790. class_desc->push_meta(url);
  791. pos=brk_end+1;
  792. tag_stack.push_front(tag);
  793. } else if (tag.begins_with("url=")) {
  794. String url = tag.substr(4,tag.length());
  795. class_desc->push_meta(url);
  796. pos=brk_end+1;
  797. tag_stack.push_front("url");
  798. } else if (tag=="img") {
  799. //use strikethrough (not supported underline instead)
  800. int end=p_bbcode.find("[",brk_end);
  801. if (end==-1)
  802. end=p_bbcode.length();
  803. String image = p_bbcode.substr(brk_end+1,end-brk_end-1);
  804. Ref<Texture> texture = ResourceLoader::load(base_path+"/"+image,"Texture");
  805. if (texture.is_valid())
  806. class_desc->add_image(texture);
  807. pos=end;
  808. tag_stack.push_front(tag);
  809. } else if (tag.begins_with("color=")) {
  810. String col = tag.substr(6,tag.length());
  811. Color color;
  812. if (col.begins_with("#"))
  813. color=Color::html(col);
  814. else if (col=="aqua")
  815. color=Color::html("#00FFFF");
  816. else if (col=="black")
  817. color=Color::html("#000000");
  818. else if (col=="blue")
  819. color=Color::html("#0000FF");
  820. else if (col=="fuchsia")
  821. color=Color::html("#FF00FF");
  822. else if (col=="gray" || col=="grey")
  823. color=Color::html("#808080");
  824. else if (col=="green")
  825. color=Color::html("#008000");
  826. else if (col=="lime")
  827. color=Color::html("#00FF00");
  828. else if (col=="maroon")
  829. color=Color::html("#800000");
  830. else if (col=="navy")
  831. color=Color::html("#000080");
  832. else if (col=="olive")
  833. color=Color::html("#808000");
  834. else if (col=="purple")
  835. color=Color::html("#800080");
  836. else if (col=="red")
  837. color=Color::html("#FF0000");
  838. else if (col=="silver")
  839. color=Color::html("#C0C0C0");
  840. else if (col=="teal")
  841. color=Color::html("#008008");
  842. else if (col=="white")
  843. color=Color::html("#FFFFFF");
  844. else if (col=="yellow")
  845. color=Color::html("#FFFF00");
  846. else
  847. color=Color(0,0,0,1); //base_color;
  848. class_desc->push_color(color);
  849. pos=brk_end+1;
  850. tag_stack.push_front("color");
  851. } else if (tag.begins_with("font=")) {
  852. String fnt = tag.substr(5,tag.length());
  853. Ref<Font> font = ResourceLoader::load(base_path+"/"+fnt,"Font");
  854. if (font.is_valid())
  855. class_desc->push_font(font);
  856. else {
  857. class_desc->push_font(get_font("source","rFonts"));
  858. }
  859. pos=brk_end+1;
  860. tag_stack.push_front("font");
  861. } else {
  862. class_desc->add_text("["); //ignore
  863. pos=brk_pos+1;
  864. }
  865. }
  866. class_desc->pop();
  867. class_desc->pop();
  868. }
  869. void EditorHelp::add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root) {
  870. if (p_types.has(p_type))
  871. return;
  872. // if (!ObjectTypeDB::is_type(p_type,base) || p_type==base)
  873. // return;
  874. String inherits=doc->class_list[p_type].inherits;
  875. TreeItem *parent=p_root;
  876. if (inherits.length()) {
  877. if (!p_types.has(inherits)) {
  878. add_type(inherits,p_types,p_root);
  879. }
  880. if (p_types.has(inherits) )
  881. parent=p_types[inherits];
  882. }
  883. TreeItem *item = class_list->create_item(parent);
  884. item->set_metadata(0,p_type);
  885. item->set_tooltip(0,doc->class_list[p_type].brief_description);
  886. item->set_text(0,p_type);
  887. if (has_icon(p_type,"EditorIcons")) {
  888. item->set_icon(0, get_icon(p_type,"EditorIcons"));
  889. }
  890. p_types[p_type]=item;
  891. }
  892. void EditorHelp::_update_doc() {
  893. class_list->clear();
  894. List<String> type_list;
  895. tree_item_map.clear();
  896. TreeItem *root = class_list->create_item();
  897. class_list->set_hide_root(true);
  898. List<String>::Element *I=type_list.front();
  899. for(Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {
  900. add_type(E->key(),tree_item_map,root);
  901. }
  902. }
  903. void EditorHelp::generate_doc() {
  904. doc = memnew( DocData );
  905. doc->generate(true);
  906. DocData compdoc;
  907. compdoc.load_compressed(_doc_data_compressed,_doc_data_compressed_size,_doc_data_uncompressed_size);
  908. doc->merge_from(compdoc); //ensure all is up to date
  909. }
  910. void EditorHelp::_notification(int p_what) {
  911. switch(p_what) {
  912. case NOTIFICATION_READY: {
  913. forward->set_icon(get_icon("Forward","EditorIcons"));
  914. back->set_icon(get_icon("Back","EditorIcons"));
  915. _update_doc();
  916. editor->connect("request_help",this,"_request_help");
  917. } break;
  918. }
  919. }
  920. void EditorHelp::_tree_item_selected() {
  921. if (select_locked)
  922. return;
  923. TreeItem *s=class_list->get_selected();
  924. if (!s)
  925. return;
  926. select_locked=true;
  927. _goto_desc(s->get_text(0));
  928. select_locked=false;
  929. }
  930. void EditorHelp::_bind_methods() {
  931. ObjectTypeDB::bind_method("_class_list_select",&EditorHelp::_class_list_select);
  932. ObjectTypeDB::bind_method("_class_desc_select",&EditorHelp::_class_desc_select);
  933. ObjectTypeDB::bind_method("_button_pressed",&EditorHelp::_button_pressed);
  934. ObjectTypeDB::bind_method("_scroll_changed",&EditorHelp::_scroll_changed);
  935. ObjectTypeDB::bind_method("_request_help",&EditorHelp::_request_help);
  936. ObjectTypeDB::bind_method("_unhandled_key_input",&EditorHelp::_unhandled_key_input);
  937. ObjectTypeDB::bind_method("_search",&EditorHelp::_search);
  938. ObjectTypeDB::bind_method("_tree_item_selected",&EditorHelp::_tree_item_selected);
  939. ObjectTypeDB::bind_method("_help_callback",&EditorHelp::_help_callback);
  940. }
  941. EditorHelp::EditorHelp(EditorNode *p_editor) {
  942. editor=p_editor;
  943. VBoxContainer *vbc = this;
  944. HBoxContainer *panel_hb = memnew( HBoxContainer );
  945. Button *b = memnew( Button );
  946. b->set_text("Class List");
  947. panel_hb->add_child(b);
  948. vbc->add_child(panel_hb);
  949. b->set_toggle_mode(true);
  950. b->set_pressed(true);
  951. b->connect("pressed",this,"_button_pressed",make_binds(PAGE_CLASS_LIST));
  952. class_list_button=b;
  953. class_list_button->hide();
  954. b = memnew( Button );
  955. b->set_text("Class");
  956. panel_hb->add_child(b);
  957. edited_class=b;
  958. edited_class->hide();
  959. b->set_toggle_mode(true);
  960. b->connect("pressed",this,"_button_pressed",make_binds(PAGE_CLASS_DESC));
  961. edited_class->hide();
  962. b = memnew( Button );
  963. b->set_text("Search in Classes");
  964. panel_hb->add_child(b);
  965. b->connect("pressed",this,"_button_pressed",make_binds(CLASS_SEARCH));
  966. Control *expand = memnew( Control );
  967. expand->set_h_size_flags(SIZE_EXPAND_FILL);
  968. panel_hb->add_child(expand);
  969. b = memnew( Button );
  970. panel_hb->add_child(b);
  971. back=b;
  972. b->connect("pressed",this,"_button_pressed",make_binds(PAGE_CLASS_PREV));
  973. b = memnew( Button );
  974. panel_hb->add_child(b);
  975. forward=b;
  976. b->connect("pressed",this,"_button_pressed",make_binds(PAGE_CLASS_NEXT));
  977. Separator *hs = memnew( VSeparator );
  978. panel_hb->add_child(hs);
  979. EmptyControl *ec = memnew( EmptyControl );
  980. ec->set_minsize(Size2(200,1));
  981. panel_hb->add_child(ec);
  982. search = memnew( LineEdit );
  983. ec->add_child(search);
  984. search->set_area_as_parent_rect();
  985. search->connect("text_entered",this,"_search");
  986. b = memnew( Button );
  987. b->set_text("Find");
  988. panel_hb->add_child(b);
  989. b->connect("pressed",this,"_button_pressed",make_binds(PAGE_SEARCH));
  990. hs = memnew( VSeparator );
  991. panel_hb->add_child(hs);
  992. h_split = memnew( HSplitContainer );
  993. h_split->set_v_size_flags(SIZE_EXPAND_FILL);
  994. vbc->add_child(h_split);
  995. class_list = memnew( Tree );
  996. h_split->add_child(class_list);
  997. //class_list->connect("meta_clicked",this,"_class_list_select");
  998. //class_list->set_selection_enabled(true);
  999. {
  1000. PanelContainer *pc = memnew( PanelContainer );
  1001. pc->add_style_override("panel",get_stylebox("normal","TextEdit"));
  1002. h_split->add_child(pc);
  1003. class_desc = memnew( RichTextLabel );
  1004. pc->add_child(class_desc);
  1005. class_desc->connect("meta_clicked",this,"_class_desc_select");
  1006. }
  1007. class_desc->get_v_scroll()->connect("value_changed",this,"_scroll_changed");
  1008. class_desc->set_selection_enabled(true);
  1009. editor=p_editor;
  1010. history_pos=0;
  1011. scroll_locked=false;
  1012. select_locked=false;
  1013. set_process_unhandled_key_input(true);
  1014. h_split->set_split_offset(200);
  1015. class_list->connect("cell_selected",this,"_tree_item_selected");
  1016. class_desc->hide();
  1017. class_search = memnew( EditorHelpSearch(editor) );
  1018. editor->get_gui_base()->add_child(class_search);
  1019. class_search->connect("go_to_help",this,"_help_callback");
  1020. // prev_search_page=-1;
  1021. }
  1022. EditorHelp::~EditorHelp() {
  1023. if (doc)
  1024. memdelete(doc);
  1025. }
  1026. void EditorHelpPlugin::edit(Object *p_object) {
  1027. if (!p_object->cast_to<Script>())
  1028. return;
  1029. //editor_help->edit(p_object->cast_to<Script>());
  1030. }
  1031. bool EditorHelpPlugin::handles(Object *p_object) const {
  1032. return false;
  1033. }
  1034. void EditorHelpPlugin::make_visible(bool p_visible) {
  1035. if (p_visible) {
  1036. editor_help->show();
  1037. } else {
  1038. editor_help->hide();
  1039. }
  1040. }
  1041. void EditorHelpPlugin::selected_notify() {
  1042. //editor_help->ensure_select_current();
  1043. }
  1044. Dictionary EditorHelpPlugin::get_state() const {
  1045. return Dictionary();
  1046. }
  1047. void EditorHelpPlugin::set_state(const Dictionary& p_state) {
  1048. //editor_help->set_state(p_state);
  1049. }
  1050. void EditorHelpPlugin::clear() {
  1051. //editor_help->clear();
  1052. }
  1053. void EditorHelpPlugin::save_external_data() {
  1054. //editor_help->save_external_data();
  1055. }
  1056. void EditorHelpPlugin::apply_changes() {
  1057. //editor_help->apply_helps();
  1058. }
  1059. void EditorHelpPlugin::restore_global_state() {
  1060. //if (bool(EDITOR_DEF("text_editor/restore_helps_on_load",true))) {
  1061. // editor_help->_load_files_state();
  1062. //}
  1063. }
  1064. void EditorHelpPlugin::save_global_state() {
  1065. //if (bool(EDITOR_DEF("text_editor/restore_helps_on_load",true))) {
  1066. // editor_help->_save_files_state();
  1067. // }
  1068. }
  1069. EditorHelpPlugin::EditorHelpPlugin(EditorNode *p_node) {
  1070. editor=p_node;
  1071. editor_help = memnew( EditorHelp(p_node) );
  1072. editor->get_viewport()->add_child(editor_help);
  1073. editor_help->set_area_as_parent_rect();
  1074. editor_help->hide();
  1075. }
  1076. EditorHelpPlugin::~EditorHelpPlugin()
  1077. {
  1078. }