MainUnit.pas 172 KB

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