MainUnit.pas 172 KB

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