Main.pas 268 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403
  1. ////////////////////////////////////////////////////////////////
  2. // IMPORTANT NOTICE:
  3. // Do not include ShareMem unit in the project. Faulting to
  4. // such thing would cause an EInvalidPointer error when
  5. // LuaEdit will close.
  6. ////////////////////////////////////////////////////////////////
  7. unit Main;
  8. interface
  9. //{$define RTASSERT}
  10. uses
  11. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  12. Dialogs, StdCtrls, ComCtrls, CommCtrl, ExtCtrls, SynEdit, SynCompletionProposal,
  13. Menus, ActnList, ImgList, ToolWin, XPMan, IniFiles, Registry, lua, lualib,
  14. lauxlib, LuaUtils, SynEditMiscClasses, SynEditSearch, SynEditRegexSearch, SynEditTypes,
  15. ShellAPI, SynEditHighlighter, SynEditKeyCmds, SynEditPrint, WinSock,
  16. JvDockControlForm, JvComponent, JvDockVIDStyle, JvDockVSNetStyle, JvAppRegistryStorage,
  17. JvXPCore, JvTabBar, Mask, JvExMask, JvToolEdit, JvMaskEdit, JvDotNetControls,
  18. JvChangeNotify, JvClipboardMonitor, JvMenus, JvExComCtrls, JvToolBar,
  19. JvInspector, XPStyleActnCtrls, ActnMan, ActnCtrls, CustomizeDlg,
  20. ActnMenus, ActnColorMaps, StdStyleActnCtrls, XPMenu, Clipbrd, JvLookOut,
  21. JvExControls, FileCtrl, VirtualTrees, Misc, LEMacros
  22. {$ifdef RTASSERT} ,RTDebug {$endif}
  23. {$ifdef madExcept} ,madExcept, madLinkDisAsm {$endif}
  24. ,JvDragDrop, JvAppEvent, JvExStdCtrls, JvButton, JvCtrls, JvComCtrls,
  25. JvDockTree, JvAppInst, JvExExtCtrls, JvItemsPanel, JvGradientCaption,
  26. JvgCaption, xmldom, XMLIntf, msxmldom, XMLDoc, MSXML, JvComponentBase;
  27. type
  28. TfrmLuaEditMain = class(TForm)
  29. Panel1: TPanel;
  30. Panel5: TPanel;
  31. Panel6: TPanel;
  32. stbMain: TStatusBar;
  33. actListMain: TActionList;
  34. actNewProject: TAction;
  35. actNewUnit: TAction;
  36. actOpenFile: TAction;
  37. actOpenProject: TAction;
  38. actExit: TAction;
  39. actSave: TAction;
  40. actSaveAs: TAction;
  41. actSaveProjectAs: TAction;
  42. actSaveAll: TAction;
  43. actClose: TAction;
  44. actPrint: TAction;
  45. actUndo: TAction;
  46. actRedo: TAction;
  47. actSelectAll: TAction;
  48. actCut: TAction;
  49. actCopy: TAction;
  50. actPaste: TAction;
  51. actFind: TAction;
  52. actFindAgain: TAction;
  53. actFindReplace: TAction;
  54. actGoToLine: TAction;
  55. actRunScript: TAction;
  56. actStepOver: TAction;
  57. actStepInto: TAction;
  58. actToggleBreakpoint: TAction;
  59. actCheckSyntax: TAction;
  60. actPause: TAction;
  61. actStop: TAction;
  62. actRunToCursor: TAction;
  63. actAddToPrj: TAction;
  64. actRemoveFromPrj: TAction;
  65. actEditorSettings: TAction;
  66. actBlockUnindent: TAction;
  67. actBlockIndent: TAction;
  68. actPrjSettings: TAction;
  69. actActiveSelPrj: TAction;
  70. imlActions: TImageList;
  71. odlgOpenUnit: TOpenDialog;
  72. odlgOpenProject: TOpenDialog;
  73. sdlgSaveAsUnit: TSaveDialog;
  74. sdlgSaveAsPrj: TSaveDialog;
  75. mnuReopen: TPopupMenu;
  76. synMainSearch: TSynEditSearch;
  77. synMainSearchRegEx: TSynEditRegexSearch;
  78. ppmEditor: TPopupMenu;
  79. Undo2: TMenuItem;
  80. Redo2: TMenuItem;
  81. N17: TMenuItem;
  82. Cut2: TMenuItem;
  83. Copy2: TMenuItem;
  84. Paste2: TMenuItem;
  85. N19: TMenuItem;
  86. IndentSelection2: TMenuItem;
  87. UnindentSelection2: TMenuItem;
  88. N16: TMenuItem;
  89. oggleBookmark1: TMenuItem;
  90. GotoBookmark12: TMenuItem;
  91. GotoBookmark13: TMenuItem;
  92. GotoBookmark14: TMenuItem;
  93. GotoBookmark15: TMenuItem;
  94. GotoBookmark16: TMenuItem;
  95. GotoBookmark17: TMenuItem;
  96. GotoBookmark18: TMenuItem;
  97. GotoBookmark81: TMenuItem;
  98. GotoBookmark91: TMenuItem;
  99. GotoBookmark11: TMenuItem;
  100. GotoBookmark1: TMenuItem;
  101. Bookmark11: TMenuItem;
  102. Bookmark12: TMenuItem;
  103. Bookmark13: TMenuItem;
  104. Bookmark14: TMenuItem;
  105. Bookmark15: TMenuItem;
  106. Bookmark16: TMenuItem;
  107. Bookmark17: TMenuItem;
  108. Bookmark18: TMenuItem;
  109. Bookmark19: TMenuItem;
  110. Bookmark110: TMenuItem;
  111. N15: TMenuItem;
  112. EditorSettings2: TMenuItem;
  113. ppmUnits: TPopupMenu;
  114. Close2: TMenuItem;
  115. synEditPrint: TSynEditPrint;
  116. pdlgPrint: TPrintDialog;
  117. ctrlBar: TControlBar;
  118. tlbRun: TToolBar;
  119. ToolButton11: TToolButton;
  120. ToolButton12: TToolButton;
  121. ToolButton13: TToolButton;
  122. ToolButton14: TToolButton;
  123. ToolButton15: TToolButton;
  124. ToolButton19: TToolButton;
  125. ToolButton16: TToolButton;
  126. ToolButton17: TToolButton;
  127. ToolButton18: TToolButton;
  128. ToolButton20: TToolButton;
  129. ToolButton21: TToolButton;
  130. tlbBaseFile: TToolBar;
  131. ToolButton1: TToolButton;
  132. ToolButton3: TToolButton;
  133. ToolButton4: TToolButton;
  134. ToolButton2: TToolButton;
  135. ToolButton7: TToolButton;
  136. ToolButton6: TToolButton;
  137. ToolButton8: TToolButton;
  138. ToolButton5: TToolButton;
  139. ToolButton9: TToolButton;
  140. ToolButton34: TToolButton;
  141. ToolButton33: TToolButton;
  142. ToolButton22: TToolButton;
  143. ToolButton10: TToolButton;
  144. ToolButton23: TToolButton;
  145. ppmToolBar: TPopupMenu;
  146. File3: TMenuItem;
  147. Edit3: TMenuItem;
  148. Run4: TMenuItem;
  149. AddBreakpoint1: TMenuItem;
  150. N20: TMenuItem;
  151. N21: TMenuItem;
  152. OpenFileatCursor1: TMenuItem;
  153. jvDockVSNet: TJvDockVSNetStyle;
  154. jvDockServer: TJvDockServer;
  155. imlDock: TImageList;
  156. jvModernUnitBarPainter: TJvModernTabBarPainter;
  157. actAddWatch: TAction;
  158. N22: TMenuItem;
  159. Save2: TMenuItem;
  160. SaveAs2: TMenuItem;
  161. jvchnNotifier: TJvChangeNotify;
  162. tlbFind: TToolBar;
  163. ToolButton35: TToolButton;
  164. ToolButton36: TToolButton;
  165. ToolButton37: TToolButton;
  166. ToolButton42: TToolButton;
  167. ToolButton43: TToolButton;
  168. actMainMenuFile: TAction;
  169. actMainMenuEdit: TAction;
  170. actMainMenuView: TAction;
  171. actMainMenuProject: TAction;
  172. actMainMenuRun: TAction;
  173. actMainMenuTools: TAction;
  174. actMainMenuHelp: TAction;
  175. actShowProjectTree: TAction;
  176. actShowBreakpoints: TAction;
  177. actShowMessages: TAction;
  178. actShowWatchList: TAction;
  179. actShowCallStack: TAction;
  180. actShowLuaStack: TAction;
  181. actShowLuaConsole: TAction;
  182. actShowLuaGlobals: TAction;
  183. actShowLuaLocals: TAction;
  184. mnuMain: TMainMenu;
  185. File1: TMenuItem;
  186. Exit1: TMenuItem;
  187. N1: TMenuItem;
  188. PrintSetup1: TMenuItem;
  189. Print1: TMenuItem;
  190. N2: TMenuItem;
  191. CloseUnit1: TMenuItem;
  192. SaveAll1: TMenuItem;
  193. SaveProjectAs1: TMenuItem;
  194. SaveAs1: TMenuItem;
  195. Save1: TMenuItem;
  196. N3: TMenuItem;
  197. Reopen1: TMenuItem;
  198. OpenLuaProject1: TMenuItem;
  199. OpenFile1: TMenuItem;
  200. New1: TMenuItem;
  201. Unit1: TMenuItem;
  202. Project1: TMenuItem;
  203. Edit1: TMenuItem;
  204. GotoLine1: TMenuItem;
  205. N4: TMenuItem;
  206. UnindentSelection1: TMenuItem;
  207. IndentSelection1: TMenuItem;
  208. N5: TMenuItem;
  209. SearchAgain1: TMenuItem;
  210. Replace1: TMenuItem;
  211. Search1: TMenuItem;
  212. N6: TMenuItem;
  213. SelectAll1: TMenuItem;
  214. Paste1: TMenuItem;
  215. Copy1: TMenuItem;
  216. Cut1: TMenuItem;
  217. N7: TMenuItem;
  218. Redo1: TMenuItem;
  219. Undo1: TMenuItem;
  220. View1: TMenuItem;
  221. oolbars1: TMenuItem;
  222. Run1: TMenuItem;
  223. Edit2: TMenuItem;
  224. File2: TMenuItem;
  225. DebugWindows1: TMenuItem;
  226. LuaLocals1: TMenuItem;
  227. LuaGlobals1: TMenuItem;
  228. LuaOutput1: TMenuItem;
  229. LuaStack1: TMenuItem;
  230. CallStack1: TMenuItem;
  231. WatchList1: TMenuItem;
  232. Messages1: TMenuItem;
  233. Breakpoints1: TMenuItem;
  234. ProjectTree1: TMenuItem;
  235. Project2: TMenuItem;
  236. Options1: TMenuItem;
  237. N8: TMenuItem;
  238. ActivateSelectedProject1: TMenuItem;
  239. N9: TMenuItem;
  240. RemoveUnitFromProject1: TMenuItem;
  241. AddUnittoProject1: TMenuItem;
  242. Run2: TMenuItem;
  243. oggleBreakpoint1: TMenuItem;
  244. N10: TMenuItem;
  245. RunScripttoCursor1: TMenuItem;
  246. StepInto1: TMenuItem;
  247. StepOver1: TMenuItem;
  248. N11: TMenuItem;
  249. CheckSyntax1: TMenuItem;
  250. N12: TMenuItem;
  251. StopScript1: TMenuItem;
  252. PauseScript1: TMenuItem;
  253. RunScript1: TMenuItem;
  254. ools1: TMenuItem;
  255. EditorSettings1: TMenuItem;
  256. N13: TMenuItem;
  257. AsciiTable1: TMenuItem;
  258. Conversions1: TMenuItem;
  259. ErrorLookup1: TMenuItem;
  260. Calculator1: TMenuItem;
  261. N14: TMenuItem;
  262. AboutLuaEdit1: TMenuItem;
  263. ContributorsList1: TMenuItem;
  264. N18: TMenuItem;
  265. LuaHelp1: TMenuItem;
  266. Help1: TMenuItem;
  267. XPManifest1: TXPManifest;
  268. xmpMenuPainter: TXPMenu;
  269. actShowRings: TAction;
  270. ClipboardRing1: TMenuItem;
  271. actShowFunctionList: TAction;
  272. FunctionList1: TMenuItem;
  273. actFunctionHeader: TAction;
  274. N23: TMenuItem;
  275. HeaderBuilder1: TMenuItem;
  276. Functions1: TMenuItem;
  277. actGotoLastEdited: TAction;
  278. GotoLastEdited1: TMenuItem;
  279. N24: TMenuItem;
  280. GotoLastEdited2: TMenuItem;
  281. GotoLine2: TMenuItem;
  282. actBlockComment: TAction;
  283. actBlockUncomment: TAction;
  284. CommentSelection1: TMenuItem;
  285. UncommentSelection1: TMenuItem;
  286. CommentSelection2: TMenuItem;
  287. UncommentSelection2: TMenuItem;
  288. jvAppDrop: TJvDragDrop;
  289. actUpperCase: TAction;
  290. actLowerCase: TAction;
  291. UpperCaseSelection1: TMenuItem;
  292. LowerCaseSelection1: TMenuItem;
  293. pnlMain: TPanel;
  294. actShowInternalBrowser: TAction;
  295. InternalBrowser1: TMenuItem;
  296. AddWatch1: TMenuItem;
  297. AddWatch2: TMenuItem;
  298. jvUnitBar: TJvTabBar;
  299. actFindInFiles: TAction;
  300. FindinFiles1: TMenuItem;
  301. actShowFindWindow1: TAction;
  302. actShowFindWindow2: TAction;
  303. FindWindow11: TMenuItem;
  304. FindWindow21: TMenuItem;
  305. actEnableDisableBreakpoint: TAction;
  306. DisableEnableBreakpoint1: TMenuItem;
  307. ToolButton26: TToolButton;
  308. ToolButton27: TToolButton;
  309. tlbEdit: TToolBar;
  310. ToolButton28: TToolButton;
  311. ToolButton29: TToolButton;
  312. ToolButton30: TToolButton;
  313. ToolButton31: TToolButton;
  314. ToolButton32: TToolButton;
  315. ToolButton44: TToolButton;
  316. ToolButton45: TToolButton;
  317. ToolButton46: TToolButton;
  318. ToolButton47: TToolButton;
  319. ToolButton48: TToolButton;
  320. ToolButton49: TToolButton;
  321. Find1: TMenuItem;
  322. Find2: TMenuItem;
  323. actRemoteSession: TAction;
  324. N25: TMenuItem;
  325. InitiateRemoteSession1: TMenuItem;
  326. N26: TMenuItem;
  327. LuaEditHomePage1: TMenuItem;
  328. actShowProfiler: TAction;
  329. Profiler1: TMenuItem;
  330. ComponentsContributors1: TMenuItem;
  331. actCompileScipt: TAction;
  332. Compilescript1: TMenuItem;
  333. sdlgCompileOut: TSaveDialog;
  334. ToolButton24: TToolButton;
  335. CreateGUID1: TMenuItem;
  336. actMacroManager: TAction;
  337. RegistryEditor1: TMenuItem;
  338. mnuMacros: TMenuItem;
  339. MacroManager1: TMenuItem;
  340. actNewMacro: TAction;
  341. Macro1: TMenuItem;
  342. ToolButton25: TToolButton;
  343. actNewTextFile: TAction;
  344. ToolButton38: TToolButton;
  345. extFile1: TMenuItem;
  346. actShowGUIInspector: TAction;
  347. ShowGUIInspector1: TMenuItem;
  348. actNewGUIForm: TAction;
  349. GUIForm1: TMenuItem;
  350. ToolButton39: TToolButton;
  351. actShowGUIControls: TAction;
  352. GUIControls1: TMenuItem;
  353. actBringGUIFormToFront: TAction;
  354. N27: TMenuItem;
  355. PathConverter1: TMenuItem;
  356. N28: TMenuItem;
  357. BringGUIFormtoFront1: TMenuItem;
  358. XMLDocument1: TXMLDocument;
  359. procedure FormCreate(Sender: TObject);
  360. procedure synEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  361. procedure actOpenFileExecute(Sender: TObject);
  362. procedure actOpenProjectExecute(Sender: TObject);
  363. procedure actExitExecute(Sender: TObject);
  364. procedure actSaveExecute(Sender: TObject);
  365. procedure actSaveAsExecute(Sender: TObject);
  366. procedure actNewUnitExecute(Sender: TObject);
  367. procedure actNewProjectExecute(Sender: TObject);
  368. procedure FormDestroy(Sender: TObject);
  369. procedure actSaveProjectAsExecute(Sender: TObject);
  370. procedure actSaveAllExecute(Sender: TObject);
  371. procedure actCloseExecute(Sender: TObject);
  372. procedure actUndoExecute(Sender: TObject);
  373. procedure actRedoExecute(Sender: TObject);
  374. procedure actCutExecute(Sender: TObject);
  375. procedure actCopyExecute(Sender: TObject);
  376. procedure actPasteExecute(Sender: TObject);
  377. procedure actFindExecute(Sender: TObject);
  378. procedure actFindAgainExecute(Sender: TObject);
  379. procedure actFindReplaceExecute(Sender: TObject);
  380. procedure actGoToLineExecute(Sender: TObject);
  381. procedure AboutLuaEdit1Click(Sender: TObject);
  382. procedure actRunScriptExecute(Sender: TObject);
  383. procedure LuaHelp1Click(Sender: TObject);
  384. procedure actToggleBreakpointExecute(Sender: TObject);
  385. procedure stbMainDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
  386. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  387. procedure actStepOverExecute(Sender: TObject);
  388. procedure actPauseExecute(Sender: TObject);
  389. procedure actRunToCursorExecute(Sender: TObject);
  390. procedure actAddToPrjExecute(Sender: TObject);
  391. procedure actRemoveFromPrjExecute(Sender: TObject);
  392. procedure Project1Click(Sender: TObject);
  393. procedure actEditorSettingsExecute(Sender: TObject);
  394. procedure ToggleBookmarkClick(Sender: TObject);
  395. procedure GotoBookmarkClick(Sender: TObject);
  396. procedure Calculator1Click(Sender: TObject);
  397. procedure actBlockUnindentExecute(Sender: TObject);
  398. procedure actBlockIndentExecute(Sender: TObject);
  399. procedure actActiveSelPrjExecute(Sender: TObject);
  400. procedure ErrorLookup1Click(Sender: TObject);
  401. procedure PrintSetup1Click(Sender: TObject);
  402. procedure actPrintExecute(Sender: TObject);
  403. procedure ctrlBarDockOver(Sender: TObject; Source: TDragDockObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  404. procedure File2Click(Sender: TObject);
  405. procedure Edit2Click(Sender: TObject);
  406. procedure Run3Click(Sender: TObject);
  407. procedure ASciiTable1Click(Sender: TObject);
  408. procedure Help1Click(Sender: TObject);
  409. procedure ContributorsList1Click(Sender: TObject);
  410. procedure OpenFileatCursor1Click(Sender: TObject);
  411. procedure Conversions1Click(Sender: TObject);
  412. procedure ppmEditorPopup(Sender: TObject);
  413. procedure actAddWatchExecute(Sender: TObject);
  414. procedure ppmUnitsPopup(Sender: TObject);
  415. procedure jvchnNotifierChangeNotify(Sender: TObject; Dir: String; Actions: TJvChangeActions);
  416. procedure actMainMenuFileExecute(Sender: TObject);
  417. procedure actMainMenuViewExecute(Sender: TObject);
  418. procedure actShowProjectTreeExecute(Sender: TObject);
  419. procedure actMainMenuEditExecute(Sender: TObject);
  420. procedure actMainMenuProjectExecute(Sender: TObject);
  421. procedure actMainMenuRunExecute(Sender: TObject);
  422. procedure actMainMenuToolsExecute(Sender: TObject);
  423. procedure actMainMenuHelpExecute(Sender: TObject);
  424. procedure actShowBreakpointsExecute(Sender: TObject);
  425. procedure actShowMessagesExecute(Sender: TObject);
  426. procedure actShowWatchListExecute(Sender: TObject);
  427. procedure actShowCallStackExecute(Sender: TObject);
  428. procedure actShowLuaStackExecute(Sender: TObject);
  429. procedure actShowLuaConsoleExecute(Sender: TObject);
  430. procedure actShowLuaGlobalsExecute(Sender: TObject);
  431. procedure actShowLuaLocalsExecute(Sender: TObject);
  432. procedure actShowRingsExecute(Sender: TObject);
  433. procedure actCheckSyntaxExecute(Sender: TObject);
  434. procedure actShowFunctionListExecute(Sender: TObject);
  435. procedure actFunctionHeaderExecute(Sender: TObject);
  436. procedure actGotoLastEditedExecute(Sender: TObject);
  437. procedure actBlockCommentExecute(Sender: TObject);
  438. procedure actBlockUncommentExecute(Sender: TObject);
  439. procedure jvAppDropDrop(Sender: TObject; Pos: TPoint; Value: TStrings);
  440. procedure actUpperCaseExecute(Sender: TObject);
  441. procedure actLowerCaseExecute(Sender: TObject);
  442. procedure actShowInternalBrowserExecute(Sender: TObject);
  443. procedure jvUnitBarTabSelecting(Sender: TObject; Item: TJvTabBarItem; var AllowSelect: Boolean);
  444. procedure jvUnitBarTabClosed(Sender: TObject; Item: TJvTabBarItem);
  445. procedure actPrjSettingsExecute(Sender: TObject);
  446. procedure actStopExecute(Sender: TObject);
  447. procedure actStepIntoExecute(Sender: TObject);
  448. procedure actSelectAllExecute(Sender: TObject);
  449. procedure actFindInFilesExecute(Sender: TObject);
  450. procedure actShowFindWindow1Execute(Sender: TObject);
  451. procedure actShowFindWindow2Execute(Sender: TObject);
  452. procedure jvUnitBarChange(Sender: TObject);
  453. procedure actEnableDisableBreakpointExecute(Sender: TObject);
  454. procedure Find1Click(Sender: TObject);
  455. procedure ppmToolBarPopup(Sender: TObject);
  456. procedure actRemoteSessionExecute(Sender: TObject);
  457. procedure LuaEditHomePage1Click(Sender: TObject);
  458. procedure actShowProfilerExecute(Sender: TObject);
  459. procedure ComponentsContributors1Click(Sender: TObject);
  460. procedure actCompileSciptExecute(Sender: TObject);
  461. procedure CreateGUID1Click(Sender: TObject);
  462. procedure RegistryEditor1Click(Sender: TObject);
  463. procedure actMacroManagerExecute(Sender: TObject);
  464. procedure actNewMacroExecute(Sender: TObject);
  465. procedure actNewTextFileExecute(Sender: TObject);
  466. procedure actShowGUIInspectorExecute(Sender: TObject);
  467. procedure actNewGUIFormExecute(Sender: TObject);
  468. procedure actShowGUIControlsExecute(Sender: TObject);
  469. procedure actBringGUIFormToFrontExecute(Sender: TObject);
  470. procedure PathConverter1Click(Sender: TObject);
  471. //procedure actFunctionHeaderExecute(Sender: TObject);
  472. private
  473. { Private declarations }
  474. procedure WndProc(var Msg: TMessage); override;
  475. public
  476. { Public declarations }
  477. // DEBUG (Lua) variables
  478. PrevFile: string;
  479. PrevLine: Integer;
  480. CurrentICI: Integer;
  481. PauseICI: Integer;
  482. Running: Boolean;
  483. ReStart, Pause: Boolean;
  484. PauseLine: Integer;
  485. PauseFile: string;
  486. NotifyModified: Boolean;
  487. LuaState: Plua_State;
  488. MacroLuaState: Plua_State;
  489. // Search variables
  490. sSearchInFilesString: String;
  491. sSearchInFilesDir: String;
  492. sSearchString: String;
  493. sReplaceString: String;
  494. SearchedText: TStringList;
  495. SearchedInFilesText: TStringList;
  496. ReplacedText: TStringList;
  497. srSearchInFilesWhere: Integer;
  498. srSearchInFilesOutput: Integer;
  499. srSearchDriection: Integer;
  500. srSearchScope: Integer;
  501. srSearchOrigin: Integer;
  502. srReplaceAll: Boolean;
  503. srPromptForReplace: Boolean;
  504. srSearchSensitive: Boolean;
  505. srSearchRegularExpression: Boolean;
  506. srSearchWholeWords: Boolean;
  507. srSearchInFilesSensitive: Boolean;
  508. srSearchInFilesRegularExpression: Boolean;
  509. srSearchInFilesWholeWords: Boolean;
  510. srSearchInFilesSubDir: Boolean;
  511. function ClosingUnit(): Boolean;
  512. procedure AddFileInTab(pFile: TLuaEditBasicTextFile);
  513. procedure AddToNotifier(sPath: String);
  514. function GetNewProjectName(sFileSuffix: String): String;
  515. function GetNewFileName(sFileSuffix: String): String;
  516. procedure CheckButtons;
  517. procedure BuildReopenMenu;
  518. function IsReopenInList(sString: String): Boolean;
  519. procedure MonitorFileToRecent(sString: String);
  520. procedure BuildMacroList();
  521. procedure mnuXReopenClick(Sender: TObject);
  522. procedure mnuXMacroClick(Sender: TObject);
  523. procedure btnXFilesClick(Sender: TObject);
  524. procedure btnXClipboardClick(Sender: TObject);
  525. function IsProjectOpened(sProjectPath: String): Boolean;
  526. function IsFileOpened(sFilePath: String): Boolean;
  527. function GetOpenedFile(sFilePath: String): TLuaEditBasicTextFile;
  528. procedure SynEditReplaceText(Sender: TObject; const ASearch, AReplace: String; Line, Column: Integer; var Action: TSynReplaceAction);
  529. procedure synEditSpecialLineColors(Sender: TObject; Line: Integer; var Special: Boolean; var FG, BG: TColor);
  530. procedure synEditGutterClick(Sender: TObject; Button: TMouseButton; X, Y, Line: Integer; Mark: TSynEditMark);
  531. procedure synEditMouseCursor(Sender: TObject; const aLineCharPos: TBufferCoord; var aCursor: TCursor);
  532. procedure synEditChange(Sender: TObject);
  533. procedure synEditClick(Sender: TObject);
  534. procedure synEditDblClick(Sender: TObject);
  535. procedure synEditMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  536. procedure synEditScroll(Sender: TObject; ScrollBar: TScrollBarKind);
  537. procedure synCompletionExecute(Kind: SynCompletionType; Sender: TObject; var CurrentInput: String; var x, y: Integer; var CanExecute: Boolean);
  538. function GetBaseCompletionProposal: TSynCompletionProposal;
  539. function GetBaseParamsProposal: TSynCompletionProposal;
  540. procedure LoadEditorSettingsFromIni;
  541. procedure LoadEditorSettingsFromReg;
  542. procedure GetColorSet(sColorSet: String);
  543. procedure ApplyValuesToEditor(synTemp: TSynEdit; lstColorSheme: TList);
  544. function ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
  545. procedure RefreshOpenedUnits;
  546. procedure synParamsExecute(Kind: SynCompletionType; Sender: TObject; var AString: String; var x, y: Integer; var CanExecute: Boolean);
  547. procedure FillLookUpList;
  548. function FileIsInTree(sFileName: String): PVirtualNode;
  549. //function FindUnitInTabs(pLuaEditBasicTextFile: TLuaEditBasicTextFile): TLuaEditBasicTextFile;
  550. //function FindUnitInTabsStr(sUnitName: String): TLuaEditBasicTextFile;
  551. procedure PrintLuaStack(L: Plua_State);
  552. procedure PrintStack;
  553. procedure PrintLocal(L: Plua_State; Level: Integer = 0);
  554. procedure PrintGlobal(L: Plua_State; Foce: Boolean = False);
  555. procedure PrintWatch(L: Plua_State);
  556. function IsBreak(sFileName: String; Line: Integer): Boolean;
  557. function IsICI(ICI: Integer): Boolean;
  558. function IsEdited(pIgnoreUnit: TLuaEditUnit = nil): Boolean;
  559. function PopUpUnitToScreen(sFileName: String; iLine: Integer = -1; bCleanPrevUnit: Boolean = False; HighlightMode: Integer = -1): TLuaEditBasicTextFile;
  560. procedure ExecuteCurrent(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer);
  561. procedure CustomExecute(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer; FuncName: string; const Args: array of string; Results: TStrings);
  562. procedure RemoteCustomExecute(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer; FuncName: string; const Args: array of string; Results: TStrings);
  563. procedure CallHookFunc(L: Plua_State; AR: Plua_Debug);
  564. procedure CleanUpTempDir();
  565. // Action manager functions
  566. function DoCompileSciptExecute(): Boolean;
  567. function DoCheckSyntaxExecute(): Boolean;
  568. function DoOpenFileExecute(FilesName: TStringList): Boolean;
  569. function DoOpenProjectExecute(): Boolean;
  570. function DoExitExecute(): Boolean;
  571. function DoSaveAsExecute(pFile: TLuaEditBasicTextFile): Boolean;
  572. function DoNewTextFileExecute(): Boolean;
  573. function DoNewMacroExecute(): Boolean;
  574. function DoNewGUIFormExecute(): Boolean;
  575. function DoNewUnitExecute(): Boolean;
  576. function DoNewProjectExecute(): Boolean;
  577. function DoSaveProjectAsExecute(): Boolean;
  578. function DoSaveAllExecute(): Boolean;
  579. function DoMainMenuFileExecute(): Boolean;
  580. function DoMainMenuEditExecute(): Boolean;
  581. function DoMainMenuViewExecute(): Boolean;
  582. function DoMainMenuProjectExecute(): Boolean;
  583. function DoMainMenuRunExecute(): Boolean;
  584. function DoMainMenuToolsExecute(): Boolean;
  585. function DoMainMenuHelpExecute(): Boolean;
  586. function DoBringGUIFormToFrontExecute(): Boolean;
  587. function DoShowProjectTreeExecute(): Boolean;
  588. function DoShowGUIInspector(): Boolean;
  589. function DoShowBreakpointsExecute(): Boolean;
  590. function DoShowMessagesExecute(): Boolean;
  591. function DoShowWatchListExecute(): Boolean;
  592. function DoShowProfilerExecute(): Boolean;
  593. function DoShowGUIControlsExecute(): Boolean;
  594. function DoShowCallStackExecute(): Boolean;
  595. function DoShowLuaStackExecute(): Boolean;
  596. function DoShowLuaConsoleExecute(): Boolean;
  597. function DoShowLuaGlobalsExecute(): Boolean;
  598. function DoShowLuaLocalsExecute(): Boolean;
  599. function DoShowRingsExecute(): Boolean;
  600. function DoShowFunctionListExecute(): Boolean;
  601. function DoShowInternalBrowserExecute(): Boolean;
  602. function DoShowFindWindow1Execute(): Boolean;
  603. function DoShowFindWindow2Execute(): Boolean;
  604. function DoUndoExecute(): Boolean;
  605. function DoRedoExecute(): Boolean;
  606. function DoCutExecute(): Boolean;
  607. function DoCopyExecute(): Boolean;
  608. function DoPasteExecute(): Boolean;
  609. function DoSelectAll(): Boolean;
  610. function DoFindExecute(): Boolean;
  611. function DoFindAgainExecute(): Boolean;
  612. function DoFindReplaceExecute(): Boolean;
  613. function DoFindInFilesExecute(): Boolean;
  614. function DoGoToLineExecute(): Boolean;
  615. function DoGotoLastEditedExecute(): Boolean;
  616. function DoRunScriptExecute(): Boolean;
  617. function DoAddWatchExecute(): Boolean;
  618. function DoToggleBreakpointExecute(): Boolean;
  619. function DoEnableDisableBreakpoint(): Boolean;
  620. function DoStepOverExecute(): Boolean;
  621. function DoStepIntoExecute(): Boolean;
  622. function DoPauseExecute(): Boolean;
  623. function DoStopExecute(): Boolean;
  624. function DoRunToCursorExecute(): Boolean;
  625. function DoAddToPrjExecute(FilePathToAdd: String = ''): Boolean;
  626. function DoRemoveFromPrjExecute(pFileToRemove: TLuaEditFile = nil): Boolean;
  627. function DoEditorSettingsExecute(): Boolean;
  628. function DoMacroManagerExecute(): Boolean;
  629. function DoBlockUnindentExecute(): Boolean;
  630. function DoBlockIndentExecute(): Boolean;
  631. function DoBlockCommentExecute(): Boolean;
  632. function DoBlockUncommentExecute(): Boolean;
  633. function DoUpperCaseExecute(): Boolean;
  634. function DoLowerCaseExecute(): Boolean;
  635. function DoPrjSettingsExecute(): Boolean;
  636. function DoActiveSelPrjExecute(): Boolean;
  637. function DoPrintExecute(): Boolean;
  638. function DoCloseExecute(): Boolean;
  639. function DoSaveExecute(pFile: TLuaEditBasicTextFile): Boolean;
  640. function DoRemoteSessionExecute(): Boolean;
  641. end;
  642. const
  643. _LuaEditVersion = '3.0.4';
  644. var
  645. frmLuaEditMain: TfrmLuaEditMain;
  646. LuaEditDebugFilesTypeSet: TLuaEditDebugFilesTypeSet;
  647. LuaEditTextFilesTypeSet: TLuaEditTextFilesTypeSet;
  648. LuaProjects: TList;
  649. LuaSingleFiles: TLuaEditProject;
  650. LuaOpenedFiles: TList;
  651. ActiveProject: TLuaEditProject;
  652. DraggedTab: Integer;
  653. LookupList: TStringList;
  654. CallStack: TList;
  655. //Settings variables
  656. EditorOptions: TSynEditorOptions;
  657. AnimatedTabsSpeed: Integer;
  658. TabWidth: Integer;
  659. UndoLimit: Integer;
  660. ShowGutter: Boolean;
  661. ShowLineNumbers: Boolean;
  662. LeadingZeros: Boolean;
  663. GutterWidth: Integer;
  664. GutterColor: String;
  665. FontName: String;
  666. FontSize: Integer;
  667. ColorSet: String;
  668. EditorColors: TList;
  669. PrintUseColor: Boolean;
  670. PrintUseSyntax: Boolean;
  671. PrintUseWrapLines: Boolean;
  672. PrintLineNumbers: Boolean;
  673. PrintLineNumbersInMargin: Boolean;
  674. AssociateFiles: Boolean;
  675. SaveProjectsInc: Boolean;
  676. SaveUnitsInc: Boolean;
  677. SaveBreakpoints: Boolean;
  678. ShowExSaveDlg: Boolean;
  679. KeepSIFWindowOpened: Boolean;
  680. ShowStatusBar: Boolean;
  681. LibrariesSearchPaths: TStringList;
  682. HomePage: String;
  683. SearchPage: String;
  684. TempFolder: String;
  685. HistoryMaxAge: Integer;
  686. MaxTablesSize: Integer;
  687. MaxSubTablesLevel: Integer;
  688. CheckCyclicReferencing: Boolean;
  689. AutoLoadLibBasic: Boolean;
  690. AutoLoadLibPackage: Boolean;
  691. AutoLoadLibTable: Boolean;
  692. AutoLoadLibString: Boolean;
  693. AutoLoadLibMath: Boolean;
  694. AutoLoadLibOSIO: Boolean;
  695. AutoLoadLibDebug: Boolean;
  696. ShowStackTraceOnError: Boolean;
  697. //Debugger variables
  698. LDebug: Plua_State;
  699. FirstClickPos: TBufferCoord;
  700. lstLocals: TList;
  701. ltGlobals: TLuaTable;
  702. lstStack: TStringList;
  703. lstLuaStack: TStringList;
  704. IsCompiledComplete: Boolean;
  705. FirstLineStop: Boolean;
  706. StepOverPressed: Boolean;
  707. StepIntoPressed: Boolean;
  708. RunToCursorPressed: Boolean;
  709. PausePressed: Boolean;
  710. PlayPressed: Boolean;
  711. StopPressed: Boolean;
  712. CallLevel: Integer;
  713. WaitInCallLevel: Integer;
  714. sMainInitializer: String;
  715. hModule: Cardinal;
  716. HasChangedWhileCompiled: Boolean;
  717. IsRemoteDebug: Boolean;
  718. WSA: WSAData;
  719. pSock: TSocket;
  720. pRSock: TSocket;
  721. // Misc functions
  722. function GetLocal(Key: String): TLuaVariable;
  723. procedure DoLuaStdoutEx(F, S: PChar; L, N: Integer);
  724. function LocalOutput(L: PLua_State): Integer; cdecl;
  725. procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
  726. procedure CallRemoteHookFunc(pSock: TSocket);
  727. function ParamStrEx(Index: Integer; CommandLine: PChar; ExeName: PChar): PChar; cdecl; external 'LuaEditSys.dll';
  728. function ParamCountEx(CommandLine: PChar): Integer; cdecl; external 'LuaEditSys.dll';
  729. //function FunctionHeaderBuilder(OwnerAppHandle: HWND; sLine: PChar): PChar; cdecl; external 'HdrBld.dll';
  730. implementation
  731. uses
  732. LuaVirtualTrees, LuaSyntax, Search, Replace, ReplaceQuerry, GotoLine, About,
  733. ProjectTree, Stack, Watch, Grids, AddToPrj, EditorSettings,
  734. PrjSettings, ErrorLookup, LuaStack, PrintSetup,
  735. Math, Contributors, LuaConsole, Breakpoints, LuaGlobals,
  736. LuaLocals, LuaEditMessages, ExSaveExit, AsciiTable, ReadOnlyMsgBox,
  737. Rings, JvOutlookBar, SynEditTextBuffer, FunctionList,
  738. JvDockSupportControl, InternalBrowser, FindInFiles, SIFReport,
  739. FindWindow1, FindWindow2, UploadFiles, Profiler, ComponentList, GUID,
  740. MacroManager, GUIInspector, GUIControls, GUIFormType, ConvertPath,
  741. ComObj;
  742. {$R *.dfm}
  743. ///////////////////////////////////////////////////////////////////
  744. // Misc functions
  745. ///////////////////////////////////////////////////////////////////
  746. // Get a lua local from the lstLocals global variable...
  747. function GetLocal(Key: String): TLuaVariable;
  748. var
  749. bFound: Boolean;
  750. x: Integer;
  751. begin
  752. Result := nil;
  753. bFound := False;
  754. x := 0;
  755. while ((not bFound) and (x < lstLocals.Count)) do
  756. begin
  757. if TLuaVariable(lstLocals.Items[x]).Name = Key then
  758. begin
  759. Result := TLuaVariable(lstLocals.Items[x]);
  760. bFound := True;
  761. end
  762. else
  763. Inc(x);
  764. end;
  765. end;
  766. // stdout extended function for lua_print and lua_io_write override
  767. procedure DoLuaStdoutEx(F, S: PChar; L, N: Integer);
  768. const
  769. CR = #$0D;
  770. LF = #$0A;
  771. CRLF = CR + LF;
  772. begin
  773. frmLuaConsole.Put(F, StringReplace(S, LF, CRLF, [rfReplaceAll]), L);
  774. end;
  775. // Handle localy lua print to stdout
  776. function LocalOutput(L: PLua_State): Integer; cdecl;
  777. begin
  778. // Prints out here!
  779. lua_print(L);
  780. Result := 0;
  781. end;
  782. // Function used for lua call hooks (localy)
  783. procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
  784. begin
  785. frmLuaEditMain.CallHookFunc(L, AR);
  786. end;
  787. // Function used for lua call hooks (remotely)
  788. procedure CallRemoteHookFunc(pSock: TSocket);
  789. var
  790. sStackString: String;
  791. x, Status: Integer;
  792. BtnInfos: Integer;
  793. Answer, CaretY: Integer;
  794. Len, ItemCount: Integer;
  795. AR: lua_Debug;
  796. DbgBuffer: array[0..5000] of char;
  797. DbgString: String;
  798. DbgInt: Integer;
  799. DbgLen: Integer;
  800. Buffer: array[0..5000] of char;
  801. begin
  802. if StopPressed then
  803. begin
  804. Answer := 1;
  805. StopPressed := False;
  806. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.iCurrentLineDebug := -1;
  807. end
  808. else
  809. Answer := 0;
  810. //sending Stop button status
  811. Status := send(pSock, Answer, SizeOf(Answer), 0);
  812. if Status <> SizeOf(Answer) then
  813. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the stop button status');
  814. //sending Pause button status
  815. if PausePressed then
  816. Answer := 1
  817. else
  818. Answer := 0;
  819. Status := send(pSock, Answer, SizeOf(Answer), 0);
  820. if Status <> SizeOf(Answer) then
  821. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the pause button status');
  822. //sending RunToCursor button status
  823. if RunToCursorPressed then
  824. Answer := 1
  825. else
  826. Answer := 0;
  827. Status := send(pSock, Answer, SizeOf(Answer), 0);
  828. if Status <> SizeOf(Answer) then
  829. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the RunToCursor button status');
  830. //receiving the lua_debug structure
  831. Status := recv(pSock, DbgInt, SizeOf(DbgInt), 0);
  832. if Status <> SizeOf(DbgInt) then
  833. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  834. // - 1 because of the lua debug bug!!!
  835. AR.currentline := DbgInt - 1;
  836. Status := recv(pSock, DbgInt, SizeOf(DbgInt), 0);
  837. if Status <> SizeOf(DbgInt) then
  838. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  839. AR.event := DbgInt;
  840. Status := recv(pSock, DbgInt, SizeOf(DbgInt), 0);
  841. if Status <> SizeOf(DbgInt) then
  842. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  843. AR.i_ci := DbgInt;
  844. Status := recv(pSock, DbgInt, SizeOf(DbgInt), 0);
  845. if Status <> SizeOf(DbgInt) then
  846. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  847. AR.linedefined := DbgInt;
  848. Status := recv(pSock, DbgInt, SizeOf(DbgInt), 0);
  849. if Status <> SizeOf(DbgInt) then
  850. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  851. AR.nups := DbgInt;
  852. FillChar(DbgBuffer, 5000, 0);
  853. DbgString := '';
  854. DbgLen := 0;
  855. Status := recv(pSock, DbgLen, SizeOf(DbgLen), 0);
  856. if Status <> SizeOf(DbgLen) then
  857. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  858. Status := recv(pSock, DbgBuffer, DbgLen, 0);
  859. if Status <> DbgLen then
  860. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  861. DbgString := DbgBuffer;
  862. if DbgString = '@@LUA_TNIL@@' then
  863. AR.name := nil
  864. else
  865. AR.name := PChar(DbgString);
  866. FillChar(DbgBuffer, 5000, 0);
  867. DbgString := '';
  868. DbgLen := 0;
  869. Status := recv(pSock, DbgLen, SizeOf(DbgLen), 0);
  870. if Status <> SizeOf(DbgLen) then
  871. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  872. Status := recv(pSock, DbgBuffer, DbgLen, 0);
  873. if Status <> DbgLen then
  874. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  875. DbgString := DbgBuffer;
  876. if DbgString = '@@LUA_TNIL@@' then
  877. AR.namewhat := nil
  878. else
  879. AR.namewhat := PChar(DbgString);
  880. FillChar(DbgBuffer, 5000, 0);
  881. DbgString := '';
  882. DbgLen := 0;
  883. Status := recv(pSock, DbgLen, SizeOf(DbgLen), 0);
  884. if Status <> SizeOf(DbgLen) then
  885. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  886. Status := recv(pSock, DbgBuffer, DbgLen, 0);
  887. if Status <> DbgLen then
  888. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  889. DbgString := DbgBuffer;
  890. if DbgString = '@@LUA_TNIL@@' then
  891. AR.short_src := ''
  892. else
  893. StrPCopy(AR.short_src, DbgString[1]);
  894. FillChar(DbgBuffer, 5000, 0);
  895. DbgString := '';
  896. DbgLen := 0;
  897. Status := recv(pSock, DbgLen, SizeOf(DbgLen), 0);
  898. if Status <> SizeOf(DbgLen) then
  899. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  900. Status := recv(pSock, DbgBuffer, DbgLen, 0);
  901. if Status <> DbgLen then
  902. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  903. DbgString := DbgBuffer;
  904. if DbgString = '@@LUA_TNIL@@' then
  905. AR.source := nil
  906. else
  907. AR.source := PChar(DbgString);
  908. FillChar(DbgBuffer, 5000, 0);
  909. DbgString := '';
  910. DbgLen := 0;
  911. Status := recv(pSock, DbgLen, SizeOf(DbgLen), 0);
  912. if Status <> SizeOf(DbgLen) then
  913. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  914. Status := recv(pSock, DbgBuffer, DbgLen, 0);
  915. if Status <> DbgLen then
  916. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving a field of the PLua_Debug structure');
  917. DbgString := DbgBuffer;
  918. if DbgString = '@@LUA_TNIL@@' then
  919. AR.what := nil
  920. else
  921. AR.what := PChar(DbgString);
  922. //Sending Current line informations...
  923. if TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.IsBreakPointLine(AR.currentline) then
  924. begin
  925. Answer := 1;
  926. frmLuaEditMain.Running := False;
  927. WaitInCallLevel := -1;
  928. end
  929. else if FirstLineStop then
  930. begin
  931. FirstLineStop := False;
  932. Answer := 1;
  933. frmLuaEditMain.Running := False;
  934. WaitInCallLevel := -1;
  935. end
  936. else
  937. Answer := 0;
  938. Status := send(pSock, Answer, SizeOf(Answer), 0);
  939. if Status <> SizeOf(Answer) then
  940. ELuaEditException.Create('Remote Debug Failed: The operation failed while sending Current line informations');
  941. //sending Caret Y...
  942. CaretY := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.CaretY;
  943. Status := send(pSock, CaretY, SizeOf(CaretY), 0);
  944. if Status <> SizeOf(CaretY) then
  945. raise ELuaEditException.Create('Remote Debug Failed: The opertion failed while sending the caret y position');
  946. if ((RunToCursorPressed = True) and (AR.currentline = TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.CaretY)) then
  947. begin
  948. RunToCursorPressed := False;
  949. frmLuaEditMain.Running := False;
  950. WaitInCallLevel := -1;
  951. end
  952. else if ((RunToCursorPressed = True) and not frmLuaEditMain.Running) then
  953. begin
  954. frmLuaEditMain.Running := True;
  955. end;
  956. if (not frmLuaEditMain.Running and (StopPressed = False)) then
  957. begin
  958. frmStack.lstCallStack.Items.Assign(Main.lstStack);
  959. frmStack.lstCallStack.Refresh;
  960. lstLuaStack.Clear;
  961. //receiving item numbers...
  962. Status := recv(pSock, ItemCount, SizeOf(ItemCount), 0);
  963. if Status <> SizeOf(ItemCount) then
  964. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the number of item for the lua stack');
  965. //receiving items values
  966. for x := 0 to ItemCount - 1 do
  967. begin
  968. FillChar(Buffer, SizeOf(Buffer), 0);
  969. Len := 0;
  970. Status := recv(pSock, Len, SizeOf(Len), 0);
  971. if Status <> SizeOf(Len) then
  972. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the length of an item value for the lua stack');
  973. Status := recv(pSock, Buffer, Len, 0);
  974. if Status <> Len then
  975. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the value of an item for the lua stack');
  976. lstLuaStack.Add(Buffer);
  977. end;
  978. frmLuaStack.lstLuaStack.Items.Assign(Main.lstLuaStack);
  979. frmLuaStack.lstLuaStack.Refresh;
  980. end;
  981. Case AR.event of
  982. LUA_HOOKCALL:
  983. begin
  984. if AR.name <> nil then
  985. begin
  986. //receiving sStackString...
  987. FillChar(Buffer, SizeOf(Buffer), 0);
  988. Len := 0;
  989. Status := recv(pSock, Len, SizeOf(Len), 0);
  990. if Status <> SizeOf(Len) then
  991. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the length of the sStackString value');
  992. Status := recv(pSock, Buffer, Len, 0);
  993. if Status <> Len then
  994. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the sStackString value');
  995. sStackString := Buffer;
  996. lstStack.Add(sStackString);
  997. end;
  998. Inc(CallLevel);
  999. end;
  1000. LUA_HOOKRET:
  1001. begin
  1002. if AR.name <> nil then
  1003. begin
  1004. lstStack.Delete(lstStack.Count - 1);
  1005. StepIntoPressed := False;
  1006. end;
  1007. Dec(CallLevel);
  1008. end;
  1009. LUA_HOOKLINE:
  1010. begin
  1011. if ((WaitInCallLevel <> -1) and (PausePressed = False)) then
  1012. begin
  1013. if CallLevel > WaitInCallLevel then
  1014. begin
  1015. Exit;
  1016. end
  1017. else
  1018. begin
  1019. WaitInCallLevel := -1;
  1020. end;
  1021. end;
  1022. if (not frmLuaEditMain.Running or (PausePressed = True)) then
  1023. begin
  1024. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.GotoLineAndCenter(AR.currentline);
  1025. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.iCurrentLineDebug := AR.currentline;
  1026. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  1027. frmStack.lstCallStack.Items.Assign(Main.lstStack);
  1028. lstLuaStack.Clear;
  1029. lstLocals.Clear;
  1030. ltGlobals.Clear;
  1031. //receiving items numbers...
  1032. Status := recv(pSock, ItemCount, SizeOf(ItemCount), 0);
  1033. if Status <> SizeOf(ItemCount) then
  1034. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the number of item for the lua stack');
  1035. //receiving items values
  1036. for x := 0 to ItemCount - 1 do
  1037. begin
  1038. FillChar(Buffer, SizeOf(Buffer), 0);
  1039. Len := 0;
  1040. Status := recv(pSock, Len, SizeOf(Len), 0);
  1041. if Status <> SizeOf(Len) then
  1042. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the length of an item value for the lua stack');
  1043. Status := recv(pSock, Buffer, Len, 0);
  1044. if Status <> Len then
  1045. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the value of an item for the lua stack');
  1046. lstLuaStack.Add(Buffer);
  1047. end;
  1048. //receiving locals numbers...
  1049. Status := recv(pSock, ItemCount, SizeOf(ItemCount), 0);
  1050. if Status <> SizeOf(ItemCount) then
  1051. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the number of locals to get');
  1052. //receiving locals values
  1053. for x := 0 to ItemCount - 1 do
  1054. begin
  1055. FillChar(Buffer, SizeOf(Buffer), 0);
  1056. Len := 0;
  1057. Status := recv(pSock, Len, SizeOf(Len), 0);
  1058. if Status <> SizeOf(Len) then
  1059. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the length of a local value');
  1060. Status := recv(pSock, Buffer, Len, 0);
  1061. if Status <> Len then
  1062. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the value of a local');
  1063. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1064. // WARNING: to part of the function is to be reviewed when remote debugging will be available
  1065. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1066. //lstLocals.Add(Buffer);
  1067. end;
  1068. //receiving globals numbers...
  1069. Status := recv(pSock, ItemCount, SizeOf(ItemCount), 0);
  1070. if Status <> SizeOf(ItemCount) then
  1071. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the number of globals to get');
  1072. //receiving globals values
  1073. for x := 0 to ItemCount - 1 do
  1074. begin
  1075. FillChar(Buffer, SizeOf(Buffer), 0);
  1076. Len := 0;
  1077. Status := recv(pSock, Len, SizeOf(Len), 0);
  1078. if Status <> SizeOf(Len) then
  1079. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the length of a global value');
  1080. Status := recv(pSock, Buffer, Len, 0);
  1081. if Status <> Len then
  1082. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the value of a global');
  1083. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1084. // WARNING: to part of the function is to be reviewed when remote debugging will be available
  1085. /////////////////////////////////////////////////////////////////////////////////////////////////////
  1086. //lstGlobals.Add(Buffer);
  1087. end;
  1088. frmLuaStack.lstLuaStack.Items.Assign(Main.lstLuaStack);
  1089. if PausePressed then
  1090. begin
  1091. frmLuaEditMain.Running := False;
  1092. StepOverPressed := False;
  1093. StepIntoPressed := False;
  1094. PlayPressed := False;
  1095. PausePressed := False;
  1096. end;
  1097. //Waiting for user action...
  1098. while ((StepOverPressed = False) and (StepIntoPressed = False) and (PlayPressed = False) and (StopPressed = False)) do
  1099. begin
  1100. Application.ProcessMessages;
  1101. Sleep(20);
  1102. end;
  1103. //Send pressed button informations
  1104. if StepOverPressed then
  1105. begin
  1106. BtnInfos := LUA_DBGSTEPOVER;
  1107. Status := send(pSock, BtnInfos, SizeOf(BtnInfos), 0);
  1108. if Status <> SizeOf(BtnInfos) then
  1109. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the pressed button informations');
  1110. end
  1111. else if StepIntoPressed then
  1112. begin
  1113. BtnInfos := LUA_DBGSTEPINTO;
  1114. Status := send(pSock, BtnInfos, SizeOf(BtnInfos), 0);
  1115. if Status <> SizeOf(BtnInfos) then
  1116. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the pressed button informations');
  1117. end
  1118. else if PlayPressed then
  1119. begin
  1120. BtnInfos := LUA_DBGPLAY;
  1121. Status := send(pSock, BtnInfos, SizeOf(BtnInfos), 0);
  1122. if Status <> SizeOf(BtnInfos) then
  1123. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the pressed button informations');
  1124. end
  1125. else if StopPressed then
  1126. begin
  1127. BtnInfos := LUA_DBGSTOP;
  1128. Status := send(pSock, BtnInfos, SizeOf(BtnInfos), 0);
  1129. if Status <> SizeOf(BtnInfos) then
  1130. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the pressed button informations');
  1131. end;
  1132. if HasChangedWhileCompiled then
  1133. begin
  1134. if Application.MessageBox('Source has been modified. Recompile?', 'LuaEdit', MB_YESNO+MB_ICONQUESTION) = IDYES then
  1135. begin
  1136. Answer := 1;
  1137. StopPressed := True;
  1138. end
  1139. else
  1140. begin
  1141. Answer := 0;
  1142. HasChangedWhileCompiled := False;
  1143. end;
  1144. end
  1145. else
  1146. Answer := 0;
  1147. //sending changing status...
  1148. Status := send(pSock, Answer, SizeOf(Answer), 0);
  1149. if Status <> SizeOf(Answer) then
  1150. ELuaEditException.Create('Remote Debug Failed: The operation failed while sending changing status');
  1151. if StepOverPressed = True then
  1152. begin
  1153. WaitInCallLevel := CallLevel;
  1154. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.iCurrentLineDebug := -1;
  1155. end;
  1156. StepOverPressed := False;
  1157. StepIntoPressed := False;
  1158. PlayPressed := False;
  1159. PausePressed := False;
  1160. end;
  1161. end;
  1162. end;
  1163. end;
  1164. ///////////////////////////////////////////////////////////////////
  1165. // TfrmLuaEditMain class
  1166. ///////////////////////////////////////////////////////////////////
  1167. procedure TfrmLuaEditMain.FormCreate(Sender: TObject);
  1168. var
  1169. AFont: TFont;
  1170. pReg: TRegistry;
  1171. begin
  1172. // Initialize important data
  1173. LuaEditDebugFilesTypeSet := [otLuaEditUnit, otLuaEditMacro];
  1174. LuaEditTextFilesTypeSet := [otLuaEditUnit, otLuaEditMacro, otTextFile];
  1175. // Sets Printing basic options...
  1176. AFont := TFont.Create;
  1177. with SynEditPrint.Header do begin
  1178. {First line, default font, right aligned}
  1179. Add('Page: $PAGENUM$ of $PAGECOUNT$', nil, taRightJustify, 1);
  1180. {Second line, default font, left aligned}
  1181. Add('$TITLE$', nil, taLeftJustify, 1);
  1182. AFont.Assign(DefaultFont);
  1183. AFont.Size := 6;
  1184. {Second line, small font, right aligned - note that lines can have different fonts}
  1185. Add('Print Date: $DATE$. Time: $TIME$', AFont, taRightJustify, 2);
  1186. end;
  1187. with SynEditPrint.Footer do begin
  1188. AFont.Assign(DefaultFont);
  1189. Add('$PAGENUM$/$PAGECOUNT$', nil, taRightJustify, 1);
  1190. AFont.Size := 6;
  1191. Add('Printed with LuaEdit for Lua 5.0', AFont, taLeftJustify, 1);
  1192. end;
  1193. AFont.Free;
  1194. // Reads last dialog's settings
  1195. pReg := TRegistry.Create;
  1196. if pReg.OpenKey('\Software\LuaEdit', False) then
  1197. begin
  1198. if pReg.ValueExists('WasMaxed') then
  1199. begin
  1200. if not pReg.ReadBool('WasMaxed') then
  1201. begin
  1202. if pReg.ValueExists('Width') then
  1203. frmLuaEditMain.Width := pReg.ReadInteger('Width');
  1204. if pReg.ValueExists('Height') then
  1205. frmLuaEditMain.Height := pReg.ReadInteger('Height');
  1206. end
  1207. else
  1208. begin
  1209. frmLuaEditMain.WindowState := wsMaximized;
  1210. end;
  1211. end;
  1212. end;
  1213. pReg.Free;
  1214. LookupList := TStringList.Create;
  1215. EditorColors := TList.Create;
  1216. CallStack := TList.Create;
  1217. lstLocals := TList.Create;
  1218. ltGlobals := TLuaTable.Create('_G', '');
  1219. lstStack := TStringList.Create;
  1220. lstLuaStack := TStringList.Create;
  1221. LuaProjects := TList.Create;
  1222. LuaOpenedFiles := TList.Create;
  1223. SearchedText := TStringList.Create;
  1224. SearchedInFilesText := TStringList.Create;
  1225. ReplacedText := TStringList.Create;
  1226. LibrariesSearchPaths := TStringList.Create;
  1227. LibrariesSearchPaths.QuoteChar := '"';
  1228. LibrariesSearchPaths.Delimiter := ',';
  1229. LuaSingleFiles := TLuaEditProject.Create(GetLuaEditInstallPath() + '\Templates\Template.lpr');
  1230. LuaSingleFiles.Name := '[@@SingleUnits@@]';
  1231. LuaProjects.Add(LuaSingleFiles);
  1232. Running := False;
  1233. IsCompiledComplete := True;
  1234. CurrentICI := 1;
  1235. // Create dockable forms...
  1236. frmProjectTree := TfrmProjectTree.Create(Self);
  1237. frmLuaConsole := TfrmLuaConsole.Create(Self);
  1238. frmLuaStack := TfrmLuaStack.Create(Self);
  1239. frmWatch := TfrmWatch.Create(Self);
  1240. frmStack := TfrmStack.Create(Self);
  1241. frmLuaLocals := TfrmLuaLocals.Create(Self);
  1242. frmLuaGlobals := TfrmLuaGlobals.Create(Self);
  1243. frmLuaEditMessages := TfrmLuaEditMessages.Create(Self);
  1244. frmBreakpoints := TfrmBreakpoints.Create(Self);
  1245. frmRings := TfrmRings.Create(Self);
  1246. frmFunctionList := TfrmFunctionList.Create(Self);
  1247. frmInternalBrowser := TfrmInternalBrowser.Create(Self);
  1248. frmFindWindow1 := TfrmFindWindow1.Create(Self);
  1249. frmFindWindow2 := TfrmFindWindow2.Create(Self);
  1250. frmProfiler := TfrmProfiler.Create(Self);
  1251. frmGUIInspector := TfrmGUIInspector.Create(Self);
  1252. frmGUIControls := TfrmGUIControls.Create(Self);
  1253. // Assign dockable forms icons...
  1254. imlDock.GetIcon(0, frmWatch.Icon);
  1255. imlDock.GetIcon(1, frmStack.Icon);
  1256. imlDock.GetIcon(2, frmLuaStack.Icon);
  1257. imlDock.GetIcon(3, frmLuaConsole.Icon);
  1258. imlDock.GetIcon(7, frmLuaGlobals.Icon);
  1259. imlDock.GetIcon(8, frmLuaLocals.Icon);
  1260. imlDock.GetIcon(9, frmLuaEditMessages.Icon);
  1261. imlDock.GetIcon(4, frmProjectTree.Icon);
  1262. imlDock.GetIcon(6, frmBreakpoints.Icon);
  1263. imlDock.GetIcon(10, frmRings.Icon);
  1264. imlDock.GetIcon(11, frmFunctionList.Icon);
  1265. imlDock.GetIcon(12, frmInternalBrowser.Icon);
  1266. imlDock.GetIcon(13, frmFindWindow1.Icon);
  1267. imlDock.GetIcon(13, frmFindWindow2.Icon);
  1268. imlDock.GetIcon(14, frmProfiler.Icon);
  1269. imlDock.GetIcon(15, frmGUIInspector.Icon);
  1270. imlDock.GetIcon(16, frmGUIControls.Icon);
  1271. // Paint some non overriden components
  1272. xmpMenuPainter.InitComponent(frmProjectTree.ppmProjectTree);
  1273. xmpMenuPainter.InitComponent(frmBreakpoints.tlbBreakpoints);
  1274. xmpMenuPainter.InitComponent(frmFunctionList.tblFunctionList);
  1275. xmpMenuPainter.InitComponent(frmInternalBrowser.tlbInternalBrowser);
  1276. xmpMenuPainter.InitComponent(frmWatch.tblWatch);
  1277. xmpMenuPainter.InitComponent(frmWatch.ppmWatch);
  1278. // Initiate Macro Lua State
  1279. MacroLuaState := lua_open();
  1280. LERegisterToLua(MacroLuaState);
  1281. LuaRegister(MacroLuaState, 'io.write', lua_io_writeex);
  1282. LuaRegister(MacroLuaState, 'print', lua_printex);
  1283. OnLuaStdoutEx := DoLuaStdoutEx;
  1284. // Build the reopen menus and ring
  1285. BuildReopenMenu();
  1286. // Build macro menus
  1287. BuildMacroList();
  1288. end;
  1289. procedure TfrmLuaEditMain.FormDestroy(Sender: TObject);
  1290. var
  1291. pReg: TRegistry;
  1292. begin
  1293. {$ifdef RTASSERT} RTAssert(0, true, ' TfrmLuaEditMain.FormDestroy', '', 0); {$endif}
  1294. CleanUpTempDir();
  1295. // Write last windows settings
  1296. pReg := TRegistry.Create;
  1297. pReg.OpenKey('\Software\LuaEdit', True);
  1298. pReg.WriteBool('WasMaxed', (Self.WindowState = wsMaximized));
  1299. pReg.WriteInteger('Width', Self.Width);
  1300. pReg.WriteInteger('Height', Self.Height);
  1301. pReg.Free;
  1302. // Free previously created objects
  1303. LuaProjects.Free;
  1304. LuaSingleFiles.Free;
  1305. LuaOpenedFiles.Free;
  1306. LibrariesSearchPaths.Free;
  1307. ReplacedText.Free;
  1308. SearchedInFilesText.Free;
  1309. SearchedText.Free;
  1310. lstStack.Free;
  1311. lstLuaStack.Free;
  1312. lstLocals.Free;
  1313. ltGlobals.Free;
  1314. EditorColors.Free;
  1315. LookupList.Free;
  1316. CallStack.Free;
  1317. // Free Macro Lua State
  1318. lua_close(MacroLuaState);
  1319. // Free the page controller
  1320. jvUnitBar.Free;
  1321. {$ifdef RTASSERT} RTAssert(0, true, ' TfrmLuaEditMain.FormDestroy Done', '', 0); {$endif}
  1322. end;
  1323. // Special window message handling for single application instance
  1324. procedure TfrmLuaEditMain.WndProc(var Msg: TMessage);
  1325. var
  1326. x, y: Integer;
  1327. CommandLine, FileName: String;
  1328. pFiles: TStringList;
  1329. copyDataStruct: PCopyDataStruct;
  1330. copyDataType: TCopyDataType;
  1331. begin
  1332. if Msg.Msg = WM_COPYDATA then
  1333. begin
  1334. copyDataStruct := TWMCopyData(Msg).CopyDataStruct;
  1335. copyDataType := TCopyDataType(copyDataStruct.dwData);
  1336. if copyDataType = cdtAnsiString then
  1337. begin
  1338. CommandLine := PChar(copyDataStruct.lpData);
  1339. if ParamCountEx(PChar(CommandLine)) > 0 then
  1340. begin
  1341. pFiles := TStringList.Create;
  1342. for x := 1 to ParamCountEx(PChar(CommandLine)) do
  1343. begin
  1344. FileName := ParamStrEx(x, PChar(CommandLine), PChar(Application.ExeName));
  1345. if FileExistsAbs(FileName) then
  1346. begin
  1347. pFiles.Add(FileName);
  1348. frmLuaEditMain.DoOpenFileExecute(pFiles);
  1349. end;
  1350. end;
  1351. // Rebuild the project tree and initialize stuff
  1352. frmProjectTree.BuildProjectTree;
  1353. frmLuaEditMain.CheckButtons;
  1354. pFiles.Free;
  1355. end;
  1356. end;
  1357. end;
  1358. inherited WndProc(Msg);
  1359. end;
  1360. procedure TfrmLuaEditMain.synEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  1361. begin
  1362. synEditClick(Sender);
  1363. end;
  1364. function TfrmLuaEditMain.DoOpenFileExecute(FilesName: TStringList): Boolean;
  1365. var
  1366. pReg: TRegistry;
  1367. pNewPrj: TLuaEditProject;
  1368. pFile: TLuaEditBasicTextFile;
  1369. procedure OpenFiles(Files: TStringList);
  1370. var
  1371. z: integer;
  1372. begin
  1373. for z := 0 to Files.Count - 1 do
  1374. begin
  1375. if FileExistsAbs(Files.Strings[z]) then
  1376. begin
  1377. if ExtractFileExt(Files.Strings[z]) = '.lpr' then
  1378. begin
  1379. if not IsProjectOpened(Files.Strings[z]) then
  1380. begin
  1381. Result := True;
  1382. pNewPrj := TLuaEditProject.Create(Files.Strings[z]);
  1383. pNewPrj.GetProjectFromDisk(Files.Strings[z]);
  1384. // Add opened file to recent opens
  1385. pReg.OpenKey('\Software\LuaEdit', True);
  1386. pReg.WriteString('RecentPath', ExtractFilePath(Files.Strings[z]));
  1387. end
  1388. else
  1389. begin
  1390. Application.MessageBox(PChar('The file "'+Files.Strings[z]+'" is already opened in LuaEdit.'), 'LuaEdit', MB_OK+MB_ICONERROR);
  1391. Exit;
  1392. end;
  1393. end
  1394. else
  1395. begin
  1396. if not Assigned(FileIsInTree(Files.Strings[z])) then
  1397. begin
  1398. Result := True;
  1399. pFile := LuaSingleFiles.AddFile(Files.Strings[z], False);
  1400. pFile.IsLoaded := True;
  1401. AddFileInTab(pFile);
  1402. MonitorFileToRecent(Files.Strings[z]);
  1403. // Add opened file to recent opens
  1404. pReg.OpenKey('\Software\LuaEdit', True);
  1405. pReg.WriteString('RecentPath', ExtractFilePath(Files.Strings[z]));
  1406. end
  1407. else
  1408. begin
  1409. PopUpUnitToScreen(Files.Strings[z]);
  1410. Exit;
  1411. end;
  1412. end;
  1413. end;
  1414. end;
  1415. end;
  1416. begin
  1417. Result := False;
  1418. pReg := TRegistry.Create;
  1419. if pReg.OpenKey('\Software\LuaEdit', False) then
  1420. odlgOpenUnit.InitialDir := pReg.ReadString('RecentPath');
  1421. if FilesName.Count > 0 then
  1422. OpenFiles(FilesName)
  1423. else
  1424. if odlgOpenUnit.Execute then
  1425. OpenFiles(TStringList(odlgOpenUnit.Files));
  1426. // Rebuild the project tree and initialize stuff
  1427. frmProjectTree.BuildProjectTree;
  1428. BuildReopenMenu;
  1429. CheckButtons();
  1430. pReg.Free;
  1431. end;
  1432. procedure TfrmLuaEditMain.actOpenFileExecute(Sender: TObject);
  1433. var
  1434. pFiles: TStringList;
  1435. begin
  1436. pFiles := TStringList.Create;
  1437. DoOpenFileExecute(pFiles);
  1438. pFiles.Free;
  1439. end;
  1440. procedure TfrmLuaEditMain.AddFileInTab(pFile: TLuaEditBasicTextFile);
  1441. var
  1442. pJvTab: TJvTabBarItem;
  1443. begin
  1444. Screen.Cursor := crHourGlass;
  1445. // Create the tab and associate the synedit control to its data property
  1446. pJvTab := jvUnitBar.AddTab(pFile.Name);
  1447. pJvTab.Data := pFile;
  1448. pJvTab.Visible := False;
  1449. pFile.AssociatedTab := pJvTab;
  1450. pFile.SynUnit.Visible := True;
  1451. LuaOpenedFiles.Add(pFile);
  1452. // Visually initialize the synedit control and other stuff
  1453. pJvTab.Visible := True;
  1454. synEditClick(pFile.SynUnit);
  1455. jvUnitBar.SelectedTab := pJvTab;
  1456. jvUnitBarChange(jvUnitBar);
  1457. ApplyValuesToEditor(pFile.SynUnit, EditorColors);
  1458. if pFile.FileType in LuaEditDebugFilesTypeSet then
  1459. begin
  1460. TLuaEditDebugFile(pFile).GetBreakpoints();
  1461. frmBreakpoints.RefreshBreakpointList();
  1462. end;
  1463. Screen.Cursor := crDefault;
  1464. end;
  1465. function TfrmLuaEditMain.GetNewProjectName(sFileSuffix: String): String;
  1466. var
  1467. x, IncFileNumber: Integer;
  1468. FoundMatch: Boolean;
  1469. begin
  1470. Result := '';
  1471. IncFileNumber := 1;
  1472. for x := 0 to LuaProjects.Count - 1 do
  1473. begin
  1474. if TLuaEditFile(LuaProjects.Items[x]).IsNew then
  1475. Inc(IncFileNumber);
  1476. end;
  1477. FoundMatch := True;
  1478. while FoundMatch do
  1479. begin
  1480. FoundMatch := False;
  1481. for x := 0 to LuaProjects.Count - 1 do
  1482. begin
  1483. if sFileSuffix+IntToStr(IncFileNumber) = TLuaEditFile(LuaProjects.Items[x]).Name then
  1484. begin
  1485. Inc(IncFileNumber);
  1486. FoundMatch := True;
  1487. end;
  1488. end;
  1489. end;
  1490. Result := sFileSuffix+IntToStr(IncFileNumber);
  1491. end;
  1492. function TfrmLuaEditMain.GetNewFileName(sFileSuffix: String): String;
  1493. var
  1494. x, y, IncFileNumber: Integer;
  1495. FoundMatch: Boolean;
  1496. begin
  1497. Result := '';
  1498. IncFileNumber := 1;
  1499. for x := 0 to LuaProjects.Count - 1 do
  1500. begin
  1501. for y := 0 to TLuaEditProject(LuaProjects.Items[x]).lstUnits.Count - 1 do
  1502. begin
  1503. if TLuaEditFile(TLuaEditProject(LuaProjects.Items[x]).lstUnits[y]).IsNew then
  1504. Inc(IncFileNumber);
  1505. end;
  1506. end;
  1507. FoundMatch := True;
  1508. while FoundMatch do
  1509. begin
  1510. FoundMatch := False;
  1511. for x := 0 to LuaProjects.Count - 1 do
  1512. begin
  1513. for y := 0 to TLuaEditProject(LuaProjects.Items[x]).lstUnits.Count - 1 do
  1514. begin
  1515. if sFileSuffix+IntToStr(IncFileNumber) = TLuaEditFile(TLuaEditProject(LuaProjects.Items[x]).lstUnits[y]).Name then
  1516. begin
  1517. Inc(IncFileNumber);
  1518. FoundMatch := True;
  1519. end;
  1520. end;
  1521. end;
  1522. end;
  1523. Result := sFileSuffix+IntToStr(IncFileNumber);
  1524. end;
  1525. // Add root to the changes notifier
  1526. procedure TfrmLuaEditMain.AddToNotifier(sPath: String);
  1527. var
  1528. pChangeNotifyItem: TJvChangeItem;
  1529. x: Integer;
  1530. begin
  1531. // make sure the actual given root is not already in list to
  1532. // avoid overkill operations for no reasons
  1533. for x := 0 to jvchnNotifier.Notifications.Count - 1 do
  1534. begin
  1535. if jvchnNotifier.Notifications[x].Directory = sPath then
  1536. Exit;
  1537. end;
  1538. // Add new changes item to notifier and initialize some parameters
  1539. pChangeNotifyItem := jvchnNotifier.Notifications.Add;
  1540. pChangeNotifyItem.Directory := sPath;
  1541. pChangeNotifyItem.IncludeSubTrees := True;
  1542. pChangeNotifyItem.Actions := [caChangeAttributes, caChangeLastWrite];
  1543. end;
  1544. procedure TfrmLuaEditMain.jvchnNotifierChangeNotify(Sender: TObject; Dir: String; Actions: TJvChangeActions);
  1545. var
  1546. srSearchRec: TSearchRec;
  1547. sFileName: String;
  1548. pLuaUnit: TLuaEditUnit;
  1549. pLuaPrj: TLuaEditProject;
  1550. x: Integer;
  1551. bNeedPrjTreeRebuild: Boolean;
  1552. test: Double;
  1553. begin
  1554. try
  1555. // Try to find wich file(s) has changed
  1556. if FindFirst(Dir+'\*.*', faAnyFile, srSearchRec) = 0 then
  1557. begin
  1558. bNeedPrjTreeRebuild := False;
  1559. repeat
  1560. sFileName := Dir+'\'+srSearchRec.Name;
  1561. if FileExistsAbs(sFileName) then
  1562. begin
  1563. // Go through all opened unit
  1564. for x := 0 to LuaOpenedFiles.Count - 1 do
  1565. begin
  1566. pLuaUnit := TLuaEditUnit(LuaOpenedFiles[x]);
  1567. if sFileName = pLuaUnit.Path then
  1568. begin
  1569. // Compare dates and read only attr each others
  1570. if ((pLuaUnit.LastTimeModified < GetFileLastTimeModified(PChar(sFileName))) or (pLuaUnit.IsReadOnly <> GetFileReadOnlyAttr(PChar(sFileName)))) then
  1571. begin
  1572. if Application.MessageBox(PChar('The file '+sFileName+' has been modified outside of the LuaEdit environnement. Do you want to reaload the file now?'), 'LuaEdit', MB_YESNO+MB_ICONQUESTION) = IDYES then
  1573. begin
  1574. pLuaUnit.LastTimeModified := GetFileLastTimeModified(PChar(sFileName));
  1575. pLuaUnit.IsReadOnly := GetFileReadOnlyAttr(PChar(sFileName));
  1576. pLuaUnit.HasChanged := True;
  1577. pLuaUnit.SynUnit.Lines.LoadFromFile(sFileName);
  1578. pLuaUnit.SynUnit.Modified := True;
  1579. SynEditChange(pLuaUnit.SynUnit);
  1580. pLuaUnit.SynUnit.Refresh;
  1581. end;
  1582. end;
  1583. end;
  1584. end;
  1585. // Go through all projects
  1586. for x := 0 to LuaProjects.Count - 1 do
  1587. begin
  1588. pLuaPrj := TLuaEditProject(LuaProjects[x]);
  1589. if sFileName = pLuaPrj.Path then
  1590. begin
  1591. test := GetFileLastTimeModified(PChar(sFileName));
  1592. if ((pLuaPrj.LastTimeModified < GetFileLastTimeModified(PChar(sFileName))) or (pLuaPrj.IsReadOnly <> GetFileReadOnlyAttr(PChar(sFileName)))) then
  1593. begin
  1594. if Application.MessageBox(PChar('The file '+sFileName+' has been modified outside of the LuaEdit environnement. Do you want to reaload the file now?'), 'LuaEdit', MB_YESNO+MB_ICONQUESTION) = IDYES then
  1595. begin
  1596. bNeedPrjTreeRebuild := True;
  1597. pLuaPrj.LastTimeModified := GetFileLastTimeModified(PChar(sFileName));
  1598. pLuaPrj.IsReadOnly := GetFileReadOnlyAttr(PChar(sFileName));
  1599. pLuaPrj.HasChanged := True;
  1600. pLuaPrj.RealoadProject;
  1601. end;
  1602. end;
  1603. end;
  1604. end;
  1605. end;
  1606. until FindNext(srSearchRec) <> 0;
  1607. end;
  1608. finally
  1609. // Do it once and only if we need it
  1610. if bNeedPrjTreeRebuild then
  1611. frmProjectTree.BuildProjectTree(False);
  1612. FindClose(srSearchRec);
  1613. end;
  1614. end;
  1615. procedure TfrmLuaEditMain.synEditClick(Sender: TObject);
  1616. var
  1617. synEditTemp: TSynEdit;
  1618. pLuaEditFile: TLuaEditFile;
  1619. pLuaEditDebugFile: TLuaEditDebugFile;
  1620. begin
  1621. if Assigned(jvUnitBar.SelectedTab) then
  1622. begin
  1623. if Assigned(jvUnitBar.SelectedTab.Data) then
  1624. begin
  1625. pLuaEditFile := TLuaEditFile(jvUnitBar.SelectedTab.Data);
  1626. if pLuaEditFile.FileType in LuaEditDebugFilesTypeSet then
  1627. begin
  1628. pLuaEditDebugFile := TLuaEditDebugFile(pLuaEditFile);
  1629. if Assigned(pLuaEditDebugFile.LinkedGUIForm) then
  1630. ShowWindow(pLuaEditDebugFile.LinkedGUIForm.GUIDesignerForm.Handle, SW_HIDE);
  1631. end;
  1632. end;
  1633. end;
  1634. synEditTemp := TSynEdit(Sender);
  1635. FirstClickPos := synEditTemp.CaretXY;
  1636. stbMain.Panels[0].Text := 'Ln:'+IntToStr(synEditTemp.CaretY)+', Col:'+IntToStr(synEditTemp.CaretX);
  1637. // Set caret mode adviser on status bar
  1638. if synEditTemp.InsertMode then
  1639. stbMain.Panels[1].Text := 'Insert'
  1640. else
  1641. stbMain.Panels[1].Text := 'Overwrite';
  1642. // Set caps lock adviser on status bar
  1643. if GetKeyState(VK_CAPITAL) = 1 then
  1644. stbMain.Panels[2].Text := 'CAPS'
  1645. else
  1646. stbMain.Panels[2].Text := '';
  1647. CheckButtons();
  1648. end;
  1649. function TfrmLuaEditMain.DoOpenProjectExecute(): Boolean;
  1650. var
  1651. pNewPrj: TLuaEditProject;
  1652. x: integer;
  1653. pReg: TRegistry;
  1654. begin
  1655. Result := False;
  1656. pReg := TRegistry.Create;
  1657. if pReg.OpenKey('\Software\LuaEdit', False) then
  1658. odlgOpenProject.InitialDir := pReg.ReadString('RecentPath');
  1659. if odlgOpenProject.Execute then
  1660. begin
  1661. for x := 0 to odlgOpenProject.Files.Count - 1 do
  1662. begin
  1663. if not IsProjectOpened(odlgOpenProject.Files.Strings[x]) then
  1664. begin
  1665. Result := True;
  1666. pNewPrj := TLuaEditProject.Create(odlgOpenProject.Files.Strings[x]);
  1667. pNewPrj.GetProjectFromDisk(odlgOpenProject.Files.Strings[x]);
  1668. // Rebuild the project tree
  1669. frmProjectTree.BuildProjectTree;
  1670. // Initialize and free stuff...
  1671. CheckButtons();
  1672. // Add opened file to recent opens
  1673. pReg.OpenKey('\Software\LuaEdit', True);
  1674. pReg.WriteString('RecentPath', ExtractFilePath(odlgOpenProject.Files.Strings[x]));
  1675. end
  1676. else
  1677. Application.MessageBox(PChar('The project "'+odlgOpenProject.Files.Strings[x]+')" is already opened by LuaEdit.'), 'LuaEdit', MB_OK+MB_ICONERROR);
  1678. end;
  1679. end;
  1680. pReg.Free;
  1681. end;
  1682. procedure TfrmLuaEditMain.actOpenProjectExecute(Sender: TObject);
  1683. begin
  1684. DoOpenProjectExecute;
  1685. end;
  1686. function TfrmLuaEditMain.DoExitExecute(): Boolean;
  1687. begin
  1688. Result := True;
  1689. Application.MainForm.Close;
  1690. end;
  1691. procedure TfrmLuaEditMain.actExitExecute(Sender: TObject);
  1692. begin
  1693. DoExitExecute;
  1694. end;
  1695. function TfrmLuaEditMain.DoSaveExecute(pFile: TLuaEditBasicTextFile): Boolean;
  1696. begin
  1697. Result := False;
  1698. if Assigned(pFile) then
  1699. begin
  1700. if SaveUnitsInc then
  1701. Result := pFile.SaveInc(pFile.Path)
  1702. else
  1703. Result := pFile.Save(pFile.Path);
  1704. end;
  1705. end;
  1706. procedure TfrmLuaEditMain.actSaveExecute(Sender: TObject);
  1707. var
  1708. pFile: TLuaEditBasicTextFile;
  1709. begin
  1710. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  1711. begin
  1712. pFile := TLuaEditBasicTextFile(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  1713. DoSaveExecute(pFile);
  1714. end;
  1715. end;
  1716. function TfrmLuaEditMain.DoSaveAsExecute(pFile: TLuaEditBasicTextFile): Boolean;
  1717. begin
  1718. Result := False;
  1719. if Assigned(pFile) then
  1720. begin
  1721. if SaveUnitsInc then
  1722. Result := pFile.SaveInc(pFile.Path, False, True)
  1723. else
  1724. Result := pFile.Save(pFile.Path, False, True);
  1725. end;
  1726. end;
  1727. procedure TfrmLuaEditMain.actSaveAsExecute(Sender: TObject);
  1728. var
  1729. pFile: TLuaEditBasicTextFile;
  1730. begin
  1731. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  1732. begin
  1733. pFile := TLuaEditBasicTextFile(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  1734. DoSaveAsExecute(pFile);
  1735. end;
  1736. end;
  1737. procedure TfrmLuaEditMain.CheckButtons;
  1738. var
  1739. pNode: PVirtualNode;
  1740. pData: PProjectTreeData;
  1741. pFile: TLuaEditBasicTextFile;
  1742. begin
  1743. actClose.Enabled := not (LuaOpenedFiles.Count = 0);
  1744. actSave.Enabled := not (LuaOpenedFiles.Count = 0);
  1745. actSaveAs.Enabled := not (LuaOpenedFiles.Count = 0);
  1746. actSaveProjectAs.Enabled := ((Assigned(ActiveProject)) and (ActiveProject <> LuaSingleFiles));
  1747. actSaveAll.Enabled := not (LuaOpenedFiles.Count = 0);
  1748. actFind.Enabled := not (LuaOpenedFiles.Count = 0);
  1749. actFindAgain.Enabled := not (LuaOpenedFiles.Count = 0);
  1750. actFindReplace.Enabled := not (LuaOpenedFiles.Count = 0);
  1751. actSelectAll.Enabled := not (LuaOpenedFiles.Count = 0);
  1752. actGoToLine.Enabled := not (LuaOpenedFiles.Count = 0);
  1753. actGotoLastEdited.Enabled := not (LuaOpenedFiles.Count = 0);
  1754. actCut.Enabled := not (LuaOpenedFiles.Count = 0);
  1755. actCopy.Enabled := not (LuaOpenedFiles.Count = 0);
  1756. actPaste.Enabled := not (LuaOpenedFiles.Count = 0);
  1757. actPrint.Enabled := not (LuaOpenedFiles.Count = 0);
  1758. actBlockIndent.Enabled := not (LuaOpenedFiles.Count = 0);
  1759. actBlockUnindent.Enabled := not (LuaOpenedFiles.Count = 0);
  1760. actBlockComment.Enabled := not (LuaOpenedFiles.Count = 0);
  1761. actBlockUncomment.Enabled := not (LuaOpenedFiles.Count = 0);
  1762. actUpperCase.Enabled := not (LuaOpenedFiles.Count = 0);
  1763. actLowerCase.Enabled := not (LuaOpenedFiles.Count = 0);
  1764. //HeaderBuilder1.Enabled := not (LuaOpenedFiles.Count = 0);
  1765. if LuaOpenedFiles.Count = 0 then
  1766. begin
  1767. actUndo.Enabled := False;
  1768. actRedo.Enabled := False;
  1769. end;
  1770. // Initialize some actions' state
  1771. actEnableDisableBreakpoint.Enabled := False;
  1772. if LuaOpenedFiles.Count > 0 then
  1773. begin
  1774. if Assigned(jvUnitBar.SelectedTab) then
  1775. begin
  1776. if Assigned(jvUnitBar.SelectedTab.Data) then
  1777. begin
  1778. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  1779. if pFile.FileType in LuaEditDebugFilesTypeSet then
  1780. begin
  1781. actEnableDisableBreakpoint.Enabled := TLuaEditUnit(pFile).DebugInfos.IsBreakPointLine(pFile.SynUnit.CaretY);
  1782. actRunScript.Enabled := (pFile.SynUnit.Text <> '');
  1783. actRemoteSession.Enabled := (pFile.SynUnit.Text <> '');
  1784. actCompileScipt.Enabled := (pFile.SynUnit.Text <> '');
  1785. actCheckSyntax.Enabled := (pFile.SynUnit.Text <> '');
  1786. actRunToCursor.Enabled := (pFile.SynUnit.Text <> '');
  1787. actToggleBreakpoint.Enabled := True;
  1788. actStepInto.Enabled := True;
  1789. actStepOver.Enabled := True;
  1790. end
  1791. else
  1792. begin
  1793. actEnableDisableBreakpoint.Enabled := False;
  1794. actRunScript.Enabled := False;
  1795. actRemoteSession.Enabled := False;
  1796. actCompileScipt.Enabled := False;
  1797. actCheckSyntax.Enabled := False;
  1798. actRunToCursor.Enabled := False;
  1799. actToggleBreakpoint.Enabled := False;
  1800. actStepInto.Enabled := False;
  1801. actStepOver.Enabled := False;
  1802. end;
  1803. if pFile.synUnit.UndoList.ItemCount = 0 then
  1804. actUndo.Enabled := False
  1805. else
  1806. actUndo.Enabled := True;
  1807. if pFile.synUnit.RedoList.ItemCount = 0 then
  1808. actRedo.Enabled := False
  1809. else
  1810. actRedo.Enabled := True;
  1811. end;
  1812. end
  1813. else
  1814. begin
  1815. actUndo.Enabled := False;
  1816. actRedo.Enabled := False;
  1817. end;
  1818. end
  1819. else
  1820. begin
  1821. actRemoteSession.Enabled := False;
  1822. actRunScript.Enabled := False;
  1823. actCompileScipt.Enabled := False;
  1824. actCheckSyntax.Enabled := False;
  1825. actStepInto.Enabled := False;
  1826. actStepOver.Enabled := False;
  1827. actRunToCursor.Enabled := False;
  1828. actToggleBreakpoint.Enabled := False;
  1829. end;
  1830. // These actions are driven by the Running global variable
  1831. // (they only needs to be enabled when the user is debugging)
  1832. actPause.Enabled := Running;
  1833. actStop.Enabled := Running;
  1834. // Retreive selected node if any
  1835. pNode := frmProjectTree.vstProjectTree.GetFirstSelected;
  1836. if Assigned(pNode) then
  1837. begin
  1838. // Retreive data from the selected node
  1839. pData := frmProjectTree.vstProjectTree.GetNodeData(pNode);
  1840. if pData.pLuaEditFile.FileType = otLuaEditProject then
  1841. actActiveSelPrj.Enabled := True
  1842. else
  1843. actActiveSelPrj.Enabled := False;
  1844. end
  1845. else
  1846. actActiveSelPrj.Enabled := False;
  1847. actNewProject.Enabled := True;
  1848. actNewUnit.Enabled := True;
  1849. actOpenFile.Enabled := True;
  1850. actOpenProject.Enabled := True;
  1851. actClose.Enabled := True;
  1852. New1.Enabled := True;
  1853. Reopen1.Enabled := True;
  1854. end;
  1855. function TfrmLuaEditMain.DoNewMacroExecute(): Boolean;
  1856. var
  1857. pLuaMacro: TLuaEditMacro;
  1858. begin
  1859. Result := True;
  1860. pLuaMacro := TLuaEditMacro(LuaSingleFiles.AddFile(GetNewFileName('Macro') + '.lmc', True));
  1861. pLuaMacro.IsLoaded := True;
  1862. AddFileInTab(pLuaMacro);
  1863. frmProjectTree.BuildProjectTree;
  1864. CheckButtons;
  1865. end;
  1866. procedure TfrmLuaEditMain.actNewMacroExecute(Sender: TObject);
  1867. begin
  1868. DoNewMacroExecute;
  1869. end;
  1870. function TfrmLuaEditMain.DoNewTextFileExecute(): Boolean;
  1871. var
  1872. pLuaTextFile: TLuaEditBasicTextFile;
  1873. begin
  1874. Result := True;
  1875. pLuaTextFile := TLuaEditBasicTextFile(LuaSingleFiles.AddFile(GetNewFileName('Text') + '.txt', True));
  1876. pLuaTextFile.IsLoaded := True;
  1877. AddFileInTab(pLuaTextFile);
  1878. frmProjectTree.BuildProjectTree;
  1879. CheckButtons();
  1880. end;
  1881. procedure TfrmLuaEditMain.actNewTextFileExecute(Sender: TObject);
  1882. begin
  1883. DoNewTextFileExecute;
  1884. end;
  1885. function TfrmLuaEditMain.DoNewGUIFormExecute(): Boolean;
  1886. var
  1887. pLuaEditGUIForm: TLuaEditGUIForm;
  1888. sFileName: String;
  1889. begin
  1890. Result := True;
  1891. Application.CreateForm(TfrmGUIFormType, frmGUIFormType);
  1892. frmGUIFormType.ShowModal;
  1893. sFileName := GetNewFileName('Form') + '.gui';
  1894. pLuaEditGUIForm := TLuaEditGUIForm(LuaSingleFiles.AddFile(sFileName, True));
  1895. pLuaEditGUIForm.IsLoaded := True;
  1896. // Created associated script according to user's type
  1897. if frmGUIFormType.optLuaUnit.Checked then
  1898. pLuaEditGUIForm.LinkedDebugFile := TLuaEditUnit(LuaSingleFiles.AddFile(ChangeFileExt(sFileName, '.lua'), True))
  1899. else
  1900. pLuaEditGUIForm.LinkedDebugFile := TLuaEditMacro(LuaSingleFiles.AddFile(ChangeFileExt(sFileName, '.lmc'), True));
  1901. // Complete cycling reference
  1902. pLuaEditGUIForm.LinkedDebugFile.LinkedGUIForm := pLuaEditGUIForm;
  1903. pLuaEditGUIForm.LinkedDebugFile.IsNew := True;
  1904. pLuaEditGUIForm.LinkedDebugFile.IsLoaded := True;
  1905. // Routine creation
  1906. AddFileInTab(pLuaEditGUIForm.LinkedDebugFile);
  1907. frmProjectTree.BuildProjectTree;
  1908. CheckButtons;
  1909. // Show the designer form
  1910. frmGUIFormType.Free;
  1911. Application.ProcessMessages;
  1912. pLuaEditGUIForm.GUIDesignerForm.Visible := True;
  1913. ShowWindow(pLuaEditGUIForm.GUIDesignerForm.Handle, SW_SHOWNORMAL);
  1914. end;
  1915. procedure TfrmLuaEditMain.actNewGUIFormExecute(Sender: TObject);
  1916. begin
  1917. DoNewGUIFormExecute();
  1918. end;
  1919. function TfrmLuaEditMain.DoNewUnitExecute(): Boolean;
  1920. var
  1921. pLuaUnit: TLuaEditUnit;
  1922. begin
  1923. Result := True;
  1924. pLuaUnit := TLuaEditUnit(LuaSingleFiles.AddFile(GetNewFileName('Unit') + '.lua', True));
  1925. pLuaUnit.IsLoaded := True;
  1926. AddFileInTab(pLuaUnit);
  1927. frmProjectTree.BuildProjectTree;
  1928. CheckButtons;
  1929. end;
  1930. procedure TfrmLuaEditMain.actNewUnitExecute(Sender: TObject);
  1931. begin
  1932. DoNewUnitExecute;
  1933. end;
  1934. function TfrmLuaEditMain.DoNewProjectExecute(): Boolean;
  1935. var
  1936. pLuaUnit: TLuaEditUnit;
  1937. pNewLuaPrj: TLuaEditProject;
  1938. begin
  1939. Result := False;
  1940. pNewLuaPrj := TLuaEditProject.Create('');
  1941. pNewLuaPrj.Name := GetNewProjectName('Project');
  1942. pNewLuaPrj.Path := GetLuaEditInstallPath() + '\Templates\Template.lpr';
  1943. pNewLuaPrj.IsNew := True;
  1944. pNewLuaPrj.IsLoaded := True;
  1945. LuaProjects.Add(pNewLuaPrj);
  1946. ActiveProject := pNewLuaPrj;
  1947. Result := True;
  1948. pLuaUnit := TLuaEditUnit(pNewLuaPrj.AddFile(GetNewFileName('Unit') + '.lua', True));
  1949. pLuaUnit.IsLoaded := True;
  1950. AddFileInTab(pLuaUnit);
  1951. frmProjectTree.BuildProjectTree;
  1952. CheckButtons;
  1953. end;
  1954. procedure TfrmLuaEditMain.actNewProjectExecute(Sender: TObject);
  1955. begin
  1956. DoNewProjectExecute;
  1957. end;
  1958. function TfrmLuaEditMain.DoSaveProjectAsExecute(): Boolean;
  1959. begin
  1960. Result := False;
  1961. if ActiveProject.Name <> '[@@SingleUnits@@]' then
  1962. begin
  1963. if SaveProjectsInc then
  1964. Result := ActiveProject.SaveInc(sdlgSaveAsPrj.FileName, False, True)
  1965. else
  1966. Result := ActiveProject.Save(sdlgSaveAsPrj.FileName, False, True);
  1967. RefreshOpenedUnits;
  1968. frmProjectTree.BuildProjectTree;
  1969. end;
  1970. end;
  1971. procedure TfrmLuaEditMain.actSaveProjectAsExecute(Sender: TObject);
  1972. begin
  1973. DoSaveProjectAsExecute;
  1974. end;
  1975. function TfrmLuaEditMain.DoSaveAllExecute(): Boolean;
  1976. var
  1977. x, y: integer;
  1978. pLuaPrj: TLuaEditProject;
  1979. pLuaUnit: TLuaEditUnit;
  1980. begin
  1981. Result := False;
  1982. for x := 0 to LuaProjects.Count - 1 do
  1983. begin
  1984. pLuaPrj := TLuaEditProject(LuaProjects.Items[x]);
  1985. for y := 0 to pLuaPrj.lstUnits.Count - 1 do
  1986. begin
  1987. pLuaUnit := TLuaEditUnit(pLuaPrj.lstUnits.Items[y]);
  1988. if SaveUnitsInc then
  1989. Result := pLuaUnit.SaveInc(pLuaUnit.Path)
  1990. else
  1991. Result := pLuaUnit.Save(pLuaUnit.Path);
  1992. if not Result then
  1993. Exit;
  1994. end;
  1995. if pLuaPrj.Name <> '[@@SingleUnits@@]' then
  1996. begin
  1997. if SaveProjectsInc then
  1998. Result := pLuaPrj.SaveInc(pLuaPrj.Path)
  1999. else
  2000. Result := pLuaPrj.Save(pLuaPrj.Path);
  2001. if not Result then
  2002. Exit;
  2003. end;
  2004. end;
  2005. frmProjectTree.BuildProjectTree;
  2006. end;
  2007. procedure TfrmLuaEditMain.actSaveAllExecute(Sender: TObject);
  2008. begin
  2009. DoSaveAllExecute;
  2010. end;
  2011. function TfrmLuaEditMain.DoCloseExecute(): Boolean;
  2012. var
  2013. pTab: TJvTabBarItem;
  2014. begin
  2015. Screen.Cursor := crHourGlass;
  2016. pTab := jvUnitBar.SelectedTab.GetPreviousVisible;
  2017. Result := ClosingUnit;
  2018. // Close the tab, free data...
  2019. if Result then
  2020. begin
  2021. TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).AssociatedTab := nil;
  2022. jvUnitBar.SelectedTab.Free;
  2023. if Assigned(pTab) then
  2024. jvUnitBar.SelectedTab := pTab;
  2025. end;
  2026. Screen.Cursor := crDefault;
  2027. end;
  2028. procedure TfrmLuaEditMain.actCloseExecute(Sender: TObject);
  2029. begin
  2030. DoCloseExecute;
  2031. end;
  2032. function TfrmLuaEditMain.ClosingUnit(): Boolean;
  2033. var
  2034. Answer, x: Integer;
  2035. pFile: TLuaEditBasicTextFile;
  2036. begin
  2037. // Initialize result to true
  2038. Result := True;
  2039. // Retrieve file class from tab
  2040. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  2041. // Prompt user for closing unit or not
  2042. if ((pFile.HasChanged) or (pFile.IsNew)) then
  2043. begin
  2044. Answer := Application.MessageBox(PChar('Do you want to save "'+pFile.DisplayPath+'"?'), 'LuaEdit', MB_YESNOCANCEL+MB_ICONQUESTION);
  2045. if Answer = IDYES then
  2046. Result := DoSaveExecute(pFile)
  2047. else if Answer = IDCANCEL then
  2048. begin
  2049. Result := False;
  2050. Exit;
  2051. end;
  2052. end;
  2053. if Assigned(jvUnitBar.SelectedTab) then
  2054. begin
  2055. if jvUnitBar.Tabs.Count = 1 then
  2056. begin
  2057. // Free previously created TFctInfo objects...
  2058. for x := 0 to frmFunctionList.lvwFunctions.Items.Count - 1 do
  2059. TFctInfo(frmFunctionList.lvwFunctions.Items[x].Data).Free;
  2060. frmFunctionList.lvwFunctions.Clear;
  2061. end;
  2062. end;
  2063. // Remove file from global opened file list
  2064. LuaOpenedFiles.Remove(pFile);
  2065. pFile.SynUnit.Visible := False;
  2066. pFile.AssociatedTab := nil;
  2067. // Reinitialize stuff...
  2068. CheckButtons;
  2069. frmProjectTree.BuildProjectTree;
  2070. frmBreakpoints.RefreshBreakpointList;
  2071. end;
  2072. procedure TfrmLuaEditMain.BuildMacroList();
  2073. var
  2074. x: Integer;
  2075. pReg: TRegistry;
  2076. lstKeyList: TStringList;
  2077. pNewMenu: TMenuItem;
  2078. begin
  2079. pReg := TRegistry.Create();
  2080. while mnuMacros.Count > 1 do
  2081. mnuMacros.Delete(mnuMacros.Count - 1);
  2082. // Open registry key to read all macros' datas
  2083. if pReg.OpenKey('\Software\LuaEdit\Macros', False) then
  2084. begin
  2085. lstKeyList := TStringList.Create();
  2086. pReg.GetKeyNames(lstKeyList);
  2087. // Add separator menu
  2088. pNewMenu := TMenuItem.Create(mnuMacros);
  2089. pNewMenu.Caption := '-';
  2090. mnuMacros.Add(pNewMenu);
  2091. for x := 0 to lstKeyList.Count - 1 do
  2092. begin
  2093. // Open current macro registry key to read macro's values
  2094. if pReg.OpenKey('\Software\LuaEdit\Macros\' + lstKeyList.Strings[x], False) then
  2095. begin
  2096. pNewMenu := TMenuItem.Create(mnuMacros);
  2097. pNewMenu.Caption := pReg.ReadString('Caption');
  2098. pNewMenu.Shortcut := TextToShortcut(pReg.ReadString('Shortcut'));
  2099. pNewMenu.Hint := lstKeyList.Strings[x]; // Use hint property to store name...
  2100. pNewMenu.OnClick := mnuXMacroClick;
  2101. mnuMacros.Add(pNewMenu);
  2102. end;
  2103. end;
  2104. lstKeyList.Free;
  2105. end;
  2106. // Repaint some non overriden component on runtime
  2107. xmpMenuPainter.ActivateMenuItem(mnuMacros, True);
  2108. pReg.Free;
  2109. end;
  2110. // Build 'reopen' submenu of the main 'file' menu
  2111. procedure TfrmLuaEditMain.BuildReopenMenu;
  2112. var
  2113. pReg: TRegistry;
  2114. lstValues: TStringList;
  2115. x: integer;
  2116. // This method add a submenu to the given reopen menu
  2117. procedure AddMenu(pOnClick: TNotifyEvent; AOwner: TComponent; sCaption: String; bEnabled: Boolean = True);
  2118. var
  2119. pNewMenu: TMenuItem;
  2120. bFound: Boolean;
  2121. x: Integer;
  2122. begin
  2123. bFound := False;
  2124. if AOwner.ClassType = TMenuItem then
  2125. begin
  2126. for x := 0 to TMenuItem(AOwner).Count - 1 do
  2127. begin
  2128. if TMenuItem(AOwner).Items[x].Caption = sCaption then
  2129. bFound := True;
  2130. end;
  2131. end
  2132. else if AOwner.ClassType = TPopupMenu then
  2133. begin
  2134. for x := 0 to TPopupMenu(AOwner).Items.Count - 1 do
  2135. begin
  2136. if TPopupMenu(AOwner).Items[x].Caption = sCaption then
  2137. bFound := True;
  2138. end;
  2139. end;
  2140. if not bFound then
  2141. begin
  2142. pNewMenu := TMenuItem.Create(AOwner);
  2143. pNewMenu.Caption := sCaption;
  2144. pNewMenu.Enabled := bEnabled;
  2145. pNewMenu.OnClick := pOnClick;
  2146. if AOwner.ClassType = TMenuItem then
  2147. TMenuItem(AOwner).Add(pNewMenu)
  2148. else if AOwner.ClassType = TPopupMenu then
  2149. TPopupMenu(AOwner).Items.Add(pNewMenu);
  2150. end;
  2151. end;
  2152. // This method add a button to the ring engine
  2153. procedure AddOBButton(pOnClick: TNotifyEvent; iPageIndex: Integer; sCaption: String; bEnabled: Boolean = True);
  2154. var
  2155. jvOBBtn: TJvOutlookBarButton;
  2156. bFound: Boolean;
  2157. x: Integer;
  2158. begin
  2159. bFound := False;
  2160. for x := 0 to frmRings.jvRings.Pages[iPageIndex].Buttons.Count - 1 do
  2161. begin
  2162. if frmRings.jvRings.Pages[iPageIndex].Buttons[x].Caption = sCaption then
  2163. bFound := True;
  2164. end;
  2165. if not bFound then
  2166. begin
  2167. jvOBBtn := frmRings.jvRings.Pages[iPageIndex].Buttons.Add();
  2168. jvOBBtn.Caption := sCaption;
  2169. jvOBBtn.Enabled := bEnabled;
  2170. jvOBBtn.OnClick := pOnClick;
  2171. end;
  2172. end;
  2173. begin
  2174. //Reopen1.Clear;
  2175. //mnuReopen.Items.Clear;
  2176. //frmRings.jvRings.Pages[JVPAGE_RING_FILES].Buttons.Clear;
  2177. pReg := TRegistry.Create;
  2178. if pReg.OpenKey('\Software\LuaEdit\RecentFiles', False) then
  2179. begin
  2180. lstValues := TStringList.Create;
  2181. pReg.GetValueNames(lstValues);
  2182. // Create (Empty) menus if no reopen values in registry
  2183. if lstValues.Count = 0 then
  2184. begin
  2185. //Popup menu adding
  2186. AddMenu(nil, mnuReopen, '(Empty)', False);
  2187. //Main menu adding
  2188. AddMenu(nil, Reopen1, '(Empty)', False);
  2189. // Recent files ring adding
  2190. AddOBButton(nil, JVPAGE_RING_FILES, '(Empty)', False);
  2191. end
  2192. else
  2193. begin
  2194. // Add project first...
  2195. for x := 0 to lstValues.Count - 1 do
  2196. begin
  2197. if ExtractFileExt(lstValues.Strings[x]) = '.lpr' then
  2198. begin
  2199. //Popup menu adding
  2200. AddMenu(mnuXReopenClick, mnuReopen, lstValues.Strings[x]);
  2201. //Main menu adding
  2202. AddMenu(mnuXReopenClick, Reopen1, lstValues.Strings[x]);
  2203. // Recent files ring adding
  2204. AddOBButton(btnXFilesClick, JVPAGE_RING_FILES, lstValues.Strings[x]);
  2205. end;
  2206. end;
  2207. // Add seperators...
  2208. if mnuReopen.Items.Count > 0 then
  2209. begin
  2210. //Popup menu adding
  2211. AddMenu(nil, mnuReopen, '-');
  2212. //Main menu adding
  2213. AddMenu(nil, Reopen1, '-');
  2214. end;
  2215. // Add all other types of files after seperators and projects
  2216. for x := 0 to lstValues.Count - 1 do
  2217. begin
  2218. if ExtractFileExt(lstValues.Strings[x]) <> '.lpr' then
  2219. begin
  2220. //Popup menu adding
  2221. AddMenu(mnuXReopenClick, mnuReopen, lstValues.Strings[x]);
  2222. //Main menu adding
  2223. AddMenu(mnuXReopenClick, Reopen1, lstValues.Strings[x]);
  2224. // Recent files ring adding
  2225. AddOBButton(btnXFilesClick, JVPAGE_RING_FILES, lstValues.Strings[x]);
  2226. end;
  2227. end;
  2228. end;
  2229. // Free list
  2230. lstValues.Free;
  2231. end
  2232. else // Create (Empty) menus if no reopen values in registry
  2233. begin
  2234. //Popup menu adding
  2235. AddMenu(nil, mnuReopen, '(Empty)', False);
  2236. //Main menu adding
  2237. AddMenu(nil, Reopen1, '(Empty)', False);
  2238. // Recent files ring adding
  2239. AddOBButton(nil, JVPAGE_RING_FILES, '(Empty)', False);
  2240. end;
  2241. // Repaint some non overriden component on runtime
  2242. xmpMenuPainter.InitComponent(mnuReopen);
  2243. xmpMenuPainter.ActivateMenuItem(Reopen1, True);
  2244. pReg.Free;
  2245. end;
  2246. function TfrmLuaEditMain.IsReopenInList(sString: String): Boolean;
  2247. var
  2248. pReg: TRegistry;
  2249. sReturn: String;
  2250. begin
  2251. pReg := TRegistry.Create;
  2252. Result := False;
  2253. if pReg.OpenKey('\Software\LuaEdit\RecentFiles', False) then
  2254. begin
  2255. sReturn := pReg.ReadString('sString');
  2256. if sReturn <> '' then
  2257. Result := True;
  2258. end;
  2259. pReg.Free;
  2260. end;
  2261. procedure TfrmLuaEditMain.MonitorFileToRecent(sString: String);
  2262. var
  2263. pReg: TRegistry;
  2264. lstValues: TStringList;
  2265. x: integer;
  2266. ValMax: integer;
  2267. iMaxHigh: integer;
  2268. begin
  2269. pReg := TRegistry.Create;
  2270. if not IsReopenInList(sString) then
  2271. begin
  2272. lstValues := TStringList.Create;
  2273. pReg.OpenKey('\Software\LuaEdit\RecentFiles', True);
  2274. pReg.GetValueNames(lstValues);
  2275. if lstValues.Count >= 20 then
  2276. begin
  2277. ValMax := 0;
  2278. iMaxHigh := 0;
  2279. for x := 0 to lstValues.Count - 1 do
  2280. begin
  2281. if ValMax < pReg.ReadInteger(lstValues.Strings[x]) then
  2282. begin
  2283. iMaxHigh := x;
  2284. ValMax := pReg.ReadInteger(lstValues.Strings[x])
  2285. end;
  2286. pReg.WriteInteger(lstValues.Strings[x], pReg.ReadInteger(lstValues.Strings[x]) + 1);
  2287. end;
  2288. pReg.DeleteValue(lstValues.Strings[iMaxHigh]);
  2289. end;
  2290. pReg.WriteInteger(sString, 0);
  2291. lstValues.Free;
  2292. end;
  2293. pReg.Free;
  2294. end;
  2295. function TfrmLuaEditMain.DoMainMenuFileExecute(): Boolean;
  2296. begin
  2297. Result := True;
  2298. CloseUnit1.Enabled := (jvUnitBar.Tabs.Count > 0);
  2299. end;
  2300. procedure TfrmLuaEditMain.actMainMenuFileExecute(Sender: TObject);
  2301. begin
  2302. DoMainMenuFileExecute;
  2303. end;
  2304. function TfrmLuaEditMain.DoMainMenuEditExecute(): Boolean;
  2305. begin
  2306. Result := False;
  2307. // Do nothing for now...
  2308. end;
  2309. procedure TfrmLuaEditMain.actMainMenuEditExecute(Sender: TObject);
  2310. begin
  2311. DoMainMenuEditExecute;
  2312. end;
  2313. function TfrmLuaEditMain.DoMainMenuViewExecute(): Boolean;
  2314. begin
  2315. Result := True;
  2316. File2.Checked := tlbBaseFile.Visible;
  2317. Edit2.Checked := tlbEdit.Visible;
  2318. Run1.Checked := tlbRun.Visible;
  2319. File3.Checked := tlbBaseFile.Visible;
  2320. Edit3.Checked := tlbEdit.Visible;
  2321. Find1.Checked := tlbFind.Visible;
  2322. Find2.Checked := tlbFind.Visible;
  2323. Run4.Checked := tlbRun.Visible;
  2324. actShowMessages.Checked := frmLuaEditMessages.Visible;
  2325. actShowProjectTree.Checked := frmProjectTree.Visible;
  2326. actShowWatchList.Checked := frmWatch.Visible;
  2327. actShowCallStack.Checked := frmStack.Visible;
  2328. actShowLuaStack.Checked := frmLuaStack.Visible;
  2329. actShowLuaConsole.Checked := frmLuaConsole.Visible;
  2330. actShowBreakpoints.Checked := frmBreakpoints.Visible;
  2331. actShowLuaGlobals.Checked := frmLuaGlobals.Visible;
  2332. actShowLuaLocals.Checked := frmLuaLocals.Visible;
  2333. actShowRings.Checked := frmRings.Visible;
  2334. actShowFunctionList.Checked := frmFunctionList.Visible;
  2335. actShowInternalBrowser.Checked := frmInternalBrowser.Visible;
  2336. actShowFindWindow1.Checked := frmFindWindow1.Visible;
  2337. actShowFindWindow2.Checked := frmFindWindow2.Visible;
  2338. actShowProfiler.Checked := frmProfiler.Visible;
  2339. actShowGUIInspector.Checked := frmGUIInspector.Visible;
  2340. actShowGUIControls.Checked := frmGUIControls.Visible;
  2341. end;
  2342. procedure TfrmLuaEditMain.actMainMenuViewExecute(Sender: TObject);
  2343. begin
  2344. DoMainMenuViewExecute;
  2345. end;
  2346. function TfrmLuaEditMain.DoMainMenuProjectExecute(): Boolean;
  2347. var
  2348. pNode: PVirtualNode;
  2349. pData: PProjectTreeData;
  2350. begin
  2351. Result := True;
  2352. // Retreive first selected node
  2353. pNode := frmProjectTree.vstProjectTree.GetFirstSelected;
  2354. // Only if a menu is selected
  2355. if Assigned(pNode) then
  2356. begin
  2357. // Retreive data from selected node
  2358. pData := frmProjectTree.vstProjectTree.GetNodeData(pNode);
  2359. actActiveSelPrj.Enabled := (pData.pLuaEditFile.FileType = otLuaEditProject);
  2360. actAddToPrj.Enabled := ((pData.pLuaEditFile = ActiveProject) and Assigned(ActiveProject));
  2361. actPrjSettings.Enabled := ((pData.pLuaEditFile = ActiveProject) and Assigned(ActiveProject));
  2362. frmProjectTree.UnloadFileProject1.Enabled := (pNode.Parent = frmProjectTree.vstProjectTree.RootNode); //(((pData.pLuaEditFile.FileType in LuaEditTextFilesTypeSet) and (pNode.Parent = frmProjectTree.vstProjectTree.RootNode)) or (pData.pLuaEditFile.FileType = otLuaEditProject));
  2363. if pData.pLuaEditFile.FileType in LuaEditTextFilesTypeSet then
  2364. actRemoveFromPrj.Enabled := ((Assigned(TLuaEditFile(pData.pLuaEditFile).PrjOwner))) and ((TLuaEditFile(pData.pLuaEditFile).PrjOwner.Name <> '[@@SingleUnits@@]') and (TLuaEditProject(TLuaEditFile(pData.pLuaEditFile).PrjOwner).lstUnits.Count <> 0))
  2365. else
  2366. actRemoveFromPrj.Enabled := False;
  2367. end
  2368. else
  2369. begin
  2370. // Flag all menus to false since no node is selected
  2371. actActiveSelPrj.Enabled := False;
  2372. actAddToPrj.Enabled := False;
  2373. actPrjSettings.Enabled := False;
  2374. frmProjectTree.UnloadFileProject1.Enabled := False;
  2375. actRemoveFromPrj.Enabled := False;
  2376. end;
  2377. end;
  2378. procedure TfrmLuaEditMain.actMainMenuProjectExecute(Sender: TObject);
  2379. begin
  2380. DoMainMenuProjectExecute;
  2381. end;
  2382. function TfrmLuaEditMain.DoMainMenuRunExecute(): Boolean;
  2383. begin
  2384. Result := True;
  2385. CheckButtons;
  2386. end;
  2387. procedure TfrmLuaEditMain.actMainMenuRunExecute(Sender: TObject);
  2388. begin
  2389. DoMainMenuRunExecute;
  2390. end;
  2391. function TfrmLuaEditMain.DoMainMenuToolsExecute(): Boolean;
  2392. begin
  2393. Result := False;
  2394. // Do nothing for now...
  2395. end;
  2396. procedure TfrmLuaEditMain.actMainMenuToolsExecute(Sender: TObject);
  2397. begin
  2398. DoMainMenuToolsExecute;
  2399. end;
  2400. function TfrmLuaEditMain.DoMainMenuHelpExecute(): Boolean;
  2401. begin
  2402. Result := False;
  2403. // Do nothing for now...
  2404. end;
  2405. procedure TfrmLuaEditMain.actMainMenuHelpExecute(Sender: TObject);
  2406. begin
  2407. DoMainMenuHelpExecute;
  2408. end;
  2409. function TfrmLuaEditMain.DoBringGUIFormToFrontExecute(): Boolean;
  2410. var
  2411. pLuaEditFile: TLuaEditFile;
  2412. pLuaEditDebugFile: TLuaEditDebugFile;
  2413. begin
  2414. if Assigned(jvUnitBar.SelectedTab) then
  2415. begin
  2416. if Assigned(jvUnitBar.SelectedTab.Data) then
  2417. begin
  2418. pLuaEditFile := TLuaEditFile(jvUnitBar.SelectedTab.Data);
  2419. if pLuaEditFile.FileType in LuaEditDebugFilesTypeSet then
  2420. begin
  2421. pLuaEditDebugFile := TLuaEditDebugFile(pLuaEditFile);
  2422. if Assigned(pLuaEditDebugFile.LinkedGUIForm) then
  2423. ShowWindow(pLuaEditDebugFile.LinkedGUIForm.GUIDesignerForm.Handle, SW_SHOWNORMAL);
  2424. end;
  2425. end;
  2426. end;
  2427. end;
  2428. procedure TfrmLuaEditMain.actBringGUIFormToFrontExecute(Sender: TObject);
  2429. begin
  2430. DoBringGUIFormToFrontExecute();
  2431. end;
  2432. function TfrmLuaEditMain.DoShowProjectTreeExecute(): Boolean;
  2433. begin
  2434. Result := True;
  2435. actShowProjectTree.Checked := not actShowProjectTree.Checked;
  2436. frmProjectTree.Visible := actShowProjectTree.Checked;
  2437. if actShowProjectTree.Checked then
  2438. ShowDockForm(frmProjectTree)
  2439. else
  2440. HideDockForm(frmProjectTree);
  2441. end;
  2442. procedure TfrmLuaEditMain.actShowProjectTreeExecute(Sender: TObject);
  2443. begin
  2444. DoShowProjectTreeExecute();
  2445. end;
  2446. function TfrmLuaEditMain.DoShowGUIInspector(): Boolean;
  2447. begin
  2448. Result := True;
  2449. actShowGUIInspector.Checked := not actShowGUIInspector.Checked;
  2450. frmGUIInspector.Visible := actShowGUIInspector.Checked;
  2451. if actShowGUIInspector.Checked then
  2452. ShowDockForm(frmGUIInspector)
  2453. else
  2454. HideDockForm(frmGUIInspector);
  2455. end;
  2456. procedure TfrmLuaEditMain.actShowGUIInspectorExecute(Sender: TObject);
  2457. begin
  2458. DoShowGUIInspector();
  2459. end;
  2460. function TfrmLuaEditMain.DoShowBreakpointsExecute(): Boolean;
  2461. begin
  2462. Result := True;
  2463. actShowBreakpoints.Checked := not actShowBreakpoints.Checked;
  2464. frmBreakpoints.Visible := actShowBreakpoints.Checked;
  2465. if actShowBreakpoints.Checked then
  2466. ShowDockForm(frmBreakpoints)
  2467. else
  2468. HideDockForm(frmBreakpoints);
  2469. end;
  2470. procedure TfrmLuaEditMain.actShowBreakpointsExecute(Sender: TObject);
  2471. begin
  2472. DoShowBreakpointsExecute;
  2473. end;
  2474. function TfrmLuaEditMain.DoShowMessagesExecute(): Boolean;
  2475. begin
  2476. Result := True;
  2477. actShowMessages.Checked := not actShowMessages.Checked;
  2478. frmLuaEditMessages.Visible := actShowMessages.Checked;
  2479. if actShowMessages.Checked then
  2480. ShowDockForm(frmLuaEditMessages)
  2481. else
  2482. HideDockForm(frmLuaEditMessages);
  2483. end;
  2484. procedure TfrmLuaEditMain.actShowMessagesExecute(Sender: TObject);
  2485. begin
  2486. DoShowMessagesExecute;
  2487. end;
  2488. function TfrmLuaEditMain.DoShowWatchListExecute(): Boolean;
  2489. begin
  2490. Result := True;
  2491. actShowWatchList.Checked := not actShowWatchList.Checked;
  2492. frmWatch.Visible := actShowWatchList.Checked;
  2493. if actShowWatchList.Checked then
  2494. ShowDockForm(frmWatch)
  2495. else
  2496. HideDockForm(frmWatch);
  2497. end;
  2498. procedure TfrmLuaEditMain.actShowWatchListExecute(Sender: TObject);
  2499. begin
  2500. DoShowWatchListExecute;
  2501. end;
  2502. function TfrmLuaEditMain.DoShowCallStackExecute(): Boolean;
  2503. begin
  2504. Result := True;
  2505. actShowCallStack.Checked := not actShowCallStack.Checked;
  2506. frmStack.Visible := actShowCallStack.Checked;
  2507. if actShowCallStack.Checked then
  2508. ShowDockForm(frmStack)
  2509. else
  2510. HideDockForm(frmStack);
  2511. end;
  2512. procedure TfrmLuaEditMain.actShowCallStackExecute(Sender: TObject);
  2513. begin
  2514. DoShowCallStackExecute;
  2515. end;
  2516. function TfrmLuaEditMain.DoShowProfilerExecute(): Boolean;
  2517. begin
  2518. Result := True;
  2519. actShowProfiler.Checked := not actShowProfiler.Checked;
  2520. frmProfiler.Visible := actShowProfiler.Checked;
  2521. if actShowProfiler.Checked then
  2522. ShowDockForm(frmProfiler)
  2523. else
  2524. HideDockForm(frmProfiler);
  2525. end;
  2526. procedure TfrmLuaEditMain.actShowProfilerExecute(Sender: TObject);
  2527. begin
  2528. DoShowProfilerExecute();
  2529. end;
  2530. function TfrmLuaEditMain.DoShowGUIControlsExecute(): Boolean;
  2531. begin
  2532. Result := True;
  2533. actShowGUIControls.Checked := not actShowGUIControls.Checked;
  2534. frmGUIControls.Visible := actShowGUIControls.Checked;
  2535. if actShowGUIControls.Checked then
  2536. ShowDockForm(frmGUIControls)
  2537. else
  2538. HideDockForm(frmGUIControls);
  2539. end;
  2540. procedure TfrmLuaEditMain.actShowGUIControlsExecute(Sender: TObject);
  2541. begin
  2542. DoShowGUIControlsExecute();
  2543. end;
  2544. function TfrmLuaEditMain.DoShowLuaStackExecute(): Boolean;
  2545. begin
  2546. Result := True;
  2547. actShowLuaStack.Checked := not actShowLuaStack.Checked;
  2548. frmLuaStack.Visible := actShowLuaStack.Checked;
  2549. if actShowLuaStack.Checked then
  2550. ShowDockForm(frmLuaStack)
  2551. else
  2552. HideDockForm(frmLuaStack);
  2553. end;
  2554. procedure TfrmLuaEditMain.actShowLuaStackExecute(Sender: TObject);
  2555. begin
  2556. DoShowLuaStackExecute;
  2557. end;
  2558. function TfrmLuaEditMain.DoShowLuaConsoleExecute(): Boolean;
  2559. begin
  2560. Result := True;
  2561. actShowLuaConsole.Checked := not actShowLuaConsole.Checked;
  2562. frmLuaConsole.Visible := actShowLuaConsole.Checked;
  2563. if actShowLuaConsole.Checked then
  2564. ShowDockForm(frmLuaConsole)
  2565. else
  2566. HideDockForm(frmLuaConsole);
  2567. end;
  2568. procedure TfrmLuaEditMain.actShowLuaConsoleExecute(Sender: TObject);
  2569. begin
  2570. DoShowLuaConsoleExecute;
  2571. end;
  2572. function TfrmLuaEditMain.DoShowLuaGlobalsExecute(): Boolean;
  2573. begin
  2574. Result := True;
  2575. actShowLuaGlobals.Checked := not actShowLuaGlobals.Checked;
  2576. frmLuaGlobals.Visible := actShowLuaGlobals.Checked;
  2577. if actShowLuaGlobals.Checked then
  2578. ShowDockForm(frmLuaGlobals)
  2579. else
  2580. HideDockForm(frmLuaGlobals);
  2581. end;
  2582. procedure TfrmLuaEditMain.actShowLuaGlobalsExecute(Sender: TObject);
  2583. begin
  2584. DoShowLuaGlobalsExecute;
  2585. end;
  2586. function TfrmLuaEditMain.DoShowLuaLocalsExecute(): Boolean;
  2587. begin
  2588. Result := True;
  2589. actShowLuaLocals.Checked := not actShowLuaLocals.Checked;
  2590. frmLuaLocals.Visible := actShowLuaLocals.Checked;
  2591. if actShowLuaLocals.Checked then
  2592. ShowDockForm(frmLuaLocals)
  2593. else
  2594. HideDockForm(frmLuaLocals);
  2595. end;
  2596. procedure TfrmLuaEditMain.actShowLuaLocalsExecute(Sender: TObject);
  2597. begin
  2598. DoShowLuaLocalsExecute;
  2599. end;
  2600. function TfrmLuaEditMain.DoShowRingsExecute(): Boolean;
  2601. begin
  2602. Result := True;
  2603. actShowRings.Checked := not actShowRings.Checked;
  2604. frmRings.Visible := actShowRings.Checked;
  2605. if actShowRings.Checked then
  2606. ShowDockForm(frmRings)
  2607. else
  2608. HideDockForm(frmRings);
  2609. end;
  2610. procedure TfrmLuaEditMain.actShowRingsExecute(Sender: TObject);
  2611. begin
  2612. DoShowRingsExecute;
  2613. end;
  2614. function TfrmLuaEditMain.DoShowFunctionListExecute(): Boolean;
  2615. begin
  2616. Result := True;
  2617. actShowFunctionList.Checked := not actShowFunctionList.Checked;
  2618. frmFunctionList.Visible := actShowFunctionList.Checked;
  2619. if actShowFunctionList.Checked then
  2620. ShowDockForm(frmFunctionList)
  2621. else
  2622. HideDockForm(frmFunctionList);
  2623. end;
  2624. procedure TfrmLuaEditMain.actShowFunctionListExecute(Sender: TObject);
  2625. begin
  2626. DoShowFunctionListExecute;
  2627. end;
  2628. function TfrmLuaEditMain.DoShowInternalBrowserExecute(): Boolean;
  2629. begin
  2630. Result := True;
  2631. actShowInternalBrowser.Checked := not actShowInternalBrowser.Checked;
  2632. frmInternalBrowser.Visible := actShowInternalBrowser.Checked;
  2633. if actShowInternalBrowser.Checked then
  2634. ShowDockForm(frmInternalBrowser)
  2635. else
  2636. HideDockForm(frmInternalBrowser);
  2637. end;
  2638. procedure TfrmLuaEditMain.actShowInternalBrowserExecute(Sender: TObject);
  2639. begin
  2640. DoShowInternalBrowserExecute;
  2641. end;
  2642. function TfrmLuaEditMain.DoShowFindWindow1Execute(): Boolean;
  2643. begin
  2644. Result := True;
  2645. actShowFindWindow1.Checked := not actShowFindWindow1.Checked;
  2646. frmFindWindow1.Visible := actShowFindWindow1.Checked;
  2647. if actShowFindWindow1.Checked then
  2648. ShowDockForm(frmFindWindow1)
  2649. else
  2650. HideDockForm(frmFindWindow1);
  2651. end;
  2652. procedure TfrmLuaEditMain.actShowFindWindow1Execute(Sender: TObject);
  2653. begin
  2654. DoShowFindWindow1Execute;
  2655. end;
  2656. function TfrmLuaEditMain.DoShowFindWindow2Execute(): Boolean;
  2657. begin
  2658. Result := True;
  2659. actShowFindWindow2.Checked := not actShowFindWindow2.Checked;
  2660. frmFindWindow2.Visible := actShowFindWindow2.Checked;
  2661. if actShowFindWindow2.Checked then
  2662. ShowDockForm(frmFindWindow2)
  2663. else
  2664. HideDockForm(frmFindWindow2);
  2665. end;
  2666. procedure TfrmLuaEditMain.actShowFindWindow2Execute(Sender: TObject);
  2667. begin
  2668. DoShowFindWindow2Execute;
  2669. end;
  2670. procedure TfrmLuaEditMain.mnuXMacroClick(Sender: TObject);
  2671. var
  2672. pReg: TRegistry;
  2673. pMenu: TMenuItem;
  2674. RunRelease: Boolean;
  2675. procedure ExecMacroRelease(FileName: String);
  2676. var
  2677. ScriptCode: TStringList;
  2678. begin
  2679. ScriptCode := TStringList.Create;
  2680. // Load/Execute macro
  2681. ScriptCode.LoadFromFile(FileName);
  2682. LuaLoadBuffer(MacroLuaState, ScriptCode.Text, FileName);
  2683. LuaPCall(MacroLuaState, 0, 0, 0);
  2684. // Free variables
  2685. ScriptCode.Free;
  2686. end;
  2687. procedure ExecMacroDebug(FileName: String);
  2688. begin
  2689. RunRelease := False;
  2690. PopUpUnitToScreen(FileName);
  2691. DoStepIntoExecute();
  2692. end;
  2693. begin
  2694. // Initiate a few things
  2695. pReg := TRegistry.Create;
  2696. pMenu := TMenuItem(Sender);
  2697. RunRelease := True;
  2698. // Get macro's datas
  2699. if pReg.OpenKey('\Software\LuaEdit\Macros\'+pMenu.Hint, False) then
  2700. begin
  2701. // Execute in debug mode if at all possible
  2702. if pReg.ReadBool('DebugMode') then
  2703. begin
  2704. if not Running then
  2705. ExecMacroDebug(pReg.ReadString('FileName'))
  2706. else
  2707. begin
  2708. Application.MessageBox('LuaEdit is enable to initiate the macro in debug mode because you are debugging another file. The macro will run in release mode.', 'LuaEdit', MB_OK+MB_ICONWARNING);
  2709. ExecMacroRelease(pReg.ReadString('FileName'));
  2710. end;
  2711. end
  2712. else
  2713. ExecMacroRelease(pReg.ReadString('FileName'));
  2714. end;
  2715. pReg.Free;
  2716. end;
  2717. procedure TfrmLuaEditMain.mnuXReopenClick(Sender: TObject);
  2718. var
  2719. pFiles: TStringList;
  2720. mnuSender: TMenuItem;
  2721. pReg: TRegistry;
  2722. BuildTreeNeeded: Boolean;
  2723. x: Integer;
  2724. begin
  2725. pFiles := TStringList.Create;
  2726. BuildTreeNeeded := False;
  2727. mnuSender := TMenuItem(Sender);
  2728. if FileExistsAbs(mnuSender.Caption) then
  2729. begin
  2730. pFiles.Add(mnuSender.Caption);
  2731. DoOpenFileExecute(pFiles);
  2732. end
  2733. else
  2734. begin
  2735. Application.MessageBox(PChar('The file "'+mnuSender.Caption+'" is innexistant and will be removed from the list.'), 'LuaEdit', MB_OK+MB_ICONERROR);
  2736. // Remove entry from registry
  2737. pReg := TRegistry.Create;
  2738. if pReg.OpenKey('\Software\LuaEdit\RecentFiles', False) then
  2739. begin
  2740. if pReg.ValueExists(mnuSender.Caption) then
  2741. pReg.DeleteValue(mnuSender.Caption);
  2742. end;
  2743. // Remove ring button from the list
  2744. for x := 0 to frmRings.jvRings.Pages[JVPAGE_RING_FILES].Buttons.Count - 1 do
  2745. begin
  2746. if frmRings.jvRings.Pages[JVPAGE_RING_FILES].Buttons[x].Caption = mnuSender.Caption then
  2747. begin
  2748. frmRings.jvRings.Pages[JVPAGE_RING_FILES].Buttons.Delete(x);
  2749. Break;
  2750. end;
  2751. end;
  2752. // Remove menu from the other reopen menu
  2753. if mnuSender.Owner.ClassType <> TPopupMenu then
  2754. begin
  2755. for x := 0 to mnuReopen.Items.Count - 1 do
  2756. begin
  2757. if mnuReopen.Items[x].Caption = mnuSender.Caption then
  2758. begin
  2759. mnuReopen.Items.Delete(x);
  2760. Break;
  2761. end;
  2762. end;
  2763. end
  2764. else
  2765. begin
  2766. for x := 0 to Reopen1.Count - 1 do
  2767. begin
  2768. if Reopen1.Items[x].Caption = mnuSender.Caption then
  2769. begin
  2770. Reopen1.Delete(x);
  2771. Break;
  2772. end;
  2773. end;
  2774. end;
  2775. // Remove itself from the list
  2776. mnuSender.Free;
  2777. end;
  2778. // Rebuild tree view and initialize stuff
  2779. if BuildTreeNeeded then
  2780. begin
  2781. frmProjectTree.BuildProjectTree;
  2782. CheckButtons;
  2783. end;
  2784. pFiles.Free;
  2785. end;
  2786. // Trigered when user clicks on a ring button of the "Files" slide bar
  2787. procedure TfrmLuaEditMain.btnXFilesClick(Sender: TObject);
  2788. var
  2789. pFiles: TStringList;
  2790. btnSender: TJvOutlookBarButton;
  2791. pReg: TRegistry;
  2792. BuildTreeNeeded: Boolean;
  2793. x: Integer;
  2794. begin
  2795. pFiles := TStringList.Create;
  2796. BuildTreeNeeded := False;
  2797. btnSender := TJvOutlookBarButton(Sender);
  2798. if FileExistsAbs(btnSender.Caption) then
  2799. begin
  2800. pFiles.Add(btnSender.Caption);
  2801. DoOpenFileExecute(pFiles);
  2802. end
  2803. else
  2804. begin
  2805. Application.MessageBox(PChar('The file "'+btnSender.Caption+'" is innexistant and will be removed from the list.'), 'LuaEdit', MB_OK+MB_ICONERROR);
  2806. // Remove entry from registry
  2807. pReg := TRegistry.Create;
  2808. if pReg.OpenKey('\Software\LuaEdit\RecentFiles', False) then
  2809. begin
  2810. if pReg.ValueExists(btnSender.Caption) then
  2811. pReg.DeleteValue(btnSender.Caption);
  2812. end;
  2813. pReg.Free;
  2814. // Remove menu from the two reopen menus
  2815. for x := 0 to mnuReopen.Items.Count - 1 do
  2816. begin
  2817. if mnuReopen.Items[x].Caption = btnSender.Caption then
  2818. begin
  2819. mnuReopen.Items.Delete(x);
  2820. Break;
  2821. end;
  2822. end;
  2823. for x := 0 to Reopen1.Count - 1 do
  2824. begin
  2825. if Reopen1.Items[x].Caption = btnSender.Caption then
  2826. begin
  2827. Reopen1.Delete(x);
  2828. Break;
  2829. end;
  2830. end;
  2831. // Remove itself from the list
  2832. btnSender.Free;
  2833. end;
  2834. // Rebuild tree view and initialize stuff
  2835. if BuildTreeNeeded then
  2836. begin
  2837. frmProjectTree.BuildProjectTree;
  2838. CheckButtons;
  2839. end;
  2840. pFiles.Free;
  2841. end;
  2842. procedure TfrmLuaEditMain.btnXClipboardClick(Sender: TObject);
  2843. begin
  2844. Clipboard.SetTextBuf(PChar(TJvOutlookBarButton(Sender).Caption));
  2845. end;
  2846. function TfrmLuaEditMain.IsProjectOpened(sProjectPath: String): Boolean;
  2847. var
  2848. x: integer;
  2849. begin
  2850. Result := False;
  2851. for x := 0 to LuaProjects.Count - 1 do
  2852. begin
  2853. if TLuaEditProject(LuaProjects.Items[x]).Path = sProjectPath then
  2854. begin
  2855. Result := True;
  2856. break;
  2857. end;
  2858. end;
  2859. end;
  2860. function TfrmLuaEditMain.IsFileOpened(sFilePath: String): Boolean;
  2861. var
  2862. x: Integer;
  2863. pFile: TLuaEditBasicTextFile;
  2864. begin
  2865. Result := False;
  2866. for x := 0 to LuaOpenedFiles.Count - 1 do
  2867. begin
  2868. pFile := TLuaEditBasicTextFile(LuaOpenedFiles.Items[x]);
  2869. if sFilePath = pFile.DisplayPath then
  2870. begin
  2871. Result := True;
  2872. Break;
  2873. end;
  2874. end;
  2875. end;
  2876. function TfrmLuaEditMain.GetOpenedFile(sFilePath: String): TLuaEditBasicTextFile;
  2877. var
  2878. x: Integer;
  2879. pFile: TLuaEditBasicTextFile;
  2880. begin
  2881. Result := nil;
  2882. for x := 0 to LuaOpenedFiles.Count - 1 do
  2883. begin
  2884. pFile := TLuaEditBasicTextFile(LuaOpenedFiles.Items[x]);
  2885. if sFilePath = pFile.DisplayPath then
  2886. begin
  2887. Result := pFile;
  2888. Break;
  2889. end;
  2890. end;
  2891. end;
  2892. function TfrmLuaEditMain.DoUndoExecute(): Boolean;
  2893. begin
  2894. Result := True;
  2895. TLuaEditUnit(jvUnitBar.SelectedTab.Data).SynUnit.Undo;
  2896. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).SynUnit.UndoList.ItemCount = 0 then
  2897. actUndo.Enabled := False
  2898. else
  2899. actUndo.Enabled := True;
  2900. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).SynUnit.RedoList.ItemCount = 0 then
  2901. actRedo.Enabled := False
  2902. else
  2903. actRedo.Enabled := True;
  2904. end;
  2905. procedure TfrmLuaEditMain.actUndoExecute(Sender: TObject);
  2906. begin
  2907. DoUndoExecute;
  2908. end;
  2909. function TfrmLuaEditMain.DoRedoExecute(): Boolean;
  2910. begin
  2911. Result := True;
  2912. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Redo;
  2913. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.UndoList.ItemCount = 0 then
  2914. actUndo.Enabled := False
  2915. else
  2916. actUndo.Enabled := True;
  2917. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.RedoList.ItemCount = 0 then
  2918. actRedo.Enabled := False
  2919. else
  2920. actRedo.Enabled := True;
  2921. end;
  2922. procedure TfrmLuaEditMain.actRedoExecute(Sender: TObject);
  2923. begin
  2924. DoRedoExecute;
  2925. end;
  2926. function TfrmLuaEditMain.DoCutExecute(): Boolean;
  2927. var
  2928. jvOBBtn: TJvOutlookBarButton;
  2929. x: Integer;
  2930. pLuaUnit: TLuaEditUnit;
  2931. begin
  2932. Result := False;
  2933. if Assigned(jvUnitBar.SelectedTab) then
  2934. begin
  2935. if Assigned(jvUnitBar.SelectedTab.Data) then
  2936. begin
  2937. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  2938. if pLuaUnit.synUnit.SelText <> '' then
  2939. begin
  2940. pLuaUnit.synUnit.CutToClipboard;
  2941. // Make sure we don't add content that was already there
  2942. for x := 0 to frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Count - 1 do
  2943. begin
  2944. if frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons[x].Caption = pLuaUnit.synUnit.SelText then
  2945. begin
  2946. frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons[x].Free;
  2947. Break;
  2948. end;
  2949. end;
  2950. // Remove last item if already 10 are listed
  2951. if frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Count = 10 then
  2952. frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Delete(9);
  2953. jvOBBtn := frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Insert(0);
  2954. jvOBBtn.Caption := Clipboard.AsText;
  2955. jvOBBtn.OnClick := btnXClipboardClick;
  2956. Result := True;
  2957. end;
  2958. end;
  2959. end;
  2960. end;
  2961. procedure TfrmLuaEditMain.actCutExecute(Sender: TObject);
  2962. begin
  2963. DoCutExecute;
  2964. end;
  2965. function TfrmLuaEditMain.DoCopyExecute(): Boolean;
  2966. var
  2967. jvOBBtn: TJvOutlookBarButton;
  2968. x: Integer;
  2969. pLuaUnit: TLuaEditUnit;
  2970. begin
  2971. Result := False;
  2972. if Assigned(jvUnitBar.SelectedTab) then
  2973. begin
  2974. if Assigned(jvUnitBar.SelectedTab.Data) then
  2975. begin
  2976. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  2977. if pLuaUnit.synUnit.SelText <> '' then
  2978. begin
  2979. pLuaUnit.synUnit.CopyToClipboard;
  2980. // Make sure we don't add content that was already there
  2981. for x := 0 to frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Count - 1 do
  2982. begin
  2983. if frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons[x].Caption = pLuaUnit.synUnit.SelText then
  2984. begin
  2985. frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons[x].Free;
  2986. Break;
  2987. end;
  2988. end;
  2989. // Remove last item if already 10 are listed
  2990. if frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Count = 10 then
  2991. frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Delete(9);
  2992. jvOBBtn := frmRings.jvRings.Pages[JVPAGE_RING_CLIPBOARD].Buttons.Insert(0);
  2993. jvOBBtn.Caption := Clipboard.AsText;
  2994. jvOBBtn.OnClick := btnXClipboardClick;
  2995. Result := True;
  2996. end;
  2997. end;
  2998. end;
  2999. end;
  3000. procedure TfrmLuaEditMain.actCopyExecute(Sender: TObject);
  3001. begin
  3002. DoCopyExecute;
  3003. end;
  3004. function TfrmLuaEditMain.DoPasteExecute(): Boolean;
  3005. begin
  3006. Result := Assigned(jvUnitBar.SelectedTab);
  3007. if Result then
  3008. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.PasteFromClipboard;
  3009. end;
  3010. procedure TfrmLuaEditMain.actPasteExecute(Sender: TObject);
  3011. begin
  3012. DoPasteExecute;
  3013. end;
  3014. function TfrmLuaEditMain.DoSelectAll(): Boolean;
  3015. begin
  3016. Result := Assigned(jvUnitBar.SelectedTab);
  3017. if Result then
  3018. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelectAll;
  3019. end;
  3020. procedure TfrmLuaEditMain.actSelectAllExecute(Sender: TObject);
  3021. begin
  3022. DoSelectAll;
  3023. end;
  3024. function TfrmLuaEditMain.DoFindExecute(): Boolean;
  3025. var
  3026. Options: TSynSearchOptions;
  3027. Index: Integer;
  3028. begin
  3029. Result := True;
  3030. frmSearch.chkRegularExpression.Checked := srSearchRegularExpression;
  3031. frmSearch.chkSearchCaseSensitive.Checked := srSearchSensitive;
  3032. frmSearch.chkSearchWholeWords.Checked := srSearchWholeWords;
  3033. frmSearch.optOrigin.ItemIndex := srSearchOrigin;
  3034. frmSearch.optScope.ItemIndex := srSearchScope;
  3035. frmSearch.optDirection.ItemIndex := srSearchDriection;
  3036. frmSearch.cboSearchText.Items.Clear;
  3037. frmSearch.cboSearchText.Items.AddStrings(SearchedText);
  3038. if SearchedText.Count > 0 then
  3039. frmSearch.cboSearchText.Text := SearchedText.Strings[SearchedText.Count - 1];
  3040. if ((TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelLength > 0) and (TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockBegin.Line = TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockEnd.Line)) then
  3041. frmSearch.cboSearchText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText
  3042. else if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY) <> '' then
  3043. frmSearch.cboSearchText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY);
  3044. frmSearch.ShowModal;
  3045. if frmSearch.SearchText <> '' then
  3046. begin
  3047. Options := [];
  3048. srSearchRegularExpression := frmSearch.IsResgularExpression;
  3049. srSearchSensitive := frmSearch.IsCaseSensitive;
  3050. if srSearchSensitive then
  3051. Options := Options + [ssoMatchCase];
  3052. srSearchWholeWords := frmSearch.IsWholeWordOnly;
  3053. if srSearchWholeWords then
  3054. Options := Options + [ssoWholeWord];
  3055. srSearchOrigin := frmSearch.GetOrigin;
  3056. if srSearchOrigin = SR_ENTIRESCOPE then
  3057. Options := Options + [ssoEntireScope];
  3058. srSearchScope := frmSearch.GetScope;
  3059. if srSearchScope = SR_SELECTED then
  3060. Options := Options + [ssoSelectedOnly];
  3061. srSearchDriection := frmSearch.GetDirection;
  3062. if srSearchDriection = SR_BACKWARD then
  3063. Options := Options + [ssoBackwards];
  3064. sSearchString := frmSearch.SearchText;
  3065. SearchedText.Sort;
  3066. if not SearchedText.Find(sSearchString, Index) then
  3067. SearchedText.Add(sSearchString);
  3068. if srSearchRegularExpression then
  3069. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearchRegEx
  3070. else
  3071. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearch;
  3072. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchReplace(sSearchString, '', Options) = 0 then
  3073. begin
  3074. Result := False;
  3075. Application.MessageBox(PChar('Search string "'+sSearchString+'" not found.'), 'LuaEdit', MB_OK+MB_ICONINFORMATION);
  3076. end;
  3077. end;
  3078. end;
  3079. procedure TfrmLuaEditMain.actFindExecute(Sender: TObject);
  3080. begin
  3081. DoFindExecute;
  3082. end;
  3083. function TfrmLuaEditMain.DoFindInFilesExecute(): Boolean;
  3084. var
  3085. Options: TSynSearchOptions;
  3086. Index: Integer;
  3087. function FileIsText(FileName : string) : boolean;
  3088. var
  3089. MS :TMemoryStream;
  3090. BytesRead, i : integer;
  3091. FileChar : Char;
  3092. NonTextChars : set of char;
  3093. const
  3094. HT = #9; // horizontal tab
  3095. LF = #10; // line feed
  3096. FF = #12; // form feed
  3097. CR = #13; // carriage return
  3098. TextChars : set of char = [HT, LF, FF, CR, ' '..'~'];
  3099. begin
  3100. NonTextChars := [#0..#255] - TextChars;
  3101. Result := true;
  3102. MS := TMemoryStream.Create;
  3103. with MS do begin
  3104. LoadFromFile(FileName);
  3105. Seek(0, soFromBeginning);
  3106. BytesRead := Read(FileChar, 1);
  3107. while BytesRead > 0 do begin
  3108. if (FileChar in NonTextChars) then begin
  3109. Result := false;
  3110. Free;
  3111. Exit;
  3112. end;
  3113. BytesRead := Read(FileChar, 1);
  3114. end;{while BytesRead > 0}
  3115. Free;
  3116. end; {with MS do begin}
  3117. end;
  3118. // Find all instances of the text in the given synedit control
  3119. procedure FindTextInSynEdit(FileName, TextToFind: String; Output: Integer; SynEdit: TSynEdit; SynOptions: TSynSearchOptions);
  3120. begin
  3121. // Initialize some stuff...
  3122. frmSIFReport.CurrentFile := FileName;
  3123. frmSIFReport.ScannedFiles := frmSIFReport.ScannedFiles + 1;
  3124. frmSIFReport.ScannedLines := frmSIFReport.ScannedLines + SynEdit.Lines.Count;
  3125. SynEdit.CaretX := 0;
  3126. SynEdit.CaretY := 0;
  3127. // Assign search engine (regular expressions or not)
  3128. if srSearchInFilesRegularExpression then
  3129. SynEdit.SearchEngine := synMainSearchRegEx
  3130. else
  3131. SynEdit.SearchEngine := synMainSearch;
  3132. while SynEdit.SearchReplace(TextToFind, '', SynOptions) <> 0 do
  3133. begin
  3134. frmSIFReport.MatchFound := frmSIFReport.MatchFound + 1;
  3135. // Add result in the right window
  3136. if Output = 0 then
  3137. frmFindWindow1.AddResult(FileName, SynEdit.CaretY, SynEdit.Lines[SynEdit.CaretY - 1])
  3138. else
  3139. frmFindWindow2.AddResult(FileName, SynEdit.CaretY, SynEdit.Lines[SynEdit.CaretY - 1])
  3140. end;
  3141. end;
  3142. // Find text through the current active project
  3143. procedure FindFilesInProject(TextToFind: String; LuaProject: TLuaEditProject; Output: Integer; SynOptions: TSynSearchOptions);
  3144. var
  3145. x: Integer;
  3146. pTmpSynEdit: TSynEdit;
  3147. begin
  3148. pTmpSynEdit := TSynEdit.Create(nil);
  3149. pTmpSynEdit.Visible := False;
  3150. for x := 0 to LuaProject.lstUnits.Count - 1 do
  3151. begin
  3152. if Assigned(TLuaEditUnit(LuaProject.lstUnits[x]).SynUnit) then
  3153. pTmpSynEdit.Text := TLuaEditUnit(LuaProject.lstUnits[x]).SynUnit.Text
  3154. else
  3155. pTmpSynEdit.Lines.LoadFromFile(TLuaEditUnit(LuaProject.lstUnits[x]).Path);
  3156. FindTextInSynEdit(TLuaEditUnit(LuaProject.lstUnits[x]).Path, TextToFind, Output, pTmpSynEdit, SynOptions);
  3157. end;
  3158. pTmpSynEdit.Free;
  3159. end;
  3160. // Find text through all opened files
  3161. procedure FindFilesOpened(TextToFind: String; Output: Integer; SynOptions: TSynSearchOptions);
  3162. var
  3163. x: Integer;
  3164. pTmpSynEdit: TSynEdit;
  3165. begin
  3166. pTmpSynEdit := TSynEdit.Create(nil);
  3167. pTmpSynEdit.Visible := False;
  3168. for x := 0 to LuaOpenedFiles.Count - 1 do
  3169. begin
  3170. pTmpSynEdit.Text := TLuaEditUnit(LuaOpenedFiles[x]).SynUnit.Text;
  3171. FindTextInSynEdit(TLuaEditUnit(LuaOpenedFiles[x]).Path, TextToFind, Output, pTmpSynEdit, SynOptions);
  3172. end;
  3173. pTmpSynEdit.Free;
  3174. end;
  3175. // Find text through the specified directory (possibly all sub directory too -- recursive calls)
  3176. procedure FindFilesInDir(Path, TextToFind: String; IsRecursive: Boolean; Output: Integer; SynOptions: TSynSearchOptions);
  3177. var
  3178. pTmpSynEdit: TSynEdit;
  3179. FullPathName: String;
  3180. iSearchResult: Integer;
  3181. hSearchHandle: TSearchRec;
  3182. begin
  3183. if Path[Length(Path) - 1] = '\' then
  3184. iSearchResult := FindFirst(Path+'*.*', faAnyFile, hSearchHandle)
  3185. else
  3186. iSearchResult := FindFirst(Path+'\*.*', faAnyFile, hSearchHandle);
  3187. while iSearchResult = 0 do
  3188. begin
  3189. if Path[Length(Path) - 1] = '\' then
  3190. FullPathName := Path + hSearchHandle.Name
  3191. else
  3192. FullPathName := Path + '\' + hSearchHandle.Name;
  3193. if (IsRecursive and (hSearchHandle.Name <> '.') and (hSearchHandle.Name <> '..') and ((hSearchHandle.Attr and faDirectory) <> 0)) then
  3194. begin
  3195. // Recursive call for the new found directory
  3196. FindFilesInDir(FullPathName, TextToFind, IsRecursive, Output, SynOptions);
  3197. end
  3198. else
  3199. begin
  3200. if (hSearchHandle.Attr and faDirectory) = 0 then
  3201. begin
  3202. // Make sure the file is a *.lua file
  3203. if FileIsText(FullPathName) then
  3204. begin
  3205. pTmpSynEdit := TSynEdit.Create(nil);
  3206. pTmpSynEdit.Visible := False;
  3207. pTmpSynEdit.Lines.LoadFromFile(FullPathName);
  3208. FindTextInSynEdit(FullPathName, TextToFind, Output, pTmpSynEdit, SynOptions);
  3209. pTmpSynEdit.Free;
  3210. end
  3211. else
  3212. frmSIFReport.SkippedFiles := frmSIFReport.SkippedFiles + 1;
  3213. end;
  3214. end;
  3215. iSearchResult := FindNext(hSearchHandle);
  3216. end;
  3217. FindClose(hSearchHandle);
  3218. end;
  3219. begin
  3220. // Initialize find in files window
  3221. Result := True;
  3222. frmFindInFiles.chkRegularExpression.Checked := srSearchInFilesRegularExpression;
  3223. frmFindInFiles.chkSearchCaseSensitive.Checked := srSearchInFilesSensitive;
  3224. frmFindInFiles.chkSearchWholeWords.Checked := srSearchInFilesWholeWords;
  3225. frmFindInFiles.optOutput.ItemIndex := srSearchInFilesOutput;
  3226. frmFindInFiles.jvoptActiveProject.Enabled := Assigned(ActiveProject);
  3227. frmFindInFiles.jvoptOpenFiles.Enabled := (LuaOpenedFiles.Count <> 0);
  3228. frmFindInFiles.SetSearchMode(srSearchInFilesWhere);
  3229. frmFindInFiles.cboSearchInFilesText.Items.Clear;
  3230. frmFindInFiles.cboSearchInFilesText.Items.AddStrings(SearchedInFilesText);
  3231. if SearchedInFilesText.Count > 0 then
  3232. frmFindInFiles.cboSearchInFilesText.Text := SearchedInFilesText.Strings[SearchedInFilesText.Count - 1];
  3233. if Assigned(jvUnitBar.SelectedTab) then
  3234. begin
  3235. if ((TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelLength > 0) and (TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockBegin.Line = TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockEnd.Line)) then
  3236. frmFindInFiles.cboSearchInFilesText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText
  3237. else if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY) <> '' then
  3238. frmFindInFiles.cboSearchInFilesText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY);
  3239. end;
  3240. // Show the find in files dialog
  3241. frmFindInFiles.ShowModal;
  3242. if frmFindInFiles.SearchText <> '' then
  3243. begin
  3244. // Set base search options
  3245. Options := [];
  3246. // Add user's preferences to search options
  3247. srSearchInFilesSubDir := frmFindInFiles.IsSubDir;
  3248. srSearchInFilesWhere := frmFindInFiles.GetSearchMode;
  3249. srSearchInFilesOutput := frmFindInFiles.GetOutput;
  3250. srSearchInFilesRegularExpression := frmFindInFiles.IsResgularExpression;
  3251. srSearchInFilesSensitive := frmFindInFiles.IsCaseSensitive;
  3252. if srSearchInFilesSensitive then
  3253. Options := Options + [ssoMatchCase];
  3254. srSearchInFilesWholeWords := frmFindInFiles.IsWholeWordOnly;
  3255. if srSearchInFilesWholeWords then
  3256. Options := Options + [ssoWholeWord];
  3257. sSearchInFilesString := frmFindInFiles.SearchText;
  3258. sSearchInFilesDir := frmFindInFiles.SearchDirectory;
  3259. SearchedInFilesText.Sort;
  3260. if not SearchedInFilesText.Find(sSearchInFilesString, Index) then
  3261. SearchedInFilesText.Add(sSearchInFilesString);
  3262. if sSearchInFilesString <> '' then
  3263. begin
  3264. // Initialize stuff...
  3265. Screen.Cursor := crHourGlass;
  3266. frmSIFReport.ResetReport;
  3267. frmSIFReport.Show;
  3268. if srSearchInFilesOutput = 0 then
  3269. frmFindWindow1.lvwResult.Clear
  3270. else
  3271. frmFindWindow2.lvwResult.Clear;
  3272. // Find results according to the search mode
  3273. case srSearchInFilesWhere of
  3274. SIF_ACTPROJECT: FindFilesInProject(sSearchInFilesString, ActiveProject, srSearchInFilesOutput, Options);
  3275. SIF_OPENED: FindFilesOpened(sSearchInFilesString, srSearchInFilesOutput, Options);
  3276. SIF_DIRECTORY: FindFilesInDir(sSearchInFilesDir, sSearchInFilesString, srSearchInFilesSubDir, srSearchInFilesOutput, Options);
  3277. end;
  3278. // Close the report window if required
  3279. if not KeepSIFWindowOpened then
  3280. frmSIFReport.Close;
  3281. // Uninitialize stuff...
  3282. Screen.Cursor := crDefault;
  3283. // Display messages if no match found or popup the right find window if there's a match
  3284. if frmSIFReport.MatchFound = 0 then
  3285. begin
  3286. Result := False;
  3287. // Spelling check, lol ([files were ...] or [file was ...])
  3288. if frmSIFReport.ScannedFiles > 1 then
  3289. Application.MessageBox(PChar('Search string "'+sSearchInFilesString+'" not found. ' + IntToStr(frmSIFReport.ScannedFiles) + ' files were scanned.'), 'LuaEdit', MB_OK+MB_ICONINFORMATION)
  3290. else
  3291. Application.MessageBox(PChar('Search string "'+sSearchInFilesString+'" not found. ' + IntToStr(frmSIFReport.ScannedFiles) + ' file was scanned.'), 'LuaEdit', MB_OK+MB_ICONINFORMATION);
  3292. end
  3293. else
  3294. begin
  3295. // Initialize actions before executing
  3296. DoMainMenuViewExecute;
  3297. // Popup the corresponding find window if not already opened
  3298. if srSearchInFilesOutput = 0 then
  3299. ShowDockForm(frmFindWindow1)
  3300. else
  3301. ShowDockForm(frmFindWindow2);
  3302. end;
  3303. end;
  3304. end;
  3305. end;
  3306. procedure TfrmLuaEditMain.actFindInFilesExecute(Sender: TObject);
  3307. begin
  3308. DoFindInFilesExecute;
  3309. end;
  3310. function TfrmLuaEditMain.DoFindAgainExecute(): Boolean;
  3311. var
  3312. Options: TSynSearchOptions;
  3313. begin
  3314. Result := True;
  3315. Options := [];
  3316. if srSearchSensitive then
  3317. Options := Options + [ssoMatchCase];
  3318. if srSearchWholeWords then
  3319. Options := Options + [ssoWholeWord];
  3320. if srSearchOrigin = SR_ENTIRESCOPE then
  3321. Options := Options + [ssoEntireScope];
  3322. if srSearchScope = SR_SELECTED then
  3323. Options := Options + [ssoSelectedOnly];
  3324. if srSearchDriection = SR_BACKWARD then
  3325. Options := Options + [ssoBackwards];
  3326. if not srSearchRegularExpression then
  3327. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearch
  3328. else
  3329. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearchRegEx;
  3330. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchReplace(sSearchString, '', Options) = 0 then
  3331. begin
  3332. Result := False;
  3333. Application.MessageBox(PChar('Search string "'+sSearchString+'" not found.'), 'LuaEdit', MB_OK+MB_ICONINFORMATION);
  3334. end;
  3335. end;
  3336. procedure TfrmLuaEditMain.actFindAgainExecute(Sender: TObject);
  3337. begin
  3338. DoFindAgainExecute;
  3339. end;
  3340. function TfrmLuaEditMain.DoFindReplaceExecute(): Boolean;
  3341. var
  3342. Options: TSynSearchOptions;
  3343. Index: Integer;
  3344. begin
  3345. Result := True;
  3346. frmReplace.chkRegularExpression.Checked := srSearchRegularExpression;
  3347. frmReplace.chkSearchCaseSensitive.Checked := srSearchSensitive;
  3348. frmReplace.chkSearchWholeWords.Checked := srSearchWholeWords;
  3349. frmReplace.optOrigin.ItemIndex := srSearchOrigin;
  3350. frmReplace.optScope.ItemIndex := srSearchScope;
  3351. frmReplace.optDirection.ItemIndex := srSearchDriection;
  3352. frmReplace.cboSearchText.Items.Clear;
  3353. frmReplace.cboSearchText.Items.AddStrings(SearchedText);
  3354. frmReplace.cboReplaceText.Clear;
  3355. frmReplace.cboReplaceText.Items.AddStrings(ReplacedText);
  3356. if SearchedText.Count > 0 then
  3357. frmReplace.cboSearchText.Text := SearchedText.Strings[SearchedText.Count - 1];
  3358. if ((TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelAvail) and (TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockBegin.Line = TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.BlockEnd.Line)) then
  3359. frmReplace.cboSearchText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText
  3360. else if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY) <> '' then
  3361. frmReplace.cboSearchText.Text := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GetWordAtRowCol(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretXY);
  3362. frmReplace.ShowModal;
  3363. if frmReplace.SearchText <> '' then
  3364. begin
  3365. Options := [ssoReplace];
  3366. srSearchRegularExpression := frmReplace.IsResgularExpression;
  3367. srReplaceAll := frmReplace.IsReplaceAll;
  3368. if srReplaceAll then
  3369. Options := Options + [ssoReplaceAll];
  3370. srPromptForReplace := frmReplace.IsPromptForReplace;
  3371. if srPromptForReplace then
  3372. Options := Options + [ssoPrompt];
  3373. srSearchSensitive := frmReplace.IsCaseSensitive;
  3374. if srSearchSensitive then
  3375. Options := Options + [ssoMatchCase];
  3376. srSearchWholeWords := frmReplace.IsWholeWordOnly;
  3377. if srSearchWholeWords then
  3378. Options := Options + [ssoWholeWord];
  3379. srSearchOrigin := frmReplace.GetOrigin;
  3380. if srSearchOrigin = SR_ENTIRESCOPE then
  3381. Options := Options + [ssoEntireScope];
  3382. srSearchScope := frmReplace.GetScope;
  3383. if srSearchScope = SR_SELECTED then
  3384. Options := Options + [ssoSelectedOnly];
  3385. srSearchDriection := frmReplace.GetDirection;
  3386. if srSearchDriection = SR_BACKWARD then
  3387. Options := Options + [ssoBackwards];
  3388. sSearchString := frmReplace.SearchText;
  3389. sReplaceString := frmReplace.ReplaceText;
  3390. ReplacedText.Sort;
  3391. SearchedText.Sort;
  3392. if not ReplacedText.Find(sReplaceString, Index) then
  3393. ReplacedText.Add(sReplaceString);
  3394. if not SearchedText.Find(sSearchString, Index) then
  3395. SearchedText.Add(sSearchString);
  3396. if not srSearchRegularExpression then
  3397. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearch
  3398. else
  3399. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchEngine := synMainSearchRegEx;
  3400. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SearchReplace(sSearchString, sReplaceString, Options) = 0 then
  3401. begin
  3402. Result := False;
  3403. Application.MessageBox(PChar('Search string "'+sSearchString+'" not found.'), 'LuaEdit', MB_OK+MB_ICONINFORMATION);
  3404. end;
  3405. end;
  3406. end;
  3407. procedure TfrmLuaEditMain.actFindReplaceExecute(Sender: TObject);
  3408. begin
  3409. DoFindReplaceExecute;
  3410. end;
  3411. procedure TfrmLuaEditMain.SynEditReplaceText(Sender: TObject; const ASearch, AReplace: String; Line, Column: Integer; var Action: TSynReplaceAction);
  3412. var
  3413. Pos: TPoint;
  3414. EditRect: TRect;
  3415. synEdit: TSynEdit;
  3416. begin
  3417. synEdit := TSynEdit(Sender);
  3418. if srPromptForReplace then
  3419. begin
  3420. Pos := synEdit.ClientToScreen(synEdit.RowColumnToPixels(synEdit.BufferToDisplayPos(BufferCoord(Column, Line))));
  3421. EditRect := ClientRect;
  3422. EditRect.TopLeft := ClientToScreen(EditRect.TopLeft);
  3423. EditRect.BottomRight := ClientToScreen(EditRect.BottomRight);
  3424. frmReplaceQuerry.Prepare(EditRect, Pos.X, Pos.Y, Pos.Y + synEdit.LineHeight, ASearch);
  3425. case frmReplaceQuerry.ShowModal of
  3426. mrYes: Action := raReplace;
  3427. mrYesToAll: Action := raReplaceAll;
  3428. mrNo: Action := raSkip;
  3429. else Action := raCancel;
  3430. end;
  3431. end
  3432. else if srReplaceAll then
  3433. begin
  3434. Action := raReplaceAll;
  3435. end;
  3436. end;
  3437. function TfrmLuaEditMain.DoGoToLineExecute(): Boolean;
  3438. begin
  3439. frmGotoLine.txtLineNumber.Text := '';
  3440. Result := (frmGotoLine.ShowModal = mrOK);
  3441. if Result then
  3442. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GotoLineAndCenter(frmGotoLine.LineNumber);
  3443. end;
  3444. procedure TfrmLuaEditMain.actGoToLineExecute(Sender: TObject);
  3445. begin
  3446. DoGoToLineExecute;
  3447. end;
  3448. function TfrmLuaEditMain.DoGotoLastEditedExecute(): Boolean;
  3449. begin
  3450. Result := True;
  3451. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.GotoLineAndCenter(TLuaEditUnit(jvUnitBar.SelectedTab.Data).LastEditedLine);
  3452. end;
  3453. procedure TfrmLuaEditMain.actGotoLastEditedExecute(Sender: TObject);
  3454. begin
  3455. DoGotoLastEditedExecute;
  3456. end;
  3457. procedure TfrmLuaEditMain.AboutLuaEdit1Click(Sender: TObject);
  3458. begin
  3459. frmAbout.ShowModal;
  3460. end;
  3461. // This function manage debug actions in general and handle initialization of debug session
  3462. procedure TfrmLuaEditMain.CustomExecute(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer; FuncName: string; const Args: array of string; Results: TStrings);
  3463. var
  3464. L: Plua_State;
  3465. FileName: string;
  3466. x, NArgs: Integer;
  3467. pLuaEditDebugFile: TLuaEditDebugFile;
  3468. iDoLuaOpen: Boolean;
  3469. pStackMarker: TBreakInfo;
  3470. pMessageParentNode: PVirtualNode;
  3471. procedure OpenLibs(L: PLua_State; LuaEditDebugFile: TLuaEditDebugFile);
  3472. begin
  3473. // Register regular lua libraries according to settings
  3474. if AutoLoadLibBasic then
  3475. lua_baselibopen(L);
  3476. if AutoLoadLibPackage then
  3477. lua_packlibopen(L);
  3478. if AutoLoadLibTable then
  3479. lua_tablibopen(L);
  3480. if AutoLoadLibOSIO then
  3481. lua_iolibopen(L);
  3482. if AutoLoadLibString then
  3483. lua_strlibopen(L);
  3484. if AutoLoadLibMath then
  3485. lua_mathlibopen(L);
  3486. if AutoLoadLibDebug then
  3487. lua_dblibopen(L);
  3488. lua_settop(L, 0);
  3489. // Register LuaEdit environement if required
  3490. if LuaEditDebugFile.FileType = otLuaEditMacro then
  3491. LERegisterToLua(L);
  3492. end;
  3493. procedure UninitializeUnits;
  3494. var
  3495. x, y: Integer;
  3496. pLuaUnit: TLuaEditUnit;
  3497. begin
  3498. // Uninitialize opened units
  3499. for x := 0 to frmLuaEditMain.jvUnitBar.Tabs.Count - 1 do
  3500. begin
  3501. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.Tabs[x].Data);
  3502. pLuaUnit.DebugInfos.iCurrentLineDebug := -1;
  3503. pLuaUnit.SynUnit.Refresh;
  3504. // Reset all breakpoints hitcount to 0
  3505. for y := 0 to pLuaUnit.DebugInfos.lstBreakpoint.Count - 1 do
  3506. TBreakpoint(pLuaUnit.DebugInfos.lstBreakpoint[y]).iHitCount := 0;
  3507. end;
  3508. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  3509. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).SynUnit.Refresh;
  3510. frmBreakpoints.RefreshBreakpointList;
  3511. frmLuaEditMain.stbMain.Refresh;
  3512. end;
  3513. procedure InitializeUnits;
  3514. var
  3515. x, y: Integer;
  3516. pLuaUnit: TLuaEditUnit;
  3517. begin
  3518. // Initialize opened units
  3519. for x := 0 to frmLuaEditMain.jvUnitBar.Tabs.Count - 1 do
  3520. begin
  3521. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.Tabs[x].Data);
  3522. pLuaUnit.SynUnit.Modified := False;
  3523. pLuaUnit.DebugInfos.iCurrentLineDebug := -1;
  3524. pLuaUnit.DebugInfos.iLineError := -1;
  3525. pLuaUnit.SynUnit.Refresh;
  3526. // Reset all breakpoints hitcount to 0
  3527. for y := 0 to pLuaUnit.DebugInfos.lstBreakpoint.Count - 1 do
  3528. TBreakpoint(pLuaUnit.DebugInfos.lstBreakpoint[y]).iHitCount := 0;
  3529. end;
  3530. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  3531. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).SynUnit.Refresh;
  3532. frmBreakpoints.RefreshBreakpointList;
  3533. frmLuaEditMain.stbMain.Refresh;
  3534. end;
  3535. procedure SetPause(LuaEditDebugFile: TLuaEditDebugFile);
  3536. begin
  3537. if not Pause then
  3538. begin
  3539. LuaEditDebugFile.DebugInfos.iCurrentLineDebug := -1;
  3540. LuaEditDebugFile.DebugInfos.iStackMarker := -1;
  3541. {if Assigned(TfrmLuaEditMain.jvUnitBar.SelectedTab.Data) then
  3542. LuaEditDebugFile(TfrmLuaEditMain.jvUnitBar.SelectedTab.Data).SynUnit.Refresh;}
  3543. end;
  3544. Self.Pause := Pause;
  3545. Self.PauseICI := PauseICI;
  3546. Self.PauseLine := PauseLine;
  3547. Self.PauseFile := PauseFile;
  3548. end;
  3549. function Initializer(L: PLua_State): Boolean;
  3550. begin
  3551. Result := True;
  3552. if TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).PrjOwner.sInitializer <> '' then
  3553. begin
  3554. if frmLuaEditMain.ExecuteInitializer(TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).PrjOwner.sInitializer, L) < 0 then
  3555. begin
  3556. Application.MessageBox('An error occured while executing the initializer function.', 'LuaEdit', MB_OK+MB_ICONERROR);
  3557. frmLuaEditMain.CheckButtons;
  3558. FreeLibrary(hModule);
  3559. Result := False;
  3560. end;
  3561. end;
  3562. end;
  3563. procedure AppendToLuaCPATH(L: PLua_State; AppendStr: String);
  3564. var
  3565. CurrentCPATH: String;
  3566. begin
  3567. lua_getglobal(L, 'package');
  3568. lua_pushstring(L, 'cpath');
  3569. lua_gettable(L, -2);
  3570. CurrentCPATH := lua_tostring(L, -1);
  3571. CurrentCPATH := CurrentCPATH + ';' + AppendStr;
  3572. lua_pop(L, 1);
  3573. lua_pushstring(L, 'cpath');
  3574. lua_pushstring(L, PChar(CurrentCPATH));
  3575. lua_settable(L, -3);
  3576. end;
  3577. procedure AppendToLuaPATH(L: PLua_State; AppendStr: String);
  3578. var
  3579. CurrentCPATH: String;
  3580. begin
  3581. lua_getglobal(L, 'package');
  3582. lua_pushstring(L, 'path');
  3583. lua_gettable(L, -2);
  3584. CurrentCPATH := lua_tostring(L, -1);
  3585. CurrentCPATH := CurrentCPATH + ';' + AppendStr;
  3586. lua_pop(L, 1);
  3587. lua_pushstring(L, 'path');
  3588. lua_pushstring(L, PChar(CurrentCPATH));
  3589. lua_settable(L, -3);
  3590. end;
  3591. begin
  3592. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  3593. begin
  3594. pLuaEditDebugFile := TLuaEditDebugFile(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  3595. if ((pLuaEditDebugFile.PrjOwner = ActiveProject) and (ActiveProject.sTargetLuaUnit <> '[Current Unit]')) then
  3596. begin
  3597. pLuaEditDebugFile := TLuaEditDebugFile(ActiveProject.pTargetLuaUnit);
  3598. PopUpUnitToScreen(pLuaEditDebugFile.Path);
  3599. end;
  3600. end
  3601. else if Assigned(ActiveProject) then
  3602. begin
  3603. pLuaEditDebugFile := TLuaEditDebugFile(ActiveProject.pTargetLuaUnit);
  3604. PopUpUnitToScreen(pLuaEditDebugFile.Path);
  3605. end;
  3606. if Assigned(pLuaEditDebugFile) then
  3607. begin
  3608. if Running then
  3609. begin
  3610. if ((IsEdited) and (NotifyModified)) then
  3611. begin
  3612. case (Application.MessageBox(PChar('The unit "'+pLuaEditDebugFile.Path+'" has changed. Stop debugging?'), 'LuaEdit', MB_ICONINFORMATION+MB_YESNO)) of
  3613. IDYES:
  3614. begin
  3615. Running := False;
  3616. frmLuaEditMessages.Put('End of Scipt - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  3617. frmLuaEditMessages.Put('Script Terminated by User - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  3618. Exit;
  3619. end;
  3620. IDNO:
  3621. begin
  3622. NotifyModified := False;
  3623. end;
  3624. end;
  3625. end;
  3626. SetPause(pLuaEditDebugFile);
  3627. ReStart := True;
  3628. Exit;
  3629. end else
  3630. begin
  3631. SetPause(pLuaEditDebugFile);
  3632. NotifyModified := False;
  3633. end;
  3634. if not DoCheckSyntaxExecute then
  3635. Exit;
  3636. iDoLuaOpen := (LuaState = nil);
  3637. if iDoLuaOpen then
  3638. LuaState := lua_open();
  3639. L := LuaState;
  3640. OpenLibs(L, pLuaEditDebugFile);
  3641. if not Initializer(L) then
  3642. begin
  3643. Running := False;
  3644. Exit;
  3645. end;
  3646. Running := True;
  3647. LuaRegister(L, 'print', lua_printex);
  3648. LuaRegister(MacroLuaState, 'io.write', lua_io_writeex);
  3649. lua_sethook(L, HookCaller, HOOK_MASK, 0);
  3650. CurrentICI := 1;
  3651. frmLuaEditMain.CheckButtons;
  3652. frmProfiler.InitProfiler;
  3653. // Initialize LUA_CPATH global for require system
  3654. AppendToLuaCPATH(L, PChar(GetLuaEditInstallPath()+'\lua5.1.dll'));
  3655. // Initializing project's settings if required
  3656. if ActiveProject = pLuaEditDebugFile.PrjOwner then
  3657. begin
  3658. // Initializing runtime directory
  3659. if DirectoryExists(ActiveProject.sRuntimeDirectory) then
  3660. begin
  3661. SetCurrentDirectory(PChar(ActiveProject.sRuntimeDirectory));
  3662. AppendToLuaPATH(L, ActiveProject.sRuntimeDirectory);
  3663. end;
  3664. end;
  3665. if (Assigned(Results)) then
  3666. Results.Clear;
  3667. try
  3668. if Assigned(jvUnitBar.SelectedTab.Data) then
  3669. begin
  3670. TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).SynUnit.Refresh;
  3671. frmLuaEditMain.stbMain.Refresh;
  3672. end;
  3673. PrevFile := pLuaEditDebugFile.Path;
  3674. PrevLine := 0;
  3675. try
  3676. frmLuaEditMessages.vstLuaEditMessages.Clear;
  3677. CallStack.Clear;
  3678. PrintStack;
  3679. if TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).SynUnit.Text = '' then
  3680. Exit;
  3681. LuaLoadBuffer(L, TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).SynUnit.Text, pLuaEditDebugFile.Path);
  3682. if (FuncName <> '') then
  3683. begin
  3684. LuaPCall(L, 0, 0, 0);
  3685. lua_getglobal(L, PChar(FuncName));
  3686. if (lua_type(L, -1) <> LUA_TFUNCTION) then
  3687. raise Exception.CreateFmt('Can''t find function "%s"', [FuncName]);
  3688. NArgs := Length(Args);
  3689. for x := 0 to NArgs - 1 do
  3690. LuaPushString(L, Args[x]);
  3691. end
  3692. else
  3693. begin
  3694. NArgs := 0;
  3695. lua_newtable(L);
  3696. for x := 0 to Length(Args) - 1 do
  3697. begin
  3698. LuaPushString(L, Args[x]);
  3699. lua_rawseti(L, -2, x + 1);
  3700. end;
  3701. lua_setglobal(L, ArgIdent);
  3702. end;
  3703. {$ifdef RTASSERT} RTAssert(0, true, ' Begin Script', '', 0); {$endif}
  3704. frmLuaEditMessages.Put('Begin of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  3705. LuaPCall(L, NArgs, LUA_MULTRET, 0);
  3706. frmLuaEditMessages.Put('End of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  3707. {$ifdef RTASSERT} RTAssert(0, true, ' End Script', '', 0); {$endif}
  3708. if (Assigned(Results)) then
  3709. begin
  3710. Results.Clear;
  3711. for x := 1 to lua_gettop(L) do
  3712. Results.Add(LuaStackToStr(L, x));
  3713. end;
  3714. PrintLuaStack(L);
  3715. PrintGlobal(L, True);
  3716. PrintWatch(L);
  3717. finally
  3718. // Handle end of script de-initialization
  3719. UninitializeUnits;
  3720. if iDoLuaOpen then
  3721. begin
  3722. lua_close(L);
  3723. LuaState := nil;
  3724. end;
  3725. frmLuaStack.lstLuaStack.Clear;
  3726. frmStack.lstCallStack.Clear;
  3727. frmLuaLocals.lstLocals.Clear;
  3728. frmLuaGlobals.vstGlobals.Clear;
  3729. //CallStack.Clear;
  3730. Running := False;
  3731. Self.Pause := False;
  3732. Self.PauseICI := 0;
  3733. Self.PauseLine := -1;
  3734. Self.PauseFile := '';
  3735. CurrentICI := 1;
  3736. Application.HintHidePause := 2500;
  3737. frmLuaEditMain.CheckButtons;
  3738. FreeLibrary(hModule);
  3739. // Compute the profiler's data
  3740. frmProfiler.ComputeProfiler;
  3741. end;
  3742. except
  3743. on E: ELuaException do
  3744. begin
  3745. PopUpUnitToScreen(PrevFile);
  3746. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  3747. begin
  3748. pLuaEditDebugFile := TLuaEditDebugFile(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  3749. FileName := pLuaEditDebugFile.Path;
  3750. if (not FileExistsAbs(FileName)) then
  3751. FileName := PrevFile;
  3752. if (FileExistsAbs(FileName) and (E.Line > 0)) then
  3753. begin
  3754. pLuaEditDebugFile.DebugInfos.iLineError := E.Line;
  3755. frmLuaEditMain.jvUnitBar.SelectedTab := pLuaEditDebugFile.AssociatedTab;
  3756. pLuaEditDebugFile.SynUnit.GotoLineAndCenter(E.Line);
  3757. end;
  3758. end;
  3759. if (E.Msg <> 'STOP') then
  3760. begin
  3761. stbMain.Panels[5].Text := '[ERROR]: '+E.Msg+' ('+IntToStr(E.Line)+') - '+DateTimeToStr(Now);
  3762. pMessageParentNode := frmLuaEditMessages.Put(E.Msg + ' (' + IntToStr(E.Line) + ') - ' + DateTimeToStr(Now), LUAEDIT_ERROR_MSG, Self.PrevFile, E.Line);
  3763. // Add call stack if stack trace setting is set to true...
  3764. if ShowStackTraceOnError then
  3765. begin
  3766. for x := CallStack.Count - 1 downto 0 do
  3767. begin
  3768. pStackMarker := TBreakInfo(CallStack.Items[x]);
  3769. frmLuaEditMessages.PutChild(pMessageParentNode, pStackMarker.Call, LUAEDIT_UNKNOW_MSG, pStackMarker.FileName, pStackMarker.Line);
  3770. end;
  3771. end;
  3772. frmLuaEditMessages.Put('End of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  3773. raise;
  3774. end;
  3775. UninitializeUnits;
  3776. end;
  3777. end;
  3778. end;
  3779. end;
  3780. procedure TfrmLuaEditMain.ExecuteCurrent(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer);
  3781. begin
  3782. CustomExecute(Pause, PauseICI, PauseFile, PauseLine, '', [], nil);
  3783. end;
  3784. function TfrmLuaEditMain.DoRunScriptExecute(): Boolean;
  3785. begin
  3786. Result := True;
  3787. ExecuteCurrent(False, 0, '', -1);
  3788. end;
  3789. procedure TfrmLuaEditMain.actRunScriptExecute(Sender: TObject);
  3790. begin
  3791. DoRunScriptExecute;
  3792. end;
  3793. {The Lua debug library is calling us every time before executing AR.currentline.
  3794. That means that the first line will get hook but only if AR.what='main' and
  3795. AR.currentline=-1 and AR.event=0. It also means that it will call us on the last
  3796. execution with AR.what='main' and AR.event=0}
  3797. procedure TfrmLuaEditMain.CallHookFunc(L: Plua_State; AR: Plua_Debug);
  3798. var
  3799. pBreakInfo: TBreakInfo;
  3800. pLuaEditDebugFile: TLuaEditDebugFile;
  3801. MemUsage: Double;
  3802. procedure Update;
  3803. var
  3804. NextFile: string;
  3805. NextLine: Integer;
  3806. LuaEditDebugFile: TLuaEditDebugFile;
  3807. begin
  3808. if FileExistsAbs(StringReplace(AR.source, '@', '',[])) then
  3809. NextFile := ExpandUNCFileName(StringReplace(AR.source, '@', '',[]))
  3810. else
  3811. NextFile := StringReplace(AR.source, '@', '',[]);
  3812. NextLine := AR.currentline;
  3813. if (PrevFile <> NextFile) then
  3814. begin
  3815. LuaEditDebugFile := TLuaEditDebugFile(GetOpenedFile(PrevFile));
  3816. if Assigned(LuaEditDebugFile) then
  3817. LuaEditDebugFile.DebugInfos.iCurrentLineDebug := -1;
  3818. PrevFile := NextFile;
  3819. end;
  3820. LuaEditDebugFile := TLuaEditDebugFile(PopUpUnitToScreen(NextFile, -1, True));
  3821. LuaEditDebugFile.DebugInfos.iCurrentLineDebug := NextLine;
  3822. LuaEditDebugFile.SynUnit.CaretY := NextLine;
  3823. LuaEditDebugFile.SynUnit.EnsureCursorPosVisibleEx(True);
  3824. LuaEditDebugFile.SynUnit.Refresh;
  3825. ////////////////////////////////////////////////////////////////////////////
  3826. // NOTE: The globals are now updated when clicking on the global's window
  3827. ////////////////////////////////////////////////////////////////////////////
  3828. PrintLuaStack(L);
  3829. PrintStack;
  3830. PrintLocal(L);
  3831. PrintGlobal(L, True);
  3832. PrintWatch(L);
  3833. end;
  3834. procedure WaitReStart;
  3835. var
  3836. sUnitName: String;
  3837. begin
  3838. // Get current call level
  3839. CurrentICI := AR.i_ci;
  3840. // NOTE: this condition has been added because when the unit is new,
  3841. // ExpandUNCFileName must not be used to avoid bugging
  3842. // Bug fixed the 02/06/2005 by Jean-Francois Goulet
  3843. if FileExistsAbs(StringReplace(AR.source, '@', '',[])) then
  3844. sUnitName := ExpandUNCFileName(StringReplace(AR.source, '@', '',[]))
  3845. else
  3846. sUnitName := StringReplace(AR.source, '@', '',[]);
  3847. // Get line break status
  3848. Pause := Pause or IsBreak(sUnitName, AR.currentline) or IsICI(CurrentICI);
  3849. ReStart := not Pause;
  3850. // Reset a few variables if we are going to break
  3851. if (Pause) then
  3852. begin
  3853. Pause := False;
  3854. PauseICI := 0;
  3855. PauseLine := -1;
  3856. PauseFile := '';
  3857. end;
  3858. PrevLine := AR.currentline - 1;
  3859. // Update debug informations only if we are going to break
  3860. if not Restart then
  3861. Update;
  3862. repeat
  3863. // Always process messages while in the waiting loop (even if not hanging in
  3864. // loop because it's running) to avoid output freezes
  3865. // Bug fixed the 10/09/2005 by Jean-Francois Goulet
  3866. Application.ProcessMessages;
  3867. // Only slow down processor if we really have to wait
  3868. // if we don't we have major poor performances
  3869. // Bug fixed the 02/06/2005 by Jean-Francois Goulet
  3870. if not ReStart then
  3871. Sleep(20);
  3872. // Quit loop if user pressed stop/run
  3873. if (not Running) then
  3874. begin
  3875. lua_pushstring(L, 'STOP');
  3876. lua_error(L);
  3877. end;
  3878. until ReStart;
  3879. end;
  3880. begin
  3881. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  3882. pLuaEditDebugFile := TLuaEditDebugFile(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  3883. lua_getinfo(L, 'Snlu', AR);
  3884. case (AR.event) of
  3885. LUA_HOOKCALL:
  3886. begin
  3887. // Detecting first line of script...
  3888. if ((AR.event = LUA_HOOKCALL) and (AR.linedefined = 0) and (AR.i_ci = 1) and (AR.what = 'main') and (AR.currentline = -1)) then
  3889. begin
  3890. AR.event := LUA_HOOKLINE;
  3891. AR.currentline := 1;
  3892. WaitReStart;
  3893. end
  3894. else
  3895. begin
  3896. // Adding to CallStack...
  3897. pBreakInfo := TBreakInfo.Create;
  3898. // Special handling for main call
  3899. if CAllStack.Count = 0 then
  3900. begin
  3901. pBreakInfo.LineOut := IntToStr(AR.currentline);
  3902. PrevLine := AR.currentline - 1;
  3903. end
  3904. else
  3905. pBreakInfo.LineOut := IntToStr(PrevLine + 1);
  3906. if AR.what <> 'C' then
  3907. begin
  3908. pBreakInfo.FileName := pLuaEditDebugFile.Path;
  3909. pBreakInfo.Line := PrevLine;
  3910. pBreakInfo.Call := pLuaEditDebugFile.SynUnit.Lines[PrevLine];
  3911. end
  3912. else
  3913. begin
  3914. pBreakInfo.Line := -1; // Always -1 value when external definition
  3915. pBreakInfo.FileName := '[' + AR.What + ']';
  3916. pBreakInfo.Call := '<External Call>';
  3917. end;
  3918. // Add To Call Stack List
  3919. CallStack.Insert(0, pBreakInfo);
  3920. end;
  3921. // Retrieve current memory usage by lua
  3922. MemUsage := RoundTo((lua_gc(L, LUA_GCCOUNTB, 0) / 1024) + lua_gc(L, LUA_GCCOUNT, 0), -2);
  3923. // Adding profiler infos
  3924. frmProfiler.AddCall(nil, AR.name, PrevLine + 1, AR.what, MemUsage); // Leave as last line to execute for optimal performances
  3925. end;
  3926. LUA_HOOKRET:
  3927. begin
  3928. frmProfiler.AddReturn(nil, AR.name); // Leave as first line to execute for optimal performances
  3929. // Removing from CallStack...
  3930. if CallStack.Count > 0 then
  3931. begin
  3932. TBreakInfo(CallStack.Items[0]).Free;
  3933. CallStack.Delete(0);
  3934. end;
  3935. end;
  3936. LUA_HOOKLINE:
  3937. begin
  3938. //if (not Running) then
  3939. WaitReStart;
  3940. end;
  3941. LUA_HOOKCOUNT, LUA_HOOKTAILRET:
  3942. begin
  3943. // nothing for now
  3944. end;
  3945. end;
  3946. end;
  3947. // Open the unit in the IDE if not already opened
  3948. function TfrmLuaEditMain.PopUpUnitToScreen(sFileName: String; iLine: Integer = -1; bCleanPrevUnit: Boolean = False; HighlightMode: Integer = -1): TLuaEditBasicTextFile;
  3949. var
  3950. pLuaEditBasicTextFile: TLuaEditBasicTextFile;
  3951. x: Integer;
  3952. procedure SynEditSelectExactLineText(SynEditCtrl: TSynEdit; Line: Integer);
  3953. begin
  3954. SynEditCtrl.SelLength := Length(SynEditCtrl.Lines[Line - 1]);
  3955. end;
  3956. begin
  3957. // Initialize some stuff...
  3958. Result := nil;
  3959. try
  3960. // if the current file is already the one selected then we exit this function
  3961. if Assigned(jvUnitBar.SelectedTab) then
  3962. begin
  3963. if TLuaEditFile(jvUnitBar.SelectedTab.Data).Path = sFileName then
  3964. begin
  3965. Result := TLuaEditDebugFile(jvUnitBar.SelectedTab.Data);
  3966. Exit;
  3967. end;
  3968. end;
  3969. if bCleanPrevUnit then
  3970. begin
  3971. if Assigned(jvUnitBar.SelectedTab) then
  3972. begin
  3973. if TLuaEditFile(jvUnitBar.SelectedTab).FileType in LuaEditDebugFilesTypeSet then
  3974. begin
  3975. TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).DebugInfos.iCurrentLineDebug := -1;
  3976. TLuaEditDebugFile(jvUnitBar.SelectedTab.Data).DebugInfos.iStackMarker := -1;
  3977. frmStack.lstCallStack.Items.BeginUpdate;
  3978. for x := 0 to frmStack.lstCallStack.Items.Count - 1 do
  3979. begin
  3980. if x = 0 then
  3981. frmStack.lstCallStack.Items[x].ImageIndex := 0
  3982. else
  3983. frmStack.lstCallStack.Items[x].ImageIndex := -1;
  3984. end;
  3985. frmStack.lstCallStack.Items.EndUpdate;
  3986. end;
  3987. end;
  3988. end;
  3989. // Open the file in LuaEdit if not already opened and if it does exists on the hdd
  3990. pLuaEditBasicTextFile := GetOpenedFile(sFileName);
  3991. if not Assigned(pLuaEditBasicTextFile) then
  3992. begin
  3993. if FileExistsAbs(sFileName) then
  3994. begin
  3995. pLuaEditBasicTextFile := TLuaEditBasicTextFile.Create(sFileName);
  3996. pLuaEditBasicTextFile := TLuaEditBasicTextFile(LuaSingleFiles.AddFile(sFileName, False));
  3997. pLuaEditBasicTextFile.IsLoaded := True;
  3998. frmLuaEditMain.AddFileInTab(pLuaEditBasicTextFile);
  3999. frmProjectTree.BuildProjectTree;
  4000. frmLuaEditMain.CheckButtons;
  4001. end;
  4002. end
  4003. else
  4004. frmLuaEditMain.jvUnitBar.SelectedTab := pLuaEditBasicTextFile.AssociatedTab;
  4005. // Set the file as result
  4006. Result := pLuaEditBasicTextFile;
  4007. finally
  4008. // Jump to specified line if we found the unit
  4009. if ((iLine > 0) and Assigned(Result)) then
  4010. begin
  4011. Result.SynUnit.GotoLineAndCenter(iLine);
  4012. // Highlight the specified line if required
  4013. if Result.FileType in LuaEditDebugFilesTypeSet then
  4014. begin
  4015. if HighlightMode >= 0 then
  4016. begin
  4017. case HighlightMode of
  4018. HIGHLIGHT_SELECT: SynEditSelectExactLineText(Result.SynUnit, iLine);
  4019. HIGHLIGHT_STACK: TLuaEditDebugFile(Result).DebugInfos.iStackMarker := iLine;
  4020. HIGHLIGHT_ERROR: TLuaEditDebugFile(Result).DebugInfos.iLineError := iLine;
  4021. HIGHLIGHT_BREAKLINE: TLuaEditDebugFile(Result).DebugInfos.iCurrentLineDebug := iLine;
  4022. end;
  4023. end;
  4024. end
  4025. else if Result.FileType in LuaEditTextFilesTypeSet then
  4026. begin
  4027. if HighlightMode = HIGHLIGHT_SELECT then
  4028. SynEditSelectExactLineText(Result.SynUnit, iLine);
  4029. end;
  4030. Result.synUnit.Refresh;
  4031. end;
  4032. end;
  4033. end;
  4034. // print the call stack
  4035. procedure TfrmLuaEditMain.PrintStack;
  4036. var
  4037. x: Integer;
  4038. pItem: TListItem;
  4039. begin
  4040. // Clear call stack before displaying
  4041. frmStack.lstCallStack.Clear;
  4042. frmStack.lstCallStack.Items.BeginUpdate;
  4043. // Display Stack
  4044. for x := 0 to CallStack.Count - 1 do
  4045. begin
  4046. pItem := frmStack.lstCallStack.Items.Add;
  4047. pItem.Caption := TBreakInfo(CallStack.Items[x]).FileName;
  4048. pItem.SubItems.Add(TBreakInfo(CallStack.Items[x]).Call);
  4049. pItem.SubItems.Add(TBreakInfo(CallStack.Items[x]).LineOut);
  4050. pItem.Data := CallStack.Items[x];
  4051. pItem.ImageIndex := -1;
  4052. end;
  4053. // Managing Stack breaking icons...
  4054. if frmStack.lstCallStack.Items.Count > 0 then
  4055. frmStack.lstCallStack.Items[0].ImageIndex := 0;
  4056. frmStack.lstCallStack.Items.EndUpdate;
  4057. end;
  4058. // print the lua stack
  4059. procedure TfrmLuaEditMain.PrintLuaStack(L: Plua_State);
  4060. begin
  4061. LuaStackToStrings(L, frmLuaStack.lstLuaStack.Items, MaxTablesSize, MaxSubTablesLevel, CheckCyclicReferencing);
  4062. end;
  4063. // print local list and fill the list of locals
  4064. procedure TfrmLuaEditMain.PrintLocal(L: Plua_State; Level: Integer = 0);
  4065. begin
  4066. // LuaLocalToVariables(L, frmLuaLocals.lstLocals.Items, MaxTablesSize, Level, MaxSubTablesLevel, CheckCyclicReferencing);
  4067. LuaLocalToVariables(L, lstLocals, MaxTablesSize, Level, MaxSubTablesLevel, CheckCyclicReferencing);
  4068. frmLuaLocals.FillLocalsList(lstLocals);
  4069. end;
  4070. // print global list
  4071. procedure TfrmLuaEditMain.PrintGlobal(L: Plua_State; Foce: Boolean);
  4072. begin
  4073. if (not Assigned(L)) then
  4074. Exit;
  4075. if not Foce then
  4076. Exit;
  4077. LuaTableToVirtualTreeView(L, LUA_GLOBALSINDEX, frmLuaGlobals.vstGlobals, MaxTablesSize, MaxSubTablesLevel, CheckCyclicReferencing);
  4078. LuaGlobalToVariables(L, ltGlobals, MaxTablesSize, MaxSubTablesLevel, CheckCyclicReferencing);
  4079. end;
  4080. // print watches list
  4081. procedure TfrmLuaEditMain.PrintWatch(L: Plua_State);
  4082. var
  4083. DummyVar: TLuaVariable;
  4084. x, iLen: Integer;
  4085. sSub, sValue, sLookup, sSubTable: String;
  4086. lstTable: TStringList;
  4087. IsTable: Boolean;
  4088. pNode, pChildNode, pNodeToDel: PVirtualNode;
  4089. pData, pChildData, pNewData: PWatchNodeData;
  4090. // Go through all nodes of the tree and set their ToKeep flag to false
  4091. procedure UnflagAllExpanded(pTree: TVirtualStringTree);
  4092. var
  4093. pNode: PVirtualNode;
  4094. pData: PWatchNodeData;
  4095. begin
  4096. pNode := pTree.GetFirst;
  4097. while Assigned(pNode) do
  4098. begin
  4099. pData := pTree.GetNodeData(pNode);
  4100. pData.ToKeep := False;
  4101. pNode := pTree.GetNext(pNode);
  4102. end;
  4103. end;
  4104. // Deletes all nodes for wich their ToKeep flag is still on false
  4105. procedure CleanTree(pTree: TVirtualStringTree);
  4106. var
  4107. pNode, pPrevious: PVirtualNode;
  4108. pData: PWatchNodeData;
  4109. begin
  4110. pNode := pTree.GetFirst;
  4111. while Assigned(pNode) do
  4112. begin
  4113. pData := pTree.GetNodeData(pNode);
  4114. if not pData.ToKeep then
  4115. begin
  4116. pPrevious := pTree.GetPrevious(pNode);
  4117. pTree.DeleteNode(pNode);
  4118. pNode := pPrevious;
  4119. end;
  4120. pNode := pTree.GetNext(pNode);
  4121. end;
  4122. end;
  4123. // Subroutine wich parse a string to retreive fields and tables
  4124. procedure LuaStrTableToStringList(sTable: String; pStrLst: TStrings);
  4125. var
  4126. sTemp, sName, sValue: String;
  4127. Token: Char;
  4128. iPos, iLevel: Integer;
  4129. begin
  4130. if sTable[1] = '{' then
  4131. begin
  4132. pStrLst.Clear;
  4133. sTemp := Copy(sTable, 3, Length(sTable) - 2);
  4134. iLen := Length(sTemp);
  4135. iPos := 1;
  4136. while sTemp[iPos] <> '}' do
  4137. begin
  4138. sName := '';
  4139. sValue := '';
  4140. // Retreive name part
  4141. while sTemp[iPos] <> '=' do
  4142. begin
  4143. sName := sName + sTemp[iPos];
  4144. Inc(iPos);
  4145. end;
  4146. // Retreive the value part
  4147. Inc(iPos);
  4148. Token := sTemp[iPos];
  4149. // Take different actions according to the token
  4150. case Token of
  4151. '"':
  4152. begin
  4153. sValue := sTemp[iPos];
  4154. Inc(iPos);
  4155. while sTemp[iPos] <> '"' do
  4156. begin
  4157. sValue := sValue + sTemp[iPos];
  4158. Inc(iPos);
  4159. end;
  4160. sValue := sValue + sTemp[iPos];
  4161. Inc(iPos);
  4162. end;
  4163. '{':
  4164. begin
  4165. iLevel := 1;
  4166. sValue := sTemp[iPos];
  4167. Inc(iPos);
  4168. repeat
  4169. sValue := sValue + sTemp[iPos];
  4170. if sTemp[iPos] = '{' then
  4171. Inc(iLevel);
  4172. if sTemp[iPos] = '}' then
  4173. Dec(iLevel);
  4174. Inc(iPos);
  4175. until iLevel = 0;
  4176. end;
  4177. else
  4178. begin
  4179. repeat
  4180. sValue := sValue + sTemp[iPos];
  4181. Inc(iPos);
  4182. until sTemp[iPos] = ' ';
  4183. end;
  4184. end;
  4185. // Check if the two last characters are '()'. If so, that means it's a function
  4186. // and that its actual index is the name; not the name + '()'.
  4187. if Length(sName) >= 2 then
  4188. if ((sName[Length(sName) - 1] = '(') and (sName[Length(sName)] = ')')) then
  4189. sName := Copy(sName, 1, Length(sName) - 2);
  4190. pStrLst.Values[sName] := sValue;
  4191. Inc(iPos);
  4192. end;
  4193. end;
  4194. end;
  4195. // Normalize a table indexing style a[1]["test"] -> a.[1].test
  4196. function NormalizeName(sName: String): String;
  4197. var
  4198. sTemp, sKey: String;
  4199. Dummy: Integer;
  4200. begin
  4201. Result := '';
  4202. sTemp := sName;
  4203. // Convert [] indexing style to . indexing style
  4204. while Pos('[', sTemp) <> 0 do
  4205. begin
  4206. Result := Result + Copy(sTemp, 1, Pos('[', sTemp) - 1) + '.';
  4207. sTemp := Copy(sTemp, Pos('[', sTemp) + 1, Length(sTemp) - Pos('[', sTemp));
  4208. sKey := Copy(sTemp, 1, Pos(']', sTemp) - 1);
  4209. // Convert integer indexing into [] formating for LuaEdit compatibility if required
  4210. if TryStrToInt(sKey, Dummy) then
  4211. Result := Result + '[' + Dequote(sKey) + ']'
  4212. else
  4213. Result := Result + Dequote(sKey);
  4214. sTemp := Copy(sTemp, Pos(']', sTemp) + 1, Length(sTemp) - Pos(']', sTemp));
  4215. end;
  4216. // Append rests of sTemp if any...
  4217. if sTemp <> '' then
  4218. Result := Result + sTemp;
  4219. // Return passed name if normal...
  4220. if Result = '' then
  4221. Result := sName;
  4222. end;
  4223. begin
  4224. // Initialize stuff
  4225. UnflagAllExpanded(frmWatch.vstWatch);
  4226. lstTable := TStringList.Create;
  4227. pNodeToDel := nil;
  4228. // Get first node to start
  4229. pNode := frmWatch.vstWatch.GetFirst;
  4230. // Go through all nodes
  4231. while pNode <> nil do
  4232. begin
  4233. // retreive current text and initializing some values
  4234. pData := frmWatch.vstWatch.GetNodeData(pNode);
  4235. IsTable := False;
  4236. sValue := '';
  4237. // A variable name must be assigned in order to make an association
  4238. if pData.Name <> '' then
  4239. begin
  4240. // Attempt to make the association
  4241. if pNode.Parent = frmWatch.vstWatch.RootNode then
  4242. begin
  4243. if ((Pos('.', pData.Name) <> 0) or (Pos('[', pData.Name) <> 0)) then
  4244. begin
  4245. IsTable := True;
  4246. // Normalize table's indexing style
  4247. sLookup := NormalizeName(pData.Name);
  4248. sSubTable := Copy(sLookup, Pos('.', sLookup) + 1, Length(sLookup) - Pos('.', sLookup));
  4249. sLookup := Copy(sLookup, 1, Pos('.', sLookup) - 1);
  4250. if sSubTable = '' then
  4251. sValue := 'nil';
  4252. end
  4253. else
  4254. sLookup := pData.Name;
  4255. // Check in locals first...
  4256. DummyVar := GetLocal(sLookup);
  4257. if Assigned(DummyVar) then
  4258. sValue := DummyVar.Value;
  4259. // Check in globals if not found in locals...
  4260. DummyVar := ltGlobals.GetAt(sLookup);
  4261. if ((sValue = '') and Assigned(DummyVar)) then
  4262. sValue := DummyVar.Value;
  4263. if sValue = '' then
  4264. sValue := 'nil';
  4265. end
  4266. else
  4267. begin
  4268. if pData.ToKeep = True then
  4269. sValue := pData.Value;
  4270. end;
  4271. if sValue <> '' then
  4272. begin
  4273. // Parse table string if it is a table and initalize any required child
  4274. if sValue[1] = '{' then
  4275. begin
  4276. // If value found and is a name is a table then we recursively search for value
  4277. if IsTable then
  4278. begin
  4279. // Initialize first item to look for
  4280. sSub := Copy(sSubTable, 1, Pos('.', sSubTable) - 1);
  4281. if sSub = '' then
  4282. sSub := sSubTable;
  4283. // Search for value/subtables in current value
  4284. while ((sValue <> 'nil') and (sSub <> '')) do
  4285. begin
  4286. if Pos('.', sSubTable) <> 0 then
  4287. sSubTable := Copy(sSubTable, Pos('.', sSubTable) + 1, Length(sSubTable) + Pos('.', sSubTable) - 1)
  4288. else
  4289. sSubTable := '';
  4290. LuaStrTableToStringList(sValue, lstTable);
  4291. sValue := lstTable.Values[sSub];
  4292. if sValue = '' then
  4293. sValue := 'nil';
  4294. sSub := Copy(sSubTable, 1, Pos('.', sSubTable) - 1);
  4295. if sSub = '' then
  4296. sSub := sSubTable;
  4297. // Find subtables in current sValue until result or not...
  4298. end;
  4299. end;
  4300. // If found value is still a table then display values/subtables...
  4301. if sValue[1] = '{' then
  4302. begin
  4303. LuaStrTableToStringList(sValue, lstTable);
  4304. pData.Value := sValue;
  4305. pData.ToKeep := True;
  4306. // Get first child
  4307. pChildNode := frmWatch.vstWatch.GetFirstChild(pNode);
  4308. while pChildNode <> nil do
  4309. begin
  4310. // Get the current data of the current child
  4311. pChildData := frmWatch.vstWatch.GetNodeData(pChildNode);
  4312. if ((lstTable.Values[pChildData.Name] <> '') and (lstTable.Values[pChildData.Name] <> 'nil')) then
  4313. begin
  4314. pChildData.ToKeep := True;
  4315. pChildData.Value := lstTable.Values[pChildData.Name];
  4316. lstTable.Values[pChildData.Name] := '';
  4317. pNodeToDel := nil;
  4318. end
  4319. else
  4320. pNodeToDel := pChildNode;
  4321. // Get next sibling child
  4322. pChildNode := frmWatch.vstWatch.GetNextSibling(pChildNode);
  4323. // Delete the node if required
  4324. if Assigned(pNodeToDel) then
  4325. begin
  4326. frmWatch.vstWatch.DeleteNode(pNodeToDel);
  4327. pNodeToDel := nil;
  4328. end;
  4329. end;
  4330. // Assign child nodes
  4331. for x := 0 to lstTable.Count - 1 do
  4332. begin
  4333. if lstTable.Values[lstTable.Names[x]] <> '' then
  4334. begin
  4335. pNewData := frmWatch.vstWatch.GetNodeData(frmWatch.vstWatch.AddChild(pNode));
  4336. pNewData.ToKeep := True;
  4337. pNewData.Name := lstTable.Names[x];
  4338. pNewData.Value := lstTable.Values[pNewData.Name];
  4339. end;
  4340. end;
  4341. end
  4342. else
  4343. begin
  4344. pData.ToKeep := True;
  4345. pData.Value := sValue;
  4346. end;
  4347. end
  4348. else
  4349. begin
  4350. pData.ToKeep := True;
  4351. pData.Value := sValue;
  4352. end;
  4353. end;
  4354. end
  4355. else
  4356. pNodeToDel := pNode;
  4357. //pNode := frmWatch.vstWatch.GetNextSibling(pNode);
  4358. pNode := frmWatch.vstWatch.GetNext(pNode);
  4359. // Delete the node if required
  4360. if Assigned(pNodeToDel) then
  4361. begin
  4362. frmWatch.vstWatch.DeleteNode(pNodeToDel);
  4363. pNodeToDel := nil;
  4364. end;
  4365. end;
  4366. // Free stuff and call virtual treeview to repaint
  4367. lstTable.Free;
  4368. CleanTree(frmWatch.vstWatch);
  4369. frmWatch.vstWatch.Refresh;
  4370. end;
  4371. // check if current debug line is a break one
  4372. function TfrmLuaEditMain.IsBreak(sFileName: String; Line: Integer): Boolean;
  4373. var
  4374. pLuaUnit: TLuaEditDebugFile;
  4375. pBreakpoint: TBreakpoint;
  4376. BreakCondition: String;
  4377. // This function evaluate a breakpoint condition for lua locals
  4378. // NB: This work around is necessary since all chunk reader functions of lua (lua_dostring, lua_load, etc...)
  4379. // are beeing executed in the global scope. So to solve the problem of conditions
  4380. // returning false all the time because they refer to local variable testing
  4381. // such as...
  4382. //
  4383. // variable intialisation from lua ----> local a = 3
  4384. // condition from luaedit -------------> return a == 3
  4385. //
  4386. // ...the trick is to take all local variables of the current scope from the main debug lua state
  4387. // and setting them into the globals of a temporary lua state and testing with that temporary state afterward.
  4388. function LuaTestLocals(L: PLua_State; sCond: String): Boolean;
  4389. var
  4390. LuaStateTemp: PLua_State;
  4391. Name: PChar;
  4392. Index: Integer;
  4393. Debug: lua_Debug;
  4394. AR: Plua_Debug;
  4395. begin
  4396. Result := False;
  4397. AR := @Debug;
  4398. Index := 1;
  4399. LuaStateTemp := lua_open();
  4400. // Get activation record (AR) of local scope (so at level 0)
  4401. if (lua_getstack(L, 0, AR) = 0) then
  4402. Exit;
  4403. Name := lua_getlocal(L, AR, Index); // Get first local value and name (if any)
  4404. while (Name <> nil) do
  4405. begin
  4406. LuaPushVariant(LuaStateTemp, LuaToVariant(L, -1)); // Retrive local value from main debug state and pushes it on the stack of temporary lua state
  4407. lua_setglobal(LuaStateTemp, Name); // Set local value with the same name in global scope of temporary lua state
  4408. lua_pop(L, 1); // Pop the value of local 'Name' from the main debug state
  4409. Inc(Index); // Increment index for next local value and name (if any)
  4410. Name := lua_getlocal(L, AR, Index); // Get next local value and name (if any)
  4411. end;
  4412. // Evaluate condition in temporary state now containing globals as locals of main debug state
  4413. // NOTE: There is no need to pop the values since it's only done in a temporary state
  4414. if luaL_loadstring(LuaStateTemp, PChar('return '+sCond)) = 0 then
  4415. if lua_pcall(LuaStateTemp, 0, 1, 0) = 0 then
  4416. if lua_type(LuaStateTemp, -1) = LUA_TBOOLEAN then
  4417. Result := (lua_toboolean(LuaStateTemp, -1) = 1);
  4418. lua_close(LuaStateTemp);
  4419. end;
  4420. // This function evaluate a breakpoint condition for lua globals
  4421. function LuaTestGlobals(L: PLua_State; sCond: String): Boolean;
  4422. begin
  4423. Result := False;
  4424. if luaL_loadstring(L, PChar('return '+sCond)) = 0 then
  4425. begin
  4426. if lua_pcall(L, 0, 1, 0) = 0 then
  4427. if lua_type(L, -1) = LUA_TBOOLEAN then
  4428. Result := (lua_toboolean(L, -1) = 1);
  4429. // Pop either the return value or the error message returned by lua_pcall
  4430. lua_pop(L, 1);
  4431. end;
  4432. // Pop either the function or the error message returned by luaL_loadstring
  4433. lua_pop(L, 1);
  4434. end;
  4435. begin
  4436. Result := False;
  4437. pLuaUnit := TLuaEditDebugFile(GetOpenedFile(sFileName));
  4438. if Assigned(pLuaUnit) then
  4439. begin
  4440. if pLuaUnit.DebugInfos.IsBreakPointLine(Line) then
  4441. begin
  4442. pBreakpoint := pLuaUnit.DebugInfos.GetBreakpointAtLine(Line);
  4443. if pBreakpoint.iStatus = BKPT_ENABLED then
  4444. begin
  4445. BreakCondition := pBreakpoint.sCondition;
  4446. if BreakCondition <> '' then
  4447. begin
  4448. // Testing conditions for locals and globals (see comment above about those functions)
  4449. if LuaTestLocals(LuaState, BreakCondition) or LuaTestGlobals(LuaState, BreakCondition) then
  4450. begin
  4451. // Breakpoint hit!!!
  4452. Result := True;
  4453. end;
  4454. end
  4455. else
  4456. begin
  4457. // Breakpoint hit!!!
  4458. Result := True;
  4459. end;
  4460. end;
  4461. if Result then
  4462. begin
  4463. Inc(pBreakpoint.iHitCount);
  4464. frmBreakpoints.RefreshBreakpointList;
  4465. end;
  4466. end
  4467. else
  4468. begin
  4469. if Line = PauseLine then
  4470. begin
  4471. Result := True;
  4472. end;
  4473. end;
  4474. end;
  4475. end;
  4476. // check if it is the current call level
  4477. function TfrmLuaEditMain.IsICI(ICI: Integer): Boolean;
  4478. begin
  4479. Result := (ICI <= PauseICI);
  4480. end;
  4481. // check if the given unit was modified
  4482. function TfrmLuaEditMain.IsEdited(pIgnoreUnit: TLuaEditUnit): Boolean;
  4483. var
  4484. x: Integer;
  4485. pLuaUnit: TLuaEditUnit;
  4486. begin
  4487. Result := False;
  4488. for x := 0 to jvUnitBar.Tabs.Count - 1 do
  4489. begin
  4490. pLuaUnit := TLuaEditUnit(jvUnitBar.Tabs[x].Data);
  4491. if (pLuaUnit <> pIgnoreUnit) then
  4492. Result := Result or pLuaUnit.HasChanged;
  4493. end;
  4494. end;
  4495. procedure TfrmLuaEditMain.LuaHelp1Click(Sender: TObject);
  4496. begin
  4497. BrowseURL(PChar(GetLuaEditInstallPath() + '\Help\LuaManual\ManualIndex.html'));
  4498. end;
  4499. function TfrmLuaEditMain.DoAddWatchExecute(): Boolean;
  4500. var
  4501. pNode: PVirtualNode;
  4502. pData: PWatchNodeData;
  4503. sVarName: String;
  4504. begin
  4505. // Determine default proposed value
  4506. sVarName := 'VarName';
  4507. if Assigned(jvUnitBar.SelectedTab) then
  4508. begin
  4509. if Assigned(jvUnitBar.SelectedTab.Data) then
  4510. begin
  4511. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText <> '' then
  4512. sVarName := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText;
  4513. end;
  4514. end;
  4515. if InputQuery('Add Watch', 'Enter the name of the variable to watch:', sVarName) then
  4516. begin
  4517. frmWatch.vstWatch.RootNodeCount := frmWatch.vstWatch.RootNodeCount + 1;
  4518. pNode := frmWatch.vstWatch.GetLast;
  4519. pData := frmWatch.vstWatch.GetNodeData(pNode);
  4520. pData.Name := sVarName;
  4521. PrintWatch(frmLuaEditMain.LuaState);
  4522. end;
  4523. end;
  4524. // add selected data to watch list
  4525. procedure TfrmLuaEditMain.actAddWatchExecute(Sender: TObject);
  4526. begin
  4527. DoAddWatchExecute;
  4528. end;
  4529. function TfrmLuaEditMain.DoToggleBreakpointExecute(): Boolean;
  4530. var
  4531. iCurrentLine: Integer;
  4532. begin
  4533. Result := True;
  4534. iCurrentLine := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.CaretY;
  4535. if not TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.IsBreakPointLine(iCurrentLine) then
  4536. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.AddBreakpointAtLine(iCurrentLine)
  4537. else
  4538. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).DebugInfos.RemoveBreakpointAtLine(iCurrentLine);
  4539. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  4540. frmBreakpoints.RefreshBreakpointList;
  4541. end;
  4542. procedure TfrmLuaEditMain.actToggleBreakpointExecute(Sender: TObject);
  4543. begin
  4544. DoToggleBreakpointExecute;
  4545. end;
  4546. function TfrmLuaEditMain.DoEnableDisableBreakpoint(): Boolean;
  4547. var
  4548. pLuaUnit: TLuaEditUnit;
  4549. begin
  4550. Result := False;
  4551. if Assigned(jvUnitBar.SelectedTab) then
  4552. begin
  4553. if Assigned(jvUnitBar.SelectedTab.Data) then
  4554. begin
  4555. Result := True;
  4556. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  4557. pLuaUnit.DebugInfos.EnableDisableBreakpointAtLine(pLuaUnit.synUnit.CaretY);
  4558. pLuaUnit.synUnit.Refresh;
  4559. frmBreakpoints.RefreshBreakpointList;
  4560. end;
  4561. end;
  4562. end;
  4563. procedure TfrmLuaEditMain.actEnableDisableBreakpointExecute(Sender: TObject);
  4564. begin
  4565. DoEnableDisableBreakpoint;
  4566. end;
  4567. procedure TfrmLuaEditMain.stbMainDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
  4568. var
  4569. InflatedRect: TRect;
  4570. begin
  4571. if ((Panel.Text <> '') and (Panel.Index = 5)) then
  4572. begin
  4573. // Special handling for error messages
  4574. StatusBar.Canvas.Font.Color := clWhite;
  4575. StatusBar.Canvas.Brush.Color := $00A06A53;
  4576. StatusBar.Canvas.FillRect(Rect);
  4577. InflatedRect := Rect;
  4578. DrawText(StatusBar.Canvas.Handle, PChar(' '+Panel.Text), Length(' '+Panel.Text), InflatedRect, DT_VCENTER or DT_LEFT or DT_SINGLELINE or DT_END_ELLIPSIS);
  4579. InflateRect(InflatedRect, 1, 1);
  4580. StatusBar.Canvas.Brush.Color := clGrayText;
  4581. StatusBar.Canvas.FrameRect(Rect);
  4582. end
  4583. else
  4584. begin
  4585. // Regualar handling
  4586. StatusBar.Canvas.Font.Color := clBlack;
  4587. StatusBar.Canvas.FillRect(Rect);
  4588. StatusBar.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ' '+Panel.Text);
  4589. InflatedRect := Rect;
  4590. InflateRect(InflatedRect, 1, 1);
  4591. StatusBar.Canvas.Brush.Color := clGrayText;
  4592. StatusBar.Canvas.FrameRect(Rect);
  4593. end;
  4594. end;
  4595. procedure TfrmLuaEditMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  4596. var
  4597. x, y, Answer: Integer;
  4598. DisplayPath: String;
  4599. pFile: TLuaEditBasicTextFile;
  4600. pLuaUnit: TLuaEditUnit;
  4601. pLuaProject: TLuaEditProject;
  4602. bProjectAdded: Boolean;
  4603. frmExSaveExit: TfrmExSaveExit;
  4604. begin
  4605. {$ifdef RTASSERT} RTAssert(0, true, ' TfrmLuaEditMain.FormCloseQuery', '', 0); {$endif}
  4606. // Here we check if the user is currently debugging a unit
  4607. // If that is the case, we aware the user that he is currently debugging a file
  4608. // and that is going to stop the debugger.
  4609. if LuaOpenedFiles.Count > 0 then
  4610. begin
  4611. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  4612. if pFile.FileType in LuaEditDebugFilesTypeSet then
  4613. begin
  4614. if (Running or (TLuaEditDebugFile(pFile).DebugInfos.iCurrentLineDebug <> -1)) then
  4615. begin
  4616. if Application.MessageBox('This action will stop the debugger. Continue anyway?', 'LuaEdit', MB_YESNO+MB_ICONINFORMATION) = IDNO then
  4617. begin
  4618. CanClose := False;
  4619. Exit;
  4620. end
  4621. else
  4622. begin
  4623. actStopExecute(nil);
  4624. TLuaEditDebugFile(pFile).DebugInfos.iCurrentLineDebug := -1;
  4625. TLuaEditDebugFile(pFile).DebugInfos.iLineError := -1;
  4626. pFile.SynUnit.Refresh;
  4627. end;
  4628. end;
  4629. end;
  4630. end;
  4631. // Initialize stuff...
  4632. frmExSaveExit := nil;
  4633. // Determines closing method...
  4634. if ShowExSaveDlg then
  4635. begin
  4636. // Create form
  4637. frmExSaveExit := TfrmExSaveExit.Create(nil);
  4638. // Clearing actual list
  4639. frmExSaveExit.lstFiles.Items.Clear;
  4640. frmExSaveExit.lstFiles.MultiSelect := True;
  4641. // Adding modfied units and projects to the list
  4642. for x := 0 to LuaProjects.Count - 1 do
  4643. begin
  4644. bProjectAdded := False;
  4645. pLuaProject := LuaProjects.Items[x];
  4646. for y := 0 to pLuaProject.lstUnits.Count - 1 do
  4647. begin
  4648. pFile := TLuaEditBasicTextFile(pLuaProject.lstUnits.Items[y]);
  4649. if ((not bProjectAdded) and (pLuaProject.Name <> '[@@SingleUnits@@]') and ((pLuaProject.HasChanged) or (pLuaProject.IsNew))) then
  4650. begin
  4651. frmExSaveExit.lstFiles.AddItem(pLuaProject.Name + ' {' + DisplayPath + ')', pLuaProject);
  4652. bProjectAdded := True;
  4653. end;
  4654. if ((pFile.HasChanged) or (pFile.IsNew)) then
  4655. begin
  4656. if pLuaProject.Name = '[@@SingleUnits@@]' then
  4657. frmExSaveExit.lstFiles.AddItem(pFile.DisplayPath, pFile)
  4658. else
  4659. frmExSaveExit.lstFiles.AddItem(' ' + pFile.DisplayPath, pFile);
  4660. end;
  4661. end;
  4662. end;
  4663. // Only show dialog if anything has to be save
  4664. if frmExSaveExit.lstFiles.Count > 0 then
  4665. begin
  4666. // Pre-seleect all items as default feature
  4667. frmExSaveExit.lstFiles.SelectAll;
  4668. // if action was not canceled
  4669. case frmExSaveExit.ShowModal of
  4670. mrYes:
  4671. begin
  4672. for x := 0 to frmExSaveExit.lstFiles.Count - 1 do
  4673. begin
  4674. // Save only if it was selected by user
  4675. if frmExSaveExit.lstFiles.Selected[x] then
  4676. begin
  4677. // Determines if it is a project or a unit
  4678. if TLuaEditFile(frmExSaveExit.lstFiles.Items.Objects[x]).FileType <> otLuaEditProject then
  4679. begin
  4680. // We know its a text file...
  4681. pFile := TLuaEditBasicTextFile(frmExSaveExit.lstFiles.Items.Objects[x]);
  4682. if SaveUnitsInc then
  4683. begin
  4684. if pFile.FileType = otLuaEditUnit then
  4685. CanClose := TLuaEditUnit(pFile).SaveInc(pFile.Path)
  4686. else if pFile.FileType = otLuaEditMacro then
  4687. CanClose := TLuaEditMacro(pFile).SaveInc(pFile.Path)
  4688. else
  4689. CanClose := pFile.SaveInc(pFile.Path);
  4690. end
  4691. else
  4692. begin
  4693. if pFile.FileType = otLuaEditUnit then
  4694. CanClose := TLuaEditUnit(pFile).Save(pFile.Path)
  4695. else if pFile.FileType = otLuaEditMacro then
  4696. CanClose := TLuaEditMacro(pFile).Save(pFile.Path)
  4697. else
  4698. CanClose := pFile.Save(pFile.Path);
  4699. end;
  4700. end
  4701. else
  4702. begin
  4703. // We know its a project...
  4704. pLuaProject := TLuaEditProject(frmExSaveExit.lstFiles.Items.Objects[x]);
  4705. if SaveProjectsInc then
  4706. CanClose := pLuaProject.SaveInc(pLuaProject.Path)
  4707. else
  4708. CanClose := pLuaProject.Save(pLuaProject.Path);
  4709. end;
  4710. // if CanClose variable has been assign to false, we should quit
  4711. // the function because that means the user has canceled the action
  4712. // in a SaveAs dialog previously
  4713. if not CanClose then
  4714. Exit;
  4715. end;
  4716. end;
  4717. end;
  4718. mrCancel:
  4719. begin
  4720. // Abort closing action by assigning this variable to false
  4721. CanClose := False;
  4722. end;
  4723. end;
  4724. end;
  4725. end
  4726. else
  4727. begin
  4728. for x := 0 to LuaProjects.Count - 1 do
  4729. begin
  4730. pLuaProject := LuaProjects.Items[x];
  4731. // Look for any unit to save (new or modified)
  4732. for y := 0 to pLuaProject.lstUnits.Count - 1 do
  4733. begin
  4734. pLuaUnit := TLuaEditUnit(pLuaProject.lstUnits.Items[y]);
  4735. if ((pLuaUnit.HasChanged) or (pLuaUnit.IsNew)) then
  4736. begin
  4737. Answer := Application.MessageBox(PChar('Save changes to unit "'+pLuaUnit.Path+'"?'), 'LuaEdit', MB_YESNOCANCEL+MB_ICONQUESTION);
  4738. if Answer = IDYES then
  4739. begin
  4740. if SaveUnitsInc then
  4741. pLuaUnit.SaveInc(pLuaUnit.Path)
  4742. else
  4743. pLuaUnit.Save(pLuaUnit.Path);
  4744. end
  4745. else if Answer = IDCANCEL then
  4746. CanClose := False;
  4747. end;
  4748. end;
  4749. // check if the project has to be save (new or modified)
  4750. if (((pLuaProject.HasChanged) or (pLuaProject.IsNew)) and (pLuaProject.Name <> '[@@SingleUnits@@]')) then
  4751. begin
  4752. Answer := Application.MessageBox(PChar('Save changes to project "'+pLuaProject.Name+'"?'), 'LuaEdit', MB_YESNOCANCEL+MB_ICONQUESTION);
  4753. if Answer = IDYES then
  4754. begin
  4755. if SaveProjectsInc then
  4756. pLuaProject.SaveInc(pLuaProject.Path)
  4757. else
  4758. pLuaProject.Save(pLuaProject.Path);
  4759. end
  4760. else if Answer = IDCANCEL then
  4761. CanClose := False;
  4762. end;
  4763. end;
  4764. end;
  4765. if Assigned(frmExSaveExit) then
  4766. frmExSaveExit.Free;
  4767. // If action was not canceled
  4768. if CanClose then
  4769. begin
  4770. // Writes editor settings to make sure all settings are saved
  4771. // Note: Some settings may be changed by the user without going thtrough the
  4772. // Editor Settings window
  4773. frmEditorSettings.LoadEditorSettings;
  4774. frmEditorSettings.WriteEditorSettings;
  4775. // Backward compatibility with the ini file (versions < 3.0)
  4776. // Delete useless *.ini and *.dat files
  4777. if FileExistsAbs(GetLuaEditInstallPath()+'\LuaEdit.ini') then
  4778. begin
  4779. DeleteFile(PChar(GetLuaEditInstallPath()+'\LuaEdit.ini'));
  4780. DeleteFile(PChar(GetLuaEditInstallPath()+'\LuaEdit.dat'));
  4781. end;
  4782. jvchnNotifier.Active := False; // "Turn off" the changes notifier
  4783. SaveDockTreeToFile(ExtractFilePath(Application.ExeName) + 'LuaEdit.dck'); // saves the dockable forms positions
  4784. end;
  4785. {$ifdef RTASSERT} RTAssert(0, true, ' TfrmLuaEditMain.FormCloseQuery Done', '', 0); {$endif}
  4786. end;
  4787. function TfrmLuaEditMain.DoStepOverExecute(): Boolean;
  4788. begin
  4789. Result := True;
  4790. if (Pause) then
  4791. begin
  4792. Result := False;
  4793. Exit;
  4794. end;
  4795. ExecuteCurrent(False, CurrentICI, '', -1);
  4796. end;
  4797. procedure TfrmLuaEditMain.actStepOverExecute(Sender: TObject);
  4798. begin
  4799. DoStepOverExecute;
  4800. end;
  4801. function TfrmLuaEditMain.DoStepIntoExecute(): Boolean;
  4802. begin
  4803. Result := True;
  4804. if (Pause) then
  4805. begin
  4806. Result := False;
  4807. Exit;
  4808. end;
  4809. ExecuteCurrent(True, 0, '', -1);
  4810. end;
  4811. procedure TfrmLuaEditMain.actStepIntoExecute(Sender: TObject);
  4812. begin
  4813. DoStepIntoExecute;
  4814. end;
  4815. procedure TfrmLuaEditMain.synEditGutterClick(Sender: TObject; Button: TMouseButton; X, Y, Line: Integer; Mark: TSynEditMark);
  4816. var
  4817. iCurrentLine: Integer;
  4818. pLuaUnit: TLuaEditUnit;
  4819. begin
  4820. if X <= 14 then
  4821. begin
  4822. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  4823. iCurrentLine := pLuaUnit.synUnit.RowToLine(Line);
  4824. if not pLuaUnit.DebugInfos.IsBreakPointLine(iCurrentLine) then
  4825. pLuaUnit.DebugInfos.AddBreakpointAtLine(iCurrentLine)
  4826. else
  4827. pLuaUnit.DebugInfos.RemoveBreakpointAtLine(iCurrentLine);
  4828. pLuaUnit.synUnit.Refresh;
  4829. frmBreakpoints.RefreshBreakpointList;
  4830. end;
  4831. end;
  4832. function TfrmLuaEditMain.DoPauseExecute(): Boolean;
  4833. begin
  4834. Result := False;
  4835. if ReStart or Running then
  4836. begin
  4837. frmLuaEditMessages.Put('Script Paused by User - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  4838. Result := True;
  4839. Pause := True;
  4840. end;
  4841. end;
  4842. procedure TfrmLuaEditMain.actPauseExecute(Sender: TObject);
  4843. begin
  4844. DoPauseExecute;
  4845. end;
  4846. function TfrmLuaEditMain.DoStopExecute(): Boolean;
  4847. begin
  4848. Result := True;
  4849. if Running then
  4850. begin
  4851. frmLuaEditMessages.Put('End of Scipt - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  4852. frmLuaEditMessages.Put('Script Terminated by User - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  4853. Running := False;
  4854. end;
  4855. end;
  4856. procedure TfrmLuaEditMain.actStopExecute(Sender: TObject);
  4857. begin
  4858. DoStopExecute;
  4859. end;
  4860. function TfrmLuaEditMain.DoRunToCursorExecute(): Boolean;
  4861. begin
  4862. Result := Assigned(jvUnitBar.SelectedTab);
  4863. if Result then
  4864. ExecuteCurrent(False, 0, '', TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretY);
  4865. end;
  4866. procedure TfrmLuaEditMain.actRunToCursorExecute(Sender: TObject);
  4867. begin
  4868. DoRunToCursorExecute;
  4869. end;
  4870. procedure TfrmLuaEditMain.synEditMouseCursor(Sender: TObject; const aLineCharPos: TBufferCoord; var aCursor: TCursor);
  4871. var
  4872. DummyVar: TLuaVariable;
  4873. sWord: String;
  4874. pFile: TLuaEditBasicTextFile;
  4875. begin
  4876. if Assigned(jvUnitBar.SelectedTab) then
  4877. begin
  4878. if Assigned(jvUnitBar.SelectedTab.Data) then
  4879. begin
  4880. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  4881. // The autodisplay value feature is only available for debuggable files
  4882. if pFile.FileType in LuaEditDebugFilesTypeSet then
  4883. begin
  4884. // Make sure we're currently debugging
  4885. if (Running and (TLuaEditDebugFile(pFile).DebugInfos.iCurrentLineDebug <> -1)) then
  4886. begin
  4887. // Make sure the cursor is in a "ok" location
  4888. if aLineCharPos.Line <= pFile.SynUnit.Lines.Count - 1 then
  4889. begin
  4890. if aLineCharPos.Char <= Length(pFile.SynUnit.Lines[aLineCharPos.Line - 1]) - 1 then
  4891. begin
  4892. // Find the word under the cursor if any
  4893. sWord := pFile.SynUnit.GetWordAtRowCol(aLineCharPos);
  4894. if sWord <> '' then
  4895. begin
  4896. // Find the "local" value associated to that word if any
  4897. DummyVar := GetLocal(sWord);
  4898. // If not found in locals, we find the "global" value associated to that word if any
  4899. if not Assigned(DummyVar) then
  4900. DummyVar := ltGlobals.GetAt(sWord);
  4901. if Assigned(DummyVar) then
  4902. begin
  4903. if pFile.SynUnit.Hint <> sWord + '=' + DummyVar.Value then
  4904. begin
  4905. Application.CancelHint;
  4906. end;
  4907. pFile.SynUnit.Hint := sWord + '=' + DummyVar.Value;
  4908. end
  4909. else
  4910. pFile.SynUnit.Hint := '';
  4911. end
  4912. else
  4913. pFile.SynUnit.Hint := '';
  4914. end
  4915. else
  4916. pFile.SynUnit.Hint := '';
  4917. end
  4918. else
  4919. pFile.SynUnit.Hint := '';
  4920. end
  4921. else
  4922. pFile.SynUnit.Hint := '';
  4923. end;
  4924. end;
  4925. end;
  4926. end;
  4927. procedure TfrmLuaEditMain.synEditScroll(Sender: TObject; ScrollBar: TScrollBarKind);
  4928. var
  4929. pFile: TLuaEditBasicTextFile;
  4930. begin
  4931. if Assigned(jvUnitBar.SelectedTab.Data) then
  4932. begin
  4933. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  4934. // Reset line painting variables
  4935. if pFile.FileType in LuaEditDebugFilesTypeSet then
  4936. begin
  4937. TLuaEditDebugFile(pFile).DebugInfos.iLineError := -1;
  4938. TLuaEditDebugFile(pFile).DebugInfos.iStackMarker := -1;
  4939. end;
  4940. stbMain.Panels[5].Text := '';
  4941. pFile.SynUnit.Refresh;
  4942. end;
  4943. end;
  4944. procedure TfrmLuaEditMain.synEditSpecialLineColors(Sender: TObject; Line: Integer; var Special: Boolean; var FG, BG: TColor);
  4945. var
  4946. pFile: TLuaEditBasicTextFile;
  4947. begin
  4948. if Assigned(jvUnitBar.SelectedTab) then
  4949. begin
  4950. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  4951. Special := False;
  4952. if pFile.FileType in LuaEditDebugFilesTypeSet then
  4953. begin
  4954. if TLuaEditDebugFile(pFile).DebugInfos.IsBreakPointLine(Line) then
  4955. begin
  4956. Special := True;
  4957. BG := StringToColor(TEditorColors(EditorColors.Items[9]).Background);
  4958. FG := StringToColor(TEditorColors(EditorColors.Items[9]).Foreground);
  4959. end;
  4960. if TLuaEditDebugFile(pFile).DebugInfos.iCurrentLineDebug = Line then
  4961. begin
  4962. Special := True;
  4963. BG := StringToColor(TEditorColors(EditorColors.Items[3]).Background);
  4964. FG := StringToColor(TEditorColors(EditorColors.Items[3]).Foreground);
  4965. end;
  4966. if TLuaEditDebugFile(pFile).DebugInfos.iLineError = Line then
  4967. begin
  4968. Special := True;
  4969. BG := StringToColor(TEditorColors(EditorColors.Items[2]).Background);
  4970. FG := StringToColor(TEditorColors(EditorColors.Items[2]).Foreground);
  4971. end;
  4972. if TLuaEditDebugFile(pFile).DebugInfos.iStackMarker = Line then
  4973. begin
  4974. Special := True;
  4975. BG := clNavy;
  4976. FG := clWhite;
  4977. end;
  4978. end;
  4979. end;
  4980. end;
  4981. procedure TfrmLuaEditMain.synEditChange(Sender: TObject);
  4982. var
  4983. pFile: TLuaEditBasicTextFile;
  4984. begin
  4985. if Assigned(jvUnitBar.SelectedTab.Data) then
  4986. begin
  4987. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  4988. if pFile.SynUnit.Modified then
  4989. NotifyModified := True;
  4990. if pFile.SynUnit.Modified <> jvUnitBar.SelectedTab.Modified then
  4991. begin
  4992. if pFile.SynUnit.Modified then
  4993. begin
  4994. pFile.HasChanged := True;
  4995. jvUnitBar.SelectedTab.Modified := True;
  4996. jvUnitBar.SelectedTab.Caption := jvUnitBar.SelectedTab.Caption + '*';
  4997. stbMain.Panels[3].Text := 'Modified';
  4998. jvUnitBar.Repaint;
  4999. end
  5000. else
  5001. begin
  5002. pFile.HasChanged := False;
  5003. stbMain.Panels[3].Text := '';
  5004. jvUnitBar.SelectedTab.Modified := False;
  5005. jvUnitBar.SelectedTab.Caption := Copy(jvUnitBar.SelectedTab.Caption, 1, Length(jvUnitBar.SelectedTab.Caption) - 1);
  5006. end;
  5007. end;
  5008. if pFile.IsReadOnly then
  5009. stbMain.Panels[4].Text := 'Read Only'
  5010. else
  5011. stbMain.Panels[4].Text := '';
  5012. // Reset line painting variables and other stuff
  5013. if pFile.FileType in LuaEditDebugFilesTypeSet then
  5014. begin
  5015. TLuaEditDebugFile(pFile).DebugInfos.iLineError := -1;
  5016. TLuaEditDebugFile(pFile).DebugInfos.iStackMarker := -1;
  5017. TLuaEditDebugFile(pFile).PrevLineNumber := pFile.SynUnit.Lines.Count;
  5018. HasChangedWhileCompiled := True;
  5019. end;
  5020. stbMain.Panels[5].Text := '';
  5021. pFile.LastEditedLine := pFile.SynUnit.CaretY;
  5022. pFile.synUnit.Refresh;
  5023. frmProjectTree.vstProjectTree.Refresh;
  5024. CheckButtons();
  5025. end;
  5026. end;
  5027. procedure TfrmLuaEditMain.synEditDblClick(Sender: TObject);
  5028. const
  5029. OpeningBrackets: set of char = ['(', '[', '{', '<', '"'];
  5030. ClosingBrackets: set of char = [')', ']', '}', '>', '"'];
  5031. var
  5032. pLuaUnit: TLuaEditUnit;
  5033. pCoord: TBufferCoord;
  5034. begin
  5035. if Assigned(jvUnitBar.SelectedTab.Data) then
  5036. begin
  5037. // Get current unit and find matching bracket
  5038. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  5039. if pLuaUnit.synUnit.Text <> '' then
  5040. begin
  5041. if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1] <> '' then
  5042. begin
  5043. // Towards left
  5044. if pLuaUnit.synUnit.CaretX > 1 then
  5045. begin
  5046. if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX - 1] in OpeningBrackets then
  5047. begin
  5048. if ((FirstClickPos.Line = pLuaUnit.synUnit.CaretXY.Line) and (FirstClickPos.Char = pLuaUnit.synUnit.CaretXY.Char)) then
  5049. begin
  5050. // Get matching bracket
  5051. pCoord := pLuaUnit.synUnit.GetMatchingBracket;
  5052. // Select matching bracket if found one
  5053. if pCoord.Char <> 0 then
  5054. begin
  5055. Inc(pCoord.Char);
  5056. pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
  5057. pLuaUnit.synUnit.BlockEnd := pCoord;
  5058. end;
  5059. end;
  5060. end
  5061. else if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX - 1] in ClosingBrackets then
  5062. begin
  5063. // Get matching bracket with previous char
  5064. pCoord := pLuaUnit.synUnit.CaretXY;
  5065. Dec(pCoord.Char);
  5066. pCoord := pLuaUnit.synUnit.GetMatchingBracketEx(pCoord);
  5067. // Select matching bracket if found one
  5068. if pCoord.Char <> 0 then
  5069. begin
  5070. pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
  5071. pLuaUnit.synUnit.BlockEnd := pCoord;
  5072. end;
  5073. end;
  5074. end;
  5075. // Towards right
  5076. if pLuaUnit.synUnit.CaretX < Length(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1]) then
  5077. begin
  5078. if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX] in OpeningBrackets then
  5079. begin
  5080. if ((FirstClickPos.Line = pLuaUnit.synUnit.CaretXY.Line) and (FirstClickPos.Char = pLuaUnit.synUnit.CaretXY.Char)) then
  5081. begin
  5082. // Get matching bracket
  5083. pCoord := pLuaUnit.synUnit.GetMatchingBracket;
  5084. // Select matching bracket if found one
  5085. if pCoord.Char <> 0 then
  5086. begin
  5087. Inc(pCoord.Char);
  5088. pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
  5089. pLuaUnit.synUnit.BlockEnd := pCoord;
  5090. end;
  5091. end;
  5092. end
  5093. else if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX] in ClosingBrackets then
  5094. begin
  5095. // Get matching bracket with previous char
  5096. pCoord := pLuaUnit.synUnit.CaretXY;
  5097. Dec(pCoord.Char);
  5098. pCoord := pLuaUnit.synUnit.GetMatchingBracketEx(pCoord);
  5099. // Select matching bracket if found one
  5100. if pCoord.Char <> 0 then
  5101. begin
  5102. pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
  5103. pLuaUnit.synUnit.BlockEnd := pCoord;
  5104. end;
  5105. end;
  5106. end;
  5107. end;
  5108. end;
  5109. end;
  5110. end;
  5111. procedure TfrmLuaEditMain.synEditMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  5112. var
  5113. pLuaUnit: TLuaEditUnit;
  5114. begin
  5115. // Only if left button is down (in other words... when selecting)
  5116. if ssLeft in Shift then
  5117. begin
  5118. if Assigned(jvUnitBar.SelectedTab.Data) then
  5119. begin
  5120. // Get currently opened unit
  5121. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  5122. // Set square selection mode if Alt key is held down
  5123. if ssAlt in Shift then
  5124. pLuaUnit.synUnit.SelectionMode := smColumn
  5125. else
  5126. pLuaUnit.synUnit.SelectionMode := smNormal;
  5127. end;
  5128. end;
  5129. end;
  5130. function TfrmLuaEditMain.DoAddToPrjExecute(FilePathToAdd: String): Boolean;
  5131. var
  5132. x, NewUnit: integer;
  5133. pFile: TLuaEditBasicTextFile;
  5134. FoundMatch: Boolean;
  5135. Name, Ext: String;
  5136. begin
  5137. if FilePathToAdd = '' then
  5138. Result := (frmAddToPrj.ShowModal = mrOk)
  5139. else
  5140. Result := True;
  5141. if Result then
  5142. begin
  5143. if FilePathToAdd <> '' then
  5144. begin
  5145. TLuaEditBasicTextFile(ActiveProject.AddFile(FilePathToAdd, False)).IsLoaded := True;
  5146. ActiveProject.HasChanged := True;
  5147. end
  5148. else
  5149. begin
  5150. if frmAddToPrj.chkExisting.Checked then
  5151. begin
  5152. for x := 0 to frmAddToPrj.lstFiles.Count - 1 do
  5153. begin
  5154. TLuaEditBasicTextFile(ActiveProject.AddFile(frmAddToPrj.lstFiles.Strings[x], False)).IsLoaded := True;
  5155. ActiveProject.HasChanged := True;
  5156. end;
  5157. end
  5158. else
  5159. begin
  5160. NewUnit := 1;
  5161. if frmAddToPrj.chkNewUnit.Checked = True then
  5162. begin
  5163. Name := 'Unit';
  5164. Ext := '.lua';
  5165. end
  5166. else if frmAddToPrj.chkNewMacro.Checked = True then
  5167. begin
  5168. Name := 'Macro';
  5169. Ext := '.lmc';
  5170. end
  5171. else if frmAddToPrj.chkNewTextFile.Checked = True then
  5172. begin
  5173. Name := 'Text';
  5174. Ext := '.txt';
  5175. end;
  5176. for x := 0 to LuaOpenedFiles.Count - 1 do
  5177. begin
  5178. if TLuaEditUnit(LuaOpenedFiles.Items[x]).IsNew then
  5179. Inc(NewUnit);
  5180. end;
  5181. FoundMatch := True;
  5182. while FoundMatch do
  5183. begin
  5184. FoundMatch := False;
  5185. for x := 0 to LuaOpenedFiles.Count - 1 do
  5186. begin
  5187. if 'Unit'+IntToStr(NewUnit)+'.lua' = TLuaEditUnit(LuaOpenedFiles.Items[x]).Name then
  5188. begin
  5189. Inc(NewUnit);
  5190. FoundMatch := True;
  5191. end;
  5192. end;
  5193. end;
  5194. pFile := TLuaEditBasicTextFile(ActiveProject.AddFile('Unit'+IntToStr(NewUnit)+'.lua', True));
  5195. pFile.IsLoaded := True;
  5196. AddFileInTab(pFile);
  5197. ActiveProject.HasChanged := True;
  5198. end;
  5199. end;
  5200. end;
  5201. frmProjectTree.BuildProjectTree;
  5202. CheckButtons;
  5203. end;
  5204. procedure TfrmLuaEditMain.actAddToPrjExecute(Sender: TObject);
  5205. begin
  5206. DoAddToPrjExecute();
  5207. end;
  5208. function TfrmLuaEditMain.DoRemoveFromPrjExecute(pFileToRemove: TLuaEditFile): Boolean;
  5209. var
  5210. pFile: TLuaEditFile;
  5211. iAnswer: Integer;
  5212. bWasSaved: Boolean;
  5213. begin
  5214. Result := False;
  5215. pFile := pFileToRemove;
  5216. bWasSaved := False;
  5217. iAnswer := -1;
  5218. if Assigned(pFile) then
  5219. begin
  5220. if ((pFile.HasChanged) or (pFile.IsNew)) then
  5221. begin
  5222. iAnswer := Application.MessageBox(PChar('Save changes to file "'+pFile.DisplayPath+'"?'), 'LuaEdit', MB_ICONQUESTION+MB_YESNOCANCEL);
  5223. if iAnswer = IDYES then
  5224. begin
  5225. if SaveUnitsInc then
  5226. begin
  5227. bWasSaved := TLuaEditBasicTextFile(pFile).SaveInc(pFile.Path);
  5228. end
  5229. else
  5230. begin
  5231. bWasSaved := TLuaEditBasicTextFile(pFile).Save(pFile.Path);
  5232. end;
  5233. end
  5234. else if iAnswer = IDNO then
  5235. begin
  5236. bWasSaved := True;
  5237. end;
  5238. end;
  5239. // Make sure user didn't press the cancel button
  5240. if ((iAnswer <> IDCANCEL) and bWasSaved) then
  5241. begin
  5242. // Remove file from the opened file global list if it's in there
  5243. if LuaOpenedFiles.IndexOf(pFile) <> -1 then
  5244. begin
  5245. if Assigned(TLuaEditBasicTextFile(pFile).AssociatedTab) then
  5246. TLuaEditBasicTextFile(pFile).AssociatedTab.Free;
  5247. LuaOpenedFiles.Remove(pFile);
  5248. end;
  5249. // Remove file from project, flag project as modified and rebuild the project tree
  5250. Result := True;
  5251. ActiveProject.lstUnits.Remove(pFile);
  5252. pFile.Free;
  5253. ActiveProject.HasChanged := True;
  5254. frmProjectTree.BuildProjectTree;
  5255. end;
  5256. end;
  5257. end;
  5258. procedure TfrmLuaEditMain.actRemoveFromPrjExecute(Sender: TObject);
  5259. var
  5260. pNode: PVirtualNode;
  5261. pData: PProjectTreeData;
  5262. pFile: TLuaEditFile;
  5263. begin
  5264. pNode := frmProjectTree.vstProjectTree.GetFirstSelected();
  5265. if Assigned(pNode) then
  5266. begin
  5267. pData := frmProjectTree.vstProjectTree.GetNodeData(pNode);
  5268. pFile := pData.pLuaEditFile;
  5269. if Assigned(pFile) then
  5270. DoRemoveFromPrjExecute(pFile);
  5271. end;
  5272. end;
  5273. procedure TfrmLuaEditMain.Project1Click(Sender: TObject);
  5274. begin
  5275. CheckButtons;
  5276. end;
  5277. function TfrmLuaEditMain.GetBaseCompletionProposal: TSynCompletionProposal;
  5278. var
  5279. pNewCompletionProposal: TSynCompletionProposal;
  5280. begin
  5281. pNewCompletionProposal := TSynCompletionProposal.Create(nil);
  5282. pNewCompletionProposal.Resizeable := True;
  5283. pNewCompletionProposal.TimerInterval := 1200;
  5284. pNewCompletionProposal.NbLinesInWindow := 10;
  5285. pNewCompletionProposal.ShortCut := ShortCut(Word(' '), [ssCtrl]);
  5286. pNewCompletionProposal.TriggerChars := '.';
  5287. pNewCompletionProposal.InsertList.Add('assert');
  5288. pNewCompletionProposal.ItemList.Add('\color{clBlue}function\color{clBlack} \column{}\style{+B}assert\style{-B}(v [, message])');
  5289. pNewCompletionProposal.Options := pNewCompletionProposal.Options + [scoUsePrettyText, scoUseBuiltInTimer, scoUseInsertList, scoCaseSensitive, scoLimitToMatchedText];
  5290. pNewCompletionProposal.OnExecute := synCompletionExecute;
  5291. pNewCompletionProposal.ActivateCompletion;
  5292. Result := pNewCompletionProposal;
  5293. end;
  5294. function TfrmLuaEditMain.GetBaseParamsProposal: TSynCompletionProposal;
  5295. var
  5296. pNewCompletionProposal: TSynCompletionProposal;
  5297. begin
  5298. pNewCompletionProposal := TSynCompletionProposal.Create(nil);
  5299. pNewCompletionProposal.Resizeable := False;
  5300. pNewCompletionProposal.ShortCut := ShortCut(Word(' '), [ssCtrl, ssShift]);
  5301. pNewCompletionProposal.TriggerChars := '(';
  5302. pNewCompletionProposal.Options := [scoUsePrettyText, scoUseBuiltInTimer, scoLimitToMatchedText];
  5303. pNewCompletionProposal.OnExecute := synParamsExecute;
  5304. pNewCompletionProposal.TimerInterval := 1200;
  5305. pNewCompletionProposal.NbLinesInWindow := 10;
  5306. pNewCompletionProposal.DefaultType := ctParams;
  5307. pNewCompletionProposal.ClBackground := clInfoBk;
  5308. pNewCompletionProposal.ActivateCompletion;
  5309. Result := pNewCompletionProposal;
  5310. end;
  5311. procedure TfrmLuaEditMain.synCompletionExecute(Kind: SynCompletionType; Sender: TObject; var CurrentInput: String; var x, y: Integer; var CanExecute: Boolean);
  5312. var
  5313. pLuaUnit: TLuaEditUnit;
  5314. pFctInfo: TFctInfo;
  5315. hFileSearch: TSearchRec;
  5316. GotTable: Boolean;
  5317. sPath, sTemp, sFormatString, sFunctionName, sNestedTable: String;
  5318. sTable, sParameters, LineType, Lookup, LookupTable: String;
  5319. lstLocalTable, sFileContent: TStringList;
  5320. i, j, Index: Integer;
  5321. begin
  5322. // Initialize stuff before going
  5323. lstLocalTable := TStringList.Create;
  5324. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  5325. pLuaUnit.synCompletion.ItemList.Clear;
  5326. pLuaUnit.synCompletion.ClearList;
  5327. pLuaUnit.synCompletion.InsertList.Clear;
  5328. j := pLuaUnit.synUnit.CaretX - 1;
  5329. // Getting lookup text and lookup table at cursor
  5330. while ((Copy(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1], j, 1) <> ' ') and (Copy(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1], j, 1) <> '') and (j > 0)) do
  5331. begin
  5332. // Retreive lookup text at cursor
  5333. Lookup := Copy(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1], j, 1) + Lookup;
  5334. // Retreive lookup table at cursor if any
  5335. if ((Copy(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1], j, 1) = '.') or GotTable) then
  5336. begin
  5337. // Don't retreive first point encountered
  5338. if GotTable then
  5339. LookupTable := Copy(pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1], j, 1) + LookupTable;
  5340. GotTable := True;
  5341. end;
  5342. Dec(j);
  5343. end;
  5344. // Go through all libraries search paths
  5345. for i := 0 to LibrariesSearchPaths.Count - 1 do
  5346. begin
  5347. // Standarize the path
  5348. sPath := LibrariesSearchPaths.Strings[i];
  5349. if Copy(sPath, Length(sPath), 1) <> '\' then
  5350. sPath := sPath + '\';
  5351. // Begin file search
  5352. if FindFirst(sPath+'*.lib', faAnyFile, hFileSearch) = 0 then
  5353. begin
  5354. repeat
  5355. // Create and initialize temporary content container
  5356. sFileContent := TStringList.Create;
  5357. sFileContent.LoadFromFile(sPath+hFileSearch.Name);
  5358. // Parse content and add it to the lookup list
  5359. for j := 0 to sFileContent.Count - 1 do
  5360. begin
  5361. // Extract line type
  5362. LineType := UpperCase(Copy(sFileContent.Strings[j], Length(sFileContent.Strings[j]) - 2, 3));
  5363. sTemp := Copy(sFileContent.Strings[j], 1, Length(sFileContent.Strings[j]) - 4);
  5364. // Format line according to type
  5365. if LineType = 'FOO' then
  5366. sFormatString := '\color{clBlue}function\color{clBlack} \column{}\style{+B}'
  5367. else if LineType = 'GBL' then
  5368. sFormatString := '\color{clMaroon}global var\color{clBlack} \column{}\style{+B}'
  5369. else if LineType = 'LCL' then
  5370. sFormatString := '\color{clMaroon}local var\color{clBlack} \column{}\style{+B}'
  5371. else if LineType = 'LIB' then
  5372. sFormatString := '\color{clGreen}library\color{clBlack} \column{}\style{+B}';
  5373. // Initialize variable before starting
  5374. sParameters := '';
  5375. sFunctionName := '';
  5376. sTable := '';
  5377. sNestedTable := '';
  5378. // Determine if a table is to retreive
  5379. while ((Pos('.', sTemp) <> 0) and ((LineType = 'LCL') or (LineType = 'GBL') or (((Pos('(', sTemp) <> 0) and (Pos('.', sTemp) < Pos('(', sTemp)))))) do
  5380. begin
  5381. // Retreive table and function name
  5382. sTable := Copy(sTemp, 1, Pos('.', sTemp) - 1);
  5383. sTemp := StringReplace(sTemp, sTable + '.', '', [rfReplaceAll, rfIgnoreCase]);
  5384. if sNestedTable = '' then
  5385. sNestedTable := sTable
  5386. else
  5387. sNestedTable := sNestedTable + '.' + sTable;
  5388. // Sort list of table/nested table before doing the find call
  5389. lstLocalTable.Sort;
  5390. // Add table in table list if not already in it
  5391. if not lstLocalTable.Find(sNestedTable, Index) then
  5392. lstLocalTable.Add(sNestedTable);
  5393. end;
  5394. // Determine if parameters are to retreive
  5395. if Pos('(', sTemp) <> 0 then
  5396. sParameters := Copy(sTemp, Pos('(', sTemp) + 1, Pos(')', sTemp) - Pos('(', sTemp) - 1);
  5397. if Pos('(', sTemp) <> 0 then
  5398. sFunctionName := Copy(sTemp, 1, Pos('(', sTemp) - 1)
  5399. else
  5400. sFunctionName := sTemp;
  5401. if sFunctionName <> '' then
  5402. begin
  5403. if ((LookupTable = Copy(sNestedTable, 1, Length(Lookup))) and (LookupTable <> '')) then
  5404. begin
  5405. if ((Pos('(', sTemp) <> 0) and (LineType = 'FOO')) then
  5406. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}(' + sParameters + ')')
  5407. else
  5408. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}');
  5409. pLuaUnit.synCompletion.InsertList.Add(sFunctionName);
  5410. end
  5411. else if (Lookup = Copy(sFunctionName, 1, Length(Lookup))) and (sNestedTable = '') then
  5412. begin
  5413. if ((Pos('(', sTemp) <> 0) and (LineType = 'FOO')) then
  5414. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}(' + sParameters + ')')
  5415. else
  5416. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}');
  5417. pLuaUnit.synCompletion.InsertList.Add(sFunctionName);
  5418. end;
  5419. end;
  5420. end;
  5421. // Free temporary content container
  5422. sFileContent.Free;
  5423. until FindNext(hFileSearch) <> 0;
  5424. FindClose(hFileSearch);
  5425. end;
  5426. end;
  5427. // Local definitions
  5428. frmFunctionList.RefreshList(pLuaUnit.Path);
  5429. for i := 0 to frmFunctionList.lvwFunctions.Items.Count - 1 do
  5430. begin
  5431. pFctInfo := TFctInfo(frmFunctionList.lvwFunctions.Items[i].Data);
  5432. sTemp := pFctInfo.FctDef;
  5433. sFunctionName := '';
  5434. sParameters := '';
  5435. sTable := '';
  5436. sNestedTable := '';
  5437. // look if it is member of a table
  5438. while ((Pos('.', sTemp) <> 0) and ((Pos('(', sTemp) <> 0) and (Pos('.', sTemp) < Pos('(', sTemp)))) do
  5439. begin
  5440. // Retreive table and function name
  5441. sTable := Copy(sTemp, 1, Pos('.', sTemp) - 1);
  5442. sTemp := StringReplace(sTemp, sTable + '.', '', [rfReplaceAll, rfIgnoreCase]);
  5443. if sNestedTable = '' then
  5444. sNestedTable := sTable
  5445. else
  5446. sNestedTable := sNestedTable + '.' + sTable;
  5447. // Sort list of table/nested table before doing the find call
  5448. lstLocalTable.Sort;
  5449. // Add table in table list if not already in it
  5450. if not lstLocalTable.Find(sNestedTable, Index) then
  5451. lstLocalTable.Add(sNestedTable);
  5452. end;
  5453. // Retreive parameters and function name
  5454. sParameters := pFctInfo.Params;
  5455. sFunctionName := Copy(sTemp, 1, Pos('(', sTemp) - 1);
  5456. if sFunctionName <> '' then
  5457. begin
  5458. if ((LookupTable = Copy(sNestedTable, 1, Length(Lookup))) and (LookupTable <> '')) then
  5459. begin
  5460. if ((Pos('(', sTemp) <> 0) and (LineType = 'FOO')) then
  5461. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}(' + sParameters + ')')
  5462. else
  5463. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}');
  5464. pLuaUnit.synCompletion.InsertList.Add(sFunctionName);
  5465. end
  5466. else if (Lookup = Copy(sFunctionName, 1, Length(Lookup))) and (sNestedTable = '') then
  5467. begin
  5468. if ((Pos('(', sTemp) <> 0) and (LineType = 'FOO')) then
  5469. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}(' + sParameters + ')')
  5470. else
  5471. pLuaUnit.synCompletion.ItemList.Add(sFormatString + sFunctionName + '\style{-B}');
  5472. pLuaUnit.synCompletion.InsertList.Add(sFunctionName);
  5473. end;
  5474. end;
  5475. end;
  5476. // add all found libraries
  5477. for i := 0 to lstLocalTable.Count - 1 do
  5478. begin
  5479. if ((LookupTable = Copy(lstLocalTable.Strings[i], 1, Length(LookupTable))) and (LookupTable <> '') and (lstLocalTable.Strings[i] <> LookupTable) and (Pos('.', Copy(lstLocalTable.Strings[i], Length(Lookup) + 1, Length(lstLocalTable.Strings[i]) - Length(Lookup) + 1)) = 0)) then
  5480. begin
  5481. // Because of sub tables, retreive only last part before last point
  5482. j := Length(lstLocalTable.Strings[i]);
  5483. sTemp := '';
  5484. while ((Copy(lstLocalTable.Strings[i], j, 1) <> '.') and (j > 0)) do
  5485. begin
  5486. sTemp := Copy(lstLocalTable.Strings[i], j, 1) + sTemp;
  5487. Dec(j);
  5488. end;
  5489. pLuaUnit.synCompletion.InsertList.Add(sTemp);
  5490. pLuaUnit.synCompletion.ItemList.Add('\color{clGreen}library\color{clBlack} \column{}\style{+B}' + sTemp + '\style{-B}');
  5491. end
  5492. else if ((Lookup = Copy(lstLocalTable.Strings[i], 1, Length(Lookup))) and (Pos('.', Copy(lstLocalTable.Strings[i], Length(Lookup) + 1, Length(lstLocalTable.Strings[i]) - Length(Lookup) + 1)) = 0)) then
  5493. begin
  5494. pLuaUnit.synCompletion.InsertList.Add(Copy(lstLocalTable.Strings[i], 1, Length(lstLocalTable.Strings[i])));
  5495. pLuaUnit.synCompletion.ItemList.Add('\color{clGreen}library\color{clBlack} \column{}\style{+B}' + Copy(lstLocalTable.Strings[i], 1, Length(lstLocalTable.Strings[i])) + '\style{-B}');
  5496. end;
  5497. end;
  5498. // Free stuff before leaving
  5499. lstLocalTable.Free;
  5500. //change title
  5501. pLuaUnit.synCompletion.Title := 'LuaEdit Completion Proposal';
  5502. pLuaUnit.synCompletion.ResetAssignedList;
  5503. end;
  5504. procedure TfrmLuaEditMain.synParamsExecute(Kind: SynCompletionType; Sender: TObject; var AString: String; var x, y: Integer; var CanExecute: Boolean);
  5505. var
  5506. locline, lookup, sProposition: String;
  5507. sPath, sFunctionName, sParameters: String;
  5508. TmpX, savepos, StartX, ParenCounter: Integer;
  5509. TmpLocation, i, j: Integer;
  5510. sFileContent: TStringList;
  5511. hFileSearch: TSearchRec;
  5512. FoundMatch: Boolean;
  5513. pFctInfo: TFctInfo;
  5514. begin
  5515. // Refill the lookup list for lastest changes
  5516. FillLookUpList;
  5517. with TSynCompletionProposal(Sender).Editor do
  5518. begin
  5519. locLine := LineText;
  5520. //go back from the cursor and find the first open paren
  5521. TmpX := CaretX;
  5522. if TmpX > length(locLine) then
  5523. TmpX := length(locLine)
  5524. else dec(TmpX);
  5525. FoundMatch := False;
  5526. TmpLocation := 0;
  5527. while (TmpX > 0) and not(FoundMatch) do
  5528. begin
  5529. if LocLine[TmpX] = ',' then
  5530. begin
  5531. inc(TmpLocation);
  5532. dec(TmpX);
  5533. end else if LocLine[TmpX] = ')' then
  5534. begin
  5535. //We found a close, go till it's opening paren
  5536. ParenCounter := 1;
  5537. dec(TmpX);
  5538. while (TmpX > 0) and (ParenCounter > 0) do
  5539. begin
  5540. if LocLine[TmpX] = ')' then inc(ParenCounter)
  5541. else if LocLine[TmpX] = '(' then dec(ParenCounter);
  5542. dec(TmpX);
  5543. end;
  5544. if TmpX > 0 then dec(TmpX); //eat the open paren
  5545. end else if locLine[TmpX] = '(' then
  5546. begin
  5547. //we have a valid open paren, lets see what the word before it is
  5548. StartX := TmpX;
  5549. while (TmpX > 0) and not(locLine[TmpX] in TSynValidStringChars) do
  5550. Dec(TmpX);
  5551. if TmpX > 0 then
  5552. begin
  5553. SavePos := TmpX;
  5554. While (TmpX > 0) and (locLine[TmpX] in TSynValidStringChars+['.']) do
  5555. dec(TmpX);
  5556. inc(TmpX);
  5557. lookup := Uppercase(Copy(LocLine, TmpX, SavePos - TmpX + 1));
  5558. FoundMatch := LookupList.IndexOf(Lookup) > -1;
  5559. if not(FoundMatch) then
  5560. begin
  5561. TmpX := StartX;
  5562. dec(TmpX);
  5563. end;
  5564. end;
  5565. end else dec(TmpX)
  5566. end;
  5567. end;
  5568. CanExecute := FoundMatch;
  5569. if CanExecute then
  5570. begin
  5571. TSynCompletionProposal(Sender).Form.CurrentIndex := TmpLocation;
  5572. if Lookup <> TSynCompletionProposal(Sender).PreviousToken then
  5573. begin
  5574. TSynCompletionProposal(Sender).ItemList.Clear;
  5575. // Go through all libraries search paths
  5576. for i := 0 to LibrariesSearchPaths.Count - 1 do
  5577. begin
  5578. // Standarize the path
  5579. sPath := LibrariesSearchPaths.Strings[i];
  5580. if Copy(sPath, Length(sPath), 1) <> '\' then
  5581. sPath := sPath +'\';
  5582. // Begin file search
  5583. if FindFirst(sPath +'*.lib', faAnyFile, hFileSearch) = 0 then
  5584. begin
  5585. repeat
  5586. // Create and initialize temporary content container
  5587. sFileContent := TStringList.Create;
  5588. sFileContent.LoadFromFile(sPath+hFileSearch.Name);
  5589. // Parse content and add it to the lookup list
  5590. for j := 0 to sFileContent.Count - 1 do
  5591. begin
  5592. if UpperCase(Copy(sFileContent.Strings[j], Length(sFileContent.Strings[j]) - 2, 3)) = 'FOO' then
  5593. begin
  5594. // Retreive parameters from the list
  5595. sParameters := Copy(sFileContent.Strings[j], Pos('(', sFileContent.Strings[j]) + 1, Length(sFileContent.Strings[j]) - 4 - Pos('(', sFileContent.Strings[j]));
  5596. sFunctionName := Copy(sFileContent.Strings[j], 1, Pos('(', sFileContent.Strings[j]) - 1);
  5597. // if current function call is equal to any of these
  5598. if Lookup = UpperCase(sFunctionName) then
  5599. begin
  5600. // Format the string to be compatible with the proposition engine
  5601. if sParameters = '' then
  5602. sProposition := '* No Parameters Expected *'
  5603. else
  5604. sProposition := StringReplace(sParameters, ',', '", ", ', [rfReplaceAll, rfIgnoreCase]);
  5605. sProposition := '"(' + sProposition + '"';
  5606. TSynCompletionProposal(Sender).ItemList.Add(sProposition);
  5607. end;
  5608. end;
  5609. end;
  5610. // Free temporary content container
  5611. sFileContent.Free;
  5612. until FindNext(hFileSearch) <> 0;
  5613. FindClose(hFileSearch);
  5614. end;
  5615. end;
  5616. // looking for local definitions
  5617. for i := 0 to frmFunctionList.lvwFunctions.Items.Count - 1 do
  5618. begin
  5619. pFctInfo := TFctInfo(frmFunctionList.lvwFunctions.Items[i].Data);
  5620. sFunctionName := Copy(pFctInfo.FctDef, 1, Pos('(', pFctInfo.FctDef) - 1);
  5621. // if current function call is equal to any of these
  5622. if Lookup = UpperCase(sFunctionName) then
  5623. begin
  5624. // Format the string to be compatible with the proposition engine
  5625. if pFctInfo.Params = '' then
  5626. sProposition := '* No Parameters Expected *'
  5627. else
  5628. sProposition := StringReplace(pFctInfo.Params, ',', '", ", ', [rfReplaceAll, rfIgnoreCase]);
  5629. sProposition := '"(' + sProposition + ')"';
  5630. TSynCompletionProposal(Sender).ItemList.Add(sProposition);
  5631. end;
  5632. end;
  5633. end;
  5634. end else TSynCompletionProposal(Sender).ItemList.Clear;
  5635. end;
  5636. // Is called when form create
  5637. procedure TfrmLuaEditMain.FillLookUpList;
  5638. var
  5639. pFctInfo: TFctInfo;
  5640. sSearchPath: String;
  5641. hFileSearch: TSearchRec;
  5642. sFileContent: TStringList;
  5643. x, y: Integer;
  5644. begin
  5645. // Initialize stuff before starting
  5646. LookupList.Clear;
  5647. // Go through all libraries search paths
  5648. for x := 0 to LibrariesSearchPaths.Count - 1 do
  5649. begin
  5650. sSearchPath := LibrariesSearchPaths.Strings[x];
  5651. if sSearchPath[Length(sSearchPath)] <> '\' then
  5652. sSearchPath := sSearchPath + '\';
  5653. // Begin file search
  5654. if FindFirst(sSearchPath+'*.lib', faAnyFile, hFileSearch) = 0 then
  5655. begin
  5656. repeat
  5657. // Create and initialize temporary content container
  5658. sFileContent := TStringList.Create;
  5659. sFileContent.LoadFromFile(sSearchPath+hFileSearch.Name);
  5660. // Parse content and add it to the lookup list
  5661. for y := 0 to sFileContent.Count - 1 do
  5662. begin
  5663. if UpperCase(Copy(sFileContent.Strings[y], Length(sFileContent.Strings[y]) - 2, 3)) = 'FOO' then
  5664. LookupList.Add(Copy(sFileContent.Strings[y], 1, Pos('(', sFileContent.Strings[y]) - 1));
  5665. end;
  5666. // Free temporary content container
  5667. sFileContent.Free;
  5668. until FindNext(hFileSearch) <> 0;
  5669. FindClose(hFileSearch);
  5670. end;
  5671. end;
  5672. // Add local definitions
  5673. for x := 0 to frmFunctionList.lvwFunctions.Items.Count - 1 do
  5674. begin
  5675. pFctInfo := TFctInfo(frmFunctionList.lvwFunctions.Items[x].Data);
  5676. LookupList.Add(Copy(pFctInfo.FctDef, 1, Pos('(', pFctInfo.FctDef) - 1));
  5677. end;
  5678. end;
  5679. function TfrmLuaEditMain.DoEditorSettingsExecute(): Boolean;
  5680. begin
  5681. Result := (frmEditorSettings.ShowModal = mrOk);
  5682. end;
  5683. procedure TfrmLuaEditMain.actEditorSettingsExecute(Sender: TObject);
  5684. begin
  5685. DoEditorSettingsExecute;
  5686. end;
  5687. function TfrmLuaEditMain.DoMacroManagerExecute(): Boolean;
  5688. begin
  5689. Result := (frmMacroManager.ShowModal = mrOk);
  5690. BuildMacroList();
  5691. end;
  5692. procedure TfrmLuaEditMain.actMacroManagerExecute(Sender: TObject);
  5693. begin
  5694. DoMacroManagerExecute();
  5695. end;
  5696. // New function wich loads the settings from the registry
  5697. procedure TfrmLuaEditMain.LoadEditorSettingsFromReg;
  5698. var
  5699. pReg: TAdvanceRegistry;
  5700. begin
  5701. pReg := TAdvanceRegistry.Create();
  5702. // Reading print Settings
  5703. pReg.OpenKey('\Software\LuaEdit\PrintSetup', True);
  5704. PrintUseColor := pReg.ReadBool('UseColors', True);
  5705. PrintUseSyntax := pReg.ReadBool('UseSyntax', True);
  5706. PrintUseWrapLines := pReg.ReadBool('UseWrapLines', True);
  5707. PrintLineNumbers := pReg.ReadBool('LineNumbers', False);
  5708. PrintLineNumbersInMargin := pReg.ReadBool('LineNumbersInMargin', False);
  5709. //Reading general settings
  5710. pReg.OpenKey('\Software\LuaEdit\EditorSettings\General', True);
  5711. EditorOptions := [eoScrollPastEol, eoEnhanceHomeKey, eoTabIndent, eoHideShowScrollbars, eoScrollPastEof, eoAutoIndent];
  5712. EditorOptions := TSynEditorOptions(pReg.ReadInteger('EditorOptions', Integer(EditorOptions)));
  5713. // Remove all options we absolutly don't want to have to make sure we don't have them!
  5714. EditorOptions := EditorOptions - [eoShowSpecialChars, eoSpecialLineDefaultFg, eoNoSelection, eoDisableScrollArrows, eoDropFiles, eoNoCaret];
  5715. UndoLimit := pReg.ReadInteger('UndoLimit', 1000);
  5716. TabWidth := pReg.ReadInteger('TabWidth', 4);
  5717. AssociateFiles := pReg.ReadBool('AssociateFiles', False);
  5718. SaveBreakpoints := pReg.ReadBool('SaveBreakpoints', True);
  5719. SaveUnitsInc := pReg.ReadBool('SaveUnitsInc', False);
  5720. SaveProjectsInc := pReg.ReadBool('SaveProjectsInc', False);
  5721. ShowExSaveDlg := pReg.ReadBool('ShowExSaveDlg', True);
  5722. KeepSIFWindowOpened := pReg.ReadBool('KeepSIFWindowOpened', True);
  5723. AnimatedTabsSpeed := pReg.ReadInteger('AnimatedTabsSpeed', 1000);
  5724. jvDockVSNet.ChannelOption.HideHoldTime := AnimatedTabsSpeed;
  5725. ShowStatusBar := pReg.ReadBool('ShowStatusBar', True);
  5726. stbMain.Visible := ShowStatusBar;
  5727. HomePage := pReg.ReadString('HomePage', 'http://www.luaedit.net');
  5728. SearchPage := pReg.ReadString('SearchPage', 'http://www.google.com');
  5729. TempFolder := pReg.ReadString('TempFolder', GetLuaEditInstallPath() + '\Temp');
  5730. HistoryMaxAge := pReg.ReadInteger('HistoryMaxAge', 10);
  5731. // Loading debugger settings
  5732. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Debugger', True);
  5733. MaxTablesSize := pReg.ReadInteger('MaxTablesSize', PRINT_SIZE);
  5734. MaxSubTablesLevel := pReg.ReadInteger('MaxSubTablesLevel', SUB_TABLE_MAX);
  5735. CheckCyclicReferencing := pReg.ReadBool('CheckCyclicReferencing', True);
  5736. AutoLoadLibBasic := pReg.ReadBool('AutoLoadLibBasic', True);
  5737. AutoLoadLibPackage := pReg.ReadBool('AutoLoadLibPackage', True);
  5738. AutoLoadLibTable := pReg.ReadBool('AutoLoadLibTable', True);
  5739. AutoLoadLibString := pReg.ReadBool('AutoLoadLibString', True);
  5740. AutoLoadLibMath := pReg.ReadBool('AutoLoadLibMath', True);
  5741. AutoLoadLibOSIO := pReg.ReadBool('AutoLoadLibOSIO', True);
  5742. AutoLoadLibDebug := pReg.ReadBool('AutoLoadLibDebug', True);
  5743. ShowStackTraceOnError := pReg.ReadBool('ShowStackTraceOnError', True);
  5744. // Reading Environment settings
  5745. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Environment', True);
  5746. LibrariesSearchPaths.DelimitedText := pReg.ReadString('LibrariesSearchPaths', '"' + GetLuaEditInstallPath() + '\Libraries"');
  5747. //Reading display settings
  5748. pReg.OpenKey('\Software\LuaEdit\EditorSettings\Display', True);
  5749. ShowGutter := pReg.ReadBool('ShowGutter', True);
  5750. ShowLineNumbers := pReg.ReadBool('ShowLineNumbers', False);
  5751. LeadingZeros := pReg.ReadBool('LeadingZeros', False);
  5752. GutterWidth := pReg.ReadInteger('GutterWidth', 30);
  5753. GutterColor := pReg.ReadString('GutterColor', 'clBtnFace');
  5754. FontName := pReg.ReadString('FontName', 'Courier');
  5755. FontSize := pReg.ReadInteger('FontSize', 10);
  5756. ColorSet := pReg.ReadString('ColorSet', 'LuaEdit (TM)');
  5757. pReg.Free;
  5758. GetColorSet(ColorSet);
  5759. // Initializing settings
  5760. frmEditorSettings.LoadEditorSettings();
  5761. end;
  5762. procedure TfrmLuaEditMain.GetColorSet(sColorSet: String);
  5763. var
  5764. pColorSet: TIniFile;
  5765. pEditorColor: TEditorColors;
  5766. x: Integer;
  5767. begin
  5768. pColorSet := TIniFile.Create(GetLuaEditInstallPath()+'\Data\' + sColorSet + '.dat');
  5769. for x := EditorColors.Count - 1 downto 0 do
  5770. begin
  5771. pEditorColor := TEditorColors(EditorColors.Items[x]);
  5772. EditorColors.Remove(pEditorColor);
  5773. pEditorColor.Free;
  5774. end;
  5775. //Background
  5776. EditorColors.Add(TEditorColors.Create);
  5777. TEditorColors(EditorColors.Items[0]).Background := pColorSet.ReadString('Background', 'BackgroundColor', 'clWhite');
  5778. TEditorColors(EditorColors.Items[0]).Foreground := pColorSet.ReadString('Foreground', 'ForegroundColor', 'clWhite');
  5779. //Comment
  5780. EditorColors.Add(TEditorColors.Create);
  5781. TEditorColors(EditorColors.Items[1]).Background := pColorSet.ReadString('Comment', 'BackgroundColor', 'clWhite');
  5782. TEditorColors(EditorColors.Items[1]).Foreground := pColorSet.ReadString('Comment', 'ForegroundColor', 'clGreen');
  5783. TEditorColors(EditorColors.Items[1]).IsBold := pColorSet.ReadBool('Comment', 'IsBold', False);
  5784. TEditorColors(EditorColors.Items[1]).IsItalic := pColorSet.ReadBool('Comment', 'IsItalic', False);
  5785. TEditorColors(EditorColors.Items[1]).IsUnderline := pColorSet.ReadBool('Comment', 'IsUnderline', False);
  5786. //Error line
  5787. EditorColors.Add(TEditorColors.Create);
  5788. TEditorColors(EditorColors.Items[2]).Background := pColorSet.ReadString('Error Line', 'BackgroundColor', 'clRed');
  5789. TEditorColors(EditorColors.Items[2]).Foreground := pColorSet.ReadString('Error Line', 'ForegroundColor', 'clWhite');
  5790. //Execution line
  5791. EditorColors.Add(TEditorColors.Create);
  5792. TEditorColors(EditorColors.Items[3]).Background := pColorSet.ReadString('Execution Line', 'BackgroundColor', 'clBlue');
  5793. TEditorColors(EditorColors.Items[3]).Foreground := pColorSet.ReadString('Execution Line', 'ForegroundColor', 'clWhite');
  5794. //Identifiers
  5795. EditorColors.Add(TEditorColors.Create);
  5796. TEditorColors(EditorColors.Items[4]).Background := pColorSet.ReadString('Identifier', 'BackgroundColor', 'clWhite');
  5797. TEditorColors(EditorColors.Items[4]).Foreground := pColorSet.ReadString('Identifier', 'ForegroundColor', 'clBlack');
  5798. TEditorColors(EditorColors.Items[4]).IsBold := pColorSet.ReadBool('Identifier', 'IsBold', False);
  5799. TEditorColors(EditorColors.Items[4]).IsItalic := pColorSet.ReadBool('Identifier', 'IsItalic', False);
  5800. TEditorColors(EditorColors.Items[4]).IsUnderline := pColorSet.ReadBool('Identifier', 'IsUnderline', False);
  5801. //Numbers
  5802. EditorColors.Add(TEditorColors.Create);
  5803. TEditorColors(EditorColors.Items[5]).Background := pColorSet.ReadString('Numbers', 'BackgroundColor', 'clWhite');
  5804. TEditorColors(EditorColors.Items[5]).Foreground := pColorSet.ReadString('Numbers', 'ForegroundColor', 'clBlue');
  5805. TEditorColors(EditorColors.Items[5]).IsBold := pColorSet.ReadBool('Numbers', 'IsBold', False);
  5806. TEditorColors(EditorColors.Items[5]).IsItalic := pColorSet.ReadBool('Numbers', 'IsItalic', False);
  5807. TEditorColors(EditorColors.Items[5]).IsUnderline := pColorSet.ReadBool('Numbers', 'IsUnderline', False);
  5808. //Reserved words
  5809. EditorColors.Add(TEditorColors.Create);
  5810. TEditorColors(EditorColors.Items[6]).Background := pColorSet.ReadString('Reserved Words', 'BackgroundColor', 'clWhite');
  5811. TEditorColors(EditorColors.Items[6]).Foreground := pColorSet.ReadString('Reserved Words', 'ForegroundColor', 'clBlue');
  5812. TEditorColors(EditorColors.Items[6]).IsBold := pColorSet.ReadBool('Reserved Words', 'IsBold', False);
  5813. TEditorColors(EditorColors.Items[6]).IsItalic := pColorSet.ReadBool('Reserved Words', 'IsItalic', False);
  5814. TEditorColors(EditorColors.Items[6]).IsUnderline := pColorSet.ReadBool('Reserved Words', 'IsUnderline', False);
  5815. //Selection
  5816. EditorColors.Add(TEditorColors.Create);
  5817. TEditorColors(EditorColors.Items[7]).Background := pColorSet.ReadString('Selection', 'BackgroundColor', 'clHighlight');
  5818. TEditorColors(EditorColors.Items[7]).Foreground := pColorSet.ReadString('Selection', 'ForegroundColor', 'clBlack');
  5819. //Strings
  5820. EditorColors.Add(TEditorColors.Create);
  5821. TEditorColors(EditorColors.Items[8]).Background := pColorSet.ReadString('Strings', 'BackgroundColor', 'clWhite');
  5822. TEditorColors(EditorColors.Items[8]).Foreground := pColorSet.ReadString('Strings', 'ForegroundColor', 'clBlack');
  5823. TEditorColors(EditorColors.Items[8]).IsBold := pColorSet.ReadBool('Strings', 'IsBold', False);
  5824. TEditorColors(EditorColors.Items[8]).IsItalic := pColorSet.ReadBool('Strings', 'IsItalic', False);
  5825. TEditorColors(EditorColors.Items[8]).IsUnderline := pColorSet.ReadBool('Strings', 'IsUnderline', False);
  5826. //Breakpoints
  5827. EditorColors.Add(TEditorColors.Create);
  5828. TEditorColors(EditorColors.Items[9]).Background := pColorSet.ReadString('Valid Breakpoint', 'BackgroundColor', 'clMaroon');
  5829. TEditorColors(EditorColors.Items[9]).Foreground := pColorSet.ReadString('Valid Breakpoint', 'ForegroundColor', 'clWhite');
  5830. pColorSet.Free;
  5831. end;
  5832. // Old function wich loads the settings from luaedit.ini file
  5833. // (still there for backward compatibility)
  5834. procedure TfrmLuaEditMain.LoadEditorSettingsFromIni;
  5835. var
  5836. pIniFile: TIniFile;
  5837. begin
  5838. pIniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'LuaEdit.ini');
  5839. EditorColors.Clear;
  5840. // Reading print Settings
  5841. PrintUseColor := pIniFile.ReadBool('PrintSetup', 'UseColors', True);
  5842. PrintUseSyntax := pIniFile.ReadBool('PrintSetup', 'UseSyntax', True);
  5843. PrintUseWrapLines := pIniFile.ReadBool('PrintSetup', 'UseWrapLines', True);
  5844. PrintLineNumbers := pIniFile.ReadBool('PrintSetup', 'LineNumbers', False);
  5845. PrintLineNumbersInMargin := pIniFile.ReadBool('PrintSetup', 'LineNumbersInMargin', False);
  5846. //Reading general settings
  5847. EditorOptions := [eoScrollPastEol, eoEnhanceHomeKey, eoTabIndent, eoHideShowScrollbars, eoScrollPastEof, eoAutoIndent];
  5848. EditorOptions := TSynEditorOptions(pIniFile.ReadInteger('General', 'EditorOptions', Integer(EditorOptions)));
  5849. // Remove all options we absolutly don't want to have to make sure we don't have them!
  5850. EditorOptions := EditorOptions - [eoShowSpecialChars, eoSpecialLineDefaultFg, eoNoSelection, eoDisableScrollArrows, eoDropFiles, eoNoCaret];
  5851. UndoLimit := pIniFile.ReadInteger('General', 'UndoLimit', 1000);
  5852. TabWidth := pIniFile.ReadInteger('General', 'TabWidth', 4);
  5853. AssociateFiles := pIniFile.ReadBool('General', 'AssociateFiles', False);
  5854. SaveBreakpoints := pIniFile.ReadBool('General', 'SaveBreakpoints', True);
  5855. SaveUnitsInc := pIniFile.ReadBool('General', 'SaveUnitsInc', False);
  5856. SaveProjectsInc := pIniFile.ReadBool('General', 'SaveProjectsInc', False);
  5857. ShowExSaveDlg := pIniFile.ReadBool('General', 'ShowExSaveDlg', True);
  5858. KeepSIFWindowOpened := pIniFile.ReadBool('General', 'KeepSIFWindowOpened', True);
  5859. // Reading Environment settings
  5860. LibrariesSearchPaths.DelimitedText := pIniFile.ReadString('Environement', 'LibrariesSearchPaths', ExtractFilePath(Application.ExeName)+'Libraries');
  5861. //Reading display settings
  5862. ShowGutter := pIniFile.ReadBool('Display', 'ShowGutter', True);
  5863. ShowLineNumbers := pIniFile.ReadBool('Display', 'ShowLineNumbers', False);
  5864. LeadingZeros := pIniFile.ReadBool('Display', 'LeadingZeros', False);
  5865. GutterWidth := pIniFile.ReadInteger('Display', 'GutterWidth', 30);
  5866. GutterColor := pIniFile.ReadString('Display', 'GutterColor', 'clBtnFace');
  5867. FontName := pIniFile.ReadString('Display', 'FontName', 'Courier');
  5868. FontSize := pIniFile.ReadInteger('Display', 'FontSize', 10);
  5869. ColorSet := pIniFile.ReadString('Display', 'ColorSet', 'LuaEdit (TM)');
  5870. pIniFile.Free;
  5871. pIniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'\LuaEdit.dat');
  5872. //Background
  5873. EditorColors.Add(TEditorColors.Create);
  5874. TEditorColors(EditorColors.Items[0]).Background := pIniFile.ReadString('Background', 'BackgroundColor', 'clWhite');
  5875. //Comment
  5876. EditorColors.Add(TEditorColors.Create);
  5877. TEditorColors(EditorColors.Items[1]).Background := pIniFile.ReadString('Comment', 'BackgroundColor', 'clWhite');
  5878. TEditorColors(EditorColors.Items[1]).Foreground := pIniFile.ReadString('Comment', 'ForegroundColor', 'clGreen');
  5879. TEditorColors(EditorColors.Items[1]).IsBold := pIniFile.ReadBool('Comment', 'IsBold', False);
  5880. TEditorColors(EditorColors.Items[1]).IsItalic := pIniFile.ReadBool('Comment', 'IsItalic', False);
  5881. TEditorColors(EditorColors.Items[1]).IsUnderline := pIniFile.ReadBool('Comment', 'IsUnderline', False);
  5882. //Error line
  5883. EditorColors.Add(TEditorColors.Create);
  5884. TEditorColors(EditorColors.Items[2]).Background := pIniFile.ReadString('Error Line', 'BackgroundColor', 'clRed');
  5885. TEditorColors(EditorColors.Items[2]).Foreground := pIniFile.ReadString('Error Line', 'ForegroundColor', 'clWhite');
  5886. //Execution line
  5887. EditorColors.Add(TEditorColors.Create);
  5888. TEditorColors(EditorColors.Items[3]).Background := pIniFile.ReadString('Execution Line', 'BackgroundColor', 'clBlue');
  5889. TEditorColors(EditorColors.Items[3]).Foreground := pIniFile.ReadString('Execution Line', 'ForegroundColor', 'clWhite');
  5890. //Identifiers
  5891. EditorColors.Add(TEditorColors.Create);
  5892. TEditorColors(EditorColors.Items[4]).Background := pIniFile.ReadString('Identifier', 'BackgroundColor', 'clWhite');
  5893. TEditorColors(EditorColors.Items[4]).Foreground := pIniFile.ReadString('Identifier', 'ForegroundColor', 'clBlack');
  5894. TEditorColors(EditorColors.Items[4]).IsBold := pIniFile.ReadBool('Identifier', 'IsBold', False);
  5895. TEditorColors(EditorColors.Items[4]).IsItalic := pIniFile.ReadBool('Identifier', 'IsItalic', False);
  5896. TEditorColors(EditorColors.Items[4]).IsUnderline := pIniFile.ReadBool('Identifier', 'IsUnderline', False);
  5897. //Numbers
  5898. EditorColors.Add(TEditorColors.Create);
  5899. TEditorColors(EditorColors.Items[5]).Background := pIniFile.ReadString('Numbers', 'BackgroundColor', 'clWhite');
  5900. TEditorColors(EditorColors.Items[5]).Foreground := pIniFile.ReadString('Numbers', 'ForegroundColor', 'clBlue');
  5901. TEditorColors(EditorColors.Items[5]).IsBold := pIniFile.ReadBool('Numbers', 'IsBold', False);
  5902. TEditorColors(EditorColors.Items[5]).IsItalic := pIniFile.ReadBool('Numbers', 'IsItalic', False);
  5903. TEditorColors(EditorColors.Items[5]).IsUnderline := pIniFile.ReadBool('Numbers', 'IsUnderline', False);
  5904. //Reserved words
  5905. EditorColors.Add(TEditorColors.Create);
  5906. TEditorColors(EditorColors.Items[6]).Background := pIniFile.ReadString('Reserved Words', 'BackgroundColor', 'clWhite');
  5907. TEditorColors(EditorColors.Items[6]).Foreground := pIniFile.ReadString('Reserved Words', 'ForegroundColor', 'clBlue');
  5908. TEditorColors(EditorColors.Items[6]).IsBold := pIniFile.ReadBool('Reserved Words', 'IsBold', False);
  5909. TEditorColors(EditorColors.Items[6]).IsItalic := pIniFile.ReadBool('Reserved Words', 'IsItalic', False);
  5910. TEditorColors(EditorColors.Items[6]).IsUnderline := pIniFile.ReadBool('Reserved Words', 'IsUnderline', False);
  5911. //Selection
  5912. EditorColors.Add(TEditorColors.Create);
  5913. TEditorColors(EditorColors.Items[7]).Background := pIniFile.ReadString('Selection', 'BackgroundColor', 'clHighlight');
  5914. TEditorColors(EditorColors.Items[7]).Foreground := pIniFile.ReadString('Selection', 'ForegroundColor', 'clBlack');
  5915. //Strings
  5916. EditorColors.Add(TEditorColors.Create);
  5917. TEditorColors(EditorColors.Items[8]).Background := pIniFile.ReadString('Strings', 'BackgroundColor', 'clWhite');
  5918. TEditorColors(EditorColors.Items[8]).Foreground := pIniFile.ReadString('Strings', 'ForegroundColor', 'clNavy');
  5919. TEditorColors(EditorColors.Items[8]).IsBold := pIniFile.ReadBool('Strings', 'IsBold', False);
  5920. TEditorColors(EditorColors.Items[8]).IsItalic := pIniFile.ReadBool('Strings', 'IsItalic', False);
  5921. TEditorColors(EditorColors.Items[8]).IsUnderline := pIniFile.ReadBool('Strings', 'IsUnderline', False);
  5922. //Breakpoints
  5923. EditorColors.Add(TEditorColors.Create);
  5924. TEditorColors(EditorColors.Items[9]).Background := pIniFile.ReadString('Valid Breakpoint', 'BackgroundColor', 'clMaroon');
  5925. TEditorColors(EditorColors.Items[9]).Foreground := pIniFile.ReadString('Valid Breakpoint', 'ForegroundColor', 'clWhite');
  5926. pIniFile.Free;
  5927. end;
  5928. procedure TfrmLuaEditMain.ApplyValuesToEditor(SynTemp: TSynEdit; lstColorSheme: TList);
  5929. var
  5930. x: Integer;
  5931. TempStyle: TFontStyles;
  5932. begin
  5933. SynTemp.Options := EditorOptions;
  5934. SynTemp.TabWidth := TabWidth;
  5935. SynTemp.MaxUndo := UndoLimit;
  5936. SynTemp.Gutter.Visible := ShowGutter;
  5937. SynTemp.Gutter.LeadingZeros := LeadingZeros;
  5938. SynTemp.Gutter.ShowLineNumbers := ShowLineNumbers;
  5939. SynTemp.Gutter.Width := GutterWidth;
  5940. SynTemp.Gutter.Color := StringToColor(GutterColor);
  5941. SynTemp.Font.Name := FontName;
  5942. SynTemp.Font.Size := FontSize;
  5943. SynTemp.Color := StringToColor(TEditorColors(lstColorSheme.Items[0]).Background);
  5944. SynTemp.SelectedColor.Foreground := StringToColor(TEditorColors(lstColorSheme.Items[7]).Foreground);
  5945. SynTemp.SelectedColor.Background := StringToColor(TEditorColors(lstColorSheme.Items[7]).Background);
  5946. frmLuaEditMain.stbMain.Visible := ShowStatusBar;
  5947. if Assigned(SynTemp.Highlighter) then
  5948. begin
  5949. for x := 0 to SynTemp.Highlighter.AttrCount - 1 do
  5950. begin
  5951. TempStyle := [];
  5952. if synTemp.Highlighter.Attribute[x].Name = 'Comment' then
  5953. begin
  5954. SynTemp.Highlighter.Attribute[x].Background := StringtoColor(TEditorColors(lstColorSheme.Items[1]).Background);
  5955. SynTemp.Highlighter.Attribute[x].Foreground := StringToColor(TEditorColors(lstColorSheme.Items[1]).Foreground);
  5956. if TEditorColors(lstColorSheme.Items[1]).IsBold then
  5957. TempStyle := TempStyle + [fsBold];
  5958. if TEditorColors(lstColorSheme.Items[1]).IsItalic then
  5959. TempStyle := TempStyle + [fsItalic];
  5960. if TEditorColors(lstColorSheme.Items[1]).IsUnderline then
  5961. TempStyle := TempStyle + [fsUnderline];
  5962. SynTemp.Highlighter.Attribute[x].Style := TempStyle;
  5963. end
  5964. else if synTemp.Highlighter.Attribute[x].Name = 'Identifier' then
  5965. begin
  5966. SynTemp.Highlighter.Attribute[x].Background := StringtoColor(TEditorColors(lstColorSheme.Items[4]).Background);
  5967. SynTemp.Highlighter.Attribute[x].Foreground := StringToColor(TEditorColors(lstColorSheme.Items[4]).Foreground);
  5968. if TEditorColors(lstColorSheme.Items[4]).IsBold then
  5969. TempStyle := TempStyle + [fsBold];
  5970. if TEditorColors(lstColorSheme.Items[4]).IsItalic then
  5971. TempStyle := TempStyle + [fsItalic];
  5972. if TEditorColors(lstColorSheme.Items[4]).IsUnderline then
  5973. TempStyle := TempStyle + [fsUnderline];
  5974. SynTemp.Highlighter.Attribute[x].Style := TempStyle;
  5975. end
  5976. else if synTemp.Highlighter.Attribute[x].Name = 'Reserved Word' then
  5977. begin
  5978. SynTemp.Highlighter.Attribute[x].Background := StringtoColor(TEditorColors(lstColorSheme.Items[6]).Background);
  5979. SynTemp.Highlighter.Attribute[x].Foreground := StringToColor(TEditorColors(lstColorSheme.Items[6]).Foreground);
  5980. if TEditorColors(lstColorSheme.Items[6]).IsBold then
  5981. TempStyle := TempStyle + [fsBold];
  5982. if TEditorColors(lstColorSheme.Items[6]).IsItalic then
  5983. TempStyle := TempStyle + [fsItalic];
  5984. if TEditorColors(lstColorSheme.Items[6]).IsUnderline then
  5985. TempStyle := TempStyle + [fsUnderline];
  5986. SynTemp.Highlighter.Attribute[x].Style := TempStyle;
  5987. end
  5988. else if ((synTemp.Highlighter.Attribute[x].Name = 'String') or (synTemp.Highlighter.Attribute[x].Name = 'LuaMString')) then
  5989. begin
  5990. SynTemp.Highlighter.Attribute[x].Background := StringtoColor(TEditorColors(lstColorSheme.Items[8]).Background);
  5991. SynTemp.Highlighter.Attribute[x].Foreground := StringToColor(TEditorColors(lstColorSheme.Items[8]).Foreground);
  5992. if TEditorColors(lstColorSheme.Items[8]).IsBold then
  5993. TempStyle := TempStyle + [fsBold];
  5994. if TEditorColors(lstColorSheme.Items[8]).IsItalic then
  5995. TempStyle := TempStyle + [fsItalic];
  5996. if TEditorColors(lstColorSheme.Items[8]).IsUnderline then
  5997. TempStyle := TempStyle + [fsUnderline];
  5998. SynTemp.Highlighter.Attribute[x].Style := TempStyle;
  5999. end
  6000. else if synTemp.Highlighter.Attribute[x].Name = 'Numbers' then
  6001. begin
  6002. SynTemp.Highlighter.Attribute[x].Background := StringtoColor(TEditorColors(lstColorSheme.Items[5]).Background);
  6003. SynTemp.Highlighter.Attribute[x].Foreground := StringToColor(TEditorColors(lstColorSheme.Items[5]).Foreground);
  6004. if TEditorColors(lstColorSheme.Items[5]).IsBold then
  6005. TempStyle := TempStyle + [fsBold];
  6006. if TEditorColors(lstColorSheme.Items[5]).IsItalic then
  6007. TempStyle := TempStyle + [fsItalic];
  6008. if TEditorColors(lstColorSheme.Items[5]).IsUnderline then
  6009. TempStyle := TempStyle + [fsUnderline];
  6010. SynTemp.Highlighter.Attribute[x].Style := TempStyle;
  6011. end;
  6012. end;
  6013. end
  6014. else
  6015. begin
  6016. SynTemp.Font.Color := StringToColor(TEditorColors(lstColorSheme.Items[4]).Foreground);
  6017. end;
  6018. synTemp.Refresh;
  6019. end;
  6020. procedure TfrmLuaEditMain.GotoBookmarkClick(Sender: TObject);
  6021. var
  6022. iBookmark: Integer;
  6023. begin
  6024. iBookmark := TMenuItem(Sender).Tag;
  6025. if iBookmark = 1 then
  6026. begin
  6027. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker1, #0, nil);
  6028. end
  6029. else if iBookmark = 2 then
  6030. begin
  6031. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker2, #0, nil);
  6032. end
  6033. else if iBookmark = 3 then
  6034. begin
  6035. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker3, #0, nil);
  6036. end
  6037. else if iBookmark = 4 then
  6038. begin
  6039. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker4, #0, nil);
  6040. end
  6041. else if iBookmark = 5 then
  6042. begin
  6043. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker5, #0, nil);
  6044. end
  6045. else if iBookmark = 6 then
  6046. begin
  6047. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker6, #0, nil);
  6048. end
  6049. else if iBookmark = 7 then
  6050. begin
  6051. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker7, #0, nil);
  6052. end
  6053. else if iBookmark = 8 then
  6054. begin
  6055. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker8, #0, nil);
  6056. end
  6057. else if iBookmark = 9 then
  6058. begin
  6059. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker9, #0, nil);
  6060. end
  6061. else if iBookmark = 0 then
  6062. begin
  6063. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecGotoMarker0, #0, nil);
  6064. end;
  6065. end;
  6066. procedure TfrmLuaEditMain.ToggleBookmarkClick(Sender: TObject);
  6067. var
  6068. iBookmark: Integer;
  6069. begin
  6070. iBookmark := TMenuItem(Sender).Tag;
  6071. if iBookmark = 1 then
  6072. begin
  6073. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker1, #0, nil);
  6074. end
  6075. else if iBookmark = 2 then
  6076. begin
  6077. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker2, #0, nil);
  6078. end
  6079. else if iBookmark = 3 then
  6080. begin
  6081. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker3, #0, nil);
  6082. end
  6083. else if iBookmark = 4 then
  6084. begin
  6085. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker4, #0, nil);
  6086. end
  6087. else if iBookmark = 5 then
  6088. begin
  6089. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker5, #0, nil);
  6090. end
  6091. else if iBookmark = 6 then
  6092. begin
  6093. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker6, #0, nil);
  6094. end
  6095. else if iBookmark = 7 then
  6096. begin
  6097. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker7, #0, nil);
  6098. end
  6099. else if iBookmark = 8 then
  6100. begin
  6101. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker8, #0, nil);
  6102. end
  6103. else if iBookmark = 9 then
  6104. begin
  6105. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker9, #0, nil);
  6106. end
  6107. else if iBookmark = 0 then
  6108. begin
  6109. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecSetMarker0, #0, nil);
  6110. end;
  6111. end;
  6112. procedure TfrmLuaEditMain.RegistryEditor1Click(Sender: TObject);
  6113. begin
  6114. ShellExecute(Self.Handle, 'open', 'regedit', nil, nil, SW_SHOWNORMAL);
  6115. end;
  6116. procedure TfrmLuaEditMain.Calculator1Click(Sender: TObject);
  6117. begin
  6118. ShellExecute(Self.Handle, 'open', 'calc', nil, nil, SW_SHOWNORMAL);
  6119. end;
  6120. procedure TfrmLuaEditMain.Conversions1Click(Sender: TObject);
  6121. begin
  6122. ShellExecute(Self.Handle, 'open', PChar(ExtractFilePath(Application.ExeName) + '\Convert.exe'), nil, nil, SW_SHOWNORMAL);
  6123. end;
  6124. function TfrmLuaEditMain.DoBlockUnindentExecute(): Boolean;
  6125. begin
  6126. Result := True;
  6127. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecBlockUnindent, #0, nil);
  6128. end;
  6129. procedure TfrmLuaEditMain.actBlockUnindentExecute(Sender: TObject);
  6130. begin
  6131. DoBlockUnindentExecute;
  6132. end;
  6133. function TfrmLuaEditMain.DoBlockIndentExecute(): Boolean;
  6134. begin
  6135. Result := True;
  6136. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.ExecuteCommand(ecBlockIndent, #0, nil);
  6137. end;
  6138. procedure TfrmLuaEditMain.actBlockIndentExecute(Sender: TObject);
  6139. begin
  6140. DoBlockIndentExecute;
  6141. end;
  6142. function TfrmLuaEditMain.DoBlockCommentExecute(): Boolean;
  6143. var
  6144. pLuaUnit: TLuaEditUnit;
  6145. x, SelStart, SelEnd, AddedChars: Integer;
  6146. UndoStart, UndoEnd: TBufferCoord;
  6147. begin
  6148. Result := False;
  6149. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6150. // Retrieve selection
  6151. SelStart := pLuaUnit.synUnit.SelStart;
  6152. SelEnd := pLuaUnit.synUnit.SelEnd;
  6153. pLuaUnit.synUnit.BeginUndoBlock;
  6154. AddedChars := 0;
  6155. for x := pLuaUnit.synUnit.BlockBegin.Line - 1 to pLuaUnit.synUnit.BlockEnd.Line - 1 do
  6156. begin
  6157. Result := True;
  6158. // Commenting line
  6159. pLuaUnit.synUnit.Lines.Strings[x] := '--' + pLuaUnit.synUnit.Lines.Strings[x];
  6160. pLuaUnit.synUnit.Modified := True;
  6161. pLuaUnit.synUnit.OnChange(pLuaUnit.synUnit);
  6162. AddedChars := AddedChars + 2;
  6163. // Notify change to synedit's undo list
  6164. UndoStart.Char := 1;
  6165. UndoStart.Line := x+1;
  6166. UndoEnd.Char := 3;
  6167. UndoEnd.Line := x+1;
  6168. pLuaUnit.synUnit.UndoList.AddChange(crInsert, UndoStart, UndoEnd, '', smNormal);
  6169. end;
  6170. // Reset selection
  6171. if Result then
  6172. begin
  6173. pLuaUnit.synUnit.SelStart := SelStart;
  6174. pLuaUnit.synUnit.SelEnd := SelEnd + AddedChars;
  6175. end;
  6176. pLuaUnit.synUnit.EndUndoBlock;
  6177. end;
  6178. procedure TfrmLuaEditMain.actBlockCommentExecute(Sender: TObject);
  6179. begin
  6180. DoBlockCommentExecute;
  6181. end;
  6182. function TfrmLuaEditMain.DoBlockUncommentExecute(): Boolean;
  6183. var
  6184. pLuaUnit: TLuaEditUnit;
  6185. x, SelStart, SelEnd, RemovedChars: Integer;
  6186. UndoStart, UndoEnd: TBufferCoord;
  6187. begin
  6188. Result := False;
  6189. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6190. // Retrieve selection
  6191. SelStart := pLuaUnit.synUnit.SelStart;
  6192. SelEnd := pLuaUnit.synUnit.SelEnd;
  6193. pLuaUnit.synUnit.BeginUndoBlock;
  6194. RemovedChars := 0;
  6195. for x := pLuaUnit.synUnit.BlockBegin.Line - 1 to pLuaUnit.synUnit.BlockEnd.Line - 1 do
  6196. begin
  6197. if Copy(pLuaUnit.synUnit.Lines.Strings[x], 1, 2) = '--' then
  6198. begin
  6199. Result := True;
  6200. // Uncommenting line
  6201. pLuaUnit.synUnit.Lines.Strings[x] := Copy(pLuaUnit.synUnit.Lines.Strings[x], 3, Length(pLuaUnit.synUnit.Lines.Strings[x]) - 2);
  6202. pLuaUnit.synUnit.Modified := True;
  6203. pLuaUnit.synUnit.OnChange(pLuaUnit.synUnit);
  6204. RemovedChars := RemovedChars + 2;
  6205. // Notify change to synedit's undo list
  6206. UndoStart.Char := 1;
  6207. UndoStart.Line := x+1;
  6208. UndoEnd.Char := 3;
  6209. UndoEnd.Line := x+1;
  6210. pLuaUnit.synUnit.UndoList.AddChange(crDelete, UndoStart, UndoEnd, '--', smNormal);
  6211. end;
  6212. end;
  6213. // Reset selection
  6214. if Result then
  6215. begin
  6216. pLuaUnit.synUnit.SelStart := SelStart;
  6217. pLuaUnit.synUnit.SelEnd := SelEnd - RemovedChars;
  6218. end;
  6219. pLuaUnit.synUnit.EndUndoBlock;
  6220. end;
  6221. procedure TfrmLuaEditMain.actBlockUncommentExecute(Sender: TObject);
  6222. begin
  6223. DoBlockUncommentExecute;
  6224. end;
  6225. function TfrmLuaEditMain.DoUpperCaseExecute(): Boolean;
  6226. var
  6227. pLuaUnit: TLuaEditUnit;
  6228. SelStart, SelLength: Integer;
  6229. begin
  6230. Result := False;
  6231. if Assigned(jvUnitBar.SelectedTab) then
  6232. begin
  6233. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6234. if pLuaUnit.synUnit.SelText <> '' then
  6235. begin
  6236. Result := True;
  6237. SelStart := pLuaUnit.synUnit.SelStart;
  6238. SelLength := pLuaUnit.synUnit.SelLength;
  6239. pLuaUnit.synUnit.SelText := UpperCase(pLuaUnit.synUnit.SelText);
  6240. pLuaUnit.synUnit.SelStart := SelStart;
  6241. pLuaUnit.synUnit.SelLength := SelLength;
  6242. end;
  6243. end;
  6244. end;
  6245. procedure TfrmLuaEditMain.actUpperCaseExecute(Sender: TObject);
  6246. begin
  6247. DoUpperCaseExecute;
  6248. end;
  6249. function TfrmLuaEditMain.DoLowerCaseExecute(): Boolean;
  6250. var
  6251. pLuaUnit: TLuaEditUnit;
  6252. SelStart, SelLength: Integer;
  6253. begin
  6254. Result := False;
  6255. if Assigned(jvUnitBar.SelectedTab) then
  6256. begin
  6257. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6258. if pLuaUnit.synUnit.SelText <> '' then
  6259. begin
  6260. Result := True;
  6261. SelStart := pLuaUnit.synUnit.SelStart;
  6262. SelLength := pLuaUnit.synUnit.SelLength;
  6263. pLuaUnit.synUnit.SelText := LowerCase(pLuaUnit.synUnit.SelText);
  6264. pLuaUnit.synUnit.SelStart := SelStart;
  6265. pLuaUnit.synUnit.SelLength := SelLength;
  6266. end;
  6267. end;
  6268. end;
  6269. procedure TfrmLuaEditMain.actLowerCaseExecute(Sender: TObject);
  6270. begin
  6271. DoLowerCaseExecute;
  6272. end;
  6273. function TfrmLuaEditMain.DoPrjSettingsExecute(): Boolean;
  6274. begin
  6275. frmPrjOptions.GetLuaProjectOptions(ActiveProject);
  6276. Result := (frmPrjOptions.ShowModal = mrOk);
  6277. if Result then
  6278. begin
  6279. frmPrjOptions.SetLuaProjectOptions(ActiveProject);
  6280. ActiveProject.HasChanged := True;
  6281. frmProjectTree.BuildProjectTree;
  6282. end;
  6283. end;
  6284. procedure TfrmLuaEditMain.actPrjSettingsExecute(Sender: TObject);
  6285. begin
  6286. DoPrjSettingsExecute;
  6287. end;
  6288. function TfrmLuaEditMain.DoActiveSelPrjExecute(): Boolean;
  6289. var
  6290. pNode: PVirtualNode;
  6291. pData: PProjectTreeData;
  6292. begin
  6293. Result := False;
  6294. // Retreive selected node if any
  6295. pNode := frmProjectTree.vstProjectTree.GetFirstSelected;
  6296. if Assigned(pNode) then
  6297. begin
  6298. // Retreive data from the selected node
  6299. pData := frmProjectTree.vstProjectTree.GetNodeData(pNode);
  6300. // Assign selected to the currently active project
  6301. if pData.pLuaEditFile.FileType = otLuaEditProject then
  6302. begin
  6303. Result := True;
  6304. ActiveProject := TLuaEditProject(pData.pLuaEditFile);
  6305. frmProjectTree.BuildProjectTree;
  6306. end;
  6307. end;
  6308. end;
  6309. procedure TfrmLuaEditMain.actActiveSelPrjExecute(Sender: TObject);
  6310. begin
  6311. DoActiveSelPrjExecute;
  6312. end;
  6313. function TfrmLuaEditMain.ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
  6314. var
  6315. Ptr: TFarProc;
  6316. pFunc: TInitializer;
  6317. iFuncReturn: Integer;
  6318. begin
  6319. try
  6320. hModule := LoadLibrary(PChar(sInitializer));
  6321. Ptr := GetProcAddress(hModule, 'LuaDebug_Initializer');
  6322. pFunc := TInitializer(Ptr);
  6323. iFuncReturn := pFunc(L);
  6324. Result := iFuncReturn;
  6325. except
  6326. Result := -1;
  6327. if hModule <> NULL then
  6328. FreeLibrary(hModule);
  6329. Application.MessageBox(PChar('An error occured when attempting to call the initializer from "'+sInitializer+'".'), 'LuaEdit', MB_ICONERROR+MB_OK);
  6330. end;
  6331. end;
  6332. procedure TfrmLuaEditMain.RefreshOpenedUnits;
  6333. var
  6334. x: Integer;
  6335. begin
  6336. for x := 0 to LuaOpenedFiles.Count - 1 do
  6337. begin
  6338. if not TLuaEditUnit(LuaOpenedFiles.Items[x]).HasChanged then
  6339. begin
  6340. jvUnitBar.Tabs[x].Caption := TLuaEditUnit(jvUnitBar.Tabs[x].Data).Name;
  6341. jvUnitBar.Tabs[x].Modified := False;
  6342. end
  6343. else
  6344. begin
  6345. jvUnitBar.Tabs[x].Modified := True;
  6346. end;
  6347. end;
  6348. end;
  6349. function TfrmLuaEditMain.FileIsInTree(sFileName: String): PVirtualNode;
  6350. var
  6351. pNode: PVirtualNode;
  6352. pData: PProjectTreeData;
  6353. begin
  6354. // Initialize stuff before going
  6355. Result := nil;
  6356. pNode := frmProjectTree.vstProjectTree.GetFirst;
  6357. while pNode <> nil do
  6358. begin
  6359. // Retreive data from current node
  6360. pData := frmProjectTree.vstProjectTree.GetNodeData(pNode);
  6361. if pData.pLuaEditFile.FileType in LuaEditTextFilesTypeSet then
  6362. begin
  6363. if pData.pLuaEditFile.PrjOwner.Name = '[@@SingleUnits@@]' then
  6364. begin
  6365. if pData.pLuaEditFile.Path = sFileName then
  6366. begin
  6367. if LuaOpenedFiles.IndexOf(pData.pLuaEditFile) <> -1 then
  6368. jvUnitBar.SelectedTab := TLuaEditBasicTextFile(pData.pLuaEditFile).AssociatedTab
  6369. else
  6370. AddFileInTab(TLuaEditBasicTextFile(pData.pLuaEditFile));
  6371. Result := pNode;
  6372. Break;
  6373. end;
  6374. end;
  6375. end;
  6376. pNode := frmProjectTree.vstProjectTree.GetNext(pNode);
  6377. end;
  6378. end;
  6379. procedure TfrmLuaEditMain.ErrorLookup1Click(Sender: TObject);
  6380. begin
  6381. frmErrorLookup.Show;
  6382. end;
  6383. procedure TfrmLuaEditMain.PrintSetup1Click(Sender: TObject);
  6384. begin
  6385. frmPrintSetup.ShowModal;
  6386. end;
  6387. function TfrmLuaEditMain.DoPrintExecute(): Boolean;
  6388. begin
  6389. synEditPrint.SynEdit := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit;
  6390. synEditPrint.Title := TLuaEditUnit(jvUnitBar.SelectedTab.Data).Path;
  6391. if synEditPrint.PageCount > 1 then
  6392. begin
  6393. pdlgPrint.Options := pdlgPrint.Options + [poPageNums];
  6394. pdlgPrint.MinPage := 1;
  6395. pdlgPrint.MaxPage := synEditPrint.PageCount;
  6396. end
  6397. else
  6398. begin
  6399. pdlgPrint.Options := pdlgPrint.Options - [poPageNums];
  6400. end;
  6401. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelAvail then
  6402. begin
  6403. pdlgPrint.Options := pdlgPrint.Options + [poSelection];
  6404. end
  6405. else
  6406. begin
  6407. pdlgPrint.Options := pdlgPrint.Options - [poSelection];
  6408. end;
  6409. Result := pdlgPrint.Execute;
  6410. if Result then
  6411. begin
  6412. synEditPrint.Colors := PrintUseColor;
  6413. synEditPrint.Highlight := PrintUseSyntax;
  6414. synEditPrint.Wrap := PrintUseWrapLines;
  6415. synEditPrint.LineNumbers := PrintLineNumbers;
  6416. synEditPrint.LineNumbersInMargin := PrintLineNumbersInMargin;
  6417. synEditPrint.Copies := pdlgPrint.Copies;
  6418. if pdlgPrint.PrintRange = prPageNums then
  6419. begin
  6420. synEditPrint.PrintRange(pdlgPrint.FromPage, pdlgPrint.ToPage);
  6421. end
  6422. else if pdlgPrint.PrintRange = prAllPages then
  6423. begin
  6424. if pdlgPrint.PrintRange = prSelection then
  6425. begin
  6426. synEditPrint.SelectedOnly := True
  6427. end;
  6428. synEditPrint.Print;
  6429. end;
  6430. end;
  6431. end;
  6432. procedure TfrmLuaEditMain.actPrintExecute(Sender: TObject);
  6433. begin
  6434. DoPrintExecute;
  6435. end;
  6436. procedure TfrmLuaEditMain.ctrlBarDockOver(Sender: TObject; Source: TDragDockObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  6437. var
  6438. ARect: TRect;
  6439. begin
  6440. Accept := (Source.Control is TToolBar);
  6441. if Accept then
  6442. begin
  6443. //Modify the DockRect to preview dock area (Coolbar client area)
  6444. ARect.TopLeft := ctrlBar.ClientToScreen(ctrlBar.ClientRect.TopLeft);
  6445. ARect.BottomRight := ctrlBar.ClientToScreen(ctrlBar.ClientRect.BottomRight);
  6446. Source.DockRect := ARect;
  6447. end;
  6448. end;
  6449. procedure TfrmLuaEditMain.File2Click(Sender: TObject);
  6450. begin
  6451. if tlbBaseFile.Visible then
  6452. tlbBaseFile.Hide
  6453. else
  6454. tlbBaseFile.Show;
  6455. end;
  6456. procedure TfrmLuaEditMain.Edit2Click(Sender: TObject);
  6457. begin
  6458. if tlbEdit.Visible then
  6459. tlbEdit.Hide
  6460. else
  6461. tlbEdit.Show;
  6462. end;
  6463. procedure TfrmLuaEditMain.Find1Click(Sender: TObject);
  6464. begin
  6465. if tlbFind.Visible then
  6466. tlbFind.Hide
  6467. else
  6468. tlbFind.Show;
  6469. end;
  6470. procedure TfrmLuaEditMain.Run3Click(Sender: TObject);
  6471. begin
  6472. if tlbRun.Visible then
  6473. tlbRun.Hide
  6474. else
  6475. tlbRun.Show;
  6476. end;
  6477. procedure TfrmLuaEditMain.ASciiTable1Click(Sender: TObject);
  6478. begin
  6479. frmAsciiTable.ShowModal;
  6480. end;
  6481. procedure TfrmLuaEditMain.CreateGUID1Click(Sender: TObject);
  6482. begin
  6483. frmGUID.ShowModal();
  6484. end;
  6485. procedure TfrmLuaEditMain.PathConverter1Click(Sender: TObject);
  6486. begin
  6487. frmConvertPath.ShowModal();
  6488. end;
  6489. procedure TfrmLuaEditMain.Help1Click(Sender: TObject);
  6490. begin
  6491. ShellExecute(Self.Handle, 'open', PChar(ExtractFilePath(Application.ExeName)+'\Help\LuaEdit.chm'), nil, nil, SW_SHOWNORMAL);
  6492. end;
  6493. procedure TfrmLuaEditMain.LuaEditHomePage1Click(Sender: TObject);
  6494. begin
  6495. BrowseURL('http://luaedit.luaforge.net');
  6496. end;
  6497. procedure TfrmLuaEditMain.ContributorsList1Click(Sender: TObject);
  6498. begin
  6499. frmContributors.ShowModal();
  6500. end;
  6501. procedure TfrmLuaEditMain.ComponentsContributors1Click(Sender: TObject);
  6502. begin
  6503. frmComponentList.ShowModal();
  6504. end;
  6505. procedure TfrmLuaEditMain.OpenFileAtCursor1Click(Sender: TObject);
  6506. var
  6507. pFiles: TStringList;
  6508. WordAtCursor: String;
  6509. pNode: PVirtualNode;
  6510. pData: PProjectTreeData;
  6511. begin
  6512. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelAvail then
  6513. WordAtCursor := ExpandUNCFileName(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText);
  6514. if FileExistsAbs(WordAtCursor) then
  6515. begin
  6516. pFiles := TStringList.Create;
  6517. pFiles.Add(WordAtCursor);
  6518. DoOpenFileExecute(pFiles);
  6519. pFiles.Free;
  6520. // Reinitialize stuff...
  6521. frmProjectTree.BuildProjectTree();
  6522. CheckButtons();
  6523. end
  6524. else
  6525. Application.MessageBox(PChar('Cannot open file "'+WordAtCursor+'"'), 'LuaEdit', MB_OK+MB_ICONERROR);
  6526. end;
  6527. procedure TfrmLuaEditMain.ppmEditorPopup(Sender: TObject);
  6528. var
  6529. sTextToShow, sOriginalName: String;
  6530. begin
  6531. sTextToShow := '';
  6532. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelAvail then
  6533. begin
  6534. OpenFileatCursor1.Enabled := True;
  6535. sOriginalName := StringReplace(TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText, '\\', '\', [rfIgnoreCase, rfReplaceAll]);
  6536. if FileExistsAbs(sOriginalName) then
  6537. sTextToShow := MinimizeName(sOriginalName, stbMain.Canvas, 150);
  6538. end;
  6539. if sTextToShow <> '' then
  6540. begin
  6541. OpenFileatCursor1.Caption := 'Open Document "'+sTextToShow+'"';
  6542. OpenFileatCursor1.Enabled := True;
  6543. end
  6544. else
  6545. begin
  6546. OpenFileatCursor1.Caption := 'Open Document ""';
  6547. OpenFileatCursor1.Enabled := False;
  6548. end;
  6549. end;
  6550. procedure TfrmLuaEditMain.jvUnitBarChange(Sender: TObject);
  6551. var
  6552. pFile: TLuaEditBasicTextFile;
  6553. begin
  6554. if Assigned(jvUnitBar.SelectedTab) then
  6555. begin
  6556. if Assigned(jvUnitBar.SelectedTab.Data) then
  6557. begin
  6558. pFile := TLuaEditBasicTextFile(jvUnitBar.SelectedTab.Data);
  6559. if pFile.HasChanged then
  6560. stbMain.Panels[3].Text := 'Modified'
  6561. else
  6562. stbMain.Panels[3].Text := '';
  6563. if pFile.IsReadOnly then
  6564. stbMain.Panels[4].Text := 'Read Only'
  6565. else
  6566. stbMain.Panels[4].Text := '';
  6567. synEditClick(pFile.SynUnit);
  6568. frmFunctionList.RefreshList(pFile.Path);
  6569. CheckButtons;
  6570. end;
  6571. end;
  6572. end;
  6573. function TfrmLuaEditMain.DoCompileSciptExecute(): Boolean;
  6574. var
  6575. sFileOut: String;
  6576. sCmd: PChar;
  6577. pLuaUnit: TLuaEditUnit;
  6578. si: TStartupInfo;
  6579. pi: TProcessInformation;
  6580. begin
  6581. Result := True;
  6582. if Assigned(jvUnitBar.SelectedTab) then
  6583. begin
  6584. if Assigned(jvUnitBar.SelectedTab.Data) then
  6585. begin
  6586. if TLuaEditFile(jvUnitBar.SelectedTab.Data).FileType in LuaEditDebugFilesTypeSet then
  6587. begin
  6588. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6589. if not DoSaveExecute(pLuaUnit) then
  6590. begin
  6591. frmLuaEditMessages.Put('Could not compile script "'+pLuaUnit.DisplayPath+'" because the file could not be saved or the action has been canceled.', LUAEDIT_WARNING_MSG);
  6592. Exit;
  6593. end;
  6594. // Prompt user for the output file path
  6595. if pLuaUnit.PrjOwner.sCompileDirectory = '' then
  6596. begin
  6597. sdlgCompileOut.FileName := ChangeFileExt(pLuaUnit.Name, pLuaUnit.PrjOwner.sCompileExtension);
  6598. sdlgCompileOut.InitialDir := ExtractFileDir(pLuaUnit.Path);
  6599. if not sdlgCompileOut.Execute then
  6600. begin
  6601. frmLuaEditMessages.Put('Could not compile script "'+pLuaUnit.DisplayPath+'" because no output path/name was specified.', LUAEDIT_WARNING_MSG);
  6602. Exit;
  6603. end;
  6604. sFileOut := sdlgCompileOut.FileName;
  6605. end
  6606. else
  6607. sFileOut := pLuaUnit.PrjOwner.sCompileDirectory + ChangeFileExt(pLuaUnit.Name, pLuaUnit.PrjOwner.sCompileExtension);
  6608. // Initialize createprocess variables for call
  6609. Screen.Cursor := crHourGlass;
  6610. ShowDockForm(frmLuaEditMessages);
  6611. frmLuaEditMessages.Put('Begin of Script Compilation - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  6612. FillChar(si, sizeof(si), 0);
  6613. si.cb := sizeof(si);
  6614. sCmd := PChar('"' + GetLuaEditInstallPath() + '\luac.exe" -l -o "' + sFileOut + '" "' + pLuaUnit.Path + '"');
  6615. // Call luac application to compile (hidden process)
  6616. CreateProcess(nil, sCmd, nil, nil, True, CREATE_NO_WINDOW, nil, nil, si, pi);
  6617. // Wait until the process is done
  6618. stbMain.Panels[5].Text := 'Compiling Script... Please Wait';
  6619. stbMain.Refresh;
  6620. frmLuaEditMessages.Put('Compiling Script... Please Wait - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  6621. Application.ProcessMessages;
  6622. WaitForSingleObject(pi.hProcess, INFINITE);
  6623. stbMain.Panels[5].Text := '';
  6624. stbMain.Refresh;
  6625. frmLuaEditMessages.Put('End of Script Compilation - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  6626. Screen.Cursor := crDefault;
  6627. Application.ProcessMessages;
  6628. end;
  6629. end;
  6630. end;
  6631. end;
  6632. procedure TfrmLuaEditMain.actCompileSciptExecute(Sender: TObject);
  6633. begin
  6634. DoCompileSciptExecute();
  6635. end;
  6636. function TfrmLuaEditMain.DoCheckSyntaxExecute(): Boolean;
  6637. var
  6638. L: Plua_State;
  6639. pLuaUnit: TLuaEditUnit;
  6640. FileName: String;
  6641. begin
  6642. Result := True;
  6643. if Assigned(jvUnitBar.SelectedTab) then
  6644. begin
  6645. if Assigned(jvUnitBar.SelectedTab.Data) then
  6646. begin
  6647. try
  6648. pLuaUnit := TLuaEditUnit(jvUnitBar.SelectedTab.Data);
  6649. if pLuaUnit.synUnit.Text <> '' then
  6650. begin
  6651. frmLuaEditMessages.vstLuaEditMessages.Clear;
  6652. PrevFile := pLuaUnit.Path;
  6653. L := lua_open();
  6654. LuaLoadBuffer(L, pLuaUnit.synUnit.Text, pLuaUnit.Path);
  6655. frmLuaEditMessages.Put('Syntax Checked - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  6656. stbMain.Panels[5].Text := '[HINT]: Syntax Checked - '+DateTimeToStr(Now);
  6657. pLuaUnit.synUnit.Refresh;
  6658. end;
  6659. except
  6660. on E: ELuaException do
  6661. begin
  6662. PopUpUnitToScreen(PrevFile);
  6663. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  6664. begin
  6665. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  6666. FileName := pLuaUnit.Path;
  6667. if (not FileExistsAbs(FileName)) then
  6668. FileName := PrevFile;
  6669. if E.Line > 0 then
  6670. begin
  6671. pLuaUnit.DebugInfos.iLineError := E.Line;
  6672. jvUnitBar.SelectedTab := pLuaUnit.AssociatedTab;
  6673. pLuaUnit.synUnit.GotoLineAndCenter(E.Line);
  6674. end;
  6675. end;
  6676. if (E.Msg <> 'STOP') then
  6677. begin
  6678. Result := False;
  6679. frmLuaEditMessages.Put(E.Msg + ' (' + IntToStr(E.Line) + ') - ' + DateTimeToStr(Now), LUAEDIT_ERROR_MSG, PrevFile, E.Line);
  6680. raise;
  6681. end;
  6682. end;
  6683. end;
  6684. end;
  6685. end;
  6686. ShowDockForm(frmLuaEditMessages);
  6687. end;
  6688. // check the syntax of the currently opened unit
  6689. procedure TfrmLuaEditMain.actCheckSyntaxExecute(Sender: TObject);
  6690. begin
  6691. DoCheckSyntaxExecute;
  6692. end;
  6693. // check the syntax of the current unit
  6694. procedure TfrmLuaEditMain.ppmUnitsPopup(Sender: TObject);
  6695. begin
  6696. Save2.Enabled := (jvUnitBar.Tabs.Count <> 0);
  6697. SaveAs2.Enabled := (jvUnitBar.Tabs.Count <> 0);
  6698. Close2.Enabled := (jvUnitBar.Tabs.Count <> 0);
  6699. end;
  6700. procedure TfrmLuaEditMain.actFunctionHeaderExecute(Sender: TObject);
  6701. var
  6702. sLine: String;
  6703. begin
  6704. if Assigned(jvUnitBar.SelectedTab) then
  6705. begin
  6706. if Assigned(jvUnitBar.SelectedTab.Data) then
  6707. begin
  6708. sLine := TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Lines[TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.CaretY - 1];
  6709. //FunctionHeaderBuilder(Application.Handle, PChar(sLine));
  6710. end;
  6711. end;
  6712. end;
  6713. procedure TfrmLuaEditMain.jvAppDropDrop(Sender: TObject; Pos: TPoint; Value: TStrings);
  6714. var
  6715. x: Integer;
  6716. pFiles: TStringList;
  6717. FileName: String;
  6718. begin
  6719. pFiles := TStringList.Create;
  6720. for x := 0 to Value.Count - 1 do
  6721. begin
  6722. // Get current file name
  6723. FileName := Value.Strings[x];
  6724. // Make the file exists
  6725. if FileExistsAbs(FileName) then
  6726. begin
  6727. pFiles.Add(FileName);
  6728. DoOpenFileExecute(pFiles);
  6729. end;
  6730. end;
  6731. // Rebuild the project tree and initialize stuff
  6732. pFiles.Free;
  6733. frmProjectTree.BuildProjectTree;
  6734. CheckButtons;
  6735. end;
  6736. procedure TfrmLuaEditMain.jvUnitBarTabClosed(Sender: TObject; Item: TJvTabBarItem);
  6737. var
  6738. pTab: TJvTabBarItem;
  6739. begin
  6740. pTab := jvUnitBar.SelectedTab.GetPreviousVisible;
  6741. if ClosingUnit then
  6742. Item.Free;
  6743. if Assigned(pTab) then
  6744. jvUnitBar.SelectedTab := pTab;
  6745. end;
  6746. procedure TfrmLuaEditMain.jvUnitBarTabSelecting(Sender: TObject; Item: TJvTabBarItem; var AllowSelect: Boolean);
  6747. begin
  6748. if Assigned(Item) then
  6749. begin
  6750. if Assigned(Item.Data) then
  6751. begin
  6752. Self.Caption := 'LuaEdit - ' + TLuaEditUnit(Item.Data).Path;
  6753. frmFunctionList.RefreshList(TLuaEditUnit(Item.Data).Path);
  6754. TLuaEditUnit(Item.Data).synUnit.Visible := True;
  6755. synEditClick(TLuaEditUnit(Item.Data).synUnit);
  6756. if Assigned(jvUnitBar.SelectedTab) then
  6757. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Visible := False;
  6758. end
  6759. else
  6760. Self.Caption := 'LuaEdit';
  6761. end
  6762. else
  6763. Self.Caption := 'LuaEdit';
  6764. end;
  6765. procedure TfrmLuaEditMain.ppmToolBarPopup(Sender: TObject);
  6766. begin
  6767. DoMainMenuViewExecute;
  6768. end;
  6769. // Clean up temporary folder (delete all *.tag files under the temporary folder)
  6770. procedure TfrmLuaEditMain.CleanUpTempDir();
  6771. var
  6772. hSearchRec: TSearchRec;
  6773. iSearchResult: Integer;
  6774. begin
  6775. SetCurrentDirectory(PChar(TempFolder));
  6776. iSearchResult := FindFirst(TempFolder + '\*.tag', faAnyFile, hSearchRec);
  6777. while iSearchResult = 0 do
  6778. begin
  6779. if FileExistsAbs(TempFolder + '\' + hSearchRec.Name) then
  6780. DeleteFile(TempFolder + '\' + hSearchRec.Name);
  6781. iSearchResult := FindNext(hSearchRec);
  6782. end;
  6783. FindClose(hSearchRec);
  6784. end;
  6785. (*procedure TDebuggerThread.Execute;
  6786. begin
  6787. //frmLuaEditMain.actCompileExecute(nil);
  6788. {if IsCompiledComplete then
  6789. begin
  6790. if WSAStartup($101, WSA) <> 0 then
  6791. begin
  6792. Application.MessageBox('Invalid winsock version!', 'LuaEdit', MB_OK+MB_ICONERROR);
  6793. EndThread(0);
  6794. end;
  6795. try
  6796. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  6797. pSock := INVALID_SOCKET;
  6798. pRSock := INVALID_SOCKET;
  6799. // initializing connection
  6800. pSock := socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  6801. if pSock = INVALID_SOCKET then
  6802. raise ELuaEditException.Create('Remote Debug Failed: Cannot open socket!');
  6803. FillChar(pAddrIn, SizeOf(pAddrIn), 0);
  6804. pAddrIn.sin_family := PF_INET;
  6805. pAddrIn.sin_port := htons(pLuaUnit.pPrjOwner.RemotePort);
  6806. pAddrIn.sin_addr.S_addr := htonl(INADDR_ANY);
  6807. // Bind the socket
  6808. if bind(pSock, TSockAddr(pAddrIn), SizeOf(pAddrIn)) <> 0 then
  6809. begin
  6810. sTemp := SysErrorMessage(WSAGetLastError());
  6811. raise ELuaEditException.Create('Remote Debug Failed: The operation failed on binding');
  6812. end;
  6813. // Listen for any client...
  6814. if listen(pSock, 5) <> 0 then
  6815. raise ELuaEditException.Create('Remote Debug Failed: The operation failed on listening');
  6816. // Building CntString...
  6817. frmCntString.memoCntString.Lines.Clear;
  6818. frmCntString.memoCntString.Text := 'rdbg.exe "'+GetLocalIP+'" "'+IntToStr(pLuaUnit.pPrjOwner.RemotePort)+'"';
  6819. // Wait after user interaction...
  6820. WaitForSingleObject(hMutex, INFINITE);
  6821. // Accept next incoming connection
  6822. pRSock := accept(pSock, 0, 0);
  6823. if pRSock = INVALID_SOCKET then
  6824. raise ELuaEditException.Create('Remote Debug Failed: The operation failed on accepting');
  6825. ReleaseMutex(hMutex);
  6826. IsRunning := True;
  6827. //Set a TimeOut (15sec)...
  6828. TimeOut := 15000;
  6829. setsockopt(pRSock, SOL_SOCKET, SO_RCVTIMEO, PChar(@TimeOut), SizeOf(TimeOut));
  6830. //Start communication...
  6831. //send remote initializer full path...
  6832. if pLuaUnit.pPrjOwner.RemoteInitializer = '' then
  6833. Buffer := '@@N/A@@' //Cannot send an empty string over tcp...
  6834. else
  6835. Buffer := pLuaUnit.pPrjOwner.RemoteInitializer;
  6836. Len := Length(Buffer);
  6837. Status := send(pRSock, Len, SizeOf(Len), 0);
  6838. if Status <> SizeOf(Len) then
  6839. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the lenght of the remote initializer full path');
  6840. Status := send(pRSock, Buffer[1], Length(Buffer), 0);
  6841. if Status <> Length(Buffer) then
  6842. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the remote initializer full path');
  6843. //send remote file name...
  6844. Buffer := pLuaUnit.pPrjOwner.DownloadDir + ExtractFileName(pLuaUnit.sName);
  6845. Len := Length(Buffer);
  6846. Status := send(pRSock, Len, SizeOf(Len), 0);
  6847. if Status <> SizeOf(Len) then
  6848. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the lenght of the remote file name');
  6849. Status := send(pRSock, Buffer[1], Length(Buffer), 0);
  6850. if Status <> Length(Buffer) then
  6851. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the remote file name');
  6852. //send the file content...
  6853. ContentByte := Length(pLuaUnit.synUnit.Text);
  6854. Status := send(pRSock, ContentByte, SizeOf(ContentByte), 0);
  6855. if Status <> SizeOf(ContentByte) then
  6856. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the length of the file content to send');
  6857. ContentByte := 0;
  6858. ContentBuffer := 'a = nil' + #$D + #$A;
  6859. ContentBuffer := ContentBuffer + pLuaUnit.synUnit.Text;
  6860. while ContentByte < Length(ContentBuffer) do
  6861. begin
  6862. if (Length(ContentBuffer) - ContentByte) >= 1024 then
  6863. Len := 1024
  6864. else
  6865. Len := Length(ContentBuffer) - ContentByte;
  6866. Buffer := '';
  6867. Buffer := Copy(ContentBuffer, ContentByte + 1, Len);
  6868. Inc(ContentByte, Len);
  6869. Status := send(pRSock, Len, SizeOf(Len), 0);
  6870. if Status <> SizeOf(Len) then
  6871. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the lenght of the remote file content');
  6872. Status := send(pRSock, Buffer[1], Length(Buffer), 0);
  6873. if Status <> Length(Buffer) then
  6874. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while sending the content of the remote file');
  6875. end;
  6876. //Handle user debugging...
  6877. while 1 = 1 do
  6878. begin
  6879. //receiving acknoledge bytes... (is also use to know if the script is in an error state...)
  6880. Status := recv(pRSock, Continue, SizeOf(Continue), 0);
  6881. if Status <> SizeOf(Continue) then
  6882. raise ELuaEditException.Create('Remote Debug Failed: The oepration failed while sending acknoledge bytes');
  6883. if Continue = -1 then
  6884. begin
  6885. //receiving compiled message
  6886. FillChar(RecvBuffer, SizeOf(RecvBuffer), 0);
  6887. Len := 0;
  6888. Status := recv(pRSock, Len, SizeOf(Len), 0);
  6889. if Status <> SizeOf(Len) then
  6890. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the compiled message length');
  6891. Status := recv(pRSock, RecvBuffer, Len, 0);
  6892. if Status <> Len then
  6893. raise ELuaEditException.Create('Remote Debug Failed: The operation failed while receiving the compiled message');
  6894. LastMessage := RecvBuffer;
  6895. if LastMessage <> '@@STOPSCRIPT@@' then
  6896. begin
  6897. sTemp := Copy(LastMessage, Pos(':', LastMessage) + 1, Length(LastMessage) - Pos(':', LastMessage));
  6898. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).pDebugInfos.iLineError := StrToInt(Copy(sTemp, 1, Pos(':', sTemp) - 1));
  6899. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.GotoLineAndCenter(TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).pDebugInfos.iLineError);
  6900. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.CaretX := Length(TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.LineText) + 1;
  6901. LastMessage := '(Line: '+IntToStr(TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).pDebugInfos.iLineError)+')' + Copy(sTemp, Pos(':', sTemp) + 1, Length(sTemp) - Pos(':', sTemp));
  6902. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  6903. frmLuaEditMain.stbMain.Refresh;
  6904. IsCompiledComplete := False;
  6905. Application.MessageBox(PChar(LastMessage), 'LuaEdit', MB_OK+MB_ICONERROR);
  6906. end;
  6907. Continue := 1;
  6908. Status := send(pRSock, Continue, SizeOf(Continue), 0);
  6909. if Status <> SizeOf(Continue) then
  6910. raise ELuaEditException.Create('Remote Debug Failed: The oepration failed while sending acknoledge bytes');
  6911. IsRunning := False;
  6912. Break;
  6913. end;
  6914. CallRemoteHookFunc(pRSock);
  6915. end;
  6916. finally
  6917. if pSock <> INVALID_SOCKET then
  6918. closesocket(pSock);
  6919. if pRSock <> INVALID_SOCKET then
  6920. closesocket(pRSock);
  6921. if Assigned(frmCntString) then
  6922. frmCntString.Free;
  6923. IsRunning := False;
  6924. WSACleanup;
  6925. end;
  6926. end; }
  6927. end;*)
  6928. // This function manage debug actions in general and handle initialization of debug session
  6929. procedure TfrmLuaEditMain.RemoteCustomExecute(Pause: Boolean; PauseICI: Integer; PauseFile: string; PauseLine: Integer; FuncName: string; const Args: array of string; Results: TStrings);
  6930. var
  6931. L: Plua_State;
  6932. FileName: string;
  6933. x, NArgs: Integer;
  6934. pLuaUnit: TLuaEditUnit;
  6935. iDoLuaOpen :Boolean;
  6936. procedure OpenLibs(L: PLua_State);
  6937. begin
  6938. luaopen_base(L);
  6939. luaopen_table(L);
  6940. luaopen_io(L);
  6941. luaopen_string(L);
  6942. luaopen_math(L);
  6943. luaopen_debug(L);
  6944. lua_settop(L, 0);
  6945. end;
  6946. procedure UninitializeUnits;
  6947. var
  6948. x, y: Integer;
  6949. pLuaUnit: TLuaEditUnit;
  6950. begin
  6951. // Uninitialize opened units
  6952. for x := 0 to frmLuaEditMain.jvUnitBar.Tabs.Count - 1 do
  6953. begin
  6954. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.Tabs[x].Data);
  6955. pLuaUnit.DebugInfos.iCurrentLineDebug := -1;
  6956. pLuaUnit.synUnit.Refresh;
  6957. // Reset all breakpoints hitcount to 0
  6958. for y := 0 to pLuaUnit.DebugInfos.lstBreakpoint.Count - 1 do
  6959. TBreakpoint(pLuaUnit.DebugInfos.lstBreakpoint[y]).iHitCount := 0;
  6960. end;
  6961. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  6962. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  6963. frmBreakpoints.RefreshBreakpointList;
  6964. frmLuaEditMain.stbMain.Refresh;
  6965. end;
  6966. procedure InitializeUnits;
  6967. var
  6968. x, y: Integer;
  6969. pLuaUnit: TLuaEditUnit;
  6970. begin
  6971. // Initialize opened units
  6972. for x := 0 to frmLuaEditMain.jvUnitBar.Tabs.Count - 1 do
  6973. begin
  6974. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.Tabs[x].Data);
  6975. pLuaUnit.synUnit.Modified := False;
  6976. pLuaUnit.DebugInfos.iCurrentLineDebug := -1;
  6977. pLuaUnit.DebugInfos.iLineError := -1;
  6978. pLuaUnit.synUnit.Refresh;
  6979. // Reset all breakpoints hitcount to 0
  6980. for y := 0 to pLuaUnit.DebugInfos.lstBreakpoint.Count - 1 do
  6981. TBreakpoint(pLuaUnit.DebugInfos.lstBreakpoint[y]).iHitCount := 0;
  6982. end;
  6983. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  6984. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).SynUnit.Refresh;
  6985. frmBreakpoints.RefreshBreakpointList;
  6986. frmLuaEditMain.stbMain.Refresh;
  6987. end;
  6988. procedure SetPause(pLuaUnit: TLuaEditUnit);
  6989. begin
  6990. if (not Pause) then
  6991. begin
  6992. pLuaUnit.DebugInfos.iCurrentLineDebug := -1;
  6993. pLuaUnit.DebugInfos.iStackMarker := -1;
  6994. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab.Data) then
  6995. TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).SynUnit.Refresh;
  6996. end;
  6997. Self.Pause := Pause;
  6998. Self.PauseICI := PauseICI;
  6999. Self.PauseLine := PauseLine;
  7000. Self.PauseFile := PauseFile;
  7001. end;
  7002. function Initializer(L: PLua_State): Boolean;
  7003. begin
  7004. Result := True;
  7005. if TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).PrjOwner.sInitializer <> '' then
  7006. begin
  7007. if frmLuaEditMain.ExecuteInitializer(TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data).PrjOwner.sInitializer, L) < 0 then
  7008. begin
  7009. Application.MessageBox('An error occured while executing the initializer function.', 'LuaEdit', MB_OK+MB_ICONERROR);
  7010. frmLuaEditMain.CheckButtons;
  7011. FreeLibrary(hModule);
  7012. Result := False;
  7013. end;
  7014. end;
  7015. end;
  7016. procedure AppendToLuaCPath(L: PLua_State; AppendStr: String);
  7017. var
  7018. CurrentStr, NewStr: String;
  7019. begin
  7020. lua_getglobal(L, 'package');
  7021. if lua_istable(L, -1) then
  7022. begin
  7023. lua_pushstring(L, 'cpath');
  7024. lua_gettable(L, -2);
  7025. CurrentStr := lua_tostring(L, -1);
  7026. NewStr := CurrentStr + ';' + AppendStr;
  7027. lua_pushstring(L, PChar(NewStr));
  7028. lua_pushstring(L, 'cpath');
  7029. lua_settable(L, -3);
  7030. end;
  7031. end;
  7032. procedure AppendToLuaPath(L: PLua_State; AppendStr: String);
  7033. var
  7034. CurrentStr, NewStr: String;
  7035. begin
  7036. lua_getglobal(L, 'package');
  7037. if lua_istable(L, -1) then
  7038. begin
  7039. lua_pushstring(L, 'path');
  7040. lua_gettable(L, -2);
  7041. CurrentStr := lua_tostring(L, -1);
  7042. NewStr := CurrentStr + ';' + AppendStr;
  7043. lua_pushstring(L, PChar(NewStr));
  7044. lua_pushstring(L, 'path');
  7045. lua_settable(L, -3);
  7046. end;
  7047. end;
  7048. begin
  7049. // Determine unit to use to start debug
  7050. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  7051. begin
  7052. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  7053. if ((pLuaUnit.PrjOwner = ActiveProject) and (ActiveProject.sTargetLuaUnit <> '[Current Unit]')) then
  7054. begin
  7055. pLuaUnit := ActiveProject.pTargetLuaUnit;
  7056. PopUpUnitToScreen(pLuaUnit.Path);
  7057. end;
  7058. end
  7059. else if Assigned(ActiveProject) then
  7060. begin
  7061. pLuaUnit := ActiveProject.pTargetLuaUnit;
  7062. PopUpUnitToScreen(pLuaUnit.Path);
  7063. end;
  7064. if Assigned(pLuaUnit) then
  7065. begin
  7066. if Running then
  7067. begin
  7068. if ((IsEdited) and (NotifyModified)) then
  7069. begin
  7070. case (Application.MessageBox(PChar('The unit "'+pLuaUnit.Path+'" has changed. Stop debugging?'), 'LuaEdit', MB_ICONINFORMATION+MB_YESNO)) of
  7071. IDYES:
  7072. begin
  7073. Running := False;
  7074. frmLuaEditMessages.Put('End of Scipt - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  7075. frmLuaEditMessages.Put('Script Terminated by User - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  7076. Exit;
  7077. end;
  7078. IDNO:
  7079. begin
  7080. NotifyModified := False;
  7081. end;
  7082. end;
  7083. end;
  7084. SetPause(pLuaUnit);
  7085. ReStart := True;
  7086. Exit;
  7087. end else
  7088. begin
  7089. SetPause(pLuaUnit);
  7090. NotifyModified := False;
  7091. end;
  7092. if not DoCheckSyntaxExecute then
  7093. Exit;
  7094. iDoLuaOpen := (LuaState = nil);
  7095. if iDoLuaOpen then
  7096. LuaState := lua_open;
  7097. L := LuaState;
  7098. OpenLibs(L);
  7099. if not Initializer(L) then
  7100. begin
  7101. Running := False;
  7102. Exit;
  7103. end;
  7104. Running := True;
  7105. LuaRegister(L, 'print', lua_print);
  7106. OnLuaStdoutEx := DoLuaStdoutEx;
  7107. lua_sethook(L, HookCaller, HOOK_MASK, 0);
  7108. CurrentICI := 1;
  7109. frmLuaEditMain.CheckButtons;
  7110. // Initializing project's settings if required
  7111. if ActiveProject = pLuaUnit.PrjOwner then
  7112. begin
  7113. // Initializing runtime directory
  7114. if DirectoryExists(ActiveProject.sRuntimeDirectory) then
  7115. begin
  7116. SetCurrentDirectory(PChar(ActiveProject.sRuntimeDirectory));
  7117. lua_pushstring(L, PChar(ActiveProject.sRuntimeDirectory));
  7118. lua_setglobal(L, 'LUA_PATH');
  7119. end;
  7120. end;
  7121. if (Assigned(Results)) then
  7122. Results.Clear;
  7123. try
  7124. if Assigned(jvUnitBar.SelectedTab.Data) then
  7125. begin
  7126. TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Refresh;
  7127. frmLuaEditMain.stbMain.Refresh;
  7128. end;
  7129. PrevFile := pLuaUnit.Path;
  7130. PrevLine := 0;
  7131. try
  7132. frmLuaEditMessages.vstLuaEditMessages.Clear;
  7133. CallStack.Clear;
  7134. PrintStack;
  7135. if TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Text = '' then
  7136. Exit;
  7137. LuaLoadBuffer(L, TLuaEditUnit(jvUnitBar.SelectedTab.Data).synUnit.Text, pLuaUnit.Path);
  7138. if (FuncName <> '') then
  7139. begin
  7140. LuaPCall(L, 0, 0, 0);
  7141. lua_getglobal(L, PChar(FuncName));
  7142. if (lua_type(L, -1) <> LUA_TFUNCTION) then
  7143. raise Exception.CreateFmt('Can''t find function "%s"', [FuncName]);
  7144. NArgs := Length(Args);
  7145. for x := 0 to NArgs - 1 do
  7146. LuaPushString(L, Args[x]);
  7147. end else
  7148. begin
  7149. NArgs := 0;
  7150. lua_newtable(L);
  7151. for x := 0 to Length(Args) - 1 do
  7152. begin
  7153. LuaPushString(L, Args[x]);
  7154. lua_rawseti(L, -2, x + 1);
  7155. end;
  7156. lua_setglobal(L, ArgIdent);
  7157. end;
  7158. {$ifdef RTASSERT} RTAssert(0, true, ' Begin Script', '', 0); {$endif}
  7159. frmLuaEditMessages.Put('Begin of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  7160. LuaPCall(L, NArgs, LUA_MULTRET, 0);
  7161. frmLuaEditMessages.Put('End of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  7162. {$ifdef RTASSERT} RTAssert(0, true, ' End Script', '', 0); {$endif}
  7163. if (Assigned(Results)) then
  7164. begin
  7165. Results.Clear;
  7166. for x := 1 to lua_gettop(L) do
  7167. Results.Add(LuaStackToStr(L, x));
  7168. end;
  7169. PrintLuaStack(L);
  7170. PrintGlobal(L, True);
  7171. PrintWatch(L);
  7172. finally
  7173. UninitializeUnits;
  7174. if iDoLuaOpen
  7175. then begin
  7176. lua_close(L);
  7177. LuaState := nil;
  7178. end;
  7179. Running := False;
  7180. Self.Pause := False;
  7181. Self.PauseICI := 0;
  7182. Self.PauseLine := -1;
  7183. Self.PauseFile := '';
  7184. CurrentICI := 1;
  7185. Application.HintHidePause := 2500;
  7186. frmLuaEditMain.CheckButtons;
  7187. FreeLibrary(hModule);
  7188. end;
  7189. except
  7190. on E: ELuaException do
  7191. begin
  7192. PopUpUnitToScreen(PrevFile);
  7193. if Assigned(frmLuaEditMain.jvUnitBar.SelectedTab) then
  7194. begin
  7195. pLuaUnit := TLuaEditUnit(frmLuaEditMain.jvUnitBar.SelectedTab.Data);
  7196. FileName := pLuaUnit.Path;
  7197. if (not FileExistsAbs(FileName)) then
  7198. FileName := PrevFile;
  7199. if (FileExistsAbs(FileName) and (E.Line > 0)) then
  7200. begin
  7201. pLuaUnit.DebugInfos.iLineError := E.Line;
  7202. frmLuaEditMain.jvUnitBar.SelectedTab := pLuaUnit.AssociatedTab;
  7203. pLuaUnit.synUnit.GotoLineAndCenter(E.Line);
  7204. end;
  7205. end;
  7206. if (E.Msg <> 'STOP') then
  7207. begin
  7208. stbMain.Panels[5].Text := '[ERROR]: '+E.Msg+' ('+IntToStr(E.Line)+') - '+DateTimeToStr(Now);
  7209. frmLuaEditMessages.Put(E.Msg + ' (' + IntToStr(E.Line) + ') - ' + DateTimeToStr(Now), LUAEDIT_ERROR_MSG, PrevFile, E.Line);
  7210. frmLuaEditMessages.Put('End of Script - '+DateTimeToStr(Now), LUAEDIT_HINT_MSG);
  7211. raise;
  7212. end;
  7213. UninitializeUnits;
  7214. end;
  7215. end;
  7216. end;
  7217. end;
  7218. function TfrmLuaEditMain.DoRemoteSessionExecute(): Boolean;
  7219. var
  7220. pInitiateClient: TInitiateClient;
  7221. pSocketCreate: TSocketCreate;
  7222. pSocketSend: TSocketSend;
  7223. Ptr: TFarProc;
  7224. hModule: Cardinal;
  7225. begin
  7226. try
  7227. Result := True;
  7228. // Initialize winsock
  7229. if WSAStartup($101, WSA) <> 0 then
  7230. ESocketException.Create('Fail to initialize winsock: ' + SysErrorMessage(WSAGetLastError()));
  7231. // Load remote plugin library
  7232. hModule := LoadLibrary(PChar(GetLuaEditInstallPath() + '\Remote.dll'));
  7233. // Retrieve the 'SocketSend' function from plugin dll
  7234. Ptr := GetProcAddress(hModule, 'SocketSend');
  7235. pSocketSend := TSocketSend(Ptr);
  7236. Ptr := nil;
  7237. // Retrieve the 'SocketCreate' function from plugin dll
  7238. Ptr := GetProcAddress(hModule, 'SocketCreate');
  7239. pSocketCreate := TSocketCreate(Ptr);
  7240. Ptr := nil;
  7241. // Create the socket...
  7242. pSock := pSocketCreate(True, 'Unable to create the socket.');
  7243. if pSock = INVALID_SOCKET then
  7244. Exit;
  7245. // Retrieve the 'InitiateClient' function from plugin dll
  7246. Ptr := GetProcAddress(hModule, 'InitiateClient');
  7247. pInitiateClient := TInitiateClient(Ptr);
  7248. Ptr := nil;
  7249. // Initiate connection
  7250. if Assigned(ActiveProject) then
  7251. begin
  7252. if ((ActiveProject.sRemoteIP <> '0.0.0.0') and (ActiveProject.iRemotePort > 0) and (ActiveProject.sRemoteDirectory <> '')) then
  7253. begin
  7254. if not pInitiateClient(pSock, PChar(ActiveProject.sRemoteIP), ActiveProject.iRemotePort, PChar(ActiveProject.sRemoteDirectory), ActiveProject.iConnectTimeOut) then
  7255. Exit;
  7256. // Uploading files on remote machine (including initializer if required)
  7257. frmUploadFiles := TfrmUploadFiles.Create(nil);
  7258. frmUploadFiles.Show;
  7259. frmUploadFiles.Transfer(pSock, ActiveProject, hModule);
  7260. // Free and nil frmUploadFiles if required
  7261. if Assigned(frmUploadFiles) then
  7262. frmUploadFiles.Free;
  7263. // Send initializer path...
  7264. if ActiveProject.sInitializer <> '' then
  7265. pSocketSend(pSock, PChar(ActiveProject.sRemoteDirectory + ExtractFileName(ActiveProject.sInitializer))^, Length(ActiveProject.sRemoteDirectory + ExtractFileName(ActiveProject.sInitializer)), 0, 'Fail to send the intializer path.')
  7266. else
  7267. pSocketSend(pSock, PChar(RDBG_EMPTY)^, Length(RDBG_EMPTY), 0, 'Fail to send the intializer path.');
  7268. end
  7269. else
  7270. Application.MessageBox('Remote debugging informations in the currently opened project must be valid!', 'LuaEdit', MB_ICONERROR + MB_OK);
  7271. end
  7272. else
  7273. Application.MessageBox('A project containing remote debugging informations must be opened!', 'LuaEdit', MB_ICONERROR + MB_OK);
  7274. // Uninitialize winsock
  7275. //WSACleanup;
  7276. except
  7277. on E: Exception do
  7278. begin
  7279. // Free and nil frmUploadFiles if required
  7280. if Assigned(frmUploadFiles) then
  7281. frmUploadFiles.Free;
  7282. // Free loaded library
  7283. if hModule <> NULL then
  7284. FreeLibrary(hModule);
  7285. // Display error message
  7286. WSACleanup;
  7287. Result := False;
  7288. Application.MessageBox(PChar(E.Message), 'LuaEdit', MB_OK+MB_ICONERROR);
  7289. end;
  7290. end;
  7291. end;
  7292. procedure TfrmLuaEditMain.actRemoteSessionExecute(Sender: TObject);
  7293. begin
  7294. DoRemoteSessionExecute;
  7295. end;
  7296. end.