MainUnit.pas 170 KB

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