MainUnit.pas 173 KB

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