MainUnit.pas 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. Copyright (C) 2005 Fréderic Bour
  5. Copyright (C) 2005-2007 Kevin Kofler
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. }
  18. unit MainUnit;
  19. interface
  20. uses
  21. MasterUnit, SourceFileUnit, FolderUnit, ToolsListUnit, LinkDLLUnit,
  22. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  23. Menus, StdCtrls, ExtCtrls, ImgList, ComCtrls, Buttons, ActnList, ToolWin,
  24. Printers, SourceEditUnit, HTMLHelpUnit, MemoComponentUnit, ScktComp,
  25. ComObj, ActiveX, TiEmuOLELib_TLB;
  26. type
  27. TPanel = class(ExtCtrls.TPanel)
  28. protected
  29. procedure Paint; override;
  30. end;
  31. TMainForm = class(TForm)
  32. ProjectTree: TTreeView;
  33. LittleIcons: TImageList;
  34. TreeEditorSplitter: TSplitter;
  35. MainMenu: TMainMenu;
  36. MainMenuFile: TMenuItem;
  37. MenuFileNew: TMenuItem;
  38. Project1: TMenuItem;
  39. AssemblerSource1: TMenuItem;
  40. Open1: TMenuItem;
  41. Save1: TMenuItem;
  42. SaveAs1: TMenuItem;
  43. N1: TMenuItem;
  44. Exit1: TMenuItem;
  45. CSourceFile1: TMenuItem;
  46. MainMenuEdit: TMenuItem;
  47. Undo1: TMenuItem;
  48. N2: TMenuItem;
  49. Delete1: TMenuItem;
  50. Cut1: TMenuItem;
  51. Copy1: TMenuItem;
  52. Paste1: TMenuItem;
  53. AddFiles1: TMenuItem;
  54. MenuCompileLine: TMenuItem;
  55. MainMenuProject: TMenuItem;
  56. Compile1: TMenuItem;
  57. Link1: TMenuItem;
  58. N4: TMenuItem;
  59. Options1: TMenuItem;
  60. AddFileDlg: TOpenDialog;
  61. N5: TMenuItem;
  62. Preferences1: TMenuItem;
  63. N6: TMenuItem;
  64. HeaderFile1: TMenuItem;
  65. SourceFilePopup: TPopupMenu;
  66. Compile2: TMenuItem;
  67. N7: TMenuItem;
  68. Remove1: TMenuItem;
  69. Delete2: TMenuItem;
  70. Splitter2: TSplitter;
  71. ErrWinPanel: TPanel;
  72. ErrorList: TListView;
  73. Save2: TMenuItem;
  74. SaveAs2: TMenuItem;
  75. N8: TMenuItem;
  76. MainMenuHelp: TMenuItem;
  77. Build1: TMenuItem;
  78. N9: TMenuItem;
  79. SelectAll1: TMenuItem;
  80. OpenProjectDlg: TOpenDialog;
  81. SaveProjectDlg: TSaveDialog;
  82. N10: TMenuItem;
  83. About1: TMenuItem;
  84. StatusBar: TStatusBar;
  85. ToolBarImages: TImageList;
  86. FileNewPopup: TPopupMenu;
  87. HeaderFile2: TMenuItem;
  88. Actions: TActionList;
  89. ActionFileNewProject: TAction;
  90. ActionFileNewCHeaderFile: TAction;
  91. ActionFileNewGNUAsmHeaderFile: TAction;
  92. ActionFileNewA68kAsmHeaderFile: TAction;
  93. ActionFileNewCFile: TAction;
  94. ActionFileNewGNUAsmFile: TAction;
  95. ActionFileNewA68kAsmFile: TAction;
  96. ActionFileOpen: TAction;
  97. ActionFileSave: TAction;
  98. ActionFileSaveAs: TAction;
  99. ActionFilePreferences: TAction;
  100. ActionFileExit: TAction;
  101. ActionEditUndo: TAction;
  102. ActionEditDelete: TAction;
  103. ActionEditCut: TAction;
  104. ActionEditCopy: TAction;
  105. ActionEditPaste: TAction;
  106. ActionEditSelectAll: TAction;
  107. ActionProjectAddFiles: TAction;
  108. ActionProjectCompile: TAction;
  109. ActionProjectMake: TAction;
  110. ActionProjectBuild: TAction;
  111. ActionProjectOptions: TAction;
  112. ActionHelpDocumentation: TAction;
  113. ActionHelpAbout: TAction;
  114. ActionTreeItemSave: TAction;
  115. ActionTreeItemSaveAs: TAction;
  116. ActionTreeItemCompile: TAction;
  117. ActionTreeItemRemove: TAction;
  118. ActionTreeItemDelete: TAction;
  119. CSourceFile2: TMenuItem;
  120. AssemblerSourceFile1: TMenuItem;
  121. Project3: TMenuItem;
  122. N11: TMenuItem;
  123. ActionProjectShowErrors: TAction;
  124. ErrorsandWarnings1: TMenuItem;
  125. N12: TMenuItem;
  126. MainMenuFind: TMenuItem;
  127. ActionFindFind: TAction;
  128. ActionFindReplace: TAction;
  129. ActionFindOpenFile: TAction;
  130. Find2: TMenuItem;
  131. Replace1: TMenuItem;
  132. OpenFileAtCursor1: TMenuItem;
  133. N13: TMenuItem;
  134. FindDlg: TFindDialog;
  135. ReplaceDlg: TReplaceDialog;
  136. ToolBarImagesDisabled: TImageList;
  137. PrintDlg: TPrintDialog;
  138. ActionFilePrint: TAction;
  139. Print1: TMenuItem;
  140. N14: TMenuItem;
  141. ActionFilePrintQuickly: TAction;
  142. ErrorListIcons: TImageList;
  143. DocFile: THTMLHelp;
  144. ActionHelpContents: TAction;
  145. ActionHelpIndex: TAction;
  146. ActionHelpSearch: TAction;
  147. ActionTreeItemRename: TAction;
  148. N19: TMenuItem;
  149. Rename1: TMenuItem;
  150. Contents1: TMenuItem;
  151. Index1: TMenuItem;
  152. Search1: TMenuItem;
  153. EditorPopup: TPopupMenu;
  154. Undo2: TMenuItem;
  155. N16: TMenuItem;
  156. Clear1: TMenuItem;
  157. Cut2: TMenuItem;
  158. Copy2: TMenuItem;
  159. Paste2: TMenuItem;
  160. N17: TMenuItem;
  161. SelectAll2: TMenuItem;
  162. MainToolBar: TToolBar;
  163. ToolBarNewButton: TToolButton;
  164. ToolButton2: TToolButton;
  165. ToolButton3: TToolButton;
  166. ToolButton4: TToolButton;
  167. ToolButton23: TToolButton;
  168. ToolButton24: TToolButton;
  169. ToolButton6: TToolButton;
  170. ToolButton7: TToolButton;
  171. ToolButton8: TToolButton;
  172. ToolButton9: TToolButton;
  173. ToolButton10: TToolButton;
  174. ToolButton5: TToolButton;
  175. ToolButton11: TToolButton;
  176. ToolButton20: TToolButton;
  177. ToolButton21: TToolButton;
  178. ToolBarCompileLine1: TToolButton;
  179. ToolBarCompileButton: TToolButton;
  180. ToolButton15: TToolButton;
  181. ToolBarCompileLine2: TToolButton;
  182. ToolButton18: TToolButton;
  183. ToolButton19: TToolButton;
  184. ActionEditRedo: TAction;
  185. Redo1: TMenuItem;
  186. Redo2: TMenuItem;
  187. EditorPanel: TPanel;
  188. NoEditor: TPanel;
  189. FunctionPopup: TPopupMenu;
  190. ActionFindFunctions: TAction;
  191. N15: TMenuItem;
  192. Functions1: TMenuItem;
  193. ToolButton25: TToolButton;
  194. NoFunctionsItem: TMenuItem;
  195. ActionFileNewTextFile: TAction;
  196. TextFile1: TMenuItem;
  197. TextFile2: TMenuItem;
  198. ActionEditIncreaseIndent: TAction;
  199. ActionEditDecreaseIndent: TAction;
  200. N18: TMenuItem;
  201. IncreaseIndent1: TMenuItem;
  202. DecreaseIndent1: TMenuItem;
  203. N20: TMenuItem;
  204. IncreaseIndent2: TMenuItem;
  205. DecreaseIndent2: TMenuItem;
  206. N21: TMenuItem;
  207. OpenFileatCursor2: TMenuItem;
  208. GNUAssemblySourceFile1: TMenuItem;
  209. GNUAssemblySourceFile2: TMenuItem;
  210. ActionFileNewQuillFile: TAction;
  211. QuillSourceFile1: TMenuItem;
  212. QuillSourceFile2: TMenuItem;
  213. ActionProjectStopCompilation: TAction;
  214. ActionProjectForceQuitCompiler: TAction;
  215. ToolButton16: TToolButton;
  216. ToolButton17: TToolButton;
  217. StopCompilation1: TMenuItem;
  218. ForceQuitCompiler1: TMenuItem;
  219. ActionHelpNews: TAction;
  220. N3: TMenuItem;
  221. News1: TMenuItem;
  222. ActionDebugRun: TAction;
  223. ActionDebugPause: TAction;
  224. ActionDebugReset: TAction;
  225. MainMenuDebug: TMenuItem;
  226. Run1: TMenuItem;
  227. N22: TMenuItem;
  228. Pause1: TMenuItem;
  229. Reset1: TMenuItem;
  230. ToolBarRunButton: TToolButton;
  231. ToolBarDebugLine: TToolButton;
  232. ToolBarPauseButton: TToolButton;
  233. ToolButton12: TToolButton;
  234. ToolButton13: TToolButton;
  235. ChangeNotificationTimer: TTimer;
  236. ToolBarBevel: TBevel;
  237. ToolBarEndLine: TToolButton;
  238. RecentFilesLine: TMenuItem;
  239. RecentFilesPopup: TPopupMenu;
  240. NoFilesItem: TMenuItem;
  241. ActionToolsConfigure: TAction;
  242. MainMenuTools: TMenuItem;
  243. Configure1: TMenuItem;
  244. ToolsLine: TMenuItem;
  245. ActionProjectShowProgramOutput: TAction;
  246. ProgramOutput1: TMenuItem;
  247. ActionFileNewFolder: TAction;
  248. N23: TMenuItem;
  249. Folder1: TMenuItem;
  250. N24: TMenuItem;
  251. Folder2: TMenuItem;
  252. FolderPopup: TPopupMenu;
  253. MenuItem6: TMenuItem;
  254. MenuItem9: TMenuItem;
  255. CategoryPopup: TPopupMenu;
  256. ActionFileNewFile: TAction;
  257. File1: TMenuItem;
  258. Folder3: TMenuItem;
  259. N25: TMenuItem;
  260. Folder4: TMenuItem;
  261. File2: TMenuItem;
  262. ActionTreeItemNewFolder: TAction;
  263. ActionTreeItemNewFile: TAction;
  264. GNUAssemblyHeaderFile1: TMenuItem;
  265. GNUAssemblyHeaderFile2: TMenuItem;
  266. A68kAssemblyHeaderFile1: TMenuItem;
  267. A68kAssemblyHeaderFile2: TMenuItem;
  268. ErrorPanel: TPanel;
  269. CloseErrorsButton: TSpeedButton;
  270. Label1: TLabel;
  271. Label2: TLabel;
  272. ErrorsLabel: TLabel;
  273. WarningsLabel: TLabel;
  274. procedure FormCreate(Sender: TObject);
  275. procedure FormDestroy(Sender: TObject);
  276. procedure AppException(Sender: TObject; E: Exception);
  277. procedure ProjectTreeEditing(Sender: TObject; Node: TTreeNode;
  278. var AllowEdit: Boolean);
  279. procedure ProjectAddFiles(Sender: TObject);
  280. procedure ProjectTreeChange(Sender: TObject; Node: TTreeNode);
  281. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  282. procedure ProjectTreeDeletion(Sender: TObject; Node: TTreeNode);
  283. procedure FileExit(Sender: TObject);
  284. procedure FileNewProject(Sender: TObject);
  285. procedure TreeItemRemove(Sender: TObject);
  286. procedure TreeItemDelete(Sender: TObject);
  287. procedure TreeItemCompile(Sender: TObject);
  288. procedure CloseErrorsButtonClick(Sender: TObject);
  289. procedure ErrorListDeletion(Sender: TObject; Item: TListItem);
  290. procedure TreeItemSave(Sender: TObject);
  291. procedure HelpDocumentation(Sender: TObject);
  292. procedure EditorEnter(Sender: TObject);
  293. procedure EditorExit(Sender: TObject);
  294. procedure EditUndo(Sender: TObject);
  295. procedure EditRedo(Sender: TObject);
  296. procedure EditClear(Sender: TObject);
  297. procedure EditCut(Sender: TObject);
  298. procedure EditCopy(Sender: TObject);
  299. procedure EditPaste(Sender: TObject);
  300. procedure EditSelectAll(Sender: TObject);
  301. procedure ProjectCompile(Sender: TObject);
  302. procedure ProjectMake(Sender: TObject);
  303. procedure FileOpenProject(Sender: TObject);
  304. procedure FileSaveAll(Sender: TObject);
  305. procedure FileSaveProjectAs(Sender: TObject);
  306. procedure EditorKeyDown(Sender: TObject; var Key: Word;
  307. Shift: TShiftState);
  308. procedure ProjectBuild(Sender: TObject);
  309. procedure ProjectTreeKeyDown(Sender: TObject; var Key: Word;
  310. Shift: TShiftState);
  311. procedure ProjectTreeMouseUp(Sender: TObject; Button: TMouseButton;
  312. Shift: TShiftState; X, Y: Integer);
  313. procedure ProjectTreeEdited(Sender: TObject; Node: TTreeNode;
  314. var S: String);
  315. procedure ProjectOptions(Sender: TObject);
  316. procedure FilePreferences(Sender: TObject);
  317. procedure FileNewHeaderFile(Sender: TObject);
  318. procedure FileNewCSourceFile(Sender: TObject);
  319. procedure FileNewGNUAssemblerSourceFile(Sender: TObject);
  320. procedure FileNewAssemblerSourceFile(Sender: TObject);
  321. procedure FileNewQuillSourceFile(Sender: TObject);
  322. procedure FileNewTextFile(Sender: TObject);
  323. procedure TreeItemSaveAs(Sender: TObject);
  324. procedure HelpAbout(Sender: TObject);
  325. procedure DisplayHint(Sender: TObject);
  326. procedure ShowHideErrors(Sender: TObject);
  327. procedure FindString(Sender: TObject; AllFiles: Boolean);
  328. procedure ReplaceDlgReplace(Sender: TObject);
  329. procedure FindText(Sender: TObject);
  330. procedure ReplaceText(Sender: TObject);
  331. procedure FindOpenFile(Sender: TObject);
  332. procedure FindDlgFind(Sender: TObject);
  333. procedure ActionsExecute(Action: TBasicAction; var Handled: Boolean);
  334. procedure ProjectTreeEnter(Sender: TObject);
  335. procedure ProjectTreeExit(Sender: TObject);
  336. procedure ProjectTreeChanging(Sender: TObject; Node: TTreeNode;
  337. var AllowChange: Boolean);
  338. procedure EditorChange(Sender: TObject);
  339. procedure FilePrint(Sender: TObject);
  340. procedure FilePrintQuickly(Sender: TObject);
  341. procedure TreeItemRename(Sender: TObject);
  342. procedure HelpContents(Sender: TObject);
  343. procedure HelpIndex(Sender: TObject);
  344. procedure HelpSearch(Sender: TObject);
  345. procedure SplitterMoved(Sender: TObject);
  346. procedure ProjectTreeMouseDown(Sender: TObject; Button: TMouseButton;
  347. Shift: TShiftState; X, Y: Integer);
  348. procedure ToolBarManagerBandMove(Sender: TObject; Control: TControl;
  349. var ARect: TRect);
  350. procedure ProjectTreeDragOver(Sender, Source: TObject; X, Y: Integer;
  351. State: TDragState; var Accept: Boolean);
  352. procedure ProjectTreeDragDrop(Sender, Source: TObject; X, Y: Integer);
  353. procedure ErrorListClick(Sender: TObject);
  354. procedure DeleteError(Sender: TObject);
  355. procedure FunctionPopupPopup(Sender: TObject);
  356. procedure FindFunctions(Sender: TObject);
  357. procedure FindFunctionFromPopup(Sender: TObject);
  358. procedure IncreaseIndent(Sender: TObject);
  359. procedure DecreaseIndent(Sender: TObject);
  360. procedure ProjectStopCompilation(Sender: TObject);
  361. procedure ProjectForceQuitCompiler(Sender: TObject);
  362. procedure HelpNews(Sender: TObject);
  363. procedure DebugRun(Sender: TObject);
  364. procedure DebugPause(Sender: TObject);
  365. procedure DebugReset(Sender: TObject);
  366. procedure FormKeyDown(Sender: TObject; var Key: Word;
  367. Shift: TShiftState);
  368. procedure ChangeNotificationTick(Sender: TObject);
  369. procedure RecentFileClick(Sender: TObject);
  370. procedure ToolsConfigure(Sender: TObject);
  371. procedure ToolClick(Sender: TObject);
  372. procedure ProjectTreeStartDrag(Sender: TObject;
  373. var DragObject: TDragObject);
  374. procedure ShowProgramOutput(Sender: TObject);
  375. procedure FileNewFolder(Sender: TObject);
  376. procedure FileNewFile(Sender: TObject);
  377. procedure ErrorListKeyDown(Sender: TObject; var Key: Word;
  378. Shift: TShiftState);
  379. private
  380. EditorToHide: TWinControl;
  381. TempLockHandle: THandle;
  382. FModified: Boolean;
  383. FInvalidated: Boolean;
  384. FProjectFile: string;
  385. InChangeNotification: Boolean;
  386. procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
  387. procedure SetProjectFile(const Value: string);
  388. procedure SetModified(const Value: Boolean);
  389. function GetCurrentEditor: TMemoComponent;
  390. function GetInvalidated: Boolean;
  391. public
  392. TopNode: TTreeNode;
  393. OriginalCaption: string;
  394. LinkLibHandle: HModule;
  395. LinkLibGetInterfaceVersion: TLinkLibGetInterfaceVersion;
  396. LinkLibLinkFiles: TLinkLibLinkFiles;
  397. LinkLibCreateArchive: TLinkLibCreateArchive;
  398. SourceFiles: TSourceFiles;
  399. JumpToError,
  400. OpenFolderMessage,
  401. AutoSave,
  402. DeleteErrors,
  403. StartingAppNow,
  404. OpeningProjectNow,
  405. NoHideEditor: Boolean;
  406. PreviousNode: TTreeNode;
  407. SyntaxCBackup: TSyntaxColoring;
  408. SyntaxCReset: Boolean;
  409. SyntaxAsmGNUBackup: TSyntaxColoring;
  410. SyntaxAsmGNUReset: Boolean;
  411. SyntaxAsmBackup: TSyntaxColoring;
  412. SyntaxAsmReset: Boolean;
  413. SyntaxQuillBackup: TSyntaxColoring;
  414. SyntaxQuillReset: Boolean;
  415. Closing: Boolean;
  416. ProgSize: Integer;
  417. OptimizeInfo: TLinkLibOptimizeInfo;
  418. Funcs: TSourceFileFunctions;
  419. CurrentStrings: TMemoryStream;
  420. CurVTIType: TVTICalcType;
  421. CurTIEmuType: TTIEmuCalcType;
  422. RecentFiles: TStringList;
  423. ToolsList: TToolsList;
  424. property ProjectFile: string read FProjectFile write SetProjectFile;
  425. property Modified: Boolean read FModified write SetModified;
  426. property Invalidated: Boolean read GetInvalidated write FInvalidated;
  427. property CurrentEditor: TMemoComponent read GetCurrentEditor;
  428. procedure Modify;
  429. procedure WarnIfModified;
  430. procedure FileNew;
  431. procedure FileClear;
  432. procedure FileLoad;
  433. procedure FileOpen(const FN: string);
  434. procedure FileSave;
  435. procedure FileSaveAs(const FN: string);
  436. procedure ResetProjectSettings;
  437. procedure AppCompStartFile;
  438. procedure AppCompStop;
  439. procedure AppCompSetMessage(const Msg: string);
  440. procedure AppCompUpdate;
  441. procedure UpdateProgramOutput;
  442. procedure CopyHeaders;
  443. procedure DeleteHeaders;
  444. procedure ClearErrors;
  445. procedure HideErrors;
  446. procedure ShowErrors;
  447. procedure UpdateErrorWindow;
  448. procedure AddError(const Line: string; BugTp: TBugType; SourceF: string; ErrFunc: string; ErrMessage: string; SourceLn: Integer; Offset: Integer);
  449. procedure CompileProject;
  450. procedure MakeFileWrapped;
  451. procedure MakeFile;
  452. function AddSourceFile(const FN: string; OpenOnly: Boolean = False; SourceFileClass: TSourceFileClass = nil; Folder: TFolder = nil): TSourceFile;
  453. function GetNewFileName(const FolderPath, Ext: string): string;
  454. procedure LoadPreferences;
  455. procedure SavePreferences;
  456. procedure BeginCompilation;
  457. procedure EndCompilation;
  458. procedure RecompileFiles;
  459. procedure UpdateEditButtons;
  460. procedure UpdateStatusBar;
  461. procedure UpdateFuncs;
  462. procedure UpdateDebugSettings;
  463. procedure SortFiles;
  464. procedure DisplayFolderMessage;
  465. procedure ClearDebugInfo;
  466. function GetVTIWindow: HWnd;
  467. function GetTiEmuInterface: ITiEmuOLE;
  468. procedure SendFiles(FNList: array of string);
  469. procedure ExecuteCommandLine(const Line: string);
  470. procedure SelectNode(Node: TTreeNode);
  471. procedure AddToRecent(const FileName: string);
  472. procedure UpdateRecent;
  473. procedure AddTool(const Title, CommandLine, WorkingDir: string; WindowState: TWindowState);
  474. function GetSourceTypeFolder(Node: TTreeNode): TTreeNode;
  475. function FindFileInsertionPoint(ParentNode: TTreeNode): TTreeNode;
  476. function CreateFileNode(ParentNode: TTreeNode; SourceFile: TSourceFile): TTreeNode;
  477. function GetSelectedFolder(SourceClass: TSourceFileClass): TFolder;
  478. {$IFDEF CODINGEXT}
  479. procedure InitCodingExt;
  480. procedure ActionFindSymbolExecute(Sender: TObject);
  481. {$ENDIF}
  482. end;
  483. var
  484. MainForm: TMainForm;
  485. type
  486. TRecentFileMenuItem = class(TObject)
  487. FileMenuItem: TMenuItem;
  488. PopupMenuItem: TMenuItem;
  489. public
  490. destructor Destroy; override;
  491. end;
  492. const
  493. MaxRecentFiles = 4;
  494. type
  495. TNoImageDragObject = class(TDragControlObject)
  496. public
  497. function GetDragImages: TDragImageList; override;
  498. procedure HideDragImage; override;
  499. procedure ShowDragImage; override;
  500. end;
  501. procedure LinkLibError(FileName, Text: PChar; MessageType: LongInt); cdecl;
  502. function LinkLibGetOutputFile(var DestFile: TLinkLibDestFile; FileSize, DestCalc, FileRole, FileFormat, FileType: LongInt; Extension: PChar; Executable: WordBool; var EffectiveSize: LongInt): WordBool; cdecl;
  503. implementation
  504. {$R *.DFM}
  505. {$R WindowsXP.res}
  506. uses
  507. CalcUnit, ParsingUnit, ProcessUnit,
  508. StartupScreenUnit, PreferencesUnit, ProjectOptionsUnit,
  509. AboutUnit, SourceFileWinUnit, FunctionsWinUnit,
  510. OpenFileStatusUnit, NewsUnit, SendProgressUnit, ToolsUnit,
  511. ProgramOutputUnit, VTIStartUnit, TIEmuStartUnit,
  512. LinkUnit,
  513. UtilsDos, UtilsWin, HandleWaitThreadUnit, FileReadToBufferThreadUnit,
  514. ShellAPI, ShlObj, IniFiles, Registry, WinSpool, ClipBrd{$IFDEF CODINGEXT}, CompletionForm{$ENDIF},
  515. ProgramOptionsUnit;
  516. const
  517. RegKey = '\Software\SeReSoft\TI-GCC IDE';
  518. type
  519. TFileRole = (frMain, frData);
  520. TLinkOutputFile = record
  521. Data: TMemoryStream;
  522. Tag: Byte;
  523. VarExt: string;
  524. ExeFile,
  525. OSUpgrade: Boolean;
  526. end;
  527. var
  528. ProcID: Cardinal;
  529. SendWin: HWnd;
  530. LinkOutputFiles: array [TCalcDest, TFileRole] of TLinkOutputFile;
  531. LinkDebugFile: TLinkOutputFile;
  532. function EnumWindowsFunc(Win: HWnd; Param: Integer): Bool; stdcall;
  533. var
  534. Name: array [0..32] of Char;
  535. NewProcID: DWord;
  536. begin
  537. Result := True;
  538. GetWindowThreadProcessID (Win, @NewProcID);
  539. if NewProcID = ProcID then begin
  540. GetClassName (Win, Name, 32);
  541. if Name = '#32770' then begin
  542. Result := False;
  543. SendWin := Win;
  544. end;
  545. end;
  546. end;
  547. procedure ErrorMessage(const Msg: string);
  548. begin
  549. if UpperCase (Copy (Msg, 1, Length ('ERROR:'))) = 'ERROR:' then
  550. MainForm.AddError (Msg, btError, '', '', Trim (Copy (Msg, Length ('ERROR:') + 1, Length (Msg))), 0, 0)
  551. else if UpperCase (Copy (Msg, 1, Length ('WARNING:'))) = 'WARNING:' then
  552. MainForm.AddError (Msg, btWarning, '', '', Trim (Copy (Msg, Length ('WARNING:') + 1, Length (Msg))), 0, 0);
  553. end;
  554. procedure LinkLibError(FileName, Text: PChar; MessageType: LongInt); cdecl;
  555. var
  556. BugTp: TBugType;
  557. ErrorLine: string;
  558. begin
  559. if MessageType = llmtError then
  560. BugTp := btError
  561. else
  562. BugTp := btWarning;
  563. ErrorLine := StringReplace (StrPas (Text), '`', '''', [rfReplaceAll]);
  564. MainForm.AddError (ErrorLine, BugTp, FileName, '', ErrorLine, 0, 0);
  565. end;
  566. function LinkLibGetOutputFile(var DestFile: TLinkLibDestFile; FileSize, DestCalc, FileRole, FileFormat, FileType: LongInt; Extension: PChar; Executable: WordBool; var EffectiveSize: LongInt): WordBool; cdecl;
  567. var
  568. CalcDest: TCalcDest;
  569. CalcFileRole: TFileRole;
  570. begin
  571. Result := False;
  572. case FileFormat of
  573. llffTIOS:
  574. EffectiveSize := 2 + FileSize + 1;
  575. llffTIOSUpgrade:
  576. EffectiveSize := FileSize + SizeOf (TCalcOSFooter);
  577. llffGDBCOFF:
  578. begin
  579. EffectiveSize := FileSize;
  580. with LinkDebugFile do begin
  581. if not Assigned (Data) then
  582. Data := TMemoryStream.Create;
  583. Data.Size := FileSize;
  584. DestFile.Data := Data.Memory;
  585. end;
  586. Result := True;
  587. Exit;
  588. end;
  589. else
  590. Exit;
  591. end;
  592. case DestCalc of
  593. llcdTI89: CalcDest := cdTI89;
  594. llcdTI89 or llcdFlagTitanium: CalcDest := cdTI89Titanium;
  595. llcdTI92Plus: CalcDest := cdTI92Plus;
  596. llcdV200: CalcDest := cdV200;
  597. llcdTI92: CalcDest := cdTI92;
  598. else
  599. Exit;
  600. end;
  601. case FileRole of
  602. llfrMain: CalcFileRole := frMain;
  603. llfrData: CalcFileRole := frData;
  604. else
  605. Exit;
  606. end;
  607. with LinkOutputFiles [CalcDest, CalcFileRole] do begin
  608. if not Assigned (Data) then
  609. Data := TMemoryStream.Create;
  610. Data.Size := FileSize;
  611. DestFile.Data := Data.Memory;
  612. Tag := FileType;
  613. if Assigned (Extension) then begin
  614. VarExt := Extension;
  615. Inc (EffectiveSize, Length (VarExt) + 2);
  616. end else
  617. VarExt := '';
  618. ExeFile := Executable;
  619. OSUpgrade := (FileFormat = llffTIOSUpgrade);
  620. end;
  621. Result := True;
  622. end;
  623. { Fix for TPanel & XP Theme }
  624. procedure TPanel.Paint;
  625. begin
  626. Canvas.Pen.Style := psClear;
  627. Canvas.Brush.Color := Color;
  628. Canvas.FillRect(GetClientRect);
  629. inherited;
  630. end;
  631. { TRecentFileMenuItem }
  632. destructor TRecentFileMenuItem.Destroy;
  633. begin
  634. FileMenuItem.Free;
  635. PopupMenuItem.Free;
  636. inherited;
  637. end;
  638. { TNoImageDragObject }
  639. function TNoImageDragObject.GetDragImages: TDragImageList;
  640. begin
  641. Result := nil;
  642. end;
  643. procedure TNoImageDragObject.HideDragImage;
  644. begin
  645. end;
  646. procedure TNoImageDragObject.ShowDragImage;
  647. begin
  648. end;
  649. { TMainForm }
  650. procedure TMainForm.Modify;
  651. begin
  652. Modified := True;
  653. end;
  654. procedure TMainForm.FormCreate(Sender: TObject);
  655. var
  656. TempDir: array [0..255] of Char;
  657. S: string;
  658. TempLockData: TWin32FindData;
  659. begin
  660. StartingAppNow := True;
  661. try
  662. if Assigned (StartupScreenForm) then
  663. StartupScreenForm.DisplayText := 'Setting Up Environment...';
  664. Application.OnException := AppException;
  665. WindowState := wsMaximized;
  666. RecentFiles := TStringList.Create;
  667. DocFile := THTMLHelp.Create(Self);
  668. ToolsList := TToolsList.Create (Self, TToolsListItem);
  669. TIGCCFolder := ExtractFilePath (ParamStr (0));
  670. Delete (TIGCCFolder, Pos (UpperCase (IDELocation), UpperCase (TIGCCFolder)), Length (TIGCCFolder));
  671. with TRegistry.Create do try
  672. RootKey := HKey_Local_Machine;
  673. if OpenKeyReadOnly ('\Software\GCC4TI Team\GCC4TI') then try
  674. if ValueExists ('Program Folder') then
  675. TIGCCFolder := ReadString ('Program Folder');
  676. except end;
  677. finally
  678. Free;
  679. end;
  680. try
  681. if FileExists (WithBackslash (TIGCCFolder) + A68kLocation + 'A68k.exe') then
  682. Include (SpecialSupport, ssA68k);
  683. except end;
  684. try
  685. if FileExists (WithBackslash (TIGCCFolder) + QuillIncludeLocation + 'Quill.drv')
  686. or FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + 'Quill.drv')
  687. or FileExists (WithBackslash (TIGCCFolder) + GCCLocation + 'Quill.drv') then
  688. Include (SpecialSupport, ssQuill);
  689. except end;
  690. try
  691. if FileExists (WithBackslash (TIGCCFolder) + PackLocation + 'Pack.exe') then
  692. Include (SpecialSupport, ssPack);
  693. except end;
  694. try
  695. if FileExists (WithBackslash (TIGCCFolder) + StdLibLocation + 'flashos.a') then
  696. Include (SpecialSupport, ssFlashOS);
  697. except end;
  698. try
  699. if FileExists (WithBackslash (TIGCCFolder) + StdLibLocation + 'fargo.a') then
  700. Include (SpecialSupport, ssFargo);
  701. except end;
  702. CompStartFile := AppCompStartFile;
  703. CompStop := AppCompStop;
  704. CompSetMessage := AppCompSetMessage;
  705. CompUpdate := AppCompUpdate;
  706. CompUpdateProgramOutput := UpdateProgramOutput;
  707. LinkLibHandle := LoadLibrary (PChar (WithBackslash (TIGCCFolder) + LinkLibLocation + 'Link.dll'));
  708. if LinkLibHandle <> 0 then begin
  709. LinkLibGetInterfaceVersion := GetProcAddress (LinkLibHandle, 'GetInterfaceVersion');
  710. if Assigned (LinkLibGetInterfaceVersion) and (LinkLibGetInterfaceVersion = LinkLibCurInterfaceVersion) then begin
  711. LinkLibLinkFiles := GetProcAddress (LinkLibHandle, 'LinkFiles');
  712. LinkLibCreateArchive := GetProcAddress (LinkLibHandle, 'CreateArchive');
  713. end;
  714. end;
  715. SourceFiles := TSourceFiles.Create;
  716. SyntaxCBackup := TSyntaxColoring.Create (nil);
  717. SyntaxCBackup.Assign (SyntaxC);
  718. SyntaxAsmGNUBackup := TSyntaxColoring.Create (nil);
  719. SyntaxAsmGNUBackup.Assign (SyntaxAsmGNU);
  720. SyntaxAsmBackup := TSyntaxColoring.Create (nil);
  721. if ssA68k in SpecialSupport then
  722. SyntaxAsmBackup.Assign (SyntaxAsm);
  723. SyntaxQuillBackup := TSyntaxColoring.Create (nil);
  724. if ssQuill in SpecialSupport then
  725. SyntaxQuillBackup.Assign (SyntaxQuill);
  726. TopNode := ProjectTree.Items.Item [0];
  727. SourceFileUnit.AppNode := TopNode;
  728. SourceFileUnit.NoEditor := NoEditor;
  729. OriginalCaption := Caption;
  730. Application.OnHint := DisplayHint;
  731. if ssA68k in SpecialSupport then begin
  732. ActionFileNewA68kAsmHeaderFile.Visible := True;
  733. ActionFileNewA68kAsmFile.Visible := True;
  734. with ProjectTree.Items.Insert (TopNode.Item [TAsmSourceFile.GetClassTreeIndex], 'A68k Assembly Files') do begin
  735. ImageIndex := TopNode.Item[0].ImageIndex;
  736. SelectedIndex := TopNode.Item[0].SelectedIndex;
  737. end;
  738. end;
  739. if ssQuill in SpecialSupport then begin
  740. ActionFileNewQuillFile.Visible := True;
  741. S := OpenProjectDlg.Filter;
  742. Insert (TQuillSourceFile.GetClassFilter + '|', S, Pos (TNormalTextSourceFile.GetClassFilter, S));
  743. while Pos ('*.asm;*.txt', S) > 0 do
  744. Insert (';*.qll', S, Pos ('*.asm;*.txt', S) + Length ('*.asm'));
  745. OpenProjectDlg.Filter := S;
  746. OpenProjectDlg.FilterIndex := OpenProjectDlg.FilterIndex + 1;
  747. S := AddFileDlg.Filter;
  748. Insert (TQuillSourceFile.GetClassFilter + '|', S, Pos (TObjectSourceFile.GetClassFilter, S));
  749. while Pos ('*.asm;*.o', S) > 0 do
  750. Insert (';*.qll', S, Pos ('*.asm;*.o', S) + Length ('*.asm'));
  751. AddFileDlg.Filter := S;
  752. AddFileDlg.FilterIndex := AddFileDlg.FilterIndex + 1;
  753. with ProjectTree.Items.Insert (TopNode.Item [TQuillSourceFile.GetClassTreeIndex], 'Quill Files') do begin
  754. ImageIndex := TopNode.Item[0].ImageIndex;
  755. SelectedIndex := TopNode.Item[0].SelectedIndex;
  756. end;
  757. end;
  758. ProjectTree.FullExpand;
  759. ResetProjectSettings;
  760. AssumeUndefined := False;
  761. AutoSave := True;
  762. AutoNews := False;
  763. LastNewsDate := 0;
  764. GetTempPath (SizeOf (TempDir), TempDir);
  765. Temp := AnsiString (TempDir);
  766. if (Length (Temp) <= 0) or (not DirExists (Temp)) then begin
  767. GetEnvironmentVariable ('TMP', TempDir, SizeOf (TempDir));
  768. Temp := AnsiString (TempDir);
  769. end;
  770. if (Length (Temp) <= 0) or (not DirExists (Temp)) then begin
  771. GetEnvironmentVariable ('TEMP', TempDir, SizeOf (TempDir));
  772. Temp := AnsiString (TempDir);
  773. end;
  774. if (Length (Temp) <= 0) or (Length (Temp) > 30) or (Pos (' ', Temp) > 0) or (Pos ('TEMP', UpperCase (Temp)) <= 0) then begin
  775. GetWindowsDirectory (TempDir, SizeOf (TempDir));
  776. Temp := WithBackslash (AnsiString (TempDir)) + 'TEMP\';
  777. if not DirExists (Temp) then try
  778. MkDir (Temp);
  779. except end;
  780. end;
  781. if (Length (Temp) <= 0) or (Length (Temp) > 30) or (Pos (' ', Temp) > 0) then begin
  782. Temp := 'C:\TEMP\';
  783. if not DirExists (Temp) then try
  784. MkDir (Temp);
  785. except end;
  786. end;
  787. Temp := WithBackslash (Temp) + IntToHex (GetCurrentProcessID, 8) + '\';
  788. if not DirExists (Temp) then try
  789. MkDir (Temp);
  790. except end;
  791. TempLockHandle := Windows.FindFirstFile (PChar (Temp + '*.*'), TempLockData);
  792. StopOnErrors := False;
  793. JumpToError := True;
  794. OpenFolderMessage := True;
  795. DeleteAssemblyFiles := True;
  796. DeleteObjectFiles := False;
  797. {$IFDEF CanSplit}
  798. SplitFiles := True;
  799. {$ENDIF}
  800. DeleteErrors := True;
  801. TransferTarget := ttTIEmu;
  802. LinkPort.PortType := lpCOM;
  803. LinkPort.PortNumber := 1;
  804. LinkCable := lcBlack;
  805. TabSizeAsm := 8;
  806. TabSizeC := 2;
  807. AutoBlocks := True;
  808. EditorOnFly := True;
  809. EditorDragDrop := True;
  810. if Assigned (StartupScreenForm) then
  811. StartupScreenForm.DisplayText := 'Loading Preferences...';
  812. try
  813. LoadPreferences;
  814. except
  815. ShowDefaultMessageBox ('An error occured while loading the preferences. Some parts of the program may not be configured correctly.', 'Error', mtProgramError);
  816. end;
  817. DocFile.FileName := WithBackslash (TIGCCFolder) + DocLocation + 'TIGCC.chm';
  818. if DirExists (WithBackslash (TIGCCFolder) + ProjectsLocation) then
  819. OpenProjectDlg.InitialDir := WithBackslash (TIGCCFolder) + ProjectsLocation
  820. else
  821. OpenProjectDlg.InitialDir := TIGCCFolder;
  822. SaveProjectDlg.InitialDir := OpenProjectDlg.InitialDir;
  823. AddFileDlg.InitialDir := OpenProjectDlg.InitialDir;
  824. DragAcceptFiles (Handle, True);
  825. ParsingUnit.ErrorMessageProc := ErrorMessage;
  826. S := '';
  827. if ParamCount > 0 then begin
  828. if LowerCase (ExtractFileExt (ParamStr (1))) = LowerCase (ProjectFileExt) then
  829. ProjectFile := ExpandFileName (ParamStr (1))
  830. else
  831. S := ExpandFileName (ParamStr (1));
  832. end;
  833. if Length (ProjectFile) > 0 then begin
  834. if Assigned (StartupScreenForm) then
  835. StartupScreenForm.DisplayText := 'Opening Project...';
  836. FileLoad;
  837. end;
  838. if Length (S) > 0 then
  839. AddSourceFile (S, True);
  840. if AutoNews then begin
  841. if Assigned (StartupScreenForm) then
  842. StartupScreenForm.DisplayText := 'Downloading Headlines...';
  843. with TNewsForm.Create (Self) do begin
  844. SilentConnect := True;
  845. Connect;
  846. end;
  847. end;
  848. except
  849. ShowDefaultMessageBox ('An error occured while setting up the application. Some parts of the program may not be configured correctly.', 'Error', mtProgramError);
  850. end;
  851. StartingAppNow := False;
  852. {$IFDEF CODINGEXT}
  853. InitCodingExt;
  854. {$ENDIF}
  855. end;
  856. procedure TMainForm.FormDestroy(Sender: TObject);
  857. var
  858. I: Integer;
  859. begin
  860. Closing := True;
  861. ClearDebugInfo;
  862. ErrorList.Items.Clear;
  863. SourceFiles.Free;
  864. SyntaxQuillBackup.Free;
  865. SyntaxAsmBackup.Free;
  866. SyntaxAsmGNUBackup.Free;
  867. SyntaxCBackup.Free;
  868. if LinkLibHandle <> 0 then
  869. FreeLibrary (LinkLibHandle);
  870. if TempLockHandle <> INVALID_HANDLE_VALUE then
  871. Windows.FindClose (TempLockHandle);
  872. try
  873. RmDir (Temp);
  874. except end;
  875. ToolsList.Free;
  876. with RecentFiles do begin
  877. for I := Count - 1 downto 0 do
  878. Objects[I].Free;
  879. Free;
  880. end;
  881. end;
  882. procedure TMainForm.AppException(Sender: TObject; E: Exception);
  883. begin
  884. if not (E is ESocketError) then
  885. ShowDefaultMessageBox ('Internal Error: Exception ' + E.ClassName + ', Message "' + E.Message + '"'#13#10#13#10'Please fill out a bug report form at http://tigcc.ticalc.org/.', 'Internal Error', mtProgramError);
  886. end;
  887. procedure TMainForm.ProjectTreeEditing(Sender: TObject; Node: TTreeNode;
  888. var AllowEdit: Boolean);
  889. begin
  890. AllowEdit := Assigned (Node.Data) or not Assigned (Node.Parent);
  891. end;
  892. procedure TMainForm.ProjectAddFiles(Sender: TObject);
  893. var
  894. I: Integer;
  895. F: TSourceFile;
  896. begin
  897. if AddFileDlg.Execute then begin
  898. for I := AddFileDlg.Files.Count - 1 downto 0 do begin
  899. F := AddSourceFile(ExpandFileName(AddFileDlg.Files[I]));
  900. if (I = 0) and Assigned (F) and Assigned (F.TreeItem) then
  901. SelectNode (F.TreeItem);
  902. end;
  903. Modify;
  904. end else
  905. Abort;
  906. end;
  907. procedure TMainForm.ProjectTreeChange(Sender: TObject; Node: TTreeNode);
  908. var
  909. NewSelection: TTreeNode;
  910. NewEditor: TWinControl;
  911. IsMemo,
  912. DataItem,
  913. BinaryType: Boolean;
  914. begin
  915. NewSelection := ProjectTree.Selected;
  916. PreviousNode := NewSelection;
  917. if not Closing then begin
  918. if Assigned (NewSelection) and Assigned (NewSelection.Data) and (TObject (NewSelection.Data) is TSourceFile) then
  919. NewEditor := TSourceFile(NewSelection.Data).Editor
  920. else
  921. NewEditor := NoEditor;
  922. if Assigned (EditorToHide) and (EditorToHide <> NewEditor) then
  923. EditorToHide.Align := alNone;
  924. if NewEditor.Parent <> EditorPanel then
  925. NewEditor.Parent := EditorPanel;
  926. if NewEditor.Align <> alClient then
  927. NewEditor.Align := alClient;
  928. IsMemo := NewEditor is TMemoComponent;
  929. if IsMemo then begin
  930. with TMemoComponent (NewEditor) do begin
  931. DrawingSuspended := True;
  932. OnEnter := EditorEnter;
  933. OnExit := EditorExit;
  934. OnKeyDown := EditorKeyDown;
  935. OnChange := EditorChange;
  936. OnSelectionChange := EditorChange;
  937. PopupMenu := EditorPopup;
  938. end;
  939. end;
  940. NewEditor.Show;
  941. Update;
  942. if IsMemo then
  943. with TMemoComponent (NewEditor) do begin
  944. DrawingSuspended := False;
  945. Repaint;
  946. end;
  947. if Assigned (EditorToHide) and (EditorToHide <> NewEditor) then
  948. EditorToHide.Hide;
  949. EditorToHide := nil;
  950. DataItem := Assigned (NewSelection) and Assigned (NewSelection.Data);
  951. Node := GetSourceTypeFolder (NewSelection);
  952. BinaryType := Assigned (Node) and ((Node.Index = TObjectSourceFile.GetClassTreeIndex) or (Node.Index = TArchiveSourceFile.GetClassTreeIndex) or (Node.Index = TOtherSourceFile.GetClassTreeIndex));
  953. ActionFileNewFolder.Enabled := Assigned (NewSelection) and Assigned (NewSelection.Parent);
  954. ActionTreeItemNewFolder.Enabled := ActionFileNewFolder.Enabled;
  955. ActionFileNewFile.Enabled := ActionFileNewFolder.Enabled and (not BinaryType);
  956. ActionTreeItemNewFile.Enabled := ActionFileNewFile.Enabled;
  957. if ActiveControl = ProjectTree then
  958. ActionEditDelete.Enabled := DataItem;
  959. ActionFilePrint.Enabled := DataItem and (TObject (NewSelection.Data) is TSourceFile) and TSourceFile(NewSelection.Data).Printable and (Printer.Printers.Count > 0);
  960. ActionFilePrintQuickly.Enabled := ActionFilePrint.Enabled;
  961. ActionFindFunctions.Enabled := DataItem and (TObject (NewSelection.Data) is TSourceTextSourceFile);
  962. UpdateStatusBar;
  963. end;
  964. end;
  965. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  966. begin
  967. if Compiling then
  968. CanClose := False
  969. else
  970. try
  971. WarnIfModified;
  972. SavePreferences;
  973. except
  974. CanClose := False;
  975. end;
  976. end;
  977. procedure TMainForm.WarnIfModified;
  978. var
  979. I: Integer;
  980. begin
  981. if Modified then
  982. case ShowDefaultMessageBox
  983. ('The current project has been modified. Do you want to save the changes?',
  984. 'Project Modified', mtQuestion, True) of
  985. idYes: FileSave;
  986. idCancel: Abort;
  987. end;
  988. with SourceFiles do
  989. for I := 0 to Count - 1 do
  990. with Items [I] as TSourceFile do
  991. WarnIfModified;
  992. end;
  993. procedure TMainForm.FileLoad;
  994. function StringToRelocFormat(const S: string): TRelocFormat;
  995. begin
  996. if S = 'None' then
  997. Result := rfNone
  998. else if S = 'Direct' then
  999. Result := rfDirect
  1000. else if S = 'AMS' then
  1001. Result := rfAMS
  1002. else if S = 'Kernel' then
  1003. Result := rfKernel
  1004. else if S = 'Compressed' then
  1005. Result := rfCompressed
  1006. else if S = 'MLink' then
  1007. Result := rfMLink
  1008. else if S = 'F-Line' then
  1009. Result := rfFLine
  1010. else
  1011. Result := rfUnknown;
  1012. end;
  1013. var
  1014. F: TOpenFileStatusForm;
  1015. I,
  1016. J,
  1017. Ps: Integer;
  1018. S,
  1019. P: string;
  1020. SL: TStringList;
  1021. Folder: TFolder;
  1022. Node,
  1023. SubNode: TTreeNode;
  1024. CurrentFile: TSourceFile;
  1025. begin
  1026. if not Compiling then begin
  1027. WarnIfModified;
  1028. Modified := False;
  1029. OpeningProjectNow := True;
  1030. Update;
  1031. F := nil;
  1032. ProjectTree.Items.BeginUpdate;
  1033. S := ProjectFile;
  1034. try
  1035. FileClear;
  1036. if (Length (S) > 0) and FileExists (S) then begin
  1037. if not StartingAppNow then begin
  1038. try
  1039. F := TOpenFileStatusForm.Create (Self);
  1040. except
  1041. F := nil;
  1042. end;
  1043. if Assigned (F) then begin
  1044. P := ExtractFileName (S);
  1045. F.FileNameLabel.Caption := 'Opening Project ''' + Copy (P, 1, LastPos ('.', P) - 1) + '''...';
  1046. F.Show;
  1047. F.Update;
  1048. end;
  1049. end;
  1050. SHAddToRecentDocs(SHARD_PATH, PChar (S));
  1051. with TIniFile.Create (S) do try
  1052. TopNode.Text := ReadString ('Settings', 'Project Name', 'Project1');
  1053. ProjectFile := S;
  1054. if ReadBool ('Settings', 'Archive', False) then
  1055. ProjectTarget := ptArchive
  1056. else if ReadBool ('Settings', 'Flash OS', False) then
  1057. ProjectTarget := ptFlashOS
  1058. else if ReadBool ('Settings', 'Fargo', False) then
  1059. ProjectTarget := ptFargo;
  1060. UseDataVar := ReadBool ('Settings', 'Use Data Variable', False);
  1061. DataVar := ReadString ('Settings', 'Data Variable', '');
  1062. DataVarCopy := ReadBool ('Settings', 'Copy Data Variable', True);
  1063. DataVarCopyIfArchived := ReadBool ('Settings', 'Copy Data Variable if Archived', True);
  1064. Pack := ReadBool ('Settings', 'Pack', False);
  1065. PackVar := ReadString ('Settings', 'Packed Variable', '');
  1066. GCCSwitches := ReadString ('Settings', 'GCC Switches', '');
  1067. AsSwitches := ReadString ('Settings', 'GNU Assembler Switches', '');
  1068. AsmSwitches := ReadString ('Settings', 'Assembler Switches', '');
  1069. DebugInfo := ReadBool ('Settings', 'Debug Info', False);
  1070. StdLib := ReadBool ('Settings', 'Standard Library', True);
  1071. InitBSS := ReadBool ('Settings', 'Initialize BSS', True);
  1072. OptimizeNOPs := ReadBool ('Settings', 'Optimize NOPs', True);
  1073. OptimizeReturns := ReadBool ('Settings', 'Optimize Returns', True);
  1074. OptimizeBranches := ReadBool ('Settings', 'Optimize Branches', True);
  1075. OptimizeMoves := ReadBool ('Settings', 'Optimize Moves', True);
  1076. OptimizeTests := ReadBool ('Settings', 'Optimize Tests', True);
  1077. OptimizeCalculations := ReadBool ('Settings', 'Optimize Calculations', True);
  1078. RemoveUnusedSections := ReadBool ('Settings', 'Remove Unused Sections', True);
  1079. CutUnusedRanges := ReadBool ('Settings', 'Cut Unused Ranges', True);
  1080. ReorderSections := ReadBool ('Settings', 'Reorder Sections', True);
  1081. MergeConstants := ReadBool ('Settings', 'Merge Constants', True);
  1082. OutputBin := ReadBool ('Settings', 'Binary Output', False);
  1083. CommandLine := ReadString ('Settings', 'Command Line', '');
  1084. PostBuildProcessFile := ReadString ('Settings', 'Post-Build Process', '');
  1085. while Pos ('`', PostBuildProcessFile) > 0 do
  1086. PostBuildProcessFile [Pos ('`', PostBuildProcessFile)] := '"';
  1087. if Assigned (PredefinedLibOptions) then
  1088. with PredefinedLibOptions do begin
  1089. CalcDests := [];
  1090. if ReadBool ('Library Options', 'Use TI-89', False) then
  1091. Include (CalcDests, cdTI89);
  1092. if ReadBool ('Library Options', 'Use TI-92 Plus', False) then
  1093. Include (CalcDests, cdTI92Plus);
  1094. if ReadBool ('Library Options', 'Use V200', False) then
  1095. Include (CalcDests, cdV200);
  1096. OptimizeCalcConsts := ReadBool ('Library Options', 'Optimize Calc Consts', False);
  1097. if ReadBool ('Library Options', 'Use PreOS', False) then
  1098. KernelFormat := kfCompressedTables
  1099. else if ReadBool ('Library Options', 'Use Kernel', False) then
  1100. KernelFormat := kfStandard
  1101. else
  1102. KernelFormat := kfNone;
  1103. UseMinAMS := ReadBool ('Library Options', 'Minimum AMS Version Defined', False);
  1104. MinAMS := ReadString ('Library Options', 'Minimum AMS Version', '1.00');
  1105. UnofficialOSSupport := ReadBool ('Library Options', 'Unofficial OS Support', False);
  1106. RelocFormat := StringToRelocFormat (ReadString ('Library Options', 'Reloc Format', ''));
  1107. ROMCallFormat := StringToRelocFormat (ReadString ('Library Options', 'ROM Call Format', ''));
  1108. BSSRefFormat := StringToRelocFormat (ReadString ('Library Options', 'BSS Ref Format', ''));
  1109. DataRefFormat := StringToRelocFormat (ReadString ('Library Options', 'Data Ref Format', ''));
  1110. UseFLineJumps := ReadBool ('Library Options', 'Use F-Line Jumps', False);
  1111. Use4ByteFLineJumps := ReadBool ('Library Options', 'Use 4-Byte F-Line Jumps', False);
  1112. OptimizeROMCalls := ReadBool ('Library Options', 'Optimize ROM Calls', False);
  1113. UseInternalFLineEmulator := ReadBool ('Library Options', 'Use Internal F-Line Emulator', False);
  1114. UseReturnValue := ReadBool ('Library Options', 'Use Return Value', False);
  1115. EnableErrorReturn := ReadBool ('Library Options', 'Enable Error Return', False);
  1116. SaveScreen := ReadBool ('Library Options', 'Save Screen', False);
  1117. end;
  1118. SL := TStringList.Create;
  1119. try
  1120. ReadSection ('Included Files', SL);
  1121. for I := 0 to SL.Count - 1 do begin
  1122. P := SL.Strings [I];
  1123. S := ReadString ('Included Files', P, '');
  1124. if Length (S) > 0 then begin
  1125. if Copy (P, Length (P) - Length (' Folder') + 1, Length (P)) = ' Folder' then begin
  1126. Delete (P, Length (P) - Length (' Folder') + 1, Length (P));
  1127. J := SL.IndexOf (P);
  1128. if J >= 0 then begin
  1129. Node := TopNode.Item [TSourceFile.GetAppropriateClassFromName (Copy (P, 1, LastPos (' ', P) - 1)).GetClassTreeIndex];
  1130. repeat
  1131. Ps := Pos ('\', S);
  1132. if Ps > 0 then
  1133. P := Copy (S, 1, Ps - 1)
  1134. else
  1135. P := S;
  1136. SubNode := Node.GetFirstChild;
  1137. while Assigned (SubNode) and ((not Assigned (SubNode.Data)) or (not (TObject (SubNode.Data) is TFolder)) or (SubNode.Text <> P)) do
  1138. SubNode := SubNode.GetNextSibling;
  1139. if Assigned (SubNode) then
  1140. Node := SubNode
  1141. else begin
  1142. Folder := TFolder.Create;
  1143. Node := ProjectTree.Items.AddChildObject (Node, P, Folder);
  1144. Folder.TreeItem := Node;
  1145. with Node do begin
  1146. ImageIndex := 0;
  1147. SelectedIndex := 1;
  1148. end;
  1149. end;
  1150. Delete (S, 1, Length (P) + 1);
  1151. until Length (S) <= 0;
  1152. SL.Objects [J] := Node.Data;
  1153. end;
  1154. end;
  1155. end;
  1156. end;
  1157. for I := 0 to SL.Count - 1 do begin
  1158. P := SL.Strings [I];
  1159. S := ReadString ('Included Files', P, '');
  1160. if Length (S) > 0 then begin
  1161. if Copy (P, Length (P) - Length (' Folder') + 1, Length (P)) <> ' Folder' then begin
  1162. if Pos (':', S) <= 0 then
  1163. S := ExtractFilePath (ProjectFile) + S;
  1164. if FileExists (S) then
  1165. AddSourceFile (S, False, TSourceFile.GetAppropriateClassFromName (Copy (P, 1, LastPos (' ', P) - 1)), TFolder (SL.Objects [I]))
  1166. else
  1167. ShowDefaultMessageBox ('File not found:'#13#10#13#10 + S, 'Error', mtProgramError);
  1168. end;
  1169. end;
  1170. end;
  1171. finally
  1172. SL.Free;
  1173. end;
  1174. S := ReadString ('File Editing', 'Open File', '');
  1175. if Length (S) > 0 then begin
  1176. CurrentFile := SourceFiles.FindFile (S);
  1177. if Assigned (CurrentFile) then
  1178. CurrentFile.Edit;
  1179. end;
  1180. finally
  1181. Free;
  1182. end;
  1183. ProjectTree.FullExpand;
  1184. NoEditor.Show;
  1185. UpdateDebugSettings;
  1186. AddToRecent (ProjectFile);
  1187. end;
  1188. SortFiles;
  1189. finally
  1190. ProjectTree.Items.EndUpdate;
  1191. OpeningProjectNow := False;
  1192. if Assigned (F) then
  1193. F.Free;
  1194. end;
  1195. Modified := False;
  1196. end;
  1197. end;
  1198. procedure TMainForm.FileNew;
  1199. begin
  1200. if not Compiling then begin
  1201. WarnIfModified;
  1202. Modified := False;
  1203. ProjectFile := '';
  1204. FileClear;
  1205. end;
  1206. end;
  1207. procedure TMainForm.FileClear;
  1208. procedure TryDeleteNode(Node: TTreeNode);
  1209. var
  1210. I: Integer;
  1211. begin
  1212. with Node do begin
  1213. for I := Count - 1 downto 0 do
  1214. TryDeleteNode (Item [I]);
  1215. if Assigned (Data) then
  1216. Delete;
  1217. end;
  1218. end;
  1219. begin
  1220. if not Compiling then begin
  1221. WarnIfModified;
  1222. Modified := False;
  1223. Invalidated := True;
  1224. ActiveControl := ProjectTree;
  1225. ErrorList.Items.BeginUpdate;
  1226. ErrorList.Items.Clear;
  1227. ErrorList.Items.EndUpdate;
  1228. ProjectTree.Items.BeginUpdate;
  1229. ClearDebugInfo;
  1230. TopNode.Text := 'Project1';
  1231. SelectNode (TopNode);
  1232. TryDeleteNode (TopNode);
  1233. ProjectTree.FullExpand;
  1234. ProjectTree.Items.EndUpdate;
  1235. ResetProjectSettings;
  1236. NoEditor.Show;
  1237. UpdateDebugSettings;
  1238. Update;
  1239. Modified := False;
  1240. end;
  1241. end;
  1242. procedure TMainForm.FileOpen(const FN: string);
  1243. begin
  1244. if not Compiling then begin
  1245. WarnIfModified;
  1246. Modified := False;
  1247. ProjectTree.Items.BeginUpdate;
  1248. ProjectFile := FN;
  1249. FileLoad;
  1250. ProjectTree.Items.EndUpdate;
  1251. end;
  1252. end;
  1253. procedure TMainForm.FileSave;
  1254. function RelocFormatToString(RelocFormat: TRelocFormat): string;
  1255. begin
  1256. case RelocFormat of
  1257. rfNone: Result := 'None';
  1258. rfDirect: Result := 'Direct';
  1259. rfAMS: Result := 'AMS';
  1260. rfKernel: Result := 'Kernel';
  1261. rfCompressed: Result := 'Compressed';
  1262. rfMLink: Result := 'MLink';
  1263. rfFLine: Result := 'F-Line';
  1264. else Result := 'Unknown';
  1265. end;
  1266. end;
  1267. var
  1268. I,
  1269. ClassCount: Integer;
  1270. S: string;
  1271. SL: TStringList;
  1272. begin
  1273. if ProjectFile = '' then
  1274. FileSaveProjectAs (Self)
  1275. else begin
  1276. try
  1277. with SourceFiles do
  1278. for I := 0 to Count - 1 do
  1279. with Items [I] as TSourceFile do begin
  1280. if UpperCase (ExtractFilePath (FileName)) = 'C:\' then
  1281. FileName := ExtractFilePath (ProjectFile) + LogicalFileName;
  1282. if Modified or not FileExists (FileName) then
  1283. Save;
  1284. end;
  1285. with TIniFile.Create (ProjectFile) do try
  1286. WriteBool ('Settings', 'Archive', ProjectTarget = ptArchive);
  1287. WriteBool ('Settings', 'Flash OS', ProjectTarget = ptFlashOS);
  1288. WriteBool ('Settings', 'Fargo', ProjectTarget = ptFargo);
  1289. WriteBool ('Settings', 'Use Data Variable', UseDataVar);
  1290. WriteString ('Settings', 'Data Variable', DataVar);
  1291. WriteBool ('Settings', 'Copy Data Variable', DataVarCopy);
  1292. WriteBool ('Settings', 'Copy Data Variable if Archived', DataVarCopyIfArchived);
  1293. WriteBool ('Settings', 'Pack', Pack);
  1294. WriteString ('Settings', 'Packed Variable', PackVar);
  1295. WriteString ('Settings', 'Project Name', TopNode.Text);
  1296. WriteString ('Settings', 'GCC Switches', GCCSwitches);
  1297. WriteString ('Settings', 'GNU Assembler Switches', AsSwitches);
  1298. WriteString ('Settings', 'Assembler Switches', AsmSwitches);
  1299. WriteBool ('Settings', 'Debug Info', DebugInfo);
  1300. WriteBool ('Settings', 'Standard Library', StdLib);
  1301. WriteBool ('Settings', 'Initialize BSS', InitBSS);
  1302. WriteBool ('Settings', 'Optimize NOPs', OptimizeNOPs);
  1303. WriteBool ('Settings', 'Optimize Returns', OptimizeReturns);
  1304. WriteBool ('Settings', 'Optimize Branches', OptimizeBranches);
  1305. WriteBool ('Settings', 'Optimize Moves', OptimizeMoves);
  1306. WriteBool ('Settings', 'Optimize Tests', OptimizeTests);
  1307. WriteBool ('Settings', 'Optimize Calculations', OptimizeCalculations);
  1308. WriteBool ('Settings', 'Remove Unused Sections', RemoveUnusedSections);
  1309. WriteBool ('Settings', 'Cut Unused Ranges', CutUnusedRanges);
  1310. WriteBool ('Settings', 'Reorder Sections', ReorderSections);
  1311. WriteBool ('Settings', 'Merge Constants', MergeConstants);
  1312. WriteBool ('Settings', 'Binary Output', OutputBin);
  1313. WriteString ('Settings', 'Command Line', CommandLine);
  1314. S := PostBuildProcessFile;
  1315. while Pos ('"', S) > 0 do
  1316. S [Pos ('"', S)] := '`';
  1317. WriteString ('Settings', 'Post-Build Process', S);
  1318. if Assigned (PredefinedLibOptions) then
  1319. with PredefinedLibOptions do begin
  1320. WriteBool ('Library Options', 'Use TI-89', cdTI89 in CalcDests);
  1321. WriteBool ('Library Options', 'Use TI-92 Plus', cdTI92Plus in CalcDests);
  1322. WriteBool ('Library Options', 'Use V200', cdV200 in CalcDests);
  1323. WriteBool ('Library Options', 'Optimize Calc Consts', OptimizeCalcConsts);
  1324. WriteBool ('Library Options', 'Use Kernel', KernelFormat <> kfNone);
  1325. WriteBool ('Library Options', 'Use PreOS', KernelFormat = kfCompressedTables);
  1326. WriteBool ('Library Options', 'Minimum AMS Version Defined', UseMinAMS);
  1327. WriteString ('Library Options', 'Minimum AMS Version', MinAMS);
  1328. WriteBool ('Library Options', 'Unofficial OS Support', UnofficialOSSupport);
  1329. WriteString ('Library Options', 'Reloc Format', RelocFormatToString (RelocFormat));
  1330. WriteString ('Library Options', 'ROM Call Format', RelocFormatToString (ROMCallFormat));
  1331. WriteString ('Library Options', 'BSS Ref Format', RelocFormatToString (BSSRefFormat));
  1332. WriteString ('Library Options', 'Data Ref Format', RelocFormatToString (DataRefFormat));
  1333. WriteBool ('Library Options', 'Use F-Line Jumps', UseFLineJumps);
  1334. WriteBool ('Library Options', 'Use 4-Byte F-Line Jumps', Use4ByteFLineJumps);
  1335. WriteBool ('Library Options', 'Optimize ROM Calls', OptimizeROMCalls);
  1336. WriteBool ('Library Options', 'Use Internal F-Line Emulator', UseInternalFLineEmulator);
  1337. WriteBool ('Library Options', 'Use Return Value', UseReturnValue);
  1338. WriteBool ('Library Options', 'Enable Error Return', EnableErrorReturn);
  1339. WriteBool ('Library Options', 'Save Screen', SaveScreen);
  1340. end;
  1341. EraseSection ('Included Files');
  1342. SL := TStringList.Create;
  1343. try
  1344. with SourceFiles do
  1345. for I := 0 to Count - 1 do
  1346. with Items [I] as TSourceFile do
  1347. if InProject then begin
  1348. S := SL.Values [ClassItemName];
  1349. if Length (S) > 0 then
  1350. ClassCount := StrToInt (S) + 1
  1351. else
  1352. ClassCount := 1;
  1353. SL.Values [ClassItemName] := IntToStr (ClassCount);
  1354. WriteString ('Included Files', ClassItemName + ' ' + IntToStr (ClassCount), DynamicName);
  1355. S := FolderPath;
  1356. if Length (S) > 0 then
  1357. WriteString ('Included Files', ClassItemName + ' ' + IntToStr (ClassCount) + ' Folder', S);
  1358. end;
  1359. finally
  1360. SL.Free;
  1361. end;
  1362. S := '';
  1363. if Assigned (ProjectTree.Selected) and Assigned (ProjectTree.Selected.Data) and (TObject (ProjectTree.Selected.Data) is TSourceFile) then
  1364. S := TSourceFile(ProjectTree.Selected.Data).FileName;
  1365. WriteString ('File Editing', 'Open File', S);
  1366. UpdateFile;
  1367. finally
  1368. Free;
  1369. end;
  1370. Modified := False;
  1371. except
  1372. ShowDefaultMessageBox ('Error saving project file.', 'Error', mtProgramError);
  1373. end;
  1374. AddToRecent (ProjectFile);
  1375. end;
  1376. end;
  1377. procedure TMainForm.FileSaveAs(const FN: string);
  1378. var
  1379. I: Integer;
  1380. begin
  1381. with SourceFiles do
  1382. for I := 0 to Count - 1 do
  1383. with Items [I] as TSourceFile do
  1384. if Pos ('\', DynamicName) <= 0 then
  1385. WriteToFile (ExtractFilePath (FN) + DynamicName, True);
  1386. ProjectFile := FN;
  1387. FileSave;
  1388. end;
  1389. procedure TMainForm.ProjectTreeDeletion(Sender: TObject; Node: TTreeNode);
  1390. begin
  1391. PreviousNode := nil;
  1392. EditorToHide := nil;
  1393. if Assigned (Node.Data) then
  1394. if TObject (Node.Data) is TSourceFile then begin
  1395. with TSourceFile (Node.Data) do begin
  1396. TreeItem := nil;
  1397. Free;
  1398. end;
  1399. end else
  1400. with TObject (Node.Data) do
  1401. Free;
  1402. ProjectTree.Invalidate;
  1403. end;
  1404. procedure TMainForm.FileExit(Sender: TObject);
  1405. begin
  1406. Close;
  1407. end;
  1408. procedure TMainForm.FileNewProject(Sender: TObject);
  1409. begin
  1410. WarnIfModified;
  1411. Modified := False;
  1412. FileNew;
  1413. end;
  1414. procedure TMainForm.TreeItemRemove(Sender: TObject);
  1415. var
  1416. Node,
  1417. CurNode: TTreeNode;
  1418. begin
  1419. Node := ProjectTree.Selected;
  1420. if (not Compiling) and Assigned (Node) and Assigned (Node.Data) then begin
  1421. CurNode := Node;
  1422. while Assigned (CurNode) and (CurNode <> Node.GetNextSibling) do begin
  1423. if Assigned (CurNode.Data) and (TObject (CurNode.Data) is TSourceFile) then
  1424. TSourceFile(CurNode.Data).WarnIfModified;
  1425. CurNode := CurNode.GetNext;
  1426. if Node.GetNextSibling = nil then
  1427. break;
  1428. end;
  1429. Node.Delete;
  1430. Modify;
  1431. end;
  1432. end;
  1433. procedure TMainForm.TreeItemDelete(Sender: TObject);
  1434. var
  1435. Node: TTreeNode;
  1436. begin
  1437. Node := ProjectTree.Selected;
  1438. if (not Compiling) and Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  1439. if ShowDefaultMessageBox
  1440. ('Are you sure you want to delete this source file? You cannot undo this operation.',
  1441. 'Confirm Deletion', mtQuestion) = idYes then begin
  1442. with TSourceFile (Node.Data) do
  1443. if (FileName <> '') and FileExists (FileName) then
  1444. DeleteFile (FileName);
  1445. Node.Delete;
  1446. Modify;
  1447. end;
  1448. end;
  1449. end;
  1450. procedure TMainForm.CopyHeaders;
  1451. var
  1452. I,
  1453. J: Integer;
  1454. HasA68kFiles: Boolean;
  1455. begin
  1456. HasA68kFiles := False;
  1457. with SourceFiles do begin
  1458. for I := 0 to Count - 1 do
  1459. if Items [I] is TAsmSourceFile then begin
  1460. HasA68kFiles := True;
  1461. Break;
  1462. end;
  1463. if HasA68kFiles then
  1464. with TFileReferences.Create do try
  1465. SearchForFiles (WithBackslash (TIGCCFolder) + ASMIncludeLocation + '*.*', atAll);
  1466. for J := 0 to Count - 1 do
  1467. CopyFile (PChar (Items[J].FullName), PChar (Temp + ExtractFileName (Items[J].FullName)), False);
  1468. finally
  1469. Free;
  1470. end;
  1471. for I := 0 to Count - 1 do begin
  1472. if Items [I] is THeaderSourceFile then begin
  1473. with Items [I] as THeaderSourceFile do begin
  1474. if Invalidated then
  1475. RecompileFiles;
  1476. if InProject then
  1477. SplitAndWriteToFile (Temp + LogicalFileName);
  1478. end;
  1479. end else if Items [I] is TOtherSourceFile then
  1480. with Items [I] as TSourceFile do
  1481. if InProject then
  1482. WriteToFile (Temp + LogicalFileName);
  1483. end;
  1484. end;
  1485. end;
  1486. procedure TMainForm.DeleteHeaders;
  1487. var
  1488. I: Integer;
  1489. FN: string;
  1490. begin
  1491. with TFileReferences.Create do try
  1492. SearchForFiles (Temp + '*.h', atAll);
  1493. for I := 0 to Count - 1 do try
  1494. DeleteFile (Items[I].FullName);
  1495. except end;
  1496. finally
  1497. Free;
  1498. end;
  1499. with SourceFiles do
  1500. for I := 0 to Count - 1 do
  1501. if (Items [I] is THeaderSourceFile) or (Items [I] is TOtherSourceFile) then
  1502. with Items [I] as TSourceFile do begin
  1503. FN := Temp + LogicalFileName;
  1504. if FileExists (FN) then try
  1505. DeleteFile (FN);
  1506. except end;
  1507. RemovePathFor (FN, Temp);
  1508. end;
  1509. end;
  1510. procedure TMainForm.TreeItemCompile(Sender: TObject);
  1511. var
  1512. Node: TTreeNode;
  1513. begin
  1514. Node := ProjectTree.Selected;
  1515. if (not Compiling) and Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) and (TSourceFile(Node.Data).Compilable) then begin
  1516. BeginCompilation;
  1517. CopyHeaders;
  1518. TSourceFile(Node.Data).Compile;
  1519. DeleteHeaders;
  1520. EndCompilation;
  1521. end;
  1522. end;
  1523. procedure TMainForm.CloseErrorsButtonClick(Sender: TObject);
  1524. begin
  1525. HideErrors;
  1526. end;
  1527. procedure TMainForm.AddError(const Line: string; BugTp: TBugType; SourceF: string; ErrFunc: string; ErrMessage: string; SourceLn: Integer; Offset: Integer);
  1528. var
  1529. I,
  1530. J: Integer;
  1531. O: TFoundError;
  1532. Ignore: Boolean;
  1533. Token: string;
  1534. begin
  1535. ErrMessage := Trim (ErrMessage);
  1536. if ErrMessage <> '' then begin
  1537. Ignore := False;
  1538. if BugTp in [btWarning, btInfo] then begin
  1539. if ((ErrFunc = '') and (UpperCase (ErrMessage) = '''STATIC'' IS NOT AT BEGINNING OF DECLARATION'))
  1540. or (Pos ('__DUMMY__', UpperCase (ErrMessage)) > 0)
  1541. or (Pos ('''__R''', UpperCase (ErrMessage)) > 0)
  1542. or (Pos ('MULTI-LINE STRING LITERALS ARE DEPRECATED', UpperCase (ErrMessage)) > 0) then
  1543. Ignore := True;
  1544. end else begin
  1545. if (Pos ('(EACH UNDECLARED IDENTIFIER IS REPORTED ONLY ONCE', UpperCase (ErrMessage)) > 0)
  1546. or (Pos ('FOR EACH FUNCTION IT APPEARS IN.)', UpperCase (ErrMessage)) > 0) then
  1547. Ignore := True;
  1548. end;
  1549. if not Ignore then begin
  1550. if ErrFunc = '__main' then
  1551. ErrFunc := '_main';
  1552. if ErrFunc = '__exit' then
  1553. ErrFunc := '_exit';
  1554. ErrorList.Items.BeginUpdate;
  1555. try
  1556. ErrMessage [1] := UpCase (ErrMessage [1]);
  1557. O := TFoundError.Create;
  1558. with O do begin
  1559. SourceFile := nil;
  1560. if (Length (SourceF) > 0) and (LowerCase (ExtractFileExt (SourceF)) <> '.exe') and (LowerCase (ExtractFileExt (SourceF)) <> '.a') then try
  1561. if Pos ('\', SourceF) > 0 then begin
  1562. SourceFile := SourceFiles.FindFile (SourceF);
  1563. if (not Assigned (SourceFile)) and (LowerCase (ExtractFileExt (SourceF)) = '.o') then begin
  1564. SourceFile := SourceFiles.FindFile (ChangeFileExt (SourceF, '.c'));
  1565. if not Assigned (SourceFile) then
  1566. SourceFile := SourceFiles.FindFile (ChangeFileExt (SourceF, '.s'));
  1567. if not Assigned (SourceFile) then
  1568. SourceFile := SourceFiles.FindFile (ChangeFileExt (SourceF, '.asm'));
  1569. end;
  1570. end else begin
  1571. SourceFile := SourceFiles.FindFileNameOnly (SourceF);
  1572. if (not Assigned (SourceFile)) and (LowerCase (ExtractFileExt (SourceF)) = '.o') then begin
  1573. SourceFile := SourceFiles.FindFileNameOnly (ChangeFileExt (SourceF, '.c'));
  1574. if not Assigned (SourceFile) then
  1575. SourceFile := SourceFiles.FindFileNameOnly (ChangeFileExt (SourceF, '.s'));
  1576. if not Assigned (SourceFile) then
  1577. SourceFile := SourceFiles.FindFileNameOnly (ChangeFileExt (SourceF, '.asm'));
  1578. end;
  1579. end;
  1580. if not Assigned (SourceFile) then begin
  1581. if (Pos ('\', SourceF) > 0) and FileExists (SourceF) then
  1582. SourceFile := AddSourceFile (SourceF, True)
  1583. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + ExtractFileName (SourceF)) then
  1584. SourceFile := AddSourceFile (WithBackslash (TIGCCFolder) + CIncludeLocation + ExtractFileName (SourceF), True)
  1585. else if FileExists (WithBackslash (TIGCCFolder) + ASMIncludeLocation + ExtractFileName (SourceF)) then
  1586. SourceFile := AddSourceFile (WithBackslash (TIGCCFolder) + ASMIncludeLocation + ExtractFileName (SourceF), True)
  1587. else if FileExists (WithBackslash (TIGCCFolder) + GASIncludeLocation + ExtractFileName (SourceF)) then
  1588. SourceFile := AddSourceFile (WithBackslash (TIGCCFolder) + GASIncludeLocation + ExtractFileName (SourceF), True);
  1589. end;
  1590. except end;
  1591. BugType := BugTp;
  1592. WholeLine := Line;
  1593. ErrorMessage := ErrMessage;
  1594. ErrFunction := ErrFunc;
  1595. if Assigned (SourceFile) and (SourceFile is TTextSourceFile) then
  1596. with SourceFile as TTextSourceFile do
  1597. if Assigned (TextEditor) then begin
  1598. I := GetCompiledLineStart (SourceLn) + Offset;
  1599. if I > 0 then begin
  1600. if Pos ('''', ErrorMessage) > 0 then begin
  1601. Token := Copy (ErrorMessage, Pos ('''', ErrorMessage) + 1, Length (ErrorMessage));
  1602. Delete (Token, Pos ('''', Token), Length (Token));
  1603. if Length (Token) > 0 then begin
  1604. J := I;
  1605. while (J <= TextEditor.TextLength) and (TextEditor.Text [J] in [#9, #10, #13, #32]) and (Copy (TextEditor.Text, J, Length (Token)) <> Token) do
  1606. Inc (J);
  1607. if Copy (TextEditor.Text, J, Length (Token)) = Token then
  1608. I := J;
  1609. end;
  1610. end;
  1611. O.Range := TMCRange.Create (TextEditor.TrackedRanges);
  1612. O.Range.RStart := I;
  1613. O.Range.OnOverwrite := DeleteError;
  1614. end else
  1615. O.Range := nil;
  1616. end;
  1617. end;
  1618. with ErrorList.Items.Add do begin
  1619. Data := Pointer (O);
  1620. ImageIndex := Integer (BugTp);
  1621. Caption := ErrMessage;
  1622. if Assigned (O.SourceFile) then
  1623. SubItems.Add (O.SourceFile.SourceName)
  1624. else
  1625. SubItems.Add ('');
  1626. SubItems.Add (ErrFunc);
  1627. ShowErrors;
  1628. if JumpToError and (BugTp = btError) and (not Assigned (ErrorList.Selected)) then begin
  1629. Selected := True;
  1630. ErrorListClick (Self);
  1631. end;
  1632. end;
  1633. except end;
  1634. ErrorList.Items.EndUpdate;
  1635. end;
  1636. end;
  1637. UpdateErrorWindow;
  1638. end;
  1639. procedure TMainForm.ClearErrors;
  1640. begin
  1641. HideErrors;
  1642. with ErrorList.Items do begin
  1643. BeginUpdate;
  1644. Clear;
  1645. EndUpdate;
  1646. end;
  1647. ActionProjectShowErrors.Enabled := False;
  1648. end;
  1649. procedure TMainForm.HideErrors;
  1650. begin
  1651. Splitter2.Hide;
  1652. ErrWinPanel.Hide;
  1653. ActionProjectShowErrors.Checked := False;
  1654. end;
  1655. procedure TMainForm.ShowErrors;
  1656. begin
  1657. if ErrorList.Items.Count > 0 then begin
  1658. ErrWinPanel.Show;
  1659. Splitter2.Show;
  1660. Splitter2.Top := ErrWinPanel.Top - Splitter2.Height;
  1661. ActionProjectShowErrors.Checked := True;
  1662. ErrorList.Refresh;
  1663. end;
  1664. end;
  1665. procedure TMainForm.ErrorListDeletion(Sender: TObject; Item: TListItem);
  1666. var
  1667. O: TObject;
  1668. begin
  1669. if Assigned (Item.Data) then begin
  1670. O := TObject(Item.Data);
  1671. Item.Data := nil;
  1672. O.Free;
  1673. end;
  1674. end;
  1675. procedure TMainForm.UpdateErrorWindow;
  1676. var
  1677. I: Integer;
  1678. EC,
  1679. WC: Integer;
  1680. begin
  1681. with ErrorList, Items do begin
  1682. EC := 0;
  1683. WC := 0;
  1684. for I := 0 to Count - 1 do
  1685. with TFoundError (Item[I].Data) do
  1686. case BugType of
  1687. btWarning:
  1688. Inc (WC);
  1689. btError:
  1690. Inc (EC);
  1691. end;
  1692. ErrorsLabel.Caption := IntToStr (EC);
  1693. WarningsLabel.Caption := IntToStr (WC);
  1694. if Count <= 0 then
  1695. HideErrors;
  1696. end;
  1697. ActionProjectShowErrors.Enabled := ErrorList.Items.Count > 0;
  1698. if not ActionProjectShowErrors.Enabled then
  1699. ActionProjectShowErrors.Checked := False;
  1700. end;
  1701. procedure TMainForm.TreeItemSave(Sender: TObject);
  1702. var
  1703. Node: TTreeNode;
  1704. begin
  1705. Node := ProjectTree.Selected;
  1706. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  1707. TSourceFile(Node.Data).Save;
  1708. end;
  1709. procedure TMainForm.HelpDocumentation(Sender: TObject);
  1710. begin
  1711. try
  1712. DocFile.Display;
  1713. except
  1714. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  1715. end;
  1716. end;
  1717. procedure TMainForm.EditorEnter(Sender: TObject);
  1718. begin
  1719. ActionEditPaste.Enabled := True;
  1720. ActionEditSelectAll.Enabled := True;
  1721. ActionEditIncreaseIndent.Enabled := True;
  1722. ActionEditDecreaseIndent.Enabled := True;
  1723. ActionFindOpenFile.Enabled := True;
  1724. UpdateEditButtons;
  1725. end;
  1726. procedure TMainForm.EditorExit(Sender: TObject);
  1727. begin
  1728. ActionEditDelete.Enabled := False;
  1729. ActionEditCut.Enabled := False;
  1730. ActionEditCopy.Enabled := False;
  1731. ActionEditPaste.Enabled := False;
  1732. ActionEditSelectAll.Enabled := False;
  1733. ActionEditIncreaseIndent.Enabled := False;
  1734. ActionEditDecreaseIndent.Enabled := False;
  1735. ActionFindOpenFile.Enabled := False;
  1736. ActionEditUndo.Enabled := False;
  1737. ActionEditRedo.Enabled := False;
  1738. end;
  1739. procedure TMainForm.EditUndo(Sender: TObject);
  1740. begin
  1741. if Assigned (CurrentEditor) then
  1742. CurrentEditor.Undo;
  1743. end;
  1744. procedure TMainForm.EditRedo(Sender: TObject);
  1745. begin
  1746. if Assigned (CurrentEditor) then
  1747. CurrentEditor.Redo;
  1748. end;
  1749. procedure TMainForm.EditClear(Sender: TObject);
  1750. var
  1751. Editor: TMemoComponent;
  1752. begin
  1753. Editor := CurrentEditor;
  1754. if Assigned (Editor) and (ActiveControl = Editor) then
  1755. Editor.ClearSelection
  1756. else if ActiveControl = ProjectTree then
  1757. TreeItemRemove (Sender);
  1758. end;
  1759. procedure TMainForm.EditCut(Sender: TObject);
  1760. var
  1761. Editor: TMemoComponent;
  1762. begin
  1763. Editor := CurrentEditor;
  1764. if Assigned (Editor) and (ActiveControl = Editor) then
  1765. Editor.CutToClipboard;
  1766. end;
  1767. procedure TMainForm.EditCopy(Sender: TObject);
  1768. var
  1769. Editor: TMemoComponent;
  1770. begin
  1771. Editor := CurrentEditor;
  1772. if Assigned (Editor) and (ActiveControl = Editor) then
  1773. Editor.CopyToClipboard;
  1774. end;
  1775. procedure TMainForm.EditPaste(Sender: TObject);
  1776. var
  1777. Editor: TMemoComponent;
  1778. begin
  1779. Editor := CurrentEditor;
  1780. if Assigned (Editor) and (ActiveControl = Editor) then
  1781. Editor.PasteFromClipboard;
  1782. end;
  1783. procedure TMainForm.EditSelectAll(Sender: TObject);
  1784. var
  1785. Editor: TMemoComponent;
  1786. begin
  1787. Editor := CurrentEditor;
  1788. if Assigned (Editor) and (ActiveControl = Editor) then
  1789. Editor.SelectAll;
  1790. end;
  1791. procedure TMainForm.ProjectCompile(Sender: TObject);
  1792. var
  1793. I: Integer;
  1794. begin
  1795. if not Compiling then begin
  1796. if AutoSave then
  1797. FileSave
  1798. else
  1799. with SourceFiles do
  1800. for I := 0 to Count - 1 do
  1801. with Items [I] as TSourceFile do
  1802. if not InProject then
  1803. Save;
  1804. BeginCompilation;
  1805. CompileProject;
  1806. EndCompilation;
  1807. end;
  1808. end;
  1809. procedure TMainForm.ProjectMake(Sender: TObject);
  1810. begin
  1811. if not Compiling then begin
  1812. MakeFileWrapped;
  1813. DisplayFolderMessage;
  1814. end;
  1815. end;
  1816. procedure TMainForm.MakeFileWrapped;
  1817. var
  1818. I: Integer;
  1819. begin
  1820. if not Compiling then begin
  1821. if AutoSave then
  1822. FileSave
  1823. else
  1824. with SourceFiles do
  1825. for I := 0 to Count - 1 do
  1826. with Items [I] as TSourceFile do
  1827. if not InProject then
  1828. Save;
  1829. OperationSuccessful := False;
  1830. if ProjectFile = '' then
  1831. ShowDefaultMessageBox ('You need to save your project before you can create executable files.', 'Project not Saved', mtProgramError)
  1832. else begin
  1833. BeginCompilation;
  1834. CompileProject;
  1835. Application.ProcessMessages;
  1836. if OperationSuccessful and not OperationCancelled then
  1837. MakeFile;
  1838. EndCompilation;
  1839. end;
  1840. end;
  1841. end;
  1842. procedure TMainForm.MakeFile;
  1843. procedure FileNotCompiled(const FileName: string);
  1844. begin
  1845. ShowDefaultMessageBox
  1846. ('The file ''' + FileName + ''' has not been compiled. You have to compile it first before you can link it to your project.',
  1847. 'No Object File', mtProgramError);
  1848. end;
  1849. var MainFiles: array [TCalcDest] of string;
  1850. procedure HandleContents(const ProjectFile, FolderName, VarName, DataFolderName, DataVarName: string; Pack: Boolean; const PackVar: string; CalcDest: TCalcDest);
  1851. var
  1852. InputStream,
  1853. OutputStream: TMemoryStream;
  1854. OutputSize: LongWord;
  1855. FileSize: Integer;
  1856. F: file;
  1857. B: Byte;
  1858. begin
  1859. CompUpdate;
  1860. OperationSuccessful := False;
  1861. with LinkOutputFiles [CalcDest, frMain] do
  1862. if Assigned (Data) then begin
  1863. OutputStream := TMemoryStream.Create;
  1864. try
  1865. if OSUpgrade then begin
  1866. OutputSize := GetOSUpgradeFileSize (Data.Size, OutputBin);
  1867. OutputStream.Size := OutputSize;
  1868. ProduceOSUpgradeFile (OutputStream.Memory, Data.Memory, Data.Size, OutputBin);
  1869. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetOSUpgradeFileExt (CalcDest, OutputBin));
  1870. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1871. if LongWord (ProgSize) < OutputSize then
  1872. ProgSize := OutputSize;
  1873. OperationSuccessful := True;
  1874. end else begin
  1875. FileSize := 2 + Data.Size + 1;
  1876. if Pack then begin
  1877. AssignFile (F, Temp + 'tempprog.bin');
  1878. Rewrite (F, 1);
  1879. B := (FileSize - 2) shr 8;
  1880. BlockWrite (F, B, 1);
  1881. B := (FileSize - 2);
  1882. BlockWrite (F, B, 1);
  1883. BlockWrite (F, Data.Memory^, Data.Size);
  1884. B := Tag;
  1885. BlockWrite (F, B, 1);
  1886. CloseFile (F);
  1887. MainConsole.Title := 'Compressor';
  1888. CompUpdate;
  1889. try
  1890. MainConsole.StartProcess (WithBackslash (TIGCCFolder) + PackLocation + 'Pack.exe', 'tempprog.bin tempprog.pck', WithoutBackslash (Temp));
  1891. WaitForMainConsole ('Compression');
  1892. except
  1893. ShowDefaultMessageBox ('Could not start compressor.', 'Error', mtProgramError);
  1894. end;
  1895. CompUpdate;
  1896. if not OperationCancelled then begin
  1897. if FileExists (Temp + 'tempprog.pck') then begin
  1898. InputStream := TMemoryStream.Create;
  1899. with InputStream do try
  1900. LoadFromFile (Temp + 'tempprog.pck');
  1901. OutputSize := GetTransferFileSize (Size, 'ppg', OutputBin);
  1902. if OutputSize > 0 then begin
  1903. OutputStream.Size := OutputSize;
  1904. ProduceTransferFile (OutputStream.Memory, Memory, Size, CalcDest, FolderName, PackVar, $F8, 'ppg', OutputBin);
  1905. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetTransferFileExt (CalcDest, $F8, OutputBin));
  1906. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1907. if LongWord (ProgSize) < OutputSize then
  1908. ProgSize := OutputSize;
  1909. OperationSuccessful := True;
  1910. end else
  1911. ShowDefaultMessageBox ('Compressed size of ' + IntToStr (Size) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1912. finally
  1913. Free;
  1914. end;
  1915. end else
  1916. ShowDefaultMessageBox ('Compression failed. Please check the program size.', 'Error', mtProgramError);
  1917. end;
  1918. if FileExists (Temp + 'tempprog.bin') then
  1919. DeleteFile (Temp + 'tempprog.bin');
  1920. if FileExists (Temp + 'tempprog.pck') then
  1921. DeleteFile (Temp + 'tempprog.pck');
  1922. end else begin
  1923. OutputSize := GetTransferFileSize (Data.Size, VarExt, OutputBin);
  1924. if OutputSize > 0 then begin
  1925. OutputStream.Size := OutputSize;
  1926. ProduceTransferFile (OutputStream.Memory, Data.Memory, Data.Size, CalcDest, FolderName, VarName, Tag, VarExt, OutputBin);
  1927. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetTransferFileExt (CalcDest, Tag, OutputBin));
  1928. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1929. if LongWord (ProgSize) < OutputSize then
  1930. ProgSize := OutputSize;
  1931. OperationSuccessful := True;
  1932. end else
  1933. ShowDefaultMessageBox ('Variable size of ' + IntToStr (FileSize) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1934. end;
  1935. end;
  1936. finally
  1937. OutputStream.Free;
  1938. end;
  1939. CompUpdate;
  1940. end else
  1941. ShowDefaultMessageBox ('Unexpected destination calculator mismatch.', 'Error', mtProgramError);
  1942. with LinkOutputFiles [CalcDest, frData] do
  1943. if Assigned (Data) and (not OSUpgrade) then begin
  1944. FileSize := 2 + Data.Size + 1;
  1945. OutputStream := TMemoryStream.Create;
  1946. try
  1947. OutputSize := GetTransferFileSize (Data.Size, VarExt, OutputBin);
  1948. if OutputSize > 0 then begin
  1949. OutputStream.Size := OutputSize;
  1950. ProduceTransferFile (OutputStream.Memory, Data.Memory, Data.Size, CalcDest, DataFolderName, DataVarName, Tag, VarExt, OutputBin);
  1951. OutputStream.SaveToFile (ChangeFileExt (ChangeFileExt (ProjectFile, '') + '-data', GetTransferFileExt (CalcDest, Tag, OutputBin)));
  1952. OperationSuccessful := True;
  1953. end else
  1954. ShowDefaultMessageBox ('Data variable size of ' + IntToStr (FileSize) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1955. finally
  1956. OutputStream.Free;
  1957. end;
  1958. CompUpdate;
  1959. end;
  1960. end;
  1961. procedure HandleDebugContents(const ProjectFile: string);
  1962. begin
  1963. with LinkDebugFile do
  1964. if Assigned (Data) then
  1965. Data.SaveToFile (ChangeFileExt (ProjectFile, '.dbg'));
  1966. end;
  1967. procedure CreatePackStarter(const ProjectFile, StarterFileName, FolderName, VarName, PackVar: string; CalcDests: TCalcDests);
  1968. var
  1969. CurCalcDest: TCalcDest;
  1970. CustomStarterObject: string;
  1971. ObjectFileNames: array [0..1] of PChar;
  1972. DataVarInfo: TLinkLibDataVarInfo;
  1973. OptimizeInfo: TLinkLibOptimizeInfo;
  1974. begin
  1975. CompUpdate;
  1976. OperationSuccessful := False;
  1977. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  1978. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  1979. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  1980. end;
  1981. try
  1982. CustomStarterObject := Temp + StarterFileName;
  1983. if FileExists (WithBackslash (TIGCCFolder) + PStarterLocation + StarterFileName) then try
  1984. ParsePStarter (WithBackslash (TIGCCFolder) + PStarterLocation + StarterFileName, CustomStarterObject, PackVar);
  1985. except
  1986. ShowDefaultMessageBox ('Error processing starter object file.', 'Error', mtProgramError);
  1987. Exit;
  1988. end else begin
  1989. ShowDefaultMessageBox ('Cannot find starter object file.', 'Error', mtProgramError);
  1990. Exit;
  1991. end;
  1992. if not OperationCancelled then begin
  1993. ObjectFileNames [0] := PChar (CustomStarterObject);
  1994. ObjectFileNames [1] := nil;
  1995. FillChar (DataVarInfo, SizeOf (DataVarInfo), 0);
  1996. FillChar (OptimizeInfo, SizeOf (OptimizeInfo), 0);
  1997. if Assigned (LinkLibLinkFiles) then
  1998. OperationSuccessful := LinkLibLinkFiles (@ObjectFileNames, nil, LinkLibError, LinkLibGetOutputFile, nil, False, False, False, DataVarInfo, OptimizeInfo, False) = 0
  1999. else
  2000. ShowDefaultMessageBox ('Linker not loaded.', 'Error', mtProgramError);
  2001. end;
  2002. for CurCalcDest := cdTI89 to cdV200 do
  2003. if OperationSuccessful and (not OperationCancelled) and (CurCalcDest in CalcDests) then
  2004. HandleContents (ProjectFile, FolderName, VarName, '', '', False, '', CurCalcDest);
  2005. finally
  2006. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  2007. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2008. LinkOutputFiles[CurCalcDest,frMain].Data.Free;
  2009. if Assigned (LinkOutputFiles[CurCalcDest,frData].Data) then
  2010. LinkOutputFiles[CurCalcDest,frData].Data.Free;
  2011. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2012. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2013. end;
  2014. if FileExists (CustomStarterObject) then
  2015. DeleteFile (CustomStarterObject);
  2016. end;
  2017. end;
  2018. var
  2019. FolderName,
  2020. VarName,
  2021. DataFolderName,
  2022. DataVarName: array [0..MaxNameLength] of Char;
  2023. I,
  2024. P: Integer;
  2025. S1,
  2026. DestFile: string;
  2027. Node: TTreeNode;
  2028. SourceFile: TSourceFile;
  2029. FileNameList: TStringList;
  2030. ObjectFileNames,
  2031. ArchiveFileNames: PPChar;
  2032. ObjectFileCount,
  2033. ArchiveFileCount: Integer;
  2034. DataVarInfo: TLinkLibDataVarInfo;
  2035. CalcDests: TCalcDests;
  2036. CurCalcDest: TCalcDest;
  2037. SR: TSearchRec;
  2038. begin
  2039. UpdateErrorWindow;
  2040. OperationCancelled := False;
  2041. OperationSuccessful := False;
  2042. ProgSize := 0;
  2043. CalcDests := [];
  2044. OperationSuccessful := True;
  2045. with TopNode do begin
  2046. I := Pos ('\', Text);
  2047. if I > 0 then begin
  2048. StrPLCopy (VarName, LowerCase (Copy (Text, I + 1, MaxNameLength)), MaxNameLength);
  2049. StrPLCopy (FolderName, LowerCase (Copy (Text, 1, I - 1)), MaxNameLength);
  2050. CharLower (FolderName);
  2051. end else begin
  2052. StrPLCopy (VarName, LowerCase (Text), MaxNameLength);
  2053. FolderName := 'main';
  2054. end;
  2055. CharLower (VarName);
  2056. end;
  2057. with SourceFiles do
  2058. for I := 0 to Count - 1 do
  2059. with TSourceFile (Items [I]) do
  2060. if InProject and Compilable and (not FileExists (ChangeFileExt (FileName, '.o'))) then begin
  2061. OperationSuccessful := False;
  2062. FileNotCompiled (SourceName);
  2063. end;
  2064. I := Pos ('\', DataVar);
  2065. if I > 0 then begin
  2066. StrPLCopy (DataVarName, LowerCase (Copy (DataVar, I + 1, MaxNameLength)), MaxNameLength);
  2067. StrPLCopy (DataFolderName, LowerCase (Copy (DataVar, 1, I - 1)), MaxNameLength);
  2068. CharLower (DataFolderName);
  2069. end else begin
  2070. StrPLCopy (DataVarName, LowerCase (DataVar), MaxNameLength);
  2071. DataFolderName := FolderName;
  2072. end;
  2073. CharLower (DataVarName);
  2074. if OperationSuccessful then begin
  2075. OperationSuccessful := False;
  2076. if Assigned (LinkLibLinkFiles) and Assigned (LinkLibCreateArchive) then begin
  2077. CompStartFile;
  2078. CompSetMessage ('Linking Project ''' + WithoutExt (ExtractFileName (ProjectFile)) + '''');
  2079. if FileExists (ChangeFileExt (ProjectFile, '-titanium.89z')) then
  2080. DeleteFile (ChangeFileExt (ProjectFile, '-titanium.89z'));
  2081. ObjectFileCount := 0;
  2082. ObjectFileNames := nil;
  2083. ArchiveFileCount := 0;
  2084. ArchiveFileNames := nil;
  2085. FileNameList := TStringList.Create;
  2086. try
  2087. Node := TopNode;
  2088. while Assigned (Node) do begin
  2089. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  2090. SourceFile := Node.Data;
  2091. if Assigned (SourceFile) then
  2092. with SourceFile do
  2093. if InProject then begin
  2094. if SourceFile is TArchiveSourceFile then begin
  2095. Inc (ArchiveFileCount);
  2096. ReallocMem (ArchiveFileNames, SizeOf (PChar) * (ArchiveFileCount + 1));
  2097. ArchiveFileNames [ArchiveFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (FileName)]);
  2098. ArchiveFileNames [ArchiveFileCount - 0] := nil;
  2099. end else if Compilable or (SourceFile is TObjectSourceFile) then begin
  2100. Inc (ObjectFileCount);
  2101. ReallocMem (ObjectFileNames, SizeOf (PChar) * (ObjectFileCount + 1));
  2102. ObjectFileNames [ObjectFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (ChangeFileExt (FileName, '.o'))]);
  2103. ObjectFileNames [ObjectFileCount] := nil;
  2104. end;
  2105. end;
  2106. end;
  2107. Node := Node.GetNext;
  2108. end;
  2109. if StdLib then begin
  2110. if ProjectTarget = ptFlashOS then
  2111. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'flashos.a'
  2112. else if ProjectTarget = ptFargo then
  2113. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'fargo.a'
  2114. else
  2115. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'tigcc.a';
  2116. if FileExists (S1) then begin
  2117. Inc (ArchiveFileCount);
  2118. ReallocMem (ArchiveFileNames, SizeOf (PChar) * (ArchiveFileCount + 1));
  2119. ArchiveFileNames [ArchiveFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (S1)]);
  2120. ArchiveFileNames [ArchiveFileCount] := nil;
  2121. end;
  2122. end;
  2123. if ProjectTarget = ptArchive then begin
  2124. DestFile := ChangeFileExt (ProjectFile, '.a');
  2125. OperationSuccessful := LinkLibCreateArchive (PChar (DestFile), ObjectFileNames, LinkLibError, True) = 0;
  2126. if OperationSuccessful then begin
  2127. if FindFirst (DestFile, faAnyFile, SR) = 0 then
  2128. ProgSize := SR.Size;
  2129. FindClose (SR);
  2130. end;
  2131. end else begin
  2132. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  2133. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2134. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2135. end;
  2136. LinkDebugFile.Data := nil;
  2137. try
  2138. FillChar (DataVarInfo, SizeOf (DataVarInfo), 0);
  2139. FillChar (OptimizeInfo, SizeOf (OptimizeInfo), 0);
  2140. if UseDataVar then
  2141. with DataVarInfo do begin
  2142. VarName := PChar (LowerCase (MasterUnit.DataVar));
  2143. CreateCopy := MasterUnit.DataVarCopy;
  2144. CopyOnlyIfArchived := MasterUnit.DataVarCopyIfArchived;
  2145. end;
  2146. with OptimizeInfo do begin
  2147. RemoveUnused := MasterUnit.RemoveUnusedSections;
  2148. OptimizeNOPs := MasterUnit.OptimizeNOPs;
  2149. OptimizeReturns := MasterUnit.OptimizeReturns;
  2150. OptimizeBranches := MasterUnit.OptimizeBranches;
  2151. OptimizeMoves := MasterUnit.OptimizeMoves;
  2152. OptimizeTests := MasterUnit.OptimizeTests;
  2153. OptimizeCalcs := MasterUnit.OptimizeCalculations;
  2154. CutRanges := MasterUnit.CutUnusedRanges;
  2155. ReorderSections := MasterUnit.ReorderSections;
  2156. MergeConstants := MasterUnit.MergeConstants;
  2157. end;
  2158. OperationSuccessful := LinkLibLinkFiles (ObjectFileNames, ArchiveFileNames, LinkLibError, LinkLibGetOutputFile, nil, False, ProjectTarget = ptFlashOS, ProjectTarget = ptFargo, DataVarInfo, OptimizeInfo, not InitBSS) = 0;
  2159. if OperationSuccessful and (not OperationCancelled) then begin
  2160. if Pack and (ssPack in SpecialSupport) then begin
  2161. CompStartFile;
  2162. CompSetMessage ('Compressing');
  2163. end;
  2164. for CurCalcDest := FirstCalcDest to LastCalcDest do
  2165. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2166. if OperationSuccessful and (not OperationCancelled) then begin
  2167. Include (CalcDests, CurCalcDest);
  2168. HandleContents (ProjectFile, FolderName, VarName, DataFolderName, DataVarName, Pack and (ssPack in SpecialSupport) and (CurCalcDest <> cdTI92), PackVar, CurCalcDest);
  2169. end;
  2170. if Assigned (LinkDebugFile.Data) then begin
  2171. if OperationSuccessful and (not OperationCancelled) then begin
  2172. HandleDebugContents (ProjectFile);
  2173. end;
  2174. end;
  2175. end;
  2176. finally
  2177. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  2178. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2179. LinkOutputFiles[CurCalcDest,frMain].Data.Free;
  2180. if Assigned (LinkOutputFiles[CurCalcDest,frData].Data) then
  2181. LinkOutputFiles[CurCalcDest,frData].Data.Free;
  2182. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2183. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2184. if Assigned (LinkDebugFile.Data) then
  2185. LinkDebugFile.Data.Free;
  2186. LinkDebugFile.Data := nil;
  2187. end;
  2188. end;
  2189. end;
  2190. except
  2191. if Assigned (ArchiveFileNames) then
  2192. FreeMem (ArchiveFileNames);
  2193. if Assigned (ObjectFileNames) then
  2194. FreeMem (ObjectFileNames);
  2195. FileNameList.Free;
  2196. end;
  2197. if OperationSuccessful and (not OperationCancelled) and Pack and (ssPack in SpecialSupport) then
  2198. CreatePackStarter (ProjectFile, 'PStarter.o', FolderName, VarName, PackVar, CalcDests - [cdTI92]);
  2199. if OperationSuccessful and (not OperationCancelled) and (Length (PostBuildProcessFile) > 0) then begin
  2200. CompStartFile;
  2201. CompSetMessage ('Calling User-Defined Program');
  2202. MainConsole.Title := 'User-Defined Program';
  2203. S1 := PostBuildProcessFile;
  2204. P := Pos ('($TI89FILE)', UpperCase (S1));
  2205. if P > 0 then begin
  2206. Delete (S1, P, Length ('($TI89FILE)'));
  2207. if cdTI89 in CalcDests then
  2208. Insert (MainFiles [cdTI89], S1, P);
  2209. end;
  2210. P := Pos ('($TI92PLUSFILE)', UpperCase (S1));
  2211. if P > 0 then begin
  2212. Delete (S1, P, Length ('($TI92PLUSFILE)'));
  2213. if cdTI92Plus in CalcDests then
  2214. Insert (MainFiles [cdTI92Plus], S1, P);
  2215. end;
  2216. P := Pos ('($V200FILE)', UpperCase (S1));
  2217. if P > 0 then begin
  2218. Delete (S1, P, Length ('($V200FILE)'));
  2219. if cdV200 in CalcDests then
  2220. Insert (MainFiles [cdV200], S1, P);
  2221. end;
  2222. P := Pos ('($TI92FILE)', UpperCase (S1));
  2223. if P > 0 then begin
  2224. Delete (S1, P, Length ('($TI92FILE)'));
  2225. if cdTI92 in CalcDests then
  2226. Insert (MainFiles [cdTI92], S1, P);
  2227. end;
  2228. try
  2229. MainConsole.StartProcess ('', S1, '');
  2230. WaitForMainConsole ('User-Defined');
  2231. except
  2232. ShowDefaultMessageBox ('Could not start the user-defined program.', 'Error', mtProgramError);
  2233. OperationSuccessful := False;
  2234. end;
  2235. UpdateProgramOutput;
  2236. end;
  2237. if not OperationSuccessful then
  2238. ProgSize := 0;
  2239. CompUpdate;
  2240. try
  2241. if FileExists (Temp + 'TEMPPROG.PCK') then
  2242. DeleteFile (Temp + 'TEMPPROG.PCK');
  2243. if OperationSuccessful and (not OperationCancelled) and DeleteAssemblyFiles then
  2244. with SourceFiles do
  2245. for I := 0 to Count - 1 do
  2246. with TSourceFile (Items [I]) do
  2247. if InProject and (Items [I] is TCSourceFile) then
  2248. if FileExists (ChangeFileExt (FileName, '.s')) then
  2249. DeleteFile (ChangeFileExt (FileName, '.s'));
  2250. if OperationSuccessful and (not OperationCancelled) and DeleteObjectFiles then
  2251. with SourceFiles do
  2252. for I := 0 to Count - 1 do
  2253. with TSourceFile (Items [I]) do
  2254. if InProject and Compilable then begin
  2255. Invalidate;
  2256. if FileExists (ChangeFileExt (FileName, '.o')) then
  2257. DeleteFile (ChangeFileExt (FileName, '.o'));
  2258. end;
  2259. except end;
  2260. UpdateErrorWindow;
  2261. ShowErrors;
  2262. CompUpdate;
  2263. if OperationSuccessful and (not OperationCancelled) then begin
  2264. Invalidated := False;
  2265. CompUpdate;
  2266. end;
  2267. end else
  2268. ShowDefaultMessageBox ('Linker not loaded.', 'Error', mtProgramError);
  2269. end;
  2270. end;
  2271. procedure TMainForm.FileOpenProject(Sender: TObject);
  2272. begin
  2273. if OpenProjectDlg.Execute then begin
  2274. if LowerCase (ExtractFileExt (OpenProjectDlg.FileName)) = LowerCase (ProjectFileExt) then
  2275. FileOpen (ExpandFileName (OpenProjectDlg.FileName))
  2276. else
  2277. AddSourceFile (OpenProjectDlg.FileName, True);
  2278. end else
  2279. Abort;
  2280. end;
  2281. procedure TMainForm.FileSaveAll(Sender: TObject);
  2282. begin
  2283. FileSave;
  2284. end;
  2285. procedure TMainForm.FileSaveProjectAs(Sender: TObject);
  2286. begin
  2287. SaveProjectDlg.FileName := ProjectFile;
  2288. if SaveProjectDlg.Execute then
  2289. FileSaveAs (ExpandFileName (SaveProjectDlg.FileName))
  2290. else
  2291. Abort;
  2292. end;
  2293. procedure TMainForm.EditorKeyDown(Sender: TObject; var Key: Word;
  2294. Shift: TShiftState);
  2295. var
  2296. I: Integer;
  2297. S: string;
  2298. begin
  2299. if Key = vk_F1 then
  2300. if Sender is TMemoComponent then
  2301. with Sender as TMemoComponent do begin
  2302. S := '';
  2303. for I := Selection.RStart - 1 downto 1 do begin
  2304. if Text [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$', '#'] then
  2305. S := Text [I] + S
  2306. else
  2307. Break;
  2308. end;
  2309. for I := Selection.RStart to TextLength do begin
  2310. if Text [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$', '#'] then
  2311. S := S + Text [I]
  2312. else
  2313. Break;
  2314. end;
  2315. if S <> '' then begin
  2316. with SourceFiles do
  2317. for I := 0 to Count - 1 do
  2318. with Items [I] as TSourceFile do
  2319. if Assigned (ParentForm) then
  2320. ParentForm.WindowState := wsMinimized;
  2321. Application.ProcessMessages;
  2322. DocFile.KeywordLookup (S);
  2323. end;
  2324. end;
  2325. end;
  2326. procedure TMainForm.ProjectBuild(Sender: TObject);
  2327. var
  2328. I: Integer;
  2329. begin
  2330. if not Compiling then begin
  2331. if AutoSave then
  2332. FileSave
  2333. else
  2334. with SourceFiles do
  2335. for I := 0 to Count - 1 do
  2336. with Items [I] as TSourceFile do
  2337. if not InProject then
  2338. Save;
  2339. OperationSuccessful := False;
  2340. if ProjectFile = '' then
  2341. ShowDefaultMessageBox ('You need to save your project before you can create executable files.', 'Project not Saved', mtProgramError)
  2342. else begin
  2343. BeginCompilation;
  2344. RecompileFiles;
  2345. CompileProject;
  2346. Application.ProcessMessages;
  2347. if OperationSuccessful and not OperationCancelled then
  2348. MakeFile;
  2349. EndCompilation;
  2350. DisplayFolderMessage;
  2351. end;
  2352. end;
  2353. end;
  2354. procedure TMainForm.ProjectTreeKeyDown(Sender: TObject; var Key: Word;
  2355. Shift: TShiftState);
  2356. begin
  2357. if (Key = vk_Delete) and not ProjectTree.IsEditing then
  2358. TreeItemRemove (Sender);
  2359. end;
  2360. procedure TMainForm.ProjectTreeMouseUp(Sender: TObject;
  2361. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2362. begin
  2363. if Button = mbRight then
  2364. with ProjectTree do
  2365. if Assigned (Selected) then begin
  2366. if Assigned (Selected.Data) then begin
  2367. if TObject (Selected.Data) is TSourceFile then begin
  2368. with TSourceFile (Selected.Data) do begin
  2369. ActionTreeItemSave.Enabled := TSourceFile (Selected.Data) is TTextSourceFile;
  2370. ActionTreeItemSaveAs.Enabled := True;
  2371. ActionTreeItemCompile.Enabled := Compilable;
  2372. end;
  2373. with Mouse.CursorPos do
  2374. SourceFilePopup.Popup (X, Y);
  2375. end else if TObject (Selected.Data) is TFolder then begin
  2376. with Mouse.CursorPos do
  2377. FolderPopup.Popup (X, Y);
  2378. end;
  2379. end else if Assigned (Selected.Parent) then begin
  2380. with Mouse.CursorPos do
  2381. CategoryPopup.Popup (X, Y);
  2382. end;
  2383. end;
  2384. end;
  2385. procedure TMainForm.ProjectTreeEdited(Sender: TObject; Node: TTreeNode;
  2386. var S: String);
  2387. var
  2388. I: Integer;
  2389. HasFolder,
  2390. NameConflict: Boolean;
  2391. begin
  2392. if Node = TopNode then begin
  2393. if Length (S) <= 0 then
  2394. S := 'Project1'
  2395. else begin
  2396. HasFolder := False;
  2397. for I := Length (S) downto 1 do begin
  2398. if S [I] = '\' then begin
  2399. if HasFolder then
  2400. Delete (S, I, 1)
  2401. else
  2402. HasFolder := True;
  2403. end else if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9']))) then
  2404. Delete (S, I, 1);
  2405. end;
  2406. if Length (S) <= 0 then
  2407. S := 'Project1'
  2408. else if not (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z', '\'])) then
  2409. S := 'X' + S;
  2410. I := Pos ('\', S);
  2411. if I > 0 then begin
  2412. while I - 1 > MaxNameLength do begin
  2413. Delete (S, I - 1, 1);
  2414. Dec (I);
  2415. end;
  2416. while Length (S) - I > MaxNameLength do
  2417. Delete (S, Length (S), 1);
  2418. if I + 1 > Length (S) then
  2419. S := S + 'Project1'
  2420. else if I = 1 then
  2421. Delete (S, 1, 1)
  2422. else if not (IsCharAlpha (S [I + 1]) or (S [I + 1] in ['A'..'Z', 'a'..'z'])) then
  2423. Insert ('X', S, I + 1);
  2424. end else
  2425. S := Copy (S, 1, MaxNameLength);
  2426. end;
  2427. Modify;
  2428. end else begin
  2429. if Assigned (Node.Data) then begin
  2430. if (TObject (Node.Data) is TSourceFile) then begin
  2431. if S = '' then
  2432. S := 'File1';
  2433. NameConflict := False;
  2434. if TSourceFile(Node.Data).Compilable then
  2435. with SourceFiles do
  2436. for I := 0 to Count - 1 do
  2437. if Items [I] <> Node.Data then
  2438. with Items [I] as TSourceFile do
  2439. if Compilable and (LowerCase (SourceName) = LowerCase (S)) and (WithoutBackslash (FolderPath) = WithoutBackslash (TSourceFile(Node.Data).FolderPath)) then begin
  2440. NameConflict := True;
  2441. Break;
  2442. end;
  2443. if not NameConflict then try
  2444. if Assigned (Node.Data) then
  2445. TSourceFile(Node.Data).SourceName := S;
  2446. Modify;
  2447. Exit;
  2448. except end;
  2449. S := Node.Text;
  2450. ShowDefaultMessageBox ('The name you chose conflicts with that of another file.', 'Error', mtProgramError)
  2451. end else begin
  2452. S := StringReplace (S, ' ', '', [rfReplaceAll]);
  2453. if Length (S) <= 0 then
  2454. S := Node.Text;
  2455. RecompileFiles;
  2456. end;
  2457. end;
  2458. end;
  2459. end;
  2460. procedure TMainForm.SetProjectFile(const Value: string);
  2461. var
  2462. S: string;
  2463. B: Boolean;
  2464. begin
  2465. FProjectFile := Value;
  2466. MasterUnit.ProjectFileName := Value;
  2467. if Value = '' then
  2468. Caption := OriginalCaption
  2469. else
  2470. Caption := OriginalCaption + ' - ' + WithoutExt (ExtractFileName (Value));
  2471. Application.Title := Caption;
  2472. if TopNode.Text = 'Project1' then begin
  2473. B := Modified;
  2474. S := WithoutExt (ExtractFileName (Value));
  2475. ProjectTreeEdited (ProjectTree, TopNode, S);
  2476. TopNode.Text := S;
  2477. Modified := B;
  2478. end;
  2479. S := ExtractFilePath (Value);
  2480. OpenProjectDlg.InitialDir := WithoutBackslash (S);
  2481. OpenProjectDlg.FileName := Value;
  2482. SaveProjectDlg.InitialDir := WithoutBackslash (S);
  2483. SaveProjectDlg.FileName := Value;
  2484. AddFileDlg.InitialDir := S;
  2485. end;
  2486. function TMainForm.AddSourceFile(const FN: string; OpenOnly: Boolean = False; SourceFileClass: TSourceFileClass = nil; Folder: TFolder = nil): TSourceFile;
  2487. var
  2488. F: TForm;
  2489. S: string;
  2490. O: TOpenFileStatusForm;
  2491. begin
  2492. if Compiling and (not OpenOnly) then
  2493. Result := nil
  2494. else begin
  2495. Result := SourceFiles.FindFile (FN);
  2496. if Assigned (Result) and Result.InProject then begin
  2497. Result := nil;
  2498. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' is already included in the project.', 'File Already Included', mtProgramError);
  2499. end else if OpenOnly and Assigned (Result) then begin
  2500. Result := nil;
  2501. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' has already been opened.', 'File Already Opened', mtProgramError);
  2502. end else if (not OpenOnly) and (LowerCase (ExtractFileExt (FN)) = '.qll') and (Assigned (SourceFiles.FindFileOfTypeInProject (TQuillSourceFile))) then begin
  2503. Result := nil;
  2504. ShowDefaultMessageBox ('There may be only one Quill source file in each project.', 'Quill Error', mtProgramError);
  2505. end else begin
  2506. if not Assigned (Result) then begin
  2507. O := nil;
  2508. try
  2509. if not OpeningProjectNow then begin
  2510. O := TOpenFileStatusForm.Create (Self);
  2511. S := ExtractFileName (FN);
  2512. O.FileNameLabel.Caption := 'Opening File ''' + Copy (S, 1, LastPos ('.', S) - 1) + '''...';
  2513. O.Show;
  2514. O.Update;
  2515. end;
  2516. if not Assigned (SourceFileClass) then
  2517. SourceFileClass := TSourceFile.GetAppropriateClassFromExt (ExtractFileExt (FN));
  2518. Result := SourceFileClass.Create (SourceFiles);
  2519. Result.Folder := Folder;
  2520. Result.LoadFromFile (FN, True);
  2521. Result.OnError := AddError;
  2522. finally
  2523. if Assigned (O) then
  2524. O.Free;
  2525. end;
  2526. if OpenOnly and (not Assigned (Result.Editor)) then begin
  2527. Result.Free;
  2528. Result := nil;
  2529. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' is not a valid file for opening.', 'Invalid File', mtProgramError);
  2530. end;
  2531. end;
  2532. if Assigned (Result) then
  2533. with Result do begin
  2534. ErrorList := Self.ErrorList;
  2535. if OpenOnly then begin
  2536. if not Assigned (ParentForm) then begin
  2537. ParentForm := TSourceFileForm.Create (nil);
  2538. with ParentForm as TSourceFileForm do begin
  2539. Enabled := False;
  2540. SourceFile := Result;
  2541. Show;
  2542. end;
  2543. if Assigned (Editor) then
  2544. with Editor do begin
  2545. Parent := ParentForm;
  2546. Align := alClient;
  2547. Show;
  2548. if Enabled then
  2549. SetFocus;
  2550. end;
  2551. end;
  2552. end else begin
  2553. if Assigned (ParentForm) then begin
  2554. F := ParentForm;
  2555. ParentForm := nil;
  2556. F.Free;
  2557. end;
  2558. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], Result);
  2559. with TreeItem do begin
  2560. ImageIndex := ClassImageIndex;
  2561. SelectedIndex := ImageIndex;
  2562. end;
  2563. end;
  2564. end;
  2565. end;
  2566. if not OpeningProjectNow then
  2567. SortFiles;
  2568. end;
  2569. end;
  2570. procedure TMainForm.ProjectOptions(Sender: TObject);
  2571. begin
  2572. with TProjectOptionsForm.Create (Self) do try
  2573. FlashOSRadioButton.Visible := ssFlashOS in SpecialSupport;
  2574. FargoRadioButton.Visible := ssFargo in SpecialSupport;
  2575. if ProjectTarget = ptArchive then
  2576. ArchiveRadioButton.Checked := True
  2577. else if (ProjectTarget = ptFlashOS) and (FlashOSRadioButton.Visible) then
  2578. FlashOSRadioButton.Checked := True
  2579. else if (ProjectTarget = ptFargo) and (FargoRadioButton.Visible) then
  2580. FargoRadioButton.Checked := True
  2581. else
  2582. ExecutableRadioButton.Checked := True;
  2583. DataVarCheckBox.Checked := UseDataVar;
  2584. DataVarEdit.Text := DataVar;
  2585. if DataVarCopy then begin
  2586. if DataVarCopyIfArchived then
  2587. DataVarCopyIfArchivedRadioButton.Checked := True
  2588. else
  2589. DataVarCopyAlwaysRadioButton.Checked := True;
  2590. end else
  2591. DataVarCopyNeverRadioButton.Checked := True;
  2592. PackCheckBox.Checked := Pack and (ssPack in SpecialSupport);
  2593. PackVarEdit.Text := PackVar;
  2594. GCCSwitchesEdit.Text := GCCSwitches;
  2595. AsSwitchesEdit.Text := AsSwitches;
  2596. AsmSwitchesEdit.Text := AsmSwitches;
  2597. DebugInfoCheckBox.Checked := DebugInfo;
  2598. OptimizeNOPsCheckBox.Checked := OptimizeNOPs;
  2599. OptimizeReturnsCheckBox.Checked := OptimizeReturns;
  2600. OptimizeBranchesCheckBox.Checked := OptimizeBranches;
  2601. OptimizeMovesCheckBox.Checked := OptimizeMoves;
  2602. OptimizeTestsCheckBox.Checked := OptimizeTests;
  2603. OptimizeCalculationsCheckBox.Checked := OptimizeCalculations;
  2604. RemoveUnusedSectionsCheckBox.Checked := RemoveUnusedSections;
  2605. CutUnusedRangesCheckBox.Checked := CutUnusedRanges;
  2606. ReorderSectionsCheckBox.Checked := ReorderSections;
  2607. MergeConstantsCheckBox.Checked := MergeConstants;
  2608. StdLibCheckBox.Checked := StdLib;
  2609. InitBSSCheckBox.Checked := InitBSS;
  2610. OutputBinCheckBox.Checked := OutputBin;
  2611. CommandLineEdit.Text := CommandLine;
  2612. ProcessFileEdit.Text := PostBuildProcessFile;
  2613. InitialLibOptions := PredefinedLibOptions;
  2614. if ShowModal = mrOK then begin
  2615. if ArchiveRadioButton.Checked then
  2616. ProjectTarget := ptArchive
  2617. else if FlashOSRadioButton.Checked then
  2618. ProjectTarget := ptFlashOS
  2619. else if FargoRadioButton.Checked then
  2620. ProjectTarget := ptFargo
  2621. else
  2622. ProjectTarget := ptRegular;
  2623. Pack := PackCheckBox.Checked;
  2624. PackVar := PackVarEdit.Text;
  2625. UseDataVar := DataVarCheckBox.Checked;
  2626. DataVar := DataVarEdit.Text;
  2627. DataVarCopy := False;
  2628. DataVarCopyIfArchived := False;
  2629. if DataVarCopyAlwaysRadioButton.Checked then
  2630. DataVarCopy := True
  2631. else if DataVarCopyIfArchivedRadioButton.Checked then begin
  2632. DataVarCopy := True;
  2633. DataVarCopyIfArchived := True;
  2634. end;
  2635. GCCSwitches := GCCSwitchesEdit.Text;
  2636. AsSwitches := AsSwitchesEdit.Text;
  2637. AsmSwitches := AsmSwitchesEdit.Text;
  2638. DebugInfo := DebugInfoCheckBox.Checked;
  2639. OptimizeNOPs := OptimizeNOPsCheckBox.Checked;
  2640. OptimizeReturns := OptimizeReturnsCheckBox.Checked;
  2641. OptimizeBranches := OptimizeBranchesCheckBox.Checked;
  2642. OptimizeMoves := OptimizeMovesCheckBox.Checked;
  2643. OptimizeTests := OptimizeTestsCheckBox.Checked;
  2644. OptimizeCalculations := OptimizeCalculationsCheckBox.Checked;
  2645. RemoveUnusedSections := RemoveUnusedSectionsCheckBox.Checked;
  2646. CutUnusedRanges := CutUnusedRangesCheckBox.Checked;
  2647. ReorderSections := ReorderSectionsCheckBox.Checked;
  2648. MergeConstants := MergeConstantsCheckBox.Checked;
  2649. StdLib := StdLibCheckBox.Checked;
  2650. InitBSS := InitBSSCheckBox.Checked;
  2651. OutputBin := OutputBinCheckBox.Checked;
  2652. CommandLine := CommandLineEdit.Text;
  2653. PostBuildProcessFile := ProcessFileEdit.Text;
  2654. if Assigned (ProgramOptionsForm) and Assigned (PredefinedLibOptions) then
  2655. with ProgramOptionsForm, PredefinedLibOptions do begin
  2656. CalcDests := [];
  2657. if TI89CheckBox.Checked then
  2658. Include (CalcDests, cdTI89);
  2659. if TI92PlusCheckBox.Checked then
  2660. Include (CalcDests, cdTI92Plus);
  2661. if V200CheckBox.Checked then
  2662. Include (CalcDests, cdV200);
  2663. OptimizeCalcConsts := OptimizeCalcConstsCheckBox.Checked;
  2664. if PreOsRadioButton.Checked then
  2665. KernelFormat := kfCompressedTables
  2666. else if DoorsRadioButton.Checked then
  2667. KernelFormat := kfStandard
  2668. else
  2669. KernelFormat := kfNone;
  2670. UseMinAMS := MinAMSCheckBox.Checked;
  2671. if Length (MinAMSEdit.Text) > 0 then
  2672. MinAMS := MinAMSEdit.Text;
  2673. UnofficialOSSupport := UnofficialOSSupportCheckBox.Checked;
  2674. if RelocKernelRadioButton.Checked then
  2675. RelocFormat := rfKernel
  2676. else if RelocCompressedRadioButton.Checked then
  2677. RelocFormat := rfCompressed
  2678. else if RelocMlinkRadioButton.Checked then
  2679. RelocFormat := rfMlink
  2680. else
  2681. RelocFormat := rfAMS;
  2682. if ROMCallKernelRadioButton.Checked then
  2683. ROMCallFormat := rfKernel
  2684. else if ROMCallCompressedRadioButton.Checked then
  2685. ROMCallFormat := rfCompressed
  2686. else if ROMCallMlinkRadioButton.Checked then
  2687. ROMCallFormat := rfMlink
  2688. else if ROMCallFLineRadioButton.Checked then
  2689. ROMCallFormat := rfFLine
  2690. else
  2691. ROMCallFormat := rfDirect;
  2692. if BSSKernelRadioButton.Checked then
  2693. BSSRefFormat := rfKernel
  2694. else if BSSCompressedRadioButton.Checked then
  2695. BSSRefFormat := rfCompressed
  2696. else if BSSMlinkRadioButton.Checked then
  2697. BSSRefFormat := rfMlink
  2698. else
  2699. BSSRefFormat := rfNone;
  2700. if DataVarKernelRadioButton.Checked then
  2701. DataRefFormat := rfKernel
  2702. else if DataVarCompressedRadioButton.Checked then
  2703. DataRefFormat := rfCompressed
  2704. else if DataVarMlinkRadioButton.Checked then
  2705. DataRefFormat := rfMlink
  2706. else
  2707. DataRefFormat := rfNone;
  2708. UseFLineJumps := RelocFLineJumpsCheckBox.Checked;
  2709. Use4ByteFLineJumps := RelocFLineJumps4ByteCheckBox.Checked;
  2710. OptimizeROMCalls := ROMCallOptimizedCheckBox.Checked;
  2711. UseInternalFLineEmulator := InternalFLineEmulatorCheckBox.Checked;
  2712. UseReturnValue := ReturnValueRadioButton.Checked;
  2713. EnableErrorReturn := EnableErrorReturnCheckBox.Checked;
  2714. SaveScreen := LCDSaveCheckBox.Checked;
  2715. end;
  2716. RecompileFiles;
  2717. if not DebugInfo then
  2718. ClearDebugInfo;
  2719. UpdateDebugSettings;
  2720. Modify;
  2721. end;
  2722. finally
  2723. Free;
  2724. end;
  2725. end;
  2726. procedure TMainForm.FilePreferences(Sender: TObject);
  2727. var
  2728. I: Integer;
  2729. begin
  2730. with TPreferencesForm.Create (Self) do try
  2731. StopCompilationBox.Checked := StopOnErrors;
  2732. JumpToErrorBox.Checked := JumpToError;
  2733. OpenFolderBox.Checked := OpenFolderMessage;
  2734. DeleteAssemblyFilesBox.Checked := DeleteAssemblyFiles;
  2735. DeleteObjectFilesBox.Checked := DeleteObjectFiles;
  2736. {$IFDEF CanSplit}
  2737. SplitFilesCheckBox.Checked := SplitFiles;
  2738. {$ENDIF}
  2739. AutoSaveCheckBox.Checked := AutoSave;
  2740. AutoNewsCheckBox.Checked := AutoNews;
  2741. DeleteErrorsCheckBox.Checked := DeleteErrors;
  2742. AllowImplicitCheckBox.Checked := not AssumeUndefined;
  2743. FlatButtonsCheckBox.Checked := MainToolbar.Flat;
  2744. MenuBitmapsCheckBox.Checked := Assigned (MainMenu.Images);
  2745. case TransferTarget of
  2746. ttVTI:
  2747. VTIBox.Checked := True;
  2748. ttTIEmu:
  2749. TIEmuBox.Checked := True;
  2750. ttCalc:
  2751. RealCalcBox.Checked := True;
  2752. else
  2753. NoneBox.Checked := True;
  2754. end;
  2755. VTIPathEdit.Text := VTIPath;
  2756. TIEmuPathEdit.Text := TIEmuPath;
  2757. case LinkPort.PortType of
  2758. lpCOM: begin
  2759. case LinkPort.PortNumber of
  2760. 1: PortCOM1Box.Checked := True;
  2761. 2: PortCOM2Box.Checked := True;
  2762. 3: PortCOM3Box.Checked := True;
  2763. 4: PortCOM4Box.Checked := True;
  2764. end;
  2765. end;
  2766. end;
  2767. case LinkCable of
  2768. lcBlack: CableBlackBox.Checked := True;
  2769. lcGray: CableGrayBox.Checked := True;
  2770. end;
  2771. AsmTabSizeEdit.Text := IntToStr (TabSizeAsm);
  2772. CTabSizeEdit.Text := IntToStr (TabSizeC);
  2773. BackColor := EditorColor;
  2774. ColorCheckBox.Checked := BackColor <> clWindow;
  2775. EditorFont.Assign (MasterUnit.EditorFont);
  2776. OnFlyCheckBox.Checked := EditorOnFly;
  2777. DragDropEditCheckBox.Checked := EditorDragDrop;
  2778. RemoveTrailingSpcCheckBox.Checked := EditorRemoveTrSp;
  2779. AutoBlockCheckBox.Checked := AutoBlocks;
  2780. SyntaxC.Assign (MasterUnit.SyntaxC);
  2781. SyntaxAsmGNU.Assign (MasterUnit.SyntaxAsmGNU);
  2782. if ssA68k in SpecialSupport then
  2783. SyntaxAsm.Assign (MasterUnit.SyntaxAsm);
  2784. if ssQuill in SpecialSupport then
  2785. SyntaxQuill.Assign (MasterUnit.SyntaxQuill);
  2786. if ShowModal = mrOK then begin
  2787. Screen.Cursor := crHourGlass;
  2788. StopOnErrors := StopCompilationBox.Checked;
  2789. JumpToError := JumpToErrorBox.Checked;
  2790. OpenFolderMessage := OpenFolderBox.Checked;
  2791. DeleteAssemblyFiles := DeleteAssemblyFilesBox.Checked;
  2792. DeleteObjectFiles := DeleteObjectFilesBox.Checked;
  2793. {$IFDEF CanSplit}
  2794. SplitFiles := SplitFilesCheckBox.Checked;
  2795. {$ENDIF}
  2796. AutoSave := AutoSaveCheckBox.Checked;
  2797. AutoNews := AutoNewsCheckBox.Checked;
  2798. DeleteErrors := DeleteErrorsCheckBox.Checked;
  2799. AssumeUndefined := not AllowImplicitCheckBox.Checked;
  2800. MainToolbar.Flat := FlatButtonsCheckBox.Checked;
  2801. if MainToolbar.Flat then
  2802. MainToolbar.Height := MainToolbar.ButtonHeight + 1
  2803. else
  2804. MainToolbar.Height := MainToolbar.ButtonHeight + 3;
  2805. if MenuBitmapsCheckBox.Checked then
  2806. MainMenu.Images := ToolbarImages
  2807. else
  2808. MainMenu.Images := nil;
  2809. if VTIBox.Checked then
  2810. TransferTarget := ttVTI
  2811. else if TIEmuBox.Checked then
  2812. TransferTarget := ttTIEmu
  2813. else if RealCalcBox.Checked then
  2814. TransferTarget := ttCalc
  2815. else
  2816. TransferTarget := ttNone;
  2817. VTIPath := VTIPathEdit.Text;
  2818. TIEmuPath := TIEmuPathEdit.Text;
  2819. LinkPort.PortType := lpCOM;
  2820. if PortCOM1Box.Checked then
  2821. LinkPort.PortNumber := 1
  2822. else if PortCOM2Box.Checked then
  2823. LinkPort.PortNumber := 2
  2824. else if PortCOM3Box.Checked then
  2825. LinkPort.PortNumber := 3
  2826. else if PortCOM4Box.Checked then
  2827. LinkPort.PortNumber := 4;
  2828. if CableBlackBox.Checked then
  2829. LinkCable := lcBlack
  2830. else if CableGrayBox.Checked then
  2831. LinkCable := lcGray;
  2832. try
  2833. TabSizeC := StrToInt (CTabSizeEdit.Text);
  2834. except
  2835. TabSizeC := 2;
  2836. end;
  2837. try
  2838. TabSizeAsm := StrToInt (AsmTabSizeEdit.Text);
  2839. except
  2840. TabSizeAsm := 2;
  2841. end;
  2842. if ColorCheckBox.Checked then
  2843. EditorColor := BackColor
  2844. else
  2845. EditorColor := clWindow;
  2846. MasterUnit.EditorFont.Assign (EditorFont);
  2847. EditorOnFly := OnFlyCheckBox.Checked;
  2848. EditorDragDrop := DragDropEditCheckBox.Checked;
  2849. EditorRemoveTrSp := RemoveTrailingSpcCheckBox.Checked;
  2850. AutoBlocks := AutoBlockCheckBox.Checked;
  2851. with SourceFiles do
  2852. for I := 0 to Count - 1 do
  2853. if Items [I] is TTextSourceFile then
  2854. (Items [I] as TTextSourceFile).UpdateEditor;
  2855. if SyntaxTabClicked then begin
  2856. MasterUnit.SyntaxC.Assign (SyntaxC);
  2857. MasterUnit.SyntaxAsmGNU.Assign (SyntaxAsmGNU);
  2858. MasterUnit.SyntaxAsm.Assign (SyntaxAsm);
  2859. MasterUnit.SyntaxQuill.Assign (SyntaxQuill);
  2860. with SourceFiles do
  2861. for I := 0 to Count - 1 do
  2862. if Items [I] is TSourceTextSourceFile then
  2863. (Items [I] as TSourceTextSourceFile).UpdateSyntax;
  2864. end;
  2865. SavePreferences;
  2866. UpdateDebugSettings;
  2867. Screen.Cursor := crDefault;
  2868. end;
  2869. finally
  2870. Free;
  2871. end;
  2872. end;
  2873. procedure TMainForm.LoadPreferences;
  2874. function LookBackForComponent(Stream: TMemoryStream): Integer;
  2875. var
  2876. I: Integer;
  2877. P: PChar;
  2878. begin
  2879. Result := 0;
  2880. with Stream do begin
  2881. P := Memory;
  2882. for I := Size - 3 downto 1 do
  2883. if (P [I] = 'T') and (P [I + 1] = 'P') and (P [I + 2] = 'F') then begin
  2884. Result := I;
  2885. Break;
  2886. end;
  2887. end;
  2888. end;
  2889. var
  2890. I,
  2891. Tmp: Integer;
  2892. L: TStringList;
  2893. Strm: TMemoryStream;
  2894. SyntaxCopy: TSyntaxColoringCopy;
  2895. begin
  2896. with TRegistry.Create do try
  2897. if OpenKeyReadOnly (RegKey) then try
  2898. if ValueExists ('Open File') then
  2899. ProjectFile := ReadString ('Open File');
  2900. if ValueExists ('Recent Files') then begin
  2901. L := TStringList.Create;
  2902. try
  2903. L.CommaText := ReadString ('Recent Files');
  2904. for I := L.Count - 1 downto 0 do
  2905. AddToRecent (L.Strings [I]);
  2906. finally
  2907. L.Free;
  2908. end;
  2909. end;
  2910. if ValueExists ('Stop on Errors') then
  2911. StopOnErrors := ReadBool ('Stop on Errors');
  2912. if ValueExists ('Jump To First Error') then
  2913. JumpToError := ReadBool ('Jump To First Error');
  2914. if ValueExists ('Open Folder Message') then
  2915. OpenFolderMessage := ReadBool ('Open Folder Message');
  2916. if ValueExists ('Delete Assembly Files') then
  2917. DeleteAssemblyFiles := ReadBool ('Delete Assembly Files');
  2918. if ValueExists ('Delete Object Files') then
  2919. DeleteObjectFiles := ReadBool ('Delete Object Files');
  2920. {$IFDEF CanSplit}
  2921. if ValueExists ('Split Files') then
  2922. SplitFiles := ReadBool ('Split Files');
  2923. {$ENDIF}
  2924. if ValueExists ('AutoSave') then
  2925. AutoSave := ReadBool ('AutoSave');
  2926. if ValueExists ('AutoNews') then
  2927. AutoNews := ReadBool ('AutoNews');
  2928. if ValueExists ('Delete Errors') then
  2929. DeleteErrors := ReadBool ('Delete Errors');
  2930. if ValueExists ('Assume Undefined References') then
  2931. AssumeUndefined := ReadBool ('Assume Undefined References');
  2932. if ValueExists ('Flat Buttons') then
  2933. MainToolbar.Flat := ReadBool ('Flat Buttons');
  2934. if MainToolbar.Flat then
  2935. MainToolbar.Height := MainToolbar.ButtonHeight + 1
  2936. else
  2937. MainToolbar.Height := MainToolbar.ButtonHeight + 3;
  2938. if ValueExists ('Menu Bitmaps') then begin
  2939. if ReadBool ('Menu Bitmaps') then
  2940. MainMenu.Images := ToolbarImages
  2941. else
  2942. MainMenu.Images := nil;
  2943. end;
  2944. if ValueExists ('Transfer Target') then
  2945. TransferTarget := TTransferTarget (ReadInteger ('Transfer Target') + 1);
  2946. if ValueExists ('VTI Path') then
  2947. VTIPath := ReadString ('VTI Path');
  2948. if ValueExists ('TiEmu Path') then
  2949. TIEmuPath := ReadString ('TiEmu Path');
  2950. if ValueExists ('Link Port') then
  2951. LinkPort.PortNumber := ReadInteger ('Link Port') and $FF;
  2952. if ValueExists ('Link Cable') then begin
  2953. if ReadInteger ('Link Cable') = 2 then
  2954. LinkCable := lcGray
  2955. else
  2956. LinkCable := lcBlack;
  2957. end;
  2958. if ValueExists ('ASM Tab Size') then
  2959. TabSizeAsm := ReadInteger ('ASM Tab Size');
  2960. if ValueExists ('C Tab Size') then
  2961. TabSizeC := ReadInteger ('C Tab Size');
  2962. if ValueExists ('Editor Background Color') then
  2963. EditorColor := ReadInteger ('Editor Background Color');
  2964. if ValueExists ('Editor Font') then
  2965. EditorFont.Name := ReadString ('Editor Font');
  2966. if ValueExists ('Editor Font Style Bold') then begin
  2967. EditorFont.Style := [];
  2968. if ReadBool ('Editor Font Style Bold') then
  2969. EditorFont.Style := EditorFont.Style + [fsBold];
  2970. if ReadBool ('Editor Font Style Italic') then
  2971. EditorFont.Style := EditorFont.Style + [fsItalic];
  2972. if ReadBool ('Editor Font Style Underline') then
  2973. EditorFont.Style := EditorFont.Style + [fsUnderline];
  2974. if ReadBool ('Editor Font Style StrikeOut') then
  2975. EditorFont.Style := EditorFont.Style + [fsStrikeOut];
  2976. end;
  2977. if ValueExists ('Editor Font Size') then
  2978. EditorFont.Size := ReadInteger ('Editor Font Size');
  2979. if ValueExists ('Editor Font Color') then
  2980. EditorFont.Color := ReadInteger ('Editor Font Color');
  2981. if ValueExists ('Editor Font Pitch') then
  2982. EditorFont.Pitch := TFontPitch (ReadInteger ('Editor Font Pitch'));
  2983. if ValueExists ('Editor Split On Fly') then
  2984. EditorOnFly := ReadBool ('Editor Split On Fly');
  2985. if ValueExists ('Editor Drag and Drop') then
  2986. EditorDragDrop := ReadBool ('Editor Drag and Drop');
  2987. if ValueExists ('Editor Remove Trailing Spaces') then
  2988. EditorRemoveTrSp := ReadBool ('Editor Remove Trailing Spaces');
  2989. if ValueExists ('AutoBlocks') then
  2990. AutoBlocks := ReadBool ('AutoBlocks');
  2991. if ValueExists ('Tree Width') then
  2992. ProjectTree.Width := ReadInteger ('Tree Width');
  2993. if ValueExists ('Error Window Height') then
  2994. ErrWinPanel.Height := ReadInteger ('Error Window Height');
  2995. if ValueExists ('Error List Message') then
  2996. ErrorList.Columns[0].Width := ReadInteger ('Error List Message');
  2997. if ValueExists ('Error List File') then
  2998. ErrorList.Columns[1].Width := ReadInteger ('Error List File');
  2999. if ValueExists ('Error List Function') then
  3000. ErrorList.Columns[2].Width := ReadInteger ('Error List Function');
  3001. if ValueExists ('Last News Update') then
  3002. LastNewsDate := ReadInteger ('Last News Update');
  3003. if ValueExists ('Proxy Name') then
  3004. ProxyName := ReadString ('Proxy Name');
  3005. if ValueExists ('Proxy Port') then
  3006. ProxyPort := ReadInteger ('Proxy Port');
  3007. Strm := TMemoryStream.Create;
  3008. if ValueExists ('Editor C Syntax Coloring') then try
  3009. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3010. try
  3011. SyntaxCopy.Assign (SyntaxC);
  3012. Strm.SetSize (GetDataSize ('Editor C Syntax Coloring'));
  3013. if Strm.Size > 0 then begin
  3014. ReadBinaryData ('Editor C Syntax Coloring', Strm.Memory^, Strm.Size);
  3015. Strm.Position := LookBackForComponent (Strm);
  3016. Strm.ReadComponent (SyntaxCopy);
  3017. SyntaxC.Assign (SyntaxCopy);
  3018. end;
  3019. finally
  3020. SyntaxCopy.Free;
  3021. end;
  3022. except end;
  3023. if ValueExists ('Editor GNU ASM Syntax Coloring') then try
  3024. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3025. try
  3026. SyntaxCopy.Assign (SyntaxAsmGNU);
  3027. Strm.SetSize (GetDataSize ('Editor GNU ASM Syntax Coloring'));
  3028. if Strm.Size > 0 then begin
  3029. ReadBinaryData ('Editor GNU ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3030. Strm.Position := LookBackForComponent (Strm);
  3031. Strm.ReadComponent (SyntaxCopy);
  3032. SyntaxAsmGNU.Assign (SyntaxCopy);
  3033. end;
  3034. finally
  3035. SyntaxCopy.Free;
  3036. end;
  3037. except end;
  3038. if (ssA68k in SpecialSupport) and ValueExists ('Editor ASM Syntax Coloring') then try
  3039. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3040. try
  3041. SyntaxCopy.Assign (SyntaxAsm);
  3042. Strm.SetSize (GetDataSize ('Editor ASM Syntax Coloring'));
  3043. if Strm.Size > 0 then begin
  3044. ReadBinaryData ('Editor ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3045. Strm.Position := LookBackForComponent (Strm);
  3046. Strm.ReadComponent (SyntaxCopy);
  3047. SyntaxAsm.Assign (SyntaxCopy);
  3048. end;
  3049. finally
  3050. SyntaxCopy.Free;
  3051. end;
  3052. except end;
  3053. if (ssQuill in SpecialSupport) and ValueExists ('Editor Quill Syntax Coloring') then try
  3054. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3055. try
  3056. SyntaxCopy.Assign (SyntaxQuill);
  3057. Strm.SetSize (GetDataSize ('Editor Quill Syntax Coloring'));
  3058. if Strm.Size > 0 then begin
  3059. ReadBinaryData ('Editor Quill Syntax Coloring', Strm.Memory^, Strm.Size);
  3060. Strm.Position := LookBackForComponent (Strm);
  3061. Strm.ReadComponent (SyntaxCopy);
  3062. SyntaxQuill.Assign (SyntaxCopy);
  3063. end;
  3064. finally
  3065. SyntaxCopy.Free;
  3066. end;
  3067. except end;
  3068. Strm.Free;
  3069. if ValueExists ('Tools Count') then begin
  3070. Tmp := ReadInteger ('Tools Count');
  3071. ToolsList.Clear;
  3072. for I := 1 to Tmp do
  3073. if OpenKeyReadOnly (RegKey + '\Tool ' + IntToStr (I)) then try
  3074. ToolsLine.Visible := True;
  3075. AddTool (ReadString ('Title'), ReadString ('Command Line'), ReadString ('Working Directory'), TWindowState (ReadInteger ('Window State')));
  3076. except end;
  3077. end;
  3078. except end;
  3079. finally
  3080. Free;
  3081. SplitterMoved (Self);
  3082. end;
  3083. with SourceFiles do
  3084. for I := 0 to Count - 1 do begin
  3085. if Items [I] is TTextSourceFile then
  3086. (Items [I] as TTextSourceFile).UpdateEditor;
  3087. if Items [I] is TSourceTextSourceFile then
  3088. (Items [I] as TSourceTextSourceFile).UpdateSyntax;
  3089. end;
  3090. UpdateDebugSettings;
  3091. end;
  3092. procedure TMainForm.SavePreferences;
  3093. var
  3094. I: Integer;
  3095. Strm: TMemoryStream;
  3096. SyntaxCopy: TSyntaxColoringCopy;
  3097. begin
  3098. with TRegistry.Create do try
  3099. if OpenKey (RegKey, True) then try
  3100. WriteString ('Open File', ProjectFile);
  3101. WriteString ('Recent Files', RecentFiles.CommaText);
  3102. WriteBool ('Stop on Errors', StopOnErrors);
  3103. WriteBool ('Jump To First Error', JumpToError);
  3104. WriteBool ('Open Folder Message', OpenFolderMessage);
  3105. WriteBool ('Delete Assembly Files', DeleteAssemblyFiles);
  3106. WriteBool ('Delete Object Files', DeleteObjectFiles);
  3107. {$IFDEF CanSplit}
  3108. WriteBool ('Split Files', SplitFiles);
  3109. {$ENDIF}
  3110. WriteBool ('AutoSave', AutoSave);
  3111. WriteBool ('AutoNews', AutoNews);
  3112. WriteBool ('Delete Errors', DeleteErrors);
  3113. WriteBool ('Assume Undefined References', AssumeUndefined);
  3114. WriteBool ('Flat Buttons', MainToolbar.Flat);
  3115. WriteBool ('Menu Bitmaps', Assigned (MainMenu.Images));
  3116. WriteInteger ('Transfer Target', Integer (TransferTarget) - 1);
  3117. WriteString ('VTI Path', VTIPath);
  3118. WriteString ('TiEmu Path', TIEmuPath);
  3119. WriteInteger ('Link Port', LinkPort.PortNumber);
  3120. case LinkCable of
  3121. lcBlack: WriteInteger ('Link Cable', 1);
  3122. lcGray: WriteInteger ('Link Cable', 2);
  3123. end;
  3124. WriteInteger ('ASM Tab Size', TabSizeAsm);
  3125. WriteInteger ('C Tab Size', TabSizeC);
  3126. WriteInteger ('Editor Background Color', EditorColor);
  3127. WriteString ('Editor Font', EditorFont.Name);
  3128. WriteBool ('Editor Font Style Bold', fsBold in EditorFont.Style);
  3129. WriteBool ('Editor Font Style Italic', fsItalic in EditorFont.Style);
  3130. WriteBool ('Editor Font Style Underline', fsUnderline in EditorFont.Style);
  3131. WriteBool ('Editor Font Style StrikeOut', fsStrikeOut in EditorFont.Style);
  3132. WriteInteger ('Editor Font Size', EditorFont.Size);
  3133. WriteInteger ('Editor Font Color', EditorFont.Color);
  3134. WriteInteger ('Editor Font Pitch', Integer (EditorFont.Pitch));
  3135. WriteBool ('Editor Split On Fly', EditorOnFly);
  3136. WriteBool ('Editor Drag and Drop', EditorDragDrop);
  3137. WriteBool ('Editor Remove Trailing Spaces', EditorRemoveTrSp);
  3138. WriteBool ('AutoBlocks', AutoBlocks);
  3139. WriteInteger ('Tree Width', ProjectTree.Width);
  3140. WriteInteger ('Error Window Height', ErrWinPanel.Height);
  3141. WriteInteger ('Error List Message', ErrorList.Columns[0].Width);
  3142. WriteInteger ('Error List File', ErrorList.Columns[1].Width);
  3143. WriteInteger ('Error List Function', ErrorList.Columns[2].Width);
  3144. WriteInteger ('Last News Update', LastNewsDate);
  3145. WriteString ('Proxy Name', ProxyName);
  3146. WriteInteger ('Proxy Port', ProxyPort);
  3147. Strm := TMemoryStream.Create;
  3148. try
  3149. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3150. try
  3151. SyntaxCopy.Assign (SyntaxC);
  3152. Strm.WriteComponent (SyntaxCopy);
  3153. WriteBinaryData ('Editor C Syntax Coloring', Strm.Memory^, Strm.Size);
  3154. if (SyntaxCReset) then begin
  3155. WriteInteger ('Editor C Syntax Coloring Version', 1);
  3156. end;
  3157. finally
  3158. SyntaxCopy.Free;
  3159. end;
  3160. Strm.Clear;
  3161. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3162. try
  3163. SyntaxCopy.Assign (SyntaxAsmGNU);
  3164. Strm.WriteComponent (SyntaxCopy);
  3165. WriteBinaryData ('Editor GNU ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3166. if (SyntaxAsmGNUReset) then begin
  3167. WriteInteger ('Editor GNU ASM Syntax Coloring Version', 1);
  3168. end;
  3169. finally
  3170. SyntaxCopy.Free;
  3171. end;
  3172. if ssA68k in SpecialSupport then begin
  3173. Strm.Clear;
  3174. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3175. try
  3176. SyntaxCopy.Assign (SyntaxAsm);
  3177. Strm.WriteComponent (SyntaxCopy);
  3178. WriteBinaryData ('Editor ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3179. if (SyntaxAsmReset) then begin
  3180. WriteInteger ('Editor ASM Syntax Coloring Version', 1);
  3181. end;
  3182. finally
  3183. SyntaxCopy.Free;
  3184. end;
  3185. end;
  3186. if ssQuill in SpecialSupport then begin
  3187. Strm.Clear;
  3188. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3189. try
  3190. SyntaxCopy.Assign (SyntaxQuill);
  3191. Strm.WriteComponent (SyntaxCopy);
  3192. WriteBinaryData ('Editor Quill Syntax Coloring', Strm.Memory^, Strm.Size);
  3193. if (SyntaxQuillReset) then begin
  3194. WriteInteger ('Editor Quill Syntax Coloring Version', 1);
  3195. end;
  3196. finally
  3197. SyntaxCopy.Free;
  3198. end;
  3199. end;
  3200. finally
  3201. Strm.Free;
  3202. end;
  3203. WriteInteger ('Tools Count', ToolsList.Count);
  3204. with ToolsList do
  3205. for I := 0 to Count - 1 do
  3206. with TToolsListItem (Items [I]) do
  3207. if OpenKey (RegKey + '\Tool ' + IntToStr (I + 1), True) then try
  3208. WriteString ('Title', Title);
  3209. WriteString ('Command Line', CommandLine);
  3210. WriteString ('Working Directory', WorkingDir);
  3211. WriteInteger ('Window State', Integer (WindowState));
  3212. except end;
  3213. except end;
  3214. finally
  3215. Free;
  3216. end;
  3217. end;
  3218. procedure TMainForm.CompileProject;
  3219. var
  3220. I: Integer;
  3221. StopIt: Boolean;
  3222. begin
  3223. OperationSuccessful := False;
  3224. OperationCancelled := False;
  3225. StopIt := True;
  3226. with SourceFiles do
  3227. for I := 0 to Count - 1 do
  3228. with Items [I] as TSourceFile do
  3229. if Compilable or (Items [I] is TObjectSourceFile) then begin
  3230. StopIt := False;
  3231. Break;
  3232. end;
  3233. if not StopIt then begin
  3234. OperationSuccessful := True;
  3235. CopyHeaders;
  3236. with SourceFiles do
  3237. for I := 0 to Count - 1 do
  3238. if (OperationSuccessful or not StopOnErrors) and not OperationCancelled then
  3239. with Items [I] as TSourceFile do
  3240. if Compilable and Invalidated then begin
  3241. Compile;
  3242. if not OperationSuccessful then
  3243. StopIt := True;
  3244. Application.ProcessMessages;
  3245. end;
  3246. DeleteHeaders;
  3247. if StopIt then
  3248. OperationSuccessful := False;
  3249. end else
  3250. ShowDefaultMessageBox ('There are no files to compile in the current project.', 'Error', mtProgramError);
  3251. end;
  3252. function TMainForm.GetNewFileName(const FolderPath, Ext: string): string;
  3253. var
  3254. I: Integer;
  3255. begin
  3256. if ProjectFile = '' then
  3257. Result := 'C:\New File'
  3258. else
  3259. Result := WithBackslash (ExtractFilePath (ProjectFile) + FolderPath) + 'New File';
  3260. if FileExists (Result + Ext) or Assigned (SourceFiles.FindFileWithoutExt (Result)) then begin
  3261. I := 2;
  3262. while FileExists (Result + ' ' + IntToStr (I) + Ext) or Assigned (SourceFiles.FindFileWithoutExt (Result + ' ' + IntToStr (I))) do
  3263. Inc (I);
  3264. Result := Result + ' ' + IntToStr (I);
  3265. end;
  3266. Result := Result + Ext;
  3267. end;
  3268. procedure TMainForm.FileNewHeaderFile(Sender: TObject);
  3269. var
  3270. O: THeaderSourceFile;
  3271. begin
  3272. if not Compiling then begin
  3273. O := THeaderSourceFile.Create (SourceFiles);
  3274. with O do begin
  3275. Folder := GetSelectedFolder (THeaderSourceFile);
  3276. FileName := GetNewFileName (FolderPath, '.h');
  3277. OnError := AddError;
  3278. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3279. with TreeItem do begin
  3280. ImageIndex := ClassImageIndex;
  3281. SelectedIndex := ImageIndex;
  3282. end;
  3283. ErrorList := Self.ErrorList;
  3284. if Assigned (TextEditor) then
  3285. with TextEditor do begin
  3286. Hide;
  3287. Parent := EditorPanel;
  3288. Align := alClient;
  3289. OnEnter := EditorEnter;
  3290. OnExit := EditorExit;
  3291. OnKeyDown := EditorKeyDown;
  3292. OnChange := EditorChange;
  3293. OnSelectionChange := EditorChange;
  3294. PopupMenu := EditorPopup;
  3295. end;
  3296. if (Sender = ActionFileNewGNUAsmHeaderFile) or ((Sender is TMenuItem) and (TMenuItem(Sender).Action = ActionFileNewGNUAsmHeaderFile)) then
  3297. Content := '| Header File'#13#10'| Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10
  3298. else if (Sender = ActionFileNewA68kAsmHeaderFile) or ((Sender is TMenuItem) and (TMenuItem(Sender).Action = ActionFileNewA68kAsmHeaderFile)) then
  3299. Content := '; Header File'#13#10'; Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10
  3300. else
  3301. Content := '// Header File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3302. UpdateSyntax;
  3303. if Assigned (TextEditor) then
  3304. TextEditor.ClearUndo;
  3305. Modified := False;
  3306. Invalidate;
  3307. SelectNode (TreeItem);
  3308. TreeItem.EditText;
  3309. end;
  3310. end;
  3311. end;
  3312. procedure TMainForm.FileNewCSourceFile(Sender: TObject);
  3313. const
  3314. CodeStr = '// Place your code here.';
  3315. var
  3316. O: TCSourceFile;
  3317. I,
  3318. P: Integer;
  3319. NewContent: string;
  3320. FirstFile: Boolean;
  3321. begin
  3322. if not Compiling then begin
  3323. FirstFile := not Assigned (SourceFiles.FindFileOfTypeInProject (TCSourceFile));
  3324. O := TCSourceFile.Create (SourceFiles);
  3325. with O do begin
  3326. Folder := GetSelectedFolder (TCSourceFile);
  3327. FileName := GetNewFileName (FolderPath, '.c');
  3328. OnError := AddError;
  3329. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3330. with TreeItem do begin
  3331. ImageIndex := ClassImageIndex;
  3332. SelectedIndex := ImageIndex;
  3333. end;
  3334. ErrorList := Self.ErrorList;
  3335. if Assigned (TextEditor) then
  3336. with TextEditor do begin
  3337. Hide;
  3338. Parent := EditorPanel;
  3339. Align := alClient;
  3340. OnEnter := EditorEnter;
  3341. OnExit := EditorExit;
  3342. OnKeyDown := EditorKeyDown;
  3343. OnChange := EditorChange;
  3344. OnSelectionChange := EditorChange;
  3345. PopupMenu := EditorPopup;
  3346. end;
  3347. NewContent := '// C Source File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3348. case ProjectTarget of
  3349. ptRegular: begin
  3350. if FirstFile then begin
  3351. NewContent := NewContent + #13#10
  3352. + '// Delete or comment out the items you do not need.'#13#10
  3353. + '#define COMMENT_STRING "Place your comment here."'#13#10
  3354. + '#define COMMENT_PROGRAM_NAME "Place your program name here."'#13#10
  3355. + '#define COMMENT_VERSION_STRING "Place your version string here."'#13#10
  3356. + '#define COMMENT_VERSION_NUMBER 0,0,0,0 /* major, minor, revision, subrevision */'#13#10
  3357. + '#define COMMENT_AUTHORS "Place your author name(s) here."'#13#10
  3358. + '#define COMMENT_BW_ICON \'#13#10
  3359. + #9'{0b0000000000000000, \'#13#10;
  3360. for I := 1 to 14 do
  3361. NewContent := NewContent
  3362. + #9' 0b0000000000000000, \'#13#10;
  3363. NewContent := NewContent
  3364. + #9' 0b0000000000000000}'#13#10
  3365. + '#define COMMENT_GRAY_ICON \'#13#10
  3366. + #9'{0b0000000000000000, \'#13#10;
  3367. for I := 1 to 14 do
  3368. NewContent := NewContent
  3369. + #9' 0b0000000000000000, \'#13#10;
  3370. NewContent := NewContent
  3371. + #9' 0b0000000000000000}, \'#13#10
  3372. + #9'{0b0000000000000000, \'#13#10;
  3373. for I := 1 to 14 do
  3374. NewContent := NewContent
  3375. + #9' 0b0000000000000000, \'#13#10;
  3376. NewContent := NewContent
  3377. + #9' 0b0000000000000000}'#13#10;
  3378. end;
  3379. NewContent := NewContent + #13#10'#include <tigcclib.h>'#13#10;
  3380. end;
  3381. ptArchive:
  3382. NewContent := NewContent + #13#10'#define _GENERIC_ARCHIVE'#13#10'#include <tigcclib.h>'#13#10;
  3383. end;
  3384. if FirstFile and (not (ProjectTarget in [ptFlashOS, ptArchive])) then
  3385. NewContent := NewContent + #13#10'// Main Function'#13#10'void _main(void)'#13#10
  3386. + '{'#13#10
  3387. + #9 + CodeStr + #13#10
  3388. + '}'#13#10;
  3389. if Assigned (TextEditor) then
  3390. TextEditor.AllowUndo := False;
  3391. Content := NewContent;
  3392. if Assigned (TextEditor) then begin
  3393. TextEditor.AllowUndo := True;
  3394. P := Pos (CodeStr, TextEditor.Text);
  3395. if P > 0 then
  3396. with TextEditor.Selection do begin
  3397. RStart := P;
  3398. RLength := Length (CodeStr);
  3399. end;
  3400. end;
  3401. Modified := False;
  3402. Invalidate;
  3403. SelectNode (TreeItem);
  3404. TreeItem.EditText;
  3405. end;
  3406. end;
  3407. end;
  3408. procedure TMainForm.FileNewGNUAssemblerSourceFile(Sender: TObject);
  3409. var
  3410. O: TGNUAsmSourceFile;
  3411. begin
  3412. if not Compiling then begin
  3413. O := TGNUAsmSourceFile.Create (SourceFiles);
  3414. with O do begin
  3415. Folder := GetSelectedFolder (TGNUAsmSourceFile);
  3416. FileName := GetNewFileName (FolderPath, '.s');
  3417. OnError := AddError;
  3418. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3419. with TreeItem do begin
  3420. ImageIndex := ClassImageIndex;
  3421. SelectedIndex := ImageIndex;
  3422. end;
  3423. ErrorList := Self.ErrorList;
  3424. if Assigned (TextEditor) then
  3425. with TextEditor do begin
  3426. Hide;
  3427. Parent := EditorPanel;
  3428. Align := alClient;
  3429. OnEnter := EditorEnter;
  3430. OnExit := EditorExit;
  3431. OnKeyDown := EditorKeyDown;
  3432. OnChange := EditorChange;
  3433. OnSelectionChange := EditorChange;
  3434. PopupMenu := EditorPopup;
  3435. end;
  3436. Content := '| Assembly Source File'#13#10'| Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3437. if Assigned (TextEditor) then
  3438. TextEditor.ClearUndo;
  3439. Modified := False;
  3440. Invalidate;
  3441. SelectNode (TreeItem);
  3442. TreeItem.EditText;
  3443. end;
  3444. end;
  3445. end;
  3446. procedure TMainForm.FileNewAssemblerSourceFile(Sender: TObject);
  3447. var
  3448. O: TAsmSourceFile;
  3449. begin
  3450. if not Compiling then begin
  3451. O := TAsmSourceFile.Create (SourceFiles);
  3452. with O do begin
  3453. Folder := GetSelectedFolder (TAsmSourceFile);
  3454. FileName := GetNewFileName (FolderPath, '.asm');
  3455. OnError := AddError;
  3456. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3457. with TreeItem do begin
  3458. ImageIndex := ClassImageIndex;
  3459. SelectedIndex := ImageIndex;
  3460. end;
  3461. ErrorList := Self.ErrorList;
  3462. if Assigned (TextEditor) then
  3463. with TextEditor do begin
  3464. Hide;
  3465. Parent := EditorPanel;
  3466. Align := alClient;
  3467. OnEnter := EditorEnter;
  3468. OnExit := EditorExit;
  3469. OnKeyDown := EditorKeyDown;
  3470. OnChange := EditorChange;
  3471. OnSelectionChange := EditorChange;
  3472. PopupMenu := EditorPopup;
  3473. end;
  3474. Content := '; Assembly Source File'#13#10'; Created ' + DateToStr (Now) + ', ' + TimeToStr (Now) + #13#10;
  3475. if Assigned (TextEditor) then
  3476. TextEditor.ClearUndo;
  3477. Modified := False;
  3478. Invalidate;
  3479. SelectNode (TreeItem);
  3480. TreeItem.EditText;
  3481. end;
  3482. end;
  3483. end;
  3484. procedure TMainForm.FileNewQuillSourceFile(Sender: TObject);
  3485. var
  3486. O: TQuillSourceFile;
  3487. begin
  3488. if not Compiling then begin
  3489. if Assigned (SourceFiles.FindFileOfTypeInProject (TQuillSourceFile)) then
  3490. ShowDefaultMessageBox ('There may be only one Quill source file in each project.', 'Quill Error', mtProgramError)
  3491. else begin
  3492. O := TQuillSourceFile.Create (SourceFiles);
  3493. with O do begin
  3494. Folder := GetSelectedFolder (TQuillSourceFile);
  3495. FileName := GetNewFileName (FolderPath, '.qll');
  3496. OnError := AddError;
  3497. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3498. with TreeItem do begin
  3499. ImageIndex := ClassImageIndex;
  3500. SelectedIndex := ImageIndex;
  3501. end;
  3502. ErrorList := Self.ErrorList;
  3503. if Assigned (TextEditor) then
  3504. with TextEditor do begin
  3505. Hide;
  3506. Parent := EditorPanel;
  3507. Align := alClient;
  3508. OnEnter := EditorEnter;
  3509. OnExit := EditorExit;
  3510. OnKeyDown := EditorKeyDown;
  3511. OnChange := EditorChange;
  3512. OnSelectionChange := EditorChange;
  3513. PopupMenu := EditorPopup;
  3514. end;
  3515. if FileExists (WithBackslash (TIGCCFolder) + QuillIncludeLocation + 'Template.qll') then
  3516. LoadFromFile (WithBackslash (TIGCCFolder) + QuillIncludeLocation + 'Template.qll')
  3517. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + 'Template.qll') then
  3518. LoadFromFile (WithBackslash (TIGCCFolder) + CIncludeLocation + 'Template.qll')
  3519. else if FileExists (WithBackslash (TIGCCFolder) + GCCLocation + 'Template.qll') then
  3520. LoadFromFile (WithBackslash (TIGCCFolder) + GCCLocation + 'Template.qll');
  3521. Content := '// Quill Source File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10#13#10 + Content;
  3522. if Assigned (TextEditor) then
  3523. TextEditor.ClearUndo;
  3524. Modified := False;
  3525. Invalidate;
  3526. SelectNode (TreeItem);
  3527. TreeItem.EditText;
  3528. end;
  3529. end;
  3530. end;
  3531. end;
  3532. procedure TMainForm.FileNewTextFile(Sender: TObject);
  3533. var
  3534. O: TNormalTextSourceFile;
  3535. begin
  3536. O := TNormalTextSourceFile.Create (SourceFiles);
  3537. with O do begin
  3538. Folder := GetSelectedFolder (TTextSourceFile);
  3539. FileName := GetNewFileName (FolderPath, '.txt');
  3540. OnError := AddError;
  3541. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3542. with TreeItem do begin
  3543. ImageIndex := ClassImageIndex;
  3544. SelectedIndex := ImageIndex;
  3545. end;
  3546. ErrorList := Self.ErrorList;
  3547. if Assigned (TextEditor) then
  3548. with TextEditor do begin
  3549. Hide;
  3550. Parent := EditorPanel;
  3551. Align := alClient;
  3552. OnEnter := EditorEnter;
  3553. OnExit := EditorExit;
  3554. OnKeyDown := EditorKeyDown;
  3555. OnChange := EditorChange;
  3556. OnSelectionChange := EditorChange;
  3557. PopupMenu := EditorPopup;
  3558. end;
  3559. if Assigned (TextEditor) then
  3560. TextEditor.ClearUndo;
  3561. Modified := False;
  3562. SelectNode (TreeItem);
  3563. TreeItem.EditText;
  3564. end;
  3565. end;
  3566. procedure TMainForm.TreeItemSaveAs(Sender: TObject);
  3567. var
  3568. Node: TTreeNode;
  3569. begin
  3570. Node := ProjectTree.Selected;
  3571. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  3572. TSourceFile(Node.Data).SaveAs;
  3573. Modify;
  3574. UpdateStatusBar;
  3575. end;
  3576. end;
  3577. procedure TMainForm.BeginCompilation;
  3578. var
  3579. I: Integer;
  3580. begin
  3581. ClearErrors;
  3582. with SourceFiles do
  3583. for I := 0 to Count - 1 do
  3584. with Items [I] as TSourceFile do
  3585. if not InProject then begin
  3586. RecompileFiles;
  3587. Break;
  3588. end;
  3589. OperationCancelled := False;
  3590. OperationSuccessful := False;
  3591. end;
  3592. procedure TMainForm.EndCompilation;
  3593. begin
  3594. CompStop;
  3595. Application.Restore;
  3596. UpdateErrorWindow;
  3597. ShowErrors;
  3598. end;
  3599. procedure TMainForm.HelpAbout(Sender: TObject);
  3600. begin
  3601. with TAboutForm.Create (Self) do try
  3602. ShowModal;
  3603. finally
  3604. Free;
  3605. end;
  3606. end;
  3607. procedure TMainForm.DisplayHint(Sender: TObject);
  3608. begin
  3609. with StatusBar.Panels do begin
  3610. BeginUpdate;
  3611. with Items [0] do begin
  3612. if Application.Hint = '' then
  3613. Width := 0
  3614. else
  3615. Width := 1000000;
  3616. Text := Application.Hint;
  3617. end;
  3618. EndUpdate;
  3619. end;
  3620. end;
  3621. procedure TMainForm.ShowHideErrors(Sender: TObject);
  3622. begin
  3623. with ActionProjectShowErrors do begin
  3624. if Checked then
  3625. HideErrors
  3626. else
  3627. ShowErrors;
  3628. end;
  3629. end;
  3630. procedure TMainForm.UpdateEditButtons;
  3631. var
  3632. TextSel: Boolean;
  3633. Editor: TMemoComponent;
  3634. begin
  3635. Editor := CurrentEditor;
  3636. if Assigned (Editor) then begin
  3637. TextSel := (Editor.SelLength > 0) and (ActiveControl = Editor);
  3638. ActionEditDelete.Enabled := TextSel;
  3639. ActionEditCut.Enabled := TextSel;
  3640. ActionEditCopy.Enabled := TextSel;
  3641. ActionEditUndo.Enabled := (ActiveControl = Editor) and Editor.CanUndo;
  3642. ActionEditRedo.Enabled := (ActiveControl = Editor) and Editor.CanRedo;
  3643. end;
  3644. end;
  3645. procedure TMainForm.RecompileFiles;
  3646. var
  3647. I: Integer;
  3648. begin
  3649. with SourceFiles do
  3650. for I := 0 to Count - 1 do
  3651. with Items [I] as TSourceFile do
  3652. if Items [I] is THeaderSourceFile then
  3653. Invalidated := False
  3654. else if Compilable then
  3655. Invalidate;
  3656. end;
  3657. procedure TMainForm.FindString(Sender: TObject; AllFiles: Boolean);
  3658. var
  3659. P: Integer;
  3660. S,
  3661. T: string;
  3662. Valid: Boolean;
  3663. FPos: Integer;
  3664. Editor: TMemoComponent;
  3665. NewSelection: TTreeNode;
  3666. FirstFile: Boolean;
  3667. begin
  3668. NewSelection := ProjectTree.Selected;
  3669. if not Assigned (NewSelection) then
  3670. NewSelection := TopNode;
  3671. Valid := False;
  3672. FirstFile := True;
  3673. repeat
  3674. if Assigned (NewSelection.Data) and (TObject (NewSelection.Data) is TSourceFile) then
  3675. if TSourceFile (NewSelection.Data) is TTextSourceFile then begin
  3676. Editor := TTextSourceFile(NewSelection.Data).TextEditor;
  3677. if Assigned (Editor) then begin
  3678. with Sender as TFindDialog do begin
  3679. if (frFindNext in Options) and FirstFile then
  3680. P := Editor.Selection.REnd
  3681. else
  3682. if frDown in Options then
  3683. P := 0
  3684. else
  3685. P := Length (Editor.Text);
  3686. repeat
  3687. if frDown in Options then
  3688. T := Copy (Editor.Text, P + 1, Length (Editor.Text))
  3689. else
  3690. T := Copy (Editor.Text, 1, P - 1);
  3691. if frMatchCase in Options then
  3692. S := FindText
  3693. else begin
  3694. S := UpperCase (FindText);
  3695. T := UpperCase (T);
  3696. end;
  3697. if frDown in Options then
  3698. FPos := Pos (S, T)
  3699. else
  3700. FPos := LastPos (S, T);
  3701. if FPos > 0 then begin
  3702. Valid := True;
  3703. if frWholeWord in Options then begin
  3704. if ((FPos > 1) and (T <> '') and (T [FPos - 1] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  3705. Valid := False;
  3706. if ((FPos + Length (S) < Length (T)) and (T <> '') and (T [FPos + Length (S)] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  3707. Valid := False;
  3708. end;
  3709. if not (frDown in Options) then
  3710. P := 0;
  3711. if not Valid then
  3712. Inc (P, FPos);
  3713. end;
  3714. until Valid or (FPos <= 0);
  3715. if Valid then begin
  3716. SelectNode (NewSelection);
  3717. with Editor do begin
  3718. with Selection do begin
  3719. DoChanging;
  3720. RStart := P + FPos;
  3721. RLength := Length (S);
  3722. DoChange;
  3723. ScrollInView (2);
  3724. end;
  3725. end;
  3726. end;
  3727. end;
  3728. end;
  3729. end;
  3730. if AllFiles and (not Valid) then begin
  3731. if frDown in (Sender as TFindDialog).Options then begin
  3732. NewSelection := NewSelection.GetNext;
  3733. if not Assigned (NewSelection) then
  3734. NewSelection := TopNode;
  3735. end else begin
  3736. NewSelection := NewSelection.GetPrev;
  3737. if not Assigned (NewSelection) then begin
  3738. NewSelection := TopNode;
  3739. while NewSelection.Count > 0 do
  3740. NewSelection := NewSelection.Item [NewSelection.Count - 1];
  3741. end;
  3742. end;
  3743. FirstFile := False;
  3744. end;
  3745. until (not AllFiles) or Valid or (NewSelection = ProjectTree.Selected);
  3746. if not Valid then
  3747. Abort;
  3748. end;
  3749. procedure TMainForm.ReplaceDlgReplace(Sender: TObject);
  3750. var
  3751. Editor: TMemoComponent;
  3752. begin
  3753. Editor := CurrentEditor;
  3754. if Assigned (Editor) then
  3755. with Sender as TReplaceDialog do
  3756. if (frReplace in Options) or (frReplaceAll in Options) then
  3757. repeat
  3758. if UpperCase (Editor.Selection.Text) = UpperCase (FindText) then
  3759. Editor.Selection.Text := ReplaceText;
  3760. Options := Options + [frFindNext];
  3761. FindString (Sender, False);
  3762. until not (frReplaceAll in Options);
  3763. end;
  3764. procedure TMainForm.FindText(Sender: TObject);
  3765. begin
  3766. try
  3767. if Assigned (CurrentEditor) then
  3768. if CurrentEditor.Selection.RLength > 0 then
  3769. FindDlg.FindText := CurrentEditor.Selection.Text;
  3770. FindDlg.Execute;
  3771. except end;
  3772. end;
  3773. procedure TMainForm.ReplaceText(Sender: TObject);
  3774. begin
  3775. try
  3776. if Assigned (CurrentEditor) then
  3777. if CurrentEditor.Selection.RLength > 0 then begin
  3778. ReplaceDlg.FindText := CurrentEditor.Selection.Text;
  3779. ReplaceDlg.ReplaceText := ReplaceDlg.FindText;
  3780. end;
  3781. ReplaceDlg.Execute;
  3782. except end;
  3783. end;
  3784. procedure TMainForm.FindOpenFile(Sender: TObject);
  3785. var
  3786. I: Integer;
  3787. S: string;
  3788. QuotesInLine: Boolean;
  3789. SelectedNode: TTreeNode;
  3790. SourceFile: TSourceFile;
  3791. Editor: TMemoComponent;
  3792. begin
  3793. Editor := CurrentEditor;
  3794. if Assigned (Editor) then begin
  3795. QuotesInLine := Pos ('"', Editor.Lines [Editor.Selection.StartRowCol.Row - 1]) > 0;
  3796. S := '';
  3797. for I := Editor.Selection.RStart - 1 downto 1 do begin
  3798. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  3799. Break;
  3800. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  3801. S := Editor.Text [I] + S
  3802. else
  3803. Break;
  3804. end;
  3805. for I := Editor.Selection.RStart to Length (Editor.Text) do begin
  3806. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  3807. Break;
  3808. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  3809. S := S + Editor.Text [I]
  3810. else
  3811. Break;
  3812. end;
  3813. S := Trim (S);
  3814. if Length (S) > 0 then begin
  3815. SourceFile := SourceFiles.FindFileNameOnly (S);
  3816. if Assigned (SourceFile) then
  3817. SourceFile.Edit
  3818. else begin
  3819. SelectedNode := ProjectTree.Selected;
  3820. if Assigned (SelectedNode) and (TObject (SelectedNode.Data) is TSourceFile) then
  3821. SourceFile := TSourceFile (SelectedNode.Data);
  3822. if FileExists (ExpandFileName (S)) then
  3823. AddSourceFile (ExpandFileName (S), True)
  3824. else if Assigned (SourceFile) and (SourceFile is TGNUAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + GASIncludeLocation + S) then
  3825. AddSourceFile (WithBackslash (TIGCCFolder) + GASIncludeLocation + S, True)
  3826. else if Assigned (SourceFile) and (SourceFile is TAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S) then
  3827. AddSourceFile (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S, True)
  3828. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + S) then
  3829. AddSourceFile (WithBackslash (TIGCCFolder) + CIncludeLocation + S, True)
  3830. else
  3831. ShowDefaultMessageBox ('File ''' + S + ''' not found.', 'Search Failed', mtProgramError);
  3832. end;
  3833. end;
  3834. end;
  3835. end;
  3836. procedure TMainForm.FindDlgFind(Sender: TObject);
  3837. begin
  3838. try
  3839. FindString (Sender, True);
  3840. except
  3841. ShowDefaultMessageBox ('Text ''' + (Sender as TFindDialog).FindText + ''' not found.', 'Search Failed', mtProgramError);
  3842. end;
  3843. end;
  3844. procedure TMainForm.ActionsExecute(Action: TBasicAction;
  3845. var Handled: Boolean);
  3846. begin
  3847. Application.ProcessMessages;
  3848. Handled := False;
  3849. end;
  3850. procedure TMainForm.ProjectTreeEnter(Sender: TObject);
  3851. begin
  3852. ActionEditDelete.Enabled := Assigned (ProjectTree.Selected) and Assigned (ProjectTree.Selected.Data);
  3853. end;
  3854. procedure TMainForm.ProjectTreeExit(Sender: TObject);
  3855. begin
  3856. ActionEditDelete.Enabled := False;
  3857. end;
  3858. procedure TMainForm.ProjectTreeChanging(Sender: TObject; Node: TTreeNode;
  3859. var AllowChange: Boolean);
  3860. begin
  3861. if not NoHideEditor then begin
  3862. if Assigned (EditorToHide) then
  3863. EditorToHide.Hide;
  3864. if (not Closing) and Assigned (PreviousNode) and Assigned (PreviousNode.Data) and (TObject (PreviousNode.Data) is TSourceFile) then
  3865. EditorToHide := TSourceFile(PreviousNode.Data).Editor
  3866. else
  3867. EditorToHide := NoEditor;
  3868. end;
  3869. end;
  3870. procedure TMainForm.EditorChange(Sender: TObject);
  3871. begin
  3872. if ActiveControl = Sender then
  3873. UpdateEditButtons;
  3874. UpdateStatusBar;
  3875. end;
  3876. procedure TMainForm.FilePrint(Sender: TObject);
  3877. var
  3878. Node: TTreeNode;
  3879. Cp: Integer;
  3880. begin
  3881. Node := ProjectTree.Selected;
  3882. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) and (Printer.Printers.Count > 0) then try
  3883. PrintDlg.PrintRange := prAllPages;
  3884. PrintDlg.MaxPage := TSourceFile(Node.Data).CountPages;
  3885. PrintDlg.ToPage := PrintDlg.MaxPage;
  3886. if Assigned (CurrentEditor) then begin
  3887. if CurrentEditor.Selection.RLength > 0 then
  3888. PrintDlg.Options := PrintDlg.Options + [poSelection]
  3889. else
  3890. PrintDlg.Options := PrintDlg.Options - [poSelection];
  3891. end;
  3892. if Assigned (Sender) then begin
  3893. if not PrintDlg.Execute then
  3894. Abort;
  3895. Cp := PrintDlg.Copies;
  3896. if Cp < 1 then
  3897. Cp := 1;
  3898. end else
  3899. Cp := 1;
  3900. TSourceFile(Node.Data).Print (Cp, PrintDlg.PrintRange, PrintDlg.FromPage, PrintDlg.ToPage);
  3901. except
  3902. Abort;
  3903. end;
  3904. end;
  3905. procedure TMainForm.FilePrintQuickly(Sender: TObject);
  3906. begin
  3907. FilePrint (nil);
  3908. end;
  3909. procedure TMainForm.TreeItemRename(Sender: TObject);
  3910. begin
  3911. if Assigned (ProjectTree.Selected) then
  3912. ProjectTree.Selected.EditText;
  3913. end;
  3914. procedure TMainForm.HelpContents(Sender: TObject);
  3915. begin
  3916. try
  3917. DocFile.DisplayContentsTab;
  3918. except
  3919. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3920. end;
  3921. end;
  3922. procedure TMainForm.HelpIndex(Sender: TObject);
  3923. begin
  3924. try
  3925. DocFile.DisplayIndexTab;
  3926. except
  3927. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3928. end;
  3929. end;
  3930. procedure TMainForm.HelpSearch(Sender: TObject);
  3931. begin
  3932. try
  3933. DocFile.DisplaySearchTab;
  3934. except
  3935. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3936. end;
  3937. end;
  3938. procedure TMainForm.SplitterMoved(Sender: TObject);
  3939. begin
  3940. StatusBar.Panels[1].Width := ProjectTree.Width;
  3941. Update;
  3942. end;
  3943. procedure TMainForm.UpdateStatusBar;
  3944. var
  3945. S: string;
  3946. I: Integer;
  3947. Total: Integer;
  3948. Cell: TTextCell;
  3949. Node,
  3950. ClassNode: TTreeNode;
  3951. begin
  3952. with StatusBar.Panels do begin
  3953. Total := 0;
  3954. Node := TopNode;
  3955. while Assigned (Node) do begin
  3956. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  3957. Inc (Total);
  3958. Node := Node.GetNext;
  3959. end;
  3960. S := IntToStr (Total) + ' File';
  3961. if Total <> 1 then
  3962. S := S + 's';
  3963. S := S + ' Total';
  3964. if Assigned (ProjectTree.Selected) then begin
  3965. ClassNode := GetSourceTypeFolder (ProjectTree.Selected);
  3966. if Assigned (ClassNode) then begin
  3967. Total := 0;
  3968. Node := ClassNode;
  3969. while Assigned (Node) and (Node <> ClassNode.GetNextSibling) do begin
  3970. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  3971. Inc (Total);
  3972. Node := Node.GetNext;
  3973. end;
  3974. S := S + ', ' + IntToStr (Total) + ' in Category';
  3975. end;
  3976. end;
  3977. if Items[1].Text <> S then
  3978. Items[1].Text := S;
  3979. if Assigned (CurrentEditor) then begin
  3980. with CurrentEditor do begin
  3981. if Enabled then begin
  3982. if Selection.RLength > 0 then begin
  3983. I := Selection.RLength + Selection.StartRowCol.Row - Selection.EndRowCol.Row;
  3984. if Selection.EndRowCol.Col > LineLength [Selection.EndRowCol.Row] then
  3985. Dec (I);
  3986. S := IntToStr (I);
  3987. if Items[3].Text <> S then
  3988. Items[3].Text := S;
  3989. if Items[4].Text <> '' then
  3990. Items[4].Text := '';
  3991. if Items[3].Width <> 60 then
  3992. Items[3].Width := 60;
  3993. if Items[4].Width <> 0 then
  3994. Items[4].Width := 0;
  3995. end else begin
  3996. Cell := Selection.StartRowCol;
  3997. S := IntToStr (Cell.Row);
  3998. if Items[3].Text <> S then
  3999. Items[3].Text := S;
  4000. S := IntToStr (Cell.Col);
  4001. if Items[4].Text <> S then
  4002. Items[4].Text := S;
  4003. if Items[3].Width <> 30 then
  4004. Items[3].Width := 30;
  4005. if Items[4].Width <> 30 then
  4006. Items[4].Width := 30;
  4007. end;
  4008. I := TextLength - LineCount + 1;
  4009. S := IntToStr (I) + ' Character';
  4010. if I <> 1 then
  4011. S := S + 's';
  4012. if Items[11].Text <> S then
  4013. Items[11].Text := S;
  4014. if Items[10].Width <> 1 then
  4015. Items[10].Width := 1;
  4016. if Items[11].Width <> 93 then
  4017. Items[11].Width := 93;
  4018. if Items[12].Width <> 1 then
  4019. Items[12].Width := 1;
  4020. end;
  4021. end;
  4022. end else begin
  4023. if Items[3].Text <> '' then
  4024. Items[3].Text := '';
  4025. if Items[4].Text <> '' then
  4026. Items[4].Text := '';
  4027. if Items[11].Text <> '' then
  4028. Items[11].Text := '';
  4029. if Items[3].Width <> 0 then
  4030. Items[3].Width := 0;
  4031. if Items[4].Width <> 0 then
  4032. Items[4].Width := 0;
  4033. if Items[10].Width <> 0 then
  4034. Items[10].Width := 0;
  4035. if Items[11].Width <> 0 then
  4036. Items[11].Width := 0;
  4037. if Items[12].Width <> 0 then
  4038. Items[12].Width := 0;
  4039. end;
  4040. Node := ProjectTree.Selected;
  4041. S := '';
  4042. if Assigned (Node) then begin
  4043. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  4044. with TSourceFile (Node.Data) do
  4045. if (ProjectFile = '') and (ExtractFilePath (FileName) = 'C:\') then
  4046. S := LogicalFileName
  4047. else
  4048. S := FileName;
  4049. end else
  4050. if Node = TopNode then
  4051. S := ProjectFile;
  4052. end;
  4053. if Items[13].Text <> S then
  4054. Items[13].Text := S;
  4055. end;
  4056. Update;
  4057. end;
  4058. procedure TMainForm.ProjectTreeMouseDown(Sender: TObject;
  4059. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  4060. begin
  4061. if Button = mbRight then
  4062. SelectNode (ProjectTree.GetNodeAt (X, Y));
  4063. end;
  4064. procedure TMainForm.SetModified(const Value: Boolean);
  4065. begin
  4066. FModified := Value;
  4067. UpdateStatusBar;
  4068. if Value then
  4069. Invalidated := True;
  4070. end;
  4071. procedure TMainForm.ToolBarManagerBandMove(Sender: TObject;
  4072. Control: TControl; var ARect: TRect);
  4073. begin
  4074. Update;
  4075. end;
  4076. procedure TMainForm.ProjectTreeDragOver(Sender, Source: TObject; X,
  4077. Y: Integer; State: TDragState; var Accept: Boolean);
  4078. var
  4079. S,
  4080. D: TTreeNode;
  4081. SameType,
  4082. FolderDest: Boolean;
  4083. begin
  4084. Accept := False;
  4085. with ProjectTree do begin
  4086. S := Selected;
  4087. if Assigned (S) and Assigned (S.Data) then begin
  4088. D := GetNodeAt (X, Y);
  4089. if Assigned (D) and (D <> TopNode) and (D <> S) and (D <> S.Parent) then begin
  4090. SameType := (GetSourceTypeFolder (S) = GetSourceTypeFolder (D));
  4091. FolderDest := (not Assigned (D.Data)) or (TObject (D.Data) is TFolder);
  4092. if TObject (S.Data) is TSourceFile then
  4093. Accept := SameType or FolderDest
  4094. else
  4095. Accept := SameType and FolderDest;
  4096. end;
  4097. end;
  4098. end;
  4099. end;
  4100. procedure TMainForm.ProjectTreeDragDrop(Sender, Source: TObject; X,
  4101. Y: Integer);
  4102. var
  4103. S,
  4104. D: TTreeNode;
  4105. FN: string;
  4106. F: TSourceFile;
  4107. Folder: TFolder;
  4108. begin
  4109. with ProjectTree do begin
  4110. S := Selected;
  4111. if Assigned (S) and Assigned (S.Data) then begin
  4112. D := GetNodeAt (X, Y);
  4113. if Assigned (D) and (D <> TopNode) then begin
  4114. // Handle moving within one type.
  4115. if GetSourceTypeFolder (S) = GetSourceTypeFolder (D) then begin
  4116. // Handle moving to a different folder.
  4117. if (not Assigned (D.Data)) or (TObject (D.Data) is TFolder) then begin
  4118. S.MoveTo (D, naAddChild);
  4119. if TObject (S.Data) is TSourceFile then
  4120. with TSourceFile (S.Data) do begin
  4121. Folder := D.Data;
  4122. Invalidate;
  4123. end;
  4124. // Handle moving within one folder.
  4125. end else begin
  4126. if (S <> D) and (S.Parent = D.Parent) then begin
  4127. if D.Index > S.Index then begin
  4128. if D.GetNextSibling <> nil then
  4129. S.MoveTo (D.GetNextSibling, naInsert)
  4130. else
  4131. S.MoveTo (D, naAdd);
  4132. end else
  4133. S.MoveTo (D, naInsert);
  4134. end;
  4135. end;
  4136. Modify;
  4137. // Handle moving to a different type.
  4138. end else begin
  4139. if S.Parent <> D then begin
  4140. if TObject (S.Data) is TSourceFile then begin
  4141. with TSourceFile (S.Data) do begin
  4142. if FileExists (FileName) then
  4143. WarnIfModified
  4144. else
  4145. Save;
  4146. FN := FileName;
  4147. end;
  4148. S.Delete;
  4149. Folder := nil;
  4150. if Assigned (D.Data) and (TObject (D.Data) is TFolder) then
  4151. Folder := D.Data;
  4152. D := GetSourceTypeFolder (D);
  4153. if Assigned (D) then begin
  4154. F := AddSourceFile (FN, False, TSourceFile.GetAppropriateClassFromTreeIndex (D.Index), Folder);
  4155. if Assigned (F) and Assigned (F.TreeItem) then
  4156. SelectNode (F.TreeItem);
  4157. end;
  4158. RecompileFiles;
  4159. Modify;
  4160. end;
  4161. end;
  4162. end;
  4163. end;
  4164. if Assigned (CurrentEditor) then
  4165. CurrentEditor.Refresh;
  4166. SortFiles;
  4167. end;
  4168. end;
  4169. end;
  4170. procedure TMainForm.ErrorListClick(Sender: TObject);
  4171. begin
  4172. if Enabled and Assigned (ErrorList.Selected) and (ErrorList.SelCount = 1) then
  4173. TFoundError(ErrorList.Selected.Data).GoToPosition;
  4174. end;
  4175. function TMainForm.GetCurrentEditor: TMemoComponent;
  4176. var
  4177. Node: TTreeNode;
  4178. begin
  4179. Node := ProjectTree.Selected;
  4180. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TTextSourceFile) then
  4181. Result := TTextSourceFile(Node.Data).TextEditor
  4182. else
  4183. Result := nil;
  4184. end;
  4185. procedure TMainForm.DeleteError(Sender: TObject);
  4186. var
  4187. I: Integer;
  4188. begin
  4189. if DeleteErrors then begin
  4190. with ErrorList.Items do
  4191. for I := Count - 1 downto 0 do
  4192. if Assigned (Item[I].Data) then
  4193. with TFoundError (Item[I].Data) do
  4194. if Range = Sender then
  4195. Item[I].Delete;
  4196. UpdateErrorWindow;
  4197. end;
  4198. end;
  4199. procedure TMainForm.UpdateFuncs;
  4200. var
  4201. Node: TTreeNode;
  4202. begin
  4203. Node := ProjectTree.Selected;
  4204. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceTextSourceFile) then
  4205. with TSourceTextSourceFile (Node.Data) do
  4206. Funcs := GetFunctions
  4207. else
  4208. SetLength (Funcs, 0);
  4209. end;
  4210. procedure TMainForm.FunctionPopupPopup(Sender: TObject);
  4211. var
  4212. I,
  4213. P: Integer;
  4214. M: TMenuItem;
  4215. begin
  4216. with (Sender as TPopupMenu).Items do begin
  4217. for I := Count - 1 downto 0 do
  4218. Remove (Items [I]);
  4219. UpdateFuncs;
  4220. for I := Low (Funcs) to High (Funcs) do begin
  4221. M := TMenuItem.Create (Self);
  4222. with M do begin
  4223. Tag := I;
  4224. Caption := Funcs[I].Name;
  4225. OnClick := FindFunctionFromPopup;
  4226. end;
  4227. P := Pos ('main', Funcs[I].Name);
  4228. if (P <> 0) and (P = Length (Funcs[I].Name) - Length ('main') + 1) then
  4229. Insert (0, M)
  4230. else
  4231. Add (M);
  4232. end;
  4233. if Count <= 0 then
  4234. Add (NoFunctionsItem);
  4235. end;
  4236. end;
  4237. procedure TMainForm.FindFunctions(Sender: TObject);
  4238. var
  4239. I: Integer;
  4240. Editor: TMemoComponent;
  4241. begin
  4242. UpdateFuncs;
  4243. with TFunctionsForm.Create (Self) do try
  4244. Funcs := @Self.Funcs;
  4245. with FuncList.Items do begin
  4246. BeginUpdate;
  4247. Clear;
  4248. for I := Low (Self.Funcs) to High (Self.Funcs) do
  4249. AddObject (Self.Funcs[I].Name, TObject (I));
  4250. EndUpdate;
  4251. end;
  4252. FuncListClick (FuncList);
  4253. case ShowModal of
  4254. mrYes: begin
  4255. Editor := CurrentEditor;
  4256. if Assigned (Editor) then begin
  4257. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].PrototypeLine, 1)));
  4258. Editor.Selection.ScrollInView (5);
  4259. end;
  4260. end;
  4261. mrNo: begin
  4262. Editor := CurrentEditor;
  4263. if Assigned (Editor) then begin
  4264. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].ImplementationLine, 1)));
  4265. Editor.Selection.ScrollInView (5);
  4266. end;
  4267. end;
  4268. end;
  4269. with FuncList.Items do begin
  4270. BeginUpdate;
  4271. for I := Count - 1 downto 0 do begin
  4272. Objects [I] := nil;
  4273. Delete (I);
  4274. end;
  4275. EndUpdate;
  4276. end;
  4277. finally
  4278. Free;
  4279. end;
  4280. end;
  4281. procedure TMainForm.FindFunctionFromPopup(Sender: TObject);
  4282. var
  4283. L: Integer;
  4284. Editor: TMemoComponent;
  4285. begin
  4286. if Sender is TMenuItem then
  4287. with Sender as TMenuItem do begin
  4288. if Funcs[Tag].ImplementationLine > 0 then
  4289. L := Funcs[Tag].ImplementationLine
  4290. else
  4291. L := Funcs[Tag].PrototypeLine;
  4292. if L > 0 then begin
  4293. Editor := CurrentEditor;
  4294. if Assigned (Editor) then begin
  4295. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (L, 1)));
  4296. Editor.Selection.ScrollInView (5);
  4297. if Editor.Visible and Editor.Enabled then
  4298. ActiveControl := Editor;
  4299. end;
  4300. end;
  4301. end;
  4302. end;
  4303. procedure TMainForm.IncreaseIndent(Sender: TObject);
  4304. var
  4305. Editor: TMemoComponent;
  4306. begin
  4307. Editor := CurrentEditor;
  4308. if Assigned (Editor) then
  4309. Editor.ChangeIndent (1);
  4310. end;
  4311. procedure TMainForm.DecreaseIndent(Sender: TObject);
  4312. var
  4313. Editor: TMemoComponent;
  4314. begin
  4315. Editor := CurrentEditor;
  4316. if Assigned (Editor) then
  4317. Editor.ChangeIndent (-1);
  4318. end;
  4319. procedure TMainForm.SortFiles;
  4320. var
  4321. CurFileIndex: Integer;
  4322. procedure DoSortFiles(Node: TTreeNode);
  4323. var
  4324. I: Integer;
  4325. begin
  4326. with Node do begin
  4327. if Assigned (Data) and (TObject (Data) is TSourceFile) then begin
  4328. with TSourceFile (Data) do
  4329. if Index > CurFileIndex then
  4330. Index := CurFileIndex;
  4331. Inc (CurFileIndex);
  4332. end;
  4333. for I := 0 to Count - 1 do
  4334. DoSortFiles (Item [I]);
  4335. end;
  4336. end;
  4337. var
  4338. I: Integer;
  4339. begin
  4340. CurFileIndex := 0;
  4341. { This is supposed to be: DoSortFiles (TopNode);
  4342. However, header files are dependent on the other
  4343. files and therefore have to be put after all the
  4344. others. }
  4345. with TopNode do begin
  4346. for I := 0 to Count - 1 do
  4347. if I <> THeaderSourceFile.GetClassTreeIndex then
  4348. DoSortFiles (Item [I]);
  4349. if Count > THeaderSourceFile.GetClassTreeIndex then
  4350. DoSortFiles (Item [THeaderSourceFile.GetClassTreeIndex]);
  4351. end;
  4352. end;
  4353. procedure TMainForm.AppCompSetMessage(const Msg: string);
  4354. begin
  4355. with StatusBar do
  4356. Panels.Items[6].Text := Msg + '...';
  4357. if not Compiling then begin
  4358. Compiling := True;
  4359. CompUpdate;
  4360. UpdateDebugSettings;
  4361. with StatusBar.Panels do begin
  4362. Items[5].Width := 5;
  4363. Items[6].Width := 180;
  4364. Items[7].Width := 100;
  4365. Items[8].Width := 100;
  4366. Items[9].Width := 1000000;
  4367. end;
  4368. end;
  4369. end;
  4370. procedure TMainForm.AppCompStartFile;
  4371. var
  4372. I: Integer;
  4373. begin
  4374. Application.Hint := '';
  4375. CompFinishAndStop := False;
  4376. CompStopNow := False;
  4377. CompFileStartTime := Now;
  4378. CompLastTime := 0;
  4379. if not Compiling then begin
  4380. CompStartTime := CompFileStartTime;
  4381. ToolBarNewButton.Enabled := False;
  4382. MenuFileNew.Enabled := False;
  4383. ActionFileOpen.Enabled := False;
  4384. ActionFileExit.Enabled := False;
  4385. ActionProjectAddFiles.Enabled := False;
  4386. ActionProjectCompile.Visible := False;
  4387. ActionProjectMake.Visible := False;
  4388. ActionProjectBuild.Visible := False;
  4389. ActionProjectStopCompilation.Enabled := True;
  4390. ActionProjectForceQuitCompiler.Enabled := True;
  4391. ActionProjectStopCompilation.Visible := True;
  4392. ActionProjectForceQuitCompiler.Visible := True;
  4393. with RecentFiles do
  4394. for I := 0 to Count - 1 do
  4395. with TRecentFileMenuItem (Objects [I]) do begin
  4396. FileMenuItem.Enabled := False;
  4397. PopupMenuItem.Enabled := False;
  4398. end;
  4399. end;
  4400. end;
  4401. procedure TMainForm.AppCompStop;
  4402. var
  4403. I: Integer;
  4404. begin
  4405. if Compiling then begin
  4406. Compiling := False;
  4407. ActionProjectStopCompilation.Visible := False;
  4408. ActionProjectForceQuitCompiler.Visible := False;
  4409. ToolBarNewButton.Enabled := True;
  4410. MenuFileNew.Enabled := True;
  4411. ActionFileOpen.Enabled := True;
  4412. ActionFileExit.Enabled := True;
  4413. ActionProjectAddFiles.Enabled := True;
  4414. ActionProjectCompile.Visible := True;
  4415. ActionProjectMake.Visible := True;
  4416. ActionProjectBuild.Visible := True;
  4417. with RecentFiles do
  4418. for I := 0 to Count - 1 do
  4419. with TRecentFileMenuItem (Objects [I]) do begin
  4420. FileMenuItem.Enabled := True;
  4421. PopupMenuItem.Enabled := True;
  4422. end;
  4423. UpdateDebugSettings;
  4424. with StatusBar.Panels do begin
  4425. Items[5].Width := 0;
  4426. Items[6].Width := 0;
  4427. Items[7].Width := 0;
  4428. Items[8].Width := 0;
  4429. Items[9].Width := 0;
  4430. end;
  4431. end;
  4432. end;
  4433. procedure TMainForm.AppCompUpdate;
  4434. const
  4435. SecondsPerDay = 24 * 60 * 60;
  4436. function CustomTimeToStr(ConvTime: TDateTime): string;
  4437. var
  4438. Seconds: Integer;
  4439. MinStr,
  4440. SecStr: string;
  4441. begin
  4442. Seconds := Trunc (ConvTime * SecondsPerDay);
  4443. MinStr := IntToStr (Seconds div 60);
  4444. SecStr := IntToStr (Seconds mod 60);
  4445. while Length (SecStr) < 2 do
  4446. SecStr := '0' + SecStr;
  4447. Result := MinStr + ':' + SecStr;
  4448. end;
  4449. var
  4450. CurTime: TDateTime;
  4451. begin
  4452. CurTime := Now;
  4453. if Trunc (CompLastTime * SecondsPerDay) <> Trunc (CurTime * SecondsPerDay) then begin
  4454. CompLastTime := CurTime;
  4455. with StatusBar, Panels do begin
  4456. Items[7].Text := 'File Time: ' + CustomTimeToStr (CurTime - CompFileStartTime);
  4457. Items[8].Text := 'Total Time: ' + CustomTimeToStr (CurTime - CompStartTime);
  4458. Update;
  4459. end;
  4460. end;
  4461. end;
  4462. procedure TMainForm.DisplayFolderMessage;
  4463. var
  4464. S: string;
  4465. begin
  4466. if OperationSuccessful and (not OperationCancelled) and OpenFolderMessage then begin
  4467. if ProjectTarget = ptArchive then
  4468. S := 'The project has been compiled successfully.'#13#10#13#10'Archive Size: ' + IntToStr (ProgSize) + ' Bytes'#13#10#13#10'Do you want to open the project folder?'
  4469. else
  4470. with OptimizeInfo do begin
  4471. S := 'The project has been compiled successfully.'#13#10#13#10'Program Variable Size: ' + IntToStr (ProgramSize) + ' Bytes'#13#10;
  4472. if DataSize > 0 then
  4473. S := S + 'Data Variable Size: ' + IntToStr (DataSize) + ' Bytes'#13#10;
  4474. if BSSSize > 0 then
  4475. S := S + 'BSS Size: ' + IntToStr (BSSSize) + ' Bytes'#13#10;
  4476. S := S + 'Absolute Relocs: ' + IntToStr (RelocCount) + #13#10'Natively Emitted Relocs: ' + IntToStr (NativeRelocCount) + #13#10;
  4477. if OptimizeBranchesResult > 0 then begin
  4478. if OptimizeBranches then
  4479. S := S + 'Relocs Saved'
  4480. else
  4481. S := S + 'Relocs Savable';
  4482. S := S + ' by Branch Optimization: ' + IntToStr (OptimizeBranchesResult) + #13#10;
  4483. end;
  4484. if OptimizeMovesResult > 0 then begin
  4485. if OptimizeMoves then
  4486. S := S + 'Relocs Saved'
  4487. else
  4488. S := S + 'Relocs Savable';
  4489. S := S + ' by Move Optimization: ' + IntToStr (OptimizeMovesResult) + #13#10;
  4490. end;
  4491. if OptimizeTestsResult > 0 then begin
  4492. if OptimizeTests then
  4493. S := S + 'Relocs Saved'
  4494. else
  4495. S := S + 'Relocs Savable';
  4496. S := S + ' by Test Optimization: ' + IntToStr (OptimizeTestsResult) + #13#10;
  4497. end;
  4498. if OptimizeCalcsResult > 0 then begin
  4499. if OptimizeCalcs then
  4500. S := S + 'Relocs Saved'
  4501. else
  4502. S := S + 'Relocs Savable';
  4503. S := S + ' by Calculation Optimization: ' + IntToStr (OptimizeCalcsResult) + #13#10;
  4504. end;
  4505. if UseFLineJumpsResult > 0 then begin
  4506. if UseFLineJumps or Use4ByteFLineJumps then
  4507. S := S + 'Relocs Saved'
  4508. else
  4509. S := S + 'Relocs Savable';
  4510. S := S + ' by F-Line Jumps: ' + IntToStr (UseFLineJumpsResult) + #13#10;
  4511. end;
  4512. if CutRangesResult > 0 then begin
  4513. if CutRanges then
  4514. S := S + 'Space Saved'
  4515. else
  4516. S := S + 'Space Savable';
  4517. S := S + ' by Range-Cutting: ' + IntToStr (CutRangesResult) + ' Bytes'#13#10;
  4518. end;
  4519. if NearAssemblyResult > 0 then
  4520. S := S + 'Space Savable by Using GNU Assembler ''-l'' Switch: ' + IntToStr (NearAssemblyResult) + ' Bytes'#13#10;
  4521. S := S + #13#10'Do you want to open the project folder?';
  4522. end;
  4523. if ShowDefaultMessageBox (S, 'Compilation Successful', mtQuestion) = idYes then
  4524. ShellExecute (0, nil, PChar (ExtractFilePath (ProjectFile)), nil, nil, sw_ShowNormal);
  4525. end;
  4526. end;
  4527. procedure TMainForm.ProjectStopCompilation(Sender: TObject);
  4528. begin
  4529. CompFinishAndStop := True;
  4530. ActionProjectStopCompilation.Enabled := False;
  4531. end;
  4532. procedure TMainForm.ProjectForceQuitCompiler(Sender: TObject);
  4533. begin
  4534. CompStopNow := True;
  4535. end;
  4536. procedure TMainForm.WMDropFiles(var Msg: TMessage);
  4537. var
  4538. DropHandle: THandle;
  4539. I,
  4540. FileCount: Integer;
  4541. CurFile: array [0..512] of Char;
  4542. begin
  4543. DropHandle := Msg.WParam;
  4544. FileCount := DragQueryFile (DropHandle, High (Cardinal), nil, 0);
  4545. for I := 0 to FileCount - 1 do begin
  4546. DragQueryFile (DropHandle, I, CurFile, SizeOf (CurFile) - 1);
  4547. if LowerCase (ExtractFileExt (AnsiString (CurFile))) = LowerCase (ProjectFileExt) then
  4548. FileOpen (AnsiString (CurFile))
  4549. else
  4550. AddSourceFile (AnsiString (CurFile), True);
  4551. end;
  4552. DragFinish (DropHandle);
  4553. end;
  4554. procedure TMainForm.HelpNews(Sender: TObject);
  4555. begin
  4556. with TNewsForm.Create (Self) do try
  4557. Execute;
  4558. finally
  4559. Free;
  4560. end;
  4561. end;
  4562. function TMainForm.GetVTIWindow: HWnd;
  4563. begin
  4564. CurVTIType := cvVTINone;
  4565. Result := FindWindow ('TEmuWnd', 'Virtual TI-89');
  4566. if Result = 0 then begin
  4567. Result := FindWindow ('TEmuWnd', 'Virtual TI-92+');
  4568. if Result = 0 then begin
  4569. Result := FindWindow ('TEmuWnd', 'Virtual TI-92');
  4570. if Result <> 0 then
  4571. CurVTIType := cvVTITI92;
  4572. end else
  4573. CurVTIType := cvVTITI92Plus;
  4574. end else
  4575. CurVTIType := cvVTITI89;
  4576. if Result = 0 then begin
  4577. if Length (VTIPath) > 0 then begin
  4578. with TVTIStartForm.Create (Self) do try
  4579. if ShowModal = mrOK then begin
  4580. Result := VTIWindow;
  4581. CurVTIType := VTIType;
  4582. end else
  4583. Abort;
  4584. finally
  4585. Free;
  4586. end;
  4587. end else begin
  4588. ShowDefaultMessageBox ('Virtual TI is not running.', 'Error', mtProgramError);
  4589. Abort;
  4590. end;
  4591. end;
  4592. end;
  4593. function TMainForm.GetTiEmuInterface: ITiEmuOLE;
  4594. var
  4595. Unknown: IUnknown;
  4596. OLEResult: HResult;
  4597. begin
  4598. OLEResult := GetActiveObject(CLASS_TiEmuOLE, nil, Unknown);
  4599. if OLEResult = S_OK then begin
  4600. OleCheck(Unknown.QueryInterface(ITiEmuOLE, Result));
  4601. end else begin
  4602. { If no TiEmu path is set, try looking it up from the registry. }
  4603. if Length (TIEmuPath) = 0 then begin
  4604. with TRegistry.Create do try
  4605. RootKey := HKey_Classes_Root;
  4606. if OpenKeyReadOnly ('\CLSID\{B2A17B13-9D6F-4DD4-A2A9-6FE06ADC1D33}\LocalServer32') then try
  4607. if ValueExists ('') then
  4608. TIEmuPath := ReadString ('');
  4609. except end;
  4610. finally
  4611. Free;
  4612. end;
  4613. end;
  4614. if Length (TIEmuPath) > 0 then begin
  4615. with TTIEmuStartForm.Create (Self) do try
  4616. if ShowModal = mrOK then begin
  4617. Result := TiEmuInterface;
  4618. end else
  4619. Abort;
  4620. finally
  4621. Free;
  4622. end;
  4623. end else begin
  4624. ShowDefaultMessageBox ('TiEmu is not running.', 'Error', mtProgramError);
  4625. Abort;
  4626. end;
  4627. end;
  4628. end;
  4629. procedure TMainForm.SendFiles(FNList: array of string);
  4630. var
  4631. Win: HWnd;
  4632. procedure SendKey(Key: Byte);
  4633. begin
  4634. PostMessage (Win, WM_KEYDOWN, Key, 0);
  4635. PostMessage (Win, WM_KEYUP, Key, 0);
  4636. end;
  4637. var
  4638. EditWin,
  4639. ButtonWin: HWnd;
  4640. StartTime: Cardinal;
  4641. FileString: string;
  4642. Name: array [0..32] of Char;
  4643. I: Integer;
  4644. FirstI: Integer;
  4645. TiEmuInterface: ITiEmuOLE;
  4646. TiEmuCalcType: TTIEmuCalcType;
  4647. Ready: Boolean;
  4648. Connection: TLinkConnection;
  4649. Size: Word;
  4650. Total: Cardinal;
  4651. Progress: DWord;
  4652. ProgressForm: TSendProgressForm;
  4653. begin
  4654. OperationSuccessful := False;
  4655. OperationCancelled := False;
  4656. if Length (FNList) > 0 then begin
  4657. if TransferTarget = ttTIEmu then begin
  4658. TiEmuInterface := GetTiEmuInterface;
  4659. Enabled := False;
  4660. try
  4661. { Wait for TiEmu to get ready. }
  4662. repeat
  4663. Sleep(100);
  4664. Application.ProcessMessages;
  4665. try
  4666. Ready := TiEmuInterface.ready_for_transfers;
  4667. except
  4668. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4669. Abort;
  4670. end;
  4671. until Ready;
  4672. { Now obtain the model from TiEmu. }
  4673. try
  4674. TiEmuCalcType := TTIEmuCalcType(TiEmuInterface.emulated_calc_type);
  4675. if TiEmuCalcType = cvTIEmuNone then Abort;
  4676. except
  4677. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4678. Abort;
  4679. end;
  4680. { Select the correct files for the model. }
  4681. if (TiEmuCalcType <> cvTIEmuTI92) and (ProjectTarget = ptFargo) then begin
  4682. ShowDefaultMessageBox ('Can''t send Fargo program to a TI-89/89Ti/92+/V200.', 'Error', mtProgramError);
  4683. Abort;
  4684. end;
  4685. if (TiEmuCalcType = cvTIEmuTI92) and (ProjectTarget <> ptFargo) then begin
  4686. ShowDefaultMessageBox ('Can''t send AMS program to a TI-92.', 'Error', mtProgramError);
  4687. Abort;
  4688. end;
  4689. for I := Low (FNList) to High (FNList) do begin
  4690. case TiEmuCalcType of
  4691. cvTIEmuTI92Plus:
  4692. FNList [I] := StringReplace (FNList [I], '.89', '.9x', []);
  4693. cvTIEmuV200:
  4694. FNList [I] := StringReplace (FNList [I], '.89', '.v2', []);
  4695. cvTIEmuTI92:
  4696. FNList [I] := StringReplace (FNList [I], '.89', '.92', []);
  4697. end;
  4698. if not FileExists (FNList [I]) then begin
  4699. ShowDefaultMessageBox ('The file "' + FNList [I] + '" could not be found.', 'Error', mtProgramError);
  4700. Abort;
  4701. end;
  4702. end;
  4703. { Now send the files. }
  4704. FirstI := Low (FNList);
  4705. if DebugInfo and not Pack and FileExists (ChangeFileExt (ProjectFile, '.dbg')) then begin
  4706. try
  4707. if not TiEmuInterface.debug_file(FNList [FirstI]) then Abort;
  4708. except
  4709. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4710. Abort;
  4711. end;
  4712. Inc (FirstI);
  4713. end;
  4714. for I := FirstI to High (FNList) do begin
  4715. try
  4716. if not TiEmuInterface.send_file(FNList [I]) then Abort;
  4717. except
  4718. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4719. Abort;
  4720. end;
  4721. end;
  4722. finally
  4723. Enabled := True;
  4724. end;
  4725. end else if TransferTarget = ttVTI then begin
  4726. Win := GetVTIWindow;
  4727. GetWindowThreadProcessID (Win, @ProcID);
  4728. SendKey (VK_SCROLL);
  4729. SendKey (VK_ESCAPE);
  4730. if CurVTIType = cvVTITI89 then
  4731. SendKey (VK_HOME);
  4732. SendKey (VK_F10);
  4733. StartTime := GetTickCount;
  4734. SendWin := 0;
  4735. repeat
  4736. EnumWindows (@EnumWindowsFunc, 0);
  4737. until (SendWin <> 0) or (GetTickCount - StartTime >= 10000);
  4738. if SendWin = 0 then begin
  4739. ShowDefaultMessageBox ('Error displaying send dialog.', 'Error', mtProgramError);
  4740. Abort;
  4741. end else begin
  4742. SetForegroundWindow (SendWin);
  4743. repeat
  4744. EditWin := GetWindow (SendWin, GW_CHILD);
  4745. GetClassName (EditWin, Name, 32);
  4746. while (EditWin <> 0) and (UpperCase (AnsiString (Name)) <> 'EDIT') do begin
  4747. EditWin := GetWindow (EditWin, GW_HWNDNEXT);
  4748. if EditWin <> 0 then
  4749. GetClassName (EditWin, Name, 32);
  4750. end;
  4751. if EditWin <> 0 then begin
  4752. StartTime := GetTickCount;
  4753. while (SendMessage (EditWin, WM_GETTEXTLENGTH, 0, 0) <= 0) and (GetTickCount - StartTime < 5000) do;
  4754. FileString := '';
  4755. for I := Low (FNList) to High (FNList) do begin
  4756. if CurVTIType = cvVTITI92Plus then
  4757. FNList [I] := StringReplace (FNList [I], '.89', '.9x', []);
  4758. if not FileExists (FNList [I]) then begin
  4759. ShowDefaultMessageBox ('The file "' + FNList [I] + '" could not be found.', 'Error', mtProgramError);
  4760. Abort;
  4761. end;
  4762. Insert ('"' + FNList [I] + '" ', FileString, Length (FileString) + 1);
  4763. end;
  4764. Delete (FileString, Length (FileString), 1);
  4765. SendMessage (EditWin, WM_SETTEXT, 0, Integer (PChar (FileString)));
  4766. end;
  4767. ButtonWin := GetWindow (SendWin, GW_CHILD);
  4768. GetClassName (ButtonWin, Name, 32);
  4769. while (ButtonWin <> 0) and ((UpperCase (AnsiString (Name)) <> 'BUTTON') or ((GetWindowLong (ButtonWin, GWL_STYLE) and BS_DEFPUSHBUTTON) = 0) or ((GetWindowLong (ButtonWin, GWL_STYLE) and BS_CHECKBOX) <> 0)) do begin
  4770. ButtonWin := GetWindow (ButtonWin, GW_HWNDNEXT);
  4771. if ButtonWin <> 0 then
  4772. GetClassName (ButtonWin, Name, 32);
  4773. end;
  4774. until SendMessage (EditWin, WM_GETTEXTLENGTH, 0, 0) >= Length (FNList [Low (FNList)]);
  4775. if ButtonWin <> 0 then begin
  4776. SendMessage (ButtonWin, WM_LBUTTONDOWN, 0, 0);
  4777. SendMessage (ButtonWin, WM_LBUTTONUP, 0, 0);
  4778. end;
  4779. end;
  4780. ShowWindow (Win, SW_SHOWNORMAL);
  4781. SetForegroundWindow (Win);
  4782. end else if TransferTarget = ttCalc then begin
  4783. FillChar (Connection, SizeOf (Connection), 0);
  4784. Connection.Port := LinkPort;
  4785. Connection.CableType := LinkCable;
  4786. if CreateConnection (Connection) then try
  4787. if OpenConnection (Connection) and GetCalcType (Connection) then begin
  4788. Total := 0;
  4789. for I := Low (FNList) to High (FNList) do begin
  4790. case Connection.CalcType of
  4791. cdTI92Plus:
  4792. FNList [I] := StringReplace (FNList [I], '.89', '.9x', []);
  4793. cdV200:
  4794. FNList [I] := StringReplace (FNList [I], '.89', '.v2', []);
  4795. cdTI92:
  4796. FNList [I] := StringReplace (FNList [I], '.89', '.92', []);
  4797. end;
  4798. if not FileExists (FNList [I]) then begin
  4799. ShowDefaultMessageBox ('The file "' + FNList [I] + '" could not be found.', 'Error', mtProgramError);
  4800. Abort;
  4801. end;
  4802. if not CheckFileFormat (Connection, PChar (FNList [I]), nil, nil, @Size) then begin
  4803. ShowDefaultMessageBox ('Error sending file.', 'Error', mtProgramError);
  4804. Abort;
  4805. end;
  4806. Inc (Total, Size);
  4807. end;
  4808. Enabled := False;
  4809. try
  4810. ProgressForm := TSendProgressForm.Create (Self);
  4811. with ProgressForm do try
  4812. ProgressBar.Max := Total;
  4813. Show;
  4814. Update;
  4815. Progress := 0;
  4816. for I := Low (FNList) to High (FNList) do begin
  4817. FileNameLabel.Caption := ExtractFileName (FNList [I]);
  4818. if not SendFile (Connection, nil, nil, PChar (FNList [I]), @Progress, ProgressProg, ProgressForm) then begin
  4819. if Cancelled then
  4820. OperationCancelled := True
  4821. else
  4822. ShowDefaultMessageBox ('Error sending file. Please check whether your calculator is on the home screen.', 'Error', mtProgramError);
  4823. Abort;
  4824. end;
  4825. end;
  4826. finally
  4827. CloseNow := True;
  4828. Free;
  4829. end;
  4830. finally
  4831. Enabled := True;
  4832. end;
  4833. end else begin
  4834. ShowDefaultMessageBox ('Error linking to calculator.', 'Error', mtProgramError);
  4835. Abort;
  4836. end;
  4837. finally
  4838. CloseConnection (Connection);
  4839. end else begin
  4840. ShowDefaultMessageBox ('Error opening link port.', 'Error', mtProgramError);
  4841. Abort;
  4842. end;
  4843. end;
  4844. OperationSuccessful := True;
  4845. end;
  4846. end;
  4847. procedure TMainForm.ExecuteCommandLine(const Line: string);
  4848. var
  4849. Win: HWnd;
  4850. procedure SendKey(Key: Byte);
  4851. begin
  4852. SendMessage (Win, WM_KEYDOWN, Key, 0);
  4853. SendMessage (Win, WM_KEYUP, Key, 0);
  4854. Sleep (20);
  4855. end;
  4856. var
  4857. I: Integer;
  4858. TiEmuInterface: ITiEmuOLE;
  4859. Connection: TLinkConnection;
  4860. begin
  4861. if TransferTarget = ttTIEmu then begin
  4862. TiEmuInterface := GetTiEmuInterface;
  4863. try
  4864. if not TiEmuInterface.execute_command(Line) then Abort;
  4865. except
  4866. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4867. Abort;
  4868. end;
  4869. end else if TransferTarget = ttVTI then begin
  4870. Win := GetVTIWindow;
  4871. SendKey (VK_SCROLL);
  4872. SendKey (VK_ESCAPE);
  4873. SendKey (VK_ESCAPE);
  4874. if CurVTIType = cvVTITI89 then
  4875. SendKey (VK_HOME);
  4876. SendKey (VK_DELETE);
  4877. SendKey (VK_DELETE);
  4878. for I := 1 to Length (Line) do
  4879. if Line [I] in ['A'..'Z', 'a'..'z', '0'..'9'] then
  4880. SendKey (Byte (UpCase (Line [I])))
  4881. else if Line [I] = '(' then
  4882. SendKey ($DB)
  4883. else if Line [I] = ')' then
  4884. SendKey ($DD)
  4885. else if Line [I] = ',' then
  4886. SendKey ($BC)
  4887. else if Line [I] = '.' then
  4888. SendKey (VK_DECIMAL)
  4889. else if Line [I] = '+' then
  4890. SendKey (VK_ADD)
  4891. else if Line [I] = '-' then
  4892. SendKey (VK_SUBTRACT)
  4893. else if Line [I] = '*' then
  4894. SendKey (VK_MULTIPLY)
  4895. else if Line [I] = '/' then
  4896. SendKey (VK_DIVIDE)
  4897. else if Line [I] = '\' then begin
  4898. SendKey (VK_MENU);
  4899. SendKey (Byte ('2'));
  4900. end;
  4901. SendKey (VK_RETURN);
  4902. end else if TransferTarget = ttCalc then begin
  4903. FillChar (Connection, SizeOf (Connection), 0);
  4904. Connection.Port := LinkPort;
  4905. Connection.CableType := LinkCable;
  4906. if CreateConnection (Connection) then try
  4907. if OpenConnection (Connection) then
  4908. ExecuteHomeLine (Connection, Line)
  4909. else begin
  4910. ShowDefaultMessageBox ('Error linking to calculator.', 'Error', mtProgramError);
  4911. Abort;
  4912. end;
  4913. finally
  4914. CloseConnection (Connection);
  4915. end else begin
  4916. ShowDefaultMessageBox ('Error opening link port.', 'Error', mtProgramError);
  4917. Abort;
  4918. end;
  4919. end;
  4920. end;
  4921. procedure TMainForm.DebugRun(Sender: TObject);
  4922. var
  4923. Files: array of string;
  4924. begin
  4925. OperationSuccessful := True;
  4926. OperationCancelled := False;
  4927. if Invalidated then
  4928. MakeFileWrapped;
  4929. if OperationSuccessful and (not OperationCancelled) and (FileExists (ChangeFileExt (ProjectFile, '.89z')) or FileExists (ChangeFileExt (ProjectFile, '.9xz')) or FileExists (ChangeFileExt (ProjectFile, '.v2z')) or FileExists (ChangeFileExt (ProjectFile, '.92p'))) then begin
  4930. if Runnable then begin
  4931. SetLength (Files, 0);
  4932. case ProjectTarget of
  4933. ptRegular: begin
  4934. SetLength (Files, 1);
  4935. Files [High (Files)] := ChangeFileExt (ProjectFile, '.89z');
  4936. if Pack and (ssPack in SpecialSupport) then begin
  4937. SetLength (Files, Length (Files) + 1);
  4938. Files [High (Files)] := ChangeFileExt (ProjectFile, '.89y');
  4939. end;
  4940. if UseDataVar then begin
  4941. SetLength (Files, Length (Files) + 1);
  4942. Files [High (Files)] := ChangeFileExt (ProjectFile, '-data.89y');
  4943. end;
  4944. end;
  4945. ptFargo: begin
  4946. SetLength (Files, 1);
  4947. Files [High (Files)] := ChangeFileExt (ProjectFile, '.92p');
  4948. end;
  4949. end;
  4950. if Length (Files) > 0 then begin
  4951. SendFiles (Files);
  4952. if OperationSuccessful then
  4953. ExecuteCommandLine (TopNode.Text + '(' + CommandLine + ')');
  4954. end;
  4955. end else
  4956. DisplayFolderMessage;
  4957. end;
  4958. end;
  4959. procedure TMainForm.DebugPause(Sender: TObject);
  4960. var
  4961. Win: HWnd;
  4962. TiEmuInterface: ITiEmuOLE;
  4963. procedure SendKey(Key: Byte);
  4964. begin
  4965. PostMessage (Win, WM_KEYDOWN, Key, 0);
  4966. PostMessage (Win, WM_KEYUP, Key, 0);
  4967. end;
  4968. begin
  4969. if TransferTarget = ttTIEmu then begin
  4970. TiEmuInterface := GetTiEmuInterface;
  4971. try
  4972. TiEmuInterface.enter_debugger;
  4973. except
  4974. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4975. end
  4976. end else if TransferTarget = ttVTI then begin
  4977. Win := GetVTIWindow;
  4978. SendKey (VK_F11);
  4979. ShowWindow (Win, SW_SHOWNORMAL);
  4980. SetForegroundWindow (Win);
  4981. end;
  4982. end;
  4983. procedure TMainForm.DebugReset(Sender: TObject);
  4984. var
  4985. Win: HWnd;
  4986. TiEmuInterface: ITiEmuOLE;
  4987. procedure SendKey(Key: Byte);
  4988. begin
  4989. PostMessage (Win, WM_KEYDOWN, Key, 0);
  4990. PostMessage (Win, WM_KEYUP, Key, 0);
  4991. end;
  4992. begin
  4993. if TransferTarget = ttTIEmu then begin
  4994. TiEmuInterface := GetTiEmuInterface;
  4995. try
  4996. TiEmuInterface.reset_calc(False);
  4997. except
  4998. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4999. end
  5000. end else if TransferTarget = ttVTI then begin
  5001. Win := GetVTIWindow;
  5002. SendKey (VK_APPS);
  5003. SendKey (Byte ('T'));
  5004. ShowWindow (Win, SW_SHOWNORMAL);
  5005. SetForegroundWindow (Win);
  5006. end;
  5007. end;
  5008. function TMainForm.GetInvalidated: Boolean;
  5009. var
  5010. I: Integer;
  5011. begin
  5012. Result := FInvalidated;
  5013. if not Result then
  5014. with SourceFiles do
  5015. for I := 0 to Count - 1 do
  5016. with Items [I] as TSourceFile do
  5017. if (Compilable or (Items [I] is THeaderSourceFile)) and Invalidated then begin
  5018. Result := True;
  5019. Break;
  5020. end;
  5021. end;
  5022. procedure TMainForm.UpdateDebugSettings;
  5023. var
  5024. CanRun: Boolean;
  5025. begin
  5026. CanRun := Runnable;
  5027. ActionDebugRun.Enabled := not Compiling;
  5028. ActionDebugPause.Enabled := (not Compiling) and ((TransferTarget = ttVTI) or (TransferTarget = ttTIEmu));
  5029. ActionDebugReset.Enabled := (not Compiling) and ((TransferTarget = ttVTI) or (TransferTarget = ttTIEmu));
  5030. MainMenuDebug.Visible := CanRun;
  5031. if not CanRun then
  5032. ToolBarDebugLine.Parent := nil;
  5033. ToolBarRunButton.Visible := CanRun;
  5034. ToolBarPauseButton.Visible := CanRun;
  5035. ToolBarDebugLine.Visible := CanRun;
  5036. if CanRun then begin
  5037. ToolBarDebugLine.Parent := MainToolBar;
  5038. ToolBarDebugLine.Left := ToolBarPauseButton.Left + ToolBarPauseButton.Width;
  5039. end;
  5040. end;
  5041. procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
  5042. Shift: TShiftState);
  5043. var
  5044. NewSelection: TTreeNode;
  5045. begin
  5046. if (Key = vk_F8) and (Shift = []) then begin
  5047. ProjectMake (Sender);
  5048. end else if (Key = vk_F8) and (Shift = [ssAlt]) then begin
  5049. ProjectCompile (Sender);
  5050. end else if (Key = vk_F9) and (Shift = [ssShift, ssCtrl, ssAlt]) then begin
  5051. if TransferTarget = ttVTI then
  5052. TransferTarget := ttTIEmu
  5053. else if TransferTarget = ttTiEmu then
  5054. TransferTarget := ttCalc
  5055. else
  5056. TransferTarget := ttVTI;
  5057. SavePreferences;
  5058. UpdateDebugSettings;
  5059. end else if ((Key = vk_Tab) or (Key = Ord('G'))) and (Shift = [ssCtrl]) then begin
  5060. NewSelection := ProjectTree.Selected;
  5061. if Assigned (NewSelection) then begin
  5062. repeat
  5063. NewSelection := NewSelection.GetNext;
  5064. if not Assigned (NewSelection) then
  5065. NewSelection := TopNode;
  5066. until (NewSelection.IsVisible and Assigned (NewSelection.Data)) or (NewSelection = ProjectTree.Selected);
  5067. if Assigned (NewSelection.Data) then
  5068. SelectNode (NewSelection);
  5069. if Assigned (CurrentEditor) and CurrentEditor.Enabled then try
  5070. CurrentEditor.SetFocus;
  5071. except end;
  5072. end;
  5073. end;
  5074. end;
  5075. procedure TMainForm.SelectNode(Node: TTreeNode);
  5076. var
  5077. Allow: Boolean;
  5078. begin
  5079. if PreviousNode <> Node then begin
  5080. Allow := True;
  5081. ProjectTreeChanging (ProjectTree, Node, Allow);
  5082. if Allow then begin
  5083. NoHideEditor := True;
  5084. ProjectTree.Selected := Node;
  5085. NoHideEditor := False;
  5086. end;
  5087. end;
  5088. end;
  5089. procedure TMainForm.ChangeNotificationTick(Sender: TObject);
  5090. var
  5091. I: Integer;
  5092. begin
  5093. if not InChangeNotification then begin
  5094. InChangeNotification := True;
  5095. with SourceFiles do
  5096. for I := 0 to Count - 1 do
  5097. with TSourceFile (Items [I]) do
  5098. TestChange;
  5099. InChangeNotification := False;
  5100. end;
  5101. end;
  5102. procedure TMainForm.ResetProjectSettings;
  5103. begin
  5104. ProjectTarget := ptRegular;
  5105. UseDataVar := False;
  5106. DataVar := '';
  5107. DataVarCopy := True;
  5108. DataVarCopyIfArchived := True;
  5109. Pack := False;
  5110. PackVar := '';
  5111. GCCSwitches := '-Os -Wall -W -Wwrite-strings -ffunction-sections -fdata-sections';
  5112. AsSwitches := '';
  5113. AsmSwitches := '-g -t';
  5114. DebugInfo := False;
  5115. StdLib := True;
  5116. InitBSS := True;
  5117. OptimizeNOPs := True;
  5118. OptimizeReturns := True;
  5119. OptimizeBranches := True;
  5120. OptimizeMoves := True;
  5121. OptimizeTests := True;
  5122. OptimizeCalculations := True;
  5123. RemoveUnusedSections := True;
  5124. CutUnusedRanges := True;
  5125. ReorderSections := True;
  5126. MergeConstants := True;
  5127. OutputBin := False;
  5128. CommandLine := '';
  5129. PostBuildProcessFile := '';
  5130. if Assigned (PredefinedLibOptions) then
  5131. with PredefinedLibOptions do begin
  5132. CalcDests := [cdTI89, cdTI92Plus, cdV200];
  5133. OptimizeCalcConsts := False;
  5134. KernelFormat := kfNone;
  5135. UseMinAMS := True;
  5136. MinAMS := '1.00';
  5137. RelocFormat := rfAMS;
  5138. ROMCallFormat := rfDirect;
  5139. BSSRefFormat := rfKernel;
  5140. DataRefFormat := rfKernel;
  5141. UseFLineJumps := False;
  5142. UseInternalFLineEmulator := False;
  5143. UseReturnValue := False;
  5144. EnableErrorReturn := False;
  5145. SaveScreen := True;
  5146. end;
  5147. end;
  5148. procedure TMainForm.AddToRecent(const FileName: string);
  5149. var
  5150. I: Integer;
  5151. O: TRecentFileMenuItem;
  5152. begin
  5153. with RecentFiles do begin
  5154. for I := 0 to Count - 1 do
  5155. if (I >= MaxRecentFiles - 1) or (UpperCase (Strings [I]) = UpperCase (FileName)) then begin
  5156. if I = 0 then
  5157. Exit
  5158. else begin
  5159. Objects[I].Free;
  5160. Delete (I);
  5161. Break;
  5162. end;
  5163. end;
  5164. RecentFilesLine.Visible := True;
  5165. O := TRecentFileMenuItem.Create;
  5166. with O do begin
  5167. FileMenuItem := TMenuItem.Create (Self);
  5168. with FileMenuItem do begin
  5169. Caption := WithoutExt (ExtractFileName (FileName));
  5170. Hint := FileName;
  5171. OnClick := RecentFileClick;
  5172. end;
  5173. MainMenuFile.Insert (RecentFilesLine.MenuIndex + 1, FileMenuItem);
  5174. PopupMenuItem := TMenuItem.Create (Self);
  5175. with PopupMenuItem do begin
  5176. Caption := FileName;
  5177. Hint := FileName;
  5178. OnClick := RecentFileClick;
  5179. end;
  5180. RecentFilesPopup.Items.Insert (0, PopupMenuItem);
  5181. end;
  5182. InsertObject (0, FileName, O);
  5183. end;
  5184. UpdateRecent;
  5185. end;
  5186. procedure TMainForm.UpdateRecent;
  5187. begin
  5188. RecentFilesLine.Visible := RecentFiles.Count > 0;
  5189. NoFilesItem.Visible := RecentFiles.Count <= 0;
  5190. end;
  5191. procedure TMainForm.RecentFileClick(Sender: TObject);
  5192. var
  5193. I: Integer;
  5194. FileName: string;
  5195. begin
  5196. FileName := (Sender as TMenuItem).Hint;
  5197. if FileExists (FileName) then
  5198. FileOpen (FileName)
  5199. else begin
  5200. with RecentFiles do
  5201. for I := 0 to Count - 1 do
  5202. if UpperCase (Strings [I]) = UpperCase (FileName) then begin
  5203. Objects[I].Free;
  5204. Delete (I);
  5205. Break;
  5206. end;
  5207. UpdateRecent;
  5208. ShowDefaultMessageBox ('File ''' + WithoutExt (ExtractFileName (FileName)) + ''' not found.', 'Error', mtProgramError);
  5209. end;
  5210. end;
  5211. procedure TMainForm.ToolsConfigure(Sender: TObject);
  5212. var
  5213. I: Integer;
  5214. begin
  5215. with TToolsForm.Create (Self) do try
  5216. with Self.ToolsList do
  5217. for I := 0 to Count - 1 do
  5218. with ToolsList.Items.Add, TToolsListItem (Items [I]) do begin
  5219. Caption := Title;
  5220. SubItems.Add (CommandLine);
  5221. SubItems.Add (WorkingDir);
  5222. SubItems.Add (WindowStateToString (WindowState));
  5223. end;
  5224. if ShowModal = mrOK then begin
  5225. Self.ToolsList.Clear;
  5226. with ToolsList.Items do begin
  5227. ToolsLine.Visible := Count > 0;
  5228. for I := 0 to Count - 1 do
  5229. with Item [I] do
  5230. AddTool (Caption, SubItems [0], SubItems [1], StringToWindowState (SubItems [2]));
  5231. end;
  5232. SavePreferences;
  5233. end;
  5234. finally
  5235. Free;
  5236. end;
  5237. end;
  5238. procedure TMainForm.ToolClick(Sender: TObject);
  5239. var
  5240. WorkDir: PChar;
  5241. StartupInfo: TStartupInfo;
  5242. ProcessInfo: TProcessInformation;
  5243. begin
  5244. with TToolsListItem ((Sender as TMenuItem).Tag) do begin
  5245. FillChar (StartupInfo, SizeOf (StartupInfo), 0);
  5246. StartupInfo.cb := SizeOf (StartupInfo);
  5247. if Length (WorkingDir) > 0 then
  5248. WorkDir := PChar (WorkingDir)
  5249. else
  5250. WorkDir := nil;
  5251. StartupInfo.dwFlags := StartF_UseShowWindow;
  5252. case WindowState of
  5253. wsMaximized:
  5254. StartupInfo.wShowWindow := SW_SHOWMAXIMIZED;
  5255. wsMinimized:
  5256. StartupInfo.wShowWindow := SW_SHOWMINIMIZED;
  5257. else
  5258. StartupInfo.dwFlags := 0;
  5259. end;
  5260. if CreateProcess (nil, PChar (CommandLine), nil, nil, False, CREATE_NEW_PROCESS_GROUP or DETACHED_PROCESS, nil, WorkDir, StartupInfo, ProcessInfo) then begin
  5261. CloseHandle (ProcessInfo.hProcess);
  5262. CloseHandle (ProcessInfo.hThread);
  5263. end else
  5264. ShowDefaultMessageBox ('An error occurred while trying to start the application.', 'Error', mtProgramError);
  5265. end;
  5266. end;
  5267. procedure TMainForm.AddTool(const Title, CommandLine, WorkingDir: string; WindowState: TWindowState);
  5268. var
  5269. O: TToolsListItem;
  5270. begin
  5271. O := TToolsListItem (Self.ToolsList.Add);
  5272. O.Title := Title;
  5273. O.CommandLine := CommandLine;
  5274. O.WorkingDir := WorkingDir;
  5275. O.WindowState := WindowState;
  5276. O.MenuItem := TMenuItem.Create (Self);
  5277. with O.MenuItem do begin
  5278. Tag := Integer (O);
  5279. Caption := Title;
  5280. Hint := CommandLine;
  5281. OnClick := ToolClick;
  5282. end;
  5283. MainMenuTools.Insert (MainMenuTools.Count, O.MenuItem);
  5284. end;
  5285. procedure TMainForm.ProjectTreeStartDrag(Sender: TObject;
  5286. var DragObject: TDragObject);
  5287. begin
  5288. DragObject := TNoImageDragObject.Create (Sender as TControl);
  5289. end;
  5290. procedure TMainForm.UpdateProgramOutput;
  5291. begin
  5292. ActionProjectShowProgramOutput.Enabled := (MainConsole.LastOutSize > 2) or (MainConsole.LastErrSize > 2);
  5293. end;
  5294. procedure TMainForm.ShowProgramOutput(Sender: TObject);
  5295. begin
  5296. with TProgramOutputForm.Create (Self) do try
  5297. OutputMemo.Text := MainConsole.LastOutText;
  5298. ErrorMemo.Text := MainConsole.LastErrText;
  5299. ShowModal;
  5300. finally
  5301. Free;
  5302. end;
  5303. end;
  5304. procedure TMainForm.ClearDebugInfo;
  5305. begin
  5306. end;
  5307. procedure TMainForm.FileNewFolder(Sender: TObject);
  5308. var
  5309. ParentNode,
  5310. Node: TTreeNode;
  5311. Folder: TFolder;
  5312. begin
  5313. ParentNode := ProjectTree.Selected;
  5314. while Assigned (ParentNode) and Assigned (ParentNode.Data) and (not (TObject (ParentNode.Data) is TFolder)) do
  5315. ParentNode := ParentNode.Parent;
  5316. if Assigned (ParentNode) and Assigned (ParentNode.Parent) then begin
  5317. Folder := TFolder.Create;
  5318. Node := ProjectTree.Items.AddChildObject (ParentNode, 'New Folder', Folder);
  5319. Folder.TreeItem := Node;
  5320. with Node do begin
  5321. ImageIndex := 0;
  5322. SelectedIndex := 1;
  5323. Selected := True;
  5324. EditText;
  5325. end;
  5326. end;
  5327. end;
  5328. function TMainForm.GetSourceTypeFolder(Node: TTreeNode): TTreeNode;
  5329. begin
  5330. if Assigned (Node) and Assigned (Node.Parent) then begin
  5331. Result := Node;
  5332. while Assigned (Result) and Assigned (Result.Data) do
  5333. Result := Result.Parent;
  5334. end else
  5335. Result := nil;
  5336. end;
  5337. function TMainForm.FindFileInsertionPoint(ParentNode: TTreeNode): TTreeNode;
  5338. begin
  5339. if Assigned (ParentNode) then begin
  5340. Result := ParentNode.GetFirstChild;
  5341. while Assigned (Result) and Assigned (Result.Data) and (TObject (Result.Data) is TSourceFile) do
  5342. Result := Result.GetNextSibling;
  5343. end else
  5344. Result := nil;
  5345. end;
  5346. function TMainForm.CreateFileNode(ParentNode: TTreeNode; SourceFile: TSourceFile): TTreeNode;
  5347. begin
  5348. if Assigned (SourceFile.Folder) then
  5349. ParentNode := SourceFile.Folder.TreeItem;
  5350. if Assigned (ParentNode) then begin
  5351. Result := FindFileInsertionPoint (ParentNode);
  5352. if Assigned (Result) then
  5353. Result := ProjectTree.Items.InsertObject (Result, SourceFile.SourceName, SourceFile)
  5354. else
  5355. Result := ProjectTree.Items.AddChildObject (ParentNode, SourceFile.SourceName, SourceFile);
  5356. end else
  5357. Result := nil;
  5358. end;
  5359. procedure TMainForm.FileNewFile(Sender: TObject);
  5360. var
  5361. Node: TTreeNode;
  5362. begin
  5363. if Assigned (ProjectTree.Selected) then begin
  5364. Node := GetSourceTypeFolder (ProjectTree.Selected);
  5365. if Assigned (Node) then
  5366. if Node.Index = THeaderSourceFile.GetClassTreeIndex then
  5367. FileNewHeaderFile (Sender)
  5368. else if Node.Index = TCSourceFile.GetClassTreeIndex then
  5369. FileNewCSourceFile (Sender)
  5370. else if Node.Index = TGNUAsmSourceFile.GetClassTreeIndex then
  5371. FileNewGNUAssemblerSourceFile (Sender)
  5372. else if (ssA68k in SpecialSupport) and (Node.Index = TAsmSourceFile.GetClassTreeIndex) then
  5373. FileNewAssemblerSourceFile (Sender)
  5374. else if (ssQuill in SpecialSupport) and (Node.Index = TQuillSourceFile.GetClassTreeIndex) then
  5375. FileNewQuillSourceFile (Sender)
  5376. else if Node.Index = TNormalTextSourceFile.GetClassTreeIndex then
  5377. FileNewTextFile (Sender);
  5378. end;
  5379. end;
  5380. function TMainForm.GetSelectedFolder(SourceClass: TSourceFileClass): TFolder;
  5381. var
  5382. Node: TTreeNode;
  5383. begin
  5384. Result := nil;
  5385. Node := ProjectTree.Selected;
  5386. while Assigned (Node) and (Node <> TopNode.Item [SourceClass.GetClassTreeIndex]) do begin
  5387. if (not Assigned (Result)) and Assigned (Node.Data) and (TObject (Node.Data) is TFolder) then
  5388. Result := Node.Data;
  5389. Node := Node.Parent;
  5390. end;
  5391. if not Assigned (Node) then
  5392. Result := nil;
  5393. end;
  5394. procedure TMainForm.ErrorListKeyDown(Sender: TObject; var Key: Word;
  5395. Shift: TShiftState);
  5396. var
  5397. S: string;
  5398. Item: TListItem;
  5399. begin
  5400. if ((Key = VK_INSERT) or (Key = Ord('C'))) and (Shift = [ssCtrl]) then
  5401. with ErrorList do begin
  5402. S := '';
  5403. Item := Selected;
  5404. while Assigned (Item) do begin
  5405. S := S + Item.Caption + #13#10;
  5406. Item := GetNextItem (Item, sdAll, [isSelected]);
  5407. end;
  5408. Clipboard.AsText := S;
  5409. end;
  5410. end;
  5411. {$IFDEF CODINGEXT}
  5412. procedure TMainForm.InitCodingExt;
  5413. var
  5414. ActionFindSymbol: TAction;
  5415. begin
  5416. // Find Symbol declaration tool
  5417. ActionFindSymbol := TAction.Create(Self);
  5418. with ActionFindSymbol do
  5419. begin
  5420. ActionList := Actions;
  5421. Caption := 'F&ind Symbol Declaration';
  5422. Category := 'Extension';
  5423. OnExecute := ActionFindSymbolExecute;
  5424. end;
  5425. InsertsAction(Self, [OpenFileAtCursor1, OpenFileatCursor2], ActionFindSymbol);
  5426. end;
  5427. procedure TMainForm.ActionFindSymbolExecute(Sender: TObject);
  5428. begin
  5429. CompForm.FindSymbolDecl;
  5430. end;
  5431. {$ENDIF}
  5432. end.