MainUnit.pas 171 KB

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