script_editor_plugin.cpp 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463
  1. /*************************************************************************/
  2. /* script_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "script_editor_plugin.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/os/file_access.h"
  33. #include "core/os/input.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/os/os.h"
  36. #include "core/project_settings.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_settings.h"
  39. #include "editor/find_in_files.h"
  40. #include "editor/node_dock.h"
  41. #include "editor/plugins/shader_editor_plugin.h"
  42. #include "editor/script_editor_debugger.h"
  43. #include "scene/main/viewport.h"
  44. #include "script_text_editor.h"
  45. /*** SCRIPT EDITOR ****/
  46. void ScriptEditorBase::_bind_methods() {
  47. ADD_SIGNAL(MethodInfo("name_changed"));
  48. ADD_SIGNAL(MethodInfo("edited_script_changed"));
  49. ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic")));
  50. ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line")));
  51. ADD_SIGNAL(MethodInfo("request_save_history"));
  52. ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what")));
  53. // TODO This signal is no use for VisualScript...
  54. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text")));
  55. }
  56. static bool _is_built_in_script(Script *p_script) {
  57. String path = p_script->get_path();
  58. return path.find("::") != -1;
  59. }
  60. class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
  61. struct Cache {
  62. uint64_t time_loaded;
  63. RES cache;
  64. };
  65. Map<String, Cache> cached;
  66. public:
  67. uint64_t max_time_cache;
  68. int max_cache_size;
  69. void cleanup() {
  70. List<Map<String, Cache>::Element *> to_clean;
  71. Map<String, Cache>::Element *I = cached.front();
  72. while (I) {
  73. if ((OS::get_singleton()->get_ticks_msec() - I->get().time_loaded) > max_time_cache) {
  74. to_clean.push_back(I);
  75. }
  76. I = I->next();
  77. }
  78. while (to_clean.front()) {
  79. cached.erase(to_clean.front()->get());
  80. to_clean.pop_front();
  81. }
  82. }
  83. virtual RES get_cached_resource(const String &p_path) {
  84. Map<String, Cache>::Element *E = cached.find(p_path);
  85. if (!E) {
  86. Cache c;
  87. c.cache = ResourceLoader::load(p_path);
  88. E = cached.insert(p_path, c);
  89. }
  90. E->get().time_loaded = OS::get_singleton()->get_ticks_msec();
  91. if (cached.size() > max_cache_size) {
  92. uint64_t older;
  93. Map<String, Cache>::Element *O = cached.front();
  94. older = O->get().time_loaded;
  95. Map<String, Cache>::Element *I = O;
  96. while (I) {
  97. if (I->get().time_loaded < older) {
  98. older = I->get().time_loaded;
  99. O = I;
  100. }
  101. I = I->next();
  102. }
  103. if (O != E) { //should never happen..
  104. cached.erase(O);
  105. }
  106. }
  107. return E->get().cache;
  108. }
  109. EditorScriptCodeCompletionCache() {
  110. max_cache_size = 128;
  111. max_time_cache = 5 * 60 * 1000; //minutes, five
  112. }
  113. virtual ~EditorScriptCodeCompletionCache() {}
  114. };
  115. void ScriptEditorQuickOpen::popup_dialog(const Vector<String> &p_functions, bool p_dontclear) {
  116. popup_centered_ratio(0.6);
  117. if (p_dontclear)
  118. search_box->select_all();
  119. else
  120. search_box->clear();
  121. search_box->grab_focus();
  122. functions = p_functions;
  123. _update_search();
  124. }
  125. void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) {
  126. _update_search();
  127. }
  128. void ScriptEditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
  129. Ref<InputEventKey> k = p_ie;
  130. if (k.is_valid() && (k->get_scancode() == KEY_UP ||
  131. k->get_scancode() == KEY_DOWN ||
  132. k->get_scancode() == KEY_PAGEUP ||
  133. k->get_scancode() == KEY_PAGEDOWN)) {
  134. search_options->call("_gui_input", k);
  135. search_box->accept_event();
  136. }
  137. }
  138. void ScriptEditorQuickOpen::_update_search() {
  139. search_options->clear();
  140. TreeItem *root = search_options->create_item();
  141. for (int i = 0; i < functions.size(); i++) {
  142. String file = functions[i];
  143. if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) {
  144. TreeItem *ti = search_options->create_item(root);
  145. ti->set_text(0, file);
  146. if (root->get_children() == ti)
  147. ti->select(0);
  148. }
  149. }
  150. get_ok()->set_disabled(root->get_children() == NULL);
  151. }
  152. void ScriptEditorQuickOpen::_confirmed() {
  153. TreeItem *ti = search_options->get_selected();
  154. if (!ti)
  155. return;
  156. int line = ti->get_text(0).get_slice(":", 1).to_int();
  157. emit_signal("goto_line", line - 1);
  158. hide();
  159. }
  160. void ScriptEditorQuickOpen::_notification(int p_what) {
  161. switch (p_what) {
  162. case NOTIFICATION_ENTER_TREE: {
  163. connect("confirmed", this, "_confirmed");
  164. search_box->set_right_icon(get_icon("Search", "EditorIcons"));
  165. search_box->set_clear_button_enabled(true);
  166. } break;
  167. case NOTIFICATION_EXIT_TREE: {
  168. disconnect("confirmed", this, "_confirmed");
  169. } break;
  170. }
  171. }
  172. void ScriptEditorQuickOpen::_bind_methods() {
  173. ClassDB::bind_method(D_METHOD("_text_changed"), &ScriptEditorQuickOpen::_text_changed);
  174. ClassDB::bind_method(D_METHOD("_confirmed"), &ScriptEditorQuickOpen::_confirmed);
  175. ClassDB::bind_method(D_METHOD("_sbox_input"), &ScriptEditorQuickOpen::_sbox_input);
  176. ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line")));
  177. }
  178. ScriptEditorQuickOpen::ScriptEditorQuickOpen() {
  179. VBoxContainer *vbc = memnew(VBoxContainer);
  180. add_child(vbc);
  181. search_box = memnew(LineEdit);
  182. vbc->add_margin_child(TTR("Search:"), search_box);
  183. search_box->connect("text_changed", this, "_text_changed");
  184. search_box->connect("gui_input", this, "_sbox_input");
  185. search_options = memnew(Tree);
  186. vbc->add_margin_child(TTR("Matches:"), search_options, true);
  187. get_ok()->set_text(TTR("Open"));
  188. get_ok()->set_disabled(true);
  189. register_text_enter(search_box);
  190. set_hide_on_ok(false);
  191. search_options->connect("item_activated", this, "_confirmed");
  192. search_options->set_hide_root(true);
  193. }
  194. /////////////////////////////////
  195. ScriptEditor *ScriptEditor::script_editor = NULL;
  196. /*** SCRIPT EDITOR ******/
  197. String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) {
  198. String val = debugger->get_var_value(p_text);
  199. if (val != String()) {
  200. return p_text + ": " + val;
  201. } else {
  202. return String();
  203. }
  204. }
  205. void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) {
  206. if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
  207. return;
  208. }
  209. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), !(p_breaked && p_can_debug));
  210. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), !(p_breaked && p_can_debug));
  211. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), p_breaked);
  212. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), !p_breaked);
  213. for (int i = 0; i < tab_container->get_child_count(); i++) {
  214. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  215. if (!se) {
  216. continue;
  217. }
  218. se->set_debugger_active(p_breaked);
  219. }
  220. }
  221. void ScriptEditor::_show_debugger(bool p_show) {
  222. //debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW), p_show);
  223. }
  224. void ScriptEditor::_script_created(Ref<Script> p_script) {
  225. editor->push_item(p_script.operator->());
  226. }
  227. void ScriptEditor::_goto_script_line2(int p_line) {
  228. ScriptEditorBase *current = _get_current_editor();
  229. if (current)
  230. current->goto_line(p_line);
  231. }
  232. void ScriptEditor::_goto_script_line(REF p_script, int p_line) {
  233. Ref<Script> script = Object::cast_to<Script>(*p_script);
  234. if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) {
  235. if (edit(p_script, p_line, 0)) {
  236. editor->push_item(p_script.ptr());
  237. ScriptEditorBase *current = _get_current_editor();
  238. if (current)
  239. current->goto_line(p_line, true);
  240. }
  241. }
  242. }
  243. void ScriptEditor::_set_execution(REF p_script, int p_line) {
  244. Ref<Script> script = Object::cast_to<Script>(*p_script);
  245. if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) {
  246. for (int i = 0; i < tab_container->get_child_count(); i++) {
  247. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  248. if (!se)
  249. continue;
  250. if ((script != NULL && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) {
  251. se->set_executing_line(p_line);
  252. }
  253. }
  254. }
  255. }
  256. void ScriptEditor::_clear_execution(REF p_script) {
  257. Ref<Script> script = Object::cast_to<Script>(*p_script);
  258. if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) {
  259. for (int i = 0; i < tab_container->get_child_count(); i++) {
  260. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  261. if (!se)
  262. continue;
  263. if ((script != NULL && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) {
  264. se->clear_executing_line();
  265. }
  266. }
  267. }
  268. }
  269. ScriptEditorBase *ScriptEditor::_get_current_editor() const {
  270. int selected = tab_container->get_current_tab();
  271. if (selected < 0 || selected >= tab_container->get_child_count())
  272. return NULL;
  273. return Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
  274. }
  275. void ScriptEditor::_update_history_arrows() {
  276. script_back->set_disabled(history_pos <= 0);
  277. script_forward->set_disabled(history_pos >= history.size() - 1);
  278. }
  279. void ScriptEditor::_save_history() {
  280. if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) {
  281. Node *n = tab_container->get_current_tab_control();
  282. if (Object::cast_to<ScriptEditorBase>(n)) {
  283. history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
  284. }
  285. if (Object::cast_to<EditorHelp>(n)) {
  286. history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
  287. }
  288. }
  289. history.resize(history_pos + 1);
  290. ScriptHistory sh;
  291. sh.control = tab_container->get_current_tab_control();
  292. sh.state = Variant();
  293. history.push_back(sh);
  294. history_pos++;
  295. _update_history_arrows();
  296. }
  297. void ScriptEditor::_go_to_tab(int p_idx) {
  298. ScriptEditorBase *current = _get_current_editor();
  299. if (current) {
  300. if (current->is_unsaved()) {
  301. current->apply_code();
  302. }
  303. }
  304. Control *c = Object::cast_to<Control>(tab_container->get_child(p_idx));
  305. if (!c)
  306. return;
  307. if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) {
  308. Node *n = tab_container->get_current_tab_control();
  309. if (Object::cast_to<ScriptEditorBase>(n)) {
  310. history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
  311. }
  312. if (Object::cast_to<EditorHelp>(n)) {
  313. history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
  314. }
  315. }
  316. history.resize(history_pos + 1);
  317. ScriptHistory sh;
  318. sh.control = c;
  319. sh.state = Variant();
  320. history.push_back(sh);
  321. history_pos++;
  322. tab_container->set_current_tab(p_idx);
  323. c = tab_container->get_current_tab_control();
  324. if (Object::cast_to<ScriptEditorBase>(c)) {
  325. script_name_label->set_text(Object::cast_to<ScriptEditorBase>(c)->get_name());
  326. script_icon->set_texture(Object::cast_to<ScriptEditorBase>(c)->get_icon());
  327. if (is_visible_in_tree())
  328. Object::cast_to<ScriptEditorBase>(c)->ensure_focus();
  329. Ref<Script> script = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource();
  330. if (script != NULL) {
  331. notify_script_changed(script);
  332. }
  333. }
  334. if (Object::cast_to<EditorHelp>(c)) {
  335. script_name_label->set_text(Object::cast_to<EditorHelp>(c)->get_class());
  336. script_icon->set_texture(get_icon("Help", "EditorIcons"));
  337. if (is_visible_in_tree())
  338. Object::cast_to<EditorHelp>(c)->set_focused();
  339. }
  340. c->set_meta("__editor_pass", ++edit_pass);
  341. _update_history_arrows();
  342. _update_script_colors();
  343. _update_members_overview();
  344. _update_help_overview();
  345. _update_selected_editor_menu();
  346. _update_members_overview_visibility();
  347. _update_help_overview_visibility();
  348. }
  349. void ScriptEditor::_add_recent_script(String p_path) {
  350. if (p_path.empty()) {
  351. return;
  352. }
  353. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
  354. if (rc.find(p_path) != -1) {
  355. rc.erase(p_path);
  356. }
  357. rc.push_front(p_path);
  358. if (rc.size() > 10) {
  359. rc.resize(10);
  360. }
  361. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", rc);
  362. _update_recent_scripts();
  363. }
  364. void ScriptEditor::_update_recent_scripts() {
  365. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
  366. recent_scripts->clear();
  367. recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T));
  368. recent_scripts->add_separator();
  369. String path;
  370. for (int i = 0; i < rc.size(); i++) {
  371. path = rc[i];
  372. recent_scripts->add_item(path.replace("res://", ""));
  373. }
  374. recent_scripts->add_separator();
  375. recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files")));
  376. recent_scripts->set_as_minsize();
  377. }
  378. void ScriptEditor::_open_recent_script(int p_idx) {
  379. // clear button
  380. if (p_idx == recent_scripts->get_item_count() - 1) {
  381. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", Array());
  382. call_deferred("_update_recent_scripts");
  383. return;
  384. }
  385. // take two for the open recent button
  386. if (p_idx > 0) {
  387. p_idx -= 2;
  388. }
  389. Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array());
  390. ERR_FAIL_INDEX(p_idx, rc.size());
  391. String path = rc[p_idx];
  392. // if its not on disk its a help file or deleted
  393. if (FileAccess::exists(path)) {
  394. List<String> extensions;
  395. ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
  396. if (extensions.find(path.get_extension())) {
  397. Ref<Script> script = ResourceLoader::load(path);
  398. if (script.is_valid()) {
  399. edit(script, true);
  400. return;
  401. }
  402. }
  403. Error err;
  404. Ref<TextFile> text_file = _load_text_file(path, &err);
  405. if (text_file.is_valid()) {
  406. edit(text_file, true);
  407. return;
  408. }
  409. // if it's a path then it's most likely a deleted file not help
  410. } else if (path.find("::") != -1) {
  411. // built-in script
  412. Ref<Script> script = ResourceLoader::load(path);
  413. if (script.is_valid()) {
  414. edit(script, true);
  415. return;
  416. }
  417. } else if (!path.is_resource_file()) {
  418. _help_class_open(path);
  419. return;
  420. }
  421. rc.remove(p_idx);
  422. EditorSettings::get_singleton()->set_project_metadata("recent_files", "scripts", rc);
  423. _update_recent_scripts();
  424. _show_error_dialog(path);
  425. }
  426. void ScriptEditor::_show_error_dialog(String p_path) {
  427. error_dialog->set_text(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_path));
  428. error_dialog->popup_centered_minsize();
  429. }
  430. void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
  431. int selected = p_idx;
  432. if (selected < 0 || selected >= tab_container->get_child_count())
  433. return;
  434. Node *tselected = tab_container->get_child(selected);
  435. ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
  436. if (current) {
  437. if (p_save) {
  438. apply_scripts();
  439. }
  440. Ref<Script> script = current->get_edited_resource();
  441. if (script != NULL) {
  442. notify_script_close(script);
  443. }
  444. }
  445. // roll back to previous tab
  446. if (p_history_back) {
  447. _history_back();
  448. }
  449. //remove from history
  450. history.resize(history_pos + 1);
  451. for (int i = 0; i < history.size(); i++) {
  452. if (history[i].control == tselected) {
  453. history.remove(i);
  454. i--;
  455. history_pos--;
  456. }
  457. }
  458. if (history_pos >= history.size()) {
  459. history_pos = history.size() - 1;
  460. }
  461. int idx = tab_container->get_current_tab();
  462. if (current) {
  463. current->clear_edit_menu();
  464. }
  465. memdelete(tselected);
  466. if (idx >= tab_container->get_child_count())
  467. idx = tab_container->get_child_count() - 1;
  468. if (idx >= 0) {
  469. if (history_pos >= 0) {
  470. idx = history[history_pos].control->get_index();
  471. }
  472. tab_container->set_current_tab(idx);
  473. } else {
  474. _update_selected_editor_menu();
  475. }
  476. _update_history_arrows();
  477. _update_script_names();
  478. _update_members_overview_visibility();
  479. _update_help_overview_visibility();
  480. _save_layout();
  481. }
  482. void ScriptEditor::_close_current_tab() {
  483. _close_tab(tab_container->get_current_tab());
  484. }
  485. void ScriptEditor::_close_discard_current_tab(const String &p_str) {
  486. _close_tab(tab_container->get_current_tab(), false);
  487. erase_tab_confirm->hide();
  488. }
  489. void ScriptEditor::_close_docs_tab() {
  490. int child_count = tab_container->get_child_count();
  491. for (int i = child_count - 1; i >= 0; i--) {
  492. EditorHelp *se = Object::cast_to<EditorHelp>(tab_container->get_child(i));
  493. if (se) {
  494. _close_tab(i, true, false);
  495. }
  496. }
  497. }
  498. void ScriptEditor::_copy_script_path() {
  499. ScriptEditorBase *se = _get_current_editor();
  500. RES script = se->get_edited_resource();
  501. OS::get_singleton()->set_clipboard(script->get_path());
  502. }
  503. void ScriptEditor::_close_other_tabs() {
  504. int child_count = tab_container->get_child_count();
  505. int current_idx = tab_container->get_current_tab();
  506. for (int i = child_count - 1; i >= 0; i--) {
  507. if (i == current_idx) {
  508. continue;
  509. }
  510. tab_container->set_current_tab(i);
  511. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  512. if (se) {
  513. // Maybe there are unsaved changes
  514. if (se->is_unsaved()) {
  515. _ask_close_current_unsaved_tab(se);
  516. continue;
  517. }
  518. }
  519. _close_current_tab();
  520. }
  521. }
  522. void ScriptEditor::_close_all_tabs() {
  523. int child_count = tab_container->get_child_count();
  524. for (int i = child_count - 1; i >= 0; i--) {
  525. tab_container->set_current_tab(i);
  526. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  527. if (se) {
  528. // Maybe there are unsaved changes
  529. if (se->is_unsaved()) {
  530. _ask_close_current_unsaved_tab(se);
  531. continue;
  532. }
  533. }
  534. _close_current_tab();
  535. }
  536. }
  537. void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) {
  538. erase_tab_confirm->set_text(TTR("Close and save changes?") + "\n\"" + current->get_name() + "\"");
  539. erase_tab_confirm->popup_centered_minsize();
  540. }
  541. void ScriptEditor::_resave_scripts(const String &p_str) {
  542. apply_scripts();
  543. for (int i = 0; i < tab_container->get_child_count(); i++) {
  544. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  545. if (!se)
  546. continue;
  547. RES script = se->get_edited_resource();
  548. if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)
  549. continue; //internal script, who cares
  550. if (trim_trailing_whitespace_on_save) {
  551. se->trim_trailing_whitespace();
  552. }
  553. se->insert_final_newline();
  554. if (convert_indent_on_save) {
  555. if (use_space_indentation) {
  556. se->convert_indent_to_spaces();
  557. } else {
  558. se->convert_indent_to_tabs();
  559. }
  560. }
  561. Ref<TextFile> text_file = script;
  562. if (text_file != NULL) {
  563. se->apply_code();
  564. _save_text_file(text_file, text_file->get_path());
  565. break;
  566. } else {
  567. editor->save_resource(script);
  568. }
  569. se->tag_saved_version();
  570. }
  571. disk_changed->hide();
  572. }
  573. void ScriptEditor::_reload_scripts() {
  574. for (int i = 0; i < tab_container->get_child_count(); i++) {
  575. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  576. if (!se) {
  577. continue;
  578. }
  579. RES edited_res = se->get_edited_resource();
  580. if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) {
  581. continue; //internal script, who cares
  582. }
  583. uint64_t last_date = edited_res->get_last_modified_time();
  584. uint64_t date = FileAccess::get_modified_time(edited_res->get_path());
  585. if (last_date == date) {
  586. continue;
  587. }
  588. Ref<Script> script = edited_res;
  589. if (script != NULL) {
  590. Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
  591. ERR_CONTINUE(!rel_script.is_valid());
  592. script->set_source_code(rel_script->get_source_code());
  593. script->set_last_modified_time(rel_script->get_last_modified_time());
  594. script->reload();
  595. }
  596. Ref<TextFile> text_file = edited_res;
  597. if (text_file != NULL) {
  598. Error err;
  599. Ref<TextFile> rel_text_file = _load_text_file(text_file->get_path(), &err);
  600. ERR_CONTINUE(!rel_text_file.is_valid());
  601. text_file->set_text(rel_text_file->get_text());
  602. text_file->set_last_modified_time(rel_text_file->get_last_modified_time());
  603. }
  604. se->reload_text();
  605. }
  606. disk_changed->hide();
  607. _update_script_names();
  608. }
  609. void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
  610. for (int i = 0; i < tab_container->get_child_count(); i++) {
  611. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  612. if (!se) {
  613. continue;
  614. }
  615. RES script = se->get_edited_resource();
  616. if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
  617. continue; //internal script, who cares
  618. }
  619. if (script == p_res) {
  620. se->tag_saved_version();
  621. }
  622. }
  623. _update_script_names();
  624. if (!pending_auto_reload && auto_reload_running_scripts) {
  625. call_deferred("_live_auto_reload_running_scripts");
  626. pending_auto_reload = true;
  627. }
  628. }
  629. void ScriptEditor::_live_auto_reload_running_scripts() {
  630. pending_auto_reload = false;
  631. debugger->reload_scripts();
  632. }
  633. bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) {
  634. disk_changed_list->clear();
  635. TreeItem *r = disk_changed_list->create_item();
  636. disk_changed_list->set_hide_root(true);
  637. bool need_ask = false;
  638. bool need_reload = false;
  639. bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false));
  640. for (int i = 0; i < tab_container->get_child_count(); i++) {
  641. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  642. if (se) {
  643. RES edited_res = se->get_edited_resource();
  644. if (p_for_script.is_valid() && edited_res.is_valid() && p_for_script != edited_res)
  645. continue;
  646. if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1)
  647. continue; //internal script, who cares
  648. uint64_t last_date = edited_res->get_last_modified_time();
  649. uint64_t date = FileAccess::get_modified_time(edited_res->get_path());
  650. if (last_date != date) {
  651. TreeItem *ti = disk_changed_list->create_item(r);
  652. ti->set_text(0, edited_res->get_path().get_file());
  653. if (!use_autoreload || se->is_unsaved()) {
  654. need_ask = true;
  655. }
  656. need_reload = true;
  657. }
  658. }
  659. }
  660. if (need_reload) {
  661. if (!need_ask) {
  662. script_editor->_reload_scripts();
  663. need_reload = false;
  664. } else {
  665. disk_changed->call_deferred("popup_centered_ratio", 0.5);
  666. }
  667. }
  668. return need_reload;
  669. }
  670. void ScriptEditor::_file_dialog_action(String p_file) {
  671. switch (file_dialog_option) {
  672. case FILE_NEW_TEXTFILE: {
  673. Error err;
  674. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  675. if (err) {
  676. memdelete(file);
  677. editor->show_warning(TTR("Error writing TextFile:") + "\n" + p_file, TTR("Error!"));
  678. break;
  679. }
  680. file->close();
  681. memdelete(file);
  682. FALLTHROUGH;
  683. }
  684. case FILE_OPEN: {
  685. List<String> extensions;
  686. ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
  687. if (extensions.find(p_file.get_extension())) {
  688. Ref<Script> scr = ResourceLoader::load(p_file);
  689. if (!scr.is_valid()) {
  690. editor->show_warning(TTR("Error: could not load file."), TTR("Error!"));
  691. file_dialog_option = -1;
  692. return;
  693. }
  694. edit(scr);
  695. file_dialog_option = -1;
  696. return;
  697. }
  698. Error error;
  699. Ref<TextFile> text_file = _load_text_file(p_file, &error);
  700. if (error != OK) {
  701. editor->show_warning(TTR("Error could not load file."), TTR("Error!"));
  702. }
  703. if (text_file.is_valid()) {
  704. edit(text_file);
  705. file_dialog_option = -1;
  706. return;
  707. }
  708. } break;
  709. case FILE_SAVE_AS: {
  710. ScriptEditorBase *current = _get_current_editor();
  711. String path = ProjectSettings::get_singleton()->localize_path(p_file);
  712. Error err = _save_text_file(current->get_edited_resource(), path);
  713. if (err != OK) {
  714. editor->show_accept(TTR("Error saving file!"), TTR("OK"));
  715. return;
  716. }
  717. ((Resource *)current->get_edited_resource().ptr())->set_path(path);
  718. _update_script_names();
  719. } break;
  720. case THEME_SAVE_AS: {
  721. if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) {
  722. editor->show_warning(TTR("Error while saving theme."), TTR("Error Saving"));
  723. }
  724. } break;
  725. case THEME_IMPORT: {
  726. if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) {
  727. editor->show_warning(TTR("Error importing theme."), TTR("Error Importing"));
  728. }
  729. } break;
  730. }
  731. file_dialog_option = -1;
  732. }
  733. Ref<Script> ScriptEditor::_get_current_script() {
  734. ScriptEditorBase *current = _get_current_editor();
  735. if (current) {
  736. Ref<Script> script = current->get_edited_resource();
  737. return script != NULL ? script : NULL;
  738. } else {
  739. return NULL;
  740. }
  741. }
  742. Array ScriptEditor::_get_open_scripts() const {
  743. Array ret;
  744. Vector<Ref<Script> > scripts = get_open_scripts();
  745. int scrits_amount = scripts.size();
  746. for (int idx_script = 0; idx_script < scrits_amount; idx_script++) {
  747. ret.push_back(scripts[idx_script]);
  748. }
  749. return ret;
  750. }
  751. void ScriptEditor::_menu_option(int p_option) {
  752. switch (p_option) {
  753. case FILE_NEW: {
  754. script_create_dialog->config("Node", "new_script");
  755. script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE);
  756. } break;
  757. case FILE_NEW_TEXTFILE: {
  758. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  759. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  760. file_dialog_option = FILE_NEW_TEXTFILE;
  761. file_dialog->clear_filters();
  762. file_dialog->popup_centered_ratio();
  763. file_dialog->set_title(TTR("New TextFile..."));
  764. } break;
  765. case FILE_OPEN: {
  766. file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  767. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  768. file_dialog_option = FILE_OPEN;
  769. List<String> extensions;
  770. ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
  771. file_dialog->clear_filters();
  772. for (int i = 0; i < extensions.size(); i++) {
  773. file_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  774. }
  775. file_dialog->popup_centered_ratio();
  776. file_dialog->set_title(TTR("Open File"));
  777. return;
  778. } break;
  779. case FILE_SAVE_ALL: {
  780. if (_test_script_times_on_disk())
  781. return;
  782. save_all_scripts();
  783. } break;
  784. case SEARCH_IN_FILES: {
  785. _on_find_in_files_requested("");
  786. } break;
  787. case SEARCH_HELP: {
  788. help_search_dialog->popup_dialog();
  789. } break;
  790. case SEARCH_WEBSITE: {
  791. OS::get_singleton()->shell_open("https://docs.godotengine.org/");
  792. } break;
  793. case REQUEST_DOCS: {
  794. OS::get_singleton()->shell_open("https://github.com/godotengine/godot-docs/issues/new");
  795. } break;
  796. case WINDOW_NEXT: {
  797. _history_forward();
  798. } break;
  799. case WINDOW_PREV: {
  800. _history_back();
  801. } break;
  802. case WINDOW_SORT: {
  803. _sort_list_on_update = true;
  804. _update_script_names();
  805. } break;
  806. case DEBUG_SHOW: {
  807. if (debugger) {
  808. bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW));
  809. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW), !visible);
  810. if (visible)
  811. debugger->hide();
  812. else
  813. debugger->show();
  814. }
  815. } break;
  816. case DEBUG_SHOW_KEEP_OPEN: {
  817. bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN));
  818. if (debugger)
  819. debugger->set_hide_on_stop(visible);
  820. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN), !visible);
  821. } break;
  822. case DEBUG_WITH_EXTERNAL_EDITOR: {
  823. bool debug_with_external_editor = !debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR));
  824. debugger->set_debug_with_external_editor(debug_with_external_editor);
  825. debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR), debug_with_external_editor);
  826. } break;
  827. case TOGGLE_SCRIPTS_PANEL: {
  828. list_split->set_visible(!list_split->is_visible());
  829. }
  830. }
  831. ScriptEditorBase *current = _get_current_editor();
  832. if (current) {
  833. switch (p_option) {
  834. case FILE_SAVE: {
  835. if (_test_script_times_on_disk())
  836. return;
  837. if (trim_trailing_whitespace_on_save)
  838. current->trim_trailing_whitespace();
  839. current->insert_final_newline();
  840. if (convert_indent_on_save) {
  841. if (use_space_indentation) {
  842. current->convert_indent_to_spaces();
  843. } else {
  844. current->convert_indent_to_tabs();
  845. }
  846. }
  847. Ref<TextFile> text_file = current->get_edited_resource();
  848. if (text_file != NULL) {
  849. current->apply_code();
  850. _save_text_file(text_file, text_file->get_path());
  851. break;
  852. }
  853. editor->save_resource(current->get_edited_resource());
  854. } break;
  855. case FILE_SAVE_AS: {
  856. if (trim_trailing_whitespace_on_save)
  857. current->trim_trailing_whitespace();
  858. current->insert_final_newline();
  859. if (convert_indent_on_save) {
  860. if (use_space_indentation) {
  861. current->convert_indent_to_spaces();
  862. } else {
  863. current->convert_indent_to_tabs();
  864. }
  865. }
  866. Ref<TextFile> text_file = current->get_edited_resource();
  867. if (text_file != NULL) {
  868. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  869. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  870. file_dialog_option = FILE_SAVE_AS;
  871. List<String> extensions;
  872. ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
  873. file_dialog->clear_filters();
  874. file_dialog->set_current_dir(text_file->get_path().get_base_dir());
  875. file_dialog->set_current_file(text_file->get_path().get_file());
  876. file_dialog->popup_centered_ratio();
  877. file_dialog->set_title(TTR("Save File As..."));
  878. break;
  879. }
  880. editor->push_item(Object::cast_to<Object>(current->get_edited_resource().ptr()));
  881. editor->save_resource_as(current->get_edited_resource());
  882. } break;
  883. case FILE_TOOL_RELOAD:
  884. case FILE_TOOL_RELOAD_SOFT: {
  885. current->reload(p_option == FILE_TOOL_RELOAD_SOFT);
  886. } break;
  887. case FILE_RUN: {
  888. Ref<Script> scr = current->get_edited_resource();
  889. if (scr == NULL || scr.is_null()) {
  890. EditorNode::get_singleton()->show_warning("Can't obtain the script for running.");
  891. break;
  892. }
  893. current->apply_code();
  894. Error err = scr->reload(false); //hard reload script before running always
  895. if (err != OK) {
  896. EditorNode::get_singleton()->show_warning("Script failed reloading, check console for errors.");
  897. return;
  898. }
  899. if (!scr->is_tool()) {
  900. EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run.");
  901. return;
  902. }
  903. if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) {
  904. EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode.");
  905. return;
  906. }
  907. Ref<EditorScript> es = memnew(EditorScript);
  908. es->set_script(scr.get_ref_ptr());
  909. es->set_editor(EditorNode::get_singleton());
  910. es->_run();
  911. EditorNode::get_undo_redo()->clear_history();
  912. } break;
  913. case FILE_CLOSE: {
  914. if (current->is_unsaved()) {
  915. _ask_close_current_unsaved_tab(current);
  916. } else {
  917. _close_current_tab();
  918. }
  919. } break;
  920. case FILE_COPY_PATH: {
  921. _copy_script_path();
  922. } break;
  923. case SHOW_IN_FILE_SYSTEM: {
  924. RES script = current->get_edited_resource();
  925. FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
  926. file_system_dock->navigate_to_path(script->get_path());
  927. // Ensure that the FileSystem dock is visible.
  928. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
  929. tab_container->set_current_tab(file_system_dock->get_position_in_parent());
  930. } break;
  931. case CLOSE_DOCS: {
  932. _close_docs_tab();
  933. } break;
  934. case CLOSE_OTHER_TABS: {
  935. _close_other_tabs();
  936. } break;
  937. case CLOSE_ALL: {
  938. _close_all_tabs();
  939. } break;
  940. case DEBUG_NEXT: {
  941. if (debugger)
  942. debugger->debug_next();
  943. } break;
  944. case DEBUG_STEP: {
  945. if (debugger)
  946. debugger->debug_step();
  947. } break;
  948. case DEBUG_BREAK: {
  949. if (debugger)
  950. debugger->debug_break();
  951. } break;
  952. case DEBUG_CONTINUE: {
  953. if (debugger)
  954. debugger->debug_continue();
  955. } break;
  956. case WINDOW_MOVE_UP: {
  957. if (tab_container->get_current_tab() > 0) {
  958. tab_container->move_child(current, tab_container->get_current_tab() - 1);
  959. tab_container->set_current_tab(tab_container->get_current_tab() - 1);
  960. _update_script_names();
  961. }
  962. } break;
  963. case WINDOW_MOVE_DOWN: {
  964. if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) {
  965. tab_container->move_child(current, tab_container->get_current_tab() + 1);
  966. tab_container->set_current_tab(tab_container->get_current_tab() + 1);
  967. _update_script_names();
  968. }
  969. } break;
  970. default: {
  971. if (p_option >= WINDOW_SELECT_BASE) {
  972. tab_container->set_current_tab(p_option - WINDOW_SELECT_BASE);
  973. script_list->select(p_option - WINDOW_SELECT_BASE);
  974. }
  975. }
  976. }
  977. } else {
  978. EditorHelp *help = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control());
  979. if (help) {
  980. switch (p_option) {
  981. case HELP_SEARCH_FIND: {
  982. help->popup_search();
  983. } break;
  984. case HELP_SEARCH_FIND_NEXT: {
  985. help->search_again();
  986. } break;
  987. case FILE_CLOSE: {
  988. _close_current_tab();
  989. } break;
  990. case CLOSE_DOCS: {
  991. _close_docs_tab();
  992. } break;
  993. case CLOSE_OTHER_TABS: {
  994. _close_other_tabs();
  995. } break;
  996. case CLOSE_ALL: {
  997. _close_all_tabs();
  998. } break;
  999. case WINDOW_MOVE_UP: {
  1000. if (tab_container->get_current_tab() > 0) {
  1001. tab_container->move_child(help, tab_container->get_current_tab() - 1);
  1002. tab_container->set_current_tab(tab_container->get_current_tab() - 1);
  1003. _update_script_names();
  1004. }
  1005. } break;
  1006. case WINDOW_MOVE_DOWN: {
  1007. if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) {
  1008. tab_container->move_child(help, tab_container->get_current_tab() + 1);
  1009. tab_container->set_current_tab(tab_container->get_current_tab() + 1);
  1010. _update_script_names();
  1011. }
  1012. } break;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. void ScriptEditor::_theme_option(int p_option) {
  1018. switch (p_option) {
  1019. case THEME_IMPORT: {
  1020. file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  1021. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1022. file_dialog_option = THEME_IMPORT;
  1023. file_dialog->clear_filters();
  1024. file_dialog->add_filter("*.tet");
  1025. file_dialog->popup_centered_ratio();
  1026. file_dialog->set_title(TTR("Import Theme"));
  1027. } break;
  1028. case THEME_RELOAD: {
  1029. EditorSettings::get_singleton()->load_text_editor_theme();
  1030. } break;
  1031. case THEME_SAVE: {
  1032. if (EditorSettings::get_singleton()->is_default_text_editor_theme()) {
  1033. ScriptEditor::_show_save_theme_as_dialog();
  1034. } else if (!EditorSettings::get_singleton()->save_text_editor_theme()) {
  1035. editor->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
  1036. }
  1037. } break;
  1038. case THEME_SAVE_AS: {
  1039. ScriptEditor::_show_save_theme_as_dialog();
  1040. } break;
  1041. }
  1042. }
  1043. void ScriptEditor::_show_save_theme_as_dialog() {
  1044. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1045. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1046. file_dialog_option = THEME_SAVE_AS;
  1047. file_dialog->clear_filters();
  1048. file_dialog->add_filter("*.tet");
  1049. file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme")));
  1050. file_dialog->popup_centered_ratio();
  1051. file_dialog->set_title(TTR("Save Theme As..."));
  1052. }
  1053. void ScriptEditor::_tab_changed(int p_which) {
  1054. ensure_select_current();
  1055. }
  1056. void ScriptEditor::_notification(int p_what) {
  1057. switch (p_what) {
  1058. case NOTIFICATION_ENTER_TREE: {
  1059. editor->connect("play_pressed", this, "_editor_play");
  1060. editor->connect("pause_pressed", this, "_editor_pause");
  1061. editor->connect("stop_pressed", this, "_editor_stop");
  1062. editor->connect("script_add_function_request", this, "_add_callback");
  1063. editor->connect("resource_saved", this, "_res_saved_callback");
  1064. script_list->connect("item_selected", this, "_script_selected");
  1065. members_overview->connect("item_selected", this, "_members_overview_selected");
  1066. help_overview->connect("item_selected", this, "_help_overview_selected");
  1067. script_split->connect("dragged", this, "_script_split_dragged");
  1068. autosave_timer->connect("timeout", this, "_autosave_scripts");
  1069. {
  1070. float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs");
  1071. if (autosave_time > 0) {
  1072. autosave_timer->set_wait_time(autosave_time);
  1073. autosave_timer->start();
  1074. } else {
  1075. autosave_timer->stop();
  1076. }
  1077. }
  1078. EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
  1079. help_search->set_icon(get_icon("HelpSearch", "EditorIcons"));
  1080. site_search->set_icon(get_icon("Instance", "EditorIcons"));
  1081. request_docs->set_icon(get_icon("Issue", "EditorIcons"));
  1082. script_forward->set_icon(get_icon("Forward", "EditorIcons"));
  1083. script_back->set_icon(get_icon("Back", "EditorIcons"));
  1084. members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons"));
  1085. } break;
  1086. case NOTIFICATION_READY: {
  1087. get_tree()->connect("tree_changed", this, "_tree_changed");
  1088. editor->get_inspector_dock()->connect("request_help", this, "_request_help");
  1089. editor->connect("request_help_search", this, "_help_search");
  1090. } break;
  1091. case NOTIFICATION_EXIT_TREE: {
  1092. editor->disconnect("play_pressed", this, "_editor_play");
  1093. editor->disconnect("pause_pressed", this, "_editor_pause");
  1094. editor->disconnect("stop_pressed", this, "_editor_stop");
  1095. } break;
  1096. case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
  1097. _test_script_times_on_disk();
  1098. _update_modified_scripts_for_external_editor();
  1099. } break;
  1100. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1101. help_search->set_icon(get_icon("HelpSearch", "EditorIcons"));
  1102. site_search->set_icon(get_icon("Instance", "EditorIcons"));
  1103. script_forward->set_icon(get_icon("Forward", "EditorIcons"));
  1104. script_back->set_icon(get_icon("Back", "EditorIcons"));
  1105. members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons"));
  1106. filename->add_style_override("normal", editor->get_gui_base()->get_stylebox("normal", "LineEdit"));
  1107. recent_scripts->set_as_minsize();
  1108. } break;
  1109. case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: {
  1110. if (is_visible()) {
  1111. find_in_files_button->show();
  1112. } else {
  1113. if (find_in_files->is_visible_in_tree()) {
  1114. editor->hide_bottom_panel();
  1115. }
  1116. find_in_files_button->hide();
  1117. }
  1118. } break;
  1119. default:
  1120. break;
  1121. }
  1122. }
  1123. bool ScriptEditor::can_take_away_focus() const {
  1124. ScriptEditorBase *current = _get_current_editor();
  1125. if (current)
  1126. return current->can_lose_focus_on_node_selection();
  1127. else
  1128. return true;
  1129. }
  1130. void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
  1131. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1132. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1133. if (se) {
  1134. Ref<Script> script = se->get_edited_resource();
  1135. if (script == NULL || !script.is_valid())
  1136. continue;
  1137. if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
  1138. _close_tab(i);
  1139. i--;
  1140. }
  1141. }
  1142. }
  1143. }
  1144. void ScriptEditor::edited_scene_changed() {
  1145. _update_modified_scripts_for_external_editor();
  1146. }
  1147. void ScriptEditor::notify_script_close(const Ref<Script> &p_script) {
  1148. emit_signal("script_close", p_script);
  1149. }
  1150. void ScriptEditor::notify_script_changed(const Ref<Script> &p_script) {
  1151. emit_signal("editor_script_changed", p_script);
  1152. }
  1153. void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
  1154. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1155. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1156. if (!se)
  1157. continue;
  1158. Ref<Script> script = se->get_edited_resource();
  1159. if (script == NULL) {
  1160. continue;
  1161. }
  1162. List<int> bpoints;
  1163. se->get_breakpoints(&bpoints);
  1164. String base = script->get_path();
  1165. ERR_CONTINUE(base.begins_with("local://") || base == "");
  1166. for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
  1167. p_breakpoints->push_back(base + ":" + itos(E->get() + 1));
  1168. }
  1169. }
  1170. }
  1171. void ScriptEditor::ensure_focus_current() {
  1172. if (!is_inside_tree())
  1173. return;
  1174. ScriptEditorBase *current = _get_current_editor();
  1175. if (current)
  1176. current->ensure_focus();
  1177. }
  1178. void ScriptEditor::_members_overview_selected(int p_idx) {
  1179. ScriptEditorBase *se = _get_current_editor();
  1180. if (!se) {
  1181. return;
  1182. }
  1183. // Go to the member's line and reset the cursor column. We can't change scroll_position
  1184. // directly until we have gone to the line first, since code might be folded.
  1185. se->goto_line(members_overview->get_item_metadata(p_idx));
  1186. Dictionary state = se->get_edit_state();
  1187. state["column"] = 0;
  1188. state["scroll_position"] = members_overview->get_item_metadata(p_idx);
  1189. se->set_edit_state(state);
  1190. }
  1191. void ScriptEditor::_help_overview_selected(int p_idx) {
  1192. Node *current = tab_container->get_child(tab_container->get_current_tab());
  1193. EditorHelp *se = Object::cast_to<EditorHelp>(current);
  1194. if (!se) {
  1195. return;
  1196. }
  1197. se->scroll_to_section(help_overview->get_item_metadata(p_idx));
  1198. }
  1199. void ScriptEditor::_script_selected(int p_idx) {
  1200. grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing
  1201. _go_to_tab(script_list->get_item_metadata(p_idx));
  1202. grab_focus_block = false;
  1203. }
  1204. void ScriptEditor::ensure_select_current() {
  1205. if (tab_container->get_child_count() && tab_container->get_current_tab() >= 0) {
  1206. ScriptEditorBase *se = _get_current_editor();
  1207. if (se) {
  1208. if (!grab_focus_block && is_visible_in_tree())
  1209. se->ensure_focus();
  1210. }
  1211. }
  1212. _update_selected_editor_menu();
  1213. }
  1214. void ScriptEditor::_find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used) {
  1215. if (p_current != p_base && p_current->get_owner() != p_base)
  1216. return;
  1217. if (p_current->get_script_instance()) {
  1218. Ref<Script> scr = p_current->get_script();
  1219. if (scr.is_valid())
  1220. used.insert(scr);
  1221. }
  1222. for (int i = 0; i < p_current->get_child_count(); i++) {
  1223. _find_scripts(p_base, p_current->get_child(i), used);
  1224. }
  1225. }
  1226. struct _ScriptEditorItemData {
  1227. String name;
  1228. String sort_key;
  1229. Ref<Texture> icon;
  1230. int index;
  1231. String tooltip;
  1232. bool used;
  1233. int category;
  1234. Node *ref;
  1235. bool operator<(const _ScriptEditorItemData &id) const {
  1236. if (category == id.category) {
  1237. if (sort_key == id.sort_key) {
  1238. return index < id.index;
  1239. } else {
  1240. return sort_key < id.sort_key;
  1241. }
  1242. } else {
  1243. return category < id.category;
  1244. }
  1245. }
  1246. };
  1247. void ScriptEditor::_update_members_overview_visibility() {
  1248. ScriptEditorBase *se = _get_current_editor();
  1249. if (!se) {
  1250. members_overview_alphabeta_sort_button->set_visible(false);
  1251. members_overview->set_visible(false);
  1252. overview_vbox->set_visible(false);
  1253. return;
  1254. }
  1255. if (members_overview_enabled && se->show_members_overview()) {
  1256. members_overview_alphabeta_sort_button->set_visible(true);
  1257. members_overview->set_visible(true);
  1258. overview_vbox->set_visible(true);
  1259. } else {
  1260. members_overview_alphabeta_sort_button->set_visible(false);
  1261. members_overview->set_visible(false);
  1262. overview_vbox->set_visible(false);
  1263. }
  1264. }
  1265. void ScriptEditor::_toggle_members_overview_alpha_sort(bool p_alphabetic_sort) {
  1266. EditorSettings::get_singleton()->set("text_editor/tools/sort_members_outline_alphabetically", p_alphabetic_sort);
  1267. _update_members_overview();
  1268. }
  1269. void ScriptEditor::_update_members_overview() {
  1270. members_overview->clear();
  1271. ScriptEditorBase *se = _get_current_editor();
  1272. if (!se) {
  1273. return;
  1274. }
  1275. Vector<String> functions = se->get_functions();
  1276. if (EditorSettings::get_singleton()->get("text_editor/tools/sort_members_outline_alphabetically")) {
  1277. functions.sort();
  1278. }
  1279. for (int i = 0; i < functions.size(); i++) {
  1280. members_overview->add_item(functions[i].get_slice(":", 0));
  1281. members_overview->set_item_metadata(i, functions[i].get_slice(":", 1).to_int() - 1);
  1282. }
  1283. String path = se->get_edited_resource()->get_path();
  1284. bool built_in = !path.is_resource_file();
  1285. String name = built_in ? path.get_file() : se->get_name();
  1286. filename->set_text(name);
  1287. }
  1288. void ScriptEditor::_update_help_overview_visibility() {
  1289. int selected = tab_container->get_current_tab();
  1290. if (selected < 0 || selected >= tab_container->get_child_count()) {
  1291. help_overview->set_visible(false);
  1292. return;
  1293. }
  1294. Node *current = tab_container->get_child(tab_container->get_current_tab());
  1295. EditorHelp *se = Object::cast_to<EditorHelp>(current);
  1296. if (!se) {
  1297. help_overview->set_visible(false);
  1298. return;
  1299. }
  1300. if (help_overview_enabled) {
  1301. members_overview_alphabeta_sort_button->set_visible(false);
  1302. help_overview->set_visible(true);
  1303. overview_vbox->set_visible(true);
  1304. filename->set_text(se->get_name());
  1305. } else {
  1306. help_overview->set_visible(false);
  1307. overview_vbox->set_visible(false);
  1308. }
  1309. }
  1310. void ScriptEditor::_update_help_overview() {
  1311. help_overview->clear();
  1312. int selected = tab_container->get_current_tab();
  1313. if (selected < 0 || selected >= tab_container->get_child_count())
  1314. return;
  1315. Node *current = tab_container->get_child(tab_container->get_current_tab());
  1316. EditorHelp *se = Object::cast_to<EditorHelp>(current);
  1317. if (!se) {
  1318. return;
  1319. }
  1320. Vector<Pair<String, int> > sections = se->get_sections();
  1321. for (int i = 0; i < sections.size(); i++) {
  1322. help_overview->add_item(sections[i].first);
  1323. help_overview->set_item_metadata(i, sections[i].second);
  1324. }
  1325. }
  1326. void ScriptEditor::_update_script_colors() {
  1327. bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled");
  1328. bool highlight_current = EditorSettings::get_singleton()->get("text_editor/open_scripts/highlight_current_script");
  1329. int hist_size = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_history_size");
  1330. Color hot_color = get_color("accent_color", "Editor");
  1331. Color cold_color = get_color("font_color", "Editor");
  1332. for (int i = 0; i < script_list->get_item_count(); i++) {
  1333. int c = script_list->get_item_metadata(i);
  1334. Node *n = tab_container->get_child(c);
  1335. if (!n)
  1336. continue;
  1337. script_list->set_item_custom_bg_color(i, Color(0, 0, 0, 0));
  1338. bool current = tab_container->get_current_tab() == c;
  1339. if (current && highlight_current) {
  1340. script_list->set_item_custom_bg_color(i, EditorSettings::get_singleton()->get("text_editor/open_scripts/current_script_background_color"));
  1341. } else if (script_temperature_enabled) {
  1342. if (!n->has_meta("__editor_pass")) {
  1343. continue;
  1344. }
  1345. int pass = n->get_meta("__editor_pass");
  1346. int h = edit_pass - pass;
  1347. if (h > hist_size) {
  1348. continue;
  1349. }
  1350. int non_zero_hist_size = (hist_size == 0) ? 1 : hist_size;
  1351. float v = Math::ease((edit_pass - pass) / float(non_zero_hist_size), 0.4);
  1352. script_list->set_item_custom_fg_color(i, hot_color.linear_interpolate(cold_color, v));
  1353. }
  1354. }
  1355. }
  1356. void ScriptEditor::_update_script_names() {
  1357. if (restoring_layout)
  1358. return;
  1359. Set<Ref<Script> > used;
  1360. Node *edited = EditorNode::get_singleton()->get_edited_scene();
  1361. if (edited) {
  1362. _find_scripts(edited, edited, used);
  1363. }
  1364. script_list->clear();
  1365. bool split_script_help = EditorSettings::get_singleton()->get("text_editor/open_scripts/group_help_pages");
  1366. ScriptSortBy sort_by = (ScriptSortBy)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/sort_scripts_by");
  1367. ScriptListName display_as = (ScriptListName)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/list_script_names_as");
  1368. Vector<_ScriptEditorItemData> sedata;
  1369. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1370. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1371. if (se) {
  1372. Ref<Texture> icon = se->get_icon();
  1373. String path = se->get_edited_resource()->get_path();
  1374. bool built_in = !path.is_resource_file();
  1375. String name;
  1376. if (built_in) {
  1377. name = path.get_file();
  1378. String resource_name = se->get_edited_resource()->get_name();
  1379. if (resource_name != "") {
  1380. name = name.substr(0, name.find("::", 0) + 2) + resource_name;
  1381. }
  1382. } else {
  1383. name = se->get_name();
  1384. }
  1385. _ScriptEditorItemData sd;
  1386. sd.icon = icon;
  1387. sd.name = name;
  1388. sd.tooltip = path;
  1389. sd.index = i;
  1390. sd.used = used.has(se->get_edited_resource());
  1391. sd.category = 0;
  1392. sd.ref = se;
  1393. switch (sort_by) {
  1394. case SORT_BY_NAME: {
  1395. sd.sort_key = name.to_lower();
  1396. } break;
  1397. case SORT_BY_PATH: {
  1398. sd.sort_key = path;
  1399. } break;
  1400. case SORT_BY_NONE: {
  1401. sd.sort_key = "";
  1402. } break;
  1403. }
  1404. switch (display_as) {
  1405. case DISPLAY_NAME: {
  1406. sd.name = name;
  1407. } break;
  1408. case DISPLAY_DIR_AND_NAME: {
  1409. if (!path.get_base_dir().get_file().empty()) {
  1410. sd.name = path.get_base_dir().get_file().plus_file(name);
  1411. } else {
  1412. sd.name = name;
  1413. }
  1414. } break;
  1415. case DISPLAY_FULL_PATH: {
  1416. sd.name = path;
  1417. } break;
  1418. }
  1419. sedata.push_back(sd);
  1420. }
  1421. EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
  1422. if (eh) {
  1423. String name = eh->get_class();
  1424. Ref<Texture> icon = get_icon("Help", "EditorIcons");
  1425. String tooltip = vformat(TTR("%s Class Reference"), name);
  1426. _ScriptEditorItemData sd;
  1427. sd.icon = icon;
  1428. sd.name = name;
  1429. sd.sort_key = name.to_lower();
  1430. sd.tooltip = tooltip;
  1431. sd.index = i;
  1432. sd.used = false;
  1433. sd.category = split_script_help ? 1 : 0;
  1434. sd.ref = eh;
  1435. sedata.push_back(sd);
  1436. }
  1437. }
  1438. if (_sort_list_on_update && !sedata.empty()) {
  1439. sedata.sort();
  1440. // change actual order of tab_container so that the order can be rearranged by user
  1441. int cur_tab = tab_container->get_current_tab();
  1442. int prev_tab = tab_container->get_previous_tab();
  1443. int new_cur_tab = -1;
  1444. int new_prev_tab = -1;
  1445. for (int i = 0; i < sedata.size(); i++) {
  1446. tab_container->move_child(sedata[i].ref, i);
  1447. if (new_prev_tab == -1 && sedata[i].index == prev_tab) {
  1448. new_prev_tab = i;
  1449. }
  1450. if (new_cur_tab == -1 && sedata[i].index == cur_tab) {
  1451. new_cur_tab = i;
  1452. }
  1453. }
  1454. tab_container->set_current_tab(new_prev_tab);
  1455. tab_container->set_current_tab(new_cur_tab);
  1456. _sort_list_on_update = false;
  1457. }
  1458. for (int i = 0; i < sedata.size(); i++) {
  1459. script_list->add_item(sedata[i].name, sedata[i].icon);
  1460. int index = script_list->get_item_count() - 1;
  1461. script_list->set_item_tooltip(index, sedata[i].tooltip);
  1462. script_list->set_item_metadata(index, sedata[i].index);
  1463. if (sedata[i].used) {
  1464. script_list->set_item_custom_bg_color(index, Color(88 / 255.0, 88 / 255.0, 60 / 255.0));
  1465. }
  1466. if (tab_container->get_current_tab() == sedata[i].index) {
  1467. script_list->select(index);
  1468. script_name_label->set_text(sedata[i].name);
  1469. script_icon->set_texture(sedata[i].icon);
  1470. }
  1471. }
  1472. if (!waiting_update_names) {
  1473. _update_members_overview();
  1474. _update_help_overview();
  1475. } else {
  1476. waiting_update_names = false;
  1477. }
  1478. _update_members_overview_visibility();
  1479. _update_help_overview_visibility();
  1480. _update_script_colors();
  1481. }
  1482. void ScriptEditor::_update_script_connections() {
  1483. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1484. ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(tab_container->get_child(i));
  1485. if (!ste) {
  1486. continue;
  1487. }
  1488. ste->_update_connected_methods();
  1489. }
  1490. }
  1491. Ref<TextFile> ScriptEditor::_load_text_file(const String &p_path, Error *r_error) {
  1492. if (r_error) {
  1493. *r_error = ERR_FILE_CANT_OPEN;
  1494. }
  1495. String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
  1496. String path = ResourceLoader::path_remap(local_path);
  1497. TextFile *text_file = memnew(TextFile);
  1498. Ref<TextFile> text_res(text_file);
  1499. Error err = text_file->load_text(path);
  1500. if (err != OK) {
  1501. ERR_FAIL_COND_V(err != OK, RES());
  1502. }
  1503. text_file->set_file_path(local_path);
  1504. text_file->set_path(local_path, true);
  1505. if (ResourceLoader::get_timestamp_on_load()) {
  1506. text_file->set_last_modified_time(FileAccess::get_modified_time(path));
  1507. }
  1508. if (r_error) {
  1509. *r_error = OK;
  1510. }
  1511. return text_res;
  1512. }
  1513. Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_path) {
  1514. Ref<TextFile> sqscr = p_text_file;
  1515. ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER);
  1516. String source = sqscr->get_text();
  1517. Error err;
  1518. FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
  1519. if (err) {
  1520. ERR_FAIL_COND_V(err, err);
  1521. }
  1522. file->store_string(source);
  1523. if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
  1524. memdelete(file);
  1525. return ERR_CANT_CREATE;
  1526. }
  1527. file->close();
  1528. memdelete(file);
  1529. if (ResourceSaver::get_timestamp_on_save()) {
  1530. p_text_file->set_last_modified_time(FileAccess::get_modified_time(p_path));
  1531. }
  1532. _res_saved_callback(sqscr);
  1533. return OK;
  1534. }
  1535. bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_grab_focus) {
  1536. if (p_resource.is_null())
  1537. return false;
  1538. Ref<Script> script = p_resource;
  1539. // refuse to open built-in if scene is not loaded
  1540. // see if already has it
  1541. bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
  1542. const bool should_open = open_dominant || !EditorNode::get_singleton()->is_changing_scene();
  1543. if (script != NULL && script->get_language()->overrides_external_editor()) {
  1544. if (should_open) {
  1545. Error err = script->get_language()->open_in_external_editor(script, p_line >= 0 ? p_line : 0, p_col);
  1546. if (err != OK)
  1547. ERR_PRINT("Couldn't open script in the overridden external text editor");
  1548. }
  1549. return false;
  1550. }
  1551. if ((debugger->get_dump_stack_script() != p_resource || debugger->get_debug_with_external_editor()) &&
  1552. p_resource->get_path().is_resource_file() &&
  1553. p_resource->get_class_name() != StringName("VisualScript") &&
  1554. bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
  1555. String path = EditorSettings::get_singleton()->get("text_editor/external/exec_path");
  1556. String flags = EditorSettings::get_singleton()->get("text_editor/external/exec_flags");
  1557. List<String> args;
  1558. bool has_file_flag = false;
  1559. String script_path = ProjectSettings::get_singleton()->globalize_path(p_resource->get_path());
  1560. if (flags.size()) {
  1561. String project_path = ProjectSettings::get_singleton()->get_resource_path();
  1562. flags = flags.replacen("{line}", itos(p_line > 0 ? p_line : 0));
  1563. flags = flags.replacen("{col}", itos(p_col));
  1564. flags = flags.strip_edges().replace("\\\\", "\\");
  1565. int from = 0;
  1566. int num_chars = 0;
  1567. bool inside_quotes = false;
  1568. for (int i = 0; i < flags.size(); i++) {
  1569. if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
  1570. if (!inside_quotes) {
  1571. from++;
  1572. }
  1573. inside_quotes = !inside_quotes;
  1574. } else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
  1575. String arg = flags.substr(from, num_chars);
  1576. if (arg.find("{file}") != -1) {
  1577. has_file_flag = true;
  1578. }
  1579. // do path replacement here, else there will be issues with spaces and quotes
  1580. arg = arg.replacen("{project}", project_path);
  1581. arg = arg.replacen("{file}", script_path);
  1582. args.push_back(arg);
  1583. from = i + 1;
  1584. num_chars = 0;
  1585. } else {
  1586. num_chars++;
  1587. }
  1588. }
  1589. }
  1590. // Default to passing script path if no {file} flag is specified.
  1591. if (!has_file_flag) {
  1592. args.push_back(script_path);
  1593. }
  1594. Error err = OS::get_singleton()->execute(path, args, false);
  1595. if (err == OK)
  1596. return false;
  1597. WARN_PRINT("Couldn't open external text editor, using internal");
  1598. }
  1599. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1600. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1601. if (!se)
  1602. continue;
  1603. if ((script != NULL && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) {
  1604. if (should_open) {
  1605. if (tab_container->get_current_tab() != i) {
  1606. _go_to_tab(i);
  1607. script_list->select(script_list->find_metadata(i));
  1608. }
  1609. if (is_visible_in_tree())
  1610. se->ensure_focus();
  1611. if (p_line > 0) {
  1612. se->goto_line(p_line - 1);
  1613. }
  1614. }
  1615. return true;
  1616. }
  1617. }
  1618. // doesn't have it, make a new one
  1619. ScriptEditorBase *se = NULL;
  1620. for (int i = script_editor_func_count - 1; i >= 0; i--) {
  1621. se = script_editor_funcs[i](p_resource);
  1622. if (se)
  1623. break;
  1624. }
  1625. ERR_FAIL_COND_V(!se, false);
  1626. bool highlighter_set = false;
  1627. for (int i = 0; i < syntax_highlighters_func_count; i++) {
  1628. SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
  1629. se->add_syntax_highlighter(highlighter);
  1630. if (script != NULL && !highlighter_set) {
  1631. List<String> languages = highlighter->get_supported_languages();
  1632. if (languages.find(script->get_language()->get_name())) {
  1633. se->set_syntax_highlighter(highlighter);
  1634. highlighter_set = true;
  1635. }
  1636. }
  1637. }
  1638. tab_container->add_child(se);
  1639. se->set_edited_resource(p_resource);
  1640. se->set_tooltip_request_func("_get_debug_tooltip", this);
  1641. if (se->get_edit_menu()) {
  1642. se->get_edit_menu()->hide();
  1643. menu_hb->add_child(se->get_edit_menu());
  1644. menu_hb->move_child(se->get_edit_menu(), 1);
  1645. }
  1646. if (p_grab_focus) {
  1647. _go_to_tab(tab_container->get_tab_count() - 1);
  1648. }
  1649. _sort_list_on_update = true;
  1650. _update_script_names();
  1651. _save_layout();
  1652. se->connect("name_changed", this, "_update_script_names");
  1653. se->connect("edited_script_changed", this, "_script_changed");
  1654. se->connect("request_help", this, "_help_search");
  1655. se->connect("request_open_script_at_line", this, "_goto_script_line");
  1656. se->connect("go_to_help", this, "_help_class_goto");
  1657. se->connect("request_save_history", this, "_save_history");
  1658. se->connect("search_in_files_requested", this, "_on_find_in_files_requested");
  1659. //test for modification, maybe the script was not edited but was loaded
  1660. _test_script_times_on_disk(p_resource);
  1661. _update_modified_scripts_for_external_editor(p_resource);
  1662. if (p_line > 0) {
  1663. se->goto_line(p_line - 1);
  1664. }
  1665. notify_script_changed(p_resource);
  1666. _add_recent_script(p_resource->get_path());
  1667. return true;
  1668. }
  1669. void ScriptEditor::save_all_scripts() {
  1670. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1671. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1672. if (!se)
  1673. continue;
  1674. if (convert_indent_on_save) {
  1675. if (use_space_indentation) {
  1676. se->convert_indent_to_spaces();
  1677. } else {
  1678. se->convert_indent_to_tabs();
  1679. }
  1680. }
  1681. if (trim_trailing_whitespace_on_save) {
  1682. se->trim_trailing_whitespace();
  1683. }
  1684. se->insert_final_newline();
  1685. if (!se->is_unsaved())
  1686. continue;
  1687. RES edited_res = se->get_edited_resource();
  1688. if (edited_res.is_valid()) {
  1689. se->apply_code();
  1690. }
  1691. if (edited_res->get_path() != "" && edited_res->get_path().find("local://") == -1 && edited_res->get_path().find("::") == -1) {
  1692. Ref<TextFile> text_file = edited_res;
  1693. if (text_file != NULL) {
  1694. _save_text_file(text_file, text_file->get_path());
  1695. continue;
  1696. }
  1697. editor->save_resource(edited_res); //external script, save it
  1698. }
  1699. }
  1700. _update_script_names();
  1701. EditorFileSystem::get_singleton()->update_script_classes();
  1702. }
  1703. void ScriptEditor::apply_scripts() const {
  1704. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1705. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1706. if (!se)
  1707. continue;
  1708. se->apply_code();
  1709. }
  1710. }
  1711. void ScriptEditor::open_script_create_dialog(const String &p_base_name, const String &p_base_path) {
  1712. _menu_option(FILE_NEW);
  1713. script_create_dialog->config(p_base_name, p_base_path);
  1714. }
  1715. void ScriptEditor::_editor_play() {
  1716. debugger->start();
  1717. debug_menu->get_popup()->grab_focus();
  1718. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true);
  1719. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true);
  1720. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), false);
  1721. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true);
  1722. }
  1723. void ScriptEditor::_editor_pause() {
  1724. }
  1725. void ScriptEditor::_editor_stop() {
  1726. debugger->stop();
  1727. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true);
  1728. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true);
  1729. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true);
  1730. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true);
  1731. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1732. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1733. if (!se) {
  1734. continue;
  1735. }
  1736. se->set_debugger_active(false);
  1737. }
  1738. }
  1739. void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PoolStringArray &p_args) {
  1740. ERR_FAIL_COND(!p_obj);
  1741. Ref<Script> script = p_obj->get_script();
  1742. ERR_FAIL_COND(!script.is_valid());
  1743. editor->push_item(script.ptr());
  1744. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1745. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1746. if (!se)
  1747. continue;
  1748. if (se->get_edited_resource() != script)
  1749. continue;
  1750. se->add_callback(p_function, p_args);
  1751. _go_to_tab(i);
  1752. script_list->select(script_list->find_metadata(i));
  1753. break;
  1754. }
  1755. }
  1756. void ScriptEditor::_save_layout() {
  1757. if (restoring_layout) {
  1758. return;
  1759. }
  1760. editor->save_layout();
  1761. }
  1762. void ScriptEditor::_editor_settings_changed() {
  1763. trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save");
  1764. convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save");
  1765. use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type");
  1766. members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview");
  1767. help_overview_enabled = EditorSettings::get_singleton()->get("text_editor/help/show_help_index");
  1768. _update_members_overview_visibility();
  1769. _update_help_overview_visibility();
  1770. float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs");
  1771. if (autosave_time > 0) {
  1772. autosave_timer->set_wait_time(autosave_time);
  1773. autosave_timer->start();
  1774. } else {
  1775. autosave_timer->stop();
  1776. }
  1777. if (current_theme == "") {
  1778. current_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme");
  1779. } else if (current_theme != EditorSettings::get_singleton()->get("text_editor/theme/color_theme")) {
  1780. current_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme");
  1781. EditorSettings::get_singleton()->load_text_editor_theme();
  1782. }
  1783. for (int i = 0; i < tab_container->get_child_count(); i++) {
  1784. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  1785. if (!se)
  1786. continue;
  1787. se->update_settings();
  1788. }
  1789. _update_script_colors();
  1790. _update_script_names();
  1791. ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true));
  1792. }
  1793. void ScriptEditor::_autosave_scripts() {
  1794. save_all_scripts();
  1795. }
  1796. void ScriptEditor::_tree_changed() {
  1797. if (waiting_update_names)
  1798. return;
  1799. waiting_update_names = true;
  1800. call_deferred("_update_script_names");
  1801. call_deferred("_update_script_connections");
  1802. }
  1803. void ScriptEditor::_script_split_dragged(float) {
  1804. _save_layout();
  1805. }
  1806. Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1807. if (tab_container->get_child_count() == 0)
  1808. return Variant();
  1809. Node *cur_node = tab_container->get_child(tab_container->get_current_tab());
  1810. HBoxContainer *drag_preview = memnew(HBoxContainer);
  1811. String preview_name = "";
  1812. Ref<Texture> preview_icon;
  1813. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(cur_node);
  1814. if (se) {
  1815. preview_name = se->get_name();
  1816. preview_icon = se->get_icon();
  1817. }
  1818. EditorHelp *eh = Object::cast_to<EditorHelp>(cur_node);
  1819. if (eh) {
  1820. preview_name = eh->get_class();
  1821. preview_icon = get_icon("Help", "EditorIcons");
  1822. }
  1823. if (!preview_icon.is_null()) {
  1824. TextureRect *tf = memnew(TextureRect);
  1825. tf->set_texture(preview_icon);
  1826. drag_preview->add_child(tf);
  1827. }
  1828. Label *label = memnew(Label(preview_name));
  1829. drag_preview->add_child(label);
  1830. set_drag_preview(drag_preview);
  1831. Dictionary drag_data;
  1832. drag_data["type"] = "script_list_element"; // using a custom type because node caused problems when dragging to scene tree
  1833. drag_data["script_list_element"] = cur_node;
  1834. return drag_data;
  1835. }
  1836. bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1837. Dictionary d = p_data;
  1838. if (!d.has("type"))
  1839. return false;
  1840. if (String(d["type"]) == "script_list_element") {
  1841. Node *node = d["script_list_element"];
  1842. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
  1843. if (se) {
  1844. return true;
  1845. }
  1846. EditorHelp *eh = Object::cast_to<EditorHelp>(node);
  1847. if (eh) {
  1848. return true;
  1849. }
  1850. }
  1851. if (String(d["type"]) == "nodes") {
  1852. Array nodes = d["nodes"];
  1853. if (nodes.size() == 0)
  1854. return false;
  1855. Node *node = get_node((nodes[0]));
  1856. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
  1857. if (se) {
  1858. return true;
  1859. }
  1860. EditorHelp *eh = Object::cast_to<EditorHelp>(node);
  1861. if (eh) {
  1862. return true;
  1863. }
  1864. }
  1865. if (String(d["type"]) == "files") {
  1866. Vector<String> files = d["files"];
  1867. if (files.size() == 0)
  1868. return false; //weird
  1869. for (int i = 0; i < files.size(); i++) {
  1870. String file = files[i];
  1871. if (file == "" || !FileAccess::exists(file))
  1872. continue;
  1873. Ref<Script> scr = ResourceLoader::load(file);
  1874. if (scr.is_valid()) {
  1875. return true;
  1876. }
  1877. }
  1878. return true;
  1879. }
  1880. return false;
  1881. }
  1882. void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1883. if (!can_drop_data_fw(p_point, p_data, p_from))
  1884. return;
  1885. Dictionary d = p_data;
  1886. if (!d.has("type"))
  1887. return;
  1888. if (String(d["type"]) == "script_list_element") {
  1889. Node *node = d["script_list_element"];
  1890. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
  1891. EditorHelp *eh = Object::cast_to<EditorHelp>(node);
  1892. if (se || eh) {
  1893. int new_index = script_list->get_item_at_position(p_point);
  1894. tab_container->move_child(node, new_index);
  1895. tab_container->set_current_tab(new_index);
  1896. _update_script_names();
  1897. }
  1898. }
  1899. if (String(d["type"]) == "nodes") {
  1900. Array nodes = d["nodes"];
  1901. if (nodes.size() == 0)
  1902. return;
  1903. Node *node = get_node(nodes[0]);
  1904. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
  1905. EditorHelp *eh = Object::cast_to<EditorHelp>(node);
  1906. if (se || eh) {
  1907. int new_index = script_list->get_item_at_position(p_point);
  1908. tab_container->move_child(node, new_index);
  1909. tab_container->set_current_tab(new_index);
  1910. _update_script_names();
  1911. }
  1912. }
  1913. if (String(d["type"]) == "files") {
  1914. Vector<String> files = d["files"];
  1915. int new_index = script_list->get_item_at_position(p_point);
  1916. int num_tabs_before = tab_container->get_child_count();
  1917. for (int i = 0; i < files.size(); i++) {
  1918. String file = files[i];
  1919. if (file == "" || !FileAccess::exists(file))
  1920. continue;
  1921. Ref<Script> scr = ResourceLoader::load(file);
  1922. if (scr.is_valid()) {
  1923. edit(scr);
  1924. if (tab_container->get_child_count() > num_tabs_before) {
  1925. tab_container->move_child(tab_container->get_child(tab_container->get_child_count() - 1), new_index);
  1926. num_tabs_before = tab_container->get_child_count();
  1927. } else {
  1928. tab_container->move_child(tab_container->get_child(tab_container->get_current_tab()), new_index);
  1929. }
  1930. }
  1931. }
  1932. tab_container->set_current_tab(new_index);
  1933. _update_script_names();
  1934. }
  1935. }
  1936. void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
  1937. if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo())
  1938. return;
  1939. if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) {
  1940. int next_tab = script_list->get_current() + 1;
  1941. next_tab %= script_list->get_item_count();
  1942. _go_to_tab(script_list->get_item_metadata(next_tab));
  1943. _update_script_names();
  1944. }
  1945. if (ED_IS_SHORTCUT("script_editor/prev_script", p_event)) {
  1946. int next_tab = script_list->get_current() - 1;
  1947. next_tab = next_tab >= 0 ? next_tab : script_list->get_item_count() - 1;
  1948. _go_to_tab(script_list->get_item_metadata(next_tab));
  1949. _update_script_names();
  1950. }
  1951. if (ED_IS_SHORTCUT("script_editor/window_move_up", p_event)) {
  1952. _menu_option(WINDOW_MOVE_UP);
  1953. }
  1954. if (ED_IS_SHORTCUT("script_editor/window_move_down", p_event)) {
  1955. _menu_option(WINDOW_MOVE_DOWN);
  1956. }
  1957. }
  1958. void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) {
  1959. Ref<InputEventMouseButton> mb = ev;
  1960. if (mb.is_valid() && mb->is_pressed()) {
  1961. switch (mb->get_button_index()) {
  1962. case BUTTON_MIDDLE: {
  1963. // Right-click selects automatically; middle-click does not.
  1964. int idx = script_list->get_item_at_position(mb->get_position(), true);
  1965. if (idx >= 0) {
  1966. script_list->select(idx);
  1967. _script_selected(idx);
  1968. _menu_option(FILE_CLOSE);
  1969. }
  1970. } break;
  1971. case BUTTON_RIGHT: {
  1972. _make_script_list_context_menu();
  1973. } break;
  1974. }
  1975. }
  1976. }
  1977. void ScriptEditor::_make_script_list_context_menu() {
  1978. context_menu->clear();
  1979. int selected = tab_container->get_current_tab();
  1980. if (selected < 0 || selected >= tab_container->get_child_count())
  1981. return;
  1982. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
  1983. if (se) {
  1984. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save"), FILE_SAVE);
  1985. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save_as"), FILE_SAVE_AS);
  1986. }
  1987. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE);
  1988. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_all"), CLOSE_ALL);
  1989. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_other_tabs"), CLOSE_OTHER_TABS);
  1990. context_menu->add_separator();
  1991. if (se) {
  1992. Ref<Script> scr = se->get_edited_resource();
  1993. if (scr != NULL) {
  1994. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
  1995. if (!scr.is_null() && scr->is_tool()) {
  1996. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN);
  1997. context_menu->add_separator();
  1998. }
  1999. }
  2000. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/copy_path"), FILE_COPY_PATH);
  2001. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/show_in_file_system"), SHOW_IN_FILE_SYSTEM);
  2002. context_menu->add_separator();
  2003. }
  2004. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_up"), WINDOW_MOVE_UP);
  2005. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_down"), WINDOW_MOVE_DOWN);
  2006. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_sort"), WINDOW_SORT);
  2007. context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_scripts_panel"), TOGGLE_SCRIPTS_PANEL);
  2008. context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
  2009. context_menu->set_size(Vector2(1, 1));
  2010. context_menu->popup();
  2011. }
  2012. void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
  2013. if (!bool(EDITOR_DEF("text_editor/files/restore_scripts_on_load", true))) {
  2014. return;
  2015. }
  2016. if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help"))
  2017. return;
  2018. Array scripts = p_layout->get_value("ScriptEditor", "open_scripts");
  2019. Array helps;
  2020. if (p_layout->has_section_key("ScriptEditor", "open_help"))
  2021. helps = p_layout->get_value("ScriptEditor", "open_help");
  2022. restoring_layout = true;
  2023. List<String> extensions;
  2024. ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
  2025. for (int i = 0; i < scripts.size(); i++) {
  2026. String path = scripts[i];
  2027. Dictionary script_info = scripts[i];
  2028. if (!script_info.empty()) {
  2029. path = script_info["path"];
  2030. }
  2031. if (!FileAccess::exists(path))
  2032. continue;
  2033. if (extensions.find(path.get_extension())) {
  2034. Ref<Script> scr = ResourceLoader::load(path);
  2035. if (!scr.is_valid()) {
  2036. continue;
  2037. }
  2038. if (!edit(scr)) {
  2039. continue;
  2040. }
  2041. } else {
  2042. Error error;
  2043. Ref<TextFile> text_file = _load_text_file(path, &error);
  2044. if (error != OK || !text_file.is_valid()) {
  2045. continue;
  2046. }
  2047. if (!edit(text_file)) {
  2048. continue;
  2049. }
  2050. }
  2051. if (!script_info.empty()) {
  2052. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(tab_container->get_tab_count() - 1));
  2053. if (se) {
  2054. se->set_edit_state(script_info["state"]);
  2055. }
  2056. }
  2057. }
  2058. for (int i = 0; i < helps.size(); i++) {
  2059. String path = helps[i];
  2060. if (path == "") { // invalid, skip
  2061. continue;
  2062. }
  2063. _help_class_open(path);
  2064. }
  2065. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2066. tab_container->get_child(i)->set_meta("__editor_pass", Variant());
  2067. }
  2068. if (p_layout->has_section_key("ScriptEditor", "split_offset")) {
  2069. script_split->set_split_offset(p_layout->get_value("ScriptEditor", "split_offset"));
  2070. }
  2071. restoring_layout = false;
  2072. _update_script_names();
  2073. }
  2074. void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
  2075. Array scripts;
  2076. Array helps;
  2077. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2078. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  2079. if (se) {
  2080. String path = se->get_edited_resource()->get_path();
  2081. if (!path.is_resource_file())
  2082. continue;
  2083. Dictionary script_info;
  2084. script_info["path"] = path;
  2085. script_info["state"] = se->get_edit_state();
  2086. scripts.push_back(script_info);
  2087. }
  2088. EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
  2089. if (eh) {
  2090. helps.push_back(eh->get_class());
  2091. }
  2092. }
  2093. p_layout->set_value("ScriptEditor", "open_scripts", scripts);
  2094. p_layout->set_value("ScriptEditor", "open_help", helps);
  2095. p_layout->set_value("ScriptEditor", "split_offset", script_split->get_split_offset());
  2096. }
  2097. void ScriptEditor::_help_class_open(const String &p_class) {
  2098. if (p_class == "")
  2099. return;
  2100. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2101. EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
  2102. if (eh && eh->get_class() == p_class) {
  2103. _go_to_tab(i);
  2104. _update_script_names();
  2105. return;
  2106. }
  2107. }
  2108. EditorHelp *eh = memnew(EditorHelp);
  2109. eh->set_name(p_class);
  2110. tab_container->add_child(eh);
  2111. _go_to_tab(tab_container->get_tab_count() - 1);
  2112. eh->go_to_class(p_class, 0);
  2113. eh->connect("go_to_help", this, "_help_class_goto");
  2114. _add_recent_script(p_class);
  2115. _sort_list_on_update = true;
  2116. _update_script_names();
  2117. _save_layout();
  2118. }
  2119. void ScriptEditor::_help_class_goto(const String &p_desc) {
  2120. String cname = p_desc.get_slice(":", 1);
  2121. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2122. EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
  2123. if (eh && eh->get_class() == cname) {
  2124. _go_to_tab(i);
  2125. eh->go_to_help(p_desc);
  2126. _update_script_names();
  2127. return;
  2128. }
  2129. }
  2130. EditorHelp *eh = memnew(EditorHelp);
  2131. eh->set_name(cname);
  2132. tab_container->add_child(eh);
  2133. _go_to_tab(tab_container->get_tab_count() - 1);
  2134. eh->go_to_help(p_desc);
  2135. eh->connect("go_to_help", this, "_help_class_goto");
  2136. _add_recent_script(eh->get_class());
  2137. _sort_list_on_update = true;
  2138. _update_script_names();
  2139. _save_layout();
  2140. }
  2141. void ScriptEditor::_update_selected_editor_menu() {
  2142. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2143. bool current = tab_container->get_current_tab() == i;
  2144. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  2145. if (se && se->get_edit_menu()) {
  2146. if (current)
  2147. se->get_edit_menu()->show();
  2148. else
  2149. se->get_edit_menu()->hide();
  2150. }
  2151. }
  2152. EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control());
  2153. script_search_menu->get_popup()->clear();
  2154. if (eh) {
  2155. script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F), HELP_SEARCH_FIND);
  2156. script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), HELP_SEARCH_FIND_NEXT);
  2157. script_search_menu->get_popup()->add_separator();
  2158. script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_in_files", TTR("Find in Files"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F), SEARCH_IN_FILES);
  2159. script_search_menu->show();
  2160. } else {
  2161. if (tab_container->get_child_count() == 0) {
  2162. script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_in_files", TTR("Find in Files"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F), SEARCH_IN_FILES);
  2163. script_search_menu->show();
  2164. } else {
  2165. script_search_menu->hide();
  2166. }
  2167. }
  2168. }
  2169. void ScriptEditor::_update_history_pos(int p_new_pos) {
  2170. Node *n = tab_container->get_current_tab_control();
  2171. if (Object::cast_to<ScriptEditorBase>(n)) {
  2172. history.write[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
  2173. }
  2174. if (Object::cast_to<EditorHelp>(n)) {
  2175. history.write[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
  2176. }
  2177. history_pos = p_new_pos;
  2178. tab_container->set_current_tab(history[history_pos].control->get_index());
  2179. n = history[history_pos].control;
  2180. if (Object::cast_to<ScriptEditorBase>(n)) {
  2181. Object::cast_to<ScriptEditorBase>(n)->set_edit_state(history[history_pos].state);
  2182. Object::cast_to<ScriptEditorBase>(n)->ensure_focus();
  2183. Ref<Script> script = Object::cast_to<ScriptEditorBase>(n)->get_edited_resource();
  2184. if (script != NULL) {
  2185. notify_script_changed(script);
  2186. }
  2187. }
  2188. if (Object::cast_to<EditorHelp>(n)) {
  2189. Object::cast_to<EditorHelp>(n)->set_scroll(history[history_pos].state);
  2190. Object::cast_to<EditorHelp>(n)->set_focused();
  2191. }
  2192. n->set_meta("__editor_pass", ++edit_pass);
  2193. _update_script_names();
  2194. _update_history_arrows();
  2195. _update_selected_editor_menu();
  2196. }
  2197. void ScriptEditor::_history_forward() {
  2198. if (history_pos < history.size() - 1) {
  2199. _update_history_pos(history_pos + 1);
  2200. }
  2201. }
  2202. void ScriptEditor::_history_back() {
  2203. if (history_pos > 0) {
  2204. _update_history_pos(history_pos - 1);
  2205. }
  2206. }
  2207. Vector<Ref<Script> > ScriptEditor::get_open_scripts() const {
  2208. Vector<Ref<Script> > out_scripts = Vector<Ref<Script> >();
  2209. for (int i = 0; i < tab_container->get_child_count(); i++) {
  2210. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
  2211. if (!se)
  2212. continue;
  2213. Ref<Script> script = se->get_edited_resource();
  2214. if (script != NULL) {
  2215. out_scripts.push_back(script);
  2216. }
  2217. }
  2218. return out_scripts;
  2219. }
  2220. void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
  2221. bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
  2222. if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")))
  2223. return;
  2224. if (open_dominant && p_script.is_valid()) {
  2225. edit(p_script);
  2226. }
  2227. }
  2228. bool ScriptEditor::script_goto_method(Ref<Script> p_script, const String &p_method) {
  2229. int line = p_script->get_member_line(p_method);
  2230. if (line == -1)
  2231. return false;
  2232. return edit(p_script, line, 0);
  2233. }
  2234. void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) {
  2235. auto_reload_running_scripts = p_enabled;
  2236. }
  2237. void ScriptEditor::_help_search(String p_text) {
  2238. help_search_dialog->popup_dialog(p_text);
  2239. }
  2240. void ScriptEditor::_open_script_request(const String &p_path) {
  2241. Ref<Script> script = ResourceLoader::load(p_path);
  2242. if (script.is_valid()) {
  2243. script_editor->edit(script, false);
  2244. return;
  2245. }
  2246. Error err;
  2247. Ref<TextFile> text_file = script_editor->_load_text_file(p_path, &err);
  2248. if (text_file.is_valid()) {
  2249. script_editor->edit(text_file, false);
  2250. return;
  2251. }
  2252. }
  2253. int ScriptEditor::syntax_highlighters_func_count = 0;
  2254. CreateSyntaxHighlighterFunc ScriptEditor::syntax_highlighters_funcs[ScriptEditor::SYNTAX_HIGHLIGHTER_FUNC_MAX];
  2255. void ScriptEditor::register_create_syntax_highlighter_function(CreateSyntaxHighlighterFunc p_func) {
  2256. ERR_FAIL_COND(syntax_highlighters_func_count == SYNTAX_HIGHLIGHTER_FUNC_MAX);
  2257. syntax_highlighters_funcs[syntax_highlighters_func_count++] = p_func;
  2258. }
  2259. int ScriptEditor::script_editor_func_count = 0;
  2260. CreateScriptEditorFunc ScriptEditor::script_editor_funcs[ScriptEditor::SCRIPT_EDITOR_FUNC_MAX];
  2261. void ScriptEditor::register_create_script_editor_function(CreateScriptEditorFunc p_func) {
  2262. ERR_FAIL_COND(script_editor_func_count == SCRIPT_EDITOR_FUNC_MAX);
  2263. script_editor_funcs[script_editor_func_count++] = p_func;
  2264. }
  2265. void ScriptEditor::_script_changed() {
  2266. NodeDock::singleton->update_lists();
  2267. }
  2268. void ScriptEditor::_on_find_in_files_requested(String text) {
  2269. find_in_files_dialog->set_search_text(text);
  2270. find_in_files_dialog->popup_centered_minsize();
  2271. }
  2272. void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) {
  2273. RES res = ResourceLoader::load(fpath);
  2274. if (fpath.get_extension() == "shader") {
  2275. ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader"));
  2276. shader_editor->edit(res.ptr());
  2277. shader_editor->make_visible(true);
  2278. shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end);
  2279. } else {
  2280. edit(res);
  2281. ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor());
  2282. if (ste) {
  2283. ste->goto_line_selection(line_number - 1, begin, end);
  2284. }
  2285. }
  2286. }
  2287. void ScriptEditor::_start_find_in_files(bool with_replace) {
  2288. FindInFiles *f = find_in_files->get_finder();
  2289. f->set_search_text(find_in_files_dialog->get_search_text());
  2290. f->set_match_case(find_in_files_dialog->is_match_case());
  2291. f->set_whole_words(find_in_files_dialog->is_whole_words());
  2292. f->set_folder(find_in_files_dialog->get_folder());
  2293. f->set_filter(find_in_files_dialog->get_filter());
  2294. find_in_files->set_with_replace(with_replace);
  2295. find_in_files->start_search();
  2296. editor->make_bottom_panel_item_visible(find_in_files);
  2297. }
  2298. void ScriptEditor::_on_find_in_files_modified_files(PoolStringArray paths) {
  2299. _test_script_times_on_disk();
  2300. _update_modified_scripts_for_external_editor();
  2301. }
  2302. void ScriptEditor::_bind_methods() {
  2303. ClassDB::bind_method("_file_dialog_action", &ScriptEditor::_file_dialog_action);
  2304. ClassDB::bind_method("_tab_changed", &ScriptEditor::_tab_changed);
  2305. ClassDB::bind_method("_menu_option", &ScriptEditor::_menu_option);
  2306. ClassDB::bind_method("_close_current_tab", &ScriptEditor::_close_current_tab);
  2307. ClassDB::bind_method("_close_discard_current_tab", &ScriptEditor::_close_discard_current_tab);
  2308. ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab);
  2309. ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs);
  2310. ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs);
  2311. ClassDB::bind_method("_open_recent_script", &ScriptEditor::_open_recent_script);
  2312. ClassDB::bind_method("_theme_option", &ScriptEditor::_theme_option);
  2313. ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play);
  2314. ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause);
  2315. ClassDB::bind_method("_editor_stop", &ScriptEditor::_editor_stop);
  2316. ClassDB::bind_method("_add_callback", &ScriptEditor::_add_callback);
  2317. ClassDB::bind_method("_reload_scripts", &ScriptEditor::_reload_scripts);
  2318. ClassDB::bind_method("_resave_scripts", &ScriptEditor::_resave_scripts);
  2319. ClassDB::bind_method("_res_saved_callback", &ScriptEditor::_res_saved_callback);
  2320. ClassDB::bind_method("_goto_script_line", &ScriptEditor::_goto_script_line);
  2321. ClassDB::bind_method("_goto_script_line2", &ScriptEditor::_goto_script_line2);
  2322. ClassDB::bind_method("_set_execution", &ScriptEditor::_set_execution);
  2323. ClassDB::bind_method("_clear_execution", &ScriptEditor::_clear_execution);
  2324. ClassDB::bind_method("_help_search", &ScriptEditor::_help_search);
  2325. ClassDB::bind_method("_save_history", &ScriptEditor::_save_history);
  2326. ClassDB::bind_method("_copy_script_path", &ScriptEditor::_copy_script_path);
  2327. ClassDB::bind_method("_breaked", &ScriptEditor::_breaked);
  2328. ClassDB::bind_method("_show_debugger", &ScriptEditor::_show_debugger);
  2329. ClassDB::bind_method("_get_debug_tooltip", &ScriptEditor::_get_debug_tooltip);
  2330. ClassDB::bind_method("_autosave_scripts", &ScriptEditor::_autosave_scripts);
  2331. ClassDB::bind_method("_editor_settings_changed", &ScriptEditor::_editor_settings_changed);
  2332. ClassDB::bind_method("_update_script_names", &ScriptEditor::_update_script_names);
  2333. ClassDB::bind_method("_update_script_connections", &ScriptEditor::_update_script_connections);
  2334. ClassDB::bind_method("_tree_changed", &ScriptEditor::_tree_changed);
  2335. ClassDB::bind_method("_members_overview_selected", &ScriptEditor::_members_overview_selected);
  2336. ClassDB::bind_method("_help_overview_selected", &ScriptEditor::_help_overview_selected);
  2337. ClassDB::bind_method("_script_selected", &ScriptEditor::_script_selected);
  2338. ClassDB::bind_method("_script_created", &ScriptEditor::_script_created);
  2339. ClassDB::bind_method("_script_split_dragged", &ScriptEditor::_script_split_dragged);
  2340. ClassDB::bind_method("_help_class_open", &ScriptEditor::_help_class_open);
  2341. ClassDB::bind_method("_help_class_goto", &ScriptEditor::_help_class_goto);
  2342. ClassDB::bind_method("_request_help", &ScriptEditor::_help_class_open);
  2343. ClassDB::bind_method("_history_forward", &ScriptEditor::_history_forward);
  2344. ClassDB::bind_method("_history_back", &ScriptEditor::_history_back);
  2345. ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts);
  2346. ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input);
  2347. ClassDB::bind_method("_script_list_gui_input", &ScriptEditor::_script_list_gui_input);
  2348. ClassDB::bind_method("_toggle_members_overview_alpha_sort", &ScriptEditor::_toggle_members_overview_alpha_sort);
  2349. ClassDB::bind_method("_update_members_overview", &ScriptEditor::_update_members_overview);
  2350. ClassDB::bind_method("_script_changed", &ScriptEditor::_script_changed);
  2351. ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts);
  2352. ClassDB::bind_method("_on_find_in_files_requested", &ScriptEditor::_on_find_in_files_requested);
  2353. ClassDB::bind_method("_start_find_in_files", &ScriptEditor::_start_find_in_files);
  2354. ClassDB::bind_method("_on_find_in_files_result_selected", &ScriptEditor::_on_find_in_files_result_selected);
  2355. ClassDB::bind_method("_on_find_in_files_modified_files", &ScriptEditor::_on_find_in_files_modified_files);
  2356. ClassDB::bind_method(D_METHOD("get_drag_data_fw", "point", "from"), &ScriptEditor::get_drag_data_fw);
  2357. ClassDB::bind_method(D_METHOD("can_drop_data_fw", "point", "data", "from"), &ScriptEditor::can_drop_data_fw);
  2358. ClassDB::bind_method(D_METHOD("drop_data_fw", "point", "data", "from"), &ScriptEditor::drop_data_fw);
  2359. ClassDB::bind_method(D_METHOD("goto_line", "line_number"), &ScriptEditor::_goto_script_line2);
  2360. ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script);
  2361. ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts);
  2362. ClassDB::bind_method(D_METHOD("open_script_create_dialog", "base_name", "base_path"), &ScriptEditor::open_script_create_dialog);
  2363. ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
  2364. ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
  2365. }
  2366. ScriptEditor::ScriptEditor(EditorNode *p_editor) {
  2367. current_theme = "";
  2368. completion_cache = memnew(EditorScriptCodeCompletionCache);
  2369. restoring_layout = false;
  2370. waiting_update_names = false;
  2371. pending_auto_reload = false;
  2372. auto_reload_running_scripts = true;
  2373. members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview");
  2374. help_overview_enabled = EditorSettings::get_singleton()->get("text_editor/help/show_help_index");
  2375. editor = p_editor;
  2376. VBoxContainer *main_container = memnew(VBoxContainer);
  2377. add_child(main_container);
  2378. menu_hb = memnew(HBoxContainer);
  2379. main_container->add_child(menu_hb);
  2380. script_split = memnew(HSplitContainer);
  2381. main_container->add_child(script_split);
  2382. script_split->set_v_size_flags(SIZE_EXPAND_FILL);
  2383. list_split = memnew(VSplitContainer);
  2384. script_split->add_child(list_split);
  2385. list_split->set_v_size_flags(SIZE_EXPAND_FILL);
  2386. script_list = memnew(ItemList);
  2387. list_split->add_child(script_list);
  2388. script_list->set_custom_minimum_size(Size2(150, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
  2389. script_list->set_v_size_flags(SIZE_EXPAND_FILL);
  2390. script_split->set_split_offset(140);
  2391. _sort_list_on_update = true;
  2392. script_list->connect("gui_input", this, "_script_list_gui_input", varray(), CONNECT_DEFERRED);
  2393. script_list->set_allow_rmb_select(true);
  2394. script_list->set_drag_forwarding(this);
  2395. context_menu = memnew(PopupMenu);
  2396. add_child(context_menu);
  2397. context_menu->connect("id_pressed", this, "_menu_option");
  2398. context_menu->set_hide_on_window_lose_focus(true);
  2399. overview_vbox = memnew(VBoxContainer);
  2400. overview_vbox->set_custom_minimum_size(Size2(0, 90));
  2401. overview_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  2402. list_split->add_child(overview_vbox);
  2403. buttons_hbox = memnew(HBoxContainer);
  2404. overview_vbox->add_child(buttons_hbox);
  2405. filename = memnew(Label);
  2406. filename->set_clip_text(true);
  2407. filename->set_h_size_flags(SIZE_EXPAND_FILL);
  2408. filename->add_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal", "LineEdit"));
  2409. buttons_hbox->add_child(filename);
  2410. members_overview_alphabeta_sort_button = memnew(ToolButton);
  2411. members_overview_alphabeta_sort_button->set_tooltip(TTR("Toggle alphabetical sorting of the method list."));
  2412. members_overview_alphabeta_sort_button->set_toggle_mode(true);
  2413. members_overview_alphabeta_sort_button->set_pressed(EditorSettings::get_singleton()->get("text_editor/tools/sort_members_outline_alphabetically"));
  2414. members_overview_alphabeta_sort_button->connect("toggled", this, "_toggle_members_overview_alpha_sort");
  2415. buttons_hbox->add_child(members_overview_alphabeta_sort_button);
  2416. members_overview = memnew(ItemList);
  2417. overview_vbox->add_child(members_overview);
  2418. members_overview->set_allow_reselect(true);
  2419. members_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
  2420. members_overview->set_v_size_flags(SIZE_EXPAND_FILL);
  2421. members_overview->set_allow_rmb_select(true);
  2422. help_overview = memnew(ItemList);
  2423. overview_vbox->add_child(help_overview);
  2424. help_overview->set_allow_reselect(true);
  2425. help_overview->set_custom_minimum_size(Size2(0, 90) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
  2426. help_overview->set_v_size_flags(SIZE_EXPAND_FILL);
  2427. tab_container = memnew(TabContainer);
  2428. tab_container->set_tabs_visible(false);
  2429. tab_container->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
  2430. script_split->add_child(tab_container);
  2431. tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
  2432. ED_SHORTCUT("script_editor/window_sort", TTR("Sort"));
  2433. ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
  2434. ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN);
  2435. ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
  2436. ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COLON);
  2437. set_process_unhandled_input(true);
  2438. file_menu = memnew(MenuButton);
  2439. menu_hb->add_child(file_menu);
  2440. file_menu->set_text(TTR("File"));
  2441. file_menu->set_switch_on_hover(true);
  2442. file_menu->get_popup()->set_hide_on_window_lose_focus(true);
  2443. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script...")), FILE_NEW);
  2444. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New TextFile...")), FILE_NEW_TEXTFILE);
  2445. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open...")), FILE_OPEN);
  2446. file_menu->get_popup()->add_submenu_item(TTR("Open Recent"), "RecentScripts", FILE_OPEN_RECENT);
  2447. recent_scripts = memnew(PopupMenu);
  2448. recent_scripts->set_name("RecentScripts");
  2449. file_menu->get_popup()->add_child(recent_scripts);
  2450. recent_scripts->connect("id_pressed", this, "_open_recent_script");
  2451. _update_recent_scripts();
  2452. file_menu->get_popup()->add_separator();
  2453. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save", TTR("Save"), KEY_MASK_ALT | KEY_MASK_CMD | KEY_S), FILE_SAVE);
  2454. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_as", TTR("Save As...")), FILE_SAVE_AS);
  2455. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_all", TTR("Save All"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_S), FILE_SAVE_ALL);
  2456. file_menu->get_popup()->add_separator();
  2457. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R), FILE_TOOL_RELOAD_SOFT);
  2458. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy_path", TTR("Copy Script Path")), FILE_COPY_PATH);
  2459. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTR("Show in FileSystem")), SHOW_IN_FILE_SYSTEM);
  2460. file_menu->get_popup()->add_separator();
  2461. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Previous"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV);
  2462. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT | KEY_RIGHT), WINDOW_NEXT);
  2463. file_menu->get_popup()->add_separator();
  2464. file_menu->get_popup()->add_submenu_item(TTR("Theme"), "Theme", FILE_THEME);
  2465. theme_submenu = memnew(PopupMenu);
  2466. theme_submenu->set_name("Theme");
  2467. file_menu->get_popup()->add_child(theme_submenu);
  2468. theme_submenu->connect("id_pressed", this, "_theme_option");
  2469. theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme...")), THEME_IMPORT);
  2470. theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), THEME_RELOAD);
  2471. theme_submenu->add_separator();
  2472. theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), THEME_SAVE);
  2473. theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As...")), THEME_SAVE_AS);
  2474. file_menu->get_popup()->add_separator();
  2475. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS);
  2476. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE);
  2477. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL);
  2478. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_other_tabs", TTR("Close Other Tabs")), CLOSE_OTHER_TABS);
  2479. file_menu->get_popup()->add_separator();
  2480. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN);
  2481. file_menu->get_popup()->add_separator();
  2482. file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL);
  2483. file_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  2484. script_search_menu = memnew(MenuButton);
  2485. menu_hb->add_child(script_search_menu);
  2486. script_search_menu->set_text(TTR("Search"));
  2487. script_search_menu->set_switch_on_hover(true);
  2488. script_search_menu->get_popup()->set_hide_on_window_lose_focus(true);
  2489. script_search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  2490. debug_menu = memnew(MenuButton);
  2491. menu_hb->add_child(debug_menu);
  2492. debug_menu->set_text(TTR("Debug"));
  2493. debug_menu->set_switch_on_hover(true);
  2494. debug_menu->get_popup()->set_hide_on_window_lose_focus(true);
  2495. debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10), DEBUG_NEXT);
  2496. debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11), DEBUG_STEP);
  2497. debug_menu->get_popup()->add_separator();
  2498. debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/break", TTR("Break")), DEBUG_BREAK);
  2499. debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/continue", TTR("Continue"), KEY_F12), DEBUG_CONTINUE);
  2500. debug_menu->get_popup()->add_separator();
  2501. //debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW);
  2502. debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/keep_debugger_open", TTR("Keep Debugger Open")), DEBUG_SHOW_KEEP_OPEN);
  2503. debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/debug_with_external_editor", TTR("Debug with External Editor")), DEBUG_WITH_EXTERNAL_EDITOR);
  2504. debug_menu->get_popup()->connect("id_pressed", this, "_menu_option");
  2505. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true);
  2506. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true);
  2507. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true);
  2508. debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true);
  2509. menu_hb->add_spacer();
  2510. script_icon = memnew(TextureRect);
  2511. menu_hb->add_child(script_icon);
  2512. script_name_label = memnew(Label);
  2513. menu_hb->add_child(script_name_label);
  2514. script_icon->hide();
  2515. script_name_label->hide();
  2516. menu_hb->add_spacer();
  2517. site_search = memnew(ToolButton);
  2518. site_search->set_text(TTR("Online Docs"));
  2519. site_search->connect("pressed", this, "_menu_option", varray(SEARCH_WEBSITE));
  2520. menu_hb->add_child(site_search);
  2521. site_search->set_tooltip(TTR("Open Godot online documentation."));
  2522. request_docs = memnew(ToolButton);
  2523. request_docs->set_text(TTR("Request Docs"));
  2524. request_docs->connect("pressed", this, "_menu_option", varray(REQUEST_DOCS));
  2525. menu_hb->add_child(request_docs);
  2526. request_docs->set_tooltip(TTR("Help improve the Godot documentation by giving feedback."));
  2527. help_search = memnew(ToolButton);
  2528. help_search->set_text(TTR("Search Help"));
  2529. help_search->connect("pressed", this, "_menu_option", varray(SEARCH_HELP));
  2530. menu_hb->add_child(help_search);
  2531. help_search->set_tooltip(TTR("Search the reference documentation."));
  2532. menu_hb->add_child(memnew(VSeparator));
  2533. script_back = memnew(ToolButton);
  2534. script_back->connect("pressed", this, "_history_back");
  2535. menu_hb->add_child(script_back);
  2536. script_back->set_disabled(true);
  2537. script_back->set_tooltip(TTR("Go to previous edited document."));
  2538. script_forward = memnew(ToolButton);
  2539. script_forward->connect("pressed", this, "_history_forward");
  2540. menu_hb->add_child(script_forward);
  2541. script_forward->set_disabled(true);
  2542. script_forward->set_tooltip(TTR("Go to next edited document."));
  2543. tab_container->connect("tab_changed", this, "_tab_changed");
  2544. erase_tab_confirm = memnew(ConfirmationDialog);
  2545. erase_tab_confirm->get_ok()->set_text(TTR("Save"));
  2546. erase_tab_confirm->add_button(TTR("Discard"), OS::get_singleton()->get_swap_ok_cancel(), "discard");
  2547. erase_tab_confirm->connect("confirmed", this, "_close_current_tab");
  2548. erase_tab_confirm->connect("custom_action", this, "_close_discard_current_tab");
  2549. add_child(erase_tab_confirm);
  2550. script_create_dialog = memnew(ScriptCreateDialog);
  2551. script_create_dialog->set_title(TTR("Create Script"));
  2552. add_child(script_create_dialog);
  2553. script_create_dialog->connect("script_created", this, "_script_created");
  2554. file_dialog_option = -1;
  2555. file_dialog = memnew(EditorFileDialog);
  2556. add_child(file_dialog);
  2557. file_dialog->connect("file_selected", this, "_file_dialog_action");
  2558. error_dialog = memnew(AcceptDialog);
  2559. add_child(error_dialog);
  2560. debugger = memnew(ScriptEditorDebugger(editor));
  2561. debugger->connect("goto_script_line", this, "_goto_script_line");
  2562. debugger->connect("set_execution", this, "_set_execution");
  2563. debugger->connect("clear_execution", this, "_clear_execution");
  2564. debugger->connect("show_debugger", this, "_show_debugger");
  2565. disk_changed = memnew(ConfirmationDialog);
  2566. {
  2567. VBoxContainer *vbc = memnew(VBoxContainer);
  2568. disk_changed->add_child(vbc);
  2569. Label *dl = memnew(Label);
  2570. dl->set_text(TTR("The following files are newer on disk.\nWhat action should be taken?:"));
  2571. vbc->add_child(dl);
  2572. disk_changed_list = memnew(Tree);
  2573. vbc->add_child(disk_changed_list);
  2574. disk_changed_list->set_v_size_flags(SIZE_EXPAND_FILL);
  2575. disk_changed->connect("confirmed", this, "_reload_scripts");
  2576. disk_changed->get_ok()->set_text(TTR("Reload"));
  2577. disk_changed->add_button(TTR("Resave"), !OS::get_singleton()->get_swap_ok_cancel(), "resave");
  2578. disk_changed->connect("custom_action", this, "_resave_scripts");
  2579. }
  2580. add_child(disk_changed);
  2581. script_editor = this;
  2582. Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"), debugger);
  2583. debugger->set_tool_button(db);
  2584. debugger->connect("breaked", this, "_breaked");
  2585. autosave_timer = memnew(Timer);
  2586. autosave_timer->set_one_shot(false);
  2587. add_child(autosave_timer);
  2588. grab_focus_block = false;
  2589. help_search_dialog = memnew(EditorHelpSearch);
  2590. add_child(help_search_dialog);
  2591. help_search_dialog->connect("go_to_help", this, "_help_class_goto");
  2592. find_in_files_dialog = memnew(FindInFilesDialog);
  2593. find_in_files_dialog->connect(FindInFilesDialog::SIGNAL_FIND_REQUESTED, this, "_start_find_in_files", varray(false));
  2594. find_in_files_dialog->connect(FindInFilesDialog::SIGNAL_REPLACE_REQUESTED, this, "_start_find_in_files", varray(true));
  2595. add_child(find_in_files_dialog);
  2596. find_in_files = memnew(FindInFilesPanel);
  2597. find_in_files_button = editor->add_bottom_panel_item(TTR("Search Results"), find_in_files);
  2598. find_in_files->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  2599. find_in_files->connect(FindInFilesPanel::SIGNAL_RESULT_SELECTED, this, "_on_find_in_files_result_selected");
  2600. find_in_files->connect(FindInFilesPanel::SIGNAL_FILES_MODIFIED, this, "_on_find_in_files_modified_files");
  2601. find_in_files->hide();
  2602. find_in_files_button->hide();
  2603. history_pos = -1;
  2604. //debugger_gui->hide();
  2605. edit_pass = 0;
  2606. trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save");
  2607. convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save");
  2608. use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type");
  2609. ScriptServer::edit_request_func = _open_script_request;
  2610. add_style_override("panel", editor->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles"));
  2611. tab_container->add_style_override("panel", editor->get_gui_base()->get_stylebox("ScriptEditor", "EditorStyles"));
  2612. }
  2613. ScriptEditor::~ScriptEditor() {
  2614. memdelete(completion_cache);
  2615. }
  2616. void ScriptEditorPlugin::edit(Object *p_object) {
  2617. if (Object::cast_to<Script>(p_object)) {
  2618. Script *p_script = Object::cast_to<Script>(p_object);
  2619. String scene_path = p_script->get_path().get_slice("::", 0);
  2620. if (_is_built_in_script(p_script) && !EditorNode::get_singleton()->is_scene_open(scene_path)) {
  2621. EditorNode::get_singleton()->load_scene(scene_path);
  2622. script_editor->call_deferred("edit", p_script);
  2623. } else {
  2624. script_editor->edit(p_script);
  2625. }
  2626. } else if (Object::cast_to<TextFile>(p_object)) {
  2627. script_editor->edit(Object::cast_to<TextFile>(p_object));
  2628. }
  2629. }
  2630. bool ScriptEditorPlugin::handles(Object *p_object) const {
  2631. if (Object::cast_to<TextFile>(p_object)) {
  2632. return true;
  2633. }
  2634. if (Object::cast_to<Script>(p_object)) {
  2635. return true;
  2636. }
  2637. return p_object->is_class("Script");
  2638. }
  2639. void ScriptEditorPlugin::make_visible(bool p_visible) {
  2640. if (p_visible) {
  2641. script_editor->show();
  2642. script_editor->set_process(true);
  2643. script_editor->ensure_select_current();
  2644. } else {
  2645. script_editor->hide();
  2646. script_editor->set_process(false);
  2647. }
  2648. }
  2649. void ScriptEditorPlugin::selected_notify() {
  2650. script_editor->ensure_select_current();
  2651. }
  2652. void ScriptEditorPlugin::save_external_data() {
  2653. script_editor->save_all_scripts();
  2654. }
  2655. void ScriptEditorPlugin::apply_changes() {
  2656. script_editor->apply_scripts();
  2657. }
  2658. void ScriptEditorPlugin::restore_global_state() {
  2659. }
  2660. void ScriptEditorPlugin::save_global_state() {
  2661. }
  2662. void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
  2663. script_editor->set_window_layout(p_layout);
  2664. }
  2665. void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
  2666. script_editor->get_window_layout(p_layout);
  2667. }
  2668. void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
  2669. return script_editor->get_breakpoints(p_breakpoints);
  2670. }
  2671. void ScriptEditorPlugin::edited_scene_changed() {
  2672. script_editor->edited_scene_changed();
  2673. }
  2674. ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) {
  2675. editor = p_node;
  2676. script_editor = memnew(ScriptEditor(p_node));
  2677. editor->get_viewport()->add_child(script_editor);
  2678. script_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  2679. script_editor->hide();
  2680. EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", true);
  2681. ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true));
  2682. EDITOR_DEF("text_editor/files/open_dominant_script_on_scene_change", true);
  2683. EDITOR_DEF("text_editor/external/use_external_editor", false);
  2684. EDITOR_DEF("text_editor/external/exec_path", "");
  2685. EDITOR_DEF("text_editor/open_scripts/script_temperature_enabled", true);
  2686. EDITOR_DEF("text_editor/open_scripts/highlight_current_script", true);
  2687. EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size", 15);
  2688. EDITOR_DEF("text_editor/open_scripts/current_script_background_color", Color(1, 1, 1, 0.3));
  2689. EDITOR_DEF("text_editor/open_scripts/group_help_pages", true);
  2690. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path,None"));
  2691. EDITOR_DEF("text_editor/open_scripts/sort_scripts_by", 0);
  2692. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/list_script_names_as", PROPERTY_HINT_ENUM, "Name,Parent Directory And Name,Full Path"));
  2693. EDITOR_DEF("text_editor/open_scripts/list_script_names_as", 0);
  2694. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_path", PROPERTY_HINT_GLOBAL_FILE));
  2695. EDITOR_DEF("text_editor/external/exec_flags", "{file}");
  2696. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_flags", PROPERTY_HINT_PLACEHOLDER_TEXT, "Call flags with placeholders: {project}, {file}, {col}, {line}."));
  2697. ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T);
  2698. ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files"));
  2699. }
  2700. ScriptEditorPlugin::~ScriptEditorPlugin() {
  2701. }