script_editor_plugin.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695
  1. /*************************************************************************/
  2. /* script_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 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 "script_editor_plugin.h"
  30. #include "tools/editor/editor_settings.h"
  31. #include "io/resource_loader.h"
  32. #include "io/resource_saver.h"
  33. #include "os/keyboard.h"
  34. #include "os/os.h"
  35. #include "tools/editor/editor_node.h"
  36. #include "tools/editor/script_editor_debugger.h"
  37. #include "globals.h"
  38. #include "os/file_access.h"
  39. #include "scene/main/viewport.h"
  40. #include "os/keyboard.h"
  41. #include "os/input.h"
  42. /*** SCRIPT EDITOR ****/
  43. class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
  44. struct Cache {
  45. uint64_t time_loaded;
  46. RES cache;
  47. };
  48. Map<String,Cache> cached;
  49. public:
  50. uint64_t max_time_cache;
  51. int max_cache_size;
  52. void cleanup() {
  53. List< Map<String,Cache>::Element * > to_clean;
  54. Map<String,Cache>::Element *I=cached.front();
  55. while(I) {
  56. if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) {
  57. to_clean.push_back(I);
  58. }
  59. I=I->next();
  60. }
  61. while(to_clean.front()) {
  62. cached.erase(to_clean.front()->get());
  63. to_clean.pop_front();
  64. }
  65. }
  66. RES get_cached_resource(const String& p_path) {
  67. Map<String,Cache>::Element *E=cached.find(p_path);
  68. if (!E) {
  69. Cache c;
  70. c.cache=ResourceLoader::load(p_path);
  71. E=cached.insert(p_path,c);
  72. }
  73. E->get().time_loaded=OS::get_singleton()->get_ticks_msec();
  74. if (cached.size()>max_cache_size) {
  75. uint64_t older;
  76. Map<String,Cache>::Element *O=cached.front();
  77. older=O->get().time_loaded;
  78. Map<String,Cache>::Element *I=O;
  79. while(I) {
  80. if (I->get().time_loaded<older) {
  81. older = I->get().time_loaded;
  82. O=I;
  83. }
  84. I=I->next();
  85. }
  86. if (O!=E) {//should never heppane..
  87. cached.erase(O);
  88. }
  89. }
  90. return E->get().cache;
  91. }
  92. EditorScriptCodeCompletionCache() {
  93. max_cache_size=128;
  94. max_time_cache=5*60*1000; //minutes, five
  95. }
  96. };
  97. #define SORT_SCRIPT_LIST
  98. void ScriptEditorQuickOpen::popup(const Vector<String>& p_functions, bool p_dontclear) {
  99. popup_centered_ratio(0.6);
  100. if (p_dontclear)
  101. search_box->select_all();
  102. else
  103. search_box->clear();
  104. search_box->grab_focus();
  105. functions=p_functions;
  106. _update_search();
  107. }
  108. void ScriptEditorQuickOpen::_text_changed(const String& p_newtext) {
  109. _update_search();
  110. }
  111. void ScriptEditorQuickOpen::_sbox_input(const InputEvent& p_ie) {
  112. if (p_ie.type==InputEvent::KEY && (
  113. p_ie.key.scancode == KEY_UP ||
  114. p_ie.key.scancode == KEY_DOWN ||
  115. p_ie.key.scancode == KEY_PAGEUP ||
  116. p_ie.key.scancode == KEY_PAGEDOWN ) ) {
  117. search_options->call("_input_event",p_ie);
  118. search_box->accept_event();
  119. }
  120. }
  121. void ScriptEditorQuickOpen::_update_search() {
  122. search_options->clear();
  123. TreeItem *root = search_options->create_item();
  124. for(int i=0;i<functions.size();i++) {
  125. String file = functions[i];
  126. if ((search_box->get_text()=="" || file.findn(search_box->get_text())!=-1)) {
  127. TreeItem *ti = search_options->create_item(root);
  128. ti->set_text(0,file);
  129. if (root->get_children()==ti)
  130. ti->select(0);
  131. }
  132. }
  133. get_ok()->set_disabled(root->get_children()==NULL);
  134. }
  135. void ScriptEditorQuickOpen::_confirmed() {
  136. TreeItem *ti = search_options->get_selected();
  137. if (!ti)
  138. return;
  139. int line = ti->get_text(0).get_slice(":",1).to_int();
  140. emit_signal("goto_line",line-1);
  141. hide();
  142. }
  143. void ScriptEditorQuickOpen::_notification(int p_what) {
  144. if (p_what==NOTIFICATION_ENTER_TREE) {
  145. connect("confirmed",this,"_confirmed");
  146. }
  147. }
  148. void ScriptEditorQuickOpen::_bind_methods() {
  149. ObjectTypeDB::bind_method(_MD("_text_changed"),&ScriptEditorQuickOpen::_text_changed);
  150. ObjectTypeDB::bind_method(_MD("_confirmed"),&ScriptEditorQuickOpen::_confirmed);
  151. ObjectTypeDB::bind_method(_MD("_sbox_input"),&ScriptEditorQuickOpen::_sbox_input);
  152. ADD_SIGNAL(MethodInfo("goto_line",PropertyInfo(Variant::INT,"line")));
  153. }
  154. ScriptEditorQuickOpen::ScriptEditorQuickOpen() {
  155. VBoxContainer *vbc = memnew( VBoxContainer );
  156. add_child(vbc);
  157. set_child_rect(vbc);
  158. search_box = memnew( LineEdit );
  159. vbc->add_margin_child("Search:",search_box);
  160. search_box->connect("text_changed",this,"_text_changed");
  161. search_box->connect("input_event",this,"_sbox_input");
  162. search_options = memnew( Tree );
  163. vbc->add_margin_child("Matches:",search_options,true);
  164. get_ok()->set_text("Open");
  165. get_ok()->set_disabled(true);
  166. register_text_enter(search_box);
  167. set_hide_on_ok(false);
  168. search_options->connect("item_activated",this,"_confirmed");
  169. search_options->set_hide_root(true);
  170. }
  171. /////////////////////////////////
  172. ScriptEditor *ScriptEditor::script_editor=NULL;
  173. Vector<String> ScriptTextEditor::get_functions() {
  174. String errortxt;
  175. int line=-1,col;
  176. TextEdit *te=get_text_edit();
  177. String text = te->get_text();
  178. List<String> fnc;
  179. if (script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) {
  180. //if valid rewrite functions to latest
  181. functions.clear();
  182. for (List<String>::Element *E=fnc.front();E;E=E->next()) {
  183. functions.push_back(E->get());
  184. }
  185. }
  186. return functions;
  187. }
  188. void ScriptTextEditor::apply_code() {
  189. if (script.is_null())
  190. return;
  191. // print_line("applying code");
  192. script->set_source_code(get_text_edit()->get_text());
  193. script->update_exports();
  194. }
  195. Ref<Script> ScriptTextEditor::get_edited_script() const {
  196. return script;
  197. }
  198. void ScriptTextEditor::_load_theme_settings() {
  199. get_text_edit()->clear_colors();
  200. /* keyword color */
  201. get_text_edit()->set_custom_bg_color(EDITOR_DEF("text_editor/background_color",Color(0,0,0,0)));
  202. get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
  203. get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
  204. get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));
  205. get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2)));
  206. get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15)));
  207. Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));
  208. get_text_edit()->set_syntax_coloring(true);
  209. List<String> keywords;
  210. script->get_language()->get_reserved_words(&keywords);
  211. for(List<String>::Element *E=keywords.front();E;E=E->next()) {
  212. get_text_edit()->add_keyword_color(E->get(),keyword_color);
  213. }
  214. //colorize core types
  215. Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
  216. get_text_edit()->add_keyword_color("Vector2",basetype_color);
  217. get_text_edit()->add_keyword_color("Vector3",basetype_color);
  218. get_text_edit()->add_keyword_color("Plane",basetype_color);
  219. get_text_edit()->add_keyword_color("Quat",basetype_color);
  220. get_text_edit()->add_keyword_color("AABB",basetype_color);
  221. get_text_edit()->add_keyword_color("Matrix3",basetype_color);
  222. get_text_edit()->add_keyword_color("Transform",basetype_color);
  223. get_text_edit()->add_keyword_color("Color",basetype_color);
  224. get_text_edit()->add_keyword_color("Image",basetype_color);
  225. get_text_edit()->add_keyword_color("InputEvent",basetype_color);
  226. get_text_edit()->add_keyword_color("Rect2",basetype_color);
  227. get_text_edit()->add_keyword_color("NodePath",basetype_color);
  228. //colorize engine types
  229. Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4));
  230. List<StringName> types;
  231. ObjectTypeDB::get_type_list(&types);
  232. for(List<StringName>::Element *E=types.front();E;E=E->next()) {
  233. String n = E->get();
  234. if (n.begins_with("_"))
  235. n = n.substr(1, n.length());
  236. get_text_edit()->add_keyword_color(n,type_color);
  237. }
  238. //colorize comments
  239. Color comment_color = EDITOR_DEF("text_editor/comment_color",Color::hex(0x797e7eff));
  240. List<String> comments;
  241. script->get_language()->get_comment_delimiters(&comments);
  242. for(List<String>::Element *E=comments.front();E;E=E->next()) {
  243. String comment = E->get();
  244. String beg = comment.get_slice(" ",0);
  245. String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String();
  246. get_text_edit()->add_color_region(beg,end,comment_color,end=="");
  247. }
  248. //colorize strings
  249. Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
  250. List<String> strings;
  251. script->get_language()->get_string_delimiters(&strings);
  252. for (List<String>::Element *E=strings.front();E;E=E->next()) {
  253. String string = E->get();
  254. String beg = string.get_slice(" ",0);
  255. String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
  256. get_text_edit()->add_color_region(beg,end,string_color,end=="");
  257. }
  258. //colorize symbols
  259. Color symbol_color= EDITOR_DEF("text_editor/symbol_color",Color::hex(0x005291ff));
  260. get_text_edit()->set_symbol_color(symbol_color);
  261. }
  262. void ScriptTextEditor::reload_text() {
  263. ERR_FAIL_COND(script.is_null()) ;
  264. TextEdit *te = get_text_edit();
  265. int column = te->cursor_get_column();
  266. int row = te->cursor_get_line();
  267. int h = te->get_h_scroll();
  268. int v = te->get_v_scroll();
  269. te->set_text(script->get_source_code());
  270. te->clear_undo_history();
  271. te->cursor_set_line(row);
  272. te->cursor_set_column(column);
  273. te->set_h_scroll(h);
  274. te->set_v_scroll(v);
  275. te->tag_saved_version();
  276. _line_col_changed();
  277. }
  278. void ScriptTextEditor::_notification(int p_what) {
  279. if (p_what==NOTIFICATION_READY) {
  280. //emit_signal("name_changed");
  281. }
  282. }
  283. bool ScriptTextEditor::is_unsaved() {
  284. return get_text_edit()->get_version()!=get_text_edit()->get_saved_version();
  285. }
  286. String ScriptTextEditor::get_name() {
  287. String name;
  288. if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
  289. name=script->get_path().get_file();
  290. if (get_text_edit()->get_version()!=get_text_edit()->get_saved_version()) {
  291. name+="(*)";
  292. }
  293. } else if (script->get_name()!="")
  294. name=script->get_name();
  295. else
  296. name=script->get_type()+"("+itos(script->get_instance_ID())+")";
  297. return name;
  298. }
  299. Ref<Texture> ScriptTextEditor::get_icon() {
  300. if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
  301. return get_parent_control()->get_icon(script->get_type(),"EditorIcons");
  302. }
  303. return Ref<Texture>();
  304. }
  305. void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
  306. ERR_FAIL_COND(!script.is_null());
  307. script=p_script;
  308. _load_theme_settings();
  309. get_text_edit()->set_text(script->get_source_code());
  310. get_text_edit()->clear_undo_history();
  311. get_text_edit()->tag_saved_version();
  312. emit_signal("name_changed");
  313. _line_col_changed();
  314. }
  315. void ScriptTextEditor::_validate_script() {
  316. String errortxt;
  317. int line=-1,col;
  318. TextEdit *te=get_text_edit();
  319. String text = te->get_text();
  320. List<String> fnc;
  321. if (!script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) {
  322. String error_text="error("+itos(line)+","+itos(col)+"): "+errortxt;
  323. set_error(error_text);
  324. } else {
  325. set_error("");
  326. line=-1;
  327. if (!script->is_tool()) {
  328. script->set_source_code(text);
  329. script->update_exports();
  330. //script->reload(); //will update all the variables in property editors
  331. }
  332. functions.clear();
  333. for (List<String>::Element *E=fnc.front();E;E=E->next()) {
  334. functions.push_back(E->get());
  335. }
  336. }
  337. line--;
  338. for(int i=0;i<te->get_line_count();i++) {
  339. te->set_line_as_marked(i,line==i);
  340. }
  341. emit_signal("name_changed");
  342. }
  343. static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Script>& p_script) {
  344. if (p_current->get_owner()!=p_base && p_base!=p_current)
  345. return NULL;
  346. Ref<Script> c = p_current->get_script();
  347. if (c==p_script)
  348. return p_current;
  349. for(int i=0;i<p_current->get_child_count();i++) {
  350. Node *found = _find_node_for_script(p_base,p_current->get_child(i),p_script);
  351. if (found)
  352. return found;
  353. }
  354. return NULL;
  355. }
  356. static void _find_changed_scripts_for_external_editor(Node* p_base, Node*p_current, Set<Ref<Script> > &r_scripts) {
  357. if (p_current->get_owner()!=p_base && p_base!=p_current)
  358. return;
  359. Ref<Script> c = p_current->get_script();
  360. if (c.is_valid())
  361. r_scripts.insert(c);
  362. for(int i=0;i<p_current->get_child_count();i++) {
  363. _find_changed_scripts_for_external_editor(p_base,p_current->get_child(i),r_scripts);
  364. }
  365. }
  366. void ScriptEditor::_update_modified_scripts_for_external_editor() {
  367. if (!bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor")))
  368. return;
  369. Set<Ref<Script> > scripts;
  370. Node *base = get_tree()->get_edited_scene_root();
  371. if (base) {
  372. _find_changed_scripts_for_external_editor(base,base,scripts);
  373. }
  374. for (Set<Ref<Script> >::Element *E=scripts.front();E;E=E->next()) {
  375. Ref<Script> script = E->get();
  376. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) {
  377. continue; //internal script, who cares, though weird
  378. }
  379. uint64_t last_date = script->get_last_modified_time();
  380. uint64_t date = FileAccess::get_modified_time(script->get_path());
  381. if (last_date!=date) {
  382. Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_type(),true);
  383. ERR_CONTINUE(!rel_script.is_valid());
  384. script->set_source_code( rel_script->get_source_code() );
  385. script->set_last_modified_time( rel_script->get_last_modified_time() );
  386. script->update_exports();
  387. }
  388. }
  389. }
  390. void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) {
  391. Node *base = get_tree()->get_edited_scene_root();
  392. if (base) {
  393. base = _find_node_for_script(base,base,script);
  394. }
  395. String hint;
  396. Error err = script->get_language()->complete_code(p_code,script->get_path().get_base_dir(),base,r_options,hint);
  397. if (hint!="") {
  398. get_text_edit()->set_code_hint(hint);
  399. print_line("hint: "+hint.replace(String::chr(0xFFFF),"|"));
  400. }
  401. }
  402. void ScriptTextEditor::_bind_methods() {
  403. ADD_SIGNAL(MethodInfo("name_changed"));
  404. }
  405. ScriptTextEditor::ScriptTextEditor() {
  406. get_text_edit()->set_draw_tabs(true);
  407. }
  408. /*** SCRIPT EDITOR ******/
  409. String ScriptEditor::_get_debug_tooltip(const String&p_text,Node *_ste) {
  410. ScriptTextEditor *ste=_ste->cast_to<ScriptTextEditor>();
  411. String val = debugger->get_var_value(p_text);
  412. if (val!=String()) {
  413. return p_text+": "+val;
  414. } else {
  415. return String();
  416. }
  417. }
  418. void ScriptEditor::_breaked(bool p_breaked,bool p_can_debug) {
  419. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), !(p_breaked && p_can_debug));
  420. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), !(p_breaked && p_can_debug) );
  421. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), p_breaked );
  422. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), !p_breaked );
  423. }
  424. void ScriptEditor::_show_debugger(bool p_show) {
  425. debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW), p_show);
  426. }
  427. void ScriptEditor::_script_created(Ref<Script> p_script) {
  428. editor->push_item(p_script.operator->());
  429. }
  430. void ScriptEditor::_goto_script_line2(int p_line) {
  431. int selected = tab_container->get_current_tab();
  432. if (selected<0 || selected>=tab_container->get_child_count())
  433. return;
  434. ScriptTextEditor *current = tab_container->get_child(selected)->cast_to<ScriptTextEditor>();
  435. if (!current)
  436. return;
  437. current->get_text_edit()->cursor_set_line(p_line);
  438. }
  439. void ScriptEditor::_goto_script_line(REF p_script,int p_line) {
  440. editor->push_item(p_script.ptr());
  441. _goto_script_line2(p_line);
  442. }
  443. void ScriptEditor::_update_history_arrows() {
  444. script_back->set_disabled( history_pos<=0 );
  445. script_forward->set_disabled( history_pos>=history.size()-1 );
  446. }
  447. void ScriptEditor::_go_to_tab(int p_idx) {
  448. Node *cn = tab_container->get_child(p_idx);
  449. if (!cn)
  450. return;
  451. Control *c = cn->cast_to<Control>();
  452. if (!c)
  453. return;
  454. if (history_pos>=0 && history_pos<history.size() && history[history_pos].control==tab_container->get_current_tab_control()) {
  455. Node *n = tab_container->get_current_tab_control();
  456. if (n->cast_to<ScriptTextEditor>()) {
  457. history[history_pos].scroll_pos=n->cast_to<ScriptTextEditor>()->get_text_edit()->get_v_scroll();
  458. history[history_pos].cursor_column=n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_get_column();
  459. history[history_pos].cursor_row=n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_get_line();
  460. }
  461. if (n->cast_to<EditorHelp>()) {
  462. history[history_pos].scroll_pos=n->cast_to<EditorHelp>()->get_scroll();
  463. }
  464. }
  465. history.resize(history_pos+1);
  466. ScriptHistory sh;
  467. sh.control=c;
  468. sh.scroll_pos=0;
  469. history.push_back(sh);
  470. history_pos++;
  471. tab_container->set_current_tab(p_idx);
  472. c = tab_container->get_current_tab_control();
  473. if (c->cast_to<ScriptTextEditor>()) {
  474. script_name_label->set_text(c->cast_to<ScriptTextEditor>()->get_name());
  475. script_icon->set_texture(c->cast_to<ScriptTextEditor>()->get_icon());
  476. if (is_visible())
  477. c->cast_to<ScriptTextEditor>()->get_text_edit()->grab_focus();
  478. }
  479. if (c->cast_to<EditorHelp>()) {
  480. script_name_label->set_text(c->cast_to<EditorHelp>()->get_class_name());
  481. script_icon->set_texture(get_icon("Help","EditorIcons"));
  482. if (is_visible())
  483. c->cast_to<EditorHelp>()->set_focused();
  484. }
  485. c->set_meta("__editor_pass",++edit_pass);
  486. _update_history_arrows();
  487. _update_script_colors();
  488. }
  489. void ScriptEditor::_close_current_tab() {
  490. int selected = tab_container->get_current_tab();
  491. if (selected<0 || selected>=tab_container->get_child_count())
  492. return;
  493. Node *tselected = tab_container->get_child(selected);
  494. ScriptTextEditor *current = tab_container->get_child(selected)->cast_to<ScriptTextEditor>();
  495. if (current) {
  496. apply_scripts();
  497. }
  498. //remove from history
  499. history.resize(history_pos+1);
  500. for(int i=0;i<history.size();i++) {
  501. if (history[i].control==tselected) {
  502. history.remove(i);
  503. i--;
  504. history_pos--;
  505. }
  506. }
  507. if (history_pos>=history.size()) {
  508. history_pos=history.size()-1;
  509. }
  510. int idx = tab_container->get_current_tab();
  511. memdelete(tselected);
  512. if (idx>=tab_container->get_child_count())
  513. idx=tab_container->get_child_count()-1;
  514. if (idx>=0) {
  515. if (history_pos>=0) {
  516. idx = history[history_pos].control->get_index();
  517. }
  518. tab_container->set_current_tab(idx);
  519. //script_list->select(idx);
  520. }
  521. _update_history_arrows();
  522. _update_script_names();
  523. EditorNode::get_singleton()->save_layout();
  524. }
  525. void ScriptEditor::_resave_scripts(const String& p_str) {
  526. apply_scripts();
  527. for(int i=0;i<tab_container->get_child_count();i++) {
  528. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  529. if (!ste)
  530. continue;
  531. Ref<Script> script = ste->get_edited_script();
  532. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1)
  533. continue; //internal script, who cares
  534. editor->save_resource(script);
  535. ste->get_text_edit()->tag_saved_version();
  536. }
  537. disk_changed->hide();
  538. }
  539. void ScriptEditor::_reload_scripts(){
  540. for(int i=0;i<tab_container->get_child_count();i++) {
  541. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  542. if (!ste) {
  543. continue;
  544. }
  545. Ref<Script> script = ste->get_edited_script();
  546. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) {
  547. continue; //internal script, who cares
  548. }
  549. Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_type(),true);
  550. ERR_CONTINUE(!rel_script.is_valid());
  551. script->set_source_code( rel_script->get_source_code() );
  552. script->set_last_modified_time( rel_script->get_last_modified_time() );
  553. script->reload();
  554. ste->reload_text();
  555. }
  556. disk_changed->hide();
  557. _update_script_names();
  558. }
  559. void ScriptEditor::_res_saved_callback(const Ref<Resource>& p_res) {
  560. for(int i=0;i<tab_container->get_child_count();i++) {
  561. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  562. if (!ste) {
  563. continue;
  564. }
  565. Ref<Script> script = ste->get_edited_script();
  566. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) {
  567. continue; //internal script, who cares
  568. }
  569. if (script==p_res) {
  570. ste->get_text_edit()->tag_saved_version();
  571. }
  572. }
  573. _update_script_names();
  574. }
  575. bool ScriptEditor::_test_script_times_on_disk() {
  576. disk_changed_list->clear();
  577. TreeItem *r = disk_changed_list->create_item();
  578. disk_changed_list->set_hide_root(true);
  579. bool need_ask=false;
  580. bool need_reload=false;
  581. bool use_autoreload=bool(EDITOR_DEF("text_editor/auto_reload_scripts_on_external_change",false));
  582. for(int i=0;i<tab_container->get_child_count();i++) {
  583. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  584. if (ste) {
  585. Ref<Script> script = ste->get_edited_script();
  586. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1)
  587. continue; //internal script, who cares
  588. uint64_t last_date = script->get_last_modified_time();
  589. uint64_t date = FileAccess::get_modified_time(script->get_path());
  590. //printf("last date: %lli vs date: %lli\n",last_date,date);
  591. if (last_date!=date) {
  592. TreeItem *ti = disk_changed_list->create_item(r);
  593. ti->set_text(0,script->get_path().get_file());
  594. if (!use_autoreload || ste->is_unsaved()) {
  595. need_ask=true;
  596. }
  597. need_reload=true;
  598. //r->set_metadata(0,);
  599. }
  600. }
  601. }
  602. if (need_reload) {
  603. if (!need_ask) {
  604. script_editor->_reload_scripts();
  605. need_reload=false;
  606. } else {
  607. disk_changed->call_deferred("popup_centered_ratio",0.5);
  608. }
  609. }
  610. return need_reload;
  611. }
  612. void ScriptEditor::swap_lines(TextEdit *tx, int line1, int line2)
  613. {
  614. String tmp = tx->get_line(line1);
  615. String tmp2 = tx->get_line(line2);
  616. tx->set_line(line2, tmp);
  617. tx->set_line(line1, tmp2);
  618. tx->cursor_set_line(line2);
  619. }
  620. void ScriptEditor::_menu_option(int p_option) {
  621. switch(p_option) {
  622. case FILE_NEW: {
  623. script_create_dialog->config("Node", ".gd");
  624. script_create_dialog->popup_centered(Size2(300, 300));
  625. } break;
  626. case FILE_OPEN: {
  627. editor->open_resource("Script");
  628. return;
  629. } break;
  630. case FILE_SAVE_ALL: {
  631. if (!_test_script_times_on_disk())
  632. return;
  633. for(int i=0;i<tab_container->get_child_count();i++) {
  634. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  635. if (!ste)
  636. continue;
  637. Ref<Script> script = ste->get_edited_script();
  638. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1)
  639. continue; //internal script, who cares
  640. editor->save_resource( script );
  641. }
  642. } break;
  643. case SEARCH_HELP: {
  644. help_search_dialog->popup();
  645. } break;
  646. case SEARCH_CLASSES: {
  647. String current;
  648. if (tab_container->get_tab_count()>0) {
  649. EditorHelp *eh = tab_container->get_child( tab_container->get_current_tab() )->cast_to<EditorHelp>();
  650. if (eh) {
  651. current=eh->get_class_name();
  652. }
  653. }
  654. help_index->popup_centered_ratio(0.6);
  655. if (current!="") {
  656. help_index->call_deferred("select_class",current);
  657. }
  658. } break;
  659. case SEARCH_WEBSITE: {
  660. OS::get_singleton()->shell_open("http://www.godotengine.org/projects/godot-engine/wiki/Documentation#Tutorials");
  661. } break;
  662. case WINDOW_NEXT: {
  663. _history_forward();
  664. } break;
  665. case WINDOW_PREV: {
  666. _history_back();
  667. } break;
  668. case DEBUG_SHOW: {
  669. if (debugger) {
  670. bool visible = debug_menu->get_popup()->is_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW) );
  671. debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW), !visible);
  672. if (visible)
  673. debugger->hide();
  674. else
  675. debugger->show();
  676. }
  677. } break;
  678. case DEBUG_SHOW_KEEP_OPEN: {
  679. bool visible = debug_menu->get_popup()->is_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN) );
  680. if (debugger)
  681. debugger->set_hide_on_stop(visible);
  682. debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN), !visible);
  683. } break;
  684. }
  685. int selected = tab_container->get_current_tab();
  686. if (selected<0 || selected>=tab_container->get_child_count())
  687. return;
  688. ScriptTextEditor *current = tab_container->get_child(selected)->cast_to<ScriptTextEditor>();
  689. if (current) {
  690. switch(p_option) {
  691. case FILE_NEW: {
  692. script_create_dialog->config("Node", ".gd");
  693. script_create_dialog->popup_centered(Size2(300, 300));
  694. } break;
  695. case FILE_SAVE: {
  696. if (!_test_script_times_on_disk())
  697. return;
  698. editor->save_resource( current->get_edited_script() );
  699. } break;
  700. case FILE_SAVE_AS: {
  701. editor->save_resource_as( current->get_edited_script() );
  702. } break;
  703. case EDIT_UNDO: {
  704. current->get_text_edit()->undo();
  705. current->get_text_edit()->call_deferred("grab_focus");
  706. } break;
  707. case EDIT_REDO: {
  708. current->get_text_edit()->redo();
  709. current->get_text_edit()->call_deferred("grab_focus");
  710. } break;
  711. case EDIT_CUT: {
  712. current->get_text_edit()->cut();
  713. current->get_text_edit()->call_deferred("grab_focus");
  714. } break;
  715. case EDIT_COPY: {
  716. current->get_text_edit()->copy();
  717. current->get_text_edit()->call_deferred("grab_focus");
  718. } break;
  719. case EDIT_PASTE: {
  720. current->get_text_edit()->paste();
  721. current->get_text_edit()->call_deferred("grab_focus");
  722. } break;
  723. case EDIT_SELECT_ALL: {
  724. current->get_text_edit()->select_all();
  725. current->get_text_edit()->call_deferred("grab_focus");
  726. } break;
  727. case EDIT_MOVE_LINE_UP: {
  728. TextEdit *tx = current->get_text_edit();
  729. Ref<Script> scr = current->get_edited_script();
  730. if (scr.is_null())
  731. return;
  732. if (tx->is_selection_active())
  733. {
  734. int from_line = tx->get_selection_from_line();
  735. int from_col = tx->get_selection_from_column();
  736. int to_line = tx->get_selection_to_line();
  737. int to_column = tx->get_selection_to_column();
  738. for (int i = from_line; i <= to_line; i++)
  739. {
  740. int line_id = i;
  741. int next_id = i - 1;
  742. if (line_id == 0 || next_id < 0)
  743. return;
  744. swap_lines(tx, line_id, next_id);
  745. }
  746. int from_line_up = from_line > 0 ? from_line-1 : from_line;
  747. int to_line_up = to_line > 0 ? to_line-1 : to_line;
  748. tx->select(from_line_up, from_col, to_line_up, to_column);
  749. }
  750. else
  751. {
  752. int line_id = tx->cursor_get_line();
  753. int next_id = line_id - 1;
  754. if (line_id == 0 || next_id < 0)
  755. return;
  756. swap_lines(tx, line_id, next_id);
  757. }
  758. tx->update();
  759. } break;
  760. case EDIT_MOVE_LINE_DOWN: {
  761. TextEdit *tx = current->get_text_edit();
  762. Ref<Script> scr = current->get_edited_script();
  763. if (scr.is_null())
  764. return;
  765. if (tx->is_selection_active())
  766. {
  767. int from_line = tx->get_selection_from_line();
  768. int from_col = tx->get_selection_from_column();
  769. int to_line = tx->get_selection_to_line();
  770. int to_column = tx->get_selection_to_column();
  771. for (int i = to_line; i >= from_line; i--)
  772. {
  773. int line_id = i;
  774. int next_id = i + 1;
  775. if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count())
  776. return;
  777. swap_lines(tx, line_id, next_id);
  778. }
  779. int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line;
  780. int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line;
  781. tx->select(from_line_down, from_col, to_line_down, to_column);
  782. }
  783. else
  784. {
  785. int line_id = tx->cursor_get_line();
  786. int next_id = line_id + 1;
  787. if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count())
  788. return;
  789. swap_lines(tx, line_id, next_id);
  790. }
  791. tx->update();
  792. } break;
  793. case EDIT_INDENT_LEFT: {
  794. TextEdit *tx = current->get_text_edit();
  795. Ref<Script> scr = current->get_edited_script();
  796. if (scr.is_null())
  797. return;
  798. if (tx->is_selection_active())
  799. {
  800. int begin = tx->get_selection_from_line();
  801. int end = tx->get_selection_to_line();
  802. for (int i = begin; i <= end; i++)
  803. {
  804. String line_text = tx->get_line(i);
  805. // begins with tab
  806. if (line_text.begins_with("\t"))
  807. {
  808. line_text = line_text.substr(1, line_text.length());
  809. tx->set_line(i, line_text);
  810. }
  811. // begins with 4 spaces
  812. else if (line_text.begins_with(" "))
  813. {
  814. line_text = line_text.substr(4, line_text.length());
  815. tx->set_line(i, line_text);
  816. }
  817. }
  818. }
  819. else
  820. {
  821. int begin = tx->cursor_get_line();
  822. String line_text = tx->get_line(begin);
  823. // begins with tab
  824. if (line_text.begins_with("\t"))
  825. {
  826. line_text = line_text.substr(1, line_text.length());
  827. tx->set_line(begin, line_text);
  828. }
  829. // begins with 4 spaces
  830. else if (line_text.begins_with(" "))
  831. {
  832. line_text = line_text.substr(4, line_text.length());
  833. tx->set_line(begin, line_text);
  834. }
  835. }
  836. tx->update();
  837. //tx->deselect();
  838. } break;
  839. case EDIT_INDENT_RIGHT: {
  840. TextEdit *tx = current->get_text_edit();
  841. Ref<Script> scr = current->get_edited_script();
  842. if (scr.is_null())
  843. return;
  844. if (tx->is_selection_active())
  845. {
  846. int begin = tx->get_selection_from_line();
  847. int end = tx->get_selection_to_line();
  848. for (int i = begin; i <= end; i++)
  849. {
  850. String line_text = tx->get_line(i);
  851. line_text = '\t' + line_text;
  852. tx->set_line(i, line_text);
  853. }
  854. }
  855. else
  856. {
  857. int begin = tx->cursor_get_line();
  858. String line_text = tx->get_line(begin);
  859. line_text = '\t' + line_text;
  860. tx->set_line(begin, line_text);
  861. }
  862. tx->update();
  863. //tx->deselect();
  864. } break;
  865. case EDIT_CLONE_DOWN: {
  866. TextEdit *tx = current->get_text_edit();
  867. Ref<Script> scr = current->get_edited_script();
  868. if (scr.is_null())
  869. return;
  870. int line = tx->cursor_get_line();
  871. int next_line = line + 1;
  872. int column = tx->cursor_get_column();
  873. if (line >= tx->get_line_count() - 1)
  874. tx->set_line(line, tx->get_line(line) + "\n");
  875. String line_clone = tx->get_line(line);
  876. tx->insert_at(line_clone, next_line);
  877. tx->cursor_set_column(column);
  878. tx->update();
  879. } break;
  880. case EDIT_TOGGLE_COMMENT: {
  881. TextEdit *tx = current->get_text_edit();
  882. Ref<Script> scr = current->get_edited_script();
  883. if (scr.is_null())
  884. return;
  885. if (tx->is_selection_active())
  886. {
  887. int begin = tx->get_selection_from_line();
  888. int end = tx->get_selection_to_line();
  889. for (int i = begin; i <= end; i++)
  890. {
  891. String line_text = tx->get_line(i);
  892. if (line_text.begins_with("#"))
  893. line_text = line_text.substr(1, line_text.length());
  894. else
  895. line_text = "#" + line_text;
  896. tx->set_line(i, line_text);
  897. }
  898. }
  899. else
  900. {
  901. int begin = tx->cursor_get_line();
  902. String line_text = tx->get_line(begin);
  903. if (line_text.begins_with("#"))
  904. line_text = line_text.substr(1, line_text.length());
  905. else
  906. line_text = "#" + line_text;
  907. tx->set_line(begin, line_text);
  908. }
  909. tx->update();
  910. //tx->deselect();
  911. } break;
  912. case EDIT_COMPLETE: {
  913. current->get_text_edit()->query_code_comple();
  914. } break;
  915. case EDIT_AUTO_INDENT: {
  916. TextEdit *te = current->get_text_edit();
  917. String text = te->get_text();
  918. Ref<Script> scr = current->get_edited_script();
  919. if (scr.is_null())
  920. return;
  921. int begin,end;
  922. if (te->is_selection_active()) {
  923. begin=te->get_selection_from_line();
  924. end=te->get_selection_to_line();
  925. } else {
  926. begin=0;
  927. end=te->get_line_count()-1;
  928. }
  929. scr->get_language()->auto_indent_code(text,begin,end);
  930. te->set_text(text);
  931. } break;
  932. case SEARCH_FIND: {
  933. find_replace_dialog->set_text_edit(current->get_text_edit());
  934. find_replace_dialog->popup_search();
  935. } break;
  936. case SEARCH_FIND_NEXT: {
  937. find_replace_dialog->set_text_edit(current->get_text_edit());
  938. find_replace_dialog->search_next();
  939. } break;
  940. case SEARCH_REPLACE: {
  941. find_replace_dialog->set_text_edit(current->get_text_edit());
  942. find_replace_dialog->popup_replace();
  943. } break;
  944. case SEARCH_LOCATE_FUNCTION: {
  945. if (!current)
  946. return;
  947. quick_open->popup(current->get_functions());
  948. } break;
  949. case SEARCH_GOTO_LINE: {
  950. goto_line_dialog->popup_find_line(current->get_text_edit());
  951. } break;
  952. case DEBUG_TOGGLE_BREAKPOINT: {
  953. int line=current->get_text_edit()->cursor_get_line();
  954. bool dobreak = !current->get_text_edit()->is_line_set_as_breakpoint(line);
  955. current->get_text_edit()->set_line_as_breakpoint(line,dobreak);
  956. get_debugger()->set_breakpoint(current->get_edited_script()->get_path(),line+1,dobreak);
  957. } break;
  958. case DEBUG_NEXT: {
  959. if (debugger)
  960. debugger->debug_next();
  961. } break;
  962. case DEBUG_STEP: {
  963. if (debugger)
  964. debugger->debug_step();
  965. } break;
  966. case DEBUG_BREAK: {
  967. if (debugger)
  968. debugger->debug_break();
  969. } break;
  970. case DEBUG_CONTINUE: {
  971. if (debugger)
  972. debugger->debug_continue();
  973. } break;
  974. case HELP_CONTEXTUAL: {
  975. String text = current->get_text_edit()->get_selection_text();
  976. if (text == "")
  977. text = current->get_text_edit()->get_word_under_cursor();
  978. if (text != "")
  979. help_search_dialog->popup(text);
  980. } break;
  981. case FILE_CLOSE: {
  982. if (current->get_text_edit()->get_version()!=current->get_text_edit()->get_saved_version()) {
  983. erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\"");
  984. erase_tab_confirm->popup_centered_minsize();
  985. } else {
  986. _close_current_tab();
  987. }
  988. } break;
  989. case WINDOW_MOVE_LEFT: {
  990. if (tab_container->get_current_tab()>0) {
  991. tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()-1);
  992. script_list->call_deferred("select",tab_container->get_current_tab()-1);
  993. tab_container->move_child(current,tab_container->get_current_tab()-1);
  994. _update_script_names();
  995. }
  996. } break;
  997. case WINDOW_MOVE_RIGHT: {
  998. if (tab_container->get_current_tab()<tab_container->get_child_count()-1) {
  999. tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()+1);
  1000. script_list->call_deferred("select",tab_container->get_current_tab()+1);
  1001. tab_container->move_child(current,tab_container->get_current_tab()+1);
  1002. _update_script_names();
  1003. }
  1004. } break;
  1005. default: {
  1006. if (p_option>=WINDOW_SELECT_BASE) {
  1007. tab_container->set_current_tab(p_option-WINDOW_SELECT_BASE);
  1008. script_list->select(p_option-WINDOW_SELECT_BASE);
  1009. }
  1010. }
  1011. }
  1012. }
  1013. EditorHelp *help = tab_container->get_child(selected)->cast_to<EditorHelp>();
  1014. if (help) {
  1015. switch(p_option) {
  1016. case SEARCH_FIND: {
  1017. help->popup_search();
  1018. } break;
  1019. case SEARCH_FIND_NEXT: {
  1020. help->search_again();
  1021. } break;
  1022. case FILE_CLOSE: {
  1023. _close_current_tab();
  1024. } break;
  1025. }
  1026. }
  1027. }
  1028. void ScriptEditor::_tab_changed(int p_which) {
  1029. ensure_select_current();
  1030. }
  1031. void ScriptEditor::_notification(int p_what) {
  1032. if (p_what==NOTIFICATION_ENTER_TREE) {
  1033. editor->connect("play_pressed",this,"_editor_play");
  1034. editor->connect("pause_pressed",this,"_editor_pause");
  1035. editor->connect("stop_pressed",this,"_editor_stop");
  1036. editor->connect("script_add_function_request",this,"_add_callback");
  1037. editor->connect("resource_saved",this,"_res_saved_callback");
  1038. script_list->connect("item_selected",this,"_script_selected");
  1039. script_split->connect("dragged",this,"_script_split_dragged");
  1040. autosave_timer->connect("timeout",this,"_autosave_scripts");
  1041. {
  1042. float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
  1043. if (autosave_time>0) {
  1044. autosave_timer->set_wait_time(autosave_time);
  1045. autosave_timer->start();
  1046. } else {
  1047. autosave_timer->stop();
  1048. }
  1049. }
  1050. EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
  1051. help_search->set_icon(get_icon("Help","EditorIcons"));
  1052. site_search->set_icon(get_icon("Godot","EditorIcons"));
  1053. class_search->set_icon(get_icon("ClassList","EditorIcons"));
  1054. script_forward->set_icon(get_icon("Forward","EditorIcons"));
  1055. script_back->set_icon(get_icon("Back","EditorIcons"));
  1056. }
  1057. if (p_what==NOTIFICATION_READY) {
  1058. get_tree()->connect("tree_changed",this,"_tree_changed");
  1059. editor->connect("request_help",this,"_request_help");
  1060. }
  1061. if (p_what==NOTIFICATION_EXIT_TREE) {
  1062. editor->disconnect("play_pressed",this,"_editor_play");
  1063. editor->disconnect("pause_pressed",this,"_editor_pause");
  1064. editor->disconnect("stop_pressed",this,"_editor_stop");
  1065. }
  1066. if (p_what==MainLoop::NOTIFICATION_WM_FOCUS_IN) {
  1067. _test_script_times_on_disk();
  1068. _update_modified_scripts_for_external_editor();
  1069. }
  1070. if (p_what==NOTIFICATION_PROCESS) {
  1071. }
  1072. }
  1073. void ScriptEditor::edited_scene_changed() {
  1074. _update_modified_scripts_for_external_editor();
  1075. }
  1076. static const Node * _find_node_with_script(const Node* p_node, const RefPtr & p_script) {
  1077. if (p_node->get_script()==p_script)
  1078. return p_node;
  1079. for(int i=0;i<p_node->get_child_count();i++) {
  1080. const Node *result = _find_node_with_script(p_node->get_child(i),p_script);
  1081. if (result)
  1082. return result;
  1083. }
  1084. return NULL;
  1085. }
  1086. Dictionary ScriptEditor::get_state() const {
  1087. // apply_scripts();
  1088. Dictionary state;
  1089. #if 0
  1090. Array paths;
  1091. int open=-1;
  1092. for(int i=0;i<tab_container->get_child_count();i++) {
  1093. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1094. if (!ste)
  1095. continue;
  1096. Ref<Script> script = ste->get_edited_script();
  1097. if (script->get_path()!="" && script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
  1098. paths.push_back(script->get_path());
  1099. } else {
  1100. const Node *owner = _find_node_with_script(get_tree()->get_root(),script.get_ref_ptr());
  1101. if (owner)
  1102. paths.push_back(owner->get_path());
  1103. }
  1104. if (i==tab_container->get_current_tab())
  1105. open=i;
  1106. }
  1107. if (paths.size())
  1108. state["sources"]=paths;
  1109. if (open!=-1)
  1110. state["current"]=open;
  1111. #endif
  1112. return state;
  1113. }
  1114. void ScriptEditor::set_state(const Dictionary& p_state) {
  1115. #if 0
  1116. print_line("attempt set state: "+String(Variant(p_state)));
  1117. if (!p_state.has("sources"))
  1118. return; //bleh
  1119. Array sources = p_state["sources"];
  1120. for(int i=0;i<sources.size();i++) {
  1121. Variant source=sources[i];
  1122. Ref<Script> script;
  1123. if (source.get_type()==Variant::NODE_PATH) {
  1124. Node *owner=get_tree()->get_root()->get_node(source);
  1125. if (!owner)
  1126. continue;
  1127. script = owner->get_script();
  1128. } else if (source.get_type()==Variant::STRING) {
  1129. script = ResourceLoader::load(source,"Script");
  1130. }
  1131. if (script.is_null()) //ah well..
  1132. continue;
  1133. editor->call("_resource_selected",script);
  1134. }
  1135. if (p_state.has("current")) {
  1136. tab_container->set_current_tab(p_state["current"]);
  1137. }
  1138. #endif
  1139. }
  1140. void ScriptEditor::clear() {
  1141. #if 0
  1142. List<ScriptTextEditor*> stes;
  1143. for(int i=0;i<tab_container->get_child_count();i++) {
  1144. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1145. if (!ste)
  1146. continue;
  1147. stes.push_back(ste);
  1148. }
  1149. while(stes.size()) {
  1150. memdelete(stes.front()->get());
  1151. stes.pop_front();
  1152. }
  1153. int idx = tab_container->get_current_tab();
  1154. if (idx>=tab_container->get_child_count())
  1155. idx=tab_container->get_child_count()-1;
  1156. if (idx>=0) {
  1157. tab_container->set_current_tab(idx);
  1158. script_list->select( script_list->find_metadata(idx) );
  1159. }
  1160. #endif
  1161. }
  1162. void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
  1163. for(int i=0;i<tab_container->get_child_count();i++) {
  1164. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1165. if (!ste)
  1166. continue;
  1167. List<int> bpoints;
  1168. ste->get_text_edit()->get_breakpoints(&bpoints);
  1169. Ref<Script> script = ste->get_edited_script();
  1170. String base = script->get_path();
  1171. ERR_CONTINUE( base.begins_with("local://") || base=="" );
  1172. for(List<int>::Element *E=bpoints.front();E;E=E->next()) {
  1173. p_breakpoints->push_back(base+":"+itos(E->get()+1));
  1174. }
  1175. }
  1176. }
  1177. void ScriptEditor::ensure_focus_current() {
  1178. if (!is_inside_tree())
  1179. return;
  1180. int cidx = tab_container->get_current_tab();
  1181. if (cidx<0 || cidx>=tab_container->get_tab_count());
  1182. Control *c = tab_container->get_child(cidx)->cast_to<Control>();
  1183. if (!c)
  1184. return;
  1185. ScriptTextEditor *ste = c->cast_to<ScriptTextEditor>();
  1186. if (!ste)
  1187. return;
  1188. ste->get_text_edit()->grab_focus();
  1189. }
  1190. void ScriptEditor::_script_selected(int p_idx) {
  1191. grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing
  1192. _go_to_tab(script_list->get_item_metadata(p_idx));
  1193. grab_focus_block=false;
  1194. }
  1195. void ScriptEditor::ensure_select_current() {
  1196. if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
  1197. Node *current = tab_container->get_child(tab_container->get_current_tab());
  1198. ScriptTextEditor *ste = current->cast_to<ScriptTextEditor>();
  1199. if (ste) {
  1200. Ref<Script> script = ste->get_edited_script();
  1201. if (!grab_focus_block && is_inside_tree())
  1202. ste->get_text_edit()->grab_focus();
  1203. edit_menu->show();
  1204. search_menu->show();
  1205. script_search_menu->hide();
  1206. }
  1207. EditorHelp *eh = current->cast_to<EditorHelp>();
  1208. if (eh) {
  1209. edit_menu->hide();
  1210. search_menu->hide();
  1211. script_search_menu->show();
  1212. }
  1213. }
  1214. }
  1215. void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> > &used) {
  1216. if (p_current!=p_base && p_current->get_owner()!=p_base)
  1217. return;
  1218. if (p_current->get_script_instance()) {
  1219. Ref<Script> scr = p_current->get_script();
  1220. if (scr.is_valid())
  1221. used.insert(scr);
  1222. }
  1223. for(int i=0;i<p_current->get_child_count();i++) {
  1224. _find_scripts(p_base,p_current->get_child(i),used);
  1225. }
  1226. }
  1227. struct _ScriptEditorItemData {
  1228. String name;
  1229. Ref<Texture> icon;
  1230. int index;
  1231. String tooltip;
  1232. bool used;
  1233. int category;
  1234. bool operator<(const _ScriptEditorItemData& id) const {
  1235. return category==id.category?name.nocasecmp_to(id.name)<0:category<id.category;
  1236. }
  1237. };
  1238. void ScriptEditor::_update_script_colors() {
  1239. bool enabled = EditorSettings::get_singleton()->get("text_editor/script_temperature_enabled");
  1240. if (!enabled)
  1241. return;
  1242. int hist_size = EditorSettings::get_singleton()->get("text_editor/script_temperature_history_size");
  1243. Color hot_color=EditorSettings::get_singleton()->get("text_editor/script_temperature_hot_color");
  1244. Color cold_color=EditorSettings::get_singleton()->get("text_editor/script_temperature_cold_color");
  1245. for(int i=0;i<script_list->get_item_count();i++) {
  1246. int c = script_list->get_item_metadata(i);
  1247. Node *n = tab_container->get_child(c);
  1248. if (!n)
  1249. continue;
  1250. script_list->set_item_custom_bg_color(i,Color(0,0,0,0));
  1251. if (!n->has_meta("__editor_pass")) {
  1252. continue;
  1253. }
  1254. int pass=n->get_meta("__editor_pass");
  1255. int h = edit_pass - pass;
  1256. if (h>hist_size) {
  1257. continue;
  1258. }
  1259. float v = Math::ease((edit_pass-pass)/float(hist_size),0.4);
  1260. script_list->set_item_custom_bg_color(i,hot_color.linear_interpolate(cold_color,v));
  1261. }
  1262. }
  1263. void ScriptEditor::_update_script_names() {
  1264. waiting_update_names=false;
  1265. Set<Ref<Script> > used;
  1266. Node* edited = EditorNode::get_singleton()->get_edited_scene();
  1267. if (edited) {
  1268. _find_scripts(edited,edited,used);
  1269. }
  1270. script_list->clear();
  1271. bool split_script_help = EditorSettings::get_singleton()->get("text_editor/group_help_pages");
  1272. Vector<_ScriptEditorItemData> sedata;
  1273. for(int i=0;i<tab_container->get_child_count();i++) {
  1274. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1275. if (ste) {
  1276. String name = ste->get_name();
  1277. Ref<Texture> icon = ste->get_icon();
  1278. String tooltip = ste->get_edited_script()->get_path();
  1279. _ScriptEditorItemData sd;
  1280. sd.icon=icon;
  1281. sd.name=name;
  1282. sd.tooltip=tooltip;
  1283. sd.index=i;
  1284. sd.used=used.has(ste->get_edited_script());
  1285. sd.category=0;
  1286. sedata.push_back(sd);
  1287. }
  1288. EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
  1289. if (eh) {
  1290. String name = eh->get_class_name();
  1291. Ref<Texture> icon = get_icon("Help","EditorIcons");
  1292. String tooltip = name+" Class Reference";
  1293. _ScriptEditorItemData sd;
  1294. sd.icon=icon;
  1295. sd.name=name;
  1296. sd.tooltip=tooltip;
  1297. sd.index=i;
  1298. sd.used=false;
  1299. sd.category=split_script_help?1:0;
  1300. sedata.push_back(sd);
  1301. }
  1302. }
  1303. sedata.sort();
  1304. for(int i=0;i<sedata.size();i++) {
  1305. script_list->add_item(sedata[i].name,sedata[i].icon);
  1306. int index = script_list->get_item_count()-1;
  1307. script_list->set_item_tooltip(index,sedata[i].tooltip);
  1308. script_list->set_item_metadata(index,sedata[i].index);
  1309. if (sedata[i].used) {
  1310. script_list->set_item_custom_bg_color(index,Color(88/255.0,88/255.0,60/255.0));
  1311. }
  1312. if (tab_container->get_current_tab()==sedata[i].index) {
  1313. script_list->select(index);
  1314. script_name_label->set_text(sedata[i].name);
  1315. script_icon->set_texture(sedata[i].icon);
  1316. }
  1317. }
  1318. _update_script_colors();
  1319. }
  1320. void ScriptEditor::edit(const Ref<Script>& p_script) {
  1321. if (p_script.is_null())
  1322. return;
  1323. // see if already has it
  1324. bool open_dominant = EditorSettings::get_singleton()->get("text_editor/open_dominant_script_on_scene_change");
  1325. if (p_script->get_path().is_resource_file() && bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor"))) {
  1326. String path = EditorSettings::get_singleton()->get("external_editor/exec_path");
  1327. String flags = EditorSettings::get_singleton()->get("external_editor/exec_flags");
  1328. List<String> args;
  1329. flags=flags.strip_edges();
  1330. if (flags!=String()) {
  1331. Vector<String> flagss = flags.split(" ",false);
  1332. for(int i=0;i<flagss.size();i++)
  1333. args.push_back(flagss[i]);
  1334. }
  1335. args.push_back(Globals::get_singleton()->globalize_path(p_script->get_path()));
  1336. Error err = OS::get_singleton()->execute(path,args,false);
  1337. if (err==OK)
  1338. return;
  1339. WARN_PRINT("Couldn't open external text editor, using internal");
  1340. }
  1341. for(int i=0;i<tab_container->get_child_count();i++) {
  1342. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1343. if (!ste)
  1344. continue;
  1345. if (ste->get_edited_script()==p_script) {
  1346. if (open_dominant || !EditorNode::get_singleton()->is_changing_scene()) {
  1347. if (tab_container->get_current_tab()!=i) {
  1348. _go_to_tab(i);
  1349. script_list->select( script_list->find_metadata(i) );
  1350. }
  1351. if (is_visible())
  1352. ste->get_text_edit()->grab_focus();
  1353. }
  1354. return;
  1355. }
  1356. }
  1357. // doesn't have it, make a new one
  1358. ScriptTextEditor *ste = memnew( ScriptTextEditor );
  1359. ste->set_edited_script(p_script);
  1360. ste->get_text_edit()->set_tooltip_request_func(this,"_get_debug_tooltip",ste);
  1361. ste->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
  1362. tab_container->add_child(ste);
  1363. _go_to_tab(tab_container->get_tab_count()-1);
  1364. _update_script_names();
  1365. ste->connect("name_changed",this,"_update_script_names");
  1366. if (!restoring_layout) {
  1367. EditorNode::get_singleton()->save_layout();
  1368. }
  1369. }
  1370. void ScriptEditor::save_external_data() {
  1371. apply_scripts();
  1372. for(int i=0;i<tab_container->get_child_count();i++) {
  1373. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1374. if (!ste)
  1375. continue;
  1376. Ref<Script> script = ste->get_edited_script();
  1377. if (script->get_path()!="" && script->get_path().find("local://")==-1 &&script->get_path().find("::")==-1) {
  1378. //external script, save it
  1379. editor->save_resource(script);
  1380. //ResourceSaver::save(script->get_path(),script);
  1381. }
  1382. }
  1383. }
  1384. void ScriptEditor::apply_scripts() const {
  1385. for(int i=0;i<tab_container->get_child_count();i++) {
  1386. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1387. if (!ste)
  1388. continue;
  1389. ste->apply_code();
  1390. }
  1391. }
  1392. void ScriptEditor::_editor_play() {
  1393. debugger->start();
  1394. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true );
  1395. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true );
  1396. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), false );
  1397. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
  1398. //debugger_gui->start_listening(Globals::get_singleton()->get("debug/debug_port"));
  1399. }
  1400. void ScriptEditor::_editor_pause() {
  1401. }
  1402. void ScriptEditor::_editor_stop() {
  1403. debugger->stop();
  1404. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true );
  1405. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true );
  1406. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true );
  1407. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
  1408. }
  1409. void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const StringArray& p_args) {
  1410. print_line("add callback! hohoho");
  1411. ERR_FAIL_COND(!p_obj);
  1412. Ref<Script> script = p_obj->get_script();
  1413. ERR_FAIL_COND( !script.is_valid() );
  1414. editor->push_item(script.ptr());
  1415. for(int i=0;i<tab_container->get_child_count();i++) {
  1416. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1417. if (!ste)
  1418. continue;
  1419. if (ste->get_edited_script()!=script)
  1420. continue;
  1421. String code = ste->get_text_edit()->get_text();
  1422. int pos = script->get_language()->find_function(p_function,code);
  1423. if (pos==-1) {
  1424. //does not exist
  1425. ste->get_text_edit()->deselect();
  1426. pos=ste->get_text_edit()->get_line_count()+2;
  1427. String func = script->get_language()->make_function("",p_function,p_args);
  1428. //code=code+func;
  1429. ste->get_text_edit()->cursor_set_line(pos+1);
  1430. ste->get_text_edit()->cursor_set_column(1000000); //none shall be that big
  1431. ste->get_text_edit()->insert_text_at_cursor("\n\n"+func);
  1432. }
  1433. _go_to_tab(i);
  1434. ste->get_text_edit()->cursor_set_line(pos);
  1435. ste->get_text_edit()->cursor_set_column(1);
  1436. script_list->select( script_list->find_metadata(i) );
  1437. break;
  1438. }
  1439. }
  1440. void ScriptEditor::_editor_settings_changed() {
  1441. print_line("settings changed");
  1442. float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
  1443. if (autosave_time>0) {
  1444. autosave_timer->set_wait_time(autosave_time);
  1445. autosave_timer->start();
  1446. } else {
  1447. autosave_timer->stop();
  1448. }
  1449. for(int i=0;i<tab_container->get_child_count();i++) {
  1450. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1451. if (!ste)
  1452. continue;
  1453. ste->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
  1454. }
  1455. }
  1456. void ScriptEditor::_autosave_scripts() {
  1457. print_line("autosaving");
  1458. save_external_data();
  1459. }
  1460. void ScriptEditor::_tree_changed() {
  1461. if (waiting_update_names)
  1462. return;
  1463. waiting_update_names=true;
  1464. call_deferred("_update_script_names");
  1465. }
  1466. void ScriptEditor::_script_split_dragged(float) {
  1467. EditorNode::get_singleton()->save_layout();
  1468. }
  1469. void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
  1470. if (!bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
  1471. return;
  1472. }
  1473. if (!p_layout->has_section_key("ScriptEditor","open_scripts") && !p_layout->has_section_key("ScriptEditor","open_help"))
  1474. return;
  1475. Array scripts = p_layout->get_value("ScriptEditor","open_scripts");
  1476. Array helps;
  1477. if (p_layout->has_section_key("ScriptEditor","open_help"))
  1478. helps=p_layout->get_value("ScriptEditor","open_help");
  1479. restoring_layout=true;
  1480. for(int i=0;i<scripts.size();i++) {
  1481. String path = scripts[i];
  1482. Ref<Script> scr = ResourceLoader::load(path);
  1483. if (scr.is_valid()) {
  1484. edit(scr);
  1485. }
  1486. }
  1487. for(int i=0;i<helps.size();i++) {
  1488. String path = helps[i];
  1489. _help_class_open(path);
  1490. }
  1491. for(int i=0;i<tab_container->get_child_count();i++) {
  1492. tab_container->get_child(i)->set_meta("__editor_pass",Variant());
  1493. }
  1494. if (p_layout->has_section_key("ScriptEditor","split_offset")) {
  1495. script_split->set_split_offset(p_layout->get_value("ScriptEditor","split_offset"));
  1496. }
  1497. restoring_layout=false;
  1498. }
  1499. void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
  1500. Array scripts;
  1501. Array helps;
  1502. for(int i=0;i<tab_container->get_child_count();i++) {
  1503. ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
  1504. if (ste) {
  1505. String path = ste->get_edited_script()->get_path();
  1506. if (!path.is_resource_file())
  1507. continue;
  1508. scripts.push_back(path);
  1509. }
  1510. EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
  1511. if (eh) {
  1512. helps.push_back(eh->get_class_name());
  1513. }
  1514. }
  1515. p_layout->set_value("ScriptEditor","open_scripts",scripts);
  1516. p_layout->set_value("ScriptEditor","open_help",helps);
  1517. p_layout->set_value("ScriptEditor","split_offset",script_split->get_split_offset());
  1518. }
  1519. void ScriptEditor::_help_class_open(const String& p_class) {
  1520. for(int i=0;i<tab_container->get_child_count();i++) {
  1521. EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
  1522. if (eh && eh->get_class_name()==p_class) {
  1523. _go_to_tab(i);
  1524. _update_script_names();
  1525. return;
  1526. }
  1527. }
  1528. EditorHelp * eh = memnew( EditorHelp );
  1529. eh->set_name(p_class);
  1530. tab_container->add_child(eh);
  1531. _go_to_tab(tab_container->get_tab_count()-1);
  1532. eh->go_to_class(p_class,0);
  1533. eh->connect("go_to_help",this,"_help_class_goto");
  1534. _update_script_names();
  1535. }
  1536. void ScriptEditor::_help_class_goto(const String& p_desc) {
  1537. String cname=p_desc.get_slice(":",1);
  1538. for(int i=0;i<tab_container->get_child_count();i++) {
  1539. EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
  1540. if (eh && eh->get_class_name()==cname) {
  1541. _go_to_tab(i);
  1542. eh->go_to_help(p_desc);
  1543. _update_script_names();
  1544. return;
  1545. }
  1546. }
  1547. EditorHelp * eh = memnew( EditorHelp );
  1548. eh->set_name(cname);
  1549. tab_container->add_child(eh);
  1550. _go_to_tab(tab_container->get_tab_count()-1);
  1551. eh->go_to_help(p_desc);
  1552. eh->connect("go_to_help",this,"_help_class_goto");
  1553. _update_script_names();
  1554. }
  1555. void ScriptEditor::_update_history_pos(int p_new_pos) {
  1556. Node *n = tab_container->get_current_tab_control();
  1557. if (n->cast_to<ScriptTextEditor>()) {
  1558. history[history_pos].scroll_pos=n->cast_to<ScriptTextEditor>()->get_text_edit()->get_v_scroll();
  1559. history[history_pos].cursor_column=n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_get_column();
  1560. history[history_pos].cursor_row=n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_get_line();
  1561. }
  1562. if (n->cast_to<EditorHelp>()) {
  1563. history[history_pos].scroll_pos=n->cast_to<EditorHelp>()->get_scroll();
  1564. }
  1565. history_pos=p_new_pos;
  1566. tab_container->set_current_tab(history[history_pos].control->get_index());
  1567. n = history[history_pos].control;
  1568. if (n->cast_to<ScriptTextEditor>()) {
  1569. n->cast_to<ScriptTextEditor>()->get_text_edit()->set_v_scroll(history[history_pos].scroll_pos);
  1570. n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_set_column( history[history_pos].cursor_column );
  1571. n->cast_to<ScriptTextEditor>()->get_text_edit()->cursor_set_line( history[history_pos].cursor_row );
  1572. n->cast_to<ScriptTextEditor>()->get_text_edit()->grab_focus();
  1573. }
  1574. if (n->cast_to<EditorHelp>()) {
  1575. n->cast_to<EditorHelp>()->set_scroll(history[history_pos].scroll_pos);
  1576. n->cast_to<EditorHelp>()->set_focused();
  1577. }
  1578. n->set_meta("__editor_pass",++edit_pass);
  1579. _update_script_names();
  1580. _update_history_arrows();
  1581. }
  1582. void ScriptEditor::_history_forward() {
  1583. if (history_pos<history.size()-1) {
  1584. _update_history_pos(history_pos+1);
  1585. }
  1586. }
  1587. void ScriptEditor::_history_back(){
  1588. if (history_pos>0) {
  1589. _update_history_pos(history_pos-1);
  1590. }
  1591. }
  1592. void ScriptEditor::set_scene_root_script( Ref<Script> p_script ) {
  1593. bool open_dominant = EditorSettings::get_singleton()->get("text_editor/open_dominant_script_on_scene_change");
  1594. if (bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor")))
  1595. return;
  1596. if (open_dominant && p_script.is_valid()) {
  1597. edit(p_script);
  1598. }
  1599. }
  1600. void ScriptEditor::_bind_methods() {
  1601. ObjectTypeDB::bind_method("_tab_changed",&ScriptEditor::_tab_changed);
  1602. ObjectTypeDB::bind_method("_menu_option",&ScriptEditor::_menu_option);
  1603. ObjectTypeDB::bind_method("_close_current_tab",&ScriptEditor::_close_current_tab);
  1604. ObjectTypeDB::bind_method("_editor_play",&ScriptEditor::_editor_play);
  1605. ObjectTypeDB::bind_method("_editor_pause",&ScriptEditor::_editor_pause);
  1606. ObjectTypeDB::bind_method("_editor_stop",&ScriptEditor::_editor_stop);
  1607. ObjectTypeDB::bind_method("_add_callback",&ScriptEditor::_add_callback);
  1608. ObjectTypeDB::bind_method("_reload_scripts",&ScriptEditor::_reload_scripts);
  1609. ObjectTypeDB::bind_method("_resave_scripts",&ScriptEditor::_resave_scripts);
  1610. ObjectTypeDB::bind_method("_res_saved_callback",&ScriptEditor::_res_saved_callback);
  1611. ObjectTypeDB::bind_method("_goto_script_line",&ScriptEditor::_goto_script_line);
  1612. ObjectTypeDB::bind_method("_goto_script_line2",&ScriptEditor::_goto_script_line2);
  1613. ObjectTypeDB::bind_method("_breaked",&ScriptEditor::_breaked);
  1614. ObjectTypeDB::bind_method("_show_debugger",&ScriptEditor::_show_debugger);
  1615. ObjectTypeDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip);
  1616. ObjectTypeDB::bind_method("_autosave_scripts",&ScriptEditor::_autosave_scripts);
  1617. ObjectTypeDB::bind_method("_editor_settings_changed",&ScriptEditor::_editor_settings_changed);
  1618. ObjectTypeDB::bind_method("_update_script_names",&ScriptEditor::_update_script_names);
  1619. ObjectTypeDB::bind_method("_tree_changed",&ScriptEditor::_tree_changed);
  1620. ObjectTypeDB::bind_method("_script_selected",&ScriptEditor::_script_selected);
  1621. ObjectTypeDB::bind_method("_script_created",&ScriptEditor::_script_created);
  1622. ObjectTypeDB::bind_method("_script_split_dragged",&ScriptEditor::_script_split_dragged);
  1623. ObjectTypeDB::bind_method("_help_class_open",&ScriptEditor::_help_class_open);
  1624. ObjectTypeDB::bind_method("_help_class_goto",&ScriptEditor::_help_class_goto);
  1625. ObjectTypeDB::bind_method("_request_help",&ScriptEditor::_help_class_open);
  1626. ObjectTypeDB::bind_method("_history_forward",&ScriptEditor::_history_forward);
  1627. ObjectTypeDB::bind_method("_history_back",&ScriptEditor::_history_back);
  1628. }
  1629. ScriptEditor::ScriptEditor(EditorNode *p_editor) {
  1630. completion_cache = memnew( EditorScriptCodeCompletionCache );
  1631. restoring_layout=false;
  1632. waiting_update_names=false;
  1633. editor=p_editor;
  1634. menu_hb = memnew( HBoxContainer );
  1635. add_child(menu_hb);
  1636. script_split = memnew( HSplitContainer );
  1637. add_child(script_split);
  1638. script_split->set_v_size_flags(SIZE_EXPAND_FILL);
  1639. script_list = memnew( ItemList );
  1640. script_split->add_child(script_list);
  1641. script_list->set_custom_minimum_size(Size2(0,0));
  1642. script_split->set_split_offset(70);
  1643. tab_container = memnew( TabContainer );
  1644. tab_container->set_tabs_visible(false);
  1645. script_split->add_child(tab_container);
  1646. tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
  1647. file_menu = memnew( MenuButton );
  1648. menu_hb->add_child(file_menu);
  1649. file_menu->set_text("File");
  1650. file_menu->get_popup()->add_item("New",FILE_NEW);
  1651. file_menu->get_popup()->add_item("Open",FILE_OPEN);
  1652. file_menu->get_popup()->add_separator();
  1653. file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S);
  1654. file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS);
  1655. file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S);
  1656. file_menu->get_popup()->add_separator();
  1657. file_menu->get_popup()->add_item("History Prev",WINDOW_PREV,KEY_MASK_CTRL|KEY_MASK_ALT|KEY_LEFT);
  1658. file_menu->get_popup()->add_item("History Next",WINDOW_NEXT,KEY_MASK_CTRL|KEY_MASK_ALT|KEY_RIGHT);
  1659. file_menu->get_popup()->add_separator();
  1660. file_menu->get_popup()->add_item("Close",FILE_CLOSE,KEY_MASK_CMD|KEY_W);
  1661. file_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1662. edit_menu = memnew( MenuButton );
  1663. menu_hb->add_child(edit_menu);
  1664. edit_menu->set_text("Edit");
  1665. edit_menu->get_popup()->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD|KEY_Z);
  1666. edit_menu->get_popup()->add_item("Redo",EDIT_REDO,KEY_MASK_CMD|KEY_Y);
  1667. edit_menu->get_popup()->add_separator();
  1668. edit_menu->get_popup()->add_item("Cut",EDIT_CUT,KEY_MASK_CMD|KEY_X);
  1669. edit_menu->get_popup()->add_item("Copy",EDIT_COPY,KEY_MASK_CMD|KEY_C);
  1670. edit_menu->get_popup()->add_item("Paste",EDIT_PASTE,KEY_MASK_CMD|KEY_V);
  1671. edit_menu->get_popup()->add_separator();
  1672. edit_menu->get_popup()->add_item("Select All",EDIT_SELECT_ALL,KEY_MASK_CMD|KEY_A);
  1673. edit_menu->get_popup()->add_separator();
  1674. edit_menu->get_popup()->add_item("Move Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP);
  1675. edit_menu->get_popup()->add_item("Move Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN);
  1676. edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT);
  1677. edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT);
  1678. edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_K);
  1679. edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B);
  1680. edit_menu->get_popup()->add_separator();
  1681. #ifdef OSX_ENABLED
  1682. edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CTRL|KEY_SPACE);
  1683. #else
  1684. edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE);
  1685. #endif
  1686. edit_menu->get_popup()->add_item("Auto Indent",EDIT_AUTO_INDENT,KEY_MASK_CMD|KEY_I);
  1687. edit_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1688. search_menu = memnew( MenuButton );
  1689. menu_hb->add_child(search_menu);
  1690. search_menu->set_text("Search");
  1691. search_menu->get_popup()->add_item("Find..",SEARCH_FIND,KEY_MASK_CMD|KEY_F);
  1692. search_menu->get_popup()->add_item("Find Next",SEARCH_FIND_NEXT,KEY_F3);
  1693. search_menu->get_popup()->add_item("Replace..",SEARCH_REPLACE,KEY_MASK_CMD|KEY_R);
  1694. search_menu->get_popup()->add_separator();
  1695. search_menu->get_popup()->add_item("Goto Function..",SEARCH_LOCATE_FUNCTION,KEY_MASK_SHIFT|KEY_MASK_CMD|KEY_F);
  1696. search_menu->get_popup()->add_item("Goto Line..",SEARCH_GOTO_LINE,KEY_MASK_CMD|KEY_L);
  1697. search_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1698. script_search_menu = memnew( MenuButton );
  1699. menu_hb->add_child(script_search_menu);
  1700. script_search_menu->set_text("Search");
  1701. script_search_menu->get_popup()->add_item("Find..",SEARCH_FIND,KEY_MASK_CMD|KEY_F);
  1702. script_search_menu->get_popup()->add_item("Find Next",SEARCH_FIND_NEXT,KEY_F3);
  1703. script_search_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1704. script_search_menu->hide();
  1705. debug_menu = memnew( MenuButton );
  1706. menu_hb->add_child(debug_menu);
  1707. debug_menu->set_text("Debug");
  1708. debug_menu->get_popup()->add_item("Toggle Breakpoint",DEBUG_TOGGLE_BREAKPOINT,KEY_F9);
  1709. debug_menu->get_popup()->add_separator();
  1710. debug_menu->get_popup()->add_item("Step Over",DEBUG_NEXT,KEY_F10);
  1711. debug_menu->get_popup()->add_item("Step Into",DEBUG_STEP,KEY_F11);
  1712. debug_menu->get_popup()->add_separator();
  1713. debug_menu->get_popup()->add_item("Break",DEBUG_BREAK);
  1714. debug_menu->get_popup()->add_item("Continue",DEBUG_CONTINUE);
  1715. debug_menu->get_popup()->add_separator();
  1716. //debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW);
  1717. debug_menu->get_popup()->add_check_item("Keep Debugger Open",DEBUG_SHOW_KEEP_OPEN);
  1718. debug_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1719. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true);
  1720. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true );
  1721. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true );
  1722. debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
  1723. #if 0
  1724. window_menu = memnew( MenuButton );
  1725. menu_hb->add_child(window_menu);
  1726. window_menu->set_text("Window");
  1727. window_menu->get_popup()->add_item("Close",WINDOW_CLOSE,KEY_MASK_CMD|KEY_W);
  1728. window_menu->get_popup()->add_separator();
  1729. window_menu->get_popup()->add_item("Move Left",WINDOW_MOVE_LEFT,KEY_MASK_CMD|KEY_LEFT);
  1730. window_menu->get_popup()->add_item("Move Right",WINDOW_MOVE_RIGHT,KEY_MASK_CMD|KEY_RIGHT);
  1731. window_menu->get_popup()->add_separator();
  1732. window_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1733. #endif
  1734. help_menu = memnew( MenuButton );
  1735. menu_hb->add_child(help_menu);
  1736. help_menu->set_text("Help");
  1737. help_menu->get_popup()->add_item("Contextual", HELP_CONTEXTUAL, KEY_MASK_SHIFT|KEY_F1);
  1738. help_menu->get_popup()->connect("item_pressed", this,"_menu_option");
  1739. menu_hb->add_spacer();
  1740. script_icon = memnew( TextureFrame );
  1741. menu_hb->add_child(script_icon);
  1742. script_name_label = memnew( Label );
  1743. menu_hb->add_child(script_name_label);
  1744. script_icon->hide();
  1745. script_name_label->hide();
  1746. menu_hb->add_spacer();
  1747. site_search = memnew( ToolButton );
  1748. site_search->set_text("Tutorials");
  1749. site_search->connect("pressed",this,"_menu_option",varray(SEARCH_WEBSITE));
  1750. menu_hb->add_child(site_search);
  1751. site_search->set_tooltip("Open http://www.godotengine.org at tutorials section.");
  1752. class_search = memnew( ToolButton );
  1753. class_search->set_text("Classes");
  1754. class_search->connect("pressed",this,"_menu_option",varray(SEARCH_CLASSES));
  1755. menu_hb->add_child(class_search);
  1756. class_search->set_tooltip("Search the class hierarchy.");
  1757. help_search = memnew( ToolButton );
  1758. help_search->set_text("Search Help");
  1759. help_search->connect("pressed",this,"_menu_option",varray(SEARCH_HELP));
  1760. menu_hb->add_child(help_search);
  1761. help_search->set_tooltip("Search the reference documentation.");
  1762. menu_hb->add_child( memnew( VSeparator) );
  1763. script_back = memnew( ToolButton );
  1764. script_back->connect("pressed",this,"_history_back");
  1765. menu_hb->add_child(script_back);
  1766. script_back->set_disabled(true);
  1767. help_search->set_tooltip("Go to previous edited document.");
  1768. script_forward = memnew( ToolButton );
  1769. script_forward->connect("pressed",this,"_history_forward");
  1770. menu_hb->add_child(script_forward);
  1771. script_forward->set_disabled(true);
  1772. help_search->set_tooltip("Go to next edited document.");
  1773. tab_container->connect("tab_changed", this,"_tab_changed");
  1774. find_replace_dialog = memnew(FindReplaceDialog);
  1775. add_child(find_replace_dialog);
  1776. erase_tab_confirm = memnew( ConfirmationDialog );
  1777. add_child(erase_tab_confirm);
  1778. erase_tab_confirm->connect("confirmed", this,"_close_current_tab");
  1779. script_create_dialog = memnew(ScriptCreateDialog);
  1780. script_create_dialog->set_title("Create Script");
  1781. add_child(script_create_dialog);
  1782. script_create_dialog->connect("script_created", this, "_script_created");
  1783. goto_line_dialog = memnew(GotoLineDialog);
  1784. add_child(goto_line_dialog);
  1785. debugger = memnew( ScriptEditorDebugger(editor) );
  1786. debugger->connect("goto_script_line",this,"_goto_script_line");
  1787. debugger->connect("show_debugger",this,"_show_debugger");
  1788. disk_changed = memnew( ConfirmationDialog );
  1789. {
  1790. VBoxContainer *vbc = memnew( VBoxContainer );
  1791. disk_changed->add_child(vbc);
  1792. disk_changed->set_child_rect(vbc);
  1793. Label *dl = memnew( Label );
  1794. dl->set_text("The following files are newer on disk.\nWhat action should be taken?:");
  1795. vbc->add_child(dl);
  1796. disk_changed_list = memnew( Tree );
  1797. vbc->add_child(disk_changed_list);
  1798. disk_changed_list->set_v_size_flags(SIZE_EXPAND_FILL);
  1799. disk_changed->connect("confirmed",this,"_reload_scripts");
  1800. disk_changed->get_ok()->set_text("Reload");
  1801. disk_changed->add_button("Resave",!OS::get_singleton()->get_swap_ok_cancel(),"resave");
  1802. disk_changed->connect("custom_action",this,"_resave_scripts");
  1803. }
  1804. add_child(disk_changed);
  1805. script_editor=this;
  1806. quick_open = memnew( ScriptEditorQuickOpen );
  1807. add_child(quick_open);
  1808. quick_open->connect("goto_line",this,"_goto_script_line2");
  1809. Button *db = EditorNode::get_singleton()->add_bottom_panel_item("Debugger",debugger);
  1810. debugger->set_tool_button(db);
  1811. debugger->connect("breaked",this,"_breaked");
  1812. autosave_timer = memnew( Timer );
  1813. autosave_timer->set_one_shot(false);
  1814. add_child(autosave_timer);
  1815. grab_focus_block=false;
  1816. help_search_dialog = memnew( EditorHelpSearch );
  1817. add_child(help_search_dialog);
  1818. help_search_dialog->connect("go_to_help",this,"_help_class_goto");
  1819. help_index = memnew( EditorHelpIndex );
  1820. add_child(help_index);
  1821. help_index->connect("open_class",this,"_help_class_open");
  1822. history_pos=-1;
  1823. // debugger_gui->hide();
  1824. edit_pass=0;
  1825. }
  1826. ScriptEditor::~ScriptEditor() {
  1827. memdelete(completion_cache);
  1828. }
  1829. void ScriptEditorPlugin::edit(Object *p_object) {
  1830. if (!p_object->cast_to<Script>())
  1831. return;
  1832. script_editor->edit(p_object->cast_to<Script>());
  1833. }
  1834. bool ScriptEditorPlugin::handles(Object *p_object) const {
  1835. return p_object->is_type("Script");
  1836. }
  1837. void ScriptEditorPlugin::make_visible(bool p_visible) {
  1838. if (p_visible) {
  1839. script_editor->show();
  1840. script_editor->set_process(true);
  1841. script_editor->ensure_select_current();
  1842. } else {
  1843. script_editor->hide();
  1844. script_editor->set_process(false);
  1845. }
  1846. }
  1847. void ScriptEditorPlugin::selected_notify() {
  1848. script_editor->ensure_select_current();
  1849. }
  1850. Dictionary ScriptEditorPlugin::get_state() const {
  1851. return script_editor->get_state();
  1852. }
  1853. void ScriptEditorPlugin::set_state(const Dictionary& p_state) {
  1854. script_editor->set_state(p_state);
  1855. }
  1856. void ScriptEditorPlugin::clear() {
  1857. script_editor->clear();
  1858. }
  1859. void ScriptEditorPlugin::save_external_data() {
  1860. script_editor->save_external_data();
  1861. }
  1862. void ScriptEditorPlugin::apply_changes() {
  1863. script_editor->apply_scripts();
  1864. }
  1865. void ScriptEditorPlugin::restore_global_state() {
  1866. }
  1867. void ScriptEditorPlugin::save_global_state() {
  1868. }
  1869. void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
  1870. script_editor->set_window_layout(p_layout);
  1871. }
  1872. void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){
  1873. script_editor->get_window_layout(p_layout);
  1874. }
  1875. void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
  1876. return script_editor->get_breakpoints(p_breakpoints);
  1877. }
  1878. void ScriptEditorPlugin::edited_scene_changed() {
  1879. script_editor->edited_scene_changed();
  1880. }
  1881. ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) {
  1882. editor=p_node;
  1883. script_editor = memnew( ScriptEditor(p_node) );
  1884. editor->get_viewport()->add_child(script_editor);
  1885. script_editor->set_area_as_parent_rect();
  1886. script_editor->hide();
  1887. EDITOR_DEF("text_editor/auto_reload_scripts_on_external_change",true);
  1888. EDITOR_DEF("text_editor/open_dominant_script_on_scene_change",true);
  1889. EDITOR_DEF("external_editor/use_external_editor",false);
  1890. EDITOR_DEF("external_editor/exec_path","");
  1891. EDITOR_DEF("text_editor/script_temperature_enabled",true);
  1892. EDITOR_DEF("text_editor/script_temperature_history_size",15);
  1893. EDITOR_DEF("text_editor/script_temperature_hot_color",Color(1,0,0,0.3));
  1894. EDITOR_DEF("text_editor/script_temperature_cold_color",Color(0,0,1,0.3));
  1895. EDITOR_DEF("text_editor/group_help_pages",false);
  1896. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"external_editor/exec_path",PROPERTY_HINT_GLOBAL_FILE));
  1897. EDITOR_DEF("external_editor/exec_flags","");
  1898. }
  1899. ScriptEditorPlugin::~ScriptEditorPlugin()
  1900. {
  1901. }