MainUnit.pas 172 KB

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