MainUnit.pas 178 KB

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