MainUnit.pas 172 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. Copyright (C) 2005 Fréderic Bour
  5. Copyright (C) 2005-2007 Kevin Kofler
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. }
  18. unit MainUnit;
  19. interface
  20. uses
  21. MasterUnit, SourceFileUnit, FolderUnit, ToolsListUnit, LinkDLLUnit,
  22. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  23. Menus, StdCtrls, ExtCtrls, ImgList, ComCtrls, Buttons, ActnList, ToolWin,
  24. Printers, SourceEditUnit, HTMLHelpUnit, MemoComponentUnit, ScktComp,
  25. ComObj, ActiveX, TiEmuOLELib_TLB;
  26. type
  27. TPanel = class(ExtCtrls.TPanel)
  28. protected
  29. procedure Paint; override;
  30. end;
  31. TMainForm = class(TForm)
  32. ProjectTree: TTreeView;
  33. LittleIcons: TImageList;
  34. TreeEditorSplitter: TSplitter;
  35. MainMenu: TMainMenu;
  36. MainMenuFile: TMenuItem;
  37. MenuFileNew: TMenuItem;
  38. Project1: TMenuItem;
  39. AssemblerSource1: TMenuItem;
  40. Open1: TMenuItem;
  41. Save1: TMenuItem;
  42. SaveAs1: TMenuItem;
  43. N1: TMenuItem;
  44. Exit1: TMenuItem;
  45. CSourceFile1: TMenuItem;
  46. MainMenuEdit: TMenuItem;
  47. Undo1: TMenuItem;
  48. N2: TMenuItem;
  49. Delete1: TMenuItem;
  50. Cut1: TMenuItem;
  51. Copy1: TMenuItem;
  52. Paste1: TMenuItem;
  53. AddFiles1: TMenuItem;
  54. MenuCompileLine: TMenuItem;
  55. MainMenuProject: TMenuItem;
  56. Compile1: TMenuItem;
  57. Link1: TMenuItem;
  58. N4: TMenuItem;
  59. Options1: TMenuItem;
  60. AddFileDlg: TOpenDialog;
  61. N5: TMenuItem;
  62. Preferences1: TMenuItem;
  63. N6: TMenuItem;
  64. HeaderFile1: TMenuItem;
  65. SourceFilePopup: TPopupMenu;
  66. Compile2: TMenuItem;
  67. N7: TMenuItem;
  68. Remove1: TMenuItem;
  69. Delete2: TMenuItem;
  70. Splitter2: TSplitter;
  71. ErrWinPanel: TPanel;
  72. ErrorList: TListView;
  73. Save2: TMenuItem;
  74. SaveAs2: TMenuItem;
  75. N8: TMenuItem;
  76. MainMenuHelp: TMenuItem;
  77. Build1: TMenuItem;
  78. N9: TMenuItem;
  79. SelectAll1: TMenuItem;
  80. OpenProjectDlg: TOpenDialog;
  81. SaveProjectDlg: TSaveDialog;
  82. N10: TMenuItem;
  83. About1: TMenuItem;
  84. StatusBar: TStatusBar;
  85. ToolBarImages: TImageList;
  86. FileNewPopup: TPopupMenu;
  87. HeaderFile2: TMenuItem;
  88. Actions: TActionList;
  89. ActionFileNewProject: TAction;
  90. ActionFileNewCHeaderFile: TAction;
  91. ActionFileNewGNUAsmHeaderFile: TAction;
  92. ActionFileNewA68kAsmHeaderFile: TAction;
  93. ActionFileNewCFile: TAction;
  94. ActionFileNewGNUAsmFile: TAction;
  95. ActionFileNewA68kAsmFile: TAction;
  96. ActionFileOpen: TAction;
  97. ActionFileSave: TAction;
  98. ActionFileSaveAs: TAction;
  99. ActionFilePreferences: TAction;
  100. ActionFileExit: TAction;
  101. ActionEditUndo: TAction;
  102. ActionEditDelete: TAction;
  103. ActionEditCut: TAction;
  104. ActionEditCopy: TAction;
  105. ActionEditPaste: TAction;
  106. ActionEditSelectAll: TAction;
  107. ActionProjectAddFiles: TAction;
  108. ActionProjectCompile: TAction;
  109. ActionProjectMake: TAction;
  110. ActionProjectBuild: TAction;
  111. ActionProjectOptions: TAction;
  112. ActionHelpDocumentation: TAction;
  113. ActionHelpAbout: TAction;
  114. ActionTreeItemSave: TAction;
  115. ActionTreeItemSaveAs: TAction;
  116. ActionTreeItemCompile: TAction;
  117. ActionTreeItemRemove: TAction;
  118. ActionTreeItemDelete: TAction;
  119. CSourceFile2: TMenuItem;
  120. AssemblerSourceFile1: TMenuItem;
  121. Project3: TMenuItem;
  122. N11: TMenuItem;
  123. ActionProjectShowErrors: TAction;
  124. ErrorsandWarnings1: TMenuItem;
  125. N12: TMenuItem;
  126. MainMenuFind: TMenuItem;
  127. ActionFindFind: TAction;
  128. ActionFindReplace: TAction;
  129. ActionFindOpenFile: TAction;
  130. Find2: TMenuItem;
  131. Replace1: TMenuItem;
  132. OpenFileAtCursor1: TMenuItem;
  133. N13: TMenuItem;
  134. FindDlg: TFindDialog;
  135. ReplaceDlg: TReplaceDialog;
  136. ToolBarImagesDisabled: TImageList;
  137. PrintDlg: TPrintDialog;
  138. ActionFilePrint: TAction;
  139. Print1: TMenuItem;
  140. N14: TMenuItem;
  141. ActionFilePrintQuickly: TAction;
  142. ErrorListIcons: TImageList;
  143. DocFile: THTMLHelp;
  144. ActionHelpContents: TAction;
  145. ActionHelpIndex: TAction;
  146. ActionHelpSearch: TAction;
  147. ActionTreeItemRename: TAction;
  148. N19: TMenuItem;
  149. Rename1: TMenuItem;
  150. Contents1: TMenuItem;
  151. Index1: TMenuItem;
  152. Search1: TMenuItem;
  153. EditorPopup: TPopupMenu;
  154. Undo2: TMenuItem;
  155. N16: TMenuItem;
  156. Clear1: TMenuItem;
  157. Cut2: TMenuItem;
  158. Copy2: TMenuItem;
  159. Paste2: TMenuItem;
  160. N17: TMenuItem;
  161. SelectAll2: TMenuItem;
  162. MainToolBar: TToolBar;
  163. ToolBarNewButton: TToolButton;
  164. ToolButton2: TToolButton;
  165. ToolButton3: TToolButton;
  166. ToolButton4: TToolButton;
  167. ToolButton23: TToolButton;
  168. ToolButton24: TToolButton;
  169. ToolButton6: TToolButton;
  170. ToolButton7: TToolButton;
  171. ToolButton8: TToolButton;
  172. ToolButton9: TToolButton;
  173. ToolButton10: TToolButton;
  174. ToolButton5: TToolButton;
  175. ToolButton11: TToolButton;
  176. ToolButton20: TToolButton;
  177. ToolButton21: TToolButton;
  178. ToolBarCompileLine1: TToolButton;
  179. ToolBarCompileButton: TToolButton;
  180. ToolButton15: TToolButton;
  181. ToolBarCompileLine2: TToolButton;
  182. ToolButton18: TToolButton;
  183. ToolButton19: TToolButton;
  184. ActionEditRedo: TAction;
  185. Redo1: TMenuItem;
  186. Redo2: TMenuItem;
  187. EditorPanel: TPanel;
  188. NoEditor: TPanel;
  189. FunctionPopup: TPopupMenu;
  190. ActionFindFunctions: TAction;
  191. N15: TMenuItem;
  192. Functions1: TMenuItem;
  193. ToolButton25: TToolButton;
  194. NoFunctionsItem: TMenuItem;
  195. ActionFileNewTextFile: TAction;
  196. TextFile1: TMenuItem;
  197. TextFile2: TMenuItem;
  198. ActionEditIncreaseIndent: TAction;
  199. ActionEditDecreaseIndent: TAction;
  200. N18: TMenuItem;
  201. IncreaseIndent1: TMenuItem;
  202. DecreaseIndent1: TMenuItem;
  203. N20: TMenuItem;
  204. IncreaseIndent2: TMenuItem;
  205. DecreaseIndent2: TMenuItem;
  206. N21: TMenuItem;
  207. OpenFileatCursor2: TMenuItem;
  208. GNUAssemblySourceFile1: TMenuItem;
  209. GNUAssemblySourceFile2: TMenuItem;
  210. ActionFileNewQuillFile: TAction;
  211. QuillSourceFile1: TMenuItem;
  212. QuillSourceFile2: TMenuItem;
  213. ActionProjectStopCompilation: TAction;
  214. ActionProjectForceQuitCompiler: TAction;
  215. ToolButton16: TToolButton;
  216. ToolButton17: TToolButton;
  217. StopCompilation1: TMenuItem;
  218. ForceQuitCompiler1: TMenuItem;
  219. ActionHelpNews: TAction;
  220. N3: TMenuItem;
  221. News1: TMenuItem;
  222. ActionDebugRun: TAction;
  223. ActionDebugPause: TAction;
  224. ActionDebugReset: TAction;
  225. MainMenuDebug: TMenuItem;
  226. Run1: TMenuItem;
  227. N22: TMenuItem;
  228. Pause1: TMenuItem;
  229. Reset1: TMenuItem;
  230. ToolBarRunButton: TToolButton;
  231. ToolBarDebugLine: TToolButton;
  232. ToolBarPauseButton: TToolButton;
  233. ToolButton12: TToolButton;
  234. ToolButton13: TToolButton;
  235. ChangeNotificationTimer: TTimer;
  236. ToolBarBevel: TBevel;
  237. ToolBarEndLine: TToolButton;
  238. RecentFilesLine: TMenuItem;
  239. RecentFilesPopup: TPopupMenu;
  240. NoFilesItem: TMenuItem;
  241. ActionToolsConfigure: TAction;
  242. MainMenuTools: TMenuItem;
  243. Configure1: TMenuItem;
  244. ToolsLine: TMenuItem;
  245. ActionProjectShowProgramOutput: TAction;
  246. ProgramOutput1: TMenuItem;
  247. ActionFileNewFolder: TAction;
  248. N23: TMenuItem;
  249. Folder1: TMenuItem;
  250. N24: TMenuItem;
  251. Folder2: TMenuItem;
  252. FolderPopup: TPopupMenu;
  253. MenuItem6: TMenuItem;
  254. MenuItem9: TMenuItem;
  255. CategoryPopup: TPopupMenu;
  256. ActionFileNewFile: TAction;
  257. File1: TMenuItem;
  258. Folder3: TMenuItem;
  259. N25: TMenuItem;
  260. Folder4: TMenuItem;
  261. File2: TMenuItem;
  262. ActionTreeItemNewFolder: TAction;
  263. ActionTreeItemNewFile: TAction;
  264. GNUAssemblyHeaderFile1: TMenuItem;
  265. GNUAssemblyHeaderFile2: TMenuItem;
  266. A68kAssemblyHeaderFile1: TMenuItem;
  267. A68kAssemblyHeaderFile2: TMenuItem;
  268. ErrorPanel: TPanel;
  269. CloseErrorsButton: TSpeedButton;
  270. Label1: TLabel;
  271. Label2: TLabel;
  272. ErrorsLabel: TLabel;
  273. WarningsLabel: TLabel;
  274. procedure FormCreate(Sender: TObject);
  275. procedure FormDestroy(Sender: TObject);
  276. procedure AppException(Sender: TObject; E: Exception);
  277. procedure ProjectTreeEditing(Sender: TObject; Node: TTreeNode;
  278. var AllowEdit: Boolean);
  279. procedure ProjectAddFiles(Sender: TObject);
  280. procedure ProjectTreeChange(Sender: TObject; Node: TTreeNode);
  281. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  282. procedure ProjectTreeDeletion(Sender: TObject; Node: TTreeNode);
  283. procedure FileExit(Sender: TObject);
  284. procedure FileNewProject(Sender: TObject);
  285. procedure TreeItemRemove(Sender: TObject);
  286. procedure TreeItemDelete(Sender: TObject);
  287. procedure TreeItemCompile(Sender: TObject);
  288. procedure CloseErrorsButtonClick(Sender: TObject);
  289. procedure ErrorListDeletion(Sender: TObject; Item: TListItem);
  290. procedure TreeItemSave(Sender: TObject);
  291. procedure HelpDocumentation(Sender: TObject);
  292. procedure EditorEnter(Sender: TObject);
  293. procedure EditorExit(Sender: TObject);
  294. procedure EditUndo(Sender: TObject);
  295. procedure EditRedo(Sender: TObject);
  296. procedure EditClear(Sender: TObject);
  297. procedure EditCut(Sender: TObject);
  298. procedure EditCopy(Sender: TObject);
  299. procedure EditPaste(Sender: TObject);
  300. procedure EditSelectAll(Sender: TObject);
  301. procedure ProjectCompile(Sender: TObject);
  302. procedure ProjectMake(Sender: TObject);
  303. procedure FileOpenProject(Sender: TObject);
  304. procedure FileSaveAll(Sender: TObject);
  305. procedure FileSaveProjectAs(Sender: TObject);
  306. procedure EditorKeyDown(Sender: TObject; var Key: Word;
  307. Shift: TShiftState);
  308. procedure ProjectBuild(Sender: TObject);
  309. procedure ProjectTreeKeyDown(Sender: TObject; var Key: Word;
  310. Shift: TShiftState);
  311. procedure ProjectTreeMouseUp(Sender: TObject; Button: TMouseButton;
  312. Shift: TShiftState; X, Y: Integer);
  313. procedure ProjectTreeEdited(Sender: TObject; Node: TTreeNode;
  314. var S: String);
  315. procedure ProjectOptions(Sender: TObject);
  316. procedure FilePreferences(Sender: TObject);
  317. procedure FileNewHeaderFile(Sender: TObject);
  318. procedure FileNewCSourceFile(Sender: TObject);
  319. procedure FileNewGNUAssemblerSourceFile(Sender: TObject);
  320. procedure FileNewAssemblerSourceFile(Sender: TObject);
  321. procedure FileNewQuillSourceFile(Sender: TObject);
  322. procedure FileNewTextFile(Sender: TObject);
  323. procedure TreeItemSaveAs(Sender: TObject);
  324. procedure HelpAbout(Sender: TObject);
  325. procedure DisplayHint(Sender: TObject);
  326. procedure ShowHideErrors(Sender: TObject);
  327. procedure FindString(Sender: TObject; AllFiles: Boolean);
  328. procedure ReplaceDlgReplace(Sender: TObject);
  329. procedure FindText(Sender: TObject);
  330. procedure ReplaceText(Sender: TObject);
  331. procedure FindOpenFile(Sender: TObject);
  332. procedure FindDlgFind(Sender: TObject);
  333. procedure ActionsExecute(Action: TBasicAction; var Handled: Boolean);
  334. procedure ProjectTreeEnter(Sender: TObject);
  335. procedure ProjectTreeExit(Sender: TObject);
  336. procedure ProjectTreeChanging(Sender: TObject; Node: TTreeNode;
  337. var AllowChange: Boolean);
  338. procedure EditorChange(Sender: TObject);
  339. procedure FilePrint(Sender: TObject);
  340. procedure FilePrintQuickly(Sender: TObject);
  341. procedure TreeItemRename(Sender: TObject);
  342. procedure HelpContents(Sender: TObject);
  343. procedure HelpIndex(Sender: TObject);
  344. procedure HelpSearch(Sender: TObject);
  345. procedure SplitterMoved(Sender: TObject);
  346. procedure ProjectTreeMouseDown(Sender: TObject; Button: TMouseButton;
  347. Shift: TShiftState; X, Y: Integer);
  348. procedure ToolBarManagerBandMove(Sender: TObject; Control: TControl;
  349. var ARect: TRect);
  350. procedure ProjectTreeDragOver(Sender, Source: TObject; X, Y: Integer;
  351. State: TDragState; var Accept: Boolean);
  352. procedure ProjectTreeDragDrop(Sender, Source: TObject; X, Y: Integer);
  353. procedure ErrorListClick(Sender: TObject);
  354. procedure DeleteError(Sender: TObject);
  355. procedure FunctionPopupPopup(Sender: TObject);
  356. procedure FindFunctions(Sender: TObject);
  357. procedure FindFunctionFromPopup(Sender: TObject);
  358. procedure IncreaseIndent(Sender: TObject);
  359. procedure DecreaseIndent(Sender: TObject);
  360. procedure ProjectStopCompilation(Sender: TObject);
  361. procedure ProjectForceQuitCompiler(Sender: TObject);
  362. procedure HelpNews(Sender: TObject);
  363. procedure DebugRun(Sender: TObject);
  364. procedure DebugPause(Sender: TObject);
  365. procedure DebugReset(Sender: TObject);
  366. procedure FormKeyDown(Sender: TObject; var Key: Word;
  367. Shift: TShiftState);
  368. procedure ChangeNotificationTick(Sender: TObject);
  369. procedure RecentFileClick(Sender: TObject);
  370. procedure ToolsConfigure(Sender: TObject);
  371. procedure ToolClick(Sender: TObject);
  372. procedure ProjectTreeStartDrag(Sender: TObject;
  373. var DragObject: TDragObject);
  374. procedure ShowProgramOutput(Sender: TObject);
  375. procedure FileNewFolder(Sender: TObject);
  376. procedure FileNewFile(Sender: TObject);
  377. procedure ErrorListKeyDown(Sender: TObject; var Key: Word;
  378. Shift: TShiftState);
  379. private
  380. EditorToHide: TWinControl;
  381. TempLockHandle: THandle;
  382. FModified: Boolean;
  383. FInvalidated: Boolean;
  384. FProjectFile: string;
  385. InChangeNotification: Boolean;
  386. procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
  387. procedure SetProjectFile(const Value: string);
  388. procedure SetModified(const Value: Boolean);
  389. function GetCurrentEditor: TMemoComponent;
  390. function GetInvalidated: Boolean;
  391. public
  392. TopNode: TTreeNode;
  393. OriginalCaption: string;
  394. LinkLibHandle: HModule;
  395. LinkLibGetInterfaceVersion: TLinkLibGetInterfaceVersion;
  396. LinkLibLinkFiles: TLinkLibLinkFiles;
  397. LinkLibCreateArchive: TLinkLibCreateArchive;
  398. SourceFiles: TSourceFiles;
  399. JumpToError,
  400. OpenFolderMessage,
  401. AutoSave,
  402. DeleteErrors,
  403. StartingAppNow,
  404. OpeningProjectNow,
  405. NoHideEditor: Boolean;
  406. PreviousNode: TTreeNode;
  407. SyntaxCBackup: TSyntaxColoring;
  408. SyntaxAsmGNUBackup: TSyntaxColoring;
  409. SyntaxAsmBackup: TSyntaxColoring;
  410. SyntaxQuillBackup: TSyntaxColoring;
  411. Closing: Boolean;
  412. ProgSize: Integer;
  413. OptimizeInfo: TLinkLibOptimizeInfo;
  414. Funcs: TSourceFileFunctions;
  415. CurrentStrings: TMemoryStream;
  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 GetTiEmuInterface: ITiEmuOLE;
  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. else if FileExists (WithBackslash (TIGCCFolder) + GASIncludeLocation + ExtractFileName (SourceF)) then
  1580. SourceFile := AddSourceFile (WithBackslash (TIGCCFolder) + GASIncludeLocation + ExtractFileName (SourceF), True);
  1581. end;
  1582. except end;
  1583. BugType := BugTp;
  1584. WholeLine := Line;
  1585. ErrorMessage := ErrMessage;
  1586. ErrFunction := ErrFunc;
  1587. if Assigned (SourceFile) and (SourceFile is TTextSourceFile) then
  1588. with SourceFile as TTextSourceFile do
  1589. if Assigned (TextEditor) then begin
  1590. I := GetCompiledLineStart (SourceLn) + Offset;
  1591. if I > 0 then begin
  1592. if Pos ('''', ErrorMessage) > 0 then begin
  1593. Token := Copy (ErrorMessage, Pos ('''', ErrorMessage) + 1, Length (ErrorMessage));
  1594. Delete (Token, Pos ('''', Token), Length (Token));
  1595. if Length (Token) > 0 then begin
  1596. J := I;
  1597. while (J <= TextEditor.TextLength) and (TextEditor.Text [J] in [#9, #10, #13, #32]) and (Copy (TextEditor.Text, J, Length (Token)) <> Token) do
  1598. Inc (J);
  1599. if Copy (TextEditor.Text, J, Length (Token)) = Token then
  1600. I := J;
  1601. end;
  1602. end;
  1603. O.Range := TMCRange.Create (TextEditor.TrackedRanges);
  1604. O.Range.RStart := I;
  1605. O.Range.OnOverwrite := DeleteError;
  1606. end else
  1607. O.Range := nil;
  1608. end;
  1609. end;
  1610. with ErrorList.Items.Add do begin
  1611. Data := Pointer (O);
  1612. ImageIndex := Integer (BugTp);
  1613. Caption := ErrMessage;
  1614. if Assigned (O.SourceFile) then
  1615. SubItems.Add (O.SourceFile.SourceName)
  1616. else
  1617. SubItems.Add ('');
  1618. SubItems.Add (ErrFunc);
  1619. ShowErrors;
  1620. if JumpToError and (BugTp = btError) and (not Assigned (ErrorList.Selected)) then begin
  1621. Selected := True;
  1622. ErrorListClick (Self);
  1623. end;
  1624. end;
  1625. except end;
  1626. ErrorList.Items.EndUpdate;
  1627. end;
  1628. end;
  1629. UpdateErrorWindow;
  1630. end;
  1631. procedure TMainForm.ClearErrors;
  1632. begin
  1633. HideErrors;
  1634. with ErrorList.Items do begin
  1635. BeginUpdate;
  1636. Clear;
  1637. EndUpdate;
  1638. end;
  1639. ActionProjectShowErrors.Enabled := False;
  1640. end;
  1641. procedure TMainForm.HideErrors;
  1642. begin
  1643. Splitter2.Hide;
  1644. ErrWinPanel.Hide;
  1645. ActionProjectShowErrors.Checked := False;
  1646. end;
  1647. procedure TMainForm.ShowErrors;
  1648. begin
  1649. if ErrorList.Items.Count > 0 then begin
  1650. ErrWinPanel.Show;
  1651. Splitter2.Show;
  1652. Splitter2.Top := ErrWinPanel.Top - Splitter2.Height;
  1653. ActionProjectShowErrors.Checked := True;
  1654. ErrorList.Refresh;
  1655. end;
  1656. end;
  1657. procedure TMainForm.ErrorListDeletion(Sender: TObject; Item: TListItem);
  1658. var
  1659. O: TObject;
  1660. begin
  1661. if Assigned (Item.Data) then begin
  1662. O := TObject(Item.Data);
  1663. Item.Data := nil;
  1664. O.Free;
  1665. end;
  1666. end;
  1667. procedure TMainForm.UpdateErrorWindow;
  1668. var
  1669. I: Integer;
  1670. EC,
  1671. WC: Integer;
  1672. begin
  1673. with ErrorList, Items do begin
  1674. EC := 0;
  1675. WC := 0;
  1676. for I := 0 to Count - 1 do
  1677. with TFoundError (Item[I].Data) do
  1678. case BugType of
  1679. btWarning:
  1680. Inc (WC);
  1681. btError:
  1682. Inc (EC);
  1683. end;
  1684. ErrorsLabel.Caption := IntToStr (EC);
  1685. WarningsLabel.Caption := IntToStr (WC);
  1686. if Count <= 0 then
  1687. HideErrors;
  1688. end;
  1689. ActionProjectShowErrors.Enabled := ErrorList.Items.Count > 0;
  1690. if not ActionProjectShowErrors.Enabled then
  1691. ActionProjectShowErrors.Checked := False;
  1692. end;
  1693. procedure TMainForm.TreeItemSave(Sender: TObject);
  1694. var
  1695. Node: TTreeNode;
  1696. begin
  1697. Node := ProjectTree.Selected;
  1698. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  1699. TSourceFile(Node.Data).Save;
  1700. end;
  1701. procedure TMainForm.HelpDocumentation(Sender: TObject);
  1702. begin
  1703. try
  1704. DocFile.Display;
  1705. except
  1706. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  1707. end;
  1708. end;
  1709. procedure TMainForm.EditorEnter(Sender: TObject);
  1710. begin
  1711. ActionEditPaste.Enabled := True;
  1712. ActionEditSelectAll.Enabled := True;
  1713. ActionEditIncreaseIndent.Enabled := True;
  1714. ActionEditDecreaseIndent.Enabled := True;
  1715. ActionFindOpenFile.Enabled := True;
  1716. UpdateEditButtons;
  1717. end;
  1718. procedure TMainForm.EditorExit(Sender: TObject);
  1719. begin
  1720. ActionEditDelete.Enabled := False;
  1721. ActionEditCut.Enabled := False;
  1722. ActionEditCopy.Enabled := False;
  1723. ActionEditPaste.Enabled := False;
  1724. ActionEditSelectAll.Enabled := False;
  1725. ActionEditIncreaseIndent.Enabled := False;
  1726. ActionEditDecreaseIndent.Enabled := False;
  1727. ActionFindOpenFile.Enabled := False;
  1728. ActionEditUndo.Enabled := False;
  1729. ActionEditRedo.Enabled := False;
  1730. end;
  1731. procedure TMainForm.EditUndo(Sender: TObject);
  1732. begin
  1733. if Assigned (CurrentEditor) then
  1734. CurrentEditor.Undo;
  1735. end;
  1736. procedure TMainForm.EditRedo(Sender: TObject);
  1737. begin
  1738. if Assigned (CurrentEditor) then
  1739. CurrentEditor.Redo;
  1740. end;
  1741. procedure TMainForm.EditClear(Sender: TObject);
  1742. var
  1743. Editor: TMemoComponent;
  1744. begin
  1745. Editor := CurrentEditor;
  1746. if Assigned (Editor) and (ActiveControl = Editor) then
  1747. Editor.ClearSelection
  1748. else if ActiveControl = ProjectTree then
  1749. TreeItemRemove (Sender);
  1750. end;
  1751. procedure TMainForm.EditCut(Sender: TObject);
  1752. var
  1753. Editor: TMemoComponent;
  1754. begin
  1755. Editor := CurrentEditor;
  1756. if Assigned (Editor) and (ActiveControl = Editor) then
  1757. Editor.CutToClipboard;
  1758. end;
  1759. procedure TMainForm.EditCopy(Sender: TObject);
  1760. var
  1761. Editor: TMemoComponent;
  1762. begin
  1763. Editor := CurrentEditor;
  1764. if Assigned (Editor) and (ActiveControl = Editor) then
  1765. Editor.CopyToClipboard;
  1766. end;
  1767. procedure TMainForm.EditPaste(Sender: TObject);
  1768. var
  1769. Editor: TMemoComponent;
  1770. begin
  1771. Editor := CurrentEditor;
  1772. if Assigned (Editor) and (ActiveControl = Editor) then
  1773. Editor.PasteFromClipboard;
  1774. end;
  1775. procedure TMainForm.EditSelectAll(Sender: TObject);
  1776. var
  1777. Editor: TMemoComponent;
  1778. begin
  1779. Editor := CurrentEditor;
  1780. if Assigned (Editor) and (ActiveControl = Editor) then
  1781. Editor.SelectAll;
  1782. end;
  1783. procedure TMainForm.ProjectCompile(Sender: TObject);
  1784. var
  1785. I: Integer;
  1786. begin
  1787. if not Compiling then begin
  1788. if AutoSave then
  1789. FileSave
  1790. else
  1791. with SourceFiles do
  1792. for I := 0 to Count - 1 do
  1793. with Items [I] as TSourceFile do
  1794. if not InProject then
  1795. Save;
  1796. BeginCompilation;
  1797. CompileProject;
  1798. EndCompilation;
  1799. end;
  1800. end;
  1801. procedure TMainForm.ProjectMake(Sender: TObject);
  1802. begin
  1803. if not Compiling then begin
  1804. MakeFileWrapped;
  1805. DisplayFolderMessage;
  1806. end;
  1807. end;
  1808. procedure TMainForm.MakeFileWrapped;
  1809. var
  1810. I: Integer;
  1811. begin
  1812. if not Compiling then begin
  1813. if AutoSave then
  1814. FileSave
  1815. else
  1816. with SourceFiles do
  1817. for I := 0 to Count - 1 do
  1818. with Items [I] as TSourceFile do
  1819. if not InProject then
  1820. Save;
  1821. OperationSuccessful := False;
  1822. if ProjectFile = '' then
  1823. ShowDefaultMessageBox ('You need to save your project before you can create executable files.', 'Project not Saved', mtProgramError)
  1824. else begin
  1825. BeginCompilation;
  1826. CompileProject;
  1827. Application.ProcessMessages;
  1828. if OperationSuccessful and not OperationCancelled then
  1829. MakeFile;
  1830. EndCompilation;
  1831. end;
  1832. end;
  1833. end;
  1834. procedure TMainForm.MakeFile;
  1835. procedure FileNotCompiled(const FileName: string);
  1836. begin
  1837. ShowDefaultMessageBox
  1838. ('The file ''' + FileName + ''' has not been compiled. You have to compile it first before you can link it to your project.',
  1839. 'No Object File', mtProgramError);
  1840. end;
  1841. var MainFiles: array [TCalcDest] of string;
  1842. procedure HandleContents(const ProjectFile, FolderName, VarName, DataFolderName, DataVarName: string; Pack: Boolean; const PackVar: string; CalcDest: TCalcDest);
  1843. var
  1844. InputStream,
  1845. OutputStream: TMemoryStream;
  1846. OutputSize: LongWord;
  1847. FileSize: Integer;
  1848. F: file;
  1849. B: Byte;
  1850. begin
  1851. CompUpdate;
  1852. OperationSuccessful := False;
  1853. with LinkOutputFiles [CalcDest, frMain] do
  1854. if Assigned (Data) then begin
  1855. OutputStream := TMemoryStream.Create;
  1856. try
  1857. if OSUpgrade then begin
  1858. OutputSize := GetOSUpgradeFileSize (Data.Size, OutputBin);
  1859. OutputStream.Size := OutputSize;
  1860. ProduceOSUpgradeFile (OutputStream.Memory, Data.Memory, Data.Size, OutputBin);
  1861. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetOSUpgradeFileExt (CalcDest, OutputBin));
  1862. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1863. if LongWord (ProgSize) < OutputSize then
  1864. ProgSize := OutputSize;
  1865. OperationSuccessful := True;
  1866. end else begin
  1867. FileSize := 2 + Data.Size + 1;
  1868. if Pack then begin
  1869. AssignFile (F, Temp + 'tempprog.bin');
  1870. Rewrite (F, 1);
  1871. B := (FileSize - 2) shr 8;
  1872. BlockWrite (F, B, 1);
  1873. B := (FileSize - 2);
  1874. BlockWrite (F, B, 1);
  1875. BlockWrite (F, Data.Memory^, Data.Size);
  1876. B := Tag;
  1877. BlockWrite (F, B, 1);
  1878. CloseFile (F);
  1879. MainConsole.Title := 'Compressor';
  1880. CompUpdate;
  1881. try
  1882. MainConsole.StartProcess (WithBackslash (TIGCCFolder) + PackLocation + 'Pack.exe', 'tempprog.bin tempprog.pck', WithoutBackslash (Temp));
  1883. WaitForMainConsole ('Compression');
  1884. except
  1885. ShowDefaultMessageBox ('Could not start compressor.', 'Error', mtProgramError);
  1886. end;
  1887. CompUpdate;
  1888. if not OperationCancelled then begin
  1889. if FileExists (Temp + 'tempprog.pck') then begin
  1890. InputStream := TMemoryStream.Create;
  1891. with InputStream do try
  1892. LoadFromFile (Temp + 'tempprog.pck');
  1893. OutputSize := GetTransferFileSize (Size, 'ppg', OutputBin);
  1894. if OutputSize > 0 then begin
  1895. OutputStream.Size := OutputSize;
  1896. ProduceTransferFile (OutputStream.Memory, Memory, Size, CalcDest, FolderName, PackVar, $F8, 'ppg', OutputBin);
  1897. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetTransferFileExt (CalcDest, $F8, OutputBin));
  1898. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1899. if LongWord (ProgSize) < OutputSize then
  1900. ProgSize := OutputSize;
  1901. OperationSuccessful := True;
  1902. end else
  1903. ShowDefaultMessageBox ('Compressed size of ' + IntToStr (Size) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1904. finally
  1905. Free;
  1906. end;
  1907. end else
  1908. ShowDefaultMessageBox ('Compression failed. Please check the program size.', 'Error', mtProgramError);
  1909. end;
  1910. if FileExists (Temp + 'tempprog.bin') then
  1911. DeleteFile (Temp + 'tempprog.bin');
  1912. if FileExists (Temp + 'tempprog.pck') then
  1913. DeleteFile (Temp + 'tempprog.pck');
  1914. end else begin
  1915. OutputSize := GetTransferFileSize (Data.Size, VarExt, OutputBin);
  1916. if OutputSize > 0 then begin
  1917. OutputStream.Size := OutputSize;
  1918. ProduceTransferFile (OutputStream.Memory, Data.Memory, Data.Size, CalcDest, FolderName, VarName, Tag, VarExt, OutputBin);
  1919. MainFiles [CalcDest] := ChangeFileExt (ProjectFile, GetTransferFileExt (CalcDest, Tag, OutputBin));
  1920. OutputStream.SaveToFile (MainFiles [CalcDest]);
  1921. if LongWord (ProgSize) < OutputSize then
  1922. ProgSize := OutputSize;
  1923. OperationSuccessful := True;
  1924. end else
  1925. ShowDefaultMessageBox ('Variable size of ' + IntToStr (FileSize) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1926. end;
  1927. end;
  1928. finally
  1929. OutputStream.Free;
  1930. end;
  1931. CompUpdate;
  1932. end else
  1933. ShowDefaultMessageBox ('Unexpected destination calculator mismatch.', 'Error', mtProgramError);
  1934. with LinkOutputFiles [CalcDest, frData] do
  1935. if Assigned (Data) and (not OSUpgrade) then begin
  1936. FileSize := 2 + Data.Size + 1;
  1937. OutputStream := TMemoryStream.Create;
  1938. try
  1939. OutputSize := GetTransferFileSize (Data.Size, VarExt, OutputBin);
  1940. if OutputSize > 0 then begin
  1941. OutputStream.Size := OutputSize;
  1942. ProduceTransferFile (OutputStream.Memory, Data.Memory, Data.Size, CalcDest, DataFolderName, DataVarName, Tag, VarExt, OutputBin);
  1943. OutputStream.SaveToFile (ChangeFileExt (ChangeFileExt (ProjectFile, '') + '-data', GetTransferFileExt (CalcDest, Tag, OutputBin)));
  1944. OperationSuccessful := True;
  1945. end else
  1946. ShowDefaultMessageBox ('Data variable size of ' + IntToStr (FileSize) + ' bytes is too large, unexpectedly.', 'Error', mtProgramError);
  1947. finally
  1948. OutputStream.Free;
  1949. end;
  1950. CompUpdate;
  1951. end;
  1952. end;
  1953. procedure HandleDebugContents(const ProjectFile: string);
  1954. begin
  1955. with LinkDebugFile do
  1956. if Assigned (Data) then
  1957. Data.SaveToFile (ChangeFileExt (ProjectFile, '.dbg'));
  1958. end;
  1959. procedure CreatePackStarter(const ProjectFile, StarterFileName, FolderName, VarName, PackVar: string; CalcDests: TCalcDests);
  1960. var
  1961. CurCalcDest: TCalcDest;
  1962. CustomStarterObject: string;
  1963. ObjectFileNames: array [0..1] of PChar;
  1964. DataVarInfo: TLinkLibDataVarInfo;
  1965. OptimizeInfo: TLinkLibOptimizeInfo;
  1966. begin
  1967. CompUpdate;
  1968. OperationSuccessful := False;
  1969. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  1970. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  1971. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  1972. end;
  1973. try
  1974. CustomStarterObject := Temp + StarterFileName;
  1975. if FileExists (WithBackslash (TIGCCFolder) + PStarterLocation + StarterFileName) then try
  1976. ParsePStarter (WithBackslash (TIGCCFolder) + PStarterLocation + StarterFileName, CustomStarterObject, PackVar);
  1977. except
  1978. ShowDefaultMessageBox ('Error processing starter object file.', 'Error', mtProgramError);
  1979. Exit;
  1980. end else begin
  1981. ShowDefaultMessageBox ('Cannot find starter object file.', 'Error', mtProgramError);
  1982. Exit;
  1983. end;
  1984. if not OperationCancelled then begin
  1985. ObjectFileNames [0] := PChar (CustomStarterObject);
  1986. ObjectFileNames [1] := nil;
  1987. FillChar (DataVarInfo, SizeOf (DataVarInfo), 0);
  1988. FillChar (OptimizeInfo, SizeOf (OptimizeInfo), 0);
  1989. if Assigned (LinkLibLinkFiles) then
  1990. OperationSuccessful := LinkLibLinkFiles (@ObjectFileNames, nil, LinkLibError, LinkLibGetOutputFile, nil, False, False, False, DataVarInfo, OptimizeInfo, False) = 0
  1991. else
  1992. ShowDefaultMessageBox ('Linker not loaded.', 'Error', mtProgramError);
  1993. end;
  1994. for CurCalcDest := cdTI89 to cdV200 do
  1995. if OperationSuccessful and (not OperationCancelled) and (CurCalcDest in CalcDests) then
  1996. HandleContents (ProjectFile, FolderName, VarName, '', '', False, '', CurCalcDest);
  1997. finally
  1998. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  1999. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2000. LinkOutputFiles[CurCalcDest,frMain].Data.Free;
  2001. if Assigned (LinkOutputFiles[CurCalcDest,frData].Data) then
  2002. LinkOutputFiles[CurCalcDest,frData].Data.Free;
  2003. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2004. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2005. end;
  2006. if FileExists (CustomStarterObject) then
  2007. DeleteFile (CustomStarterObject);
  2008. end;
  2009. end;
  2010. var
  2011. FolderName,
  2012. VarName,
  2013. DataFolderName,
  2014. DataVarName: array [0..MaxNameLength] of Char;
  2015. I,
  2016. P: Integer;
  2017. S1,
  2018. DestFile: string;
  2019. Node: TTreeNode;
  2020. SourceFile: TSourceFile;
  2021. FileNameList: TStringList;
  2022. ObjectFileNames,
  2023. ArchiveFileNames: PPChar;
  2024. ObjectFileCount,
  2025. ArchiveFileCount: Integer;
  2026. DataVarInfo: TLinkLibDataVarInfo;
  2027. CalcDests: TCalcDests;
  2028. CurCalcDest: TCalcDest;
  2029. SR: TSearchRec;
  2030. begin
  2031. UpdateErrorWindow;
  2032. OperationCancelled := False;
  2033. OperationSuccessful := False;
  2034. ProgSize := 0;
  2035. CalcDests := [];
  2036. OperationSuccessful := True;
  2037. with TopNode do begin
  2038. I := Pos ('\', Text);
  2039. if I > 0 then begin
  2040. StrPLCopy (VarName, LowerCase (Copy (Text, I + 1, MaxNameLength)), MaxNameLength);
  2041. StrPLCopy (FolderName, LowerCase (Copy (Text, 1, I - 1)), MaxNameLength);
  2042. CharLower (FolderName);
  2043. end else begin
  2044. StrPLCopy (VarName, LowerCase (Text), MaxNameLength);
  2045. FolderName := 'main';
  2046. end;
  2047. CharLower (VarName);
  2048. end;
  2049. with SourceFiles do
  2050. for I := 0 to Count - 1 do
  2051. with TSourceFile (Items [I]) do
  2052. if InProject and Compilable and (not FileExists (ChangeFileExt (FileName, '.o'))) then begin
  2053. OperationSuccessful := False;
  2054. FileNotCompiled (SourceName);
  2055. end;
  2056. I := Pos ('\', DataVar);
  2057. if I > 0 then begin
  2058. StrPLCopy (DataVarName, LowerCase (Copy (DataVar, I + 1, MaxNameLength)), MaxNameLength);
  2059. StrPLCopy (DataFolderName, LowerCase (Copy (DataVar, 1, I - 1)), MaxNameLength);
  2060. CharLower (DataFolderName);
  2061. end else begin
  2062. StrPLCopy (DataVarName, LowerCase (DataVar), MaxNameLength);
  2063. DataFolderName := FolderName;
  2064. end;
  2065. CharLower (DataVarName);
  2066. if OperationSuccessful then begin
  2067. OperationSuccessful := False;
  2068. if Assigned (LinkLibLinkFiles) and Assigned (LinkLibCreateArchive) then begin
  2069. CompStartFile;
  2070. CompSetMessage ('Linking Project ''' + WithoutExt (ExtractFileName (ProjectFile)) + '''');
  2071. if FileExists (ChangeFileExt (ProjectFile, '-titanium.89z')) then
  2072. DeleteFile (ChangeFileExt (ProjectFile, '-titanium.89z'));
  2073. ObjectFileCount := 0;
  2074. ObjectFileNames := nil;
  2075. ArchiveFileCount := 0;
  2076. ArchiveFileNames := nil;
  2077. FileNameList := TStringList.Create;
  2078. try
  2079. Node := TopNode;
  2080. while Assigned (Node) do begin
  2081. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  2082. SourceFile := Node.Data;
  2083. if Assigned (SourceFile) then
  2084. with SourceFile do
  2085. if InProject then begin
  2086. if SourceFile is TArchiveSourceFile then begin
  2087. Inc (ArchiveFileCount);
  2088. ReallocMem (ArchiveFileNames, SizeOf (PChar) * (ArchiveFileCount + 1));
  2089. ArchiveFileNames [ArchiveFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (FileName)]);
  2090. ArchiveFileNames [ArchiveFileCount - 0] := nil;
  2091. end else if Compilable or (SourceFile is TObjectSourceFile) then begin
  2092. Inc (ObjectFileCount);
  2093. ReallocMem (ObjectFileNames, SizeOf (PChar) * (ObjectFileCount + 1));
  2094. ObjectFileNames [ObjectFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (ChangeFileExt (FileName, '.o'))]);
  2095. ObjectFileNames [ObjectFileCount] := nil;
  2096. end;
  2097. end;
  2098. end;
  2099. Node := Node.GetNext;
  2100. end;
  2101. if StdLib then begin
  2102. if ProjectTarget = ptFlashOS then
  2103. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'flashos.a'
  2104. else if ProjectTarget = ptFargo then
  2105. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'fargo.a'
  2106. else
  2107. S1 := WithBackslash (TIGCCFolder) + StdLibLocation + 'tigcc.a';
  2108. if FileExists (S1) then begin
  2109. Inc (ArchiveFileCount);
  2110. ReallocMem (ArchiveFileNames, SizeOf (PChar) * (ArchiveFileCount + 1));
  2111. ArchiveFileNames [ArchiveFileCount - 1] := PChar (FileNameList.Strings [FileNameList.Add (S1)]);
  2112. ArchiveFileNames [ArchiveFileCount] := nil;
  2113. end;
  2114. end;
  2115. if ProjectTarget = ptArchive then begin
  2116. DestFile := ChangeFileExt (ProjectFile, '.a');
  2117. OperationSuccessful := LinkLibCreateArchive (PChar (DestFile), ObjectFileNames, LinkLibError, True) = 0;
  2118. if OperationSuccessful then begin
  2119. if FindFirst (DestFile, faAnyFile, SR) = 0 then
  2120. ProgSize := SR.Size;
  2121. FindClose (SR);
  2122. end;
  2123. end else begin
  2124. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  2125. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2126. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2127. end;
  2128. LinkDebugFile.Data := nil;
  2129. try
  2130. FillChar (DataVarInfo, SizeOf (DataVarInfo), 0);
  2131. FillChar (OptimizeInfo, SizeOf (OptimizeInfo), 0);
  2132. if UseDataVar then
  2133. with DataVarInfo do begin
  2134. VarName := PChar (LowerCase (MasterUnit.DataVar));
  2135. CreateCopy := MasterUnit.DataVarCopy;
  2136. CopyOnlyIfArchived := MasterUnit.DataVarCopyIfArchived;
  2137. end;
  2138. with OptimizeInfo do begin
  2139. RemoveUnused := MasterUnit.RemoveUnusedSections;
  2140. OptimizeNOPs := MasterUnit.OptimizeNOPs;
  2141. OptimizeReturns := MasterUnit.OptimizeReturns;
  2142. OptimizeBranches := MasterUnit.OptimizeBranches;
  2143. OptimizeMoves := MasterUnit.OptimizeMoves;
  2144. OptimizeTests := MasterUnit.OptimizeTests;
  2145. OptimizeCalcs := MasterUnit.OptimizeCalculations;
  2146. CutRanges := MasterUnit.CutUnusedRanges;
  2147. ReorderSections := MasterUnit.ReorderSections;
  2148. MergeConstants := MasterUnit.MergeConstants;
  2149. end;
  2150. OperationSuccessful := LinkLibLinkFiles (ObjectFileNames, ArchiveFileNames, LinkLibError, LinkLibGetOutputFile, nil, False, ProjectTarget = ptFlashOS, ProjectTarget = ptFargo, DataVarInfo, OptimizeInfo, not InitBSS) = 0;
  2151. if OperationSuccessful and (not OperationCancelled) then begin
  2152. if Pack and (ssPack in SpecialSupport) then begin
  2153. CompStartFile;
  2154. CompSetMessage ('Compressing');
  2155. end;
  2156. for CurCalcDest := FirstCalcDest to LastCalcDest do
  2157. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2158. if OperationSuccessful and (not OperationCancelled) then begin
  2159. Include (CalcDests, CurCalcDest);
  2160. HandleContents (ProjectFile, FolderName, VarName, DataFolderName, DataVarName, Pack and (ssPack in SpecialSupport) and (CurCalcDest <> cdTI92), PackVar, CurCalcDest);
  2161. end;
  2162. if Assigned (LinkDebugFile.Data) then begin
  2163. if OperationSuccessful and (not OperationCancelled) then begin
  2164. HandleDebugContents (ProjectFile);
  2165. end;
  2166. end;
  2167. end;
  2168. finally
  2169. for CurCalcDest := FirstCalcDest to LastCalcDest do begin
  2170. if Assigned (LinkOutputFiles[CurCalcDest,frMain].Data) then
  2171. LinkOutputFiles[CurCalcDest,frMain].Data.Free;
  2172. if Assigned (LinkOutputFiles[CurCalcDest,frData].Data) then
  2173. LinkOutputFiles[CurCalcDest,frData].Data.Free;
  2174. LinkOutputFiles[CurCalcDest,frMain].Data := nil;
  2175. LinkOutputFiles[CurCalcDest,frData].Data := nil;
  2176. if Assigned (LinkDebugFile.Data) then
  2177. LinkDebugFile.Data.Free;
  2178. LinkDebugFile.Data := nil;
  2179. end;
  2180. end;
  2181. end;
  2182. except
  2183. if Assigned (ArchiveFileNames) then
  2184. FreeMem (ArchiveFileNames);
  2185. if Assigned (ObjectFileNames) then
  2186. FreeMem (ObjectFileNames);
  2187. FileNameList.Free;
  2188. end;
  2189. if OperationSuccessful and (not OperationCancelled) and Pack and (ssPack in SpecialSupport) then
  2190. CreatePackStarter (ProjectFile, 'PStarter.o', FolderName, VarName, PackVar, CalcDests - [cdTI92]);
  2191. if OperationSuccessful and (not OperationCancelled) and (Length (PostBuildProcessFile) > 0) then begin
  2192. CompStartFile;
  2193. CompSetMessage ('Calling User-Defined Program');
  2194. MainConsole.Title := 'User-Defined Program';
  2195. S1 := PostBuildProcessFile;
  2196. P := Pos ('($TI89FILE)', UpperCase (S1));
  2197. if P > 0 then begin
  2198. Delete (S1, P, Length ('($TI89FILE)'));
  2199. if cdTI89 in CalcDests then
  2200. Insert (MainFiles [cdTI89], S1, P);
  2201. end;
  2202. P := Pos ('($TI92PLUSFILE)', UpperCase (S1));
  2203. if P > 0 then begin
  2204. Delete (S1, P, Length ('($TI92PLUSFILE)'));
  2205. if cdTI92Plus in CalcDests then
  2206. Insert (MainFiles [cdTI92Plus], S1, P);
  2207. end;
  2208. P := Pos ('($V200FILE)', UpperCase (S1));
  2209. if P > 0 then begin
  2210. Delete (S1, P, Length ('($V200FILE)'));
  2211. if cdV200 in CalcDests then
  2212. Insert (MainFiles [cdV200], S1, P);
  2213. end;
  2214. P := Pos ('($TI92FILE)', UpperCase (S1));
  2215. if P > 0 then begin
  2216. Delete (S1, P, Length ('($TI92FILE)'));
  2217. if cdTI92 in CalcDests then
  2218. Insert (MainFiles [cdTI92], S1, P);
  2219. end;
  2220. try
  2221. MainConsole.StartProcess ('', S1, '');
  2222. WaitForMainConsole ('User-Defined');
  2223. except
  2224. ShowDefaultMessageBox ('Could not start the user-defined program.', 'Error', mtProgramError);
  2225. OperationSuccessful := False;
  2226. end;
  2227. UpdateProgramOutput;
  2228. end;
  2229. if not OperationSuccessful then
  2230. ProgSize := 0;
  2231. CompUpdate;
  2232. try
  2233. if FileExists (Temp + 'TEMPPROG.PCK') then
  2234. DeleteFile (Temp + 'TEMPPROG.PCK');
  2235. if OperationSuccessful and (not OperationCancelled) and DeleteAssemblyFiles then
  2236. with SourceFiles do
  2237. for I := 0 to Count - 1 do
  2238. with TSourceFile (Items [I]) do
  2239. if InProject and (Items [I] is TCSourceFile) then
  2240. if FileExists (ChangeFileExt (FileName, '.s')) then
  2241. DeleteFile (ChangeFileExt (FileName, '.s'));
  2242. if OperationSuccessful and (not OperationCancelled) and DeleteObjectFiles then
  2243. with SourceFiles do
  2244. for I := 0 to Count - 1 do
  2245. with TSourceFile (Items [I]) do
  2246. if InProject and Compilable then begin
  2247. Invalidate;
  2248. if FileExists (ChangeFileExt (FileName, '.o')) then
  2249. DeleteFile (ChangeFileExt (FileName, '.o'));
  2250. end;
  2251. except end;
  2252. UpdateErrorWindow;
  2253. ShowErrors;
  2254. CompUpdate;
  2255. if OperationSuccessful and (not OperationCancelled) then begin
  2256. Invalidated := False;
  2257. CompUpdate;
  2258. end;
  2259. end else
  2260. ShowDefaultMessageBox ('Linker not loaded.', 'Error', mtProgramError);
  2261. end;
  2262. end;
  2263. procedure TMainForm.FileOpenProject(Sender: TObject);
  2264. begin
  2265. if OpenProjectDlg.Execute then begin
  2266. if LowerCase (ExtractFileExt (OpenProjectDlg.FileName)) = LowerCase (ProjectFileExt) then
  2267. FileOpen (ExpandFileName (OpenProjectDlg.FileName))
  2268. else
  2269. AddSourceFile (OpenProjectDlg.FileName, True);
  2270. end else
  2271. Abort;
  2272. end;
  2273. procedure TMainForm.FileSaveAll(Sender: TObject);
  2274. begin
  2275. FileSave;
  2276. end;
  2277. procedure TMainForm.FileSaveProjectAs(Sender: TObject);
  2278. begin
  2279. SaveProjectDlg.FileName := ProjectFile;
  2280. if SaveProjectDlg.Execute then
  2281. FileSaveAs (ExpandFileName (SaveProjectDlg.FileName))
  2282. else
  2283. Abort;
  2284. end;
  2285. procedure TMainForm.EditorKeyDown(Sender: TObject; var Key: Word;
  2286. Shift: TShiftState);
  2287. var
  2288. I: Integer;
  2289. S: string;
  2290. begin
  2291. if Key = vk_F1 then
  2292. if Sender is TMemoComponent then
  2293. with Sender as TMemoComponent do begin
  2294. S := '';
  2295. for I := Selection.RStart - 1 downto 1 do begin
  2296. if Text [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$', '#'] then
  2297. S := Text [I] + S
  2298. else
  2299. Break;
  2300. end;
  2301. for I := Selection.RStart to TextLength do begin
  2302. if Text [I] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$', '#'] then
  2303. S := S + Text [I]
  2304. else
  2305. Break;
  2306. end;
  2307. if S <> '' then begin
  2308. with SourceFiles do
  2309. for I := 0 to Count - 1 do
  2310. with Items [I] as TSourceFile do
  2311. if Assigned (ParentForm) then
  2312. ParentForm.WindowState := wsMinimized;
  2313. Application.ProcessMessages;
  2314. DocFile.KeywordLookup (S);
  2315. end;
  2316. end;
  2317. end;
  2318. procedure TMainForm.ProjectBuild(Sender: TObject);
  2319. var
  2320. I: Integer;
  2321. begin
  2322. if not Compiling then begin
  2323. if AutoSave then
  2324. FileSave
  2325. else
  2326. with SourceFiles do
  2327. for I := 0 to Count - 1 do
  2328. with Items [I] as TSourceFile do
  2329. if not InProject then
  2330. Save;
  2331. OperationSuccessful := False;
  2332. if ProjectFile = '' then
  2333. ShowDefaultMessageBox ('You need to save your project before you can create executable files.', 'Project not Saved', mtProgramError)
  2334. else begin
  2335. BeginCompilation;
  2336. RecompileFiles;
  2337. CompileProject;
  2338. Application.ProcessMessages;
  2339. if OperationSuccessful and not OperationCancelled then
  2340. MakeFile;
  2341. EndCompilation;
  2342. DisplayFolderMessage;
  2343. end;
  2344. end;
  2345. end;
  2346. procedure TMainForm.ProjectTreeKeyDown(Sender: TObject; var Key: Word;
  2347. Shift: TShiftState);
  2348. begin
  2349. if (Key = vk_Delete) and not ProjectTree.IsEditing then
  2350. TreeItemRemove (Sender);
  2351. end;
  2352. procedure TMainForm.ProjectTreeMouseUp(Sender: TObject;
  2353. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2354. begin
  2355. if Button = mbRight then
  2356. with ProjectTree do
  2357. if Assigned (Selected) then begin
  2358. if Assigned (Selected.Data) then begin
  2359. if TObject (Selected.Data) is TSourceFile then begin
  2360. with TSourceFile (Selected.Data) do begin
  2361. ActionTreeItemSave.Enabled := TSourceFile (Selected.Data) is TTextSourceFile;
  2362. ActionTreeItemSaveAs.Enabled := True;
  2363. ActionTreeItemCompile.Enabled := Compilable;
  2364. end;
  2365. with Mouse.CursorPos do
  2366. SourceFilePopup.Popup (X, Y);
  2367. end else if TObject (Selected.Data) is TFolder then begin
  2368. with Mouse.CursorPos do
  2369. FolderPopup.Popup (X, Y);
  2370. end;
  2371. end else if Assigned (Selected.Parent) then begin
  2372. with Mouse.CursorPos do
  2373. CategoryPopup.Popup (X, Y);
  2374. end;
  2375. end;
  2376. end;
  2377. procedure TMainForm.ProjectTreeEdited(Sender: TObject; Node: TTreeNode;
  2378. var S: String);
  2379. var
  2380. I: Integer;
  2381. HasFolder,
  2382. NameConflict: Boolean;
  2383. begin
  2384. if Node = TopNode then begin
  2385. if Length (S) <= 0 then
  2386. S := 'Project1'
  2387. else begin
  2388. HasFolder := False;
  2389. for I := Length (S) downto 1 do begin
  2390. if S [I] = '\' then begin
  2391. if HasFolder then
  2392. Delete (S, I, 1)
  2393. else
  2394. HasFolder := True;
  2395. end else if (not (IsCharAlphaNumeric (S [I]) or (S [I] in ['A'..'Z', 'a'..'z', '0'..'9']))) then
  2396. Delete (S, I, 1);
  2397. end;
  2398. if Length (S) <= 0 then
  2399. S := 'Project1'
  2400. else if not (IsCharAlpha (S [1]) or (S [1] in ['A'..'Z', 'a'..'z', '\'])) then
  2401. S := 'X' + S;
  2402. I := Pos ('\', S);
  2403. if I > 0 then begin
  2404. while I - 1 > MaxNameLength do begin
  2405. Delete (S, I - 1, 1);
  2406. Dec (I);
  2407. end;
  2408. while Length (S) - I > MaxNameLength do
  2409. Delete (S, Length (S), 1);
  2410. if I + 1 > Length (S) then
  2411. S := S + 'Project1'
  2412. else if I = 1 then
  2413. Delete (S, 1, 1)
  2414. else if not (IsCharAlpha (S [I + 1]) or (S [I + 1] in ['A'..'Z', 'a'..'z'])) then
  2415. Insert ('X', S, I + 1);
  2416. end else
  2417. S := Copy (S, 1, MaxNameLength);
  2418. end;
  2419. Modify;
  2420. end else begin
  2421. if Assigned (Node.Data) then begin
  2422. if (TObject (Node.Data) is TSourceFile) then begin
  2423. if S = '' then
  2424. S := 'File1';
  2425. NameConflict := False;
  2426. if TSourceFile(Node.Data).Compilable then
  2427. with SourceFiles do
  2428. for I := 0 to Count - 1 do
  2429. if Items [I] <> Node.Data then
  2430. with Items [I] as TSourceFile do
  2431. if Compilable and (LowerCase (SourceName) = LowerCase (S)) and (WithoutBackslash (FolderPath) = WithoutBackslash (TSourceFile(Node.Data).FolderPath)) then begin
  2432. NameConflict := True;
  2433. Break;
  2434. end;
  2435. if not NameConflict then try
  2436. if Assigned (Node.Data) then
  2437. TSourceFile(Node.Data).SourceName := S;
  2438. Modify;
  2439. Exit;
  2440. except end;
  2441. S := Node.Text;
  2442. ShowDefaultMessageBox ('The name you chose conflicts with that of another file.', 'Error', mtProgramError)
  2443. end else begin
  2444. S := StringReplace (S, ' ', '', [rfReplaceAll]);
  2445. if Length (S) <= 0 then
  2446. S := Node.Text;
  2447. RecompileFiles;
  2448. end;
  2449. end;
  2450. end;
  2451. end;
  2452. procedure TMainForm.SetProjectFile(const Value: string);
  2453. var
  2454. S: string;
  2455. B: Boolean;
  2456. begin
  2457. FProjectFile := Value;
  2458. MasterUnit.ProjectFileName := Value;
  2459. if Value = '' then
  2460. Caption := OriginalCaption
  2461. else
  2462. Caption := OriginalCaption + ' - ' + WithoutExt (ExtractFileName (Value));
  2463. Application.Title := Caption;
  2464. if TopNode.Text = 'Project1' then begin
  2465. B := Modified;
  2466. S := WithoutExt (ExtractFileName (Value));
  2467. ProjectTreeEdited (ProjectTree, TopNode, S);
  2468. TopNode.Text := S;
  2469. Modified := B;
  2470. end;
  2471. S := ExtractFilePath (Value);
  2472. OpenProjectDlg.InitialDir := WithoutBackslash (S);
  2473. OpenProjectDlg.FileName := Value;
  2474. SaveProjectDlg.InitialDir := WithoutBackslash (S);
  2475. SaveProjectDlg.FileName := Value;
  2476. AddFileDlg.InitialDir := S;
  2477. end;
  2478. function TMainForm.AddSourceFile(const FN: string; OpenOnly: Boolean = False; SourceFileClass: TSourceFileClass = nil; Folder: TFolder = nil): TSourceFile;
  2479. var
  2480. F: TForm;
  2481. S: string;
  2482. O: TOpenFileStatusForm;
  2483. begin
  2484. if Compiling and (not OpenOnly) then
  2485. Result := nil
  2486. else begin
  2487. Result := SourceFiles.FindFile (FN);
  2488. if Assigned (Result) and Result.InProject then begin
  2489. Result := nil;
  2490. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' is already included in the project.', 'File Already Included', mtProgramError);
  2491. end else if OpenOnly and Assigned (Result) then begin
  2492. Result := nil;
  2493. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' has already been opened.', 'File Already Opened', mtProgramError);
  2494. end else if (not OpenOnly) and (LowerCase (ExtractFileExt (FN)) = '.qll') and (Assigned (SourceFiles.FindFileOfTypeInProject (TQuillSourceFile))) then begin
  2495. Result := nil;
  2496. ShowDefaultMessageBox ('There may be only one Quill source file in each project.', 'Quill Error', mtProgramError);
  2497. end else begin
  2498. if not Assigned (Result) then begin
  2499. O := nil;
  2500. try
  2501. if not OpeningProjectNow then begin
  2502. O := TOpenFileStatusForm.Create (Self);
  2503. S := ExtractFileName (FN);
  2504. O.FileNameLabel.Caption := 'Opening File ''' + Copy (S, 1, LastPos ('.', S) - 1) + '''...';
  2505. O.Show;
  2506. O.Update;
  2507. end;
  2508. if not Assigned (SourceFileClass) then
  2509. SourceFileClass := TSourceFile.GetAppropriateClassFromExt (ExtractFileExt (FN));
  2510. Result := SourceFileClass.Create (SourceFiles);
  2511. Result.Folder := Folder;
  2512. Result.LoadFromFile (FN, True);
  2513. Result.OnError := AddError;
  2514. finally
  2515. if Assigned (O) then
  2516. O.Free;
  2517. end;
  2518. if OpenOnly and (not Assigned (Result.Editor)) then begin
  2519. Result.Free;
  2520. Result := nil;
  2521. ShowDefaultMessageBox ('The file ''' + ExtractFileName (FN) + ''' is not a valid file for opening.', 'Invalid File', mtProgramError);
  2522. end;
  2523. end;
  2524. if Assigned (Result) then
  2525. with Result do begin
  2526. ErrorList := Self.ErrorList;
  2527. if OpenOnly then begin
  2528. if not Assigned (ParentForm) then begin
  2529. ParentForm := TSourceFileForm.Create (nil);
  2530. with ParentForm as TSourceFileForm do begin
  2531. Enabled := False;
  2532. SourceFile := Result;
  2533. Show;
  2534. end;
  2535. if Assigned (Editor) then
  2536. with Editor do begin
  2537. Parent := ParentForm;
  2538. Align := alClient;
  2539. Show;
  2540. if Enabled then
  2541. SetFocus;
  2542. end;
  2543. end;
  2544. end else begin
  2545. if Assigned (ParentForm) then begin
  2546. F := ParentForm;
  2547. ParentForm := nil;
  2548. F.Free;
  2549. end;
  2550. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], Result);
  2551. with TreeItem do begin
  2552. ImageIndex := ClassImageIndex;
  2553. SelectedIndex := ImageIndex;
  2554. end;
  2555. end;
  2556. end;
  2557. end;
  2558. if not OpeningProjectNow then
  2559. SortFiles;
  2560. end;
  2561. end;
  2562. procedure TMainForm.ProjectOptions(Sender: TObject);
  2563. begin
  2564. with TProjectOptionsForm.Create (Self) do try
  2565. FlashOSRadioButton.Visible := ssFlashOS in SpecialSupport;
  2566. FargoRadioButton.Visible := ssFargo in SpecialSupport;
  2567. if ProjectTarget = ptArchive then
  2568. ArchiveRadioButton.Checked := True
  2569. else if (ProjectTarget = ptFlashOS) and (FlashOSRadioButton.Visible) then
  2570. FlashOSRadioButton.Checked := True
  2571. else if (ProjectTarget = ptFargo) and (FargoRadioButton.Visible) then
  2572. FargoRadioButton.Checked := True
  2573. else
  2574. ExecutableRadioButton.Checked := True;
  2575. DataVarCheckBox.Checked := UseDataVar;
  2576. DataVarEdit.Text := DataVar;
  2577. if DataVarCopy then begin
  2578. if DataVarCopyIfArchived then
  2579. DataVarCopyIfArchivedRadioButton.Checked := True
  2580. else
  2581. DataVarCopyAlwaysRadioButton.Checked := True;
  2582. end else
  2583. DataVarCopyNeverRadioButton.Checked := True;
  2584. PackCheckBox.Checked := Pack and (ssPack in SpecialSupport);
  2585. PackVarEdit.Text := PackVar;
  2586. GCCSwitchesEdit.Text := GCCSwitches;
  2587. AsSwitchesEdit.Text := AsSwitches;
  2588. AsmSwitchesEdit.Text := AsmSwitches;
  2589. DebugInfoCheckBox.Checked := DebugInfo;
  2590. OptimizeNOPsCheckBox.Checked := OptimizeNOPs;
  2591. OptimizeReturnsCheckBox.Checked := OptimizeReturns;
  2592. OptimizeBranchesCheckBox.Checked := OptimizeBranches;
  2593. OptimizeMovesCheckBox.Checked := OptimizeMoves;
  2594. OptimizeTestsCheckBox.Checked := OptimizeTests;
  2595. OptimizeCalculationsCheckBox.Checked := OptimizeCalculations;
  2596. RemoveUnusedSectionsCheckBox.Checked := RemoveUnusedSections;
  2597. CutUnusedRangesCheckBox.Checked := CutUnusedRanges;
  2598. ReorderSectionsCheckBox.Checked := ReorderSections;
  2599. MergeConstantsCheckBox.Checked := MergeConstants;
  2600. StdLibCheckBox.Checked := StdLib;
  2601. InitBSSCheckBox.Checked := InitBSS;
  2602. OutputBinCheckBox.Checked := OutputBin;
  2603. CommandLineEdit.Text := CommandLine;
  2604. ProcessFileEdit.Text := PostBuildProcessFile;
  2605. InitialLibOptions := PredefinedLibOptions;
  2606. if ShowModal = mrOK then begin
  2607. if ArchiveRadioButton.Checked then
  2608. ProjectTarget := ptArchive
  2609. else if FlashOSRadioButton.Checked then
  2610. ProjectTarget := ptFlashOS
  2611. else if FargoRadioButton.Checked then
  2612. ProjectTarget := ptFargo
  2613. else
  2614. ProjectTarget := ptRegular;
  2615. Pack := PackCheckBox.Checked;
  2616. PackVar := PackVarEdit.Text;
  2617. UseDataVar := DataVarCheckBox.Checked;
  2618. DataVar := DataVarEdit.Text;
  2619. DataVarCopy := False;
  2620. DataVarCopyIfArchived := False;
  2621. if DataVarCopyAlwaysRadioButton.Checked then
  2622. DataVarCopy := True
  2623. else if DataVarCopyIfArchivedRadioButton.Checked then begin
  2624. DataVarCopy := True;
  2625. DataVarCopyIfArchived := True;
  2626. end;
  2627. GCCSwitches := GCCSwitchesEdit.Text;
  2628. AsSwitches := AsSwitchesEdit.Text;
  2629. AsmSwitches := AsmSwitchesEdit.Text;
  2630. DebugInfo := DebugInfoCheckBox.Checked;
  2631. OptimizeNOPs := OptimizeNOPsCheckBox.Checked;
  2632. OptimizeReturns := OptimizeReturnsCheckBox.Checked;
  2633. OptimizeBranches := OptimizeBranchesCheckBox.Checked;
  2634. OptimizeMoves := OptimizeMovesCheckBox.Checked;
  2635. OptimizeTests := OptimizeTestsCheckBox.Checked;
  2636. OptimizeCalculations := OptimizeCalculationsCheckBox.Checked;
  2637. RemoveUnusedSections := RemoveUnusedSectionsCheckBox.Checked;
  2638. CutUnusedRanges := CutUnusedRangesCheckBox.Checked;
  2639. ReorderSections := ReorderSectionsCheckBox.Checked;
  2640. MergeConstants := MergeConstantsCheckBox.Checked;
  2641. StdLib := StdLibCheckBox.Checked;
  2642. InitBSS := InitBSSCheckBox.Checked;
  2643. OutputBin := OutputBinCheckBox.Checked;
  2644. CommandLine := CommandLineEdit.Text;
  2645. PostBuildProcessFile := ProcessFileEdit.Text;
  2646. if Assigned (ProgramOptionsForm) and Assigned (PredefinedLibOptions) then
  2647. with ProgramOptionsForm, PredefinedLibOptions do begin
  2648. CalcDests := [];
  2649. if TI89CheckBox.Checked then
  2650. Include (CalcDests, cdTI89);
  2651. if TI92PlusCheckBox.Checked then
  2652. Include (CalcDests, cdTI92Plus);
  2653. if V200CheckBox.Checked then
  2654. Include (CalcDests, cdV200);
  2655. OptimizeCalcConsts := OptimizeCalcConstsCheckBox.Checked;
  2656. if PreOsRadioButton.Checked then
  2657. KernelFormat := kfCompressedTables
  2658. else if DoorsRadioButton.Checked then
  2659. KernelFormat := kfStandard
  2660. else
  2661. KernelFormat := kfNone;
  2662. UseMinAMS := MinAMSCheckBox.Checked;
  2663. if Length (MinAMSEdit.Text) > 0 then
  2664. MinAMS := MinAMSEdit.Text;
  2665. UnofficialOSSupport := UnofficialOSSupportCheckBox.Checked;
  2666. if RelocKernelRadioButton.Checked then
  2667. RelocFormat := rfKernel
  2668. else if RelocCompressedRadioButton.Checked then
  2669. RelocFormat := rfCompressed
  2670. else if RelocMlinkRadioButton.Checked then
  2671. RelocFormat := rfMlink
  2672. else
  2673. RelocFormat := rfAMS;
  2674. if ROMCallKernelRadioButton.Checked then
  2675. ROMCallFormat := rfKernel
  2676. else if ROMCallCompressedRadioButton.Checked then
  2677. ROMCallFormat := rfCompressed
  2678. else if ROMCallMlinkRadioButton.Checked then
  2679. ROMCallFormat := rfMlink
  2680. else if ROMCallFLineRadioButton.Checked then
  2681. ROMCallFormat := rfFLine
  2682. else
  2683. ROMCallFormat := rfDirect;
  2684. if BSSKernelRadioButton.Checked then
  2685. BSSRefFormat := rfKernel
  2686. else if BSSCompressedRadioButton.Checked then
  2687. BSSRefFormat := rfCompressed
  2688. else if BSSMlinkRadioButton.Checked then
  2689. BSSRefFormat := rfMlink
  2690. else
  2691. BSSRefFormat := rfNone;
  2692. if DataVarKernelRadioButton.Checked then
  2693. DataRefFormat := rfKernel
  2694. else if DataVarCompressedRadioButton.Checked then
  2695. DataRefFormat := rfCompressed
  2696. else if DataVarMlinkRadioButton.Checked then
  2697. DataRefFormat := rfMlink
  2698. else
  2699. DataRefFormat := rfNone;
  2700. UseFLineJumps := RelocFLineJumpsCheckBox.Checked;
  2701. Use4ByteFLineJumps := RelocFLineJumps4ByteCheckBox.Checked;
  2702. OptimizeROMCalls := ROMCallOptimizedCheckBox.Checked;
  2703. UseInternalFLineEmulator := InternalFLineEmulatorCheckBox.Checked;
  2704. UseReturnValue := ReturnValueRadioButton.Checked;
  2705. EnableErrorReturn := EnableErrorReturnCheckBox.Checked;
  2706. SaveScreen := LCDSaveCheckBox.Checked;
  2707. end;
  2708. RecompileFiles;
  2709. if not DebugInfo then
  2710. ClearDebugInfo;
  2711. UpdateDebugSettings;
  2712. Modify;
  2713. end;
  2714. finally
  2715. Free;
  2716. end;
  2717. end;
  2718. procedure TMainForm.FilePreferences(Sender: TObject);
  2719. var
  2720. I: Integer;
  2721. begin
  2722. with TPreferencesForm.Create (Self) do try
  2723. StopCompilationBox.Checked := StopOnErrors;
  2724. JumpToErrorBox.Checked := JumpToError;
  2725. OpenFolderBox.Checked := OpenFolderMessage;
  2726. DeleteAssemblyFilesBox.Checked := DeleteAssemblyFiles;
  2727. DeleteObjectFilesBox.Checked := DeleteObjectFiles;
  2728. {$IFDEF CanSplit}
  2729. SplitFilesCheckBox.Checked := SplitFiles;
  2730. {$ENDIF}
  2731. AutoSaveCheckBox.Checked := AutoSave;
  2732. AutoNewsCheckBox.Checked := AutoNews;
  2733. DeleteErrorsCheckBox.Checked := DeleteErrors;
  2734. AllowImplicitCheckBox.Checked := not AssumeUndefined;
  2735. FlatButtonsCheckBox.Checked := MainToolbar.Flat;
  2736. MenuBitmapsCheckBox.Checked := Assigned (MainMenu.Images);
  2737. case TransferTarget of
  2738. ttVTI:
  2739. VTIBox.Checked := True;
  2740. ttCalc:
  2741. RealCalcBox.Checked := True;
  2742. else
  2743. NoneBox.Checked := True;
  2744. end;
  2745. VTIPathEdit.Text := VTIPath;
  2746. case LinkPort.PortType of
  2747. lpCOM: begin
  2748. case LinkPort.PortNumber of
  2749. 1: PortCOM1Box.Checked := True;
  2750. 2: PortCOM2Box.Checked := True;
  2751. 3: PortCOM3Box.Checked := True;
  2752. 4: PortCOM4Box.Checked := True;
  2753. end;
  2754. end;
  2755. end;
  2756. case LinkCable of
  2757. lcBlack: CableBlackBox.Checked := True;
  2758. lcGray: CableGrayBox.Checked := True;
  2759. end;
  2760. AsmTabSizeEdit.Text := IntToStr (TabSizeAsm);
  2761. CTabSizeEdit.Text := IntToStr (TabSizeC);
  2762. BackColor := EditorColor;
  2763. ColorCheckBox.Checked := BackColor <> clWindow;
  2764. EditorFont.Assign (MasterUnit.EditorFont);
  2765. OnFlyCheckBox.Checked := EditorOnFly;
  2766. DragDropEditCheckBox.Checked := EditorDragDrop;
  2767. RemoveTrailingSpcCheckBox.Checked := EditorRemoveTrSp;
  2768. AutoBlockCheckBox.Checked := AutoBlocks;
  2769. SyntaxC.Assign (MasterUnit.SyntaxC);
  2770. SyntaxAsmGNU.Assign (MasterUnit.SyntaxAsmGNU);
  2771. if ssA68k in SpecialSupport then
  2772. SyntaxAsm.Assign (MasterUnit.SyntaxAsm);
  2773. if ssQuill in SpecialSupport then
  2774. SyntaxQuill.Assign (MasterUnit.SyntaxQuill);
  2775. if ShowModal = mrOK then begin
  2776. Screen.Cursor := crHourGlass;
  2777. StopOnErrors := StopCompilationBox.Checked;
  2778. JumpToError := JumpToErrorBox.Checked;
  2779. OpenFolderMessage := OpenFolderBox.Checked;
  2780. DeleteAssemblyFiles := DeleteAssemblyFilesBox.Checked;
  2781. DeleteObjectFiles := DeleteObjectFilesBox.Checked;
  2782. {$IFDEF CanSplit}
  2783. SplitFiles := SplitFilesCheckBox.Checked;
  2784. {$ENDIF}
  2785. AutoSave := AutoSaveCheckBox.Checked;
  2786. AutoNews := AutoNewsCheckBox.Checked;
  2787. DeleteErrors := DeleteErrorsCheckBox.Checked;
  2788. AssumeUndefined := not AllowImplicitCheckBox.Checked;
  2789. MainToolbar.Flat := FlatButtonsCheckBox.Checked;
  2790. if MainToolbar.Flat then
  2791. MainToolbar.Height := MainToolbar.ButtonHeight + 1
  2792. else
  2793. MainToolbar.Height := MainToolbar.ButtonHeight + 3;
  2794. if MenuBitmapsCheckBox.Checked then
  2795. MainMenu.Images := ToolbarImages
  2796. else
  2797. MainMenu.Images := nil;
  2798. if VTIBox.Checked then
  2799. TransferTarget := ttVTI
  2800. else if RealCalcBox.Checked then
  2801. TransferTarget := ttCalc
  2802. else
  2803. TransferTarget := ttNone;
  2804. VTIPath := VTIPathEdit.Text;
  2805. LinkPort.PortType := lpCOM;
  2806. if PortCOM1Box.Checked then
  2807. LinkPort.PortNumber := 1
  2808. else if PortCOM2Box.Checked then
  2809. LinkPort.PortNumber := 2
  2810. else if PortCOM3Box.Checked then
  2811. LinkPort.PortNumber := 3
  2812. else if PortCOM4Box.Checked then
  2813. LinkPort.PortNumber := 4;
  2814. if CableBlackBox.Checked then
  2815. LinkCable := lcBlack
  2816. else if CableGrayBox.Checked then
  2817. LinkCable := lcGray;
  2818. try
  2819. TabSizeC := StrToInt (CTabSizeEdit.Text);
  2820. except
  2821. TabSizeC := 2;
  2822. end;
  2823. try
  2824. TabSizeAsm := StrToInt (AsmTabSizeEdit.Text);
  2825. except
  2826. TabSizeAsm := 2;
  2827. end;
  2828. if ColorCheckBox.Checked then
  2829. EditorColor := BackColor
  2830. else
  2831. EditorColor := clWindow;
  2832. MasterUnit.EditorFont.Assign (EditorFont);
  2833. EditorOnFly := OnFlyCheckBox.Checked;
  2834. EditorDragDrop := DragDropEditCheckBox.Checked;
  2835. EditorRemoveTrSp := RemoveTrailingSpcCheckBox.Checked;
  2836. AutoBlocks := AutoBlockCheckBox.Checked;
  2837. with SourceFiles do
  2838. for I := 0 to Count - 1 do
  2839. if Items [I] is TTextSourceFile then
  2840. (Items [I] as TTextSourceFile).UpdateEditor;
  2841. if SyntaxTabClicked then begin
  2842. MasterUnit.SyntaxC.Assign (SyntaxC);
  2843. MasterUnit.SyntaxAsmGNU.Assign (SyntaxAsmGNU);
  2844. MasterUnit.SyntaxAsm.Assign (SyntaxAsm);
  2845. MasterUnit.SyntaxQuill.Assign (SyntaxQuill);
  2846. with SourceFiles do
  2847. for I := 0 to Count - 1 do
  2848. if Items [I] is TSourceTextSourceFile then
  2849. (Items [I] as TSourceTextSourceFile).UpdateSyntax;
  2850. end;
  2851. SavePreferences;
  2852. UpdateDebugSettings;
  2853. Screen.Cursor := crDefault;
  2854. end;
  2855. finally
  2856. Free;
  2857. end;
  2858. end;
  2859. procedure TMainForm.LoadPreferences;
  2860. function LookBackForComponent(Stream: TMemoryStream): Integer;
  2861. var
  2862. I: Integer;
  2863. P: PChar;
  2864. begin
  2865. Result := 0;
  2866. with Stream do begin
  2867. P := Memory;
  2868. for I := Size - 3 downto 1 do
  2869. if (P [I] = 'T') and (P [I + 1] = 'P') and (P [I + 2] = 'F') then begin
  2870. Result := I;
  2871. Break;
  2872. end;
  2873. end;
  2874. end;
  2875. var
  2876. I,
  2877. Tmp: Integer;
  2878. L: TStringList;
  2879. Strm: TMemoryStream;
  2880. SyntaxCopy: TSyntaxColoringCopy;
  2881. begin
  2882. with TRegistry.Create do try
  2883. if OpenKeyReadOnly (RegKey) then try
  2884. if ValueExists ('Open File') then
  2885. ProjectFile := ReadString ('Open File');
  2886. if ValueExists ('Recent Files') then begin
  2887. L := TStringList.Create;
  2888. try
  2889. L.CommaText := ReadString ('Recent Files');
  2890. for I := L.Count - 1 downto 0 do
  2891. AddToRecent (L.Strings [I]);
  2892. finally
  2893. L.Free;
  2894. end;
  2895. end;
  2896. if ValueExists ('Stop on Errors') then
  2897. StopOnErrors := ReadBool ('Stop on Errors');
  2898. if ValueExists ('Jump To First Error') then
  2899. JumpToError := ReadBool ('Jump To First Error');
  2900. if ValueExists ('Open Folder Message') then
  2901. OpenFolderMessage := ReadBool ('Open Folder Message');
  2902. if ValueExists ('Delete Assembly Files') then
  2903. DeleteAssemblyFiles := ReadBool ('Delete Assembly Files');
  2904. if ValueExists ('Delete Object Files') then
  2905. DeleteObjectFiles := ReadBool ('Delete Object Files');
  2906. {$IFDEF CanSplit}
  2907. if ValueExists ('Split Files') then
  2908. SplitFiles := ReadBool ('Split Files');
  2909. {$ENDIF}
  2910. if ValueExists ('AutoSave') then
  2911. AutoSave := ReadBool ('AutoSave');
  2912. if ValueExists ('AutoNews') then
  2913. AutoNews := ReadBool ('AutoNews');
  2914. if ValueExists ('Delete Errors') then
  2915. DeleteErrors := ReadBool ('Delete Errors');
  2916. if ValueExists ('Assume Undefined References') then
  2917. AssumeUndefined := ReadBool ('Assume Undefined References');
  2918. if ValueExists ('Flat Buttons') then
  2919. MainToolbar.Flat := ReadBool ('Flat Buttons');
  2920. if MainToolbar.Flat then
  2921. MainToolbar.Height := MainToolbar.ButtonHeight + 1
  2922. else
  2923. MainToolbar.Height := MainToolbar.ButtonHeight + 3;
  2924. if ValueExists ('Menu Bitmaps') then begin
  2925. if ReadBool ('Menu Bitmaps') then
  2926. MainMenu.Images := ToolbarImages
  2927. else
  2928. MainMenu.Images := nil;
  2929. end;
  2930. if ValueExists ('Transfer Target') then
  2931. TransferTarget := TTransferTarget (ReadInteger ('Transfer Target') + 1);
  2932. if ValueExists ('TiEmu Path') then
  2933. VTIPath := ReadString ('TiEmu Path');
  2934. if ValueExists ('Link Port') then
  2935. LinkPort.PortNumber := ReadInteger ('Link Port') and $FF;
  2936. if ValueExists ('Link Cable') then begin
  2937. if ReadInteger ('Link Cable') = 2 then
  2938. LinkCable := lcGray
  2939. else
  2940. LinkCable := lcBlack;
  2941. end;
  2942. if ValueExists ('ASM Tab Size') then
  2943. TabSizeAsm := ReadInteger ('ASM Tab Size');
  2944. if ValueExists ('C Tab Size') then
  2945. TabSizeC := ReadInteger ('C Tab Size');
  2946. if ValueExists ('Editor Background Color') then
  2947. EditorColor := ReadInteger ('Editor Background Color');
  2948. if ValueExists ('Editor Font') then
  2949. EditorFont.Name := ReadString ('Editor Font');
  2950. if ValueExists ('Editor Font Style Bold') then begin
  2951. EditorFont.Style := [];
  2952. if ReadBool ('Editor Font Style Bold') then
  2953. EditorFont.Style := EditorFont.Style + [fsBold];
  2954. if ReadBool ('Editor Font Style Italic') then
  2955. EditorFont.Style := EditorFont.Style + [fsItalic];
  2956. if ReadBool ('Editor Font Style Underline') then
  2957. EditorFont.Style := EditorFont.Style + [fsUnderline];
  2958. if ReadBool ('Editor Font Style StrikeOut') then
  2959. EditorFont.Style := EditorFont.Style + [fsStrikeOut];
  2960. end;
  2961. if ValueExists ('Editor Font Size') then
  2962. EditorFont.Size := ReadInteger ('Editor Font Size');
  2963. if ValueExists ('Editor Font Color') then
  2964. EditorFont.Color := ReadInteger ('Editor Font Color');
  2965. if ValueExists ('Editor Font Pitch') then
  2966. EditorFont.Pitch := TFontPitch (ReadInteger ('Editor Font Pitch'));
  2967. if ValueExists ('Editor Split On Fly') then
  2968. EditorOnFly := ReadBool ('Editor Split On Fly');
  2969. if ValueExists ('Editor Drag and Drop') then
  2970. EditorDragDrop := ReadBool ('Editor Drag and Drop');
  2971. if ValueExists ('Editor Remove Trailing Spaces') then
  2972. EditorRemoveTrSp := ReadBool ('Editor Remove Trailing Spaces');
  2973. if ValueExists ('AutoBlocks') then
  2974. AutoBlocks := ReadBool ('AutoBlocks');
  2975. if ValueExists ('Tree Width') then
  2976. ProjectTree.Width := ReadInteger ('Tree Width');
  2977. if ValueExists ('Error Window Height') then
  2978. ErrWinPanel.Height := ReadInteger ('Error Window Height');
  2979. if ValueExists ('Error List Message') then
  2980. ErrorList.Columns[0].Width := ReadInteger ('Error List Message');
  2981. if ValueExists ('Error List File') then
  2982. ErrorList.Columns[1].Width := ReadInteger ('Error List File');
  2983. if ValueExists ('Error List Function') then
  2984. ErrorList.Columns[2].Width := ReadInteger ('Error List Function');
  2985. if ValueExists ('Last News Update') then
  2986. LastNewsDate := ReadInteger ('Last News Update');
  2987. if ValueExists ('Proxy Name') then
  2988. ProxyName := ReadString ('Proxy Name');
  2989. if ValueExists ('Proxy Port') then
  2990. ProxyPort := ReadInteger ('Proxy Port');
  2991. Strm := TMemoryStream.Create;
  2992. if ValueExists ('Editor C Syntax Coloring') then try
  2993. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  2994. try
  2995. SyntaxCopy.Assign (SyntaxC);
  2996. Strm.SetSize (GetDataSize ('Editor C Syntax Coloring'));
  2997. if Strm.Size > 0 then begin
  2998. ReadBinaryData ('Editor C Syntax Coloring', Strm.Memory^, Strm.Size);
  2999. Strm.Position := LookBackForComponent (Strm);
  3000. Strm.ReadComponent (SyntaxCopy);
  3001. SyntaxC.Assign (SyntaxCopy);
  3002. end;
  3003. finally
  3004. SyntaxCopy.Free;
  3005. end;
  3006. except end;
  3007. if ValueExists ('Editor GNU ASM Syntax Coloring') then try
  3008. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3009. try
  3010. SyntaxCopy.Assign (SyntaxAsmGNU);
  3011. Strm.SetSize (GetDataSize ('Editor GNU ASM Syntax Coloring'));
  3012. if Strm.Size > 0 then begin
  3013. ReadBinaryData ('Editor GNU ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3014. Strm.Position := LookBackForComponent (Strm);
  3015. Strm.ReadComponent (SyntaxCopy);
  3016. SyntaxAsmGNU.Assign (SyntaxCopy);
  3017. end;
  3018. finally
  3019. SyntaxCopy.Free;
  3020. end;
  3021. except end;
  3022. if (ssA68k in SpecialSupport) and ValueExists ('Editor ASM Syntax Coloring') then try
  3023. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3024. try
  3025. SyntaxCopy.Assign (SyntaxAsm);
  3026. Strm.SetSize (GetDataSize ('Editor ASM Syntax Coloring'));
  3027. if Strm.Size > 0 then begin
  3028. ReadBinaryData ('Editor ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3029. Strm.Position := LookBackForComponent (Strm);
  3030. Strm.ReadComponent (SyntaxCopy);
  3031. SyntaxAsm.Assign (SyntaxCopy);
  3032. end;
  3033. finally
  3034. SyntaxCopy.Free;
  3035. end;
  3036. except end;
  3037. if (ssQuill in SpecialSupport) and ValueExists ('Editor Quill Syntax Coloring') then try
  3038. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3039. try
  3040. SyntaxCopy.Assign (SyntaxQuill);
  3041. Strm.SetSize (GetDataSize ('Editor Quill Syntax Coloring'));
  3042. if Strm.Size > 0 then begin
  3043. ReadBinaryData ('Editor Quill Syntax Coloring', Strm.Memory^, Strm.Size);
  3044. Strm.Position := LookBackForComponent (Strm);
  3045. Strm.ReadComponent (SyntaxCopy);
  3046. SyntaxQuill.Assign (SyntaxCopy);
  3047. end;
  3048. finally
  3049. SyntaxCopy.Free;
  3050. end;
  3051. except end;
  3052. Strm.Free;
  3053. if ValueExists ('Tools Count') then begin
  3054. Tmp := ReadInteger ('Tools Count');
  3055. ToolsList.Clear;
  3056. for I := 1 to Tmp do
  3057. if OpenKeyReadOnly (RegKey + '\Tool ' + IntToStr (I)) then try
  3058. ToolsLine.Visible := True;
  3059. AddTool (ReadString ('Title'), ReadString ('Command Line'), ReadString ('Working Directory'), TWindowState (ReadInteger ('Window State')));
  3060. except end;
  3061. end;
  3062. except end;
  3063. finally
  3064. Free;
  3065. SplitterMoved (Self);
  3066. end;
  3067. with SourceFiles do
  3068. for I := 0 to Count - 1 do begin
  3069. if Items [I] is TTextSourceFile then
  3070. (Items [I] as TTextSourceFile).UpdateEditor;
  3071. if Items [I] is TSourceTextSourceFile then
  3072. (Items [I] as TSourceTextSourceFile).UpdateSyntax;
  3073. end;
  3074. UpdateDebugSettings;
  3075. end;
  3076. procedure TMainForm.SavePreferences;
  3077. var
  3078. I: Integer;
  3079. Strm: TMemoryStream;
  3080. SyntaxCopy: TSyntaxColoringCopy;
  3081. begin
  3082. with TRegistry.Create do try
  3083. if OpenKey (RegKey, True) then try
  3084. WriteString ('Open File', ProjectFile);
  3085. WriteString ('Recent Files', RecentFiles.CommaText);
  3086. WriteBool ('Stop on Errors', StopOnErrors);
  3087. WriteBool ('Jump To First Error', JumpToError);
  3088. WriteBool ('Open Folder Message', OpenFolderMessage);
  3089. WriteBool ('Delete Assembly Files', DeleteAssemblyFiles);
  3090. WriteBool ('Delete Object Files', DeleteObjectFiles);
  3091. {$IFDEF CanSplit}
  3092. WriteBool ('Split Files', SplitFiles);
  3093. {$ENDIF}
  3094. WriteBool ('AutoSave', AutoSave);
  3095. WriteBool ('AutoNews', AutoNews);
  3096. WriteBool ('Delete Errors', DeleteErrors);
  3097. WriteBool ('Assume Undefined References', AssumeUndefined);
  3098. WriteBool ('Flat Buttons', MainToolbar.Flat);
  3099. WriteBool ('Menu Bitmaps', Assigned (MainMenu.Images));
  3100. WriteInteger ('Transfer Target', Integer (TransferTarget) - 1);
  3101. WriteString ('TiEmu Path', VTIPath);
  3102. WriteInteger ('Link Port', LinkPort.PortNumber);
  3103. case LinkCable of
  3104. lcBlack: WriteInteger ('Link Cable', 1);
  3105. lcGray: WriteInteger ('Link Cable', 2);
  3106. end;
  3107. WriteInteger ('ASM Tab Size', TabSizeAsm);
  3108. WriteInteger ('C Tab Size', TabSizeC);
  3109. WriteInteger ('Editor Background Color', EditorColor);
  3110. WriteString ('Editor Font', EditorFont.Name);
  3111. WriteBool ('Editor Font Style Bold', fsBold in EditorFont.Style);
  3112. WriteBool ('Editor Font Style Italic', fsItalic in EditorFont.Style);
  3113. WriteBool ('Editor Font Style Underline', fsUnderline in EditorFont.Style);
  3114. WriteBool ('Editor Font Style StrikeOut', fsStrikeOut in EditorFont.Style);
  3115. WriteInteger ('Editor Font Size', EditorFont.Size);
  3116. WriteInteger ('Editor Font Color', EditorFont.Color);
  3117. WriteInteger ('Editor Font Pitch', Integer (EditorFont.Pitch));
  3118. WriteBool ('Editor Split On Fly', EditorOnFly);
  3119. WriteBool ('Editor Drag and Drop', EditorDragDrop);
  3120. WriteBool ('Editor Remove Trailing Spaces', EditorRemoveTrSp);
  3121. WriteBool ('AutoBlocks', AutoBlocks);
  3122. WriteInteger ('Tree Width', ProjectTree.Width);
  3123. WriteInteger ('Error Window Height', ErrWinPanel.Height);
  3124. WriteInteger ('Error List Message', ErrorList.Columns[0].Width);
  3125. WriteInteger ('Error List File', ErrorList.Columns[1].Width);
  3126. WriteInteger ('Error List Function', ErrorList.Columns[2].Width);
  3127. WriteInteger ('Last News Update', LastNewsDate);
  3128. WriteString ('Proxy Name', ProxyName);
  3129. WriteInteger ('Proxy Port', ProxyPort);
  3130. Strm := TMemoryStream.Create;
  3131. try
  3132. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3133. try
  3134. SyntaxCopy.Assign (SyntaxC);
  3135. Strm.WriteComponent (SyntaxCopy);
  3136. WriteBinaryData ('Editor C Syntax Coloring', Strm.Memory^, Strm.Size);
  3137. finally
  3138. SyntaxCopy.Free;
  3139. end;
  3140. Strm.Clear;
  3141. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3142. try
  3143. SyntaxCopy.Assign (SyntaxAsmGNU);
  3144. Strm.WriteComponent (SyntaxCopy);
  3145. WriteBinaryData ('Editor GNU ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3146. finally
  3147. SyntaxCopy.Free;
  3148. end;
  3149. if ssA68k in SpecialSupport then begin
  3150. Strm.Clear;
  3151. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3152. try
  3153. SyntaxCopy.Assign (SyntaxAsm);
  3154. Strm.WriteComponent (SyntaxCopy);
  3155. WriteBinaryData ('Editor ASM Syntax Coloring', Strm.Memory^, Strm.Size);
  3156. finally
  3157. SyntaxCopy.Free;
  3158. end;
  3159. end;
  3160. if ssQuill in SpecialSupport then begin
  3161. Strm.Clear;
  3162. SyntaxCopy := TSyntaxColoringCopy.Create (nil);
  3163. try
  3164. SyntaxCopy.Assign (SyntaxQuill);
  3165. Strm.WriteComponent (SyntaxCopy);
  3166. WriteBinaryData ('Editor Quill Syntax Coloring', Strm.Memory^, Strm.Size);
  3167. finally
  3168. SyntaxCopy.Free;
  3169. end;
  3170. end;
  3171. finally
  3172. Strm.Free;
  3173. end;
  3174. WriteInteger ('Tools Count', ToolsList.Count);
  3175. with ToolsList do
  3176. for I := 0 to Count - 1 do
  3177. with TToolsListItem (Items [I]) do
  3178. if OpenKey (RegKey + '\Tool ' + IntToStr (I + 1), True) then try
  3179. WriteString ('Title', Title);
  3180. WriteString ('Command Line', CommandLine);
  3181. WriteString ('Working Directory', WorkingDir);
  3182. WriteInteger ('Window State', Integer (WindowState));
  3183. except end;
  3184. except end;
  3185. finally
  3186. Free;
  3187. end;
  3188. end;
  3189. procedure TMainForm.CompileProject;
  3190. var
  3191. I: Integer;
  3192. StopIt: Boolean;
  3193. begin
  3194. OperationSuccessful := False;
  3195. OperationCancelled := False;
  3196. StopIt := True;
  3197. with SourceFiles do
  3198. for I := 0 to Count - 1 do
  3199. with Items [I] as TSourceFile do
  3200. if Compilable or (Items [I] is TObjectSourceFile) then begin
  3201. StopIt := False;
  3202. Break;
  3203. end;
  3204. if not StopIt then begin
  3205. OperationSuccessful := True;
  3206. CopyHeaders;
  3207. with SourceFiles do
  3208. for I := 0 to Count - 1 do
  3209. if (OperationSuccessful or not StopOnErrors) and not OperationCancelled then
  3210. with Items [I] as TSourceFile do
  3211. if Compilable and Invalidated then begin
  3212. Compile;
  3213. if not OperationSuccessful then
  3214. StopIt := True;
  3215. Application.ProcessMessages;
  3216. end;
  3217. DeleteHeaders;
  3218. if StopIt then
  3219. OperationSuccessful := False;
  3220. end else
  3221. ShowDefaultMessageBox ('There are no files to compile in the current project.', 'Error', mtProgramError);
  3222. end;
  3223. function TMainForm.GetNewFileName(const FolderPath, Ext: string): string;
  3224. var
  3225. I: Integer;
  3226. begin
  3227. if ProjectFile = '' then
  3228. Result := 'C:\New File'
  3229. else
  3230. Result := WithBackslash (ExtractFilePath (ProjectFile) + FolderPath) + 'New File';
  3231. if FileExists (Result + Ext) or Assigned (SourceFiles.FindFileWithoutExt (Result)) then begin
  3232. I := 2;
  3233. while FileExists (Result + ' ' + IntToStr (I) + Ext) or Assigned (SourceFiles.FindFileWithoutExt (Result + ' ' + IntToStr (I))) do
  3234. Inc (I);
  3235. Result := Result + ' ' + IntToStr (I);
  3236. end;
  3237. Result := Result + Ext;
  3238. end;
  3239. procedure TMainForm.FileNewHeaderFile(Sender: TObject);
  3240. var
  3241. O: THeaderSourceFile;
  3242. begin
  3243. if not Compiling then begin
  3244. O := THeaderSourceFile.Create (SourceFiles);
  3245. with O do begin
  3246. Folder := GetSelectedFolder (THeaderSourceFile);
  3247. FileName := GetNewFileName (FolderPath, '.h');
  3248. OnError := AddError;
  3249. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3250. with TreeItem do begin
  3251. ImageIndex := ClassImageIndex;
  3252. SelectedIndex := ImageIndex;
  3253. end;
  3254. ErrorList := Self.ErrorList;
  3255. if Assigned (TextEditor) then
  3256. with TextEditor do begin
  3257. Hide;
  3258. Parent := EditorPanel;
  3259. Align := alClient;
  3260. OnEnter := EditorEnter;
  3261. OnExit := EditorExit;
  3262. OnKeyDown := EditorKeyDown;
  3263. OnChange := EditorChange;
  3264. OnSelectionChange := EditorChange;
  3265. PopupMenu := EditorPopup;
  3266. end;
  3267. if (Sender = ActionFileNewGNUAsmHeaderFile) or ((Sender is TMenuItem) and (TMenuItem(Sender).Action = ActionFileNewGNUAsmHeaderFile)) then
  3268. Content := '| Header File'#13#10'| Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10
  3269. else if (Sender = ActionFileNewA68kAsmHeaderFile) or ((Sender is TMenuItem) and (TMenuItem(Sender).Action = ActionFileNewA68kAsmHeaderFile)) then
  3270. Content := '; Header File'#13#10'; Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10
  3271. else
  3272. Content := '// Header File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3273. UpdateSyntax;
  3274. if Assigned (TextEditor) then
  3275. TextEditor.ClearUndo;
  3276. Modified := False;
  3277. Invalidate;
  3278. SelectNode (TreeItem);
  3279. TreeItem.EditText;
  3280. end;
  3281. end;
  3282. end;
  3283. procedure TMainForm.FileNewCSourceFile(Sender: TObject);
  3284. const
  3285. CodeStr = '// Place your code here.';
  3286. var
  3287. O: TCSourceFile;
  3288. I,
  3289. P: Integer;
  3290. NewContent: string;
  3291. FirstFile: Boolean;
  3292. begin
  3293. if not Compiling then begin
  3294. FirstFile := not Assigned (SourceFiles.FindFileOfTypeInProject (TCSourceFile));
  3295. O := TCSourceFile.Create (SourceFiles);
  3296. with O do begin
  3297. Folder := GetSelectedFolder (TCSourceFile);
  3298. FileName := GetNewFileName (FolderPath, '.c');
  3299. OnError := AddError;
  3300. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3301. with TreeItem do begin
  3302. ImageIndex := ClassImageIndex;
  3303. SelectedIndex := ImageIndex;
  3304. end;
  3305. ErrorList := Self.ErrorList;
  3306. if Assigned (TextEditor) then
  3307. with TextEditor do begin
  3308. Hide;
  3309. Parent := EditorPanel;
  3310. Align := alClient;
  3311. OnEnter := EditorEnter;
  3312. OnExit := EditorExit;
  3313. OnKeyDown := EditorKeyDown;
  3314. OnChange := EditorChange;
  3315. OnSelectionChange := EditorChange;
  3316. PopupMenu := EditorPopup;
  3317. end;
  3318. NewContent := '// C Source File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3319. case ProjectTarget of
  3320. ptRegular: begin
  3321. if FirstFile then begin
  3322. NewContent := NewContent + #13#10
  3323. + '// Delete or comment out the items you do not need.'#13#10
  3324. + '#define COMMENT_STRING "Place your comment here."'#13#10
  3325. + '#define COMMENT_PROGRAM_NAME "Place your program name here."'#13#10
  3326. + '#define COMMENT_VERSION_STRING "Place your version string here."'#13#10
  3327. + '#define COMMENT_VERSION_NUMBER 0,0,0,0 /* major, minor, revision, subrevision */'#13#10
  3328. + '#define COMMENT_AUTHORS "Place your author name(s) here."'#13#10
  3329. + '#define COMMENT_BW_ICON \'#13#10
  3330. + #9'{0b0000000000000000, \'#13#10;
  3331. for I := 1 to 14 do
  3332. NewContent := NewContent
  3333. + #9' 0b0000000000000000, \'#13#10;
  3334. NewContent := NewContent
  3335. + #9' 0b0000000000000000}'#13#10
  3336. + '#define COMMENT_GRAY_ICON \'#13#10
  3337. + #9'{0b0000000000000000, \'#13#10;
  3338. for I := 1 to 14 do
  3339. NewContent := NewContent
  3340. + #9' 0b0000000000000000, \'#13#10;
  3341. NewContent := NewContent
  3342. + #9' 0b0000000000000000}, \'#13#10
  3343. + #9'{0b0000000000000000, \'#13#10;
  3344. for I := 1 to 14 do
  3345. NewContent := NewContent
  3346. + #9' 0b0000000000000000, \'#13#10;
  3347. NewContent := NewContent
  3348. + #9' 0b0000000000000000}'#13#10;
  3349. end;
  3350. NewContent := NewContent + #13#10'#include <tigcclib.h>'#13#10;
  3351. end;
  3352. ptArchive:
  3353. NewContent := NewContent + #13#10'#define _GENERIC_ARCHIVE'#13#10'#include <tigcclib.h>'#13#10;
  3354. end;
  3355. if FirstFile and (not (ProjectTarget in [ptFlashOS, ptArchive])) then
  3356. NewContent := NewContent + #13#10'// Main Function'#13#10'void _main(void)'#13#10
  3357. + '{'#13#10
  3358. + #9 + CodeStr + #13#10
  3359. + '}'#13#10;
  3360. if Assigned (TextEditor) then
  3361. TextEditor.AllowUndo := False;
  3362. Content := NewContent;
  3363. if Assigned (TextEditor) then begin
  3364. TextEditor.AllowUndo := True;
  3365. P := Pos (CodeStr, TextEditor.Text);
  3366. if P > 0 then
  3367. with TextEditor.Selection do begin
  3368. RStart := P;
  3369. RLength := Length (CodeStr);
  3370. end;
  3371. end;
  3372. Modified := False;
  3373. Invalidate;
  3374. SelectNode (TreeItem);
  3375. TreeItem.EditText;
  3376. end;
  3377. end;
  3378. end;
  3379. procedure TMainForm.FileNewGNUAssemblerSourceFile(Sender: TObject);
  3380. var
  3381. O: TGNUAsmSourceFile;
  3382. begin
  3383. if not Compiling then begin
  3384. O := TGNUAsmSourceFile.Create (SourceFiles);
  3385. with O do begin
  3386. Folder := GetSelectedFolder (TGNUAsmSourceFile);
  3387. FileName := GetNewFileName (FolderPath, '.s');
  3388. OnError := AddError;
  3389. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3390. with TreeItem do begin
  3391. ImageIndex := ClassImageIndex;
  3392. SelectedIndex := ImageIndex;
  3393. end;
  3394. ErrorList := Self.ErrorList;
  3395. if Assigned (TextEditor) then
  3396. with TextEditor do begin
  3397. Hide;
  3398. Parent := EditorPanel;
  3399. Align := alClient;
  3400. OnEnter := EditorEnter;
  3401. OnExit := EditorExit;
  3402. OnKeyDown := EditorKeyDown;
  3403. OnChange := EditorChange;
  3404. OnSelectionChange := EditorChange;
  3405. PopupMenu := EditorPopup;
  3406. end;
  3407. Content := '| Assembly Source File'#13#10'| Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10;
  3408. if Assigned (TextEditor) then
  3409. TextEditor.ClearUndo;
  3410. Modified := False;
  3411. Invalidate;
  3412. SelectNode (TreeItem);
  3413. TreeItem.EditText;
  3414. end;
  3415. end;
  3416. end;
  3417. procedure TMainForm.FileNewAssemblerSourceFile(Sender: TObject);
  3418. var
  3419. O: TAsmSourceFile;
  3420. begin
  3421. if not Compiling then begin
  3422. O := TAsmSourceFile.Create (SourceFiles);
  3423. with O do begin
  3424. Folder := GetSelectedFolder (TAsmSourceFile);
  3425. FileName := GetNewFileName (FolderPath, '.asm');
  3426. OnError := AddError;
  3427. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3428. with TreeItem do begin
  3429. ImageIndex := ClassImageIndex;
  3430. SelectedIndex := ImageIndex;
  3431. end;
  3432. ErrorList := Self.ErrorList;
  3433. if Assigned (TextEditor) then
  3434. with TextEditor do begin
  3435. Hide;
  3436. Parent := EditorPanel;
  3437. Align := alClient;
  3438. OnEnter := EditorEnter;
  3439. OnExit := EditorExit;
  3440. OnKeyDown := EditorKeyDown;
  3441. OnChange := EditorChange;
  3442. OnSelectionChange := EditorChange;
  3443. PopupMenu := EditorPopup;
  3444. end;
  3445. Content := '; Assembly Source File'#13#10'; Created ' + DateToStr (Now) + ', ' + TimeToStr (Now) + #13#10;
  3446. if Assigned (TextEditor) then
  3447. TextEditor.ClearUndo;
  3448. Modified := False;
  3449. Invalidate;
  3450. SelectNode (TreeItem);
  3451. TreeItem.EditText;
  3452. end;
  3453. end;
  3454. end;
  3455. procedure TMainForm.FileNewQuillSourceFile(Sender: TObject);
  3456. var
  3457. O: TQuillSourceFile;
  3458. begin
  3459. if not Compiling then begin
  3460. if Assigned (SourceFiles.FindFileOfTypeInProject (TQuillSourceFile)) then
  3461. ShowDefaultMessageBox ('There may be only one Quill source file in each project.', 'Quill Error', mtProgramError)
  3462. else begin
  3463. O := TQuillSourceFile.Create (SourceFiles);
  3464. with O do begin
  3465. Folder := GetSelectedFolder (TQuillSourceFile);
  3466. FileName := GetNewFileName (FolderPath, '.qll');
  3467. OnError := AddError;
  3468. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3469. with TreeItem do begin
  3470. ImageIndex := ClassImageIndex;
  3471. SelectedIndex := ImageIndex;
  3472. end;
  3473. ErrorList := Self.ErrorList;
  3474. if Assigned (TextEditor) then
  3475. with TextEditor do begin
  3476. Hide;
  3477. Parent := EditorPanel;
  3478. Align := alClient;
  3479. OnEnter := EditorEnter;
  3480. OnExit := EditorExit;
  3481. OnKeyDown := EditorKeyDown;
  3482. OnChange := EditorChange;
  3483. OnSelectionChange := EditorChange;
  3484. PopupMenu := EditorPopup;
  3485. end;
  3486. if FileExists (WithBackslash (TIGCCFolder) + QuillIncludeLocation + 'Template.qll') then
  3487. LoadFromFile (WithBackslash (TIGCCFolder) + QuillIncludeLocation + 'Template.qll')
  3488. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + 'Template.qll') then
  3489. LoadFromFile (WithBackslash (TIGCCFolder) + CIncludeLocation + 'Template.qll')
  3490. else if FileExists (WithBackslash (TIGCCFolder) + GCCLocation + 'Template.qll') then
  3491. LoadFromFile (WithBackslash (TIGCCFolder) + GCCLocation + 'Template.qll');
  3492. Content := '// Quill Source File'#13#10'// Created ' + DateToStr (Now) + '; ' + TimeToStr (Now) + #13#10#13#10 + Content;
  3493. if Assigned (TextEditor) then
  3494. TextEditor.ClearUndo;
  3495. Modified := False;
  3496. Invalidate;
  3497. SelectNode (TreeItem);
  3498. TreeItem.EditText;
  3499. end;
  3500. end;
  3501. end;
  3502. end;
  3503. procedure TMainForm.FileNewTextFile(Sender: TObject);
  3504. var
  3505. O: TNormalTextSourceFile;
  3506. begin
  3507. O := TNormalTextSourceFile.Create (SourceFiles);
  3508. with O do begin
  3509. Folder := GetSelectedFolder (TTextSourceFile);
  3510. FileName := GetNewFileName (FolderPath, '.txt');
  3511. OnError := AddError;
  3512. TreeItem := CreateFileNode (TopNode.Item [ClassTreeIndex], O);
  3513. with TreeItem do begin
  3514. ImageIndex := ClassImageIndex;
  3515. SelectedIndex := ImageIndex;
  3516. end;
  3517. ErrorList := Self.ErrorList;
  3518. if Assigned (TextEditor) then
  3519. with TextEditor do begin
  3520. Hide;
  3521. Parent := EditorPanel;
  3522. Align := alClient;
  3523. OnEnter := EditorEnter;
  3524. OnExit := EditorExit;
  3525. OnKeyDown := EditorKeyDown;
  3526. OnChange := EditorChange;
  3527. OnSelectionChange := EditorChange;
  3528. PopupMenu := EditorPopup;
  3529. end;
  3530. if Assigned (TextEditor) then
  3531. TextEditor.ClearUndo;
  3532. Modified := False;
  3533. SelectNode (TreeItem);
  3534. TreeItem.EditText;
  3535. end;
  3536. end;
  3537. procedure TMainForm.TreeItemSaveAs(Sender: TObject);
  3538. var
  3539. Node: TTreeNode;
  3540. begin
  3541. Node := ProjectTree.Selected;
  3542. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  3543. TSourceFile(Node.Data).SaveAs;
  3544. Modify;
  3545. UpdateStatusBar;
  3546. end;
  3547. end;
  3548. procedure TMainForm.BeginCompilation;
  3549. var
  3550. I: Integer;
  3551. begin
  3552. ClearErrors;
  3553. with SourceFiles do
  3554. for I := 0 to Count - 1 do
  3555. with Items [I] as TSourceFile do
  3556. if not InProject then begin
  3557. RecompileFiles;
  3558. Break;
  3559. end;
  3560. OperationCancelled := False;
  3561. OperationSuccessful := False;
  3562. end;
  3563. procedure TMainForm.EndCompilation;
  3564. begin
  3565. CompStop;
  3566. Application.Restore;
  3567. UpdateErrorWindow;
  3568. ShowErrors;
  3569. end;
  3570. procedure TMainForm.HelpAbout(Sender: TObject);
  3571. begin
  3572. with TAboutForm.Create (Self) do try
  3573. ShowModal;
  3574. finally
  3575. Free;
  3576. end;
  3577. end;
  3578. procedure TMainForm.DisplayHint(Sender: TObject);
  3579. begin
  3580. with StatusBar.Panels do begin
  3581. BeginUpdate;
  3582. with Items [0] do begin
  3583. if Application.Hint = '' then
  3584. Width := 0
  3585. else
  3586. Width := 1000000;
  3587. Text := Application.Hint;
  3588. end;
  3589. EndUpdate;
  3590. end;
  3591. end;
  3592. procedure TMainForm.ShowHideErrors(Sender: TObject);
  3593. begin
  3594. with ActionProjectShowErrors do begin
  3595. if Checked then
  3596. HideErrors
  3597. else
  3598. ShowErrors;
  3599. end;
  3600. end;
  3601. procedure TMainForm.UpdateEditButtons;
  3602. var
  3603. TextSel: Boolean;
  3604. Editor: TMemoComponent;
  3605. begin
  3606. Editor := CurrentEditor;
  3607. if Assigned (Editor) then begin
  3608. TextSel := (Editor.SelLength > 0) and (ActiveControl = Editor);
  3609. ActionEditDelete.Enabled := TextSel;
  3610. ActionEditCut.Enabled := TextSel;
  3611. ActionEditCopy.Enabled := TextSel;
  3612. ActionEditUndo.Enabled := (ActiveControl = Editor) and Editor.CanUndo;
  3613. ActionEditRedo.Enabled := (ActiveControl = Editor) and Editor.CanRedo;
  3614. end;
  3615. end;
  3616. procedure TMainForm.RecompileFiles;
  3617. var
  3618. I: Integer;
  3619. begin
  3620. with SourceFiles do
  3621. for I := 0 to Count - 1 do
  3622. with Items [I] as TSourceFile do
  3623. if Items [I] is THeaderSourceFile then
  3624. Invalidated := False
  3625. else if Compilable then
  3626. Invalidate;
  3627. end;
  3628. procedure TMainForm.FindString(Sender: TObject; AllFiles: Boolean);
  3629. var
  3630. P: Integer;
  3631. S,
  3632. T: string;
  3633. Valid: Boolean;
  3634. FPos: Integer;
  3635. Editor: TMemoComponent;
  3636. NewSelection: TTreeNode;
  3637. FirstFile: Boolean;
  3638. begin
  3639. NewSelection := ProjectTree.Selected;
  3640. if not Assigned (NewSelection) then
  3641. NewSelection := TopNode;
  3642. Valid := False;
  3643. FirstFile := True;
  3644. repeat
  3645. if Assigned (NewSelection.Data) and (TObject (NewSelection.Data) is TSourceFile) then
  3646. if TSourceFile (NewSelection.Data) is TTextSourceFile then begin
  3647. Editor := TTextSourceFile(NewSelection.Data).TextEditor;
  3648. if Assigned (Editor) then begin
  3649. with Sender as TFindDialog do begin
  3650. if (frFindNext in Options) and FirstFile then
  3651. P := Editor.Selection.REnd
  3652. else
  3653. if frDown in Options then
  3654. P := 0
  3655. else
  3656. P := Length (Editor.Text);
  3657. repeat
  3658. if frDown in Options then
  3659. T := Copy (Editor.Text, P + 1, Length (Editor.Text))
  3660. else
  3661. T := Copy (Editor.Text, 1, P - 1);
  3662. if frMatchCase in Options then
  3663. S := FindText
  3664. else begin
  3665. S := UpperCase (FindText);
  3666. T := UpperCase (T);
  3667. end;
  3668. if frDown in Options then
  3669. FPos := Pos (S, T)
  3670. else
  3671. FPos := LastPos (S, T);
  3672. if FPos > 0 then begin
  3673. Valid := True;
  3674. if frWholeWord in Options then begin
  3675. if ((FPos > 1) and (T <> '') and (T [FPos - 1] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  3676. Valid := False;
  3677. if ((FPos + Length (S) < Length (T)) and (T <> '') and (T [FPos + Length (S)] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  3678. Valid := False;
  3679. end;
  3680. if not (frDown in Options) then
  3681. P := 0;
  3682. if not Valid then
  3683. Inc (P, FPos);
  3684. end;
  3685. until Valid or (FPos <= 0);
  3686. if Valid then begin
  3687. SelectNode (NewSelection);
  3688. with Editor do begin
  3689. with Selection do begin
  3690. DoChanging;
  3691. RStart := P + FPos;
  3692. RLength := Length (S);
  3693. DoChange;
  3694. ScrollInView (2);
  3695. end;
  3696. end;
  3697. end;
  3698. end;
  3699. end;
  3700. end;
  3701. if AllFiles and (not Valid) then begin
  3702. if frDown in (Sender as TFindDialog).Options then begin
  3703. NewSelection := NewSelection.GetNext;
  3704. if not Assigned (NewSelection) then
  3705. NewSelection := TopNode;
  3706. end else begin
  3707. NewSelection := NewSelection.GetPrev;
  3708. if not Assigned (NewSelection) then begin
  3709. NewSelection := TopNode;
  3710. while NewSelection.Count > 0 do
  3711. NewSelection := NewSelection.Item [NewSelection.Count - 1];
  3712. end;
  3713. end;
  3714. FirstFile := False;
  3715. end;
  3716. until (not AllFiles) or Valid or (NewSelection = ProjectTree.Selected);
  3717. if not Valid then
  3718. Abort;
  3719. end;
  3720. procedure TMainForm.ReplaceDlgReplace(Sender: TObject);
  3721. var
  3722. Editor: TMemoComponent;
  3723. begin
  3724. Editor := CurrentEditor;
  3725. if Assigned (Editor) then
  3726. with Sender as TReplaceDialog do
  3727. if (frReplace in Options) or (frReplaceAll in Options) then
  3728. repeat
  3729. if UpperCase (Editor.Selection.Text) = UpperCase (FindText) then
  3730. Editor.Selection.Text := ReplaceText;
  3731. Options := Options + [frFindNext];
  3732. FindString (Sender, False);
  3733. until not (frReplaceAll in Options);
  3734. end;
  3735. procedure TMainForm.FindText(Sender: TObject);
  3736. begin
  3737. try
  3738. if Assigned (CurrentEditor) then
  3739. if CurrentEditor.Selection.RLength > 0 then
  3740. FindDlg.FindText := CurrentEditor.Selection.Text;
  3741. FindDlg.Execute;
  3742. except end;
  3743. end;
  3744. procedure TMainForm.ReplaceText(Sender: TObject);
  3745. begin
  3746. try
  3747. if Assigned (CurrentEditor) then
  3748. if CurrentEditor.Selection.RLength > 0 then begin
  3749. ReplaceDlg.FindText := CurrentEditor.Selection.Text;
  3750. ReplaceDlg.ReplaceText := ReplaceDlg.FindText;
  3751. end;
  3752. ReplaceDlg.Execute;
  3753. except end;
  3754. end;
  3755. procedure TMainForm.FindOpenFile(Sender: TObject);
  3756. var
  3757. I: Integer;
  3758. S: string;
  3759. QuotesInLine: Boolean;
  3760. SelectedNode: TTreeNode;
  3761. SourceFile: TSourceFile;
  3762. Editor: TMemoComponent;
  3763. begin
  3764. Editor := CurrentEditor;
  3765. if Assigned (Editor) then begin
  3766. QuotesInLine := Pos ('"', Editor.Lines [Editor.Selection.StartRowCol.Row - 1]) > 0;
  3767. S := '';
  3768. for I := Editor.Selection.RStart - 1 downto 1 do begin
  3769. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  3770. Break;
  3771. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  3772. S := Editor.Text [I] + S
  3773. else
  3774. Break;
  3775. end;
  3776. for I := Editor.Selection.RStart to Length (Editor.Text) do begin
  3777. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  3778. Break;
  3779. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  3780. S := S + Editor.Text [I]
  3781. else
  3782. Break;
  3783. end;
  3784. S := Trim (S);
  3785. if Length (S) > 0 then begin
  3786. SourceFile := SourceFiles.FindFileNameOnly (S);
  3787. if Assigned (SourceFile) then
  3788. SourceFile.Edit
  3789. else begin
  3790. SelectedNode := ProjectTree.Selected;
  3791. if Assigned (SelectedNode) and (TObject (SelectedNode.Data) is TSourceFile) then
  3792. SourceFile := TSourceFile (SelectedNode.Data);
  3793. if FileExists (ExpandFileName (S)) then
  3794. AddSourceFile (ExpandFileName (S), True)
  3795. else if Assigned (SourceFile) and (SourceFile is TGNUAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + GASIncludeLocation + S) then
  3796. AddSourceFile (WithBackslash (TIGCCFolder) + GASIncludeLocation + S, True)
  3797. else if Assigned (SourceFile) and (SourceFile is TAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S) then
  3798. AddSourceFile (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S, True)
  3799. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + S) then
  3800. AddSourceFile (WithBackslash (TIGCCFolder) + CIncludeLocation + S, True)
  3801. else
  3802. ShowDefaultMessageBox ('File ''' + S + ''' not found.', 'Search Failed', mtProgramError);
  3803. end;
  3804. end;
  3805. end;
  3806. end;
  3807. procedure TMainForm.FindDlgFind(Sender: TObject);
  3808. begin
  3809. try
  3810. FindString (Sender, True);
  3811. except
  3812. ShowDefaultMessageBox ('Text ''' + (Sender as TFindDialog).FindText + ''' not found.', 'Search Failed', mtProgramError);
  3813. end;
  3814. end;
  3815. procedure TMainForm.ActionsExecute(Action: TBasicAction;
  3816. var Handled: Boolean);
  3817. begin
  3818. Application.ProcessMessages;
  3819. Handled := False;
  3820. end;
  3821. procedure TMainForm.ProjectTreeEnter(Sender: TObject);
  3822. begin
  3823. ActionEditDelete.Enabled := Assigned (ProjectTree.Selected) and Assigned (ProjectTree.Selected.Data);
  3824. end;
  3825. procedure TMainForm.ProjectTreeExit(Sender: TObject);
  3826. begin
  3827. ActionEditDelete.Enabled := False;
  3828. end;
  3829. procedure TMainForm.ProjectTreeChanging(Sender: TObject; Node: TTreeNode;
  3830. var AllowChange: Boolean);
  3831. begin
  3832. if not NoHideEditor then begin
  3833. if Assigned (EditorToHide) then
  3834. EditorToHide.Hide;
  3835. if (not Closing) and Assigned (PreviousNode) and Assigned (PreviousNode.Data) and (TObject (PreviousNode.Data) is TSourceFile) then
  3836. EditorToHide := TSourceFile(PreviousNode.Data).Editor
  3837. else
  3838. EditorToHide := NoEditor;
  3839. end;
  3840. end;
  3841. procedure TMainForm.EditorChange(Sender: TObject);
  3842. begin
  3843. if ActiveControl = Sender then
  3844. UpdateEditButtons;
  3845. UpdateStatusBar;
  3846. end;
  3847. procedure TMainForm.FilePrint(Sender: TObject);
  3848. var
  3849. Node: TTreeNode;
  3850. Cp: Integer;
  3851. begin
  3852. Node := ProjectTree.Selected;
  3853. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) and (Printer.Printers.Count > 0) then try
  3854. PrintDlg.PrintRange := prAllPages;
  3855. PrintDlg.MaxPage := TSourceFile(Node.Data).CountPages;
  3856. PrintDlg.ToPage := PrintDlg.MaxPage;
  3857. if Assigned (CurrentEditor) then begin
  3858. if CurrentEditor.Selection.RLength > 0 then
  3859. PrintDlg.Options := PrintDlg.Options + [poSelection]
  3860. else
  3861. PrintDlg.Options := PrintDlg.Options - [poSelection];
  3862. end;
  3863. if Assigned (Sender) then begin
  3864. if not PrintDlg.Execute then
  3865. Abort;
  3866. Cp := PrintDlg.Copies;
  3867. if Cp < 1 then
  3868. Cp := 1;
  3869. end else
  3870. Cp := 1;
  3871. TSourceFile(Node.Data).Print (Cp, PrintDlg.PrintRange, PrintDlg.FromPage, PrintDlg.ToPage);
  3872. except
  3873. Abort;
  3874. end;
  3875. end;
  3876. procedure TMainForm.FilePrintQuickly(Sender: TObject);
  3877. begin
  3878. FilePrint (nil);
  3879. end;
  3880. procedure TMainForm.TreeItemRename(Sender: TObject);
  3881. begin
  3882. if Assigned (ProjectTree.Selected) then
  3883. ProjectTree.Selected.EditText;
  3884. end;
  3885. procedure TMainForm.HelpContents(Sender: TObject);
  3886. begin
  3887. try
  3888. DocFile.DisplayContentsTab;
  3889. except
  3890. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3891. end;
  3892. end;
  3893. procedure TMainForm.HelpIndex(Sender: TObject);
  3894. begin
  3895. try
  3896. DocFile.DisplayIndexTab;
  3897. except
  3898. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3899. end;
  3900. end;
  3901. procedure TMainForm.HelpSearch(Sender: TObject);
  3902. begin
  3903. try
  3904. DocFile.DisplaySearchTab;
  3905. except
  3906. ShowDefaultMessageBox ('Error opening documentation.', 'Error', mtProgramError);
  3907. end;
  3908. end;
  3909. procedure TMainForm.SplitterMoved(Sender: TObject);
  3910. begin
  3911. StatusBar.Panels[1].Width := ProjectTree.Width;
  3912. Update;
  3913. end;
  3914. procedure TMainForm.UpdateStatusBar;
  3915. var
  3916. S: string;
  3917. I: Integer;
  3918. Total: Integer;
  3919. Cell: TTextCell;
  3920. Node,
  3921. ClassNode: TTreeNode;
  3922. begin
  3923. with StatusBar.Panels do begin
  3924. Total := 0;
  3925. Node := TopNode;
  3926. while Assigned (Node) do begin
  3927. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  3928. Inc (Total);
  3929. Node := Node.GetNext;
  3930. end;
  3931. S := IntToStr (Total) + ' File';
  3932. if Total <> 1 then
  3933. S := S + 's';
  3934. S := S + ' Total';
  3935. if Assigned (ProjectTree.Selected) then begin
  3936. ClassNode := GetSourceTypeFolder (ProjectTree.Selected);
  3937. if Assigned (ClassNode) then begin
  3938. Total := 0;
  3939. Node := ClassNode;
  3940. while Assigned (Node) and (Node <> ClassNode.GetNextSibling) do begin
  3941. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then
  3942. Inc (Total);
  3943. Node := Node.GetNext;
  3944. end;
  3945. S := S + ', ' + IntToStr (Total) + ' in Category';
  3946. end;
  3947. end;
  3948. if Items[1].Text <> S then
  3949. Items[1].Text := S;
  3950. if Assigned (CurrentEditor) then begin
  3951. with CurrentEditor do begin
  3952. if Enabled then begin
  3953. if Selection.RLength > 0 then begin
  3954. I := Selection.RLength + Selection.StartRowCol.Row - Selection.EndRowCol.Row;
  3955. if Selection.EndRowCol.Col > LineLength [Selection.EndRowCol.Row] then
  3956. Dec (I);
  3957. S := IntToStr (I);
  3958. if Items[3].Text <> S then
  3959. Items[3].Text := S;
  3960. if Items[4].Text <> '' then
  3961. Items[4].Text := '';
  3962. if Items[3].Width <> 60 then
  3963. Items[3].Width := 60;
  3964. if Items[4].Width <> 0 then
  3965. Items[4].Width := 0;
  3966. end else begin
  3967. Cell := Selection.StartRowCol;
  3968. S := IntToStr (Cell.Row);
  3969. if Items[3].Text <> S then
  3970. Items[3].Text := S;
  3971. S := IntToStr (Cell.Col);
  3972. if Items[4].Text <> S then
  3973. Items[4].Text := S;
  3974. if Items[3].Width <> 30 then
  3975. Items[3].Width := 30;
  3976. if Items[4].Width <> 30 then
  3977. Items[4].Width := 30;
  3978. end;
  3979. I := TextLength - LineCount + 1;
  3980. S := IntToStr (I) + ' Character';
  3981. if I <> 1 then
  3982. S := S + 's';
  3983. if Items[11].Text <> S then
  3984. Items[11].Text := S;
  3985. if Items[10].Width <> 1 then
  3986. Items[10].Width := 1;
  3987. if Items[11].Width <> 93 then
  3988. Items[11].Width := 93;
  3989. if Items[12].Width <> 1 then
  3990. Items[12].Width := 1;
  3991. end;
  3992. end;
  3993. end else begin
  3994. if Items[3].Text <> '' then
  3995. Items[3].Text := '';
  3996. if Items[4].Text <> '' then
  3997. Items[4].Text := '';
  3998. if Items[11].Text <> '' then
  3999. Items[11].Text := '';
  4000. if Items[3].Width <> 0 then
  4001. Items[3].Width := 0;
  4002. if Items[4].Width <> 0 then
  4003. Items[4].Width := 0;
  4004. if Items[10].Width <> 0 then
  4005. Items[10].Width := 0;
  4006. if Items[11].Width <> 0 then
  4007. Items[11].Width := 0;
  4008. if Items[12].Width <> 0 then
  4009. Items[12].Width := 0;
  4010. end;
  4011. Node := ProjectTree.Selected;
  4012. S := '';
  4013. if Assigned (Node) then begin
  4014. if Assigned (Node.Data) and (TObject (Node.Data) is TSourceFile) then begin
  4015. with TSourceFile (Node.Data) do
  4016. if (ProjectFile = '') and (ExtractFilePath (FileName) = 'C:\') then
  4017. S := LogicalFileName
  4018. else
  4019. S := FileName;
  4020. end else
  4021. if Node = TopNode then
  4022. S := ProjectFile;
  4023. end;
  4024. if Items[13].Text <> S then
  4025. Items[13].Text := S;
  4026. end;
  4027. Update;
  4028. end;
  4029. procedure TMainForm.ProjectTreeMouseDown(Sender: TObject;
  4030. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  4031. begin
  4032. if Button = mbRight then
  4033. SelectNode (ProjectTree.GetNodeAt (X, Y));
  4034. end;
  4035. procedure TMainForm.SetModified(const Value: Boolean);
  4036. begin
  4037. FModified := Value;
  4038. UpdateStatusBar;
  4039. if Value then
  4040. Invalidated := True;
  4041. end;
  4042. procedure TMainForm.ToolBarManagerBandMove(Sender: TObject;
  4043. Control: TControl; var ARect: TRect);
  4044. begin
  4045. Update;
  4046. end;
  4047. procedure TMainForm.ProjectTreeDragOver(Sender, Source: TObject; X,
  4048. Y: Integer; State: TDragState; var Accept: Boolean);
  4049. var
  4050. S,
  4051. D: TTreeNode;
  4052. SameType,
  4053. FolderDest: Boolean;
  4054. begin
  4055. Accept := False;
  4056. with ProjectTree do begin
  4057. S := Selected;
  4058. if Assigned (S) and Assigned (S.Data) then begin
  4059. D := GetNodeAt (X, Y);
  4060. if Assigned (D) and (D <> TopNode) and (D <> S) and (D <> S.Parent) then begin
  4061. SameType := (GetSourceTypeFolder (S) = GetSourceTypeFolder (D));
  4062. FolderDest := (not Assigned (D.Data)) or (TObject (D.Data) is TFolder);
  4063. if TObject (S.Data) is TSourceFile then
  4064. Accept := SameType or FolderDest
  4065. else
  4066. Accept := SameType and FolderDest;
  4067. end;
  4068. end;
  4069. end;
  4070. end;
  4071. procedure TMainForm.ProjectTreeDragDrop(Sender, Source: TObject; X,
  4072. Y: Integer);
  4073. var
  4074. S,
  4075. D: TTreeNode;
  4076. FN: string;
  4077. F: TSourceFile;
  4078. Folder: TFolder;
  4079. begin
  4080. with ProjectTree do begin
  4081. S := Selected;
  4082. if Assigned (S) and Assigned (S.Data) then begin
  4083. D := GetNodeAt (X, Y);
  4084. if Assigned (D) and (D <> TopNode) then begin
  4085. // Handle moving within one type.
  4086. if GetSourceTypeFolder (S) = GetSourceTypeFolder (D) then begin
  4087. // Handle moving to a different folder.
  4088. if (not Assigned (D.Data)) or (TObject (D.Data) is TFolder) then begin
  4089. S.MoveTo (D, naAddChild);
  4090. if TObject (S.Data) is TSourceFile then
  4091. with TSourceFile (S.Data) do begin
  4092. Folder := D.Data;
  4093. Invalidate;
  4094. end;
  4095. // Handle moving within one folder.
  4096. end else begin
  4097. if (S <> D) and (S.Parent = D.Parent) then begin
  4098. if D.Index > S.Index then begin
  4099. if D.GetNextSibling <> nil then
  4100. S.MoveTo (D.GetNextSibling, naInsert)
  4101. else
  4102. S.MoveTo (D, naAdd);
  4103. end else
  4104. S.MoveTo (D, naInsert);
  4105. end;
  4106. end;
  4107. Modify;
  4108. // Handle moving to a different type.
  4109. end else begin
  4110. if S.Parent <> D then begin
  4111. if TObject (S.Data) is TSourceFile then begin
  4112. with TSourceFile (S.Data) do begin
  4113. if FileExists (FileName) then
  4114. WarnIfModified
  4115. else
  4116. Save;
  4117. FN := FileName;
  4118. end;
  4119. S.Delete;
  4120. Folder := nil;
  4121. if Assigned (D.Data) and (TObject (D.Data) is TFolder) then
  4122. Folder := D.Data;
  4123. D := GetSourceTypeFolder (D);
  4124. if Assigned (D) then begin
  4125. F := AddSourceFile (FN, False, TSourceFile.GetAppropriateClassFromTreeIndex (D.Index), Folder);
  4126. if Assigned (F) and Assigned (F.TreeItem) then
  4127. SelectNode (F.TreeItem);
  4128. end;
  4129. RecompileFiles;
  4130. Modify;
  4131. end;
  4132. end;
  4133. end;
  4134. end;
  4135. if Assigned (CurrentEditor) then
  4136. CurrentEditor.Refresh;
  4137. SortFiles;
  4138. end;
  4139. end;
  4140. end;
  4141. procedure TMainForm.ErrorListClick(Sender: TObject);
  4142. begin
  4143. if Enabled and Assigned (ErrorList.Selected) and (ErrorList.SelCount = 1) then
  4144. TFoundError(ErrorList.Selected.Data).GoToPosition;
  4145. end;
  4146. function TMainForm.GetCurrentEditor: TMemoComponent;
  4147. var
  4148. Node: TTreeNode;
  4149. begin
  4150. Node := ProjectTree.Selected;
  4151. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TTextSourceFile) then
  4152. Result := TTextSourceFile(Node.Data).TextEditor
  4153. else
  4154. Result := nil;
  4155. end;
  4156. procedure TMainForm.DeleteError(Sender: TObject);
  4157. var
  4158. I: Integer;
  4159. begin
  4160. if DeleteErrors then begin
  4161. with ErrorList.Items do
  4162. for I := Count - 1 downto 0 do
  4163. if Assigned (Item[I].Data) then
  4164. with TFoundError (Item[I].Data) do
  4165. if Range = Sender then
  4166. Item[I].Delete;
  4167. UpdateErrorWindow;
  4168. end;
  4169. end;
  4170. procedure TMainForm.UpdateFuncs;
  4171. var
  4172. Node: TTreeNode;
  4173. begin
  4174. Node := ProjectTree.Selected;
  4175. if Assigned (Node) and Assigned (Node.Data) and (TObject (Node.Data) is TSourceTextSourceFile) then
  4176. with TSourceTextSourceFile (Node.Data) do
  4177. Funcs := GetFunctions
  4178. else
  4179. SetLength (Funcs, 0);
  4180. end;
  4181. procedure TMainForm.FunctionPopupPopup(Sender: TObject);
  4182. var
  4183. I,
  4184. P: Integer;
  4185. M: TMenuItem;
  4186. begin
  4187. with (Sender as TPopupMenu).Items do begin
  4188. for I := Count - 1 downto 0 do
  4189. Remove (Items [I]);
  4190. UpdateFuncs;
  4191. for I := Low (Funcs) to High (Funcs) do begin
  4192. M := TMenuItem.Create (Self);
  4193. with M do begin
  4194. Tag := I;
  4195. Caption := Funcs[I].Name;
  4196. OnClick := FindFunctionFromPopup;
  4197. end;
  4198. P := Pos ('main', Funcs[I].Name);
  4199. if (P <> 0) and (P = Length (Funcs[I].Name) - Length ('main') + 1) then
  4200. Insert (0, M)
  4201. else
  4202. Add (M);
  4203. end;
  4204. if Count <= 0 then
  4205. Add (NoFunctionsItem);
  4206. end;
  4207. end;
  4208. procedure TMainForm.FindFunctions(Sender: TObject);
  4209. var
  4210. I: Integer;
  4211. Editor: TMemoComponent;
  4212. begin
  4213. UpdateFuncs;
  4214. with TFunctionsForm.Create (Self) do try
  4215. Funcs := @Self.Funcs;
  4216. with FuncList.Items do begin
  4217. BeginUpdate;
  4218. Clear;
  4219. for I := Low (Self.Funcs) to High (Self.Funcs) do
  4220. AddObject (Self.Funcs[I].Name, TObject (I));
  4221. EndUpdate;
  4222. end;
  4223. FuncListClick (FuncList);
  4224. case ShowModal of
  4225. mrYes: begin
  4226. Editor := CurrentEditor;
  4227. if Assigned (Editor) then begin
  4228. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].PrototypeLine, 1)));
  4229. Editor.Selection.ScrollInView (5);
  4230. end;
  4231. end;
  4232. mrNo: begin
  4233. Editor := CurrentEditor;
  4234. if Assigned (Editor) then begin
  4235. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].ImplementationLine, 1)));
  4236. Editor.Selection.ScrollInView (5);
  4237. end;
  4238. end;
  4239. end;
  4240. with FuncList.Items do begin
  4241. BeginUpdate;
  4242. for I := Count - 1 downto 0 do begin
  4243. Objects [I] := nil;
  4244. Delete (I);
  4245. end;
  4246. EndUpdate;
  4247. end;
  4248. finally
  4249. Free;
  4250. end;
  4251. end;
  4252. procedure TMainForm.FindFunctionFromPopup(Sender: TObject);
  4253. var
  4254. L: Integer;
  4255. Editor: TMemoComponent;
  4256. begin
  4257. if Sender is TMenuItem then
  4258. with Sender as TMenuItem do begin
  4259. if Funcs[Tag].ImplementationLine > 0 then
  4260. L := Funcs[Tag].ImplementationLine
  4261. else
  4262. L := Funcs[Tag].PrototypeLine;
  4263. if L > 0 then begin
  4264. Editor := CurrentEditor;
  4265. if Assigned (Editor) then begin
  4266. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (L, 1)));
  4267. Editor.Selection.ScrollInView (5);
  4268. if Editor.Visible and Editor.Enabled then
  4269. ActiveControl := Editor;
  4270. end;
  4271. end;
  4272. end;
  4273. end;
  4274. procedure TMainForm.IncreaseIndent(Sender: TObject);
  4275. var
  4276. Editor: TMemoComponent;
  4277. begin
  4278. Editor := CurrentEditor;
  4279. if Assigned (Editor) then
  4280. Editor.ChangeIndent (1);
  4281. end;
  4282. procedure TMainForm.DecreaseIndent(Sender: TObject);
  4283. var
  4284. Editor: TMemoComponent;
  4285. begin
  4286. Editor := CurrentEditor;
  4287. if Assigned (Editor) then
  4288. Editor.ChangeIndent (-1);
  4289. end;
  4290. procedure TMainForm.SortFiles;
  4291. var
  4292. CurFileIndex: Integer;
  4293. procedure DoSortFiles(Node: TTreeNode);
  4294. var
  4295. I: Integer;
  4296. begin
  4297. with Node do begin
  4298. if Assigned (Data) and (TObject (Data) is TSourceFile) then begin
  4299. with TSourceFile (Data) do
  4300. if Index > CurFileIndex then
  4301. Index := CurFileIndex;
  4302. Inc (CurFileIndex);
  4303. end;
  4304. for I := 0 to Count - 1 do
  4305. DoSortFiles (Item [I]);
  4306. end;
  4307. end;
  4308. var
  4309. I: Integer;
  4310. begin
  4311. CurFileIndex := 0;
  4312. { This is supposed to be: DoSortFiles (TopNode);
  4313. However, header files are dependent on the other
  4314. files and therefore have to be put after all the
  4315. others. }
  4316. with TopNode do begin
  4317. for I := 0 to Count - 1 do
  4318. if I <> THeaderSourceFile.GetClassTreeIndex then
  4319. DoSortFiles (Item [I]);
  4320. if Count > THeaderSourceFile.GetClassTreeIndex then
  4321. DoSortFiles (Item [THeaderSourceFile.GetClassTreeIndex]);
  4322. end;
  4323. end;
  4324. procedure TMainForm.AppCompSetMessage(const Msg: string);
  4325. begin
  4326. with StatusBar do
  4327. Panels.Items[6].Text := Msg + '...';
  4328. if not Compiling then begin
  4329. Compiling := True;
  4330. CompUpdate;
  4331. UpdateDebugSettings;
  4332. with StatusBar.Panels do begin
  4333. Items[5].Width := 5;
  4334. Items[6].Width := 180;
  4335. Items[7].Width := 100;
  4336. Items[8].Width := 100;
  4337. Items[9].Width := 1000000;
  4338. end;
  4339. end;
  4340. end;
  4341. procedure TMainForm.AppCompStartFile;
  4342. var
  4343. I: Integer;
  4344. begin
  4345. Application.Hint := '';
  4346. CompFinishAndStop := False;
  4347. CompStopNow := False;
  4348. CompFileStartTime := Now;
  4349. CompLastTime := 0;
  4350. if not Compiling then begin
  4351. CompStartTime := CompFileStartTime;
  4352. ToolBarNewButton.Enabled := False;
  4353. MenuFileNew.Enabled := False;
  4354. ActionFileOpen.Enabled := False;
  4355. ActionFileExit.Enabled := False;
  4356. ActionProjectAddFiles.Enabled := False;
  4357. ActionProjectCompile.Visible := False;
  4358. ActionProjectMake.Visible := False;
  4359. ActionProjectBuild.Visible := False;
  4360. ActionProjectStopCompilation.Enabled := True;
  4361. ActionProjectForceQuitCompiler.Enabled := True;
  4362. ActionProjectStopCompilation.Visible := True;
  4363. ActionProjectForceQuitCompiler.Visible := True;
  4364. with RecentFiles do
  4365. for I := 0 to Count - 1 do
  4366. with TRecentFileMenuItem (Objects [I]) do begin
  4367. FileMenuItem.Enabled := False;
  4368. PopupMenuItem.Enabled := False;
  4369. end;
  4370. end;
  4371. end;
  4372. procedure TMainForm.AppCompStop;
  4373. var
  4374. I: Integer;
  4375. begin
  4376. if Compiling then begin
  4377. Compiling := False;
  4378. ActionProjectStopCompilation.Visible := False;
  4379. ActionProjectForceQuitCompiler.Visible := False;
  4380. ToolBarNewButton.Enabled := True;
  4381. MenuFileNew.Enabled := True;
  4382. ActionFileOpen.Enabled := True;
  4383. ActionFileExit.Enabled := True;
  4384. ActionProjectAddFiles.Enabled := True;
  4385. ActionProjectCompile.Visible := True;
  4386. ActionProjectMake.Visible := True;
  4387. ActionProjectBuild.Visible := True;
  4388. with RecentFiles do
  4389. for I := 0 to Count - 1 do
  4390. with TRecentFileMenuItem (Objects [I]) do begin
  4391. FileMenuItem.Enabled := True;
  4392. PopupMenuItem.Enabled := True;
  4393. end;
  4394. UpdateDebugSettings;
  4395. with StatusBar.Panels do begin
  4396. Items[5].Width := 0;
  4397. Items[6].Width := 0;
  4398. Items[7].Width := 0;
  4399. Items[8].Width := 0;
  4400. Items[9].Width := 0;
  4401. end;
  4402. end;
  4403. end;
  4404. procedure TMainForm.AppCompUpdate;
  4405. const
  4406. SecondsPerDay = 24 * 60 * 60;
  4407. function CustomTimeToStr(ConvTime: TDateTime): string;
  4408. var
  4409. Seconds: Integer;
  4410. MinStr,
  4411. SecStr: string;
  4412. begin
  4413. Seconds := Trunc (ConvTime * SecondsPerDay);
  4414. MinStr := IntToStr (Seconds div 60);
  4415. SecStr := IntToStr (Seconds mod 60);
  4416. while Length (SecStr) < 2 do
  4417. SecStr := '0' + SecStr;
  4418. Result := MinStr + ':' + SecStr;
  4419. end;
  4420. var
  4421. CurTime: TDateTime;
  4422. begin
  4423. CurTime := Now;
  4424. if Trunc (CompLastTime * SecondsPerDay) <> Trunc (CurTime * SecondsPerDay) then begin
  4425. CompLastTime := CurTime;
  4426. with StatusBar, Panels do begin
  4427. Items[7].Text := 'File Time: ' + CustomTimeToStr (CurTime - CompFileStartTime);
  4428. Items[8].Text := 'Total Time: ' + CustomTimeToStr (CurTime - CompStartTime);
  4429. Update;
  4430. end;
  4431. end;
  4432. end;
  4433. procedure TMainForm.DisplayFolderMessage;
  4434. var
  4435. S: string;
  4436. begin
  4437. if OperationSuccessful and (not OperationCancelled) and OpenFolderMessage then begin
  4438. if ProjectTarget = ptArchive then
  4439. 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?'
  4440. else
  4441. with OptimizeInfo do begin
  4442. S := 'The project has been compiled successfully.'#13#10#13#10'Program Variable Size: ' + IntToStr (ProgramSize) + ' Bytes'#13#10;
  4443. if DataSize > 0 then
  4444. S := S + 'Data Variable Size: ' + IntToStr (DataSize) + ' Bytes'#13#10;
  4445. if BSSSize > 0 then
  4446. S := S + 'BSS Size: ' + IntToStr (BSSSize) + ' Bytes'#13#10;
  4447. S := S + 'Absolute Relocs: ' + IntToStr (RelocCount) + #13#10'Natively Emitted Relocs: ' + IntToStr (NativeRelocCount) + #13#10;
  4448. if OptimizeBranchesResult > 0 then begin
  4449. if OptimizeBranches then
  4450. S := S + 'Relocs Saved'
  4451. else
  4452. S := S + 'Relocs Savable';
  4453. S := S + ' by Branch Optimization: ' + IntToStr (OptimizeBranchesResult) + #13#10;
  4454. end;
  4455. if OptimizeMovesResult > 0 then begin
  4456. if OptimizeMoves then
  4457. S := S + 'Relocs Saved'
  4458. else
  4459. S := S + 'Relocs Savable';
  4460. S := S + ' by Move Optimization: ' + IntToStr (OptimizeMovesResult) + #13#10;
  4461. end;
  4462. if OptimizeTestsResult > 0 then begin
  4463. if OptimizeTests then
  4464. S := S + 'Relocs Saved'
  4465. else
  4466. S := S + 'Relocs Savable';
  4467. S := S + ' by Test Optimization: ' + IntToStr (OptimizeTestsResult) + #13#10;
  4468. end;
  4469. if OptimizeCalcsResult > 0 then begin
  4470. if OptimizeCalcs then
  4471. S := S + 'Relocs Saved'
  4472. else
  4473. S := S + 'Relocs Savable';
  4474. S := S + ' by Calculation Optimization: ' + IntToStr (OptimizeCalcsResult) + #13#10;
  4475. end;
  4476. if UseFLineJumpsResult > 0 then begin
  4477. if UseFLineJumps or Use4ByteFLineJumps then
  4478. S := S + 'Relocs Saved'
  4479. else
  4480. S := S + 'Relocs Savable';
  4481. S := S + ' by F-Line Jumps: ' + IntToStr (UseFLineJumpsResult) + #13#10;
  4482. end;
  4483. if CutRangesResult > 0 then begin
  4484. if CutRanges then
  4485. S := S + 'Space Saved'
  4486. else
  4487. S := S + 'Space Savable';
  4488. S := S + ' by Range-Cutting: ' + IntToStr (CutRangesResult) + ' Bytes'#13#10;
  4489. end;
  4490. if NearAssemblyResult > 0 then
  4491. S := S + 'Space Savable by Using GNU Assembler ''-l'' Switch: ' + IntToStr (NearAssemblyResult) + ' Bytes'#13#10;
  4492. S := S + #13#10'Do you want to open the project folder?';
  4493. end;
  4494. if ShowDefaultMessageBox (S, 'Compilation Successful', mtQuestion) = idYes then
  4495. ShellExecute (0, nil, PChar (ExtractFilePath (ProjectFile)), nil, nil, sw_ShowNormal);
  4496. end;
  4497. end;
  4498. procedure TMainForm.ProjectStopCompilation(Sender: TObject);
  4499. begin
  4500. CompFinishAndStop := True;
  4501. ActionProjectStopCompilation.Enabled := False;
  4502. end;
  4503. procedure TMainForm.ProjectForceQuitCompiler(Sender: TObject);
  4504. begin
  4505. CompStopNow := True;
  4506. end;
  4507. procedure TMainForm.WMDropFiles(var Msg: TMessage);
  4508. var
  4509. DropHandle: THandle;
  4510. I,
  4511. FileCount: Integer;
  4512. CurFile: array [0..512] of Char;
  4513. begin
  4514. DropHandle := Msg.WParam;
  4515. FileCount := DragQueryFile (DropHandle, High (Cardinal), nil, 0);
  4516. for I := 0 to FileCount - 1 do begin
  4517. DragQueryFile (DropHandle, I, CurFile, SizeOf (CurFile) - 1);
  4518. if LowerCase (ExtractFileExt (AnsiString (CurFile))) = LowerCase (ProjectFileExt) then
  4519. FileOpen (AnsiString (CurFile))
  4520. else
  4521. AddSourceFile (AnsiString (CurFile), True);
  4522. end;
  4523. DragFinish (DropHandle);
  4524. end;
  4525. procedure TMainForm.HelpNews(Sender: TObject);
  4526. begin
  4527. with TNewsForm.Create (Self) do try
  4528. Execute;
  4529. finally
  4530. Free;
  4531. end;
  4532. end;
  4533. function TMainForm.GetTiEmuInterface: ITiEmuOLE;
  4534. var
  4535. Unknown: IUnknown;
  4536. OLEResult: HResult;
  4537. begin
  4538. OLEResult := GetActiveObject(CLASS_TiEmuOLE, nil, Unknown);
  4539. if OLEResult = S_OK then begin
  4540. OleCheck(Unknown.QueryInterface(ITiEmuOLE, Result));
  4541. end else begin
  4542. { If no TiEmu path is set, try looking it up from the registry. }
  4543. if Length (VTIPath) = 0 then begin
  4544. with TRegistry.Create do try
  4545. RootKey := HKey_Classes_Root;
  4546. if OpenKeyReadOnly ('\CLSID\{B2A17B13-9D6F-4DD4-A2A9-6FE06ADC1D33}\LocalServer32') then try
  4547. if ValueExists ('') then
  4548. VTIPath := ReadString ('');
  4549. except end;
  4550. finally
  4551. Free;
  4552. end;
  4553. end;
  4554. if Length (VTIPath) > 0 then begin
  4555. with TVTIStartForm.Create (Self) do try
  4556. if ShowModal = mrOK then begin
  4557. Result := TiEmuInterface;
  4558. end else
  4559. Abort;
  4560. finally
  4561. Free;
  4562. end;
  4563. end else begin
  4564. ShowDefaultMessageBox ('TiEmu is not running.', 'Error', mtProgramError);
  4565. Abort;
  4566. end;
  4567. end;
  4568. end;
  4569. procedure TMainForm.SendFiles(FNList: array of string);
  4570. var
  4571. I: Integer;
  4572. FirstI: Integer;
  4573. TiEmuInterface: ITiEmuOLE;
  4574. TiEmuCalcType: TTiEmuCalcType;
  4575. Ready: Boolean;
  4576. Connection: TLinkConnection;
  4577. Size: Word;
  4578. Total: Cardinal;
  4579. Progress: DWord;
  4580. ProgressForm: TSendProgressForm;
  4581. begin
  4582. OperationSuccessful := False;
  4583. OperationCancelled := False;
  4584. if Length (FNList) > 0 then begin
  4585. if TransferTarget = ttVTI then begin
  4586. TiEmuInterface := GetTiEmuInterface;
  4587. Enabled := False;
  4588. try
  4589. { Wait for TiEmu to get ready. }
  4590. repeat
  4591. Sleep(100);
  4592. Application.ProcessMessages;
  4593. try
  4594. Ready := TiEmuInterface.ready_for_transfers;
  4595. except
  4596. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4597. Abort;
  4598. end;
  4599. until Ready;
  4600. { Now obtain the model from TiEmu. }
  4601. try
  4602. TiEmuCalcType := TTiEmuCalcType(TiEmuInterface.emulated_calc_type);
  4603. if TiEmuCalcType = cvNone then Abort;
  4604. except
  4605. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4606. Abort;
  4607. end;
  4608. { Select the correct files for the model. }
  4609. if (TiEmuCalcType <> cvTI92) and (ProjectTarget = ptFargo) then begin
  4610. ShowDefaultMessageBox ('Can''t send Fargo program to a TI-89/89Ti/92+/V200.', 'Error', mtProgramError);
  4611. Abort;
  4612. end;
  4613. if (TiEmuCalcType = cvTI92) and (ProjectTarget <> ptFargo) then begin
  4614. ShowDefaultMessageBox ('Can''t send AMS program to a TI-92.', 'Error', mtProgramError);
  4615. Abort;
  4616. end;
  4617. for I := Low (FNList) to High (FNList) do begin
  4618. case TiEmuCalcType of
  4619. cvTI92Plus:
  4620. FNList [I] := StringReplace (FNList [I], '.89', '.9x', []);
  4621. cvV200:
  4622. FNList [I] := StringReplace (FNList [I], '.89', '.v2', []);
  4623. cvTI92:
  4624. FNList [I] := StringReplace (FNList [I], '.89', '.92', []);
  4625. end;
  4626. if not FileExists (FNList [I]) then begin
  4627. ShowDefaultMessageBox ('The file "' + FNList [I] + '" could not be found.', 'Error', mtProgramError);
  4628. Abort;
  4629. end;
  4630. end;
  4631. { Now send the files. }
  4632. FirstI := Low (FNList);
  4633. if DebugInfo and not Pack and FileExists (ChangeFileExt (ProjectFile, '.dbg')) then begin
  4634. try
  4635. if not TiEmuInterface.debug_file(FNList [FirstI]) then Abort;
  4636. except
  4637. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4638. Abort;
  4639. end;
  4640. Inc (FirstI);
  4641. end;
  4642. for I := FirstI to High (FNList) do begin
  4643. try
  4644. if not TiEmuInterface.send_file(FNList [I]) then Abort;
  4645. except
  4646. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4647. Abort;
  4648. end;
  4649. end;
  4650. finally
  4651. Enabled := True;
  4652. end;
  4653. end else if TransferTarget = ttCalc then begin
  4654. FillChar (Connection, SizeOf (Connection), 0);
  4655. Connection.Port := LinkPort;
  4656. Connection.CableType := LinkCable;
  4657. if CreateConnection (Connection) then try
  4658. if OpenConnection (Connection) and GetCalcType (Connection) then begin
  4659. Total := 0;
  4660. for I := Low (FNList) to High (FNList) do begin
  4661. case Connection.CalcType of
  4662. cdTI92Plus:
  4663. FNList [I] := StringReplace (FNList [I], '.89', '.9x', []);
  4664. cdV200:
  4665. FNList [I] := StringReplace (FNList [I], '.89', '.v2', []);
  4666. cdTI92:
  4667. FNList [I] := StringReplace (FNList [I], '.89', '.92', []);
  4668. end;
  4669. if not FileExists (FNList [I]) then begin
  4670. ShowDefaultMessageBox ('The file "' + FNList [I] + '" could not be found.', 'Error', mtProgramError);
  4671. Abort;
  4672. end;
  4673. if not CheckFileFormat (Connection, PChar (FNList [I]), nil, nil, @Size) then begin
  4674. ShowDefaultMessageBox ('Error sending file.', 'Error', mtProgramError);
  4675. Abort;
  4676. end;
  4677. Inc (Total, Size);
  4678. end;
  4679. Enabled := False;
  4680. try
  4681. ProgressForm := TSendProgressForm.Create (Self);
  4682. with ProgressForm do try
  4683. ProgressBar.Max := Total;
  4684. Show;
  4685. Update;
  4686. Progress := 0;
  4687. for I := Low (FNList) to High (FNList) do begin
  4688. FileNameLabel.Caption := ExtractFileName (FNList [I]);
  4689. if not SendFile (Connection, nil, nil, PChar (FNList [I]), @Progress, ProgressProg, ProgressForm) then begin
  4690. if Cancelled then
  4691. OperationCancelled := True
  4692. else
  4693. ShowDefaultMessageBox ('Error sending file. Please check whether your calculator is on the home screen.', 'Error', mtProgramError);
  4694. Abort;
  4695. end;
  4696. end;
  4697. finally
  4698. CloseNow := True;
  4699. Free;
  4700. end;
  4701. finally
  4702. Enabled := True;
  4703. end;
  4704. end else begin
  4705. ShowDefaultMessageBox ('Error linking to calculator.', 'Error', mtProgramError);
  4706. Abort;
  4707. end;
  4708. finally
  4709. CloseConnection (Connection);
  4710. end else begin
  4711. ShowDefaultMessageBox ('Error opening link port.', 'Error', mtProgramError);
  4712. Abort;
  4713. end;
  4714. end;
  4715. OperationSuccessful := True;
  4716. end;
  4717. end;
  4718. procedure TMainForm.ExecuteCommandLine(const Line: string);
  4719. var
  4720. TiEmuInterface: ITiEmuOLE;
  4721. Connection: TLinkConnection;
  4722. begin
  4723. if TransferTarget = ttVTI then begin
  4724. TiEmuInterface := GetTiEmuInterface;
  4725. try
  4726. if not TiEmuInterface.execute_command(Line) then Abort;
  4727. except
  4728. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4729. Abort;
  4730. end;
  4731. end else if TransferTarget = ttCalc then begin
  4732. FillChar (Connection, SizeOf (Connection), 0);
  4733. Connection.Port := LinkPort;
  4734. Connection.CableType := LinkCable;
  4735. if CreateConnection (Connection) then try
  4736. if OpenConnection (Connection) then
  4737. ExecuteHomeLine (Connection, Line)
  4738. else begin
  4739. ShowDefaultMessageBox ('Error linking to calculator.', 'Error', mtProgramError);
  4740. Abort;
  4741. end;
  4742. finally
  4743. CloseConnection (Connection);
  4744. end else begin
  4745. ShowDefaultMessageBox ('Error opening link port.', 'Error', mtProgramError);
  4746. Abort;
  4747. end;
  4748. end;
  4749. end;
  4750. procedure TMainForm.DebugRun(Sender: TObject);
  4751. var
  4752. Files: array of string;
  4753. begin
  4754. OperationSuccessful := True;
  4755. OperationCancelled := False;
  4756. if Invalidated then
  4757. MakeFileWrapped;
  4758. 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
  4759. if Runnable then begin
  4760. SetLength (Files, 0);
  4761. case ProjectTarget of
  4762. ptRegular: begin
  4763. SetLength (Files, 1);
  4764. Files [High (Files)] := ChangeFileExt (ProjectFile, '.89z');
  4765. if Pack and (ssPack in SpecialSupport) then begin
  4766. SetLength (Files, Length (Files) + 1);
  4767. Files [High (Files)] := ChangeFileExt (ProjectFile, '.89y');
  4768. end;
  4769. if UseDataVar then begin
  4770. SetLength (Files, Length (Files) + 1);
  4771. Files [High (Files)] := ChangeFileExt (ProjectFile, '-data.89y');
  4772. end;
  4773. end;
  4774. ptFargo: begin
  4775. SetLength (Files, 1);
  4776. Files [High (Files)] := ChangeFileExt (ProjectFile, '.92p');
  4777. end;
  4778. end;
  4779. if Length (Files) > 0 then begin
  4780. SendFiles (Files);
  4781. if OperationSuccessful then
  4782. ExecuteCommandLine (TopNode.Text + '(' + CommandLine + ')');
  4783. end;
  4784. end else
  4785. DisplayFolderMessage;
  4786. end;
  4787. end;
  4788. procedure TMainForm.DebugPause(Sender: TObject);
  4789. var
  4790. TiEmuInterface: ITiEmuOLE;
  4791. begin
  4792. TiEmuInterface := GetTiEmuInterface;
  4793. try
  4794. TiEmuInterface.enter_debugger;
  4795. except
  4796. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4797. end;
  4798. end;
  4799. procedure TMainForm.DebugReset(Sender: TObject);
  4800. var
  4801. TiEmuInterface: ITiEmuOLE;
  4802. begin
  4803. TiEmuInterface := GetTiEmuInterface;
  4804. try
  4805. TiEmuInterface.reset_calc(False);
  4806. except
  4807. ShowDefaultMessageBox ('OLE function call failed.', 'Error', mtProgramError);
  4808. end;
  4809. end;
  4810. function TMainForm.GetInvalidated: Boolean;
  4811. var
  4812. I: Integer;
  4813. begin
  4814. Result := FInvalidated;
  4815. if not Result then
  4816. with SourceFiles do
  4817. for I := 0 to Count - 1 do
  4818. with Items [I] as TSourceFile do
  4819. if (Compilable or (Items [I] is THeaderSourceFile)) and Invalidated then begin
  4820. Result := True;
  4821. Break;
  4822. end;
  4823. end;
  4824. procedure TMainForm.UpdateDebugSettings;
  4825. var
  4826. CanRun: Boolean;
  4827. begin
  4828. CanRun := Runnable;
  4829. ActionDebugRun.Enabled := not Compiling;
  4830. ActionDebugPause.Enabled := (not Compiling) and (TransferTarget = ttVTI);
  4831. ActionDebugReset.Enabled := (not Compiling) and (TransferTarget = ttVTI);
  4832. MainMenuDebug.Visible := CanRun;
  4833. if not CanRun then
  4834. ToolBarDebugLine.Parent := nil;
  4835. ToolBarRunButton.Visible := CanRun;
  4836. ToolBarPauseButton.Visible := CanRun;
  4837. ToolBarDebugLine.Visible := CanRun;
  4838. if CanRun then begin
  4839. ToolBarDebugLine.Parent := MainToolBar;
  4840. ToolBarDebugLine.Left := ToolBarPauseButton.Left + ToolBarPauseButton.Width;
  4841. end;
  4842. end;
  4843. procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
  4844. Shift: TShiftState);
  4845. var
  4846. NewSelection: TTreeNode;
  4847. begin
  4848. if (Key = vk_F8) and (Shift = []) then begin
  4849. ProjectMake (Sender);
  4850. end else if (Key = vk_F8) and (Shift = [ssAlt]) then begin
  4851. ProjectCompile (Sender);
  4852. end else if (Key = vk_F9) and (Shift = [ssShift, ssCtrl, ssAlt]) then begin
  4853. if TransferTarget = ttVTI then
  4854. TransferTarget := ttCalc
  4855. else
  4856. TransferTarget := ttVTI;
  4857. SavePreferences;
  4858. UpdateDebugSettings;
  4859. end else if ((Key = vk_Tab) or (Key = Ord('G'))) and (Shift = [ssCtrl]) then begin
  4860. NewSelection := ProjectTree.Selected;
  4861. if Assigned (NewSelection) then begin
  4862. repeat
  4863. NewSelection := NewSelection.GetNext;
  4864. if not Assigned (NewSelection) then
  4865. NewSelection := TopNode;
  4866. until (NewSelection.IsVisible and Assigned (NewSelection.Data)) or (NewSelection = ProjectTree.Selected);
  4867. if Assigned (NewSelection.Data) then
  4868. SelectNode (NewSelection);
  4869. if Assigned (CurrentEditor) and CurrentEditor.Enabled then try
  4870. CurrentEditor.SetFocus;
  4871. except end;
  4872. end;
  4873. end;
  4874. end;
  4875. procedure TMainForm.SelectNode(Node: TTreeNode);
  4876. var
  4877. Allow: Boolean;
  4878. begin
  4879. if PreviousNode <> Node then begin
  4880. Allow := True;
  4881. ProjectTreeChanging (ProjectTree, Node, Allow);
  4882. if Allow then begin
  4883. NoHideEditor := True;
  4884. ProjectTree.Selected := Node;
  4885. NoHideEditor := False;
  4886. end;
  4887. end;
  4888. end;
  4889. procedure TMainForm.ChangeNotificationTick(Sender: TObject);
  4890. var
  4891. I: Integer;
  4892. begin
  4893. if not InChangeNotification then begin
  4894. InChangeNotification := True;
  4895. with SourceFiles do
  4896. for I := 0 to Count - 1 do
  4897. with TSourceFile (Items [I]) do
  4898. TestChange;
  4899. InChangeNotification := False;
  4900. end;
  4901. end;
  4902. procedure TMainForm.ResetProjectSettings;
  4903. begin
  4904. ProjectTarget := ptRegular;
  4905. UseDataVar := False;
  4906. DataVar := '';
  4907. DataVarCopy := True;
  4908. DataVarCopyIfArchived := True;
  4909. Pack := False;
  4910. PackVar := '';
  4911. GCCSwitches := '-Os -Wall -W -Wwrite-strings -ffunction-sections -fdata-sections';
  4912. AsSwitches := '';
  4913. AsmSwitches := '-g -t';
  4914. DebugInfo := False;
  4915. StdLib := True;
  4916. InitBSS := True;
  4917. OptimizeNOPs := True;
  4918. OptimizeReturns := True;
  4919. OptimizeBranches := True;
  4920. OptimizeMoves := True;
  4921. OptimizeTests := True;
  4922. OptimizeCalculations := True;
  4923. RemoveUnusedSections := True;
  4924. CutUnusedRanges := True;
  4925. ReorderSections := True;
  4926. MergeConstants := True;
  4927. OutputBin := False;
  4928. CommandLine := '';
  4929. PostBuildProcessFile := '';
  4930. if Assigned (PredefinedLibOptions) then
  4931. with PredefinedLibOptions do begin
  4932. CalcDests := [cdTI89, cdTI92Plus, cdV200];
  4933. OptimizeCalcConsts := False;
  4934. KernelFormat := kfNone;
  4935. UseMinAMS := True;
  4936. MinAMS := '1.00';
  4937. RelocFormat := rfAMS;
  4938. ROMCallFormat := rfDirect;
  4939. BSSRefFormat := rfKernel;
  4940. DataRefFormat := rfKernel;
  4941. UseFLineJumps := False;
  4942. UseInternalFLineEmulator := False;
  4943. UseReturnValue := False;
  4944. EnableErrorReturn := False;
  4945. SaveScreen := True;
  4946. end;
  4947. end;
  4948. procedure TMainForm.AddToRecent(const FileName: string);
  4949. var
  4950. I: Integer;
  4951. O: TRecentFileMenuItem;
  4952. begin
  4953. with RecentFiles do begin
  4954. for I := 0 to Count - 1 do
  4955. if (I >= MaxRecentFiles - 1) or (UpperCase (Strings [I]) = UpperCase (FileName)) then begin
  4956. if I = 0 then
  4957. Exit
  4958. else begin
  4959. Objects[I].Free;
  4960. Delete (I);
  4961. Break;
  4962. end;
  4963. end;
  4964. RecentFilesLine.Visible := True;
  4965. O := TRecentFileMenuItem.Create;
  4966. with O do begin
  4967. FileMenuItem := TMenuItem.Create (Self);
  4968. with FileMenuItem do begin
  4969. Caption := WithoutExt (ExtractFileName (FileName));
  4970. Hint := FileName;
  4971. OnClick := RecentFileClick;
  4972. end;
  4973. MainMenuFile.Insert (RecentFilesLine.MenuIndex + 1, FileMenuItem);
  4974. PopupMenuItem := TMenuItem.Create (Self);
  4975. with PopupMenuItem do begin
  4976. Caption := FileName;
  4977. Hint := FileName;
  4978. OnClick := RecentFileClick;
  4979. end;
  4980. RecentFilesPopup.Items.Insert (0, PopupMenuItem);
  4981. end;
  4982. InsertObject (0, FileName, O);
  4983. end;
  4984. UpdateRecent;
  4985. end;
  4986. procedure TMainForm.UpdateRecent;
  4987. begin
  4988. RecentFilesLine.Visible := RecentFiles.Count > 0;
  4989. NoFilesItem.Visible := RecentFiles.Count <= 0;
  4990. end;
  4991. procedure TMainForm.RecentFileClick(Sender: TObject);
  4992. var
  4993. I: Integer;
  4994. FileName: string;
  4995. begin
  4996. FileName := (Sender as TMenuItem).Hint;
  4997. if FileExists (FileName) then
  4998. FileOpen (FileName)
  4999. else begin
  5000. with RecentFiles do
  5001. for I := 0 to Count - 1 do
  5002. if UpperCase (Strings [I]) = UpperCase (FileName) then begin
  5003. Objects[I].Free;
  5004. Delete (I);
  5005. Break;
  5006. end;
  5007. UpdateRecent;
  5008. ShowDefaultMessageBox ('File ''' + WithoutExt (ExtractFileName (FileName)) + ''' not found.', 'Error', mtProgramError);
  5009. end;
  5010. end;
  5011. procedure TMainForm.ToolsConfigure(Sender: TObject);
  5012. var
  5013. I: Integer;
  5014. begin
  5015. with TToolsForm.Create (Self) do try
  5016. with Self.ToolsList do
  5017. for I := 0 to Count - 1 do
  5018. with ToolsList.Items.Add, TToolsListItem (Items [I]) do begin
  5019. Caption := Title;
  5020. SubItems.Add (CommandLine);
  5021. SubItems.Add (WorkingDir);
  5022. SubItems.Add (WindowStateToString (WindowState));
  5023. end;
  5024. if ShowModal = mrOK then begin
  5025. Self.ToolsList.Clear;
  5026. with ToolsList.Items do begin
  5027. ToolsLine.Visible := Count > 0;
  5028. for I := 0 to Count - 1 do
  5029. with Item [I] do
  5030. AddTool (Caption, SubItems [0], SubItems [1], StringToWindowState (SubItems [2]));
  5031. end;
  5032. SavePreferences;
  5033. end;
  5034. finally
  5035. Free;
  5036. end;
  5037. end;
  5038. procedure TMainForm.ToolClick(Sender: TObject);
  5039. var
  5040. WorkDir: PChar;
  5041. StartupInfo: TStartupInfo;
  5042. ProcessInfo: TProcessInformation;
  5043. begin
  5044. with TToolsListItem ((Sender as TMenuItem).Tag) do begin
  5045. FillChar (StartupInfo, SizeOf (StartupInfo), 0);
  5046. StartupInfo.cb := SizeOf (StartupInfo);
  5047. if Length (WorkingDir) > 0 then
  5048. WorkDir := PChar (WorkingDir)
  5049. else
  5050. WorkDir := nil;
  5051. StartupInfo.dwFlags := StartF_UseShowWindow;
  5052. case WindowState of
  5053. wsMaximized:
  5054. StartupInfo.wShowWindow := SW_SHOWMAXIMIZED;
  5055. wsMinimized:
  5056. StartupInfo.wShowWindow := SW_SHOWMINIMIZED;
  5057. else
  5058. StartupInfo.dwFlags := 0;
  5059. end;
  5060. if CreateProcess (nil, PChar (CommandLine), nil, nil, False, CREATE_NEW_PROCESS_GROUP or DETACHED_PROCESS, nil, WorkDir, StartupInfo, ProcessInfo) then begin
  5061. CloseHandle (ProcessInfo.hProcess);
  5062. CloseHandle (ProcessInfo.hThread);
  5063. end else
  5064. ShowDefaultMessageBox ('An error occurred while trying to start the application.', 'Error', mtProgramError);
  5065. end;
  5066. end;
  5067. procedure TMainForm.AddTool(const Title, CommandLine, WorkingDir: string; WindowState: TWindowState);
  5068. var
  5069. O: TToolsListItem;
  5070. begin
  5071. O := TToolsListItem (Self.ToolsList.Add);
  5072. O.Title := Title;
  5073. O.CommandLine := CommandLine;
  5074. O.WorkingDir := WorkingDir;
  5075. O.WindowState := WindowState;
  5076. O.MenuItem := TMenuItem.Create (Self);
  5077. with O.MenuItem do begin
  5078. Tag := Integer (O);
  5079. Caption := Title;
  5080. Hint := CommandLine;
  5081. OnClick := ToolClick;
  5082. end;
  5083. MainMenuTools.Insert (MainMenuTools.Count, O.MenuItem);
  5084. end;
  5085. procedure TMainForm.ProjectTreeStartDrag(Sender: TObject;
  5086. var DragObject: TDragObject);
  5087. begin
  5088. DragObject := TNoImageDragObject.Create (Sender as TControl);
  5089. end;
  5090. procedure TMainForm.UpdateProgramOutput;
  5091. begin
  5092. ActionProjectShowProgramOutput.Enabled := (MainConsole.LastOutSize > 2) or (MainConsole.LastErrSize > 2);
  5093. end;
  5094. procedure TMainForm.ShowProgramOutput(Sender: TObject);
  5095. begin
  5096. with TProgramOutputForm.Create (Self) do try
  5097. OutputMemo.Text := MainConsole.LastOutText;
  5098. ErrorMemo.Text := MainConsole.LastErrText;
  5099. ShowModal;
  5100. finally
  5101. Free;
  5102. end;
  5103. end;
  5104. procedure TMainForm.ClearDebugInfo;
  5105. begin
  5106. end;
  5107. procedure TMainForm.FileNewFolder(Sender: TObject);
  5108. var
  5109. ParentNode,
  5110. Node: TTreeNode;
  5111. Folder: TFolder;
  5112. begin
  5113. ParentNode := ProjectTree.Selected;
  5114. while Assigned (ParentNode) and Assigned (ParentNode.Data) and (not (TObject (ParentNode.Data) is TFolder)) do
  5115. ParentNode := ParentNode.Parent;
  5116. if Assigned (ParentNode) and Assigned (ParentNode.Parent) then begin
  5117. Folder := TFolder.Create;
  5118. Node := ProjectTree.Items.AddChildObject (ParentNode, 'New Folder', Folder);
  5119. Folder.TreeItem := Node;
  5120. with Node do begin
  5121. ImageIndex := 0;
  5122. SelectedIndex := 1;
  5123. Selected := True;
  5124. EditText;
  5125. end;
  5126. end;
  5127. end;
  5128. function TMainForm.GetSourceTypeFolder(Node: TTreeNode): TTreeNode;
  5129. begin
  5130. if Assigned (Node) and Assigned (Node.Parent) then begin
  5131. Result := Node;
  5132. while Assigned (Result) and Assigned (Result.Data) do
  5133. Result := Result.Parent;
  5134. end else
  5135. Result := nil;
  5136. end;
  5137. function TMainForm.FindFileInsertionPoint(ParentNode: TTreeNode): TTreeNode;
  5138. begin
  5139. if Assigned (ParentNode) then begin
  5140. Result := ParentNode.GetFirstChild;
  5141. while Assigned (Result) and Assigned (Result.Data) and (TObject (Result.Data) is TSourceFile) do
  5142. Result := Result.GetNextSibling;
  5143. end else
  5144. Result := nil;
  5145. end;
  5146. function TMainForm.CreateFileNode(ParentNode: TTreeNode; SourceFile: TSourceFile): TTreeNode;
  5147. begin
  5148. if Assigned (SourceFile.Folder) then
  5149. ParentNode := SourceFile.Folder.TreeItem;
  5150. if Assigned (ParentNode) then begin
  5151. Result := FindFileInsertionPoint (ParentNode);
  5152. if Assigned (Result) then
  5153. Result := ProjectTree.Items.InsertObject (Result, SourceFile.SourceName, SourceFile)
  5154. else
  5155. Result := ProjectTree.Items.AddChildObject (ParentNode, SourceFile.SourceName, SourceFile);
  5156. end else
  5157. Result := nil;
  5158. end;
  5159. procedure TMainForm.FileNewFile(Sender: TObject);
  5160. var
  5161. Node: TTreeNode;
  5162. begin
  5163. if Assigned (ProjectTree.Selected) then begin
  5164. Node := GetSourceTypeFolder (ProjectTree.Selected);
  5165. if Assigned (Node) then
  5166. if Node.Index = THeaderSourceFile.GetClassTreeIndex then
  5167. FileNewHeaderFile (Sender)
  5168. else if Node.Index = TCSourceFile.GetClassTreeIndex then
  5169. FileNewCSourceFile (Sender)
  5170. else if Node.Index = TGNUAsmSourceFile.GetClassTreeIndex then
  5171. FileNewGNUAssemblerSourceFile (Sender)
  5172. else if (ssA68k in SpecialSupport) and (Node.Index = TAsmSourceFile.GetClassTreeIndex) then
  5173. FileNewAssemblerSourceFile (Sender)
  5174. else if (ssQuill in SpecialSupport) and (Node.Index = TQuillSourceFile.GetClassTreeIndex) then
  5175. FileNewQuillSourceFile (Sender)
  5176. else if Node.Index = TNormalTextSourceFile.GetClassTreeIndex then
  5177. FileNewTextFile (Sender);
  5178. end;
  5179. end;
  5180. function TMainForm.GetSelectedFolder(SourceClass: TSourceFileClass): TFolder;
  5181. var
  5182. Node: TTreeNode;
  5183. begin
  5184. Result := nil;
  5185. Node := ProjectTree.Selected;
  5186. while Assigned (Node) and (Node <> TopNode.Item [SourceClass.GetClassTreeIndex]) do begin
  5187. if (not Assigned (Result)) and Assigned (Node.Data) and (TObject (Node.Data) is TFolder) then
  5188. Result := Node.Data;
  5189. Node := Node.Parent;
  5190. end;
  5191. if not Assigned (Node) then
  5192. Result := nil;
  5193. end;
  5194. procedure TMainForm.ErrorListKeyDown(Sender: TObject; var Key: Word;
  5195. Shift: TShiftState);
  5196. var
  5197. S: string;
  5198. Item: TListItem;
  5199. begin
  5200. if ((Key = VK_INSERT) or (Key = Ord('C'))) and (Shift = [ssCtrl]) then
  5201. with ErrorList do begin
  5202. S := '';
  5203. Item := Selected;
  5204. while Assigned (Item) do begin
  5205. S := S + Item.Caption + #13#10;
  5206. Item := GetNextItem (Item, sdAll, [isSelected]);
  5207. end;
  5208. Clipboard.AsText := S;
  5209. end;
  5210. end;
  5211. {$IFDEF CODINGEXT}
  5212. procedure TMainForm.InitCodingExt;
  5213. var
  5214. ActionFindSymbol: TAction;
  5215. begin
  5216. // Find Symbol declaration tool
  5217. ActionFindSymbol := TAction.Create(Self);
  5218. with ActionFindSymbol do
  5219. begin
  5220. ActionList := Actions;
  5221. Caption := 'F&ind Symbol Declaration';
  5222. Category := 'Extension';
  5223. OnExecute := ActionFindSymbolExecute;
  5224. end;
  5225. InsertsAction(Self, [OpenFileAtCursor1, OpenFileatCursor2], ActionFindSymbol);
  5226. end;
  5227. procedure TMainForm.ActionFindSymbolExecute(Sender: TObject);
  5228. begin
  5229. CompForm.FindSymbolDecl;
  5230. end;
  5231. {$ENDIF}
  5232. end.