1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107 |
- using System;
- using System.Security.Cryptography;
- using System.Text;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Reflection;
- using System.Threading;
- using System.Threading.Tasks;
- using Beefy;
- using Beefy.widgets;
- using Beefy.gfx;
- using Beefy.theme;
- using Beefy.theme.dark;
- using Beefy.sys;
- using Beefy.events;
- using Beefy.geom;
- using Beefy.res;
- using System.Diagnostics;
- using Beefy.utils;
- using IDE.Debugger;
- using IDE.Compiler;
- using IDE.Util;
- using IDE.ui;
- using IDE.util;
- [AttributeUsage(.Method, .ReflectAttribute | .AlwaysIncludeTarget, ReflectUser=.All)]
- struct IDECommandAttribute : Attribute
- {
- }
- namespace IDE
- {
- public class WindowData
- {
- public DrawLayer mOverlayLayer ~ delete _;
- }
- enum SourceShowType
- {
- ShowExisting,
- ShowExistingInActivePanel,
- New,
- Temp,
- }
- enum Verbosity
- {
- Default,
- Quiet,
- Minimal,
- Normal,
- Detailed,
- Diagnostic
- }
- class DeferredUserRequest
- {
- }
- class DeferredShowPCLocation : DeferredUserRequest
- {
- public int32 mStackIdx;
- public this(int32 stackIdx)
- {
- mStackIdx = stackIdx;
- }
- }
- enum BeefVerb
- {
- None,
- Open,
- New,
- OpenOrNew,
- Test,
- Run,
- GetVersion
- }
- enum HotResolveState
- {
- None,
- Pending,
- PendingWithDataChanges
- }
- public class IDETabbedView : DarkTabbedView
- {
- public ~this()
- {
- if (gApp.mActiveDocumentsTabbedView == this)
- gApp.mActiveDocumentsTabbedView = null;
- }
- }
- public class IDEApp : BFApp
- {
- public static String sRTVersionStr = "042";
- #if BF_PLATFORM_WINDOWS
- public static readonly String sPlatform64Name = "Win64";
- public static readonly String sPlatform32Name = "Win32";
- #elif BF_PLATFORM_LINUX
- public static readonly String sPlatform64Name = "Linux64";
- public static readonly String sPlatform32Name = "Linux32";
- #elif BF_PLATFORM_OSX
- public static readonly String sPlatform64Name = "macOS";
- public static readonly String sPlatform32Name = null;
- #else
- public static readonly String sPlatform64Name = "Unknown64";
- public static readonly String sPlatform32Name = "Unknown32";
- #endif
- public const uint32 cDialogOutlineLightColor = 0xFF404040;
- public const uint32 cDialogOutlineDarkColor = 0xFF202020;
- public static bool sExitTest;
- public Verbosity mVerbosity = .Default;
- public BeefVerb mVerb;
- public bool mDbgCompileDump;
- public int mDbgCompileIdx = -1;
- public String mDbgCompileDir ~ delete _;
- public String mDbgVersionedCompileDir ~ delete _;
- public DateTime mDbgHighestTime;
- public bool mForceFirstRun;
- public bool mIsFirstRun;
- public int? mTargetExitCode;
- public FileVersionInfo mVersionInfo ~ delete _;
- //public ToolboxPanel mToolboxPanel;
- public Monitor mMonitor = new Monitor() ~ delete _;
- public Thread mMainThread;
- public PropertiesPanel mPropertiesPanel;
- public Font mTinyCodeFont ~ delete _;
- public Font mCodeFont ~ delete _;
- protected bool mInitialized;
- public bool mConfig_NoIR;
- public bool mFailed;
- public bool mLastTestFailed;
- public bool mLastCompileFailed;
- public bool mLastCompileSucceeded;
- public bool mLastCompileHadMessages;
- public bool mPauseOnExit;
- public bool mDbgDelayedAutocomplete;
- public BeefConfig mBeefConfig = new BeefConfig() ~ delete _;
- public List<String> mDeferredFails = new .() ~ DeleteContainerAndItems!(_);
- public String mInitialCWD = new .() ~ delete _;
- public Commands mCommands = new .() ~ delete _;
- public KeyChordState mKeyChordState ~ delete _;
- public WidgetWindow mMainWindow;
- public DarkDockingFrame mDockingFrame;
- public MainFrame mMainFrame;
- public GlobalUndoManager mGlobalUndoManager = new GlobalUndoManager() ~ delete _;
- public SourceControl mSourceControl = new SourceControl() ~ delete _;
- public WidgetWindow mPopupWindow;
-
- public IDETabbedView mActiveDocumentsTabbedView;
- public static new IDEApp sApp;
- public Image mTransparencyGridImage ~ delete _;
- public Image mSquiggleImage ~ delete _;
- public Image mCircleImage ~ delete _;
- public OutputPanel mOutputPanel;
- public ImmediatePanel mImmediatePanel;
- public FindResultsPanel mFindResultsPanel;
- public WatchPanel mAutoWatchPanel;
- public WatchPanel mWatchPanel;
- public MemoryPanel mMemoryPanel;
- public CallStackPanel mCallStackPanel;
- public BreakpointPanel mBreakpointPanel;
- public ModulePanel mModulePanel;
- public ThreadPanel mThreadPanel;
- public ProfilePanel mProfilePanel;
- public ProjectPanel mProjectPanel;
- public ClassViewPanel mClassViewPanel;
- public Widget mLastActivePanel;
- public SourceViewPanel mLastActiveSourceViewPanel;
- public AutoCompletePanel mAutoCompletePanel;
-
- public Rect mRequestedWindowRect = Rect(64, 64, 1200, 1024);
- public BFWindow.ShowKind mRequestedShowKind;
- public WakaTime mWakaTime ~ delete _;
- public Settings mSettings = new Settings() ~ delete _;
- public Workspace mWorkspace = new Workspace() ~ delete _;
- public FileWatcher mFileWatcher = new FileWatcher() ~ delete _;
- public int mLastFileChangeId;
- public bool mHaveSourcesChangedInternallySinceLastCompile;
- public bool mHaveSourcesChangedExternallySinceLastCompile;
- public String mConfigName = new String() ~ delete _;
- public String mPlatformName = new String() ~ delete _;
- public Targets mTargets = new Targets() ~ delete _;
- public DebugManager mDebugger ~ delete _;
- public String mSymSrvStatus = new String() ~ delete _;
- public Action<String> mPendingDebugExprHandler = null;
- public bool mIsImmediateDebugExprEval;
- public BookmarkManager mBookmarkManager = new BookmarkManager() ~ delete _;
- public HistoryManager mHistoryManager = new HistoryManager() ~ delete _;
- public Stopwatch mCompileAndRunStopwatch ~ delete _;
- // The Beef build system only gets populated when a build is requested,
- // but the Clang build system keeps up-to-date with the projects' files
- // and watches for file changes
- public BfSystem mBfBuildSystem ~ delete _;
- public BfCompiler mBfBuildCompiler;
- public int mCompileSinceCleanCount;
- public BuildContext mBuildContext ~ delete _;
- #if IDE_C_SUPPORT
- public ClangCompiler mDepClang ~ delete _;
- #endif
- // The Beef resolve system is up-to-date with the projects' files,
- // but the Clang resolver only has open files in it
- public bool mNoResolve = false;
- public BfSystem mBfResolveSystem ~ delete _;
- public BfCompiler mBfResolveCompiler;
- public BfResolveHelper mBfResolveHelper ~ delete _;
- #if IDE_C_SUPPORT
- public ClangCompiler mResolveClang;
- #endif
- public SpellChecker mSpellChecker;
- public List<String> mExternalChangeDeferredOpen = new List<String>() ~ DeleteContainerAndItems!(_);
- public SettingHistoryManager mLaunchHistoryManager = new SettingHistoryManager(true) ~ delete _;
- public SettingHistoryManager mFindAndReplaceHistoryManager = new SettingHistoryManager(true) ~ delete _;
- List<Object> mIdleDeferredDeletes = new List<Object>() ~ delete _;
- public bool mCompilingBeef = false;
- public bool mWantsClean = false;
- public bool mWantsBeefClean = false;
- public bool mWantsRehupCallstack = false;
- public bool mDebugAutoBuild = false;
- public bool mDebugAutoRun = false;
- public bool mDisableBuilding;
- public int32 mDebugAutoShutdownCounter;
- public bool mTargetDidInitBreak = false;
- public bool mTargetHadFirstBreak = false;
- public bool mTargetStartWithStep = false;
- public Breakpoint mMainBreakpoint;
- public Breakpoint mMainBreakpoint2;
- public bool mInDisassemblyView;
- public bool mIsAttachPendingSourceShow;
- public bool mStepOverExternalFiles;
- public bool mRunningTestScript;
- public bool mStartedWithTestScript;
- public bool mExitWhenTestScriptDone = true;
- public ScriptManager mScriptManager = new ScriptManager() ~ delete _;
- public TestManager mTestManager;
- public bool mExecutionPaused = false;
- public HotResolveState mHotResolveState;
- public int mHotResolveTryIdx;
- public bool mDebuggerPerformingTask = false; // Executing an expression, loading from symbol server
- public int32 mForegroundTargetCountdown = 0;
- public int32 mDebuggerContinueIdx;
- public SysMenu mWindowMenu;
- public List<SourceViewPanel> mPostRemoveUpdatePanels = new .() ~ delete _;
- public List<String> mRecentlyDisplayedFiles = new List<String>() ~ DeleteContainerAndItems!(_);
- public List<SysMenu> mRecentlyDisplayedFilesMenuItems = new List<SysMenu>() ~ delete _;
- public Dictionary<BFWindow, WindowData> mWindowDatas = new Dictionary<BFWindow, WindowData>() ~ delete _;
- public Dictionary<String, FileEditData> mFileEditData = new Dictionary<String, FileEditData>() ~
- {
- for (var editDataPair in mFileEditData)
- {
- delete editDataPair.key;
- editDataPair.value.Deref();
- }
- delete _;
- };
- public int32 mFileDataDataRevision;
-
- /*public Point mLastAbsMousePos;
- public Point mLastRelMousePos;
- public int32 mMouseStillTicks;
- public Widget mLastMouseWidget;*/
- public int32 mCloseDelay;
- public FileChangedDialog mFileChangedDialog;
- public FindAndReplaceDialog mFindAndReplaceDialog;
- public LaunchDialog mLaunchDialog;
- public SymbolReferenceHelper mSymbolReferenceHelper;
- public WrappedMenuValue mViewWhiteSpace = .(false);
- public bool mEnableGCCollect = true;
- public bool mDbgFastUpdate;
- public bool mTestEnableConsole = false;
- public bool mTestIncludeIgnored = false;
- public ProfileInstance mLongUpdateProfileId;
- public uint32 mLastLongUpdateCheck;
- public uint32 mLastLongUpdateCheckError;
- bool mRunTest;
- int mRunTestDelay;
- bool mEnableRunTiming = false; ///
- ProfileInstance mRunTimingProfileId;
- bool mDoingRunTiming;
- bool mProfileCompile = false;
- ProfileInstance mProfileCompileProfileId;
- #if !CLI
- public IPCHelper mIPCHelper ~ delete _;
- public bool mIPCHadFocus;
- #endif
- int32 mProcessAttachId;
- #if BF_PLATFORM_WINDOWS
- Windows.EventHandle mProcessAttachHandle;
- #endif
- String mCrashDumpPath ~ delete _;
- bool mShowedFirstDocument = false;
- class LaunchData
- {
- public String mTargetPath = new .() ~ delete _;
- public String mArgs ~ delete _;
- public String mWorkingDir ~ delete _;
- public bool mPaused = false;
- }
- LaunchData mLaunchData ~ delete _;
- DeferredUserRequest mDeferredUserRequest ~ delete _;
- enum DeferredOpenKind
- {
- None,
- File,
- Workspace,
- NewWorkspace,
- NewWorkspaceOrProject,
- CrashDump,
- DebugSession
- }
- DeferredOpenKind mDeferredOpen;
- String mDeferredOpenFileName;
- public class ExecutionCmd
- {
- public bool mOnlyIfNotFailed;
- }
- public class BuildCompletedCmd : ExecutionCmd
- {
- public Stopwatch mStopwatch ~ delete _;
- public String mHotProjectName ~ delete _;
- public bool mFailed;
- #if IDE_C_SUPPORT
- public HashSet<String> mClangCompiledFiles = new HashSet<String>() ~ DeleteContainerAndItems!(_);
- #endif
- }
- class ProcessBfCompileCmd : ExecutionCmd
- {
- public BfPassInstance mBfPassInstance;
- public bool mRunAfter;
- public Project mHotProject;
- public Stopwatch mStopwatch ~ delete _;
- public Profiler mProfiler;
- public ProfileCmd mProfileCmd ~ delete _;
- public bool mHadBeef;
- public ~this()
- {
- }
- }
- class ProfileCmd : ExecutionCmd
- {
- public int mThreadId;
- public String mDesc ~ delete _;
- public int mSampleRate;
- }
- class StartDebugCmd : ExecutionCmd
- {
- public bool mWasCompiled;
- public this()
- {
- }
- }
- public class TargetCompletedCmd : ExecutionCmd
- {
- public Project mProject;
- public bool mIsReady = true;
- public this(Project project)
- {
- mProject = project;
- }
- public ~this()
- {
- }
- }
- public enum ArgsFileKind
- {
- None,
- UTF8,
- UTF16WithBom
- }
- public class ExecutionQueueCmd : ExecutionCmd
- {
- public String mFileName ~ delete _;
- public String mArgs ~ delete _;
- public String mWorkingDir ~ delete _;
- public Dictionary<String, String> mEnvVars ~ DeleteDictionyAndKeysAndItems!(_);
- public ArgsFileKind mUseArgsFile;
- public int32 mParallelGroup = -1;
- public bool mIsTargetRun;
- }
- public List<ExecutionCmd> mExecutionQueue = new List<ExecutionCmd>() ~ DeleteContainerAndItems!(_);
- public class ExecutionInstance
- {
- public SpawnedProcess mProcess /*~ delete _*/;
- public List<String> mDeferredOutput = new List<String>() ~ DeleteContainerAndItems!(_);
- public Stopwatch mStopwatch = new Stopwatch() ~ delete _;
- public String mTempFileName ~ delete _;
- public int32 mParallelGroup = -1;
- public Task<String> mReadTask /*~ delete _*/;
- public Action<Task<String>> mOnReadTaskComplete /*~ delete _*/;
- public Task<String> mErrorTask /*~ delete _*/;
- public Action<Task<String>> mOnErrorTaskComplete /*~ delete _*/;
- public Monitor mMonitor = new Monitor() ~ delete _;
- public Thread mOutputThread;
- public Thread mErrorThread;
- public int? mExitCode;
- public bool mAutoDelete = true;
- public bool mCanceled;
- public bool mIsTargetRun;
- public ~this()
- {
- delete mProcess;
- /*if (mProcess != null)
- mProcess.Close();*/
- if (mOutputThread != null)
- mOutputThread.Join();
- delete mOutputThread;
- if (mErrorThread != null)
- mErrorThread.Join();
- delete mErrorThread;
- delete mReadTask;
- delete mOnReadTaskComplete;
- delete mErrorTask;
- delete mOnErrorTaskComplete;
- }
- public void Cancel()
- {
- mCanceled = true;
- mProcess.Kill(0, .KillChildren);
- }
- }
- List<ExecutionInstance> mExecutionInstances = new List<ExecutionInstance>() ~ DeleteContainerAndItems!(_);
- public int32 mHotIndex = 0;
- private int32 mStepCount;
- private int32 mNoDebugMessagesTick;
- public bool IsCompiling
- {
- get
- {
- return (mExecutionInstances.Count > 0) || (mExecutionQueue.Count > 0) || (mBuildContext != null);
- }
- }
- public bool EnableGCCollect
- {
- get
- {
- return mEnableGCCollect;
- }
- set
- {
- mEnableGCCollect = value;
- //GC.SetAutoCollectPeriod(mEnableGCCollect ? 2000 : -1);
- GC.SetAutoCollectPeriod(mEnableGCCollect ? 20 : -1);
- GC.SetCollectFreeThreshold(mEnableGCCollect ? 64*1024*1024 : -1);
- }
- }
- public this()
- {
- sApp = this;
- gApp = this;
- mMainThread = Thread.CurrentThread;
- #if !CLI
- mDebugger = new DebugManager();
- mVerb = .OpenOrNew;
- #endif
- //BfParser_Go();///
- mScriptManager.AddTarget(this);
- }
- public static this()
- {
- //Profiler.StartSampling();
- }
- public void GetBfSystems(List<BfSystem> systems)
- {
- systems.Add(mBfBuildSystem);
- if (mBfResolveSystem != null)
- systems.Add(mBfResolveSystem);
- }
- public void GetBfCompilers(List<BfCompiler> compiler)
- {
- compiler.Add(mBfBuildCompiler);
- compiler.Add(mBfResolveCompiler);
- }
- public bool HaveSourcesChanged()
- {
- return mHaveSourcesChangedInternallySinceLastCompile || mHaveSourcesChangedExternallySinceLastCompile;
- }
- public void MarkWatchesDirty()
- {
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.MarkWatchesDirty(false);
- });
- }
- void PCChanged()
- {
- var disasmPanel = TryGetDisassemblyPanel();
- if (disasmPanel != null)
- disasmPanel.mLocationDirty = true;
- mDebugger.mCallStackDirty = true;
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.MarkWatchesDirty(true, !mTargetHadFirstBreak);
- });
- mMemoryPanel.MarkViewDirty();
- mCallStackPanel.MarkCallStackDirty();
- mThreadPanel.MarkThreadsDirty();
- mDebugger.CheckCallStack();
- // If we do a "PCChanged" from the execution of a method in the Immediate panel, don't move
- // the focus away from the Immediate edit widget
- bool setFocus = true;
- for (var window in mWindows)
- {
- var widgetWindow = window as WidgetWindow;
- if ((widgetWindow != null) && (widgetWindow.mHasFocus))
- {
- if (widgetWindow.mFocusWidget is ImmediateWidget)
- {
- setFocus = false;
- }
- }
- }
- if (mRunningTestScript)
- setFocus = true;
- ShowPCLocation(mDebugger.mActiveCallStackIdx, false, false, false, setFocus);
- }
- public ~this()
- {
- #if !CLI
- if (!mStartedWithTestScript && !mForceFirstRun)
- {
- mSettings.Save();
- SaveDefaultLayoutData();
- }
- #endif
- /*WithTabs(scope (tabButton) =>
- {
- var panel = tabButton.mContent as Panel;
- if (panel != null)
- {
- if (!panel.mAutoDelete)
- {
- // Is part of the panel list, clear mContent so we don't double-delete
- tabButton.mContent = null;
- }
- }
- });*/
- mixin RemoveAndDelete(var widget)
- {
- Widget.RemoveAndDelete(widget);
- widget = null;
- }
-
- RemoveAndDelete!(mProjectPanel);
- RemoveAndDelete!(mClassViewPanel);
- RemoveAndDelete!(mOutputPanel);
- RemoveAndDelete!(mImmediatePanel);
- RemoveAndDelete!(mFindResultsPanel);
- RemoveAndDelete!(mAutoWatchPanel);
- RemoveAndDelete!(mWatchPanel);
- RemoveAndDelete!(mMemoryPanel);
- RemoveAndDelete!(mCallStackPanel);
- RemoveAndDelete!(mBreakpointPanel);
- RemoveAndDelete!(mModulePanel);
- RemoveAndDelete!(mThreadPanel);
- RemoveAndDelete!(mProfilePanel);
- RemoveAndDelete!(mPropertiesPanel);
- RemoveAndDelete!(mAutoCompletePanel);
- if (mSymbolReferenceHelper != null)
- mSymbolReferenceHelper.Close();
- if (mBfBuildCompiler != null)
- mBfBuildCompiler.CancelBackground();
- if (mBfResolveCompiler != null)
- mBfResolveCompiler.CancelBackground();
- #if IDE_C_SUPPORT
- mDepClang.CancelBackground();
- mResolveClang.CancelBackground();
- #endif
- /*if (mMainBreakpoint != null)
- {
- mMainBreakpoint.Dispose();
- mMainBreakpoint = null;
- }*/
- /*delete mBfBuildCompiler;
- delete mBfBuildSystem;
- delete mDepClang;
-
-
- delete mBfResolveCompiler;
- delete mBfResolveSystem;
- delete mResolveClang;
- delete mSpellChecker;
- //base.Dispose();
- delete mDebugger;
- delete ThemeFactory.mDefault;*/
- for (var val in mWindowDatas.Values)
- delete val;
- ProcessIdleDeferredDeletes();
- // Get rid of panels
- ProcessDeferredDeletes();
- delete mBfBuildCompiler;
- delete mBfResolveCompiler;
- #if IDE_C_SUPPORT
- delete mResolveClang;
- #endif
- delete mSpellChecker;
- // Clear these out, for delete ordering purposes
- ProcessDeferredDeletes();
- }
- public bool IsCrashDump
- {
- get
- {
- return mCrashDumpPath != null;
- }
- }
- public override void ShutdownCompleted()
- {
- base.ShutdownCompleted();
- }
- public override void Shutdown()
- {
- if ((mDebugger != null) && (mDebugger.mIsRunning))
- {
- mDebugger.DisposeNativeBreakpoints();
- mDebugger.Detach();
- mDebugger.mIsRunning = false;
- mExecutionPaused = false;
- }
- base.Shutdown();
- }
- public override void Run()
- {
- base.Run();
- }
- public void Cmd_NewFileView()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- ShowSourceFile(sourceViewPanel.mFilePath, sourceViewPanel.mProjectSource, SourceShowType.New);
- }
- }
- public void IdleDeferDelete(Object obj)
- {
- mIdleDeferredDeletes.Add(obj);
- }
- void ProcessIdleDeferredDeletes()
- {
- if (((mBfBuildCompiler != null) && mBfBuildCompiler.HasQueuedCommands()) ||
- ((mBfResolveCompiler != null) && (mBfResolveCompiler.HasQueuedCommands()))
- #if IDE_C_SUPPORT
- || (mDepClang.HasQueuedCommands()) ||
- (mResolveClang.HasQueuedCommands())
- #endif
- )
- return;
- for (var obj in mIdleDeferredDeletes)
- delete obj;
- mIdleDeferredDeletes.Clear();
- }
- public void DoOpenFile()
- {
- #if !CLI
- String fullDir = scope .();
- let sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- Path.GetDirectoryPath(sourceViewPanel.mFilePath, fullDir);
- }
- else if ((gApp.mDebugger.mRunningPath != null) && (!mWorkspace.IsInitialized))
- {
- Path.GetDirectoryPath(gApp.mDebugger.mRunningPath, fullDir);
- }
- var fileDialog = scope OpenFileDialog();
- fileDialog.Title = "Open File";
- fileDialog.Multiselect = true;
- fileDialog.ValidateNames = true;
- if (!fullDir.IsEmpty)
- fileDialog.InitialDirectory = fullDir;
- mMainWindow.PreModalChild();
- if (fileDialog.ShowDialog(GetActiveWindow()).GetValueOrDefault() == .OK)
- {
- for (String openFileName in fileDialog.FileNames)
- {
- //openFileName.Replace('\\', '/');
- AddRecentFile(.OpenedFile, openFileName);
- ShowSourceFile(openFileName);
- }
- }
- #endif
- }
- public void OpenWorkspace(StringView openFileName)
- {
- CloseWorkspace();
- mWorkspace.mDir = new String();
- Path.GetDirectoryPath(openFileName, mWorkspace.mDir);
- mWorkspace.mName = new String();
- Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
- LoadWorkspace(.OpenOrNew);
- FinishShowingNewWorkspace();
- }
- public void DoOpenWorkspace()
- {
- #if !CLI
- if (mDeferredOpenFileName != null)
- {
- OpenWorkspace(mDeferredOpenFileName);
- DeleteAndNullify!(mDeferredOpenFileName);
- return;
- }
- var folderDialog = scope FolderBrowserDialog();
- var initialDir = scope String();
- if (mInstallDir.Length > 0)
- Path.GetDirectoryPath(.(mInstallDir, 0, mInstallDir.Length - 1), initialDir);
- initialDir.Concat(Path.DirectorySeparatorChar, "Samples");
- folderDialog.SelectedPath = initialDir;
- if (folderDialog.ShowDialog(GetActiveWindow()).GetValueOrDefault() == .OK)
- {
- var selectedPath = scope String..AppendF(folderDialog.SelectedPath);
- selectedPath.Append(Path.DirectorySeparatorChar);
- selectedPath.Append("BeefSpace.toml");
- String.NewOrSet!(mDeferredOpenFileName, selectedPath);
- mDeferredOpen = .Workspace;
- }
- #endif
- }
- public void DoOpenDebugSession(StringView filePath)
- {
- let data = scope StructuredData();
- if (data.Load(filePath) case .Err)
- {
- CreateDefaultLayout();
- OutputErrorLine("Failed to load debug session '{}'", filePath);
- return;
- }
- AddRecentFile(.OpenedDebugSession, filePath);
- NewDebugSession(true);
- let project = mWorkspace.mProjects[0];
- project.mProjectPath.Set(filePath);
- LoadWorkspaceUserData(data);
- using (data.Open("DebugSession"))
- {
- project.Deserialize(data);
- }
- }
- public void DoOpenDebugSession()
- {
- #if !CLI
- if (mDeferredOpenFileName != null)
- {
- CloseWorkspace();
- DoOpenDebugSession(mDeferredOpenFileName);
- FinishShowingNewWorkspace(false);
- DeleteAndNullify!(mDeferredOpenFileName);
- return;
- }
- var fileDialog = scope OpenFileDialog();
- fileDialog.Title = "Open Debug Session";
- fileDialog.SetFilter("Debug Session (*.bfdbg)|*.bfdbg|All files (*.*)|*.*");
- fileDialog.ValidateNames = true;
- mMainWindow.PreModalChild();
- if (fileDialog.ShowDialog(GetActiveWindow()).GetValueOrDefault() == .OK)
- {
- for (String openFileName in fileDialog.FileNames)
- {
- String.NewOrSet!(mDeferredOpenFileName, openFileName);
- mDeferredOpen =.DebugSession;
- break;
- }
- }
- #endif
- }
- public void OpenCrashDump(StringView path)
- {
- AddRecentFile(.OpenedCrashDump, path);
- StopDebugging();
- String.NewOrSet!(mCrashDumpPath, path);
- if (mDebugger.OpenMiniDump(mCrashDumpPath))
- {
- mDebugger.mIsRunning = true;
- mExecutionPaused = false; // Make this false so we can detect a Pause immediately
- }
- else
- {
- Fail(StackStringFormat!("Failed to load minidump '{0}'", mCrashDumpPath));
- DeleteAndNullify!(mCrashDumpPath);
- }
- }
- public void DoOpenCrashDump()
- {
- #if !CLI
- if (mDeferredOpenFileName != null)
- {
- OpenCrashDump(mDeferredOpenFileName);
- DeleteAndNullify!(mDeferredOpenFileName);
- return;
- }
- var fileDialog = scope OpenFileDialog();
- fileDialog.Title = "Open Crash Dump";
- fileDialog.SetFilter("Crash Dump (*.dmp)|*.dmp|All files (*.*)|*.*");
- fileDialog.ValidateNames = true;
- mMainWindow.PreModalChild();
- if (fileDialog.ShowDialog(GetActiveWindow()).GetValueOrDefault() == .OK)
- {
- for (String openFileName in fileDialog.FileNames)
- {
- OpenCrashDump(openFileName);
- break;
- }
- }
- #endif
- }
- public void CheckProjectRelativePath(String path)
- {
- if (path.Length < 2)
- return;
- if ((path[0] == '\\') || (path[0] == '/') || (path[1] == ':'))
- return;
- for (var project in mWorkspace.mProjects)
- {
- String testPath = scope String();
- testPath.Append(project.mProjectDir);
- testPath.Append(Path.DirectorySeparatorChar);
- testPath.Append(path);
- if (File.Exists(testPath))
- {
- path.Set(testPath);
- return;
- }
- }
- }
- public void PerformAction(String cmdStr)
- {
- List<String> cmds = scope List<String>();
- int strIdx = 0;
- while (true)
- {
- String str = scope:: String();
- Utils.ParseSpaceSep(cmdStr, ref strIdx, str);
- if (str.IsEmpty)
- break;
- cmds.Add(str);
- }
- if (cmds.Count == 0)
- return;
- switch (cmds[0])
- {
- case "ShowCode":
- if (cmds.Count < 3)
- break;
- if (var sourceViewPanel = GetActiveSourceViewPanel(true))
- sourceViewPanel.RecordHistoryLocation();
- int32 char8Idx = int32.Parse(cmds[2]).GetValueOrDefault();
- var sourceViewPanel = ShowSourceFile(cmds[1], null, SourceShowType.Temp);
- if (sourceViewPanel == null)
- return;
- var editWidgetContent = sourceViewPanel.mEditWidget.mEditWidgetContent;
- int line;
- int lineChar;
- editWidgetContent.GetLineCharAtIdx(char8Idx, out line, out lineChar);
- sourceViewPanel.ShowFileLocation(char8Idx, .Always);
- case "ShowCodeAddr":
- var sourceViewPanel = GetActiveSourceViewPanel(true);
- if (sourceViewPanel != null)
- sourceViewPanel.RecordHistoryLocation();
- int64 addr = int64.Parse(cmds[1], System.Globalization.NumberStyles.HexNumber).GetValueOrDefault();
- String fileName = scope String();
- int lineNum = 0;
- int column;
- int hotIdx;
- int defLineStart;
- int defLineEnd;
- mDebugger.GetCodeAddrInfo((int)addr, fileName, out hotIdx, out defLineStart, out defLineEnd, out lineNum, out column);
- if (fileName.Length > 0)
- {
- int showHotIdx = -1;
- if ((defLineStart == -1) || (sourceViewPanel == null) || (sourceViewPanel.HasTextChangedSinceCompile(defLineStart, defLineEnd, hotIdx)))
- showHotIdx = hotIdx;
- ShowSourceFileLocation(fileName, showHotIdx, hotIdx, lineNum, column, LocatorType.Always);
- }
- else if (addr != 0)
- {
- var disassemblyPanel = ShowDisassemblyPanel(true);
- disassemblyPanel.Show(addr);
- }
- }
- }
- public Dialog QuerySaveFiles(List<String> changedList, WidgetWindow window = null)
- {
- Dialog aDialog;
- if (changedList.Count == 1)
- {
- aDialog = ThemeFactory.mDefault.CreateDialog("Save file?", StackStringFormat!("{0} has been modified. Save before closing?", changedList[0]), DarkTheme.sDarkTheme.mIconWarning);
- }
- else
- {
- String text = scope String("The following files have been modified: ");
- text.Join(", ", changedList.GetEnumerator());
- text .Append(". Save before closing?");
- aDialog = ThemeFactory.mDefault.CreateDialog("Save files?", text, DarkTheme.sDarkTheme.mIconWarning);
- }
- return aDialog;
- }
- public bool CheckCloseWorkspace(BFWindow window, Action onSave, Action onNoSave, Action onCancel)
- {
- void DeleteDelegates()
- {
- delete onSave;
- delete onNoSave;
- delete onCancel;
- }
- if (mStopping)
- {
- DeleteDelegates();
- return true;
- }
- List<String> changedList = scope List<String>();
- if (mWorkspace.mHasChanged)
- {
- var path = scope String();
- GetWorkspaceFileName(path);
- var fileName = new String();
- Path.GetFileName(path, fileName);
- if (fileName.IsEmpty)
- fileName.Append("Workspace");
- changedList.Add(fileName);
- }
- for (var project in mWorkspace.mProjects)
- if (project.mHasChanged)
- {
- var fileName = new String();
- Path.GetFileName(project.mProjectPath, fileName);
- if (fileName.IsEmpty)
- fileName.Append(project.IsDebugSession ? "Debug Session" : "Project");
- changedList.Add(fileName);
- }
- mWorkspace.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource != null)
- {
- if ((projectSource.mEditData != null) && (projectSource.mEditData.HasTextChanged()))
- {
- var fileName = new String();
- Path.GetFileName(projectSource.mPath, fileName);
- changedList.Add(fileName);
- }
- }
-
- });
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- if (sourceViewPanel.HasUnsavedChanges())
- {
- var fileName = scope String();
- Path.GetFileName(sourceViewPanel.mFilePath, fileName);
- if (!changedList.Contains(fileName))
- changedList.Add(new String(fileName));
- }
- });
- if (changedList.Count == 0)
- {
- DeleteDelegates();
- if (!mRunningTestScript)
- SaveWorkspaceUserData(false);
- return true;
- }
- var aDialog = QuerySaveFiles(changedList);
- DeleteAndClearItems!(changedList);
- aDialog.mDefaultButton = aDialog.AddButton("Save", new (evt) =>
- {
- onSave();
- } ~ delete onSave);
- aDialog.AddButton("Don't Save", new (evt) =>
- {
- OutputLine("Changes not saved.");
- onNoSave();
- } ~ delete onNoSave);
- aDialog.mEscButton = aDialog.AddButton("Cancel", new (evt) =>
- {
- if (onCancel != null)
- onCancel();
- } ~ delete onCancel);
- aDialog.PopupWindow((WidgetWindow)window ?? mMainWindow);
- return false;
- }
- public bool AllowClose(BFWindow window)
- {
- if (mRunningTestScript)
- return true;
- return CheckCloseWorkspace(window,
- new () =>
- {
- // We use a close delay after saving so the user can see we actually saved before closing down
- if (SaveAll())
- mCloseDelay = 30;
- },
- new () =>
- {
- SaveWorkspaceUserData(false);
- mMainWindow.Close(true);
- }, null);
- }
- public bool SecondaryAllowClose(BFWindow window)
- {
- if (mRunningTestScript)
- return true;
- List<String> changedList = scope List<String>();
- defer ClearAndDeleteItems(changedList);
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- if ((sourceViewPanel.mWidgetWindow == window) && (sourceViewPanel.HasUnsavedChanges()))
- {
- var fileName = new String();
- Path.GetFileName(sourceViewPanel.mFilePath, fileName);
- changedList.Add(fileName);
- }
- });
- if (changedList.Count == 0)
- return true;
- var aDialog = QuerySaveFiles(changedList, (WidgetWindow)window);
- aDialog.mDefaultButton = aDialog.AddButton("Save", new (evt) =>
- {
- bool hadError = false;
- // We use a close delay after saving so the user can see we actually saved before closing down
- var _this = this;
- WithSourceViewPanels(scope [&] (sourceViewPanel) =>
- {
- if ((!hadError) && (sourceViewPanel.mWidgetWindow == window) && (sourceViewPanel.HasUnsavedChanges()))
- if (!_this.SaveFile(sourceViewPanel))
- hadError = true;
- });
- if (hadError)
- return;
- mMainWindow.SetForeground();
- window.Close(true);
- });
- aDialog.AddButton("Don't Save", new (evt) =>
- {
- mMainWindow.SetForeground();
- window.Close(true);
- });
- aDialog.mEscButton = aDialog.AddButton("Cancel");
- aDialog.PopupWindow((WidgetWindow)window ?? mMainWindow);
- return false;
- }
- public SourceViewPanel GetActiveSourceViewPanel(bool includeLastActive = false)
- {
- if (mRunningTestScript)
- return mLastActiveSourceViewPanel;
- var activePanel = GetActiveDocumentPanel();
- var sourceViewPanel = activePanel as SourceViewPanel;
- if (sourceViewPanel != null)
- return sourceViewPanel.GetActivePanel();
- if ((mLastActiveSourceViewPanel != null) && (includeLastActive))
- return mLastActiveSourceViewPanel.GetActivePanel();
- return null;
- }
- public TextPanel GetActiveTextPanel()
- {
- var activePanel = GetActivePanel();
- return activePanel as TextPanel;
- }
- public void RefreshVisibleViews(SourceViewPanel excludeSourceViewPanel = null)
- {
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- if ((sourceViewPanel.mParent != null) && (sourceViewPanel != excludeSourceViewPanel))
- sourceViewPanel.QueueFullRefresh(true);
- });
- }
- public bool SaveFile(ProjectSource projectSource)
- {
- if (projectSource.mEditData.HasTextChanged())
- {
- for (var user in projectSource.mEditData.mEditWidget.mEditWidgetContent.mData.mUsers)
- {
- user.MarkDirty();
- }
- using (mFileWatcher.mMonitor.Enter())
- {
- String path = scope String();
- projectSource.GetFullImportPath(path);
- String text = scope String();
- projectSource.mEditData.mEditWidget.GetText(text);
- if (!SafeWriteTextFile(path, text, true, projectSource.mEditData.mLineEndingKind))
- return false;
- mFileWatcher.OmitFileChange(path, text);
- projectSource.mEditData.mLastFileTextVersion = projectSource.mEditData.mEditWidget.Content.mData.mCurTextVersionId;
- #if IDE_C_SUPPORT
- mDepClang.FileSaved(path);
- #endif
-
- if (mWakaTime != null)
- mWakaTime.QueueFile(path, projectSource.mProject.mProjectName, true);
- }
- }
- return true;
- }
- public bool SafeWriteTextFile(StringView path, StringView text, bool showErrors = true, LineEndingKind lineEndingKind = .Default)
- {
- if (mWorkspace.IsSingleFileWorkspace)
- {
- if (mWorkspace.mCompositeFile.IsIncluded(path))
- {
- mWorkspace.mCompositeFile.Set(path, text);
- return true;
- }
- }
- StringView useText = text;
- if (lineEndingKind != .Lf)
- {
- var str = scope:: String()..Append(text);
- if (lineEndingKind == .Cr)
- str.Replace('\n', '\r');
- else
- str.Replace("\n", "\r\n");
- useText = str;
- }
- if (Utils.WriteTextFile(path, useText) case .Err)
- {
- if (gApp.mSettings.mEditorSettings.mPerforceAutoCheckout)
- mSourceControl.Checkout(path);
- Thread.Sleep(10);
- if (Utils.WriteTextFile(path, useText) case .Err)
- {
- Thread.Sleep(100);
- if (Utils.WriteTextFile(path, useText) case .Err)
- {
- if (showErrors)
- Fail(StackStringFormat!("Failed to write file '{0}'", path));
- return false;
- }
- }
- }
- return true;
- }
- public Result<void, FileError> LoadTextFile(String fileName, String outBuffer, bool autoRetry = true, delegate void() onPreFilter = null)
- {
- if (mWorkspace.IsSingleFileWorkspace)
- {
- if (mWorkspace.mCompositeFile.IsIncluded(fileName))
- {
- mWorkspace.mCompositeFile.Get(fileName, outBuffer);
- if (onPreFilter != null)
- onPreFilter();
- return .Ok;
- }
- }
- return Utils.LoadTextFile(fileName, outBuffer, autoRetry, onPreFilter);
- }
- public bool SaveFileAs(SourceViewPanel sourceViewPanel)
- {
- #if !CLI
- SaveFileDialog dialog = scope .();
- //dialog.ValidateNames = true;
- if (sourceViewPanel.mFilePath != null)
- {
- String ext = scope .();
- Path.GetExtension(sourceViewPanel.mFilePath, ext);
- dialog.DefaultExt = ext;
- String fileName = scope .();
- Path.GetFileName(sourceViewPanel.mFilePath, fileName);
- dialog.FileName = fileName;
- }
- //dialog.SetFilter("Beef projects (BeefProj.toml)|BeefProj.toml");
- let activeWindow = GetActiveWindow();
- dialog.OverwritePrompt = true;
- if (dialog.ShowDialog(activeWindow).GetValueOrDefault() != .OK)
- return false;
- if (dialog.FileNames.Count != 1)
- return false;
- String filePath = dialog.FileNames[0];
- // Same path?
- if ((sourceViewPanel.mFilePath != null) && (Path.Equals(filePath, sourceViewPanel.mFilePath)))
- return true;
- if (!SaveFile(sourceViewPanel, filePath))
- return false;
- // Kinda hacky - we lose all view information...
- CloseDocument(sourceViewPanel);
- ShowSourceFile(filePath);
- #endif
- return true;
- }
- public bool SaveFile(SourceViewPanel sourceViewPanel, String forcePath = null)
- {
- if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
- {
- if ((forcePath == null) && (sourceViewPanel.mFilePath == null))
- {
- return SaveFileAs(sourceViewPanel);
- }
- var lineEndingKind = LineEndingKind.Default;
- if (sourceViewPanel.mEditData != null)
- {
- for (var user in sourceViewPanel.mEditData.mEditWidget.mEditWidgetContent.mData.mUsers)
- {
- user.MarkDirty();
- }
- lineEndingKind = sourceViewPanel.mEditData.mLineEndingKind;
- }
- // Lock file watcher to synchronize the 'file changed' notification so we don't
- // think a file was externally saved
- using (mFileWatcher.mMonitor.Enter())
- {
- String path = forcePath ?? sourceViewPanel.mFilePath;
- String text = scope String();
- sourceViewPanel.mEditWidget.GetText(text);
- if (!SafeWriteTextFile(path, text, true, lineEndingKind))
- return false;
- mFileWatcher.OmitFileChange(path, text);
- if (forcePath == null)
- sourceViewPanel.FileSaved();
- #if IDE_C_SUPPORT
- mDepClang.FileSaved(path);
- #endif
- if (sourceViewPanel.mProjectSource != null)
- {
- if (mWakaTime != null)
- {
- mWakaTime.QueueFile(path, sourceViewPanel.mProjectSource.mProject.mProjectName, true);
- }
- }
- }
- }
- return true;
- }
- public ProjectSource FindProjectItem(ProjectFolder projectFolder, String relPath)
- {
- for (var childItem in projectFolder.mChildItems)
- {
- ProjectSource projectSource = childItem as ProjectSource;
- if (projectSource != null)
- {
- if (String.Equals(projectSource.mPath, relPath, Environment.IsFileSystemCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase))
- return projectSource;
- }
- ProjectFolder childFolder = childItem as ProjectFolder;
- if (childFolder != null)
- {
- projectSource = FindProjectItem(childFolder, relPath);
- if (projectSource != null)
- return projectSource;
- }
- }
- return null;
- }
- public Project FindProjectByName(String projectName)
- {
- for (var project in mWorkspace.mProjects)
- if (project.mProjectName == projectName)
- return project;
- return null;
- }
- public ProjectSource FindProjectSourceItem(String filePath)
- {
- for (var project in mWorkspace.mProjects)
- {
- String relPath = scope String();
- project.GetProjectRelPath(filePath, relPath);
- var projectItem = FindProjectItem(project.mRootFolder, relPath);
- if (projectItem != null)
- return projectItem;
- }
- return null;
- }
- ///
-
- void SerializeWindow(StructuredData data, WidgetWindow window)
- {
- data.Add("X", window.mNormX);
- data.Add("Y", window.mNormY);
- data.Add("Width", window.mNormWidth);
- data.Add("Height", window.mNormHeight);
- data.Add("ShowKind", window.mShowKind);
- }
- void SerializeTabbedView(StructuredData data, DarkTabbedView tabbedView, bool serializeDocs)
- {
- if (tabbedView == mActiveDocumentsTabbedView)
- data.Add("DefaultDocumentsTabbedView", true);
- data.Add("Type", "TabbedView");
- using (data.CreateArray("Tabs"))
- {
- for (var tabWidget in tabbedView.mTabs)
- {
- if (!serializeDocs)
- {
- if (tabWidget.mContent is SourceViewPanel)
- continue;
- if (tabWidget.mContent is DisassemblyPanel)
- continue;
- if (tabWidget.mContent is WelcomePanel)
- continue;
- }
- using (data.CreateObject())
- {
- var panel = tabWidget.mContent as Panel;
- if (!panel.WantsSerialization)
- continue;
- if (tabWidget.mIsActive)
- data.Add("Active", true);
- data.Add("TabLabel", tabWidget.mLabel);
- data.Add("TabWidth", tabWidget.mWantWidth / DarkTheme.sScale);
- if (var watchPanel = tabWidget.mContent as WatchPanel)
- {
- watchPanel.Serialize(data, serializeDocs);
- }
- else if (panel != null)
- {
- panel.Serialize(data);
- }
- else
- {
- var innerTabbedView = tabWidget.mContent as DarkTabbedView;
- if (innerTabbedView != null)
- {
- SerializeTabbedView(data, innerTabbedView, serializeDocs);
- }
- }
- }
- }
- }
- }
- void SerializeDockingFrame(StructuredData data, DockingFrame dockingFrame, bool serializeDocs)
- {
- data.Add("Type", "DockingFrame");
- data.Add("SplitType", (int32)dockingFrame.mSplitType);
- using (data.CreateArray("DockedWidgets"))
- {
- for (var dockedWidget in dockingFrame.mDockedWidgets)
- {
- using (data.CreateObject())
- {
- if (dockedWidget.mIsFillWidget)
- data.Add("IsFillWidget", true);
- if (!dockedWidget.mAutoClose)
- data.Add("Permanent", true);
- data.Add("RequestedWidth", dockedWidget.mRequestedWidth);
- data.Add("RequestedHeight", dockedWidget.mRequestedHeight);
- data.ConditionalAdd("SizePriority", dockedWidget.mSizePriority, 0);
- if (dockedWidget is DarkDockingFrame)
- {
- var innerDockingFrame = (DarkDockingFrame)dockedWidget;
- SerializeDockingFrame(data, innerDockingFrame, serializeDocs);
- }
- if (dockedWidget is DarkTabbedView)
- {
- var tabbedView = (DarkTabbedView)dockedWidget;
- SerializeTabbedView(data, tabbedView, serializeDocs);
- }
- }
- }
- }
- }
- bool SaveDefaultLayoutData()
- {
- if (mMainWindow == null)
- return true;
- StructuredData sd = scope StructuredData();
- sd.CreateNew();
- sd.Add("FileVersion", 1);
- using (sd.CreateObject("MainWindow"))
- {
- SerializeWindow(sd, mMainWindow);
- }
- using (sd.CreateObject("MainDockingFrame"))
- {
- SerializeDockingFrame(sd, mDockingFrame, false);
- }
- String projectUserFileName = scope String();
- GetDefaultLayoutDataFileName(projectUserFileName);
- String dataStr = scope String();
- sd.ToTOML(dataStr);
- return SafeWriteTextFile(projectUserFileName, dataStr, true);
- }
- bool LoadDefaultLayoutData()
- {
- String projectUserFileName = scope String();
- GetDefaultLayoutDataFileName(projectUserFileName);
-
- StructuredData sd = scope .();
- if (sd.Load(projectUserFileName) case .Err)
- return false;
- return LoadWorkspaceUserData(sd);
- }
- void SaveWorkspaceUserData(StructuredData sd)
- {
- sd.Add("FileVersion", 1);
- sd.Add("LastConfig", mConfigName);
- sd.Add("LastPlatform", mPlatformName);
- using (sd.CreateObject("MainWindow"))
- {
- SerializeWindow(sd, mMainWindow);
- }
- using (sd.CreateObject("MainDockingFrame"))
- {
- SerializeDockingFrame(sd, mDockingFrame, true);
- }
- using (sd.CreateArray("RecentFilesList"))
- {
- for (var recentFile in mRecentlyDisplayedFiles)
- sd.Add(recentFile);
- }
- using (sd.CreateArray("UserPlatforms"))
- {
- for (var platformName in gApp.mWorkspace.mUserPlatforms)
- sd.Add(platformName);
- }
- using (sd.CreateArray("Breakpoints"))
- {
- for (var breakpoint in mDebugger.mBreakpointList)
- {
- if ((breakpoint.mFileName != null) || (breakpoint.mIsMemoryBreakpoint) || (breakpoint.mSymbol != null))
- {
- using (sd.CreateObject())
- {
- if (breakpoint.mFileName != null)
- {
- sd.Add("File", breakpoint.mFileName);
- sd.Add("Line", breakpoint.mLineNum);
- sd.Add("Column", breakpoint.mColumn);
- if (breakpoint.mInstrOffset != -1)
- sd.Add("InstrOffset", breakpoint.mInstrOffset);
- }
- if (breakpoint.mSymbol != null)
- sd.Add("Symbol", breakpoint.mSymbol);
- if (breakpoint.mIsMemoryBreakpoint)
- sd.Add("MemoryWatchExpression", breakpoint.mMemoryWatchExpression);
- if (breakpoint.mCondition != null)
- sd.Add("Condition", breakpoint.mCondition);
- if (breakpoint.mLogging != null)
- sd.Add("Logging", breakpoint.mLogging);
- sd.ConditionalAdd("BreakAfterLogging", breakpoint.mBreakAfterLogging, false);
- sd.ConditionalAdd("HitCountBreak", breakpoint.mHitCountBreakKind, .None);
- sd.ConditionalAdd("HitCountTarget", breakpoint.mHitCountTarget, 0);
- if (breakpoint.mDisabled)
- sd.Add("Disabled", true);
- if (breakpoint.mThreadId != -1)
- sd.Add("HasThreadId", true);
- }
- }
- }
- }
- using (sd.CreateArray("Bookmarks"))
- {
- for (var bookmark in mBookmarkManager.mBookmarkList)
- {
- if (bookmark.mFileName != null)
- {
- using (sd.CreateObject())
- {
- sd.Add("File", bookmark.mFileName);
- sd.Add("Line", bookmark.mLineNum);
- sd.Add("Column", bookmark.mColumn);
- }
- }
- }
- }
- using (sd.CreateObject("DebuggerDisplayTypes"))
- {
- var displayTypeNames = scope String();
- mDebugger.GetDisplayTypeNames(displayTypeNames);
- var referenceIds = String.StackSplit!(displayTypeNames, '\n');
- for (var referenceId in referenceIds)
- {
- if (!referenceId.StartsWith("0", StringComparison.Ordinal))
- {
- DebugManager.IntDisplayType intDisplayType;
- DebugManager.MmDisplayType mmDisplayType;
- mDebugger.GetDisplayTypes(referenceId, out intDisplayType, out mmDisplayType);
- using (sd.CreateObject(referenceId))
- {
- sd.Add("IntDisplayType", intDisplayType);
- sd.Add("MmDisplayType", mmDisplayType);
- }
- }
- }
- }
- using (sd.CreateArray("StepFilters"))
- {
- for (var stepFilter in mDebugger.mStepFilterList.Values)
- {
- if (stepFilter.mIsGlobal)
- continue;
- if (stepFilter.mKind == .Filtered)
- sd.Add(stepFilter.mFilter);
- }
- sd.RemoveIfEmpty();
- }
- using (sd.CreateArray("StepNotFilters"))
- {
- for (var stepFilter in mDebugger.mStepFilterList.Values)
- {
- if (stepFilter.mIsGlobal)
- continue;
- if (stepFilter.mKind == .NotFiltered)
- sd.Add(stepFilter.mFilter);
- }
- sd.RemoveIfEmpty();
- }
- }
- bool SaveWorkspaceUserData(bool showErrors = true)
- {
- // Don't save if we didn't finish creating the workspace
- if (mWorkspace.mNeedsCreate)
- return false;
- if (mWorkspace.IsDebugSession)
- {
- bool hasUnsavedProjects = false;
- for (let project in mWorkspace.mProjects)
- if (project.mHasChanged)
- hasUnsavedProjects = true;
- // If we purposely abandoned changes then don't save now
- if (!hasUnsavedProjects)
- SaveDebugSession();
- return true;
- }
- StructuredData sd = scope StructuredData();
- sd.CreateNew();
- SaveWorkspaceUserData(sd);
- String projectUserFileName = scope String();
- GetWorkspaceUserDataFileName(projectUserFileName);
- String jsonString = scope String();
- sd.ToTOML(jsonString);
- if (projectUserFileName.IsEmpty)
- return false;
- return SafeWriteTextFile(projectUserFileName, jsonString, showErrors);
- }
-
- bool GetWorkspaceUserDataFileName(String outResult)
- {
- if (mWorkspace.mDir == null)
- return false;
- if (mWorkspace.mCompositeFile != null)
- {
- outResult.Append(mWorkspace.mCompositeFile.mFilePath, ".bfuser");
- }
- else
- {
- outResult.Append(mWorkspace.mDir, "/BeefSpace_User.toml");
- var legacyName = scope String(mWorkspace.mDir, "/BeefUser.toml");
- if (File.Exists(legacyName))
- {
- File.Move(legacyName, outResult).IgnoreError();
- }
- }
- // Temporary for legacy
- if (!mInitialized)
- {
- String legacyName = scope String();
- legacyName.Append(mWorkspace.mDir, "/", mWorkspace.mName, ".bfuser");
- if (File.Exists(legacyName))
- {
- File.Move(legacyName, outResult).IgnoreError();
- File.Delete(legacyName).IgnoreError();
- }
- }
- return true;
- }
- void GetDefaultLayoutDataFileName(String outResult)
- {
- outResult.Append(mInstallDir, "/DefaultLayout.toml");
- }
- bool GetWorkspaceFileName(String outResult)
- {
- if (mWorkspace.mDir == null)
- return false;
- //LEGACY:
- /*if (!mInitialized)
- {
- outResult.Append(mWorkspace.mDir, "/", mWorkspace.mName, ".bfspace");
- if (File.Exists(outResult))
- return true;
- outResult.Clear();
- }*/
- outResult.Append(mWorkspace.mDir, "/BeefSpace.toml");
- IDEUtils.FixFilePath(outResult);
- return true;
- }
- ///
- bool SaveWorkspace()
- {
- if (!mWorkspace.IsSingleFileWorkspace)
- {
- #if !CLI
- if (mWorkspace.mDir == null)
- {
- let activeWindow = GetActiveWindow();
-
- FolderBrowserDialog folderDialog = scope FolderBrowserDialog();
- //folderDialog.SelectedPath = fullDir;
- if (activeWindow != null)
- activeWindow.PreModalChild();
- if (folderDialog.ShowDialog(gApp.GetActiveWindow()).GetValueOrDefault() != .OK)
- return false;
- mWorkspace.mDir = new String(folderDialog.SelectedPath);
-
- String workspaceFileName = scope .();
- GetWorkspaceFileName(workspaceFileName);
- if (File.Exists(workspaceFileName))
- {
- Fail(scope String()..AppendF("A Beef workspace already exists at '{0}'", mWorkspace.mDir));
- DeleteAndNullify!(mWorkspace.mDir);
- return false;
- }
- }
- #endif
- if (Directory.CreateDirectory(mWorkspace.mDir) case .Err)
- {
- Fail(StackStringFormat!("Failed to create workspace directory '{0}'", mWorkspace.mDir));
- return false;
- }
- }
- StructuredData data = scope StructuredData();
- data.CreateNew();
- mWorkspace.Serialize(data);
- String tomlString = scope String();
- data.ToTOML(tomlString);
- if (!mWorkspace.IsSingleFileWorkspace)
- {
- String workspaceFileName = scope String();
- GetWorkspaceFileName(workspaceFileName);
-
- if (!SafeWriteTextFile(workspaceFileName, tomlString))
- {
- Fail(StackStringFormat!("Failed to write workspace file '{0}'", workspaceFileName));
- return false;
- }
- }
- else
- {
- // If it's just the FileVersion then don't save anything...
- /*if (tomlString.Count('\n') < 2)
- tomlString.Clear();*/
- mWorkspace.mCompositeFile.Set("Workspace", tomlString);
- }
- mWorkspace.mHasChanged = false;
- MarkDirty();
- return true;
- }
- bool SaveDebugSession()
- {
- let project = mWorkspace.mProjects[0];
- #if !CLI
- if (project.mProjectPath.IsEmpty)
- {
- SaveFileDialog dialog = scope .();
- let activeWindow = GetActiveWindow();
- let workspaceOptions = GetCurWorkspaceOptions();
- let options = GetCurProjectOptions(project);
- if (!options.mDebugOptions.mCommand.IsWhiteSpace)
- {
- String execCmd = scope .();
- ResolveConfigString(mPlatformName, workspaceOptions, project, options, options.mDebugOptions.mCommand, "command", execCmd);
- String initialDir = scope .();
- Path.GetDirectoryPath(execCmd, initialDir);
- dialog.InitialDirectory = initialDir;
- dialog.SetFilter("Debug Session (*.bfdbg)|*.bfdbg");
- dialog.DefaultExt = ".bfdbg";
- String fileName = scope .();
- Path.GetFileNameWithoutExtension(execCmd, fileName);
- if (!fileName.IsEmpty)
- {
- fileName.Append(".bfdbg");
- dialog.FileName = fileName;
- }
- }
- dialog.OverwritePrompt = true;
- if (dialog.ShowDialog(activeWindow).GetValueOrDefault() != .OK)
- return false;
-
- project.mProjectPath.Set(dialog.FileNames[0]);
- }
- #endif
- if (project.mProjectPath.IsEmpty)
- return false;
- StructuredData sd = scope StructuredData();
- sd.CreateNew();
- SaveWorkspaceUserData(sd);
- using (sd.CreateObject("DebugSession"))
- {
- project.Serialize(sd);
- }
- String jsonString = scope String();
- sd.ToTOML(jsonString);
- if (!SafeWriteTextFile(project.mProjectPath, jsonString, true))
- return false;
- project.mHasChanged = false;
- MarkDirty();
- return true;
- }
- void LoadDebugSession()
- {
- /*String path = scope String();
- if (!GetWorkspaceUserDataFileName(path))
- return false;
- var data = scope StructuredData();
- if (data.Load(path) case .Err)
- return false;
- if (!LoadWorkspaceUserData(data))
- return false;*/
- }
- public void AddProjectToWorkspace(Project project, bool addToProjectList = true)
- {
- if (addToProjectList)
- mWorkspace.mProjects.Add(project);
- mBfBuildSystem.AddProject(project);
- #if !CLI
- if (mBfResolveSystem != null)
- mBfResolveSystem.AddProject(project);
- #endif
- mWorkspace.ClearProjectNameCache();
- }
- public void AddNewProjectToWorkspace(Project project, VerSpecRecord verSpec = null)
- {
- AddProjectToWorkspace(project);
- mWorkspace.SetChanged();
- var relPath = scope String();
- Path.GetRelativePath(project.mProjectPath, mWorkspace.mDir, relPath);
- relPath.Replace("\\", "/");
- int lastSlash = relPath.LastIndexOf('/');
- if (lastSlash != -1)
- relPath.RemoveToEnd(lastSlash);
- /*var endStr = "/BeefProj.toml";
- if (relPath.EndsWith(endStr))
- relPath.RemoveToEnd(relPath.Length - endStr.Length);*/
- var projectSpec = new Workspace.ProjectSpec;
- projectSpec.mProjectName = new .(project.mProjectName);
- if (verSpec != null)
- {
- projectSpec.mVerSpec = verSpec;
- }
- else
- {
- projectSpec.mVerSpec = new .();
- projectSpec.mVerSpec.SetPath(relPath);
- }
- mWorkspace.mProjectSpecs.Add(projectSpec);
- var dep = new Project.Dependency();
- dep.mProjectName = new .("corlib");
- dep.mVerSpec = new .();
- dep.mVerSpec.SetSemVer("*");
- project.mDependencies.Add(dep);
- for (var checkProject in mWorkspace.mProjects)
- {
- int idx = checkProject.mDependencies.FindIndex(scope (dep) => dep.mProjectName == project.mProjectName);
- if (idx != -1)
- ProjectOptionsChanged(checkProject);
- }
- ProjectOptionsChanged(project, false);
- }
- public Project CreateProject(String projName, String projDir, Project.TargetType targetType)
- {
- Project project = new Project();
- project.mProjectName.Set(projName);
- project.mProjectPath.Set(projDir);
- Utils.GetDirWithSlash(project.mProjectPath);
- project.mProjectPath.Append("BeefProj.toml");
- project.mProjectDir.Set(projDir);
- project.mGeneralOptions.mTargetType = targetType;
- project.SetupDefault();
- project.SetChanged();
- AddNewProjectToWorkspace(project);
- project.FinishCreate();
- mProjectPanel.InitProject(project);
- mProjectPanel.Sort();
- mWorkspace.FixOptions();
- mWorkspace.mHasChanged = true;
- mWorkspace.ClearProjectNameCache();
- CurrentWorkspaceConfigChanged();
- return project;
- }
- void StopDebugging()
- {
- if (mDebugger.mIsRunning)
- {
- mDebugger.StopDebugging();
- while (mDebugger.GetRunState() != .Terminated)
- {
- mDebugger.Update();
- }
- mDebugger.mIsRunning = false;
- mExecutionPaused = false;
- }
- mDebugger.DisposeNativeBreakpoints();
- mWantsRehupCallstack = false;
- }
- void CloseWorkspace()
- {
- StopDebugging();
- mDebugger.Reset();
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.Reset();
- });
- mMemoryPanel.MarkViewDirty();
- mCallStackPanel.MarkCallStackDirty();
- mThreadPanel.MarkThreadsDirty();
- if (mBfResolveCompiler != null)
- {
- mBfResolveCompiler.RequestCancelBackground();
- mBfResolveCompiler.CancelBackground();
- delete mBfResolveCompiler;
- delete mBfResolveSystem;
- delete mBfResolveHelper;
- }
- mBfBuildCompiler.RequestCancelBackground();
- mBfBuildCompiler.CancelBackground();
- delete mBfBuildCompiler;
- delete mBfBuildSystem;
- if (!mNoResolve)
- {
- mBfResolveSystem = new BfSystem();
- mBfResolveCompiler = mBfResolveSystem.CreateCompiler(true);
- mBfResolveHelper = new BfResolveHelper();
- }
- mCompileSinceCleanCount = 0;
- mBfBuildSystem = new BfSystem();
- mBfBuildCompiler = mBfBuildSystem.CreateCompiler(false);
- mBfBuildCompiler.ClearBuildCache();
- /*var docPanels = scope List<Widget>();
- WithTabs(scope [&] (tab) =>
- {
- var sourceViewPanel = tab.mContent as SourceViewPanel;
- if (sourceViewPanel != null)
- {
- docPanels.Add(sourceViewPanel);
- }
- });
- for (var docPanel in docPanels)
- CloseDocument(docPanel);*/
- while (mWindows.Count > 1)
- mWindows.Back.Close(true);
- void ResetPanel(Widget widget)
- {
- if (widget.mParent != null)
- widget.RemoveSelf();
- }
- if (!mRunningTestScript)
- {
- mActiveDocumentsTabbedView = null;
- ResetPanel(mProjectPanel);
- ResetPanel(mClassViewPanel);
- ResetPanel(mOutputPanel);
- ResetPanel(mImmediatePanel);
- ResetPanel(mFindResultsPanel);
- ResetPanel(mAutoWatchPanel);
- ResetPanel(mWatchPanel);
- ResetPanel(mMemoryPanel);
- ResetPanel(mCallStackPanel);
- ResetPanel(mBreakpointPanel);
- ResetPanel(mModulePanel);
- ResetPanel(mThreadPanel);
- ResetPanel(mProfilePanel);
- ResetPanel(mPropertiesPanel);
- ResetPanel(mAutoCompletePanel);
- mMainFrame.Reset();
- }
- mGlobalUndoManager.Clear();
- mHaveSourcesChangedExternallySinceLastCompile = false;
- mHaveSourcesChangedInternallySinceLastCompile = false;
- mIsImmediateDebugExprEval = false;
- //mActiveDocumentsTabbedView;
- if (mConfigName.IsEmpty)
- mConfigName.Set("Debug");
- if (mPlatformName.IsEmpty)
- mPlatformName.Set(sPlatform64Name);
- mDockingFrame = mMainFrame.mDockingFrame;
- //mMainFrame.AddedToParent;
- delete mWorkspace;
- mWorkspace = new Workspace();
- OutputLine("Workspace closed.");
- }
- void FinishShowingNewWorkspace(bool loadUserData = true)
- {
- if ((loadUserData) && (!mRunningTestScript))
- {
- if (!LoadWorkspaceUserData())
- {
- CreateDefaultLayout();
- }
- }
- WorkspaceLoaded();
- UpdateTitle();
- UpdateRecentDisplayedFilesMenuItems();
- mProjectPanel.RebuildUI();
- ShowPanel(mOutputPanel, false);
- mMainFrame.RehupSize();
- ShowStartupFile();
- }
- void CloseWorkspaceAndSetupNew()
- {
- CloseWorkspace();
- FinishShowingNewWorkspace();
- }
- // TryCloseWorkspaceAndSetupNew
- [IDECommand]
- void Cmd_CloseWorkspaceAndSetupNew()
- {
- bool done = CheckCloseWorkspace(mMainWindow,
- new () =>
- {
- // We use a close delay after saving so the user can see we actually saved before closing down
- if (SaveAll())
- {
- CloseWorkspaceAndSetupNew();
- }
- },
- new () =>
- {
- CloseWorkspaceAndSetupNew();
- }, null);
- if (done)
- {
- CloseWorkspaceAndSetupNew();
- }
- //CloseWorkspace();
- //FinishShowingNewWorkspace();
- }
- public Result<void, StructuredData.Error> StructuredLoad(StructuredData data, StringView filePath)
- {
- if (mWorkspace.IsSingleFileWorkspace)
- {
- String dataStr = scope .();
- mWorkspace.mCompositeFile.Get(filePath, dataStr);
- Try!(data.LoadFromString(dataStr));
- return .Ok;
- }
- return data.Load(filePath);
- }
- public Result<void> StructuredSave(StringView filePath, StringView contents)
- {
- if (mWorkspace.IsSingleFileWorkspace)
- {
- mWorkspace.mCompositeFile.Set(filePath, contents);
- return .Ok;
- }
- if (gApp.SafeWriteTextFile(filePath, contents))
- return .Ok;
- else
- return .Err;
- }
- protected void LoadWorkspace(BeefVerb verb)
- {
- scope AutoBeefPerf("IDEApp.LoadWorkspace");
- AddRecentFile(.OpenedWorkspace, mWorkspace.mDir);
- StructuredData data = null;
-
- String workspaceFileName = scope String();
- if (mWorkspace.IsSingleFileWorkspace)
- {
- if (mWorkspace.mCompositeFile.Load() case .Err)
- {
- OutputErrorLine("Failed to load workspace '{0}'", mWorkspace.mCompositeFile.FilePath);
- }
- workspaceFileName.Append("Workspace");
- }
- else
- GetWorkspaceFileName(workspaceFileName);
- data = scope StructuredData(); //.LoadFromFile(workspaceFileName).GetValueOrDefault();
- LoadConfig();
- bool isNew = false;
- bool wantSave = false;
-
- if (StructuredLoad(data, workspaceFileName) case .Err(let err))
- {
- mBeefConfig.Refresh();
- switch (err)
- {
- case .FormatError(int lineNum):
- OutputLineSmart("ERROR: Workspace format error in '{0}' on line {1}", workspaceFileName, lineNum);
- LoadFailed();
- return;
- case .FileError: // Assume 'file not found'
- if (verb == .OpenOrNew)
- {
- isNew = true;
- }
- else if (verb == .New)
- {
- isNew = true;
- wantSave = true;
- }
- else
- {
- #if CLI
- OutputLineSmart("ERROR: Workspace '{0}' does not exist. Use the '-new' command line argument to create a new workspace.", workspaceFileName);
- LoadFailed();
- return;
- #endif
- }
- default:
- OutputErrorLine("Failed to load workspace '{0}'", workspaceFileName);
- LoadFailed();
- return;
- }
- //Directory.CreateDirectory(mWorkspace.mDir).IgnoreError();
- int lastSlashPos = mWorkspace.mDir.LastIndexOf(IDEUtils.cNativeSlash);
- String projectName = scope String(mWorkspace.mDir, lastSlashPos + 1);
- String projectPath = scope String(mWorkspace.mDir);
- Utils.GetDirWithSlash(projectPath);
- projectPath.Append("BeefProj.toml");
-
- Project project = new Project();
- mWorkspace.mProjects.Add(project);
- project.mProjectPath.Set(projectPath);
- if (!project.Load(projectPath))
- {
- project.mBeefGlobalOptions.mDefaultNamespace.Set(projectName);
- project.mBeefGlobalOptions.mStartupObject.Clear();
- project.mBeefGlobalOptions.mStartupObject.AppendF("{0}.Program", projectName);
- project.mProjectName.Set(projectName);
- project.SetupDefault();
- project.mNeedsCreate = true;
- project.mHasChanged = true;
- project.mProjectDir.Set(mWorkspace.mDir);
-
- project.FinishCreate(false);
- var verSpec = new VerSpecRecord();
- verSpec.SetSemVer("*");
- switch (AddProject("corlib", verSpec))
- {
- case .Ok(let libProject):
- var dep = new Project.Dependency();
- dep.mProjectName = new String("corlib");
- dep.mVerSpec = verSpec;
- project.mDependencies.Add(dep);
- default:
- delete verSpec;
- }
- }
- var projSpec = new Workspace.ProjectSpec;
- projSpec.mProjectName = new String(project.mProjectName);
- projSpec.mVerSpec = new VerSpecRecord();
- projSpec.mVerSpec.SetPath(".");
- mWorkspace.mProjectSpecs.Add(projSpec);
- mWorkspace.mStartupProject = project;
- mWorkspace.mHasChanged = true;
- AddProjectToWorkspace(project, false);
- ShowPanel(mOutputPanel, false);
- /*var str = scope String();
- Font.StrEncodeColor(0xfffef860, str);
- str.AppendF("Created new workspace in '{0}'", mWorkspace.mDir);
- Font.StrEncodePopColor(str);
- OutputLine(str);*/
- OutputWarnLine("Created new workspace in '{0}'", mWorkspace.mDir);
- if (wantSave)
- {
- SaveWorkspace();
- project.Save();
- }
- else
- {
- mWorkspace.mNeedsCreate = true;
- OutputLine("Use 'File\\Save All' to commit to disk.");
- }
- }
- else
- {
- if (mVerb == .New)
- {
- OutputLineSmart("ERROR: Workspace '{0}' already exists, but '-new' argument was specified.", workspaceFileName);
- LoadFailed();
- }
- var startupProjectName = scope String();
- using (data.Open("Workspace"))
- {
- data.GetString("StartupProject", startupProjectName);
- }
- if (mWorkspace.IsSingleFileWorkspace)
- {
- var project = new Project();
- project.mProjectName.Set("Program");
- project.mGeneralOptions.mTargetType = .BeefConsoleApplication;
- Path.GetDirectoryPath(mWorkspace.mCompositeFile.FilePath, project.mProjectDir);
- project.DeferLoad("");
- mWorkspace.mProjects.Add(project);
- }
- if (data.Contains("Projects"))
- {
- for (var projectName in data.Enumerate("Projects"))
- {
- var projSpec = new Workspace.ProjectSpec;
- projSpec.mProjectName = new String(projectName);
- projSpec.mVerSpec = new VerSpecRecord();
- mWorkspace.mProjectSpecs.Add(projSpec);
- if (projSpec.mVerSpec.Parse(data) case .Err)
- {
- var err = scope String();
- err.AppendF("Unable to parse version specifier for {0} in {1}", projectName, workspaceFileName);
- Fail(err);
- LoadFailed();
- continue;
- }
- switch (AddProject(projectName, projSpec.mVerSpec))
- {
- case .Ok(let project):
- if ((!startupProjectName.IsEmpty) && (StringView.Compare(startupProjectName, projectName, true) == 0))
- {
- mWorkspace.mStartupProject = project;
- }
- project.mLocked = data.GetBool("Locked", project.mLockedDefault);
- case .Err:
- OutputLineSmart("ERROR: Unable to load project '{0}' specified in workspace", projectName);
- LoadFailed();
- default:
- }
-
- }
- }
- mWorkspace.Deserialize(data);
- }
- while (true)
- {
- bool hadLoad = false;
- for (int projectIdx = 0; projectIdx < mWorkspace.mProjects.Count; projectIdx++)
- {
- var project = mWorkspace.mProjects[projectIdx];
- if (project.mLoadDeferred)
- {
- hadLoad = true;
- var projectPath = project.mProjectPath;
- if (!project.Load(projectPath))
- {
- OutputErrorLine("Failed to load project '{0}' from '{1}'", project.mProjectName, projectPath);
- LoadFailed();
- project.mFailed = true;
- }
- AddProjectToWorkspace(project, false);
- }
- }
- if (!hadLoad)
- break;
- }
- mWorkspace.FinishDeserialize(data);
- mWorkspace.FixOptions(mConfigName, mPlatformName);
- #if !CLI
- if (mBfResolveCompiler != null)
- mBfResolveCompiler.QueueSetWorkspaceOptions(null, 0);
- #endif
- MarkDirty();
- }
- public void RetryProjectLoad(Project project)
- {
- var projectPath = project.mProjectPath;
- if (!project.Load(projectPath))
- {
- Fail(scope String()..AppendF("Failed to load project '{0}' from '{1}'", project.mProjectName, projectPath));
- LoadFailed();
- project.mFailed = true;
- }
- else
- {
- project.mFailed = false;
- CurrentWorkspaceConfigChanged();
- mProjectPanel.RebuildUI();
- }
- }
- public enum ProjectAddError
- {
- InvalidVersion,
- InvalidVersionSpec,
- LoadFailed,
- NotFound
- }
- public Result<Project, ProjectAddError> AddProject(StringView projectName, VerSpecRecord verSpecRecord)
- {
- VerSpecRecord useVerSpecRecord = verSpecRecord;
- String verConfigDir = mWorkspace.mDir;
- for (var project in mWorkspace.mProjects)
- {
- if (project.mProjectName == projectName)
- {
- return project;
- }
- }
- for (int regEntryIdx = mBeefConfig.mRegistry.Count - 1; regEntryIdx >= 0; regEntryIdx--)
- {
- var regEntry = mBeefConfig.mRegistry[regEntryIdx];
- if (regEntry.mProjName == projectName)
- {
- useVerSpecRecord = regEntry.mLocation;
- verConfigDir = regEntry.mConfigFile.mConfigDir;
- }
- }
- var project = new Project();
- // For project locking, assume that only anything that is referenced with a path is editable
- project.mLockedDefault = !(verSpecRecord.mVerSpec case .Path);
- project.mLocked = project.mLockedDefault;
- mWorkspace.mProjects.Add(project);
- bool success = false;
- defer
- {
- if (!success)
- {
- mWorkspace.mProjects.Remove(project);
- delete project;
- }
- }
- String projectFilePath = null;
- switch (useVerSpecRecord.mVerSpec)
- {
- case .Path(let path):
- var relPath = scope String(path);
- IDEUtils.FixFilePath(relPath);
- if (!relPath.EndsWith(IDEUtils.cNativeSlash))
- relPath.Append(IDEUtils.cNativeSlash);
- var absPath = scope String();
- Path.GetAbsolutePath(relPath, verConfigDir, absPath);
- projectFilePath = scope:: String();
- projectFilePath.Append(absPath, "BeefProj.toml");
- case .SemVer(let semVer):
- //
- default:
- Fail("Invalid version specifier");
- return .Err(.InvalidVersionSpec);
- }
- if (projectFilePath == null)
- {
- return .Err(.NotFound);
- }
- project.mProjectName.Set(projectName);
- project.DeferLoad(projectFilePath);
- success = true;
- /*if (!project.Load(projectFilePath))
- {
- Fail(StackStringFormat!("Failed to load project {0}", projectFilePath));
- delete project;
- return .Err(.LoadFailed);
- }
- success = true;
- AddProjectToWorkspace(project, false);*/
- return .Ok(project);
- }
- protected void WorkspaceLoaded()
- {
- scope AutoBeefPerf("IDE.WorkspaceLoaded");
- if (!Environment.IsFileSystemCaseSensitive)
- {
- // Make sure we have the correct actual path
- String newPath = new String();
- Path.GetActualPathName(mWorkspace.mDir, newPath);
- delete mWorkspace.mDir;
- mWorkspace.mDir = newPath;
- }
- List<String> platforms = scope List<String>();
- if (IDEApp.sPlatform32Name != null)
- platforms.Add(IDEApp.sPlatform32Name);
- if (IDEApp.sPlatform64Name != null)
- platforms.Add(IDEApp.sPlatform64Name);
- List<String> configs = scope List<String>();
- configs.Add("Debug");
- configs.Add("Release");
- configs.Add("Paranoid");
- configs.Add("Test");
- for (let platformName in platforms)
- {
- for (let configName in configs)
- {
- mWorkspace.FixOptions(configName, platformName);
- }
- }
- mWorkspace.FixOptions(mConfigName, mPlatformName);
- #if !CLI
- PreConfigureBeefSystem(mBfResolveSystem, mBfResolveCompiler);
- #endif
- for (var project in mWorkspace.mProjects)
- {
- project.mEnabled = IsProjectEnabled(project);
- #if !CLI
- if (mBfResolveSystem != null)
- SetupBeefProjectSettings(mBfResolveSystem, mBfResolveCompiler, project);
- #endif
- project.mRootFolder.SortItems();
- }
- if (mWorkspace.IsSingleFileWorkspace)
- {
- AddToRecentDisplayedFilesList(CompositeFile.sMainFileName);
- }
- }
- ///
- void DeserializeTabbedView(StructuredData data, IDETabbedView tabbedView)
- {
- if (data.GetBool("DefaultDocumentsTabbedView"))
- mActiveDocumentsTabbedView = tabbedView;
- SourceViewTab activeTab = null;
- for (data.Enumerate("Tabs"))
- {
- Panel panel = Panel.Create(data);
- if (panel == null)
- continue;
- Debug.Assert(panel != null);
- bool isActive = data.GetBool("Active");
-
- var newTabButton = new SourceViewTab();
- newTabButton.Label = "";
- data.GetString("TabLabel", newTabButton.mLabel);
- newTabButton.mOwnsContent = panel.mAutoDelete;
- newTabButton.mTabWidthOffset = panel.TabWidthOffset;
- //newTabButton.mWantWidth = (float)Math.Round(data.GetFloat("TabWidth") * DarkTheme.sScale);
- newTabButton.mHeight = tabbedView.mTabHeight;
- newTabButton.mContent = panel;
- tabbedView.AddTab(newTabButton, tabbedView.GetTabCount());
- newTabButton.RehupScale(1.0f, 1.0f);
-
- newTabButton.mCloseClickedEvent.Add(new () => DocumentCloseClicked(panel));
- if (isActive)
- activeTab = newTabButton;
- }
- if (activeTab != null)
- activeTab.Activate(false);
- }
- void DeserializeDockingFrame(StructuredData data, DockingFrame dockingFrame)
- {
- dockingFrame.mSplitType = (DockingFrame.SplitType)data.GetInt("SplitType");
- for (var _docWid in data.Enumerate("DockedWidgets"))
- {
- //for (int32 dockedWidgetIdx = 0; dockedWidgetIdx < data.Count; dockedWidgetIdx++)
- //for (var dockedWidgetKV in data)
- {
- //using (data.Open(dockedWidgetIdx))
- //using (data.Open(@dockedWidgetKV))
- {
- DockedWidget dockedWidget = null;
- IDETabbedView tabbedView = null;
- String type = scope String();
- data.GetString("Type", type);
- if (type == "DockingFrame")
- {
- var innerDockingFrame = new DarkDockingFrame();
- DeserializeDockingFrame(data, innerDockingFrame);
- dockedWidget = innerDockingFrame;
- }
- else if (type == "TabbedView")
- {
- tabbedView = CreateTabbedView();
- DeserializeTabbedView(data, tabbedView);
- dockedWidget = tabbedView;
- }
- dockedWidget.mParentDockingFrame = dockingFrame;
- dockedWidget.mIsFillWidget = data.GetBool("IsFillWidget");
- dockedWidget.mAutoClose = !data.GetBool("Permanent");
- if (dockedWidget.mIsFillWidget)
- dockedWidget.mHasFillWidget = true;
- if (dockedWidget.mHasFillWidget)
- dockingFrame.mHasFillWidget = true;
- if ((dockedWidget.mIsFillWidget) && (tabbedView != null) && (mActiveDocumentsTabbedView == null))
- mActiveDocumentsTabbedView = tabbedView;
- dockedWidget.mHasFillWidget = data.GetBool("HasFillWidget");
- dockedWidget.mSizePriority = data.GetFloat("SizePriority");
- dockedWidget.mRequestedWidth = data.GetFloat("RequestedWidth");
- dockedWidget.mRequestedHeight = data.GetFloat("RequestedHeight");
- dockedWidget.mWidth = dockedWidget.mRequestedWidth;
- dockedWidget.mHeight = dockedWidget.mRequestedHeight;
- dockingFrame.AddWidget(dockedWidget);
- dockingFrame.mDockedWidgets.Add(dockedWidget);
- }
- }
- }
- dockingFrame.Rehup();
- dockingFrame.ResizeContent();
- }
- void DeserializeWindow(StructuredData data, WidgetWindow window)
- {
- int32 x = data.GetInt("X");
- int32 y = data.GetInt("Y");
- int32 width = data.GetInt("Width");
- int32 height = data.GetInt("Height");
- if ((width > 0) && (height > 0))
- {
- mRequestedWindowRect = Rect(x, y, width, height);
- }
- mRequestedShowKind = data.GetEnum<BFWindow.ShowKind>("ShowKind");
- }
- bool LoadWorkspaceUserData(StructuredData data)
- {
- String configName = scope String();
- data.GetString("LastConfig", configName);
- if (!configName.IsEmpty)
- {
- mConfigName.Set(configName);
- }
- //
- {
- String platformName = scope String();
- data.GetString("LastPlatform", platformName);
- if (!platformName.IsEmpty)
- {
- Workspace.Config config;
- mWorkspace.mConfigs.TryGetValue(mConfigName, out config);
- if (config != null)
- {
- if (Utils.Contains(config.mPlatforms.Keys, platformName))
- mPlatformName.Set(platformName);
- }
- }
- }
- using (data.Open("MainWindow"))
- DeserializeWindow(data, mMainWindow);
- if (mMainWindow == null)
- mMainFrame.Resize(0, 0, mRequestedWindowRect.mWidth, mRequestedWindowRect.mHeight);
- using (data.Open("MainDockingFrame"))
- DeserializeDockingFrame(data, mDockingFrame);
- DeleteAndClearItems!(mRecentlyDisplayedFiles);
- for (data.Enumerate("RecentFilesList"))
- {
- String fileStr = new String();
- data.GetCurString(fileStr);
- IDEUtils.FixFilePath(fileStr);
- mRecentlyDisplayedFiles.Add(fileStr);
- }
- DeleteAndClearItems!(gApp.mWorkspace.mUserPlatforms);
- for (data.Enumerate("UserPlatforms"))
- {
- String platformName = scope String();
- data.GetCurString(platformName);
- if (!gApp.mWorkspace.mUserPlatforms.Contains(platformName))
- {
- gApp.mWorkspace.mUserPlatforms.Add(new String(platformName));
- gApp.mWorkspace.FixOptionsForPlatform(platformName);
- }
- }
-
- for (var _breakpoint in data.Enumerate("Breakpoints"))
- {
- String fileName = scope String();
- data.GetString("File", fileName);
- IDEUtils.FixFilePath(fileName);
- int32 lineNum = data.GetInt("Line");
- int32 column = data.GetInt("Column");
- int32 instrOffset = data.GetInt("InstrOffset", -1);
- String memoryWatchExpression = scope String();
- data.GetString("MemoryWatchExpression", memoryWatchExpression);
- Breakpoint breakpoint = null;
- if (memoryWatchExpression.Length > 0)
- breakpoint = mDebugger.CreateMemoryBreakpoint(memoryWatchExpression, (int)0, 0, null);
- else if (fileName.Length > 0)
- breakpoint = mDebugger.CreateBreakpoint(fileName, lineNum, column, instrOffset);
- else
- {
- String symbol = scope .();
- data.GetString("Symbol", symbol);
- if (!symbol.IsEmpty)
- breakpoint = mDebugger.CreateSymbolBreakpoint(symbol);
- }
- if (breakpoint != null)
- {
- String condition = scope String();
- data.GetString("Condition", condition);
- if (condition.Length > 0)
- breakpoint.SetCondition(condition);
- let logging = scope String();
- data.GetString("Logging", logging);
- bool breakAfterLogging = data.GetBool("BreakAfterLogging");
- breakpoint.SetLogging(logging, breakAfterLogging);
- let hitCountBreakKind = data.GetEnum<Breakpoint.HitCountBreakKind>("HitCountBreak");
- int hitCountTarget = data.GetInt("HitCountTarget");
- breakpoint.SetHitCountTarget(hitCountTarget, hitCountBreakKind);
- if (data.GetBool("Disabled"))
- mDebugger.SetBreakpointDisabled(breakpoint, true);
- if (data.GetBool("HasThreadId"))
- breakpoint.SetThreadId(0);
- }
- }
-
- for (var _bookmark in data.Enumerate("Bookmarks"))
- {
- String fileName = scope String();
- data.GetString("File", fileName);
- IDEUtils.FixFilePath(fileName);
- int32 lineNum = data.GetInt("Line");
- int32 column = data.GetInt("Column");
- mBookmarkManager.CreateBookmark(fileName, lineNum, column);
- }
- for (var referenceId in data.Enumerate("DebuggerDisplayTypes"))
- {
- var referenceIdStr = scope String(referenceId);
- if (referenceIdStr.Length == 0)
- referenceIdStr = null;
-
- var intDisplayType = data.GetEnum<DebugManager.IntDisplayType>("IntDisplayType");
- var mmDisplayType = data.GetEnum<DebugManager.MmDisplayType>("MmDisplayType");
- mDebugger.SetDisplayTypes(referenceIdStr, intDisplayType, mmDisplayType);
- }
- for (data.Enumerate("StepFilters"))
- {
- String filter = scope String();
- data.GetCurString(filter);
- if (!filter.IsEmpty)
- mDebugger.CreateStepFilter(filter, false, .Filtered);
- }
- for (data.Enumerate("StepNotFilters"))
- {
- String filter = scope String();
- data.GetCurString(filter);
- if (!filter.IsEmpty)
- mDebugger.CreateStepFilter(filter, false, .NotFiltered);
- }
- return true;
- }
- bool LoadWorkspaceUserData()
- {
- scope AutoBeefPerf("IDEApp.LoadWorkspaceUserData");
- //return false;
- String path = scope String();
- if (!GetWorkspaceUserDataFileName(path))
- return false;
- var data = scope StructuredData();
- if (data.Load(path) case .Err)
- return false;
- if (!LoadWorkspaceUserData(data))
- return false;
- return true;
- }
- ///
- public void RehupStepFilters()
- {
- mDebugger.SetStepOverExternalFiles(mStepOverExternalFiles);
- }
- public void SaveClangFiles()
- {
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- if (sourceViewPanel.mIsClang)
- SaveFile(sourceViewPanel);
- });
- }
- [IDECommand]
- public void SaveFile()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- SaveFile(sourceViewPanel);
- }
- [IDECommand]
- public void SaveAs()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- SaveFileAs(sourceViewPanel);
- }
- }
- [IDECommand]
- public void OpenWorkspace()
- {
- mDeferredOpen = .Workspace;
- }
- void NewDebugSession(bool fromLoad)
- {
- if (!fromLoad)
- CloseWorkspaceAndSetupNew();
- mWorkspace.mIsDebugSession = true;
- /*DebugSessionProperties workspaceProperties = new .();
- workspaceProperties.PopupWindow(mMainWindow);
- workspaceProperties.StartNew();*/
- mPlatformName.Set(sPlatform64Name);
- mConfigName.Set("Debug");
- Project project = new .();
- project.mGeneralOptions.mTargetType = .CustomBuild;
- project.mProjectName.Set("Debug Session");
- AddProjectToWorkspace(project);
- mWorkspace.mStartupProject = project;
- if (!fromLoad)
- project.mHasChanged = true;
- gApp.mWorkspace.FixOptions(mConfigName, mPlatformName);
- mProjectPanel.RebuildUI();
- if (!fromLoad)
- {
- ProjectProperties dialog = new .(project);
- dialog.PopupWindow(mMainWindow);
- dialog.mNewDebugSessionCountdown = 60;
- }
- }
- [IDECommand]
- public void Cmd_NewDebugSession()
- {
- #if !CLI
- /*SaveFileDialog dialog = scope .();
-
- let activeWindow = GetActiveWindow();
- dialog.OverwritePrompt = true;
- dialog.SetFilter("Debug Session (*.bfdbg)|*.bfdbg");
- dialog.DefaultExt = ".bfdbg";
- if (dialog.ShowDialog(activeWindow).GetValueOrDefault() != .OK)
- return;*/
- bool done = CheckCloseWorkspace(mMainWindow,
- new () =>
- {
- // We use a close delay after saving so the user can see we actually saved before closing down
- if (SaveAll())
- {
- NewDebugSession(false);
- }
- },
- new () =>
- {
- NewDebugSession(false);
- }, null);
- if (done)
- {
- NewDebugSession(false);
- }
- #endif
- }
- [IDECommand]
- public void Cmd_NewWorkspace()
- {
- mDeferredOpen = .NewWorkspaceOrProject;
- }
- [IDECommand]
- public void Cmd_NewProject()
- {
- mProjectPanel.[Friend]AddNewProject();
- }
- [IDECommand]
- public void Cmd_NewFile()
- {
- ShowSourceFile(null, null, .New);
- }
- [IDECommand]
- public void Cmd_OpenProject()
- {
- mProjectPanel.[Friend]ImportProject();
- }
- [IDECommand]
- public void OpenFile()
- {
- mDeferredOpen = .File;
- }
- [IDECommand]
- public void OpenCrashDump()
- {
- mDeferredOpen = .CrashDump;
- }
- [IDECommand]
- public bool SaveAll()
- {
- bool success = true;
- WithSourceViewPanels(scope [&] (sourceViewPanel) =>
- {
- success &= SaveFile(sourceViewPanel);
- });
- mWorkspace.WithProjectItems(scope [&] (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource != null)
- {
- if ((projectSource.mEditData != null) && (projectSource.mEditData.HasTextChanged()))
- {
- success &= SaveFile(projectSource);
- }
- }
-
- });
- for (var project in mWorkspace.mProjects)
- {
- if (project.mHasChanged)
- {
- if (project.IsDebugSession)
- success &= SaveDebugSession();
- else
- project.Save();
- }
- }
- if ((mWorkspace.IsInitialized) && (!mWorkspace.IsDebugSession) &&
- ((mWorkspace.mHasChanged) || (mWorkspace.mDir == null)))
- success &= SaveWorkspace();
- if (!mRunningTestScript)
- {
- if (!mWorkspace.IsDebugSession)
- success &= SaveWorkspaceUserData();
- mSettings.Save();
- }
- MarkDirty();
- return success;
- }
- [IDECommand]
- void Cmd_Exit()
- {
- mMainWindow.Close();
- }
- WidgetWindow GetCurrentWindow()
- {
- if (mRunningTestScript)
- {
- if (mLastActivePanel != null)
- return mLastActivePanel.mWidgetWindow;
- return mMainWindow;
- }
- for (var window in mWindows)
- {
- if (window.mHasFocus)
- {
- var returnWindow = window;
- // With this "modal" flag, it caused errors to popup within a hoverwatch on a failed variable edit
- while ((returnWindow.mParent != null) /*&& (returnWindow.mWindowFlags.HasFlag(BFWindow.Flags.Modal))*/)
- returnWindow = returnWindow.mParent;
- return (WidgetWindow)returnWindow;
- }
- }
- return mMainWindow;
- }
- public Dialog Fail(String text, Widget addWidget = null, WidgetWindow parentWindow = null)
- {
- // Always write to STDOUT even if we're running as a GUI, allowing cases like RunAndWait to pass us a stdout handle
- Console.Error.WriteLine("ERROR: {0}", text);
- #if CLI
- mFailed = true;
- return null;
- #endif
- #unwarn
- if (mMainWindow == null)
- {
- mDeferredFails.Add(new String(text));
- return null;
- }
- if (mRunningTestScript)
- {
- if (mScriptManager.IsErrorExpected(text))
- {
- DeleteAndNullify!(mScriptManager.mExpectingError);
- OutputLine("Received expected error: {0}", text);
- return null;
- }
- ShowOutput();
- mFailed = true;
- OutputLineSmart("ERROR: {0}", text);
- Console.Error.WriteLine("ERROR: {0}", text);
- return null;
- }
- #unwarn
- Debug.Assert(Thread.CurrentThread == mMainThread);
- if (mMainWindow == null)
- {
- Internal.FatalError(StackStringFormat!("FAILED: {0}", text));
- }
- Beep(MessageBeepType.Error);
- Dialog dialog = ThemeFactory.mDefault.CreateDialog("ERROR", text, DarkTheme.sDarkTheme.mIconError);
- dialog.mDefaultButton = dialog.AddButton("OK");
- dialog.mEscButton = dialog.mDefaultButton;
- dialog.mWindowFlags |= .Modal;
- dialog.PopupWindow(parentWindow ?? GetCurrentWindow());
- if (addWidget != null)
- {
- dialog.AddWidget(addWidget);
- addWidget.mY = dialog.mHeight - 60;
- addWidget.mX = 90;
- }
- return dialog;
- }
- public void MessageDialog(String title, String text)
- {
- Dialog dialog = ThemeFactory.mDefault.CreateDialog(title, text);
- dialog.mDefaultButton = dialog.AddButton("OK");
- dialog.mEscButton = dialog.mDefaultButton;
- dialog.PopupWindow(mMainWindow);
- }
- public void DoQuickFind(bool isReplace)
- {
- var textPanel = GetActiveTextPanel();
- if (textPanel != null)
- textPanel.ShowQuickFind(isReplace);
- else
- {
- if (let activeWindow = GetActiveWindow())
- {
- var widget = activeWindow.mFocusWidget;
- while (widget != null)
- {
- if (let watchStringEdit = widget as WatchStringEdit)
- {
- watchStringEdit.ShowQuickFind(isReplace);
- return;
- }
- widget = widget.mParent;
- }
- }
- }
- }
- [IDECommand]
- public void ShowAbout()
- {
- Dialog dialog = new AboutDialog();
- dialog.PopupWindow(mMainWindow);
- }
- [IDECommand]
- public void Cmd_Document__Find()
- {
- DoQuickFind(false);
- }
- [IDECommand]
- public void Cmd_Document__Replace()
- {
- DoQuickFind(true);
- }
- private void DoFindAndReplace(bool isReplace)
- {
- RecordHistoryLocation();
- if (mFindAndReplaceDialog != null)
- {
- mFindAndReplaceDialog.mWidgetWindow.SetForeground();
- return;
- }
- mFindAndReplaceDialog = new FindAndReplaceDialog(isReplace);
- mFindAndReplaceDialog.PopupWindow(mMainWindow);
- mFindAndReplaceDialog.mOnClosed.Add(new () => { mFindAndReplaceDialog = null; });
- }
- [IDECommand]
- public void Cmd_Find()
- {
- DoFindAndReplace(false);
- }
- [IDECommand]
- public void Cmd_Replace()
- {
- DoFindAndReplace(true);
- }
- [IDECommand]
- public void Cmd_FindPrev()
- {
- DoFindNext(-1);
- }
- [IDECommand]
- public void Cmd_FindNext()
- {
- DoFindNext(1);
- }
- [IDECommand]
- public void CursorToLineEnd()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.mEditWidget.mEditWidgetContent.CursorToLineEnd();
- }
- [IDECommand]
- public void CursorToLineStart()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.mEditWidget.mEditWidgetContent.CursorToLineStart(true);
- }
- public void DoFindNext(int32 dir = 1)
- {
- var textPanel = GetActiveTextPanel();
- if (textPanel != null)
- {
- textPanel.FindNext(dir);
- }
- else
- {
- if (let activeWindow = GetActiveWindow())
- {
- var widget = activeWindow.mFocusWidget;
- while (widget != null)
- {
- if (let watchStringEdit = widget as WatchStringEdit)
- {
- watchStringEdit.FindNext(dir);
- return;
- }
- widget = widget.mParent;
- }
- }
- }
- }
- void DoShowNextDocumentPanel()
- {
- var activeDoumentPanel = GetActiveDocumentPanel();
- if ((activeDoumentPanel == null) && (mActiveDocumentsTabbedView != null))
- {
- var activeTab = mActiveDocumentsTabbedView.GetActiveTab();
- activeTab.Activate();
- return;
- }
- DarkTabbedView nextTabbedView = null;
- DarkTabbedView firstTabbedView = null;
- bool foundActiveTabbedView = false;
- WithDocumentTabbedViews(scope [&] (tabbedView) =>
- {
- if (tabbedView.mIsFillWidget)
- {
- if (firstTabbedView == null)
- firstTabbedView = tabbedView;
- if (tabbedView == mActiveDocumentsTabbedView)
- foundActiveTabbedView = true;
- else if ((foundActiveTabbedView) && (nextTabbedView == null))
- nextTabbedView = tabbedView;
- }
- });
- if (nextTabbedView == null)
- nextTabbedView = firstTabbedView;
- if (nextTabbedView != null)
- {
- var activeTab = nextTabbedView.GetActiveTab();
- activeTab.Activate();
- }
- }
- [IDECommand]
- public void Cmd_ShowCurrent()
- {
- var activePanel = GetActivePanel();
- if (var sourceViewPanel = activePanel as SourceViewPanel)
- {
- sourceViewPanel.ShowCurrent();
- }
- else if (var disassemblyPanel = activePanel as DisassemblyPanel)
- {
- disassemblyPanel.GoToSource();
- }
- }
- [IDECommand]
- public void Cmd_GotoLine()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- sourceViewPanel.GotoLine();
- return;
- }
- var activePanel = GetActivePanel();
- if (let memoryPanel = activePanel as MemoryPanel)
- {
- memoryPanel.GotoAddress();
- }
- }
- [IDECommand]
- public void Cmd_GotoMethod()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.GotoMethod();
- }
- [IDECommand]
- public void Cmd_RenameItem()
- {
- let activePanel = GetActivePanel();
- if (var projectPanel = activePanel as ProjectPanel)
- {
- projectPanel.TryRenameItem();
- }
- else if (var watchPanel = activePanel as WatchPanel)
- {
- watchPanel.TryRenameItem();
- }
- }
- [IDECommand]
- public void Cmd_RenameSymbol()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.RenameSymbol();
- }
- [IDECommand]
- public void Cmd_FindAllReferences()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.FindAllReferences();
- }
- [IDECommand]
- public void Cmd_FindClass()
- {
- var widgetWindow = GetCurrentWindow();
- if (widgetWindow != null)
- {
- var dialog = new FindClassDialog();
- dialog.PopupWindow(mMainWindow);
- }
- }
- [IDECommand]
- public void Cmd_ViewWhiteSpace()
- {
- mViewWhiteSpace.Toggle();
- MarkDirty();
- }
- [IDECommand]
- public void Cmd_ShowAutoComplete()
- {
- var sewc = GetActiveSourceEditWidgetContent();
- if (sewc != null)
- {
- sewc.ShowAutoComplete(true);
- }
- }
- [IDECommand]
- public void Cmd_ShowFixit()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.FixitAtCursor();
- }
- [IDECommand]
- public void Cmd_PrevBookmark()
- {
- mBookmarkManager.PrevBookmark();
- }
- [IDECommand]
- public void Cmd_NextBookmark()
- {
- mBookmarkManager.NextBookmark();
- }
- [IDECommand]
- public void Cmd_ToggleBookmark()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.ToggleBookmarkAtCursor();
- }
- [IDECommand]
- public void Cmd_ClearBookmarks()
- {
- mBookmarkManager.Clear();
- }
- [IDECommand]
- public void Cmd_Clean()
- {
- if (IsCompiling)
- {
- Fail("Cannot clean while compilign");
- return; // Ignore
- }
- if (mDebugger.mIsRunning)
- {
- Fail("Cannot clean while running");
- return; // Ignore
- }
- mWantsClean = true;
- }
- [IDECommand]
- public void Cmd_CleanBeef()
- {
- if (IsCompiling)
- {
- Fail("Cannot clean while compilign");
- return; // Ignore
- }
- if (mDebugger.mIsRunning)
- {
- Fail("Cannot clean while running");
- return; // Ignore
- }
- mWantsBeefClean = true;
- }
- [IDECommand]
- public void Cmd_CompileFile()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- if (sourceViewPanel.mProjectSource != null)
- {
- var filePath = scope String();
- sourceViewPanel.mProjectSource.GetFullImportPath(filePath);
- if ((filePath.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase)) ||
- (filePath.EndsWith(".c", StringComparison.OrdinalIgnoreCase)))
- {
- ShowPanel(mOutputPanel, false);
- SaveFile(sourceViewPanel);
- var project = sourceViewPanel.mProjectSource.mProject;
- Project.Options options = GetCurProjectOptions(project);
- if (options != null)
- {
- Workspace.Options workspaceOptions = GetCurWorkspaceOptions();
- CompileSource(project, workspaceOptions, options, filePath);
- }
- }
- }
- }
- }
- [IDECommand]
- public void Cmd_MatchBrace()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.MatchBrace();
- }
- [IDECommand]
- public void Cmd_GotoNextItem()
- {
- var curOutputPanel = mOutputPanel;
- if ((mFindResultsPanel != null) && (mFindResultsPanel.mWidgetWindow != null))
- {
- if (mFindResultsPanel.mLastFocusAppUpdateCnt > curOutputPanel.mLastFocusAppUpdateCnt)
- curOutputPanel = mFindResultsPanel;
- }
- curOutputPanel.GotoNextSourceReference();
- }
-
- [IDECommand]
- public void Cmd_ZoomOut()
- {
- float scale = DarkTheme.sScale;
- if (scale > 0.25f)
- {
- if (scale < 0)
- scale -= 0.05f;
- else //if (scale < 2.0f)
- scale -= 0.10f;
- SetScale(scale);
- }
- }
- [IDECommand]
- public void Cmd_ZoomIn()
- {
- float scale = DarkTheme.sScale;
- if (scale < 4.0f)
- {
- if (scale < 0)
- scale += 0.02f;//0.05f;
- else //if (scale < 2.0f)
- scale += 0.04f;//0.10f;
- SetScale(scale);
- }
- }
- [IDECommand]
- public void Cmd_ShowFileExternally()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- ProcessStartInfo psi = scope ProcessStartInfo();
- psi.SetFileName("/bin/OpenFileLine");
- var args = scope String();
- args.AppendF("{0} {1}", sourceViewPanel.mFilePath, sourceViewPanel.mEditWidget.mEditWidgetContent.CursorLineAndColumn.mLine + 1);
- psi.SetArguments(args);
- psi.UseShellExecute = false;
- SpawnedProcess process = scope SpawnedProcess();
- process.Start(psi).IgnoreError();
- /*if (case .Ok(var process) = Process.Start(psi))
- delete process;*/
- }
- }
- [IDECommand]
- public void Cmd_ZoomReset()
- {
- SetScale(1.0f, true);
- }
- [IDECommand]
- public void Cmd_ReformatDocument()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- sourceViewPanel.ReformatDocument();
- }
- void RemoveAllBreakpoints()
- {
- BfLog.LogDbg("IDEApp.RemoveAllBreakpoints\n");
- while (mDebugger.mBreakpointList.Count > 0)
- mDebugger.DeleteBreakpoint(mDebugger.mBreakpointList[0]);
- }
- [IDECommand]
- void Cmd_Break()
- {
- mDebugger.BreakAll();
- }
- public void ShowDisassemblyAtCursor()
- {
- if (!mDebugger.mIsRunning)
- return; // Ignore
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- int line;
- int lineChar;
- sourceViewPanel.mEditWidget.Content.GetCursorLineChar(out line, out lineChar);
-
- var disassemblyPanel = ShowDisassemblyPanel();
- if (!disassemblyPanel.Show(sourceViewPanel.mFilePath, line, lineChar))
- ShowRecentFile(1); // Go back a file
- }
- }
- [IDECommand]
- public void ShowDisassemblyAtStack()
- {
- var activePanel = GetActivePanel();
- if (var diassemblyPanel = activePanel as DisassemblyPanel)
- {
- diassemblyPanel.mStayInDisassemblyCheckbox.Checked ^= true;
- return;
- }
- if ((mDebugger.mIsRunning) && (mDebugger.IsPaused()))
- {
- ShowPCLocation(mDebugger.mActiveCallStackIdx, false, false, true);
- }
- else
- {
- ShowDisassemblyPanel(true);
- }
- mInDisassemblyView = true;
- }
- public void GoToDefinition()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- int line;
- int lineChar;
- sourceViewPanel.mEditWidget.Content.GetCursorLineChar(out line, out lineChar);
- #if IDE_C_SUPPORT
- if (sourceViewPanel.mIsClang)
- {
- String defFile = scope String();
- int defLine;
- int defColumn;
- mResolveClang.CancelBackground();
-
- int defIdx = sourceViewPanel.mEditWidget.Content.GetTextIdx(line, lineChar);
- if (mResolveClang.FindDefinition(sourceViewPanel.mFilePath, defIdx,
- defFile, out defLine, out defColumn))
- {
- sourceViewPanel.RecordHistoryLocation();
- sourceViewPanel = ShowSourceFileLocation(defFile, -1, -1, defLine, defColumn, LocatorType.Smart, true);
- if (sourceViewPanel != null)
- sourceViewPanel.RecordHistoryLocation();
- return;
- }
- }
- else
- #endif
- {
- ResolveParams resolveParams = scope ResolveParams();
- sourceViewPanel.Classify(ResolveType.GoToDefinition, resolveParams);
- if (resolveParams.mOutFileName != null)
- {
- sourceViewPanel.RecordHistoryLocation();
- sourceViewPanel = ShowSourceFileLocation(resolveParams.mOutFileName, -1, -1, resolveParams.mOutLine, resolveParams.mOutLineChar, LocatorType.Smart, true);
- sourceViewPanel.RecordHistoryLocation(true);
- return;
- }
- }
- if (mBfResolveCompiler.HasResolvedAll())
- {
- Fail("Unable to locate definition");
- }
- else
- {
- sourceViewPanel.ShowSymbolReferenceHelper(.GoToDefinition);
- }
- }
- }
- public void StackPositionChanged()
- {
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.MarkWatchesDirty(false, true);
- });
- mMemoryPanel.MarkViewDirty();
- }
- public void RefreshWatches()
- {
- //Debug.WriteLine("RefreshWatches");
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.MarkWatchesDirty(false);
- });
- MarkDirty();
- for (var window in gApp.mWindows)
- {
- var widgetWindow = window as WidgetWindow;
- if (var hoverWatch = widgetWindow.mRootWidget as HoverWatch)
- {
- hoverWatch.Refresh();
- }
- }
- }
- public void MemoryEdited()
- {
- RefreshWatches();
- mMemoryPanel.MarkViewDirty();
- }
- public void AddWatch(String watchExpr)
- {
- ShowWatches();
- mWatchPanel.AddWatchItem(watchExpr);
- mWatchPanel.MarkWatchesDirty(false);
- }
- public bool IsInDisassemblyMode(bool wantShowSource = false)
- {
- //return GetActiveDocumentPanel() is DisassemblyPanel;
- if (!mInDisassemblyView)
- return false;
- DisassemblyPanel disassemblyPanel = TryGetDisassemblyPanel();
- if (disassemblyPanel == null)
- return false;
- return ((disassemblyPanel.mStayInDisassemblyCheckbox != null) && (disassemblyPanel.mStayInDisassemblyCheckbox.Checked)) || (!wantShowSource);
- }
- DisassemblyPanel TryGetDisassemblyPanel(bool onlyIfVisible = true)
- {
- Debug.Assert(true);
- DisassemblyPanel disassemblyPanel = null;
- WithTabs(scope [&] (tabButton) =>
- {
- if ((disassemblyPanel == null) && (tabButton.mContent is DisassemblyPanel))
- {
- var checkDisassemblyPanel = (DisassemblyPanel)tabButton.mContent;
- if ((!onlyIfVisible) || (checkDisassemblyPanel.mWidgetWindow != null))
- disassemblyPanel = checkDisassemblyPanel;
- }
- });
- return disassemblyPanel;
- }
- [IDECommand]
- void Compile()
- {
- if (AreTestsRunning())
- return;
- if (mHotResolveState != .None)
- return;
- if (IsCompiling)
- return;
- if (mWorkspace.mProjects.IsEmpty)
- {
- Fail("No projects exist to compile. Create or load a project.");
- return;
- }
- if (mWorkspace.IsDebugSession)
- {
- bool hadCommands = false;
- for (let project in mWorkspace.mProjects)
- {
- if (project.mGeneralOptions.mTargetType == .CustomBuild)
- {
- let options = GetCurProjectOptions(project);
- if (options == null)
- continue;
- if ((!options.mBuildOptions.mPreBuildCmds.IsEmpty) || (!options.mBuildOptions.mPostBuildCmds.IsEmpty))
- hadCommands = true;
- }
- else
- hadCommands = true;
- }
- if (!hadCommands)
- {
- Fail("No build commands have been defined");
- return;
- }
- }
- if ((!mDebugger.mIsRunning) || (!mDebugger.mIsRunningCompiled))
- {
- if (mExecutionQueue.Count == 0)
- {
- mOutputPanel.Clear();
- OutputLine("Compiling...");
- Compile(.Normal, null);
- }
- }
- else
- {
- mOutputPanel.Clear();
- OutputLine("Hot Compiling...");
- Project runningProject = mWorkspace.mStartupProject;
- Compile(.Normal, runningProject);
- }
- }
- [IDECommand]
- void RunWithStep()
- {
- mTargetStartWithStep = true;
- CompileAndRun();
- }
- [IDECommand]
- void StepInto()
- {
- if (mDebugger.mIsRunning)
- {
- if (mExecutionPaused)
- {
- DebuggerUnpaused();
- mDebugger.StepInto(IsInDisassemblyMode());
- }
- }
- else
- {
- RunWithStep();
- }
- }
- [IDECommand]
- void StepOver()
- {
- mStepCount++;
- if (mDebugger.mIsRunning)
- {
- if (mExecutionPaused)
- {
- DebuggerUnpaused();
- mDebugger.StepOver(IsInDisassemblyMode());
- }
- }
- else
- {
- if (mEnableRunTiming)
- {
- mRunTimingProfileId = Profiler.StartSampling("RunTiming");
- }
- RunWithStep();
- }
- }
- [IDECommand]
- void StepOut()
- {
- if (mExecutionPaused)
- {
- DebuggerUnpaused();
- mDebugger.StepOut(IsInDisassemblyMode());
- }
- }
- [IDECommand]
- void Cmd_Continue()
- {
- if (mDebugger.mIsRunning)
- {
- if (mDebugger.IsPaused())
- {
- DebuggerUnpaused();
- mDebugger.Continue();
- }
- }
- }
- [IDECommand]
- public void RunWithCompiling()
- {
- if (mDebugger.mIsRunning)
- {
- if (mDebugger.IsPaused())
- {
- DebuggerUnpaused();
- mDebugger.Continue();
- }
- }
- else if (AreTestsRunning())
- {
- // Ignore
- }
- else
- {
- mTargetStartWithStep = false;
- CompileAndRun();
- }
- }
- [IDECommand]
- void RunWithoutCompiling()
- {
- if (!mDebugger.mIsRunning)
- {
- OutputLine("Starting target without compiling...");
- mTargetStartWithStep = false;
- var startDebugCmd = new StartDebugCmd();
- startDebugCmd.mWasCompiled = false;
- startDebugCmd.mOnlyIfNotFailed = true;
- mExecutionQueue.Add(startDebugCmd);
- }
- }
- [IDECommand]
- void RunToCursor()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (mDebugger.mRunToCursorBreakpoint != null)
- {
- BfLog.LogDbg("Deleting mRunToCursorBreakpoint\n");
- mDebugger.DeleteBreakpoint(mDebugger.mRunToCursorBreakpoint);
- mDebugger.mRunToCursorBreakpoint = null;
- }
- if (sourceViewPanel != null)
- {
- BfLog.LogDbg("Creating mRunToCursorBreakpoint\n");
- mDebugger.mRunToCursorBreakpoint = sourceViewPanel.ToggleBreakpointAtCursor(true, mDebugger.GetActiveThread());
- }
- else if (var disassemblyPanel = GetActiveDocumentPanel() as DisassemblyPanel)
- {
- mDebugger.mRunToCursorBreakpoint = disassemblyPanel.ToggleAddrBreakpointAtCursor(true, mDebugger.GetActiveThread());
- }
- if (mDebugger.mIsRunning)
- {
- if (mDebugger.IsPaused())
- {
- DebuggerUnpaused();
- mDebugger.Continue();
- }
- }
- else
- {
- mTargetStartWithStep = false;
- CompileAndRun();
- }
- }
- [IDECommand]
- void SetNextStatement()
- {
- var documentPanel = GetActiveDocumentPanel();
- var sourceViewPanel = documentPanel as SourceViewPanel;
- var disassemblyPanel = GetActiveDocumentPanel() as DisassemblyPanel;
- if (mDebugger.mIsRunning)
- {
- if (mExecutionPaused)
- {
- if (gApp.mDebugger.mActiveCallStackIdx != 0)
- {
- gApp.Fail("Set Next Statement cannot only be used when the top of the callstack is selected");
- return;
- }
- if (disassemblyPanel != null)
- {
- String sourceFileName = scope String();
- int addr = disassemblyPanel.GetCursorAddress(sourceFileName);
- if (addr != (int)0)
- {
- mDebugger.SetNextStatement(true, sourceFileName, addr, 0);
- PCChanged();
- }
- DebuggerUnpaused();
- }
- else
- {
- var activePanel = sourceViewPanel.GetActivePanel();
- int lineIdx;
- int lineCharIdx;
- var editWidgetContent = activePanel.mEditWidget.Content;
- editWidgetContent.GetLineCharAtIdx(editWidgetContent.CursorTextPos, out lineIdx, out lineCharIdx);
- /*int hotFileIdx = sourceViewPanel.[Friend]mHotFileIdx;
- sourceViewPanel.[Friend]RemapActiveToCompiledLine(hotFileIdx, ref lineIdx, ref lineCharIdx);*/
- int textPos = editWidgetContent.CursorTextPos - lineCharIdx;
- lineCharIdx = 0;
- // Find first non-space char8
- while ((textPos < editWidgetContent.mData.mTextLength) && (((char8)editWidgetContent.mData.mText[textPos].mChar).IsWhiteSpace))
- {
- textPos++;
- lineCharIdx++;
- }
- if (sourceViewPanel.[Friend]mOldVersionPanel == null)
- {
- int addr;
- String file = scope String();
- int hotIdx;
- int defLineStart;
- int defLineEnd;
- int line;
- int column;
- int language;
- int stackSize;
- mDebugger.CheckCallStack();
- String label = scope String();
- DebugManager.FrameFlags frameFlags;
- mDebugger.GetStackFrameInfo(0, label, out addr, file, out hotIdx, out defLineStart, out defLineEnd, out line, out column, out language, out stackSize, out frameFlags);
- if (hotIdx != -1)
- sourceViewPanel.[Friend]RemapActiveToCompiledLine(hotIdx, ref lineIdx, ref lineCharIdx);
- }
- mDebugger.SetNextStatement(false, sourceViewPanel.mFilePath, (int)lineIdx, lineCharIdx);
- PCChanged();
- DebuggerUnpaused();
- }
- }
- }
- }
- void ToggleBreakpoint(WidgetWindow window, bool bindToThread = false)
- {
- var documentPanel = GetActiveDocumentPanel();
- if (var sourceViewPanel = documentPanel as SourceViewPanel)
- {
- sourceViewPanel.ToggleBreakpointAtCursor(false, bindToThread ? gApp.mDebugger.GetActiveThread() : -1);
- }
- else if (var disassemblyPanel = documentPanel as DisassemblyPanel)
- {
- disassemblyPanel.ToggleBreakpointAtCursor(false, bindToThread ? gApp.mDebugger.GetActiveThread() : -1);
- }
- }
- [IDECommand]
- void ToggleComment()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel == null)
- return;
- var ewc = (SourceEditWidgetContent)sourceViewPanel.mEditWidget.mEditWidgetContent;
- ewc.ToggleComment();
- }
- [IDECommand]
- void ToggleBreakpoint()
- {
- ToggleBreakpoint(GetCurrentWindow(), false);
- }
- [IDECommand]
- void ToggleThreadBreakpoint()
- {
- ToggleBreakpoint(GetCurrentWindow(), true);
- }
- void CompileCurrentFile()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel == null)
- return;
-
- if (sourceViewPanel.mProjectSource == null)
- return;
- if (!sourceViewPanel.mIsClang)
- return;
- var project = sourceViewPanel.mProjectSource.mProject;
- var options = GetCurProjectOptions(project);
- var workspaceOptions = GetCurWorkspaceOptions();
- CompileSource(project, workspaceOptions, options, sourceViewPanel.mFilePath, "-v");
- }
- [IDECommand]
- void CancelBuild()
- {
- mBfBuildCompiler.RequestCancelBackground();
- if (IsCompiling)
- {
- OutputLine("Canceling Compilation...");
- //DeleteAndClearItems!(mExecutionQueue);
- for (var cmd in mExecutionQueue)
- {
- #unwarn
- if (var processBfCompileCmd = cmd as ProcessBfCompileCmd)
- {
-
- }
- else if (var buildCompleteCmd = cmd as BuildCompletedCmd)
- {
- }
- else
- {
- delete cmd;
- @cmd.Remove();
- }
- }
- for (var executionInstance in mExecutionInstances)
- {
- executionInstance.Cancel();
- }
- }
- if ((mBuildContext != null) && (mBuildContext.mScriptManager != null))
- mBuildContext.mScriptManager.Cancel();
- }
- TabbedView FindTabbedView(DockingFrame dockingFrame, int32 xDir, int32 yDir)
- {
- bool useFirst = true;
- if (dockingFrame.mSplitType == DockingFrame.SplitType.Horz)
- {
- useFirst = xDir > 0;
- }
- else
- useFirst = yDir > 0;
- for (int32 pass = 0; pass < 2; pass++)
- {
- for (int32 i = 0; i < dockingFrame.mDockedWidgets.Count; i++)
- {
- if ((useFirst) && (i == 0) && (pass == 0))
- continue;
- var widget = dockingFrame.mDockedWidgets[i];
- if (widget is TabbedView)
- return (TabbedView)widget;
- DockingFrame childFrame = widget as DockingFrame;
- if (childFrame != null)
- {
- TabbedView tabbedView = FindTabbedView(childFrame, xDir, yDir);
- if (tabbedView != null)
- return tabbedView;
- }
- }
- }
- return null;
- }
- enum ShowTabResult
- {
- Existing,
- OpenedNew
- }
- ShowTabResult ShowTab(Widget tabContent, String name, bool ownsContent, bool setFocus)
- {
- var result = ShowTabResult.Existing;
- var tabButton = GetTab(tabContent);
- if (tabButton == null)
- {
- TabbedView tabbedView = null;
- if (var newPanel = tabContent as Panel)
- {
- WithTabs(scope [&] (tabButton) =>
- {
- if (newPanel.HasAffinity(tabButton.mContent))
- {
- tabbedView = tabButton.mTabbedView;
- }
- });
- }
- if (tabbedView == null)
- tabbedView = FindTabbedView(mDockingFrame, -1, 1);
- if (tabbedView == null)
- {
- tabbedView = CreateTabbedView();
- mDockingFrame.AddDockedWidget(tabbedView, null, .Left);
- }
- if (tabbedView != null)
- {
- tabButton = SetupTab(tabbedView, name, 100, tabContent, ownsContent);
- result = ShowTabResult.OpenedNew;
- }
- }
- if (tabButton != null)
- {
- tabButton.RehupScale(1.0f, 1.0f);
- tabButton.Activate(setFocus);
- }
- return result;
- }
- public void RecordHistoryLocation(bool includeLastActive = false, bool b = true)
- {
- var sourceViewPanel = GetActiveSourceViewPanel(includeLastActive);
- if (sourceViewPanel != null)
- sourceViewPanel.RecordHistoryLocation();
- }
- void ShowPanel(Panel panel, String label, bool setFocus = true)
- {
- mLastActivePanel = panel;
- RecordHistoryLocation();
- ShowTab(panel, label, false, setFocus);
- if (setFocus)
- panel.FocusForKeyboard();
- if ((!panel.mWidgetWindow.mHasFocus) && (!mRunningTestScript))
- panel.mWidgetWindow.SetForeground();
- }
- [IDECommand]
- public void ShowWorkspacePanel()
- {
- ShowPanel(mProjectPanel, "Workspace");
- }
- [IDECommand]
- public void ShowClassViewPanel()
- {
- ShowPanel(mClassViewPanel, "Class View");
- }
- [IDECommand]
- public void ShowThreads()
- {
- ShowPanel(mThreadPanel, "Threads");
- }
- [IDECommand]
- public void ShowCallstack()
- {
- ShowPanel(mCallStackPanel, "Call Stack");
- }
- [IDECommand]
- public void ShowWatches()
- {
- ShowPanel(mWatchPanel, "Watch");
- }
- [IDECommand]
- public void ShowAutoWatches()
- {
- ShowPanel(mAutoWatchPanel, "Auto Watches");
- }
- [IDECommand]
- public void ShowImmediatePanel()
- {
- ShowPanel(mImmediatePanel, "Immediate");
- }
- [IDECommand]
- public void ShowBreakpoints()
- {
- ShowPanel(mBreakpointPanel, "Breakpoints");
- }
- [IDECommand]
- public void ShowModules()
- {
- ShowPanel(mModulePanel, "Modules");
- }
- [IDECommand]
- public void ShowMemory()
- {
- ShowPanel(mMemoryPanel, "Memory");
- }
- [IDECommand]
- public void ShowProfilePanel()
- {
- ShowPanel(mProfilePanel, "Profile");
- }
- [IDECommand]
- public void ShowQuickWatch()
- {
- QuickWatchDialog dialog = new .();
- var activePanel = GetActivePanel();
- if (let sourceViewPanel = activePanel as SourceViewPanel)
- {
- sourceViewPanel.RecordHistoryLocation();
- var debugExpr = scope String();
- var ewc = sourceViewPanel.EditWidget.Content;
- if (ewc.HasSelection())
- ewc.GetSelectionText(debugExpr);
- else
- sourceViewPanel.GetDebugExpressionAt(ewc.CursorTextPos, debugExpr);
- dialog.Init(debugExpr);
- }
- else if (let immediatePanel = activePanel as ImmediatePanel)
- {
- var debugExpr = scope String();
- immediatePanel.GetQuickExpression(debugExpr);
- dialog.Init(debugExpr);
- }
- else
- {
- dialog.Init(.());
- }
- if (activePanel != null)
- dialog.PopupWindow(activePanel.mWidgetWindow);
- else
- dialog.PopupWindow(mMainWindow);
- }
- [IDECommand]
- public void SelectConfig()
- {
- mMainFrame.mStatusBar.mConfigComboBox.ShowDropdown();
- }
- [IDECommand]
- public void SelectPlatform()
- {
- mMainFrame.mStatusBar.mPlatformComboBox.ShowDropdown();
- }
- [IDECommand]
- public void ShowSettings()
- {
- var workspaceProperties = new SettingsDialog();
- workspaceProperties.PopupWindow(mMainWindow);
- }
- [IDECommand]
- public void ShowKeyboardShortcuts()
- {
- /*var workspaceProperties = new SettingsDialog();
- workspaceProperties.PopupWindow(mMainWindow);*/
- }
- public void ShowFindResults(bool setFocus)
- {
- ShowPanel(mFindResultsPanel, "Find Results", setFocus);
- }
- [IDECommand]
- public void ShowFindResults()
- {
- ShowFindResults(true);
- }
- [IDECommand]
- public void ShowOutput()
- {
- ShowPanel(mOutputPanel, "Output");
- }
- [IDECommand]
- public void ShowAutoCompletePanel()
- {
- ShowPanel(mAutoCompletePanel, "Autocomplete", false);
- }
- [IDECommand]
- private void OpenCorresponding()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- String fileName = sourceViewPanel.mFilePath;
- String findFileName = null;
- int dotPos = fileName.LastIndexOf('.');
- if ((fileName.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase)) || (fileName.EndsWith(".c", StringComparison.OrdinalIgnoreCase)))
- {
- findFileName = scope:: String(fileName, 0, dotPos);
- findFileName.Append(".h");
- }
- else if ((fileName.EndsWith(".h", StringComparison.OrdinalIgnoreCase)) || (fileName.EndsWith(".hpp", StringComparison.OrdinalIgnoreCase)))
- {
- findFileName = scope:: String(fileName, 0, dotPos);
- findFileName.Append(".c");
- if (!File.Exists(findFileName))
- {
- findFileName = scope:: String(fileName, 0, dotPos);
- findFileName.Append(".cpp");
- }
- }
- if (findFileName != null)
- {
- if (File.Exists(findFileName))
- {
- ShowSourceFile(findFileName);
- }
- else
- {
- Fail("Unable to find corresponding file");
- }
- }
- }
- }
- DarkTabbedView GetActiveTabbedView()
- {
- var activePanel = GetActivePanel();
- if (activePanel == null)
- return null;
- return activePanel.mParent as DarkTabbedView;
- }
- [IDECommand]
- void TabFirst()
- {
- var tabbedView = GetActiveTabbedView();
- if ((tabbedView == null) || (tabbedView.mTabs.IsEmpty))
- return;
- tabbedView.mTabs[0].Activate();
- }
- [IDECommand]
- void TabLast()
- {
- var tabbedView = GetActiveTabbedView();
- if ((tabbedView == null) || (tabbedView.mTabs.IsEmpty))
- return;
- tabbedView.mTabs.Back.Activate();
- }
- [IDECommand]
- void TabNext()
- {
- var tabbedView = GetActiveTabbedView();
- if ((tabbedView == null) || (tabbedView.mTabs.IsEmpty))
- return;
- for (var tab in tabbedView.mTabs)
- {
- if (tab.mIsActive)
- {
- if (@tab.Index < tabbedView.mTabs.Count - 1)
- {
- tabbedView.mTabs[@tab.Index + 1].Activate();
- return;
- }
- }
- }
- tabbedView.mTabs[0].Activate();
- }
- [IDECommand]
- void TabPrev()
- {
- var tabbedView = GetActiveTabbedView();
- if ((tabbedView == null) || (tabbedView.mTabs.IsEmpty))
- return;
- for (var tab in tabbedView.mTabs)
- {
- if (tab.mIsActive)
- {
- if (@tab.Index > 0)
- {
- tabbedView.mTabs[@tab.Index - 1].Activate();
- return;
- }
- }
- }
- tabbedView.mTabs.Back.Activate();
- }
- void DoErrorTest()
- {
- Dialog aDialog = ThemeFactory.mDefault.CreateDialog("ERROR", "This\nmultiline!\nLine 3.", DarkTheme.sDarkTheme.mIconError);
- aDialog.mDefaultButton = aDialog.AddButton("OK");
- aDialog.mEscButton = aDialog.mDefaultButton;
- aDialog.PopupWindow(GetCurrentWindow());
- }
- void ReportMemory()
- {
- mDebugger.FullReportMemory();
- if (mBfResolveSystem != null)
- mBfResolveSystem.ReportMemory();
- mBfBuildSystem.ReportMemory();
- Internal.ReportMemory();
- GC.Report();
- }
- [IDECommand]
- void DoAttach()
- {
- var widgetWindow = GetCurrentWindow();
- if (widgetWindow != null)
- {
- var attachDialog = new AttachDialog();
- attachDialog.PopupWindow(mMainWindow);
- }
- }
- [IDECommand]
- void DoLaunch()
- {
- if (mLaunchDialog != null)
- {
- mLaunchDialog.mWidgetWindow.SetForeground();
- return;
- }
- mLaunchDialog = new LaunchDialog();
- mLaunchDialog.PopupWindow(mMainWindow);
- mLaunchDialog.mOnClosed.Add(new () => { mLaunchDialog = null; });
- }
-
- void DoProfile()
- {
- if (gApp.mProfilePanel.mUserProfiler != null)
- {
- ShowProfilePanel();
- gApp.mProfilePanel.StopProfiling();
- }
- else
- {
- ShowProfilePanel();
- gApp.mProfilePanel.StartProfiling();
- }
- }
- [IDECommand]
- void NavigateBackwards()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if ((sourceViewPanel != null) && (sourceViewPanel.HasFocus()))
- {
- var sourceEditWidgetContent = (SourceEditWidgetContent)sourceViewPanel.mEditWidget.mEditWidgetContent;
- if (sourceEditWidgetContent.IsAtCurrentHistory())
- {
- mHistoryManager.PrevHistory();
- return;
- }
- }
- mHistoryManager.GoToCurrentHistory();
- }
- [IDECommand]
- void NavigateForwards()
- {
- mHistoryManager.NextHistory();
- }
- void ExitTest()
- {
- sExitTest = true;
- Stop();
- }
- void ToggleCheck(IMenu menu, ref bool checkVal)
- {
- checkVal = !checkVal;
- var sysMenu = (SysMenu)menu;
- sysMenu.Modify(null, null, null, true, checkVal ? 1 : 0);
- }
- public bool AreTestsRunning()
- {
- return (mTestManager != null);
- }
- protected void RunTests(bool debug)
- {
- if (mOutputPanel != null)
- {
- ShowPanel(mOutputPanel, false);
- mOutputPanel.Clear();
- }
- if (AreTestsRunning())
- {
- OutputLineSmart("ERROR: Tests already running");
- return;
- }
- if ((mDebugger != null) && (mDebugger.mIsRunning))
- {
- OutputLineSmart("ERROR: Tests cannot be run while program is executing");
- return;
- }
- String prevConfigName = scope String(mConfigName);
- var workspaceOptions = GetCurWorkspaceOptions();
- if (workspaceOptions.mBuildKind != .Test)
- {
- mMainFrame.mStatusBar.SelectConfig("Test");
- }
- workspaceOptions = GetCurWorkspaceOptions();
- if (workspaceOptions.mBuildKind != .Test)
- {
- mMainFrame.mStatusBar.SelectConfig(prevConfigName);
- OutputLineSmart("ERROR: No valid Test workspace configuration exists");
- return;
- }
- mLastTestFailed = false;
- mTestManager = new TestManager();
- mTestManager.mPrevConfigName = new String(prevConfigName);
- mTestManager.mDebug = debug;
- mTestManager.mIncludeIgnored = mTestIncludeIgnored;
- if (mOutputPanel != null)
- mOutputPanel.Clear();
- OutputLine("Compiling for testing...");
- if (!Compile(.Test, null))
- {
- mTestManager.BuildFailed();
- }
- }
- [IDECommand]
- public void Cmd_RunAllTests()
- {
- RunTests(false);
- }
- [IDECommand]
- public void Cmd_TestEnableConsole()
- {
- let ideCommand = gApp.mCommands.mCommandMap["Test Enable Console"];
- ToggleCheck(ideCommand.mMenuItem, ref mTestEnableConsole);
- }
- [IDECommand]
- public void Cmd_TestIncludeIgnored()
- {
- let ideCommand = gApp.mCommands.mCommandMap["Test Include Ignored"];
- ToggleCheck(ideCommand.mMenuItem, ref mTestIncludeIgnored);
- }
- public void CreateMenu()
- {
- scope AutoBeefPerf("IDEApp.CreateMenu");
- SysMenu root = mMainWindow.mSysMenu;
- String keyStr = scope String();
-
- SysMenu AddMenuItem(SysMenu menu, String dispString, String cmdName, MenuItemUpdateHandler menuItemUpdateHandler = null,
- SysBitmap bitmap = null, bool enabled = true, int32 checkState = -1, bool radioCheck = false)
- {
- let ideCommand = mCommands.mCommandMap[cmdName];
- if (ideCommand != null)
- {
- keyStr.Clear();
- ideCommand.ToString(keyStr);
- keyStr.Insert(0, "#");
- }
- let itemMenu = menu.AddMenuItem(dispString, (ideCommand != null) ? keyStr : null, new (evt) => ideCommand.mAction(), menuItemUpdateHandler, bitmap, enabled, checkState, radioCheck);
- if (ideCommand != null)
- {
- ideCommand.mMenuItem = itemMenu;
- }
- return itemMenu;
- }
- //////////
- SysMenu subMenu = root.AddMenuItem("&File");
- let newMenu = subMenu.AddMenuItem("&New");
- AddMenuItem(newMenu, "New &Workspace", "New Workspace");
- AddMenuItem(newMenu, "New &Project", "New Project");
- AddMenuItem(newMenu, "New &Debug Session", "New Debug Session");
- AddMenuItem(newMenu, "New &File", "New File");
- let openMenu = subMenu.AddMenuItem("&Open");
- //openMenu.AddMenuItem("&Open Workspace...", GetCmdKey("Open Workspace"), new (evt) => { OpenWorkspace(); } );
- AddMenuItem(openMenu, "Open &Workspace...", "Open Workspace");
- AddMenuItem(openMenu, "Open &Project...", "Open Project");
- AddMenuItem(openMenu, "Open &Debug Session...", "Open Debug Session");
- AddMenuItem(openMenu, "Open &File...", "Open File");
- AddMenuItem(openMenu, "&Open File in Workspace", "Open File in Workspace");
- AddMenuItem(openMenu, "&Open Corresponding (cpp/h)", "Open Corresponding");
- AddMenuItem(openMenu, "Open &Crash Dump...", "Open Crash Dump");
- let recentMenu = subMenu.AddMenuItem("Open &Recent");
- mSettings.mRecentFiles.mRecents[(int)RecentFiles.RecentKind.OpenedWorkspace].mMenu = recentMenu.AddMenuItem("Open Recent &Workspace");
- mSettings.mRecentFiles.mRecents[(int)RecentFiles.RecentKind.OpenedDebugSession].mMenu = recentMenu.AddMenuItem("Open Recent &Debug Session");
- mSettings.mRecentFiles.mRecents[(int)RecentFiles.RecentKind.OpenedFile].mMenu = recentMenu.AddMenuItem("Open Recent &File");
- mSettings.mRecentFiles.mRecents[(int)RecentFiles.RecentKind.OpenedCrashDump].mMenu = recentMenu.AddMenuItem("Open Recent &Crash Dump");
- AddMenuItem(subMenu, "&Save File","Save File");
- AddMenuItem(subMenu, "Save &As...", "Save As");
- AddMenuItem(subMenu, "Save A&ll", "Save All");
- AddMenuItem(subMenu, "N&ew View into File", "New View Into File");
- let prefMenu = subMenu.AddMenuItem("&Preferences");
- //prefMenu.AddMenuItem("&Keyboard Shortcuts", null, new (evt) => { ShowKeyboardShortcuts(); });
- AddMenuItem(prefMenu, "&Settings", "Settings");
- AddMenuItem(subMenu, "Close Workspace", "Close Workspace");
- AddMenuItem(subMenu, "E&xit", "Exit");
- //////////
- subMenu = root.AddMenuItem("&Edit");
- AddMenuItem(subMenu, "Quick &Find...", "Find in Document");
- AddMenuItem(subMenu, "Quick &Replace...", "Replace in Document");
- AddMenuItem(subMenu, "Find in &Files...", "Find in Files");
- AddMenuItem(subMenu, "Replace in Files...", "Replace in Files");
- AddMenuItem(subMenu, "Find Prev", "Find Prev");
- AddMenuItem(subMenu, "Find Next", "Find Next");
- AddMenuItem(subMenu, "Show &Current", "Show Current");
-
- AddMenuItem(subMenu, "&Goto Line...", "Goto Line");
- AddMenuItem(subMenu, "Goto &Method...", "Goto Method");
- AddMenuItem(subMenu, "&Rename Symbol", "Rename Symbol");
- AddMenuItem(subMenu, "Show Fi&xit", "Show Fixit");
- AddMenuItem(subMenu, "Find &All References", "Find All References");
- AddMenuItem(subMenu, "Find C&lass...", "Find Class");
- subMenu.AddMenuItem(null);
- var encodingMenu = subMenu.AddMenuItem("Encoding");
- var lineEndingMenu = encodingMenu.AddMenuItem("Line Ending");
- void AddLineEndingKind(String name, LineEndingKind lineEndingKind)
- {
- lineEndingMenu.AddMenuItem(name, null,
- new (menu) =>
- {
- var sysMenu = (SysMenu)menu;
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- if (sourceViewPanel.mEditData.mLineEndingKind != lineEndingKind)
- {
- sourceViewPanel.EditWidget.Content.mData.mCurTextVersionId++;
- sourceViewPanel.mEditData.mLineEndingKind = lineEndingKind;
- sysMenu.mParent.UpdateChildItems();
- }
- }
- },
- new (menu) =>
- {
- var sysMenu = (SysMenu)menu;
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- sysMenu.Modify(null, null, null, true, (sourceViewPanel.mEditData.mLineEndingKind == lineEndingKind) ? 1 : 0, true);
- }
- else
- {
- sysMenu.Modify(null, null, null, false, 0, true);
- }
- });
- }
- AddLineEndingKind("Windows", .CrLf);
- AddLineEndingKind("Unix", .Lf);
- AddLineEndingKind("Mac OS 9", .Cr);
- var bookmarkMenu = subMenu.AddMenuItem("Boo&kmarks");
- AddMenuItem(bookmarkMenu, "&Toggle Bookmark", "Bookmark Toggle");
- AddMenuItem(bookmarkMenu, "&Next Bookmark", "Bookmark Next");
- AddMenuItem(bookmarkMenu, "&Previous Bookmark", "Bookmark Prev");
- AddMenuItem(bookmarkMenu, "&Clear Bookmarks", "Bookmark Clear");
- var advancedEditMenu = subMenu.AddMenuItem("Advanced");
- AddMenuItem(advancedEditMenu, "Make Uppercase", "Make Uppercase");
- AddMenuItem(advancedEditMenu, "Make Lowercase", "Make Lowercase");
- mViewWhiteSpace.mMenu = AddMenuItem(advancedEditMenu, "View White Space", "View White Space", null, null, true, mViewWhiteSpace.Bool ? 1 : 0);
- AddMenuItem(advancedEditMenu, "Reformat Document", "Reformat Document");
- if (mSettings.mEnableDevMode)
- {
- subMenu.AddMenuItem(null);
- var internalEditMenu = subMenu.AddMenuItem("Internal");
- internalEditMenu.AddMenuItem("Hilight Cursor References", null, new (menu) => { ToggleCheck(menu, ref gApp.mSettings.mEditorSettings.mHiliteCursorReferences); }, null, null, true, gApp.mSettings.mEditorSettings.mHiliteCursorReferences ? 1 : 0);
- internalEditMenu.AddMenuItem("Delayed Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgDelayedAutocomplete); }, null, null, true, gApp.mDbgDelayedAutocomplete ? 1 : 0);
- }
- //////////
- subMenu = root.AddMenuItem("&View");
- AddMenuItem(subMenu, "Work&space Explorer", "Show Workspace Explorer");
- AddMenuItem(subMenu, "C&lass View", "Show Class View");
- AddMenuItem(subMenu, "&Immediate Window", "Show Immediate");
- AddMenuItem(subMenu, "&Threads", "Show Threads");
- AddMenuItem(subMenu, "&Call Stack", "Show Call Stack");
- AddMenuItem(subMenu, "&Watches", "Show Watches");
- AddMenuItem(subMenu, "&Auto Watches", "Show Auto Watches");
- AddMenuItem(subMenu, "&Breakpoints", "Show Breakpoints");
- AddMenuItem(subMenu, "&Memory", "Show Memory");
- AddMenuItem(subMenu, "Mo&dules", "Show Modules");
- AddMenuItem(subMenu, "&Output", "Show Output");
- AddMenuItem(subMenu, "&Find Results", "Show Find Results");
- AddMenuItem(subMenu, "&Profiler", "Show Profiler");
- AddMenuItem(subMenu, "A&utoComplete", "Show Autocomplete Panel");
- subMenu.AddMenuItem(null);
- AddMenuItem(subMenu, "Next Document Panel", "Next Document Panel");
- AddMenuItem(subMenu, "Navigate Backwards", "Navigate Backwards");
- AddMenuItem(subMenu, "Navigate Forwards", "Navigate Forwards");
- //////////
- subMenu = root.AddMenuItem("&Build");
- AddMenuItem(subMenu, "&Build Solution", "Build Solution");
- AddMenuItem(subMenu, "&Clean", "Clean");
- AddMenuItem(subMenu, "Clean Beef", "Clean Beef");
- //subMenu.AddMenuItem("Compile Current File", null, new (menu) => { CompileCurrentFile(); });
- AddMenuItem(subMenu, "Cancel Build", "Cancel Build", new (menu) => { menu.SetDisabled(!IsCompiling); });
- if (mSettings.mEnableDevMode)
- {
- var internalBuildMenu = subMenu.AddMenuItem("Internal");
- internalBuildMenu.AddMenuItem("Autobuild (Debug)", null, new (menu) => { mDebugAutoBuild = !mDebugAutoBuild; });
- internalBuildMenu.AddMenuItem("Autorun (Debug)", null, new (menu) => { mDebugAutoRun = !mDebugAutoRun; });
- internalBuildMenu.AddMenuItem("Disable Compiling", null, new (menu) => { ToggleCheck(menu, ref mDisableBuilding); }, null, null, true, mDisableBuilding ? 1 : 0);
- }
- //////////
- subMenu = root.AddMenuItem("&Debug");
- AddMenuItem(subMenu, "&Start Debugging", "Start Debugging");
- AddMenuItem(subMenu, "Start Wit&hout Debugging", "Start Without Debugging");
- AddMenuItem(subMenu, "&Launch Process...", "Launch Process");
- AddMenuItem(subMenu, "&Attach to Process...", "Attach to Process");
- AddMenuItem(subMenu, "&Stop Debugging", "Stop Debugging");
- AddMenuItem(subMenu, "Break All", "Break All");
- AddMenuItem(subMenu, "Remove All Breakpoints", "Remove All Breakpoints");
- AddMenuItem(subMenu, "Show &Disassembly", "Show Disassembly");
- AddMenuItem(subMenu, "&Quick Watch", "Show QuickWatch");
- AddMenuItem(subMenu, "&Profile", "Profile");
- subMenu.AddMenuItem(null);
- AddMenuItem(subMenu, "Step Into", "Step Into");
- AddMenuItem(subMenu, "Step Over", "Step Over");
- AddMenuItem(subMenu, "Step Out", "Step Out");
- subMenu.AddMenuItem(null);
- AddMenuItem(subMenu, "To&ggle Breakpoint", "Breakpoint Toggle");
- AddMenuItem(subMenu, "Toggle Thread Breakpoint", "Breakpoint Toggle Thread");
- var newBreakpointMenu = subMenu.AddMenuItem("New &Breakpoint");
- AddMenuItem(newBreakpointMenu, "&Memory Breakpoint...", "Breakpoint Memory");
- AddMenuItem(newBreakpointMenu, "&Symbol Breakpoint...", "Breakpoint Symbol");
- if (mSettings.mEnableDevMode)
- {
- var internalDebugMenu = subMenu.AddMenuItem("Internal");
- internalDebugMenu.AddMenuItem("Error Test", null, new (menu) => { DoErrorTest(); } );
- internalDebugMenu.AddMenuItem("Reconnect BeefPerf", null, new (menu) => { BeefPerf.RetryConnect(); } );
- AddMenuItem(internalDebugMenu, "Report Memory", "Report Memory");
- internalDebugMenu.AddMenuItem("Crash", null, new (menu) => { Runtime.FatalError("Bad"); });
- internalDebugMenu.AddMenuItem("Show Welcome", null, new (menu) => { ShowWelcome(); });
- internalDebugMenu.AddMenuItem("Exit Test", null, new (menu) => { ExitTest(); });
- internalDebugMenu.AddMenuItem("Run Test", null, new (menu) => { mRunTest = !mRunTest; });
- internalDebugMenu.AddMenuItem("GC Collect", null, new (menu) =>
- {
- var profileId = Profiler.StartSampling().GetValueOrDefault();
- for (int i < 10)
- GC.Collect(false);
- if (profileId != 0)
- profileId.Dispose();
- });
- internalDebugMenu.AddMenuItem("Enable GC Collect", null, new (menu) => { ToggleCheck(menu, ref mEnableGCCollect); EnableGCCollect = mEnableGCCollect; }, null, null, true, mEnableGCCollect ? 1 : 0);
- internalDebugMenu.AddMenuItem("Fast Updating", null, new (menu) => { ToggleCheck(menu, ref mDbgFastUpdate); EnableGCCollect = mDbgFastUpdate; }, null, null, true, mDbgFastUpdate ? 1 : 0);
- internalDebugMenu.AddMenuItem("Alloc String", null, new (menu) => { new String("Alloc String"); });
- internalDebugMenu.AddMenuItem("Perform Long Update Checks", null, new (menu) =>
- {
- bool wantsLongUpdateCheck = mLongUpdateProfileId != 0;
- ToggleCheck(menu, ref wantsLongUpdateCheck);
- mLastLongUpdateCheck = 0;
- mLastLongUpdateCheckError = 0;
- if (wantsLongUpdateCheck)
- mLongUpdateProfileId = Profiler.StartSampling("LongUpdate");
- else
- {
- mLongUpdateProfileId.Dispose();
- mLongUpdateProfileId = 0;
- }
- }, null, null, true, (mLongUpdateProfileId != 0) ? 1 : 0);
- }
- //////////
- var testMenu = root.AddMenuItem("&Test");
- var testRunMenu = testMenu.AddMenuItem("&Run");
- AddMenuItem(testRunMenu, "&All Tests", "Run All Tests");
- var testDebugMenu = testMenu.AddMenuItem("&Debug");
- AddMenuItem(testDebugMenu, "&All Tests", "Debug All Tests");
- AddMenuItem(testMenu, "Enable Console", "Test Enable Console", null, null, true, mTestEnableConsole ? 1 : 0);
- AddMenuItem(testMenu, "Include Ignored Tests", "Test Include Ignored", null, null, true, mTestIncludeIgnored ? 1 : 0);
- //////////
- mWindowMenu = root.AddMenuItem("&Window");
- AddMenuItem(mWindowMenu, "&Close", "Close Window");
- AddMenuItem(mWindowMenu, "&Close All", "Close All Windows");
- AddMenuItem(mWindowMenu, "&Split View", "Split View");
- subMenu = root.AddMenuItem("&Help");
- AddMenuItem(subMenu, "&About", "About");
- }
- IDETabbedView CreateTabbedView()
- {
- var tabbedView = new IDETabbedView();
- tabbedView.mSharedData.mOpenNewWindowDelegate.Add(new (fromTabbedView, newWindow) => SetupNewWindow(newWindow, true));
- tabbedView.mSharedData.mTabbedViewClosed.Add(new (tabbedView) =>
- {
- if (tabbedView == mActiveDocumentsTabbedView)
- mActiveDocumentsTabbedView = null;
- });
- return tabbedView;
- }
- public void SetupNewWindow(WidgetWindow window, bool isMainWindow)
- {
- window.mOnWindowKeyDown.Add(new => SysKeyDown);
- if (isMainWindow)
- window.mOnWindowCloseQuery.Add(new => SecondaryAllowClose);
- }
- DarkTabbedView FindDocumentTabbedView()
- {
- for (int32 windowIdx = 0; windowIdx < mWindows.Count; windowIdx++)
- {
- var window = mWindows[windowIdx];
- var widgetWindow = window as WidgetWindow;
- if (widgetWindow != null)
- {
- var darkDockingFrame = widgetWindow.mRootWidget as DarkDockingFrame;
- if (widgetWindow == mMainWindow)
- darkDockingFrame = mDockingFrame;
- //DarkTabbedView documentTabbedView = null;
- DarkTabbedView documentTabbedView = null;
- if (darkDockingFrame != null)
- {
- darkDockingFrame.WithAllDockedWidgets(scope [&] (dockedWidget) =>
- {
- bool hadSource = false;
- var tabbedView = dockedWidget as DarkTabbedView;
- if (tabbedView != null)
- {
- tabbedView.WithTabs(scope [&] (tab) =>
- {
- if (documentTabbedView != null)
- return;
- var content = tab.mContent;
- if ((content is SourceViewPanel) ||
- (content is DisassemblyPanel))
- hadSource = true;
- });
- }
- if (hadSource)
- documentTabbedView = tabbedView;
- });
- }
- if (documentTabbedView != null)
- return documentTabbedView;
- }
- }
- return null;
- }
- public DarkTabbedView GetDefaultDocumentTabbedView()
- {
- if ((mActiveDocumentsTabbedView == null) || (mActiveDocumentsTabbedView.mParent == null))
- {
- mActiveDocumentsTabbedView = CreateTabbedView();
- mActiveDocumentsTabbedView.SetRequestedSize(150, 150);
- mActiveDocumentsTabbedView.mIsFillWidget = true;
- mActiveDocumentsTabbedView.mAutoClose = false;
- if ((mProjectPanel != null) && (mProjectPanel.mWidgetWindow != null))
- {
- if (var tabbedView = mProjectPanel.mParent as TabbedView)
- {
- if (var dockingFrame = tabbedView.mParent as DockingFrame)
- {
- dockingFrame.AddDockedWidget(mActiveDocumentsTabbedView, tabbedView, DockingFrame.WidgetAlign.Right);
- return mActiveDocumentsTabbedView;
- }
- }
- }
-
- mDockingFrame.AddDockedWidget(mActiveDocumentsTabbedView, null, DockingFrame.WidgetAlign.Right);
- }
- return mActiveDocumentsTabbedView;
- }
- void PopulateDocumentMenu(DarkTabbedView tabbedView, Menu menu)
- {
- WithTabs(scope (tab) =>
- {
- var menuItem = menu.AddItem(tab.mLabel);
- menuItem.mOnMenuItemSelected.Add(new (selMenuItem) =>
- {
- TabbedView.TabButton activateTab = tab;
- activateTab.Activate();
- });
- });
- }
- public void WithDocumentTabbedViews(Action<DarkTabbedView> func)
- {
- for (int32 windowIdx = 0; windowIdx < mWindows.Count; windowIdx++)
- {
- var window = mWindows[windowIdx];
- var widgetWindow = window as WidgetWindow;
- if (widgetWindow != null)
- {
- var darkDockingFrame = widgetWindow.mRootWidget as DarkDockingFrame;
- if (widgetWindow == mMainWindow)
- darkDockingFrame = mDockingFrame;
- if (darkDockingFrame != null)
- {
- darkDockingFrame.WithAllDockedWidgets(scope (dockedWidget) =>
- {
- var tabbedView = dockedWidget as DarkTabbedView;
- if (tabbedView != null)
- func(tabbedView);
- });
- }
- }
- }
- }
- public void EnsureDocumentArea()
- {
- GetDefaultDocumentTabbedView();
- }
- public Widget GetActivePanel()
- {
- if (mRunningTestScript)
- return mLastActivePanel;
- for (var window in mWindows)
- {
- if (!window.mHasFocus)
- continue;
- var widgetWindow = window as WidgetWindow;
- if (widgetWindow != null)
- {
- var focusWidget = widgetWindow.mFocusWidget;
- if ((focusWidget == null) && (var hoverWatch = widgetWindow.mRootWidget as HoverWatch))
- {
- return hoverWatch.mTextPanel;
- }
- while ((focusWidget != null) && (focusWidget.mParent != null))
- {
- if (focusWidget.mParent is TabbedView)
- return focusWidget;
- focusWidget = focusWidget.mParent;
- }
- }
- }
- return null;
- }
- public SourceEditWidgetContent GetActiveSourceEditWidgetContent()
- {
- let activeWindow = GetActiveWindow();
- if (activeWindow.mFocusWidget != null)
- {
- if (let editWidget = activeWindow.mFocusWidget as EditWidget)
- {
- let sewc = editWidget.mEditWidgetContent as SourceEditWidgetContent;
- if (sewc != null)
- return sewc;
- }
- }
- var activeTextPanel = GetActivePanel() as TextPanel;
- if (activeTextPanel != null)
- {
- return activeTextPanel.EditWidget.mEditWidgetContent as SourceEditWidgetContent;
- }
- return null;
- }
- public WidgetWindow GetActiveWindow()
- {
- for (let window in mWindows)
- if (window.mHasFocus)
- {
- var result = window;
- while ((result.mWindowFlags.HasFlag(.Modal)) && (result.mParent != null))
- result = result.mParent;
- return result as WidgetWindow;
- }
- return mMainWindow;
- }
- public Widget GetActiveDocumentPanel()
- {
- var activePanel = GetActivePanel();
- if ((activePanel is SourceViewPanel) || (activePanel is DisassemblyPanel))
- return activePanel;
- return null;
- }
-
- public void WithTabs(Action<TabbedView.TabButton> func)
- {
- WithDocumentTabbedViews(scope (documentTabbedView) =>
- {
- documentTabbedView.WithTabs(func);
- });
- }
- public TabbedView.TabButton GetTab(Widget content)
- {
- TabbedView.TabButton tab = null;
- WithTabs(scope [&] (checkTab) =>
- {
- if (checkTab.mContent == content)
- tab = checkTab;
- });
- return tab;
- }
- public void WithSourceViewPanels(Action<SourceViewPanel> func)
- {
- WithTabs(scope (tab) =>
- {
- var sourceViewPanel = tab.mContent as SourceViewPanel;
- if (sourceViewPanel != null)
- func(sourceViewPanel);
- });
- }
- TabbedView.TabButton SetupTab(TabbedView tabView, String name, float width, Widget content, bool ownsContent) // 2
- {
- TabbedView.TabButton tabButton = tabView.AddTab(name, width, content, ownsContent);
- if ((var panel = content as Panel) && (var darkTabButton = tabButton as DarkTabbedView.DarkTabButton))
- {
- darkTabButton.mTabWidthOffset = panel.TabWidthOffset;
- }
- tabButton.mCloseClickedEvent.Add(new () => CloseDocument(content)); // 1
- return tabButton;
- }
- public DisassemblyPanel ShowDisassemblyPanel(bool clearData = false)
- {
- DisassemblyPanel disassemblyPanel = null;
- WithTabs(scope [&] (tab) =>
- {
- if ((disassemblyPanel == null) && (tab.mContent is DisassemblyPanel))
- {
- disassemblyPanel = (DisassemblyPanel)tab.mContent;
- disassemblyPanel.ClearQueuedData();
- tab.Activate();
- }
- });
- if (disassemblyPanel != null)
- return disassemblyPanel;
-
- TabbedView tabbedView = GetDefaultDocumentTabbedView();
- disassemblyPanel = new DisassemblyPanel();
- //diassemblyPanel.Show(filePath);
- var newTabButton = new SourceViewTab();
- newTabButton.Label = DisassemblyPanel.sPanelName;
- newTabButton.mWantWidth = newTabButton.GetWantWidth();
- newTabButton.mHeight = tabbedView.mTabHeight;
- newTabButton.mContent = disassemblyPanel;
- tabbedView.AddTab(newTabButton);
-
- newTabButton.mCloseClickedEvent.Add(new () => CloseDocument(disassemblyPanel));
- newTabButton.Activate();
- //diassemblyPanel.FocusEdit();
- mLastActivePanel = disassemblyPanel;
- return disassemblyPanel;
- }
- public class SourceViewTab : DarkTabbedView.DarkTabButton
- {
- public float GetWantWidth()
- {
- return DarkTheme.sDarkTheme.mSmallFont.GetWidth(mLabel) + DarkTheme.GetScaled(40);
- }
- public override void Activate(bool setFocus)
- {
- base.Activate(setFocus);
- if ((mUpdateCnt > 0) && (mTabbedView.mUpdateCnt == 0) && (mTabbedView.mTabs.Count == 1))
- {
- //bool isDocument = mContent;
- // We were dropped onto a new tabbed view, mark it as a document frame
- bool isFillWidget = false;
- if (mContent is SourceViewPanel)
- isFillWidget = true;
- if (mContent is DisassemblyPanel)
- isFillWidget = true;
- if (isFillWidget)
- {
- mTabbedView.mIsFillWidget = true;
- mTabbedView.mHasFillWidget = true;
- }
- }
- }
- public override void Draw(Graphics g)
- {
- base.Draw(g);
- if (mWidth < mWantWidth / 2)
- return;
- var sourceViewPanel = mContent as SourceViewPanel;
- if (sourceViewPanel != null)
- {
- if (sourceViewPanel.HasUnsavedChanges())
- {
- g.SetFont(IDEApp.sApp.mTinyCodeFont);
- g.DrawString("*", mWantWidth - DarkTheme.sUnitSize + GS!(2), 0);
- }
- else if (sourceViewPanel.mLoadFailed)
- {
- g.SetFont(IDEApp.sApp.mCodeFont);
- using (g.PushColor(0xFFFF8080))
- g.DrawString("!", mWantWidth - DarkTheme.sUnitSize, 0);
- }
- }
- else if (let findResultsPanel = mContent as FindResultsPanel)
- {
- if (findResultsPanel.IsSearching)
- {
- g.SetFont(IDEApp.sApp.mTinyCodeFont);
- String rotChars = @"/-\|";
- StringView sv = .(rotChars, (mUpdateCnt / 16) % 4, 1);
- g.DrawString(sv, mWantWidth - DarkTheme.sUnitSize, 0);
- }
- }
- else if (let profilePanel = mContent as ProfilePanel)
- {
- if (profilePanel.IsSamplingHidden)
- {
- //using (g.PushColor(((mUpdateCnt / 20) % 2 == 0) ? 0xFFF0F0F0 : 0xFFFFFFFF))
- using (g.PushColor(0x80FFFFFF))
- g.Draw(DarkTheme.sDarkTheme.GetImage(.RedDot), GS!(8), GS!(0));
- }
- }
- }
- public override void MouseDown(float x, float y, int32 btn, int32 btnCount)
- {
- base.MouseDown(x, y, btn, btnCount);
- if (btn == 1)
- {
- Menu menu = new Menu();
- if (var sourceViewPanel = mContent as SourceViewPanel)
- {
- var item = menu.AddItem("Copy Full Path");
- item.mOnMenuItemSelected.Add(new (menu) =>
- {
- gApp.SetClipboardText(sourceViewPanel.mFilePath);
- });
- item = menu.AddItem("Open Containing Folder");
- item.mOnMenuItemSelected.Add(new (menu) =>
- {
- let directory = scope String();
- Path.GetDirectoryPath(sourceViewPanel.mFilePath, directory);
- ProcessStartInfo procInfo = scope ProcessStartInfo();
- procInfo.UseShellExecute = true;
- procInfo.SetFileName(directory);
- let process = scope SpawnedProcess();
- process.Start(procInfo).IgnoreError();
- });
- }
- if (menu.mItems.Count > 0)
- {
- SelfToRootTranslate(x, mHeight, var windowX, var windowY);
- MenuWidget menuWidget = DarkTheme.sDarkTheme.CreateMenuWidget(menu);
- menuWidget.Init(mWidgetWindow.mRootWidget, windowX, windowY);
- }
- else
- delete menu;
- }
-
- if ((mIsRightTab) && (btn == 0) && (btnCount > 1))
- {
- IDEApp.sApp.MakeTabPermanent(this);
- }
- }
- public override void Update()
- {
- base.Update();
- Point point;
- if (DarkTooltipManager.CheckMouseover(this, 25, out point))
- {
- var sourceViewPanel = mContent as SourceViewPanel;
- if (sourceViewPanel != null)
- DarkTooltipManager.ShowTooltip(sourceViewPanel.mFilePath, this, point.x, 14);
- }
- }
- }
- public SourceViewPanel FindSourceViewPanel(String filePath)
- {
- if (filePath == null)
- return null;
- String useFilePath = scope String(filePath);
- if (!IDEUtils.FixFilePath(useFilePath))
- return null;
-
- SourceViewPanel sourceViewPanel = null;
- WithTabs(scope [&] (tabButton) =>
- {
- if ((sourceViewPanel == null) && (tabButton.mContent is SourceViewPanel))
- {
- var checkedResourceViewPanel = (SourceViewPanel)tabButton.mContent;
- if (Path.Equals(checkedResourceViewPanel.mFilePath, useFilePath))
- sourceViewPanel = checkedResourceViewPanel;
- }
- });
- return sourceViewPanel;
- }
- void MakeTabPermanent(DarkTabbedView.DarkTabButton tabButton)
- {
- tabButton.mDragHelper.mAllowDrag = false;
- tabButton.mTextColor = Color.White;
- tabButton.mIsRightTab = false;
- var darkTabbedView = (DarkTabbedView)tabButton.mTabbedView;
- darkTabbedView.SetRightTab(null, false);
- darkTabbedView.AddTab(tabButton);
- tabButton.Activate();
- }
- public SourceEditWidget CreateSourceEditWidget(SourceEditWidget refEditWidget = null)
- {
- var editWidget = new SourceEditWidget(null, refEditWidget);
- editWidget.Content.mIsMultiline = true;
- editWidget.Content.mWordWrap = false;
- editWidget.InitScrollbars(true, true);
- var editWidgetContent = (SourceEditWidgetContent)editWidget.Content;
- //mEditWidget.mVertScrollbar.mScrollIncrement = editWidgetContent.mFont.GetLineSpacing();
- editWidgetContent.mHiliteColor = 0xFF384858;
- editWidgetContent.mUnfocusedHiliteColor = 0x80384858;
- return editWidget;
- }
- public bool CreateEditDataEditWidget(FileEditData editData, SourceHash.Kind hashKind = .MD5)
- {
- if (editData.mEditWidget != null)
- return true;
- var text = scope String();
- if (LoadTextFile(editData.mFilePath, text, true, scope () =>
- {
- for (int i < text.Length)
- {
- char8 c = text[i];
- if (c == '\r')
- {
- char8 nextC = 0;
- if (i < text.Length - 1)
- {
- nextC = text[++i];
- if (nextC == 0)
- {
- if (i < text.Length - 2)
- nextC = text[++i];
- }
- }
- if (nextC == '\n')
- editData.mLineEndingKind = .CrLf;
- else
- editData.mLineEndingKind = .Cr;
- break;
- }
- else if (c == '\n')
- {
- editData.mLineEndingKind = .Lf;
- break;
- }
- }
- editData.mLoadedHash = SourceHash.Create(hashKind, text);
- } ) case .Err)
- return false;
- mFileWatcher.FileIsValid(editData.mFilePath);
- using (mMonitor.Enter())
- {
- if (editData.mEditWidget != null)
- return true;
- editData.mEditWidget = CreateSourceEditWidget();
- editData.mEditWidget.Content.AppendText(text);
- editData.mOwnsEditWidget = true;
- editData.mLastFileTextVersion = editData.mEditWidget.Content.mData.mCurTextVersionId;
- editData.mEditWidgetCreatedEvent();
- }
- mFileDataDataRevision++;
- return true;
- }
- public FileEditData GetEditData(String filePath, bool createEditData = true, bool createEditDataWidget = true, SourceHash.Kind hashKind = .MD5)
- {
- FileEditData editData;
- using (mMonitor.Enter())
- {
- String fixedFilePath = scope String(filePath);
- IDEUtils.FixFilePath(fixedFilePath);
- if (!Environment.IsFileSystemCaseSensitive)
- fixedFilePath.ToUpper();
- if (!mFileEditData.TryGetValue(fixedFilePath, out editData))
- {
- if (createEditData)
- {
- editData = new FileEditData();
- editData.mFilePath = new String(filePath);
- mFileEditData.Add(new String(fixedFilePath), editData);
- }
- }
- }
- if (createEditDataWidget)
- CreateEditDataEditWidget(editData, hashKind);
- return editData;
- }
- public void RenameEditData(String oldPath, String newPath)
- {
- using (mMonitor.Enter())
- {
- String oldFixedFilePath = scope String(oldPath);
- IDEUtils.FixFilePath(oldFixedFilePath);
- if (!Environment.IsFileSystemCaseSensitive)
- oldFixedFilePath.ToUpper();
- String newFixedFilePath = scope String(newPath);
- IDEUtils.FixFilePath(newFixedFilePath);
- if (!Environment.IsFileSystemCaseSensitive)
- newFixedFilePath.ToUpper();
- String outKey;
- FileEditData editData;
- if (mFileEditData.TryGetValue(oldFixedFilePath, out outKey, out editData))
- {
- mFileEditData.Remove(oldFixedFilePath);
- delete outKey;
- editData.mFilePath.Set(newPath);
- String* newKeyPtr;
- FileEditData* newEditDataPtr;
- if (mFileEditData.TryAdd(newFixedFilePath, out newKeyPtr, out newEditDataPtr))
- {
- *newKeyPtr = new String(newFixedFilePath);
- *newEditDataPtr = editData;
- }
- else
- {
- let oldEditData = *newEditDataPtr;
- // This can happen if we rename a file to the name of a file that used to exist and is bound to
- // another source view panel
- WithTabs(scope (tab) =>
- {
- if (var sourceViewPanel = tab.mContent as SourceViewPanel)
- {
- if (sourceViewPanel.mEditData == oldEditData)
- {
- tab.mTabbedView.RemoveTab(tab, true);
- }
- }
- });
- for (var projectSource in oldEditData.mProjectSources)
- projectSource.mEditData = editData;
- gApp.ProcessDeferredDeletes();
- oldEditData.Deref();
- //editData.Deref();
- *newEditDataPtr = editData;
- }
- }
- }
- }
- public void DeleteEditData(FileEditData editData)
- {
- if (editData.mOwnsEditWidget)
- {
- delete editData.mEditWidget;
- editData.mEditWidget = null;
- editData.mOwnsEditWidget = false;
- }
- //mFileEditData.Remove(editData);
- //delete editData;
- }
- public FileEditData GetEditData(ProjectSource projectSource, bool createEditWidget = true, SourceHash.Kind hashKind = .MD5)
- {
- using (mMonitor.Enter())
- {
- if (projectSource.mEditData == null)
- {
- String filePath = scope String();
- projectSource.GetFullImportPath(filePath);
- var editData = GetEditData(filePath, true, false);
- if (editData != null)
- {
- editData.mProjectSources.Add(projectSource);
- editData.Ref();
- projectSource.mEditData = editData;
- }
- }
- /*editData = CreateEditData(filePath);
- /*if (projectSource.mSavedContent == null)
- {
- editData = CreateEditData(filePath);
- }
- else
- {
- editData = new FileEditData();
- editData.mFilePath = new String(filePath);
- editData.mEditWidget = CreateSourceEditWidget();
- editData.mEditWidget.Content.AppendText(projectSource.mSavedContent);
- editData.mEditWidget.Content.mData.mTextIdData.DuplicateFrom(projectSource.mSavedCharIdData);
- editData.mOwnsEditWidget = true;
- }*/
- if (editData != null)
- {
- editData.Ref();
- mFileEditData.Add(editData);
- projectSource.mEditData = editData;
- projectSource.mEditData.mLastFileTextVersion = projectSource.mEditData.mEditWidget.Content.mData.mCurTextVersionId;
- }
- }
- return projectSource.mEditData;*/
- }
- if (createEditWidget)
- CreateEditDataEditWidget(projectSource.mEditData);
- return projectSource.mEditData;
- }
- public SourceViewPanel ShowSourceFile(String filePath, ProjectSource projectSource = null, SourceShowType showType = SourceShowType.ShowExisting, bool setFocus = true)
- {
- //TODO: PUT BACK!
- //return null;
- #unwarn
- String useFilePath = filePath;
- var useProjectSource = projectSource;
- if ((useFilePath == null) && (useProjectSource != null))
- {
- useFilePath = scope:: String();
- useProjectSource.GetFullImportPath(useFilePath);
- }
- else if (useFilePath != null)
- {
- useFilePath = scope:: String(useFilePath);
- }
-
- if ((useFilePath != null) && (!IDEUtils.FixFilePath(useFilePath)))
- return null;
- if ((useFilePath == null) & (showType != .New))
- return null;
- SourceViewPanel sourceViewPanel = null;
- DarkTabbedView.DarkTabButton sourceViewPanelTab = null;
- if ((useProjectSource == null) && (useFilePath != null))
- {
- useProjectSource = FindProjectSourceItem(useFilePath);
- if (useProjectSource != null)
- {
- var projectSourcePath = scope:: String();
- useProjectSource.GetFullImportPath(projectSourcePath);
- useFilePath = projectSourcePath;
- }
- }
- if (showType != SourceShowType.New)
- {
- Action<TabbedView.TabButton> tabFunc = scope [&] (tabButton) =>
- {
- var darkTabButton = (DarkTabbedView.DarkTabButton)tabButton;
- if (tabButton.mContent is SourceViewPanel)
- {
- var checkSourceViewPanel = (SourceViewPanel)tabButton.mContent;
-
- if (checkSourceViewPanel.FileNameMatches(useFilePath))
- {
- if (sourceViewPanel != null)
- {
- // Already found one that matches our active tabbed view?
- if (sourceViewPanelTab.mTabbedView == mActiveDocumentsTabbedView)
- return;
- }
- sourceViewPanel = checkSourceViewPanel;
- sourceViewPanelTab = darkTabButton;
- }
- }
- };
- if ((showType == .ShowExistingInActivePanel) && (mActiveDocumentsTabbedView != null))
- {
- mActiveDocumentsTabbedView.WithTabs(tabFunc);
- }
- else
- WithTabs(tabFunc);
- if (sourceViewPanelTab != null)
- {
- //matchedTabButton = tabButton;
- if ((sourceViewPanelTab.mIsRightTab) && (showType != SourceShowType.Temp))
- {
- MakeTabPermanent(sourceViewPanelTab);
- }
- if ((useProjectSource != null) &&
- (sourceViewPanel.mProjectSource != useProjectSource))
- {
- //TODO: Change project source in view
- sourceViewPanel.AttachToProjectSource(useProjectSource);
- //sourceViewPanel.mProjectSource = useProjectSource;
- //sourceViewPanel.QueueFullRefresh(true);
- }
- if ((sourceViewPanel.mWidgetWindow != null) && (!HasModalDialogs()) && (!mRunningTestScript))
- sourceViewPanel.mWidgetWindow.SetForeground();
- sourceViewPanelTab.Activate(setFocus);
- sourceViewPanelTab.mTabbedView.FinishTabAnim();
- if (setFocus)
- sourceViewPanel.FocusEdit();
- }
- }
- if (sourceViewPanel != null)
- return sourceViewPanel;
- //ShowSourceFile(filePath, projectSource, showTemp, setFocus);
- DarkTabbedView tabbedView = GetDefaultDocumentTabbedView();
- sourceViewPanel = new SourceViewPanel();
- bool success;
- if (useProjectSource != null)
- {
- success = sourceViewPanel.Show(useProjectSource, !mInitialized);
- }
- else
- success = sourceViewPanel.Show(useFilePath, !mInitialized);
- if (!success)
- {
- sourceViewPanel.Close();
- delete sourceViewPanel;
- return null;
- }
- var newTabButton = new SourceViewTab();
- newTabButton.Label = "";
- if (useFilePath != null)
- Path.GetFileName(useFilePath, newTabButton.mLabel);
- else
- newTabButton.mLabel.Set("untitled");
- newTabButton.mWantWidth = newTabButton.GetWantWidth();
- newTabButton.mHeight = tabbedView.mTabHeight;
- newTabButton.mContent = sourceViewPanel;
- if (showType == SourceShowType.Temp)
- {
- let prevAutoClose = tabbedView.mAutoClose;
- defer { tabbedView.mAutoClose = prevAutoClose; }
- tabbedView.mAutoClose = false;
- if (tabbedView.mRightTab != null)
- {
- CloseDocument(tabbedView.mRightTab.mContent);
- Debug.Assert(tabbedView.mRightTab == null);
- }
- newTabButton.mTextColor = 0xFFC8C8C8;
- newTabButton.mIsRightTab = true;
- tabbedView.SetRightTab(newTabButton);
- }
- else
- tabbedView.AddTab(newTabButton);
- newTabButton.mCloseClickedEvent.Add(new () => DocumentCloseClicked(sourceViewPanel));
- newTabButton.Activate(setFocus);
- if (setFocus)
- sourceViewPanel.FocusEdit();
- return sourceViewPanel;
- }
- int32 GetRecentFilesIdx(String filePath)
- {
- return mRecentlyDisplayedFiles.FindIndex(scope (item) => Path.Equals(item, filePath));
- }
- public void UpdateRecentFilesMenuItems(List<String> filesList)
- {
- }
- public void UpdateRecentDisplayedFilesMenuItems()
- {
- if (mWindowMenu == null)
- return;
- RecentFiles.UpdateMenu(mRecentlyDisplayedFiles, mWindowMenu, mRecentlyDisplayedFilesMenuItems, scope (idx, sysMenu) =>
- {
- sysMenu.mOnMenuItemSelected.Add(new (evt) => ShowRecentFile(idx));
- });
- }
- public void UpdateRecentFileMenuItems(RecentFiles.RecentKind recentKind)
- {
- let entry = mSettings.mRecentFiles.mRecents[(int)recentKind];
- if (entry.mMenu == null)
- return;
- RecentFiles.UpdateMenu(entry.mList, entry.mMenu, entry.mMenuItems, scope (idx, sysMenu) =>
- {
- sysMenu.mOnMenuItemSelected.Add(new (evt) => ShowRecentFile(recentKind, idx));
- });
- }
- public void UpdateRecentFileMenuItems()
- {
- if (mWindowMenu == null)
- return;
- for (RecentFiles.RecentKind recentKind = default; recentKind < RecentFiles.RecentKind.COUNT; recentKind++)
- {
- UpdateRecentFileMenuItems(recentKind);
- }
- }
- public void AddRecentFile(RecentFiles.RecentKind recentKind, StringView file)
- {
- mSettings.mRecentFiles.Add(recentKind, file);
- UpdateRecentFileMenuItems(recentKind);
- }
- public void AddToRecentDisplayedFilesList(String path)
- {
- //int idx = mRecentFilesList.IndexOf(path);
- RecentFiles.Add(mRecentlyDisplayedFiles, path);
- UpdateRecentDisplayedFilesMenuItems();
- }
- void ShowRecentFile(int idx, bool setFocus = true)
- {
- String sourceFile = mRecentlyDisplayedFiles[idx];
- if (sourceFile == DisassemblyPanel.sPanelName)
- {
- ShowDisassemblyPanel();
- return;
- }
- ShowSourceFile(sourceFile, null, SourceShowType.ShowExisting, setFocus);
- }
- void ShowRecentFile(RecentFiles.RecentKind recentKind, int idx, bool setFocus = true)
- {
- String filePath = mSettings.mRecentFiles.mRecents[(int)recentKind].mList[idx];
- switch (recentKind)
- {
- case .OpenedFile:
- ShowSourceFile(filePath, null, SourceShowType.ShowExisting, setFocus);
- case .OpenedWorkspace:
- var selectedPath = scope String()..AppendF(filePath);
- selectedPath.Append(Path.DirectorySeparatorChar);
- selectedPath.Append("BeefSpace.toml");
- String.NewOrSet!(mDeferredOpenFileName, selectedPath);
- mDeferredOpen = .Workspace;
- case .OpenedCrashDump:
- String.NewOrSet!(mDeferredOpenFileName, filePath);
- mDeferredOpen = .CrashDump;
- case .OpenedDebugSession:
- String.NewOrSet!(mDeferredOpenFileName, filePath);
- mDeferredOpen = .DebugSession;
- default:
- }
- }
- void DocumentCloseClicked(Widget documentPanel)
- {
- var sourceViewPanel = documentPanel as SourceViewPanel;
- if (sourceViewPanel == null)
- {
- CloseDocument(documentPanel);
- return;
- }
- // This is a test
- // This is a test
- if ((!sourceViewPanel.HasUnsavedChanges()) || (!sourceViewPanel.IsLastViewOfData()))
- {
- CloseDocument(sourceViewPanel);
- return;
- }
- // This is a test
- String fileName = scope String();
- if (sourceViewPanel.mFilePath != null)
- Path.GetFileName(sourceViewPanel.mFilePath, fileName);
- else
- fileName.Append("untitled");
- Dialog aDialog = ThemeFactory.mDefault.CreateDialog("Save file?", StackStringFormat!("Save changes to '{0}' before closing?", fileName), DarkTheme.sDarkTheme.mIconWarning);
- aDialog.mDefaultButton = aDialog.AddButton("Save", new (evt) => { SaveFile(sourceViewPanel); CloseDocument(sourceViewPanel); });
- aDialog.AddButton("Don't Save", new (evt) => CloseDocument(sourceViewPanel));
- aDialog.mEscButton = aDialog.AddButton("Cancel");
- aDialog.PopupWindow(mMainWindow);
- }
- public void CloseDocument(Widget documentPanel)
- {
- bool hasFocus = false;
- var sourceViewPanel = documentPanel as SourceViewPanel;
- if ((documentPanel.mWidgetWindow != null) && (documentPanel.mWidgetWindow.mFocusWidget != null))
- {
- if (documentPanel.mWidgetWindow.mFocusWidget.HasParent(documentPanel))
- hasFocus = true;
- }
- /*if (sourceViewPanel != null)
- hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/
- if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges()))
- {
- // When we close a Beef file that has modified text, we need to revert by
- // reparsing from the actual source file
- if (sourceViewPanel.mIsBeefSource)
- {
- mBfResolveHelper.DeferReparse(sourceViewPanel.mFilePath, null);
- //mBfResolveHelper.DeferRefreshVisibleViews(null);
- }
- var projectSource = sourceViewPanel.mProjectSource;
- if (projectSource != null)
- {
- var editData = GetEditData(projectSource, true);
- if (editData != null)
- {
- var editWidgetContent = editData.mEditWidget.mEditWidgetContent;
- //TODO: Verify this, once we have multiple panes allowed within a single SourceViewContent
- if (editWidgetContent.mData.mUsers.Count == 1) // Is last view of data...
- {
- if ((editData != null) && (editData.mHadRefusedFileChange))
- {
- // If we didn't take an external file change then closing the file means we want to revert
- // our data to the version on disk
- sourceViewPanel.Reload();
- }
- else
- {
- // Undo until we either get to whatever the last saved state was, or until we
- // get to a global action like renaming a symbol - we need to leave those
- // so the global undo actually works if invoked from another file
- while (editData.HasTextChanged())
- {
- var nextUndoAction = editWidgetContent.mData.mUndoManager.GetLastUndoAction();
- if (nextUndoAction == null)
- break;
- if (nextUndoAction is UndoBatchEnd)
- {
- var undoBatchEnd = (UndoBatchEnd)nextUndoAction;
- if (undoBatchEnd.Name.StartsWith("#"))
- {
- break;
- }
- }
- editWidgetContent.mData.mUndoManager.Undo();
- }
- editWidgetContent.mData.mTextIdData.Prepare();
- }
- }
- }
- }
- }
- DarkTabbedView tabbedView = null;
- DarkTabbedView.DarkTabButton tabButton = null;
- WithTabs(scope [&] (tab) =>
- {
- if (tab.mContent == documentPanel)
- {
- tabbedView = (DarkTabbedView)tab.mTabbedView;
- tabButton = (DarkTabbedView.DarkTabButton)tab;
- }
- });
- Debug.Assert(tabbedView != null);
- if (tabbedView == null)
- return;
- int32 recentFileIdx = -1;
- if (sourceViewPanel != null)
- {
- sourceViewPanel.Dispose();
- if (sourceViewPanel.mFilePath != null)
- recentFileIdx = GetRecentFilesIdx(sourceViewPanel.mFilePath);
- }
- /*if (tabButton.mIsRightTab)
- tabbedView.SetRightTab(null);
- else*/
-
- if (documentPanel is DisassemblyPanel)
- recentFileIdx = GetRecentFilesIdx(DisassemblyPanel.sPanelName);
- //mRecentFilesList.Remove(DisassemblyPanel.sPanelName);
- if (recentFileIdx != -1)
- {
- delete mRecentlyDisplayedFiles[recentFileIdx];
- mRecentlyDisplayedFiles.RemoveAt(recentFileIdx);
- UpdateRecentDisplayedFilesMenuItems();
- }
- TabbedView.TabButton nextTab = null;
- bool foundRemovedTab = false;
- // Select the previous tab or the next one (if this is the first)
- tabbedView.WithTabs(scope [&] (checkTab) =>
- {
- if (checkTab == tabButton)
- foundRemovedTab = true;
- else if ((!foundRemovedTab) || (nextTab == null))
- nextTab = checkTab;
- });
- tabbedView.RemoveTab(tabButton);
- if (nextTab != null)
- {
- nextTab.Activate(hasFocus);
- }
- else if (tabbedView.mAutoClose)
- {
- tabbedView.mParentDockingFrame.RemoveDockedWidget(tabbedView);
- gApp.DeferDelete(tabbedView);
- var documentTabbedView = FindDocumentTabbedView();
- if (documentTabbedView != null)
- {
- Debug.Assert(documentTabbedView != tabbedView);
- // If there is some OTHER document window them show that and remove this empty one
- documentTabbedView.GetActiveTab().Activate();
- }
- }
- //var intDict = scope Dictionary<String, int>();
- /*if (mRecentFilesList.Count >= 1)
- {
- // Show second-last file
- ShowRecentFile(0, hasFocus);
- }*/
- //var newActiveTab = tabbedView.GetActiveTab();
- //if (newActiveTab != null)
- //newActiveTab.mContent.SetFocus();
- }
- void TryCloseCurrentDocument()
- {
- var activeDocumentPanel = GetActiveDocumentPanel();
- if (activeDocumentPanel != null)
- {
- if (activeDocumentPanel is SourceViewPanel)
- {
- var sourceViewPanel = (SourceViewPanel)activeDocumentPanel;
- DocumentCloseClicked(sourceViewPanel);
- return;
- }
- CloseDocument(activeDocumentPanel);
- return;
- }
- var activePanel = GetActivePanel();
- if (activePanel != null)
- CloseDocument(activePanel);
- }
- void TryCloseAllDocuments()
- {
- var docPanels = scope List<Widget>();
- WithTabs(scope [&] (tab) =>
- {
- if ((tab.mContent is SourceViewPanel) || (tab.mTabbedView.mIsFillWidget))
- {
- docPanels.Add(tab.mContent);
- }
- });
-
- for (var docPanel in docPanels)
- DocumentCloseClicked(docPanel);
- }
- void SplitView()
- {
- var sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel != null)
- {
- sourceViewPanel.SplitView();
- }
- }
- [IDECommand]
- void CloseCurrentDocument()
- {
- var activeDocumentPanel = GetActiveDocumentPanel();
- if (activeDocumentPanel != null)
- CloseDocument(activeDocumentPanel);
- }
- public SourceViewPanel ShowProjectItem(ProjectItem projectItem, bool showTemp = true, bool setFocus = true)
- {
- if (projectItem is ProjectSource)
- {
- var projectSource = (ProjectSource)projectItem;
- var fullPath = scope String();
- projectSource.GetFullImportPath(fullPath);
- return ShowSourceFile(fullPath, projectSource, showTemp ? SourceShowType.Temp : SourceShowType.ShowExistingInActivePanel, setFocus);
- }
- return null;
- }
- public SourceViewPanel ShowSourceFileLocation(String filePath, int showHotIdx, int refHotIdx, int line, int column, LocatorType hilitePosition, bool showTemp = false)
- {
- var sourceViewPanel = ShowSourceFile(filePath, null, showTemp ? SourceShowType.Temp : SourceShowType.ShowExisting);
- if (sourceViewPanel == null)
- return null;
- sourceViewPanel.ShowHotFileIdx(showHotIdx);
- sourceViewPanel.ShowFileLocation(refHotIdx, Math.Max(0, line), Math.Max(0, column), hilitePosition);
- return sourceViewPanel;
- }
- public SourceViewPanel ShowSourceFileLocation(String filePath, int32 cursorIdx, LocatorType hilitePosition)
- {
- var sourceViewPanel = ShowSourceFile(filePath);
- sourceViewPanel.ShowFileLocation(cursorIdx, hilitePosition);
- return sourceViewPanel;
- }
- public void ShowPCLocation(int32 stackIdx, bool onlyShowCurrent = false, bool wantShowSource = false, bool wantShowDisassembly = false, bool setFocus = true)
- {
- if (stackIdx == -1)
- return;
- ClearDeferredUserRequest();
- int addr;
- String filePath = scope String();
- int hotIdx;
- int defLineStart;
- int defLineEnd;
- int line;
- int column;
- int language;
- int stackSize;
- mDebugger.CheckCallStack();
- String entryName = scope String();
- DebugManager.FrameFlags frameFlags;
- for (int pass < 2)
- {
- mDebugger.GetStackFrameInfo(stackIdx, entryName, out addr, filePath, out hotIdx, out defLineStart, out defLineEnd, out line, out column, out language, out stackSize, out frameFlags);
- if (!frameFlags.HasFlag(.HasPendingDebugInfo))
- break;
-
- int bangPos = entryName.IndexOf('!');
- if (bangPos == -1)
- break;
-
- String moduleName = scope String(entryName, 0, bangPos);
- int result = mDebugger.LoadDebugInfoForModule(moduleName);
- if (result == 0)
- break;
- // If we are backgrounding the load then we'll try to open this up afterward
- if (result == 2)
- {
- SetDeferredUserRequest(new DeferredShowPCLocation(stackIdx));
- return;
- }
- // Try again on result == 1
- filePath.Clear();
- entryName.Clear();
- mCallStackPanel.MarkCallStackDirty();
- mThreadPanel.MarkThreadsDirty();
- }
- bool useWantShowDisassembly = wantShowDisassembly;
- for (var breakpoint in mDebugger.mBreakpointList)
- {
- if (((breakpoint.mAddressRequested) || (breakpoint.mInstrOffset != -1)) &&
- (breakpoint.ContainsAddress(addr)))
- useWantShowDisassembly = true;
- }
- String aliasFilePath = null;
- String loadCmd = null;
- SourceHash hash = default;
- int hashPos = filePath.IndexOf('#');
- bool checkForOldFileInfo = false;
- if (hashPos != -1)
- {
- let hashStr = StringView(filePath, hashPos + 1);
- if (hashStr.Length == 32)
- {
- if (MD5Hash.Parse(hashStr) case .Ok(let parsedHash))
- {
- hash = .MD5(parsedHash);
- }
- }
- else
- {
- if (SHA256Hash.Parse(hashStr) case .Ok(let parsedHash))
- {
- hash = .SHA256(parsedHash);
- }
- }
- filePath.RemoveToEnd(hashPos);
- if (frameFlags.HasFlag(.CanLoadOldVersion))
- {
- aliasFilePath = scope:: String(filePath);
- String fileText = scope String();
- SourceHash fileHash = default;
- var hashKind = hash.GetKind();
- if (hashKind == .None)
- hashKind = .MD5;
- LoadTextFile(filePath, fileText, false, scope [&] () => { fileHash = SourceHash.Create(hashKind, fileText); }).IgnoreError();
- if (fileHash != hash)
- checkForOldFileInfo = true;
- }
- }
- else
- {
- if (!File.Exists(filePath))
- checkForOldFileInfo = true;
- }
- if (checkForOldFileInfo)
- {
- String outFileInfo = scope String();
- mDebugger.GetStackFrameOldFileInfo(mDebugger.mActiveCallStackIdx, outFileInfo);
- var args = outFileInfo.Split!('\n');
- if (args.Count == 3)
- {
- aliasFilePath = scope:: String(filePath);
- filePath.Set(args[0]);
- loadCmd = scope:: String(args[1]);
- }
- }
- // If we attach to an executable and we happen to have the Diassembly panel shown, STILL just show the source instead of the disassembly at first
- if (mIsAttachPendingSourceShow)
- {
- mInDisassemblyView = false;
- mIsAttachPendingSourceShow = false;
- }
- bool hasSource = filePath.Length != 0;
- if ((IsInDisassemblyMode(wantShowSource)) || (!hasSource) || (useWantShowDisassembly))
- {
- if (frameFlags.HasFlag(.HasPendingDebugInfo))
- {
- SetDeferredUserRequest(new DeferredShowPCLocation(stackIdx));
- }
- else
- {
- var disassemblyPanel = ShowDisassemblyPanel(true);
- if (aliasFilePath != null)
- String.NewOrSet!(disassemblyPanel.mAliasFilePath, aliasFilePath);
- disassemblyPanel.Show(addr, filePath, line, column, hotIdx, defLineStart, defLineEnd);
- disassemblyPanel.mSourceHash = hash;
- }
- }
- else if (filePath.Length > 0)
- {
- if ((IsCrashDump) && (!mShowedFirstDocument))
- {
- mShowedFirstDocument = true;
- ShowCallstack();
- }
- var sourceViewPanel = ShowSourceFile(filePath, null, SourceShowType.ShowExisting, setFocus);
- if (sourceViewPanel != null)
- {
- sourceViewPanel.mIsSourceCode = true; // It's always source code, even if there is no extension (ie: stl types like "vector")
- if ((aliasFilePath != null) && (sourceViewPanel.mAliasFilePath == null))
- String.NewOrSet!(sourceViewPanel.mAliasFilePath, aliasFilePath);
- if (sourceViewPanel.mLoadFailed)
- {
- sourceViewPanel.mLoadedHash = hash;
- if (loadCmd != null)
- {
- sourceViewPanel.SetLoadCmd(loadCmd);
- }
- }
- else if ((hash != .None) && (hash != sourceViewPanel.mLoadedHash))
- {
- sourceViewPanel.ShowWrongHash();
- }
- int showHotIdx = -1;
- if (!onlyShowCurrent)
- {
- bool checkForChange = false;
- if (frameFlags.HasFlag(.WasHotReplaced))
- checkForChange = true;
- else
- {
- // If we make a trivial change (ie: characters in a comment) then we won't actually generate a new method
- // So don't show as an "old file" if we don't actually have any file changes and we're on the current hot version
- if ((sourceViewPanel.mProjectSource != null) && (sourceViewPanel.mProjectSource.mHasChangedSinceLastSuccessfulCompile))
- checkForChange = true;
- }
- if (checkForChange)
- {
- if (sourceViewPanel.HasTextChangedSinceCompile(defLineStart, defLineEnd, hotIdx))
- showHotIdx = hotIdx;
- }
- /*else
- {
- if (sourceViewPanel.HasTextChangedSinceCompile(defLineStart, defLineEnd, -1))
- showHotIdx = mWorkspace.GetHighestCompileIdx();
- }*/
- }
- sourceViewPanel.ShowHotFileIdx(showHotIdx);
- sourceViewPanel.ShowFileLocation(hotIdx, Math.Max(0, line), Math.Max(0, column), LocatorType.Smart);
- }
- var disassemblyPanel = TryGetDisassemblyPanel(false);
- if (disassemblyPanel != null)
- disassemblyPanel.Show(addr, filePath, line, column, hotIdx, defLineStart, defLineEnd);
- }
- }
- public override void UnhandledCommandLine(String key, String value)
- {
- Fail(StackStringFormat!("Unhandled command line param: {0}", key));
- }
- public override bool HandleCommandLineParam(String key, String value)
- {
- if (mLaunchData != null)
- {
- if (mLaunchData.mArgs != null)
- {
- if (!mLaunchData.mArgs.IsEmpty)
- mLaunchData.mArgs.Append(" ");
- mLaunchData.mArgs.Append(key);
- if (value != null)
- mLaunchData.mArgs.Append("=", value);
- return true;
- }
- if ((key == "--") && (value == null))
- {
- mLaunchData.mArgs = new .();
- return true;
- }
- }
- if (base.HandleCommandLineParam(key, value))
- return true;
- if (value == null)
- {
- switch (key)
- {
- case "-autoshutdown":
- mDebugAutoShutdownCounter = 200;
- case "-new":
- mVerb = .New;
- case "-testNoExit":
- mExitWhenTestScriptDone = false;
- case "-firstRun":
- mForceFirstRun = true;
- mIsFirstRun = true;
- case "-clean":
- mWantsClean = true;
- case "-dbgCompileDump":
- mDbgCompileDump = true;
- case "-launchPaused":
- if (mLaunchData != null)
- mLaunchData.mPaused = true;
- else
- Fail("'-launchPaused' can only be used after '-launch'");
- default:
- return false;
- }
- return true;
- }
- else
- {
- switch (key)
- {
- #if BF_PLATFORM_WINDOWS
- case "-attachHandle":
- mProcessAttachHandle = (Windows.EventHandle)int32.Parse(value).GetValueOrDefault();
- #endif
- case "-attachId":
- mProcessAttachId = int32.Parse(value).GetValueOrDefault();
- case "-config":
- mConfigName.Set(value);
- case "-launch":
- if (mLaunchData == null)
- mLaunchData = new .();
- mLaunchData.mTargetPath.Set(value);
- #if BF_PLATFORM_WINDOWS
- case "-minidump":
- String.NewOrSet!(mCrashDumpPath, value);
- #endif
- case "-platform":
- mPlatformName.Set(value);
- case "-test":
- Runtime.SetCrashReportKind(.PrintOnly);
- String absTestPath = scope String();
- if (mWorkspace.mDir != null)
- Path.GetAbsolutePath(value, mWorkspace.mDir, absTestPath);
- else
- Path.GetFullPath(value, absTestPath);
- mWantsClean = true;
- mRunningTestScript = true;
- mScriptManager.SetTimeoutMS(20*60*1000); // 20 minute timeout
- mScriptManager.QueueCommandFile(absTestPath);
- case "-verbosity":
- if (value == "quiet")
- mVerbosity = .Quiet;
- else if (value == "minimal")
- mVerbosity = .Minimal;
- else if (value == "normal")
- mVerbosity = .Normal;
- else if (value == "detailed")
- mVerbosity = .Detailed;
- else if (value == "diagnostic")
- mVerbosity = .Diagnostic;
- else
- Fail(scope String()..AppendF("Invalid verbosity option: {}", value));
- case "-workspace","-proddir":
- var relDir = scope String(value);
- if ((relDir.EndsWith("\\")) || relDir.EndsWith("\""))
- relDir.RemoveToEnd(relDir.Length - 1);
- IDEUtils.FixFilePath(relDir);
- String fullDir = new String();
- Path.GetFullPath(relDir, fullDir);
- if ((File.Exists(fullDir)) || (IsBeefFile(fullDir)))
- {
- mWorkspace.mCompositeFile = new CompositeFile(fullDir);
- delete fullDir;
- }
- else
- mWorkspace.mDir = fullDir;
- case "-file":
- String.NewOrSet!(mDeferredOpenFileName, value);
- if (mDeferredOpenFileName.EndsWith(".bfdbg", .OrdinalIgnoreCase))
- mDeferredOpen = .DebugSession;
- else if (mDeferredOpenFileName.EndsWith(".dmp", .OrdinalIgnoreCase))
- mDeferredOpen = .CrashDump;
- else
- mDeferredOpen = .File;
- default:
- return false;
- }
- return true;
- }
- }
- class Board : Widget
- {
- public override void Draw(Graphics g)
- {
- base.Draw(g);
- using (g.PushColor(0xFFFFFFFF))
- g.FillRect(0, 0, 80, 80);
- }
- }
- public void Output(String outStr)
- {
- #if CLI
- Console.Write(outStr);
- return;
- #endif
- #unwarn
- outStr.Replace("\r", "");
- mOutputPanel.Write(outStr);
- }
- public void OutputSmart(String outStr)
- {
- #if CLI
- Console.Write(outStr);
- return;
- #endif
- #unwarn
- if (outStr.Contains('\r'))
- {
- let newStr = scope String()..Append(outStr);
- newStr.Replace("\r", "");
- mOutputPanel.WriteSmart(newStr);
- }
- else
- mOutputPanel.WriteSmart(outStr);
- }
- public void Output(String format, params Object[] args)
- {
- String outStr = format;
- if (args.Count > 0)
- {
- outStr = scope:: String();
- outStr.AppendF(outStr, params args);
- }
- else
- outStr = scope:: String(format);
- outStr.Replace("\r", "");
- mOutputPanel.Write(outStr);
- }
- public void OutputLine(String format, params Object[] args)
- {
- String outStr;
- if (args.Count > 0)
- {
- outStr = scope:: String();
- outStr.AppendF(format, params args);
- }
- else
- outStr = scope:: String(format);
- outStr.Replace("\r", "");
- if (mRunningTestScript)
- Console.WriteLine(outStr);
- #if CLI
- Console.WriteLine(outStr);
- #else
- outStr.Append("\n");
- mOutputPanel.Write(outStr);
- #endif
- }
- public void OutputErrorLine(String format, params Object[] args)
- {
- var errStr = scope String();
- errStr.Append("ERROR: ", format);
- OutputLineSmart(errStr, params args);
- }
- public void OutputWarnLine(String format, params Object[] args)
- {
- var warnStr = scope String();
- warnStr.AppendF(format, params args);
- #if CLI
- var outStr = warnStr;
- #else
- var outStr = scope String();
- outStr.AppendF("{0}{1}{2}", Font.EncodeColor(0xfffef860), warnStr, Font.EncodePopColor());
- #endif
- OutputLine(outStr);
- }
- public void OutputLineSmart(String format, params Object[] args)
- {
- String outStr;
- if (args.Count > 0)
- {
- outStr = scope:: String();
- outStr.AppendF(format, params args);
- }
- else
- outStr = scope:: String(format);
- outStr.Replace("\r", "");
- #if CLI
- Console.WriteLine(outStr);
- #else
- outStr.Append("\n");
- if (mOutputPanel != null)
- mOutputPanel.WriteSmart(outStr);
- #endif
- }
- public void OutputFormatted(String str, bool isDbgEvalOutput = false)
- {
- #if CLI
- Console.Write(str);
- return;
- #endif
- #unwarn
- String useStr = str;
- while (true)
- {
- if (mDebugger.GetRunState() != .NotStarted)
- {
- int locPos = useStr.IndexOf("^loc:");
- if (locPos != -1)
- {
- String addrSB = scope String();
- int i = locPos + 5;
- for (; i < useStr.Length; i++)
- {
- char8 c = useStr[i];
- if ((c == 'x') || ((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')))
- {
- addrSB.Append(c);
- }
- else if (c == '\'')
- {
- // Allow
- }
- else
- break;
- }
- int64 memoryAddress = int64.Parse(addrSB, .HexNumber);
- String srcLocation = scope String();
- mDebugger.GetAddressSourceLocation((int)memoryAddress, srcLocation);
- var newStr = scope:: String();
- newStr.Append(useStr, 0, locPos);
- newStr.Append(srcLocation);
- newStr.Append(useStr, i);
- useStr = newStr;
- continue;
- }
- }
- break;
- }
- if ((isDbgEvalOutput) && (mIsImmediateDebugExprEval))
- mImmediatePanel.WriteResult(useStr);
- OutputSmart(useStr);
- }
- public void SetScale(float scale, bool force = false)
- {
- var prevScale = DarkTheme.sScale;
- float useScale = Math.Clamp(scale, 0.5f, 4.0f);
- if ((prevScale == useScale) && (!force))
- return;
- DarkTheme.SetScale(useScale);
- RehupScale();
- for (int32 windowIdx = 0; windowIdx < mWindows.Count; windowIdx++)
- {
- var window = mWindows[windowIdx];
- var widgetWindow = window as WidgetWindow;
- if (widgetWindow != null)
- {
- widgetWindow.mRootWidget.RehupScale(prevScale, DarkTheme.sScale);
- var darkDockingFrame = widgetWindow.mRootWidget as DarkDockingFrame;
- if (widgetWindow == mMainWindow)
- darkDockingFrame = mDockingFrame;
- if (darkDockingFrame != null)
- {
- darkDockingFrame.WithAllDockedWidgets(scope (dockedWidget) =>
- {
- var tabbedView = dockedWidget as DarkTabbedView;
- if (tabbedView != null)
- {
- tabbedView.WithTabs(scope (tab) =>
- {
- var panel = tab.mContent as Panel;
- if ((panel != null) && (panel.mWidgetWindow == null))
- {
- panel.RehupScale(prevScale, DarkTheme.sScale);
- }
- });
- }
- });
- }
- widgetWindow.mRootWidget.RehupSize();
- }
- widgetWindow.mIsDirty = true;
- }
- }
- void SysKeyDown(KeyDownEvent evt)
- {
- if (evt.mHandled)
- return;
- var window = (WidgetWindow)evt.mSender;
- IDECommand.ContextFlags useFlags = .None;
- var activeWindow = GetActiveWindow();
- bool isMainWindow = activeWindow.mRootWidget is MainFrame;
- var activePanel = GetActivePanel() as Panel;
- if (activePanel is SourceViewPanel)
- useFlags |= .Editor;
- else if (activePanel is DisassemblyPanel)
- useFlags |= .Editor;
- if (isMainWindow)
- useFlags |= .MainWindow;
- if (evt.mKeyCode == .Tab)
- {
- if (activePanel != null)
- {
- if (activePanel.HandleTab(window.IsKeyDown(.Shift) ? -1 : 1))
- return;
- }
- }
- var keyState = scope KeyState();
- keyState.mKeyCode = evt.mKeyCode;
- keyState.mKeyFlags = evt.mKeyFlags;
- var curKeyMap = mCommands.mKeyMap;
- bool hadChordState = mKeyChordState != null;
- if (mKeyChordState != null)
- curKeyMap = mKeyChordState.mCommandMap;
- DeleteAndNullify!(mKeyChordState);
- KeyState matchedKey;
- IDECommandBase commandBase;
- if (curKeyMap.mMap.TryGetValue(keyState, out matchedKey, out commandBase))
- {
- if (var commandMap = commandBase as CommandMap)
- {
- mKeyChordState = new .();
- mKeyChordState.mCommandMap = commandMap;
- mKeyChordState.mKeyState = matchedKey;
- evt.mHandled = true;
- return;
- }
- else if (var command = commandBase as IDECommand)
- {
- bool foundMatch = false;
- if (useFlags != .None)
- {
- var checkCommand = command;
- while (checkCommand != null)
- {
- bool matches = checkCommand.mContextFlags == .None;
- if (checkCommand.mContextFlags.HasFlag(.Editor))
- matches |= useFlags.HasFlag(.Editor);
- if (checkCommand.mContextFlags.HasFlag(.MainWindow))
- matches |= useFlags.HasFlag(.MainWindow);
- if (matches)
- {
- checkCommand.mAction();
- foundMatch = true;
- }
- checkCommand = checkCommand.mNext;
- }
- }
- if (!foundMatch)
- {
- var checkCommand = command;
- while (checkCommand != null)
- {
- if (checkCommand.mContextFlags == .None)
- {
- checkCommand.mAction();
- foundMatch = true;
- }
- checkCommand = checkCommand.mNext;
- }
- }
- if (foundMatch)
- {
- evt.mHandled = true;
- return;
- }
- }
- }
- else
- {
- // Not found
- if (hadChordState)
- {
- Beep(.Error);
- evt.mHandled = true;
- return;
- }
- }
- SourceViewPanel sourceViewPanel = null;
- Widget focusWidget = window.mFocusWidget;
-
- if (focusWidget is EditWidget)
- focusWidget = focusWidget.mParent;
- if (focusWidget is SourceViewPanel)
- sourceViewPanel = (SourceViewPanel)focusWidget;
- //if (focusWidget is DisassemblyPanel)
- //break;
- if (evt.mKeyFlags == 0) // No ctrl/shift/alt
- {
- switch (evt.mKeyCode)
- {
- case KeyCode.F2:
- if (sourceViewPanel != null)
- {
- mBookmarkManager.NextBookmark();
- }
- else if (focusWidget is ProjectPanel)
- {
- var projectPanel = (ProjectPanel)focusWidget;
- projectPanel.TryRenameItem();
- }
- break;
- default:
- //OutputLine("Unknown key: {0}", (int)evt.mKeycode);
- break;
- }
- }
- }
-
- void ShowOpenFileInSolutionDialog()
- {
- var widgetWindow = GetCurrentWindow();
- if (widgetWindow != null)
- {
- var openFileInSolutionDialog = new OpenFileInSolutionDialog();
- openFileInSolutionDialog.PopupWindow(mMainWindow);
- }
- }
- void ChangeCase(bool toUpper)
- {
- let sourceViewPanel = GetActiveSourceViewPanel();
- if (sourceViewPanel == null)
- return;
- var ewc = sourceViewPanel.mEditWidget.mEditWidgetContent;
- if (!ewc.HasSelection())
- return;
- /*ewc.mSelection.Value.GetAsForwardSelect(var startPos, var endPos);
- for (int i = startPos; i < endPos; i++)
- {
- var c = ref ewc.mData.mText[i].mChar;
- if (toUpper)
- c = c.ToUpper;
- else
- c = c.ToLower;
- }*/
- var prevSel = ewc.mSelection.Value;
- var str = scope String();
- ewc.GetSelectionText(str);
- var prevStr = scope String();
- prevStr.Append(str);
- if (toUpper)
- str.ToUpper();
- else
- str.ToLower();
- if (str == prevStr)
- return;
- ewc.InsertAtCursor(str);
- ewc.mSelection = prevSel;
- }
- public bool IsFilteredOut(String fileName)
- {
- if (fileName.Contains('~'))
- return true;
- if (fileName.EndsWith(".TMP", .OrdinalIgnoreCase))
- return true;
- return false;
- }
- public static bool IsBeefFile(String fileName)
- {
- return fileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".bf", StringComparison.OrdinalIgnoreCase);
- }
- public static bool IsClangSourceFile(String fileName)
- {
- #if IDE_C_SUPPORT
- return fileName.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".c", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".cc", StringComparison.OrdinalIgnoreCase);
- #else
- return false;
- #endif
- }
- public static bool IsSourceCode(String fileName)
- {
- return fileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".bf", StringComparison.OrdinalIgnoreCase) ||
- fileName.EndsWith(".h", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) ||
- fileName.EndsWith(".c", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".cc", StringComparison.OrdinalIgnoreCase) ||
- fileName.EndsWith(".hpp", StringComparison.OrdinalIgnoreCase);
- }
- public static bool IsClangSourceHeader(String fileName)
- {
- return fileName.EndsWith(".h", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".hpp", StringComparison.OrdinalIgnoreCase);
- }
- public void GetBeefPreprocessorMacros(DefinesSet macroList)
- {
- let platform = Workspace.PlatformType.GetFromName(mPlatformName);
- if (platform != .Unknown)
- {
- String def = scope .();
- def.Append("BF_PLATFORM_");
- platform.ToString(def);
- def.ToUpper();
- macroList.Add(def);
- }
- var workspaceOptions = GetCurWorkspaceOptions();
- if (workspaceOptions.mRuntimeChecks)
- macroList.Add("BF_RUNTIME_CHECKS");
- if (workspaceOptions.mEnableObjectDebugFlags)
- macroList.Add("BF_ENABLE_OBJECT_DEBUG_FLAGS");
- if (workspaceOptions.mAllowHotSwapping)
- macroList.Add("BF_ALLOW_HOT_SWAPPING");
- bool is64Bits = Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 8;
- if (is64Bits)
- {
- if (workspaceOptions.mLargeStrings)
- macroList.Add("BF_LARGE_STRINGS");
- if (workspaceOptions.mLargeCollections)
- macroList.Add("BF_LARGE_COLLECTIONS");
- }
- // Only supported on Windows at the moment
- bool hasLeakCheck = false;
- #if BF_PLATFORM_WINDOWS
- if (workspaceOptions.mEnableRealtimeLeakCheck && workspaceOptions.mEnableObjectDebugFlags)
- {
- hasLeakCheck = true;
- macroList.Add("BF_ENABLE_REALTIME_LEAK_CHECK");
- }
- #endif
- if ((workspaceOptions.mAllocType == .Debug) || (hasLeakCheck))
- macroList.Add("BF_DEBUG_ALLOC");
- if (workspaceOptions.mEmitDynamicCastCheck)
- macroList.Add("BF_DYNAMIC_CAST_CHECK");
- if (workspaceOptions.mBuildKind == .Test)
- macroList.Add("BF_TEST_BUILD");
- macroList.Add("BF_LITTLE_ENDIAN");
- if (is64Bits)
- macroList.Add("BF_64_BIT");
- else
- macroList.Add("BF_32_BIT");
- //if (workspaceOptions.mE)
- macroList.Add("BF_HAS_VDATA_EXTENDER");
- }
- public void GetClangResolveArgs(Project project, List<String> outResolveArgs)
- {
- using (project.mMonitor.Enter())
- {
- //List<string> argsList = new List<string>();
- var options = GetCurProjectOptions(project);
- if (options == null)
- return;
- outResolveArgs.Add(new String("-std=c++11"));
- if (options.mCOptions.mEnableBeefInterop)
- {
- var beefPreprocMacros = scope DefinesSet();
- GetBeefPreprocessorMacros(beefPreprocMacros);
- for (var beefPreprocMacro in beefPreprocMacros.mDefines)
- {
- outResolveArgs.Add(new String("-D", beefPreprocMacro));
- }
- }
- for (var preprocMacro in options.mCOptions.mPreprocessorMacros)
- outResolveArgs.Add(new String("-D", preprocMacro));
- for (var includePath in options.mCOptions.mIncludePaths)
- {
- //outResolveArgs.Add(new String("-I", includePath));
- var fullIncludePath = scope String();
- project.GetProjectFullPath(includePath, fullIncludePath);
- outResolveArgs.Add(new String("-I", fullIncludePath));
- }
- String llvmDir = scope String(IDEApp.sApp.mInstallDir);
- IDEUtils.FixFilePath(llvmDir);
- llvmDir.Append("llvm/");
- outResolveArgs.Add(new String("-I", llvmDir, "lib/gcc/i686-w64-mingw32/5.2.0/include"));
- outResolveArgs.Add(new String("-I", llvmDir, "lib/gcc/i686-w64-mingw32/5.2.0/include-fixed"));
- outResolveArgs.Add(new String("-I", llvmDir, "i686-w64-mingw32/include"));
- outResolveArgs.Add(new String("-I", llvmDir, "i686-w64-mingw32/include/c++"));
- outResolveArgs.Add(new String("-I", llvmDir, "i686-w64-mingw32/include/c++/i686-w64-mingw32"));
- outResolveArgs.Add(new String("-I", llvmDir, "i686-w64-mingw32/include/c++/backward"));
- outResolveArgs.Add(new String("-I", llvmDir, "bin/../lib/clang/3.7.0/include"));
-
- outResolveArgs.Add(new String("-I", llvmDir, "i686-w64-mingw32/include"));
- outResolveArgs.Add(new String("-cc1"));
- outResolveArgs.Add(new String("-std=c++11"));
- outResolveArgs.Add(new String("-x"));
- outResolveArgs.Add(new String("c++"));
- /*outResolveArgs.Add(new String("-triple"));
- outResolveArgs.Add(new String("x86_64-pc-windows-gnu"));
- outResolveArgs.Add(new String("-target-cpu"));
- outResolveArgs.Add(new String("x86-64"));
- outResolveArgs.Add(new String("-target-feature"));
- outResolveArgs.Add(new String("+sse2"));*/
- }
- }
- public CompilerBase GetProjectCompilerForFile(String fileName)
- {
- if (IsBeefFile(fileName))
- return mBfResolveCompiler;
- #if IDE_C_SUPPORT
- if (IsClangSourceFile(fileName))
- return mDepClang;
- #endif
- return null;
- }
- public CompilerBase GetResolveCompilerForFile(String fileName)
- {
- if (IsBeefFile(fileName))
- return mBfResolveCompiler;
- #if IDE_C_SUPPORT
- if (IsClangSourceFile(fileName))
- return mResolveClang;
- #endif
- return null;
- }
- public void GetClangFiles(ProjectFolder projectFolder, List<ProjectSource> clangFiles)
- {
- for (var item in projectFolder.mChildItems)
- {
- if (item is ProjectSource)
- {
- var projectSource = (ProjectSource)item;
- if (!IsClangSourceFile(projectSource.mPath))
- continue;
- clangFiles.Add(projectSource);
- }
- if (item is ProjectFolder)
- {
- var innerProjectFolder = (ProjectFolder)item;
- GetClangFiles(innerProjectFolder, clangFiles);
- }
- }
- }
- /*void StopExecutionInstance()
- {
- if (mExecutionInstance != null)
- {
- try
- {
- mExecutionInstance.mProcess.Kill();
- }
- catch (Exception)
- {
- }
- }
- }*/
- const int cArgFileThreshold = 0x7800;
- public ExecutionQueueCmd QueueRun(String fileName, String args, String workingDir, ArgsFileKind argsFileKind = .None)
- {
- var executionQueueCmd = new ExecutionQueueCmd();
- executionQueueCmd.mFileName = new String(fileName);
- executionQueueCmd.mArgs = new String(args);
- executionQueueCmd.mWorkingDir = new String(workingDir);
- if (args.Length > cArgFileThreshold)
- {
- // Only use UTF16 if we absolutely need to
- if ((argsFileKind == .UTF16WithBom) && (!args.HasMultibyteChars()))
- executionQueueCmd.mUseArgsFile = .UTF8;
- else
- executionQueueCmd.mUseArgsFile = argsFileKind;
- }
- mExecutionQueue.Add(executionQueueCmd);
- return executionQueueCmd;
- }
- void GotExecutionOutputLine(ExecutionInstance executionInstance, String str)
- {
- if (!String.IsNullOrEmpty(str))
- {
- using (mMonitor.Enter())
- {
- executionInstance.mDeferredOutput.Add(new String(str));
- }
- }
- }
- static void ReadOutputThread(Object obj)
- {
- ExecutionInstance executionInstance = (ExecutionInstance)obj;
- FileStream fileStream = scope FileStream();
- if (executionInstance.mProcess.AttachStandardOutput(fileStream) case .Err)
- return;
- StreamReader streamReader = scope StreamReader(fileStream, null, false, 4096);
- while (true)
- {
- var buffer = scope String();
- if (streamReader.ReadLine(buffer) case .Err)
- break;
- using (IDEApp.sApp.mMonitor.Enter())
- executionInstance.mDeferredOutput.Add(new String(buffer));
- }
- }
- static void ReadErrorThread(Object obj)
- {
- ExecutionInstance executionInstance = (ExecutionInstance)obj;
- FileStream fileStream = scope FileStream();
- if (executionInstance.mProcess.AttachStandardError(fileStream) case .Err)
- return;
- StreamReader streamReader = scope StreamReader(fileStream, null, false, 4096);
- while (true)
- {
- var buffer = scope String();
- if (streamReader.ReadLine(buffer) case .Err)
- break;
- using (IDEApp.sApp.mMonitor.Enter())
- executionInstance.mDeferredOutput.Add(new String(buffer));
- }
- }
- public ExecutionInstance DoRun(String inFileName, String args, String workingDir, ArgsFileKind useArgsFile, Dictionary<String, String> envVars = null)
- {
- //Debug.Assert(executionInstance == null);
- String fileName = scope String(inFileName ?? "");
- QuoteIfNeeded(fileName);
- ProcessStartInfo startInfo = scope ProcessStartInfo();
- startInfo.UseShellExecute = false;
- if (!fileName.IsEmpty)
- startInfo.SetFileName(fileName);
- startInfo.SetWorkingDirectory(workingDir);
- startInfo.SetArguments(args);
- startInfo.RedirectStandardOutput = true;
- startInfo.RedirectStandardError = true;
- startInfo.CreateNoWindow = true;
- if (envVars != null)
- {
- for (var envKV in envVars)
- startInfo.AddEnvironmentVariable(envKV.key, envKV.value);
- }
- var executionInstance = new ExecutionInstance();
- mExecutionInstances.Add(executionInstance);
- if (useArgsFile != .None)
- {
- String tempFileName = scope String();
- Path.GetTempFileName(tempFileName);
- Encoding encoding = Encoding.UTF8;
- if (useArgsFile == .UTF16WithBom)
- encoding = Encoding.UTF16WithBOM;
- var result = File.WriteAllText(tempFileName, args, encoding);
- if (result case .Err)
- OutputLine("Failed to create temporary param file");
- String arguments = scope String();
- arguments.Concat("@", tempFileName);
- startInfo.SetArguments(arguments);
-
- executionInstance.mTempFileName = new String(tempFileName);
- }
- if (mVerbosity >= .Detailed)
- {
- String showArgs = startInfo.mArguments;
- if ((mRunningTestScript) && (showArgs.Length > 1024))
- {
- showArgs = scope:: String(showArgs, 0, 1024);
- showArgs.Append("...");
- }
- if (!startInfo.mFileName.IsEmpty)
- OutputLine("Executing: {0} {1}", startInfo.mFileName, showArgs);
- else
- OutputLine("Executing: {0}", showArgs);
- }
- //if (useArgsFile)
- {
- //if (mVerbosity >= .Detailed)
- //OutputLine(" Args: {0}", args);
- }
-
- /*var processResult = Process.Start(startInfo);
- if (case .Err = processResult)
- {
- OutputLine("Failed to execute \"{0}\"", fileName);
- return executionInstance;
- }*/
- SpawnedProcess process = new SpawnedProcess();
- if (process.Start(startInfo) case .Err)
- {
- OutputLine("Failed to execute \"{0}\"", inFileName);
- delete process;
- return executionInstance;
- }
- executionInstance.mStopwatch.Start();
- executionInstance.mProcess = process;
- executionInstance.mOutputThread = new Thread(new => ReadOutputThread);
- executionInstance.mOutputThread.Start(executionInstance, false);
- executionInstance.mErrorThread = new Thread(new => ReadErrorThread);
- executionInstance.mErrorThread.Start(executionInstance, false);
- return executionInstance;
- }
- protected virtual void BeefCompileStarted()
- {
- }
- protected virtual void BeefCompileDone()
- {
- }
- protected virtual void CompileDone(bool succeeded)
- {
- }
- BuildCompletedCmd GetBuildCompletedCmd()
- {
- for (int idx = mExecutionQueue.Count - 1; idx >= 0; idx--)
- {
- if (var buildCompletedCmd = mExecutionQueue[idx] as BuildCompletedCmd)
- return buildCompletedCmd;
- }
- return null;
- }
- void UpdateExecution()
- {
- if (mExecutionInstances.Count > 0)
- {
- var executionInstance = mExecutionInstances[0];
- bool failed = false;
- bool isDone = false;
- using (mMonitor.Enter())
- {
- for (var str in executionInstance.mDeferredOutput)
- {
- OutputLine(str);
- delete str;
- }
- executionInstance.mDeferredOutput.Clear();
- }
- if (executionInstance.mProcess == null)
- {
- // Didn't even get off the ground
- isDone = true;
- failed = true;
- executionInstance.mExitCode = -1;
- }
- else if (executionInstance.mProcess.HasExited)
- {
- isDone = true;
- if (executionInstance.mOutputThread != null)
- {
- if (!executionInstance.mOutputThread.Join(0))
- isDone = false;
- }
- if (executionInstance.mErrorThread != null)
- {
- if (!executionInstance.mErrorThread.Join(0))
- isDone = false;
- }
- if (isDone)
- {
- executionInstance.mExitCode = executionInstance.mProcess.ExitCode;
- if (executionInstance.mProcess.ExitCode != 0)
- failed = true;
- executionInstance.mProcess.WaitFor(-1);
- executionInstance.mProcess.Close();
- executionInstance.mStopwatch.Stop();
- if (executionInstance.mIsTargetRun)
- {
- mTargetExitCode = executionInstance.mExitCode;
- }
- else
- {
- if (executionInstance.mParallelGroup == -1)
- {
- if (mVerbosity >= .Detailed)
- OutputLine("Execution time: {0:0.00}s", executionInstance.mStopwatch.ElapsedMilliseconds / 1000.0f);
- }
- if (executionInstance.mCanceled)
- OutputLine("Execution Canceled");
- else if (failed)
- OutputLine("Execution Failed");
- }
- if (executionInstance.mTempFileName != null)
- {
- File.Delete(executionInstance.mTempFileName).IgnoreError();
- }
- }
- }
- if (failed)
- {
- if (mExecutionQueue.Count > 0)
- {
- var buildCompletedCmd = GetBuildCompletedCmd();
- if (buildCompletedCmd != null)
- buildCompletedCmd.mFailed = true;
- }
- }
- if (isDone)
- {
- mExecutionInstances.RemoveAt(0);
- if (executionInstance.mAutoDelete)
- delete executionInstance;
- }
- /*if (failed)
- {
- OutputLine("COMPILATION FAILED");
- mExecutionQueue.Clear();
- }
- if ((executionInstance == null) && (mExecutionQueue.Count == 0))
- {
- OutputLine("Compilation finished.");
- }*/
- }
- bool buildFailed = false;
- if ((mBuildContext != null) && (mBuildContext.Failed))
- buildFailed = true;
- let buildCompleteCmd = GetBuildCompletedCmd();
- if ((buildCompleteCmd != null) && (buildCompleteCmd.mFailed))
- buildFailed = true;
- bool canExecuteNext = false;
- int32 parallelExecutionCount = 16;
- if ((mExecutionQueue.Count > 0) && (mExecutionInstances.Count < parallelExecutionCount))
- {
- var executionQueueCmd = mExecutionQueue[0] as ExecutionQueueCmd;
- if (executionQueueCmd != null)
- {
- if (mExecutionInstances.Count > 0)
- {
- var executionInstance = mExecutionInstances[0];
- if ((executionQueueCmd.mParallelGroup != -1) &&
- (executionQueueCmd.mParallelGroup == executionInstance.mParallelGroup))
- canExecuteNext = true;
- }
- else
- canExecuteNext = true;
- }
- else if (mExecutionInstances.Count == 0)
- canExecuteNext = true;
- }
- if (canExecuteNext)
- {
- var next = mExecutionQueue[0];
- bool waitForBuildClang = false;
- #if IDE_C_SUPPORT
- waitForBuildClang = (mDepClang.mCompileWaitsForQueueEmpty) && (mDepClang.HasQueuedCommands());
- #endif
- if ((next is ProcessBfCompileCmd) && (mBfBuildCompiler.HasQueuedCommands() || (waitForBuildClang)))
- return;
- /*if (next is BuildCompletedCmd)
- {
- if (mBuildContext != null)
- return;
- }*/
- if (let targetCompletedCmd = next as TargetCompletedCmd)
- {
- if ((mBuildContext == null) || (!mBuildContext.Failed))
- {
- if (!targetCompletedCmd.mIsReady)
- return;
- }
- }
- defer delete next;
- mExecutionQueue.RemoveAt(0);
- bool ignoreCommand = false;
- if (next.mOnlyIfNotFailed)
- {
- if (mExecutionQueue.Count > 0)
- {
- var buildCompletedCmd = GetBuildCompletedCmd();
- if ((buildCompletedCmd != null) && (buildCompletedCmd.mFailed))
- ignoreCommand = true;
- }
- }
- if (ignoreCommand)
- {
- // Nothing
- if (let targetCompletedCmd = next as TargetCompletedCmd)
- {
- String projectBuildDir = scope String();
- gApp.GetProjectBuildDir(targetCompletedCmd.mProject, projectBuildDir);
- gApp.mBfBuildCompiler.SetBuildValue(projectBuildDir, "Link", "FAILED");
- gApp.mBfBuildCompiler.WriteBuildCache(projectBuildDir);
- }
- }
- else if (next is ProcessBfCompileCmd)
- {
- var processCompileCmd = (ProcessBfCompileCmd)next;
- mCompilingBeef = false;
- BeefCompileDone();
- //processCompileCmd.mStopwatch.Stop();
- if ((processCompileCmd.mHadBeef) && (mVerbosity >= .Normal))
- OutputLine("Beef compilation time: {0:0.00}s", processCompileCmd.mStopwatch.ElapsedMilliseconds / 1000.0f);
- var compileInstance = mWorkspace.mCompileInstanceList.Back;
- compileInstance.mCompileResult = .Failure;
- if (processCompileCmd.mBfPassInstance.mCompileSucceeded)
- {
- //foreach (var sourceViewPanel in GetSourceViewPanels())
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- sourceViewPanel.mHasChangedSinceLastCompile = false;
- });
- compileInstance.mCompileResult = .Success;
- }
- else
- {
- compileInstance.mCompileResult = .Failure;
- }
- ProcessBeefCompileResults(processCompileCmd.mBfPassInstance, processCompileCmd.mRunAfter, processCompileCmd.mHotProject, processCompileCmd.mStopwatch);
- if (mHotResolveState != .None)
- {
- if (compileInstance.mCompileResult == .Success)
- compileInstance.mCompileResult = .PendingHotLoad;
- }
- if (processCompileCmd.mProfileCmd != null)
- {
- mExecutionQueue.Add(processCompileCmd.mProfileCmd);
- processCompileCmd.mProfileCmd = null;
- }
- delete processCompileCmd.mStopwatch;
- processCompileCmd.mStopwatch = null;
- }
- else if (next is TargetCompletedCmd)
- {
- if (!buildFailed)
- {
- var targetCompletedCmd = (TargetCompletedCmd)next;
- targetCompletedCmd.mProject.mNeedsTargetRebuild = false;
- targetCompletedCmd.mProject.mForceCustomCommands = false;
- }
- }
- else if (next is StartDebugCmd)
- {
- if (!buildFailed)
- {
- var startDebugCmd = (StartDebugCmd)next;
- if (DebugProject(startDebugCmd.mWasCompiled))
- {
- OutputLine("Debugger started");
- }
- else
- OutputLine("Failed to start debugger");
- }
- }
- else if (next is ExecutionQueueCmd)
- {
- var executionQueueCmd = (ExecutionQueueCmd)next;
- var executionInstance = DoRun(executionQueueCmd.mFileName, executionQueueCmd.mArgs, executionQueueCmd.mWorkingDir, executionQueueCmd.mUseArgsFile, executionQueueCmd.mEnvVars);
- executionInstance.mParallelGroup = executionQueueCmd.mParallelGroup;
- executionInstance.mIsTargetRun = executionQueueCmd.mIsTargetRun;
- }
- else if (next is BuildCompletedCmd)
- {
- var buildCompletedCmd = (BuildCompletedCmd)next;
- #if IDE_C_SUPPORT
- mWorkspace.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectItem != null)
- {
- String fullPath = scope String();
- projectSource.GetFullImportPath(fullPath);
- if (completedCompileCmd.mClangCompiledFiles.Contains(fullPath))
- {
- mDepClang.QueueCheckDependencies(projectSource, ClangCompiler.DepCheckerType.Clang);
- }
- }
- });
- if (!completedCompileCmd.mFailed)
- mDepClang.mDoDependencyCheck = false;
- #endif
- if (buildFailed)
- buildCompletedCmd.mFailed = true;
-
- CompileResult(buildCompletedCmd.mHotProjectName, !buildCompletedCmd.mFailed);
- if (buildCompletedCmd.mFailed)
- OutputLineSmart("ERROR: BUILD FAILED");
- if ((mVerbosity >= .Detailed) && (buildCompletedCmd.mStopwatch != null))
- OutputLine("Total build time: {0:0.00}s", buildCompletedCmd.mStopwatch.ElapsedMilliseconds / 1000.0f);
- CompileDone(!buildCompletedCmd.mFailed);
- if (mTestManager != null)
- {
- if (buildCompletedCmd.mFailed)
- mTestManager.BuildFailed();
- else
- mTestManager.Start();
- }
- }
- else if (var profileCmd = next as ProfileCmd)
- {
- if (gApp.mDebugger.mIsRunning)
- mProfilePanel.StartProfiling(profileCmd.mThreadId, profileCmd.mDesc, profileCmd.mSampleRate);
- }
- else
- {
- Runtime.FatalError("Unknown command");
- }
- }
- }
- public bool ParseSourceFile(BfSystem bfSystem, BfPassInstance passInstance, ProjectSource projectSource)
- {
- bool worked = true;
- if (!IsBeefFile(projectSource.mPath))
- return true;
- var fullPath = scope String();
- projectSource.GetFullImportPath(fullPath);
- String data = scope String();
- LoadTextFile(fullPath, data);
- if (data == null)
- {
- OutputErrorLine("FAILED TO LOAD FILE: {0}", fullPath);
- return true;
- }
- mFileWatcher.FileIsValid(fullPath);
- var bfParser = bfSystem.CreateParser(projectSource);
- bfParser.SetSource(data, fullPath);
- worked &= bfParser.Parse(passInstance, false);
- worked &= bfParser.Reduce(passInstance);
- worked &= bfParser.BuildDefs(passInstance, null, false);
- return worked;
- }
- public bool FindProjectSourceContent(ProjectSource projectSource, out IdSpan char8IdData, bool loadOnFail, String sourceContent)
- {
- char8IdData = IdSpan();
- var fullPath = scope String();
- projectSource.GetFullImportPath(fullPath);
- //SourceViewPanel sourceViewPanel = null;
-
- using (mMonitor.Enter())
- {
- if (projectSource.mEditData != null)
- {
- if (projectSource.mEditData.IsFileDeleted())
- {
- return false;
- }
- if (projectSource.mEditData.mEditWidget != null)
- {
- var idData = ref projectSource.mEditData.mEditWidget.Content.mData.mTextIdData;
- idData.Prepare();
- if (!projectSource.mEditData.mSavedCharIdData.Equals(idData))
- {
- char8IdData = projectSource.mEditData.mEditWidget.mEditWidgetContent.mData.mTextIdData.Duplicate();
- projectSource.mEditData.mEditWidget.GetText(sourceContent);
- return true;
- }
- }
- if (projectSource.mEditData.mSavedContent != null)
- {
- char8IdData = projectSource.mEditData.mSavedCharIdData.Duplicate();
- sourceContent.Set(projectSource.mEditData.mSavedContent);
- return true;
- }
- }
- }
- if (loadOnFail)
- {
- String text = scope String();
- bool isValid = false;
- if (LoadTextFile(fullPath, text) case .Ok)
- {
- mFileWatcher.FileIsValid(fullPath);
- isValid = true;
- }
-
- char8IdData = IdSpan.GetDefault((int32)text.Length);
- var editData = GetEditData(projectSource, false);
- using (mMonitor.Enter())
- {
- if (isValid)
- {
- editData.SetSavedData(text, char8IdData);
- sourceContent.Set(text);
- }
- else
- {
- editData.SetSavedData(null, IdSpan());
- editData.mFileDeleted = true;
- }
- }
- return isValid;
- }
- return false;
- }
- public void SetInDisassemblyView(bool inDisassemblyView)
- {
- if (mShuttingDown)
- return;
- if (mInDisassemblyView != inDisassemblyView)
- {
- // We need to refresh auto watch panel so we can handle displaying registers when switching to disasm
- mAutoWatchPanel.MarkWatchesDirty(false);
- mInDisassemblyView = inDisassemblyView;
- }
- }
- public bool ParseSourceFiles(BfSystem bfSystem, BfPassInstance passInstance, ProjectFolder projectFolder)
- {
- bool worked = true;
- for (var item in projectFolder.mChildItems)
- {
- if (item is ProjectSource)
- {
- var projectSource = (ProjectSource)item;
- worked &= ParseSourceFile(bfSystem, passInstance, projectSource);
- }
- if (item is ProjectFolder)
- {
- var innerProjectFolder = (ProjectFolder)item;
- worked &= ParseSourceFiles(bfSystem, passInstance, innerProjectFolder);
- }
- }
- return worked;
- }
- public bool HasPendingBeefFiles(bool forceQueue, ProjectFolder projectFolder)
- {
- bool hadBeef = false;
-
- for (var item in projectFolder.mChildItems)
- {
- if (item.mIncludeKind == .Ignore)
- continue;
- if (item is ProjectSource)
- {
- var projectSource = (ProjectSource)item;
- if (IsBeefFile(projectSource.mPath))
- {
- if ((projectSource.HasChangedSinceLastCompile) || (forceQueue))
- {
- hadBeef = true;
- }
- }
- }
- if (item is ProjectFolder)
- {
- var innerProjectFolder = (ProjectFolder)item;
- hadBeef |= HasPendingBeefFiles(forceQueue, innerProjectFolder);
- }
- }
- return hadBeef;
- }
- public bool QueueParseBeefFiles(BfCompiler bfCompiler, bool forceQueue, ProjectFolder projectFolder)
- {
- bool hadBeef = false;
-
- for (var item in projectFolder.mChildItems)
- {
- if (item.mIncludeKind == .Ignore)
- continue;
- if (item is ProjectSource)
- {
- var projectSource = (ProjectSource)item;
- if (IsBeefFile(projectSource.mPath))
- {
- // if it's the resolve compiler then we take this as an indication that we need to recompile this file
- // later on when a build is requested, most likely because the project or workspace configuration has
- // changed (such as preprocessor or other setting changes)
- if ((bfCompiler == null) || (bfCompiler.mIsResolveOnly))
- {
- projectSource.HasChangedSinceLastCompile = true;
- }
- else // Actual build
- {
- if ((projectSource.HasChangedSinceLastCompile) || (forceQueue))
- {
- // mHasChangedSinceLastCompile is safe to set 'false' here since it just determines whether or not
- // we rebuild the TypeDefs from the sources. It isn't affected by any compilation errors.
- projectSource.mHasChangedSinceLastCompile = false;
- bfCompiler.QueueProjectSource(projectSource);
- hadBeef = true;
- }
- }
- }
- }
- if (item is ProjectFolder)
- {
- var innerProjectFolder = (ProjectFolder)item;
- hadBeef |= QueueParseBeefFiles(bfCompiler, forceQueue, innerProjectFolder);
- }
- }
- return hadBeef;
- }
- #if IDE_C_SUPPORT
- public void QueueParseClangFiles(ClangCompiler clangCompiler, ProjectFolder projectFolder)
- {
- for (var item in projectFolder.mChildItems)
- {
- if (item is ProjectSource)
- {
- var projectSource = (ProjectSource)item;
- if (IsClangSourceFile(projectSource.mPath))
- clangCompiler.QueueProjectSource(projectSource);
- }
- if (item is ProjectFolder)
- {
- var innerProjectFolder = (ProjectFolder)item;
- QueueParseClangFiles(clangCompiler, innerProjectFolder);
- }
- }
- }
- #endif
- public Workspace.Options GetCurWorkspaceOptions()
- {
- return mWorkspace.GetOptions(mConfigName, mPlatformName);
- }
- public Workspace.ConfigSelection GetCurConfigSelection(Project project)
- {
- var workspaceOptions = mWorkspace.GetOptions(mConfigName, mPlatformName);
- if (workspaceOptions == null)
- return null;
- Workspace.ConfigSelection configSelection;
- workspaceOptions.mConfigSelections.TryGetValue(project, out configSelection);
- if ((configSelection == null) || (!configSelection.mEnabled))
- return null;
- return configSelection;
- }
- public Project.Options GetCurProjectOptions(Project project)
- {
- if (project.mFailed)
- return null;
-
- Workspace.ConfigSelection configSelection = GetCurConfigSelection(project);
- if (configSelection == null)
- return null;
- return project.GetOptions(configSelection.mConfig, configSelection.mPlatform);
- }
- public bool IsProjectEnabled(Project project)
- {
- return GetCurProjectOptions(project) != null;
- }
- public bool IsProjectSourceEnabled(ProjectSource projectSource)
- {
- if (projectSource.mIncludeKind == .Ignore)
- return false;
- if (!IsProjectEnabled(projectSource.mProject))
- return false;
- return true;
- }
- public void PreConfigureBeefSystem(BfSystem bfSystem, BfCompiler bfCompiler)
- {
- if (!bfCompiler.mIsResolveOnly)
- {
- bfCompiler.WaitForBackground();
- bfSystem.ClearTypeOptions();
- }
- }
- // Project options are inherently thread safe. Resolve-system project settings
- // Can only be changed from the Resolve BfCompiler thread, and Build settings
- // are only changed before background compilation begins. We also call this
- // during WorkspaceLoad, but the resolve threads aren't processing then.
- public bool SetupBeefProjectSettings(BfSystem bfSystem, BfCompiler bfCompiler, Project project)
- {
- bool success = true;
- var bfProject = bfSystem.GetBfProject(project);
- Project.Options options = GetCurProjectOptions(project);
- Workspace.Options workspaceOptions = GetCurWorkspaceOptions();
- if (options == null)
- {
- //Fail(StackStringFormat!("Failed to retrieve options for {0}", project.mProjectName));
- bfProject.SetDisabled(true);
- return false;
- }
- bfProject.SetDisabled(false);
- var preprocessorMacros = scope DefinesSet();
- void AddMacros(List<String> macros)
- {
- for (var macro in macros)
- {
- preprocessorMacros.Add(macro);
- }
- }
- AddMacros(project.mBeefGlobalOptions.mPreprocessorMacros);
- AddMacros(options.mBeefOptions.mPreprocessorMacros);
- AddMacros(mWorkspace.mBeefGlobalOptions.mPreprocessorMacros);
- AddMacros(workspaceOptions.mPreprocessorMacros);
- GetBeefPreprocessorMacros(preprocessorMacros);
-
- var optimizationLevel = workspaceOptions.mBfOptimizationLevel;
- if (options.mBeefOptions.mOptimizationLevel != null)
- optimizationLevel = options.mBeefOptions.mOptimizationLevel.Value;
- if ((optimizationLevel == .OgPlus) && (mPlatformName != "Win64") && (bfCompiler == mBfBuildCompiler))
- {
- OutputLineSmart("WARNING: Project '{0}' has Og+ specified, which is only supported for Win64 targets.", project.mProjectName);
- optimizationLevel = .O0;
- }
- var ltoType = workspaceOptions.mLTOType;
- if (options.mBeefOptions.mLTOType != null)
- ltoType = options.mBeefOptions.mLTOType.Value;
-
- var targetType = project.mGeneralOptions.mTargetType;
- if (bfSystem != mBfResolveSystem)
- {
- if (options.mBuildOptions.mBuildKind == .Test)
- {
- if (workspaceOptions.mBuildKind == .Test)
- {
- targetType = .BeefTest;
- if (mTestManager != null)
- mTestManager.AddProject(project);
- }
- else
- {
- OutputLineSmart("ERROR: Project '{0}' has a Test configuration specified but the workspace is not using a Test configuration", project.mProjectName);
- success = false;
- }
- }
- }
- bfProject.SetOptions(targetType,
- project.mBeefGlobalOptions.mStartupObject,
- preprocessorMacros.mDefines,
- optimizationLevel, ltoType, options.mBeefOptions.mMergeFunctions, options.mBeefOptions.mCombineLoads,
- options.mBeefOptions.mVectorizeLoops, options.mBeefOptions.mVectorizeSLP);
- List<Project> depProjectList = scope List<Project>();
- if (!GetDependentProjectList(project, depProjectList))
- success = false;
- bfProject.ClearDependencies();
- for (var depProject in depProjectList)
- {
- if (bfSystem.mProjectMap.TryGetValue(depProject, var depBfProject))
- bfProject.AddDependency(depBfProject);
- }
- if (!bfCompiler.mIsResolveOnly)
- {
- for (let typeOption in project.mBeefGlobalOptions.mDistinctBuildOptions)
- bfSystem.AddTypeOptions(typeOption);
- for (let typeOption in options.mBeefOptions.mDistinctBuildOptions)
- bfSystem.AddTypeOptions(typeOption);
- }
- return success;
- }
- public void CurrentWorkspaceConfigChanged()
- {
- #if IDE_C_SUPPORT
- for (var val in mDepClang.mProjectBuildString.Values)
- delete val;
- mDepClang.mProjectBuildString.Clear();
- #endif
- if (mBfResolveCompiler != null)
- {
- mBfResolveCompiler.QueueSetWorkspaceOptions(null, 0);
- mBfResolveCompiler.QueueDeferredResolveAll();
- }
- mWorkspace.FixOptions(mConfigName, mPlatformName);
- for (var project in mWorkspace.mProjects)
- {
- ProjectOptionsChanged(project);
- #if IDE_C_SUPPORT
- QueueParseClangFiles(mDepClang, project.mRootFolder);
- #endif
- }
- mWorkspace.ClearProjectNameCache();
- mProjectPanel.RehupProjects();
- }
- /*public string GetClangDepConfigName(Project project)
- {
- string[] clangArgs = GetClangResolveArgs(project);
- string clangArgsStr = String.Join("\n", clangArgs);
- long hash = 0;
- for (int i = 0; i < clangArgsStr.Length; i++)
- hash = (hash << 5) - hash + clangArgsStr[i];
- return String.Format("{0:X16}", hash);
- }*/
- public void ProjectOptionsChanged(Project project, bool reparseFiles = true)
- {
- bool isEnabled = IsProjectEnabled(project);
- mWorkspace.ClearProjectNameCache();
- if (mBfResolveCompiler != null)
- {
- mBfResolveCompiler.QueueSetupProjectSettings(project);
- }
- if (isEnabled != project.mEnabled)
- {
- project.mEnabled = isEnabled;
- if (isEnabled)
- {
- QueueProjectItems(project);
- }
- else
- {
- RemoveProjectItems(project);
- }
- mBfResolveCompiler.QueueDeferredResolveAll();
- mBfResolveCompiler.QueueRefreshViewCommand();
- return;
- }
- #if IDE_C_SUPPORT
- mDepClang.mDoDependencyCheck = true;
- #endif
- if (mBfResolveCompiler != null)
- {
- if (reparseFiles)
- QueueParseBeefFiles(mBfResolveCompiler, false, project.mRootFolder);
- mBfResolveCompiler.QueueDeferredResolveAll();
- mBfResolveCompiler.QueueRefreshViewCommand();
- }
- else
- {
- if (reparseFiles)
- QueueParseBeefFiles(mBfResolveCompiler, false, project.mRootFolder);
- }
- }
- public void RenameProject(Project project, String newName)
- {
- mWantsBeefClean = true;
- for (var checkProject in mWorkspace.mProjects)
- {
- for (var dep in checkProject.mDependencies)
- {
- if (dep.mProjectName == project.mProjectName)
- {
- dep.mProjectName.Set(newName);
- checkProject.SetChanged();
- }
- }
- }
- for (var dep in mWorkspace.mProjectSpecs)
- {
- if (dep.mProjectName == project.mProjectName)
- {
- dep.mProjectName.Set(newName);
- mWorkspace.SetChanged();
- }
- }
- project.mProjectName.Set(newName);
- project.SetChanged();
- mWorkspace.ClearProjectNameCache();
- }
- public void RemoveProject(Project project)
- {
- RemoveProjectItems(project);
- mWorkspace.SetChanged();
- mWorkspace.mProjects.Remove(project);
- #if IDE_C_SUPPORT
- using (mDepClang.mMonitor.Enter())
- {
- mDepClang.mProjectBuildString.Remove(project);
- }
- #endif
- if (mWorkspace.mStartupProject == project)
- mWorkspace.mStartupProject = null;
- mWorkspace.FixOptions();
- CurrentWorkspaceConfigChanged();
- var bfCompilers = scope List<BfCompiler>();
- GetBfCompilers(bfCompilers);
- for (var bfCompiler in bfCompilers)
- {
- var bfProject = bfCompiler.mBfSystem.GetBfProject(project);
- bfProject.SetDisabled(true);
- bfCompiler.mBfSystem.RemoveBfProject(project);
- bfCompiler.QueueDeleteBfProject(bfProject);
- }
- for (var checkProject in mWorkspace.mProjects)
- {
- for (var dep in checkProject.mDependencies)
- {
- if (dep.mProjectName == project.mProjectName)
- {
- @dep.Remove();
- delete dep;
- }
- }
- }
- for (var dep in mWorkspace.mProjectSpecs)
- {
- if (dep.mProjectName == project.mProjectName)
- {
- @dep.Remove();
- delete dep;
- }
- }
- List<WidgetWindow> closeList = scope .();
- for (var window in gApp.mWindows)
- {
- if (var widgetWindow = window as WidgetWindow)
- {
- if (var projectProperties = widgetWindow.mRootWidget as ProjectProperties)
- {
- if (projectProperties.[Friend]mProject == project)
- closeList.Add(widgetWindow);
- }
- }
- }
- for (var window in closeList)
- window.Close(true);
- delete project;
- }
- BfPassInstance CompileBeef(Project hotProject, int32 hotIdx, bool lastCompileHadMessages, out bool hadBeef)
- {
- hadBeef = false;
- mCompilingBeef = true;
- BeefCompileStarted();
- bool success = true;
- BfSystem bfSystem = mBfBuildSystem;
- BfCompiler bfCompiler = mBfBuildCompiler;
- BfPassInstance passInstance = bfSystem.CreatePassInstance();
- bfCompiler.QueueSetPassInstance(passInstance);
- bfCompiler.QueueSetWorkspaceOptions(hotProject, hotIdx);
-
- Workspace.Options workspaceOptions = GetCurWorkspaceOptions();
- bool tryQueueFiles = true;
- bool doCompile = false;
- if (lastCompileHadMessages)
- doCompile = true;
- if ((!workspaceOptions.mIncrementalBuild) && (!lastCompileHadMessages))
- {
- tryQueueFiles = false;
- for (var project in mWorkspace.mProjects)
- {
- if (HasPendingBeefFiles(false, project.mRootFolder))
- tryQueueFiles = true;
- }
- }
- if (hotProject != null)
- {
- mWorkspace.mHadHotCompileSinceLastFullCompile = true;
- }
- else
- {
- if (mWorkspace.mHadHotCompileSinceLastFullCompile)
- {
- doCompile = true;
- mWorkspace.mHadHotCompileSinceLastFullCompile = false;
- }
- }
- if (mWorkspace.mForceNextCompile)
- {
- doCompile = true;
- mWorkspace.mForceNextCompile = false;
- }
- if (tryQueueFiles)
- {
- PreConfigureBeefSystem(bfSystem, bfCompiler);
- for (var project in mWorkspace.mProjects)
- {
- if (SetupBeefProjectSettings(bfSystem, bfCompiler, project))
- {
- doCompile |= QueueParseBeefFiles(bfCompiler, !workspaceOptions.mIncrementalBuild, project.mRootFolder);
- }
- else if (IsProjectEnabled(project))
- success = false;
- }
- }
- if (!success)
- return null;
- for (var project in mWorkspace.mProjects)
- {
- if (!project.mGeneralOptions.mTargetType.IsBeef)
- continue;
- hadBeef = true;
- String projectBuildDir = scope String();
- GetWorkspaceBuildDir(projectBuildDir);
- projectBuildDir.Append("/", project.mProjectName);
- Directory.CreateDirectory(projectBuildDir).IgnoreError();
- }
- if (!hadBeef)
- doCompile = false;
- if (doCompile)
- {
- for (var project in mWorkspace.mProjects)
- {
- // Regenerate these
- DeleteContainerAndItems!(project.mCurBfOutputFileNames);
- project.mCurBfOutputFileNames = null;
- }
- var dir = scope String();
- GetWorkspaceBuildDir(dir);
- bfCompiler.QueueCompile(dir);
- }
- else
- {
- bfCompiler.ClearResults();
- passInstance.mCompileSucceeded = true;
- }
- return passInstance;
- }
- public bool DoResolveConfigString(String platformName, Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String error, String result)
- {
- int i = result.Length;
- result.Append(configString);
- bool hadError = false;
- for ( ; i < result.Length - 2; i++)
- {
- if ((result[i] == '$') && (result[i + 1] == '('))
- {
- int parenPos = -1;
- int openCount = 1;
- bool inString = false;
- char8 prevC = 0;
- for (int checkIdx = i + 2; checkIdx < result.Length; checkIdx++)
- {
- char8 c = result[checkIdx];
- if (inString)
- {
- if (prevC == '\\')
- {
- // Slashed char
- prevC = 0;
- continue;
- }
- if (c == '"')
- inString = false;
- }
- else
- {
- if (c == '"')
- inString = true;
- else if (c == '(')
- openCount++;
- else if (c == ')')
- {
- openCount--;
- if (openCount == 0)
- {
- parenPos = checkIdx;
- break;
- }
- }
- }
- prevC = c;
- }
- if (parenPos != -1)
- ReplaceBlock:
- do
- {
- String replaceStr = scope String(result, i + 2, parenPos - i - 2);
- String newString = null;
- if (replaceStr.Contains(' '))
- {
- String cmd = scope .();
- List<String> args = scope .();
- for (let str in replaceStr.Split(' ', .RemoveEmptyEntries))
- {
- if (cmd.IsEmpty)
- cmd.Set(str);
- else
- {
- String arg = scope:ReplaceBlock .();
- if (str.StartsWith("\""))
- {
- String unresolvedStr = scope .();
- str.UnQuoteString(unresolvedStr);
- if (!DoResolveConfigString(platformName, workspaceOptions, project, options, unresolvedStr, error, arg))
- return false;
- }
- else
- arg.Append(str);
- args.Add(arg);
- }
- }
- String cmdErr = null;
- switch (cmd)
- {
- case "Slash":
- if (args.Count == 1)
- {
- newString = scope:ReplaceBlock .();
- args[0].QuoteString(newString);
- }
- else
- cmdErr = "Invalid number of arguments";
- }
- if (newString == null)
- {
- if (error != null)
- {
- if (cmdErr != null)
- error.Set(cmdErr);
- else
- error.Set(replaceStr);
- }
- hadError = true;
- break ReplaceBlock;
- }
- }
- if ((newString == null) && (project != null))
- {
- switch (replaceStr)
- {
- case "ProjectName":
- newString = project.mProjectName;
- break;
- }
- }
- if ((newString == null) && (options != null))
- {
- switch (replaceStr)
- {
- case "Arguments":
- newString = options.mDebugOptions.mCommandArguments;
- case "WorkingDir":
- newString = options.mDebugOptions.mWorkingDirectory;
- case "TargetDir":
- {
- if (project.IsDebugSession)
- {
- let targetPath = scope:ReplaceBlock String();
- DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, targetPath);
- newString = scope:ReplaceBlock String();
- Path.GetDirectoryPath(targetPath, newString);
- break;
- }
- String targetDir = scope String();
- DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir);
- newString = scope:ReplaceBlock String();
- Path.GetAbsolutePath(targetDir, project.mProjectDir, newString);
- }
- case "TargetPath":
- {
- if (project.IsDebugSession)
- {
- newString = scope:ReplaceBlock String();
- DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString);
- break;
- }
- String targetDir = scope String();
- DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir);
- newString = scope:ReplaceBlock String();
- Path.GetAbsolutePath(targetDir, project.mProjectDir, newString);
- Utils.GetDirWithSlash(newString);
-
- if (!DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString))
- return false;
- #if BF_PLATFORM_WINDOWS
- if (project.mGeneralOptions.mTargetType == .BeefLib)
- newString.Append(".lib");
- else if (project.mGeneralOptions.mTargetType == .BeefDynLib)
- newString.Append(".dll");
- else if (project.mGeneralOptions.mTargetType != .CustomBuild)
- newString.Append(".exe");
- #else
- if (project.mGeneralOptions.mTargetType == Project.TargetType.BeefLib)
- newString.Append(".so");
- #endif
- }
- case "ProjectDir":
- if (project.IsDebugSession)
- {
- newString = scope:ReplaceBlock String();
- Path.GetDirectoryPath(project.mProjectPath, newString);
- }
- else
- newString = project.mProjectDir;
- case "BuildDir":
- newString = scope:ReplaceBlock String();
- GetProjectBuildDir(project, newString);
- //Debug.WriteLine("BuildDir: {0}", newString);
- case "LinkFlags":
- newString = scope:ReplaceBlock String();
- if ((project.mGeneralOptions.mTargetType == .BeefConsoleApplication) ||
- (project.mGeneralOptions.mTargetType == .BeefWindowsApplication) ||
- (project.mGeneralOptions.mTargetType == .BeefDynLib) ||
- ((options.mBuildOptions.mBuildKind == .Test) && (project == mWorkspace.mStartupProject)))
- {
- #if BF_PLATFORM_WINDOWS
- String rtName = scope String();
- String dbgName = scope String();
- BuildContext.GetRtLibNames(workspaceOptions, options, false, rtName, dbgName);
- newString.Append(rtName);
- if (!dbgName.IsEmpty)
- newString.Append(" ", dbgName);
- switch (workspaceOptions.mAllocType)
- {
- case .JEMalloc:
- newString.Append(" jemalloc.lib");
- case .TCMalloc:
- newString.Append(" tcmalloc.lib");
- default:
- }
- #else
- newString.Append("./libBeefRT_d.so -Wl,-rpath -Wl,.");
- #endif
- }
- case "VSToolPath":
- if (Workspace.PlatformType.GetPtrSizeByName(platformName) == 4)
- newString = gApp.mSettings.mVSSettings.mBin32Path;
- else
- newString = gApp.mSettings.mVSSettings.mBin64Path;
- case "VSToolPath_x86":
- newString = gApp.mSettings.mVSSettings.mBin32Path;
- case "VSToolPath_x64":
- newString = gApp.mSettings.mVSSettings.mBin64Path;
- }
- }
- if ((newString == null) && (mScriptManager != null))
- {
- switch (replaceStr)
- {
- case "ScriptDir":
- if ((mScriptManager != null) && (mScriptManager.mCurCmd != null))
- {
- newString = scope:ReplaceBlock String();
- Path.GetDirectoryPath(mScriptManager.mCurCmd.mSrcFile, newString);
- }
- }
- }
- if (newString == null)
- {
- switch (replaceStr)
- {
- case "Configuration":
- newString = mConfigName;
- case "Platform":
- newString = mPlatformName;
- case "WorkspaceDir":
- if (mWorkspace.mDir != null)
- newString = mWorkspace.mDir;
- else if (project.IsDebugSession)
- {
- newString = scope:ReplaceBlock String();
- Path.GetDirectoryPath(project.mProjectPath, newString);
- }
- case "BeefPath":
- newString = gApp.mInstallDir;
- default:
- }
- }
- if (newString == null)
- {
- if (error != null)
- error.Set(replaceStr);
- hadError = true;
- break;
- }
- if (newString != null)
- {
- result.Remove(i, parenPos - i + 1);
- result.Insert(i, newString);
- i--;
- }
- }
- }
- }
- return !hadError;
- }
- public bool ResolveConfigString(String platformName, Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String errorContext, String outResult)
- {
- String errorString = scope String();
- if (!DoResolveConfigString(platformName, workspaceOptions, project, options, configString, errorString, outResult))
- {
- OutputErrorLine("Invalid macro in {0}: {1}", errorContext, errorString);
- return false;
- }
- return true;
- }
- public void GetWorkspaceBuildDir(String outResult)
- {
- if (mWorkspace.mDir == null)
- return;
- outResult.Append(mWorkspace.mDir, "/build/", mConfigName, "_", mPlatformName);
- }
- public void GetProjectBuildDir(Project project, String outResult)
- {
- GetWorkspaceBuildDir(outResult);
- if (!outResult.IsEmpty)
- outResult.Append("/", project.mProjectName);
- }
- public void GetClangOutputFilePathWithoutExtension(ProjectSource projectSource, String outResult)
- {
- GetProjectBuildDir(projectSource.mProject, outResult);
- outResult.Append("/");
- String fullPath = scope String();
- projectSource.GetFullImportPath(fullPath);
- Path.GetFileNameWithoutExtension(fullPath, outResult);
- }
- public void GetClangBuildString(Project project, Project.Options options, Workspace.Options workspaceOptions, bool isC, String clangOptions)
- {
- bool isClang = options.mCOptions.mCompilerType == Project.CCompilerType.Clang;
- if (options.mCOptions.mEmitDebugInfo)
- {
- if (isClang)
- {
- clangOptions.Append("-g -fstandalone-debug ");
- if (workspaceOptions.mToolsetType != .GNU)
- clangOptions.Append("-gcodeview ");
- }
- else
- clangOptions.Append("-g ");
- }
- //TODO:
- var simd = workspaceOptions.mCSIMDSetting;
- if (options.mCOptions.mSIMD != null)
- simd = options.mCOptions.mSIMD.Value;
- switch (simd)
- {
- case .SSE:
- clangOptions.Append("-msse ");
- break;
- case .SSE2:
- clangOptions.Append("-msse2 ");
- break;
- case .SSE3:
- clangOptions.Append("-msse3 ");
- break;
- case .SSE4:
- clangOptions.Append("-msse4 ");
- break;
- case .SSE41:
- clangOptions.Append("-msse4.1 ");
- break;
- case .AVX:
- clangOptions.Append("-mavx ");
- break;
- case .AVX2:
- clangOptions.Append("-mavx2 ");
- break;
- default:
- }
- if (options.mCOptions.mEnableBeefInterop)
- {
- var beefPreprocMacros = scope DefinesSet();
- GetBeefPreprocessorMacros(beefPreprocMacros);
- for (var beefPreprocMacro in beefPreprocMacros.mDefines)
- clangOptions.Append("-D", beefPreprocMacro, " ");
- }
- if (options.mCOptions.mAllWarnings)
- clangOptions.Append("-Wall ");
- var optimizationLevel = options.mCOptions.mOptimizationLevel;
- if (optimizationLevel == Project.COptimizationLevel.FromWorkspace)
- optimizationLevel = (Project.COptimizationLevel)workspaceOptions.mCOptimizationLevel;
- clangOptions.AppendF("-{0} ", optimizationLevel);
- for (var preprocMacro in options.mCOptions.mPreprocessorMacros)
- {
- clangOptions.Append("-D", preprocMacro, " ");
- }
- for (var includePath in options.mCOptions.mIncludePaths)
- {
- var fullIncludePath = scope String();
- project.GetProjectFullPath(includePath, fullIncludePath);
- if (fullIncludePath.Contains(' '))
- clangOptions.Append("\"-I", fullIncludePath, "\" ");
- else
- clangOptions.Append("-I", fullIncludePath, " ");
- }
- if (options.mCOptions.mCompilerType == Project.CCompilerType.GCC)
- {
- if (Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4)
- clangOptions.Append("-m32 ");
- else
- clangOptions.Append("-m64 ");
- }
- else
- {
- clangOptions.Append("--target=");
- Workspace.PlatformType.GetTargetTripleByName(gApp.mPlatformName, workspaceOptions.mToolsetType, clangOptions);
- clangOptions.Append(" ");
- if (workspaceOptions.mToolsetType == .GNU)
- {
- //
- }
- else
- {
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include\" ");
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\atlmfc\\include\" ");
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.14393.0\\ucrt\" ");
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.14393.0\\um\" ");
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.14393.0\\shared\" ");
- clangOptions.Append("-I\"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.14393.0\\winrt\" ");
- }
- }
- if (options.mCOptions.mNoOmitFramePointers)
- clangOptions.Append("-fno-omit-frame-pointer ");
- if (options.mCOptions.mGenerateLLVMAsm)
- clangOptions.Append("-emit-llvm -S ");
- else
- clangOptions.Append("-c ");
- if (!isC)
- {
- if (!String.IsNullOrEmpty(options.mCOptions.mOtherCPPFlags))
- clangOptions.Append(options.mCOptions.mOtherCPPFlags, " ") ;
- clangOptions.Append("-std=c++14 ");
- }
- else
- {
- if (!String.IsNullOrEmpty(options.mCOptions.mOtherCFlags))
- clangOptions.Append(options.mCOptions.mOtherCFlags, " ");
- }
- }
- static void QuoteIfNeeded(String str)
- {
- if (!str.Contains(' '))
- return;
- for (int32 i = 0; i < str.Length; i++)
- {
- char8 c = str[i];
- if ((c == '\\') || (c == '"'))
- {
- str.Insert(i, '\\');
- i++;
- }
- }
- str.Insert(0, '"');
- str.Append('"');
- }
- ExecutionQueueCmd CompileSource(Project project, Workspace.Options workspaceOptions, Project.Options options, String buildFileName, String addOptions = null)
- {
- String workspaceBuildDir = scope String();
- GetWorkspaceBuildDir(workspaceBuildDir);
- String projectBuildDir = scope String(workspaceBuildDir, "/", project.mProjectName);
- String baseName = scope String();
- Path.GetFileNameWithoutExtension(buildFileName, baseName);
- String objName = scope String(projectBuildDir, "/", baseName, (options.mCOptions.mGenerateLLVMAsm ? ".ll" : ".obj"));
- String llvmDir = scope String(IDEApp.sApp.mInstallDir);
- IDEUtils.FixFilePath(llvmDir);
- llvmDir.Append("llvm/");
- String gccExePath = "c:/mingw/bin/g++.exe";
- String clangCppExePath = scope String(llvmDir, "bin/clang++.exe");
- String clangCExePath = scope String(llvmDir, "bin/clang.exe");
- String clangOptions = scope String(buildFileName);
- QuoteIfNeeded(clangOptions);
- clangOptions.Append(" ");
- bool isC = false;
- var ext = scope String();
- Path.GetExtension(buildFileName, ext);
- if (ext == ".c")
- isC = true;
-
- var buildStr = scope String();
- GetClangBuildString(project, options, workspaceOptions, isC, buildStr);
- clangOptions.Append(buildStr);
- int lastDot = objName.LastIndexOf('.');
- String depFileName = scope String(objName, 0, lastDot);
- QuoteIfNeeded(depFileName);
- depFileName.Append(".dep");
- clangOptions.Append("-MD -MF ", depFileName, " ");
- if (addOptions != null)
- clangOptions.Append(addOptions, " ");
- clangOptions.Append("-o ");
- String quotedObjName = scope String(objName);
- QuoteIfNeeded(quotedObjName);
- clangOptions.Append(quotedObjName);
-
- String compilerExePath = (options.mCOptions.mCompilerType == Project.CCompilerType.GCC) ? gccExePath : isC ? clangCExePath : clangCppExePath;
- return QueueRun(compilerExePath, clangOptions, IDEApp.sApp.mInstallDir, .UTF8);
- }
-
- void SkipProjectCompile(Project project, Project hotProject)
- {
- Project.Options options = GetCurProjectOptions(project);
- if (options == null)
- return;
-
- BfCompiler bfCompiler = mBfBuildCompiler;
- var bfProject = mBfBuildSystem.mProjectMap[project];
- bool bfHadOutputChanges;
- List<String> bfFileNames = scope List<String>();
- bfCompiler.GetOutputFileNames(bfProject, false, out bfHadOutputChanges, bfFileNames);
- defer(scope) ClearAndDeleteItems(bfFileNames);
- if (bfHadOutputChanges)
- project.mNeedsTargetRebuild = true;
- }
- void GetTargetPaths(Project project, String platformName, Workspace.Options workspaceOptions, Project.Options options, List<String> outPaths)
- {
- String targetPath = scope String();
- ResolveConfigString(platformName, workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath);
- outPaths.Add(new String(targetPath));
- #if BF_PLATFORM_WINDOWS
- if ((project.mGeneralOptions.mTargetType == .BeefConsoleApplication) ||
- (project.mGeneralOptions.mTargetType == .BeefWindowsApplication))
- {
- if (workspaceOptions.mToolsetType != .GNU)
- {
- String pdbPath = scope String();
- BuildContext.GetPdbPath(targetPath, workspaceOptions, options, pdbPath);
- outPaths.Add(new String(pdbPath));
- }
- }
- #endif
- }
- public class ArgBuilder
- {
- String mTarget;
- bool mDoLongBreak;
- int mLastBreak;
- HashSet<String> mLinkPaths = new HashSet<String>() ~ DeleteContainerAndItems!(_);
- public this(String target, bool doLongBreak)
- {
- mTarget = target;
- mDoLongBreak = doLongBreak;
- if (mDoLongBreak)
- mLastBreak = mTarget.LastIndexOf('\n');
- else
- mLastBreak = 0;
- }
- public void AddSep()
- {
- if (mDoLongBreak)
- {
- if (mTarget.Length - mLastBreak > 0x1F000)
- {
- mLastBreak = mTarget.Length;
- mTarget.Append('\n');
- return;
- }
- }
- mTarget.Append(' ');
- }
-
- public void AddFileName(String filePath)
- {
- IDEUtils.AppendWithOptionalQuotes(mTarget, filePath);
- /*int lastSlash = Math.Max(filePath.LastIndexOf('\\'), filePath.LastIndexOf('/'));
- if (lastSlash == -1)
- {
- IDEUtils.AppendWithOptionalQuotes(mTarget, filePath);
- return;
- }
- String fileDir = scope String(filePath, 0, lastSlash);
- String fileName = scope String(filePath, lastSlash + 1);
- String* strPtr = null;
- if (mLinkPaths.TryAdd(fileDir, out strPtr))
- {
- *strPtr = new String(fileDir);
- mTarget.Append("-libpath:");
- IDEUtils.AppendWithOptionalQuotes(mTarget, fileDir);
- AddSep();
- }
- IDEUtils.AppendWithOptionalQuotes(mTarget, fileName);*/
- }
- }
- Project FindProject(String projectName)
- {
- return mWorkspace.FindProject(projectName);
- }
- public bool GetDependentProjectList(Project project, List<Project> orderedProjectList, List<Project> projectStack = null)
- {
- var useProjectStack = projectStack;
- if ((useProjectStack != null) && (useProjectStack.Contains(project)))
- {
- String projectError = scope String("Circular dependency between projects: ");
- for (int32 i = 0; i < useProjectStack.Count; i++)
- {
- if (i > 0)
- projectError.Append(", ");
- projectError.Append(useProjectStack[i].mProjectName);
- }
- OutputLine(projectError);
- return true;
- }
- if (orderedProjectList.Contains(project))
- return true;
- bool addSelf = true;
- if (useProjectStack == null)
- {
- useProjectStack = scope:: List<Project>();
- addSelf = false;
- }
- useProjectStack.Add(project);
- for (var dep in project.mDependencies)
- {
- Project depProject = FindProject(dep.mProjectName);
- if (depProject == null)
- {
- OutputLine(StackStringFormat!("Unable to find project '{0}', a dependency of project '{1}'", dep.mProjectName, project.mProjectName));
- return false;
- }
- if (!GetDependentProjectList(depProject, orderedProjectList, useProjectStack))
- return false;
- }
- if (addSelf)
- {
- useProjectStack.RemoveAt(useProjectStack.Count - 1);
- orderedProjectList.Add(project);
- }
- return true;
- }
- void GetOrderedProjectList(List<Project> orderedProjectList)
- {
- List<Project> projectStack = scope List<Project>();
- for (var project in mWorkspace.mProjects)
- GetDependentProjectList(project, orderedProjectList, projectStack);
- }
- public virtual void LoadFailed()
- {
- if (mRunningTestScript)
- mFailed = true;
- }
- public virtual void TestFailed()
- {
- mLastTestFailed = true;
- }
- protected virtual void CompileFailed()
- {
- if (mTestManager != null)
- mTestManager.BuildFailed();
- if (mVerbosity > .Quiet)
- OutputLine("Compile failed.");
- mLastCompileFailed = true;
- if (mRunningTestScript)
- {
- if (!gApp.mScriptManager.mHadExpectingError)
- gApp.mScriptManager.Fail("Compile failed");
- }
- else
- {
- Beep(MessageBeepType.Error);
- }
- }
- void DbgCopyChangedFiles(DateTime cmpTime, StringView srcDir, StringView destDir)
- {
- bool isFirstFile = true;
- for (let fileEntry in Directory.EnumerateFiles(srcDir))
- {
- var fileWriteTime = fileEntry.GetLastWriteTime();
- String dates = scope .();
- cmpTime.ToString(dates);
- dates.Append("\n");
- fileWriteTime.ToString(dates);
- if (fileWriteTime > mDbgHighestTime)
- mDbgHighestTime = fileWriteTime;
- if (fileWriteTime < cmpTime)
- {
- continue;
- }
- String fileName = scope String();
- fileEntry.GetFileName(fileName);
- if (isFirstFile)
- {
- Directory.CreateDirectory(destDir).IgnoreError();
- isFirstFile = false;
- }
- String srcFile = scope .();
- srcFile.Append(srcDir);
- srcFile.Append("/");
- srcFile.Append(fileName);
- String destFile = scope .();
- destFile.Append(destDir);
- destFile.Append("/");
- destFile.Append(fileName);
- File.Copy(srcFile, destFile);
- }
- for (let fileEntry in Directory.EnumerateDirectories(srcDir))
- {
- String dirName = scope String();
- fileEntry.GetFileName(dirName);
- String newSrcDir = scope String();
- newSrcDir.Append(srcDir);
- newSrcDir.Append("/");
- newSrcDir.Append(dirName);
- String newDestDir = scope String();
- newDestDir.Append(destDir);
- newDestDir.Append("/");
- newDestDir.Append(dirName);
- DbgCopyChangedFiles(cmpTime, newSrcDir, newDestDir);
- }
- }
- void CompileResult(String hotProjectName, bool success)
- {
- if (mDbgCompileDir != null)
- {
- String compileResults = scope .();
- compileResults.AppendF("COMPILE {} {} {}: ", mDbgCompileIdx, mConfigName, mPlatformName);
- if (hotProjectName != null)
- compileResults.Append("Hot compile. ");
- if (!success)
- compileResults.Append("FAILED\n");
- else
- compileResults.Append("SUCCESS\n");
- String path = scope .();
- path.Append(mDbgCompileDir);
- path.Append("log.txt");
- File.WriteAllText(path, compileResults, true);
- var prevHighestTime = mDbgHighestTime;
- for (var project in mWorkspace.mProjects)
- {
- String buildDir = scope .();
- GetProjectBuildDir(project, buildDir);
- String toPath = scope .();
- toPath.Append(mDbgVersionedCompileDir);
- toPath.Append(project.mProjectName);
- toPath.Append("/");
- DbgCopyChangedFiles(prevHighestTime, buildDir, toPath);
- }
- }
- }
- void ProcessBeefCompileResults(BfPassInstance passInstance, bool runAfter, Project hotProject, Stopwatch startStopWatch)
- {
- bool didCompileSucceed = true;
- if (passInstance != null)
- {
- if (mProfileCompileProfileId != 0)
- mProfileCompileProfileId.Dispose();
- while (true)
- {
- String str = scope String();
- if (!passInstance.PopOutString(str))
- break;
- if (mVerbosity == .Quiet)
- continue;
- if (str.StartsWith(":"))
- {
- int spacePos = str.IndexOf(' ');
- if (spacePos > 0)
- {
- bool wantsDisp = true;
- StringView msgType = StringView(str, 0, spacePos);
- if (msgType == ":warn")
- {
- mLastCompileHadMessages = true;
- wantsDisp = mVerbosity >= .Minimal;
- }
- else if (msgType == ":error")
- {
- mLastCompileHadMessages = true;
- }
- else if (msgType == ":low")
- wantsDisp = mVerbosity >= .Detailed;
- else if (msgType == ":med")
- wantsDisp = mVerbosity >= .Normal;
- if (!wantsDisp)
- continue;
- str.Remove(0, spacePos + 1);
- }
- }
- str.Append("\n");
- OutputSmart(str);
- //OutputLine(str);
- }
- if ((passInstance.mFailed) && (passInstance.mCompileSucceeded))
- {
- // This can happen if we can't load a Beef file
- CompileFailed();
- passInstance.mCompileSucceeded = false;
- }
- didCompileSucceed = passInstance.mCompileSucceeded;
- if (didCompileSucceed)
- {
- mLastCompileSucceeded = true;
- mWorkspace.WithProjectItems(scope (item) =>
- {
- if (var projectSource = item as ProjectSource)
- {
- if (IsBeefFile(projectSource.mPath))
- {
- if (!projectSource.mHasChangedSinceLastCompile)
- projectSource.mHasChangedSinceLastSuccessfulCompile = false;
- }
- }
- });
- }
- else
- mLastCompileHadMessages = true;
- delete passInstance;
- }
- if ((hotProject != null) && (passInstance != null) && (didCompileSucceed))
- {
- if (!mDebugger.mIsRunning)
- {
- OutputSmart("Hot compile failed - target no longer running");
- CompileFailed();
- return;
- }
- DebugManager.HotResolveFlags hotResolveFlags = .ActiveMethods;
- if (mBfBuildCompiler.GetHasHotPendingDataChanges())
- {
- hotResolveFlags |= .Allocations;
- mHotResolveState = .PendingWithDataChanges;
- }
- else
- {
- mHotResolveState = .Pending;
- }
-
- mHotResolveTryIdx = 0;
-
- mDebugger.InitiateHotResolve(hotResolveFlags);
- return;
- }
- List<Project> orderedProjectList = scope List<Project>();
- GetOrderedProjectList(orderedProjectList);
- if (!didCompileSucceed)
- {
- // Failed, bail out
- for (var project in orderedProjectList)
- {
- SkipProjectCompile(project, hotProject);
- }
- CompileResult((hotProject != null) ? hotProject.mProjectName : null, false);
- CompileFailed();
- return;
- }
- var completedCompileCmd = new BuildCompletedCmd();
- if (hotProject != null)
- completedCompileCmd.mHotProjectName = new String(hotProject.mProjectName);
- //TODO: Pass in
- //Project project = mWorkspace.mProjects[0];
- bool success = true;
- List<String> hotFileNames = scope List<String>();
- defer ClearAndDeleteItems(hotFileNames);
- Debug.Assert(mBuildContext == null);
- DeleteAndNullify!(mBuildContext);
- mBuildContext = new .();
- mBuildContext.mWorkspaceOptions = GetCurWorkspaceOptions();
- for (var project in orderedProjectList)
- {
- if (!mBuildContext.QueueProjectCompile(project, hotProject, completedCompileCmd, hotFileNames, runAfter))
- success = false;
- }
- if (hotFileNames.Count > 0)
- {
- // Why were we rehupping BEFORE hotLoad?
- mDebugger.RehupBreakpoints(false, false);
- String[] entries = scope String[hotFileNames.Count];
- for (int32 i = 0; i < hotFileNames.Count; i++)
- entries[i] = hotFileNames[i];
- //
- mBfBuildCompiler.HotCommit();
- mDebugger.HotLoad(entries, mWorkspace.HotCompileIdx);
- /*if (mDebugger.IsPaused())
- PCChanged();*/
- //mDebugger.RehupBreakpoints(false);
- RefreshWatches();
- }
- if (!success)
- CompileFailed();
- if ((runAfter) && (success))
- {
- var startDebugCmd = new StartDebugCmd();
- startDebugCmd.mWasCompiled = true;
- startDebugCmd.mOnlyIfNotFailed = true;
- mExecutionQueue.Add(startDebugCmd);
- }
-
- if (startStopWatch != null)
- {
- delete completedCompileCmd.mStopwatch;
- var stopwatch = new Stopwatch();
- stopwatch.CopyFrom(startStopWatch);
- completedCompileCmd.mStopwatch = stopwatch;
- }
- mExecutionQueue.Add(completedCompileCmd);
- }
- bool CompileAndRun()
- {
- if (AreTestsRunning())
- return false;
- if (IsCompiling)
- return false;
- if (!mExecutionQueue.IsEmpty)
- {
- if (var processCompileCmd = mExecutionQueue.Back as ProcessBfCompileCmd)
- {
- processCompileCmd.mRunAfter = true;
- }
- return false;
- }
- mOutputPanel.Clear();
- OutputLine("Compiling...");
- if (!Compile(.RunAfter))
- return false;
- return true;
- }
- public void QueueProfiling(int threadId, String desc, int sampleRate)
- {
- var profileCmd = new ProfileCmd();
- profileCmd.mThreadId = threadId;
- profileCmd.mDesc = new String(desc);
- profileCmd.mSampleRate = sampleRate;
- if (var processCompileCmd = mExecutionQueue.Back as ProcessBfCompileCmd)
- {
- processCompileCmd.mProfileCmd = profileCmd;
- }
- }
- [IDECommand]
- void StopRunning()
- {
- if (AreTestsRunning())
- {
- mTestManager.Stop();
- return;
- }
- if (mCrashDumpPath != null)
- {
- DeleteAndNullify!(mCrashDumpPath);
- mDebugger.Detach();
- mDebugger.mIsRunning = false;
- mExecutionPaused = false;
- }
- if (mDebugger.mIsRunning)
- {
- mDebugger.StopDebugging();
- }
- }
- enum CompileKind
- {
- Normal,
- RunAfter,
- Test
- }
- protected bool Compile(CompileKind compileKind = .Normal, Project hotProject = null)
- {
- Debug.Assert(mBuildContext == null);
- let platform = Workspace.PlatformType.GetFromName(mPlatformName);
- let hostPlatform = Workspace.PlatformType.GetHostPlatform();
- if (platform == .Unknown)
- {
- OutputErrorLine("Failed to compiler for unknown platform '{}'", mPlatformName);
- return false;
- }
- bool canCompile = false;
- if (platform == hostPlatform)
- {
- canCompile = true;
- }
- else
- {
- canCompile = false;
- }
-
- if (!canCompile)
- {
- OutputErrorLine("Cannot compile for platform '{}' from host platform '{}'", platform, hostPlatform);
- return false;
- }
- if (mDbgCompileDump)
- {
- mDbgCompileIdx++;
- String dbgBuildDir = scope .();
- dbgBuildDir.Append(mInstallDir);
- dbgBuildDir.Append("_dbg/");
- String exePath = scope .();
- Environment.GetExecutableFilePath(exePath);
- Path.GetFileNameWithoutExtension(exePath, dbgBuildDir);
- /*String exePath = scope .();
- Environment.GetExecutableFilePath(exePath);
- String exeName = scope .();
- Path.GetFileNameWithoutExtension(exePath, exeName);
- String dbgBuildDir = scope String(mInstallDir, "dbg_build_", exeName);*/
- if (mDbgCompileIdx == 0)
- {
- String tempDirName = scope .();
- tempDirName.Append(mInstallDir);
- tempDirName.AppendF("_dbg/_{0}", DateTime.Now.Ticks);
- if (Directory.Move(dbgBuildDir, tempDirName) case .Err(let err))
- {
- if (err != .NotFound)
- {
- Fail(scope String..AppendF("Failed to rename {0} to {1}", dbgBuildDir, tempDirName));
- return false;
- }
- }
- String delDirName = new String(tempDirName);
- ThreadPool.QueueUserWorkItem(new () =>
- {
- Utils.DelTree(delDirName).IgnoreError();
- delete delDirName;
- });
-
- bool worked = false;
- for (int i < 20)
- {
- if (Directory.CreateDirectory(dbgBuildDir) case .Ok)
- {
- worked = true;
- break;
- }
- Thread.Sleep(100);
- }
- Debug.Assert(worked);
- }
- dbgBuildDir.Append("/");
- if (mDbgCompileIdx == 0)
- {
- delete mDbgCompileDir;
- mDbgCompileDir = new String(dbgBuildDir);
-
- for (var project in mWorkspace.mProjects)
- {
- String buildDir = scope .();
- GetProjectBuildDir(project, buildDir);
- String toPath = scope .();
- toPath.Append(mDbgCompileDir);
- toPath.Append("/init/");
- toPath.Append(project.mProjectName);
- toPath.Append("/");
- DbgCopyChangedFiles(default, buildDir, toPath);
- }
- }
- dbgBuildDir.AppendF("{0}", mDbgCompileIdx);
- Directory.CreateDirectory(dbgBuildDir);
- DeleteAndNullify!(mDbgVersionedCompileDir);
- mDbgVersionedCompileDir = new String(dbgBuildDir);
- mDbgVersionedCompileDir.Append("/");
- }
- if ((AreTestsRunning()) && (compileKind != .Test))
- {
- return false;
- }
- var workspaceOptions = GetCurWorkspaceOptions();
- if (compileKind == .RunAfter)
- {
- if (workspaceOptions.mBuildKind == .Test)
- {
- OutputLineSmart("ERROR: Cannot directly run Test workspace configurations. Use the 'Test' menu to run or debug tests.");
- return false;
- }
- }
- if (Workspace.PlatformType.GetFromName(mPlatformName) == .Windows)
- {
- if (!mSettings.mVSSettings.IsConfigured())
- mSettings.mVSSettings.SetDefaults();
- if (!mSettings.mVSSettings.IsConfigured())
- {
- String err =
- """
- Beef requires the Microsoft C++ build tools for Visual Studio 2013 or later, but they don't seem to be installed.
- Install just Microsoft Visual C++ Build Tools or the entire Visual Studio suite from:
- https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
- """;
- #if CLI
- Fail(err);
- #else
- DarkDialog dlg = new DarkDialog("Visual C++ Not Found", err, DarkTheme.sDarkTheme.mIconError);
- dlg.mWindowFlags |= .Modal;
- dlg.AddOkCancelButtons(new (dlg) =>
- {
- ProcessStartInfo psi = scope ProcessStartInfo();
- psi.SetFileName("https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019");
- psi.UseShellExecute = true;
- psi.SetVerb("Open");
- var process = scope SpawnedProcess();
- process.Start(psi).IgnoreError();
- },
- new (dlg) =>
- {
- });
- ((DarkButton)dlg.mButtons[0]).Label = "Open Link";
- dlg.PopupWindow(GetActiveWindow());
- MessageBeep(.Error);
- #endif
- }
- }
- if (mProfileCompile)
- mProfileCompileProfileId = Profiler.StartSampling("Compile");
- if (mWantsBeefClean)
- {
- // We must finish cleaning before we can compile
- while (mWantsBeefClean)
- {
- UpdateCompilersAndDebugger();
- }
- }
-
- if ((!workspaceOptions.mIncrementalBuild) && (mCompileSinceCleanCount > 0) && (hotProject == null))
- {
- delete mBfBuildCompiler;
- delete mBfBuildSystem;
- mBfBuildSystem = new BfSystem();
- mBfBuildCompiler = mBfBuildSystem.CreateCompiler(false);
- for (var project in mWorkspace.mProjects)
- {
- mBfBuildSystem.AddProject(project);
- }
- }
- bool lastCompileHadMessages = mLastCompileHadMessages;
- mLastCompileFailed = false;
- mLastCompileSucceeded = false;
- mLastCompileHadMessages = false;
- mCompileSinceCleanCount++;
- ShowPanel(mOutputPanel, false);
- if (mDisableBuilding)
- {
- OutputLineSmart("ERROR: Compiling disabled!");
- return false;
- }
- if (mExecutionQueue.Count > 0)
- return false;
- if ((mDebugger != null) && (mDebugger.mIsRunning) && (hotProject == null))
- {
- Debug.Assert(!mDebugger.mIsRunningCompiled);
- Debug.Assert(compileKind == .Normal);
- }
- mHaveSourcesChangedExternallySinceLastCompile = false;
- mHaveSourcesChangedInternallySinceLastCompile = false;
- mWorkspace.SetupProjectCompileInstance(hotProject != null);
- int32 hotIdx = mWorkspace.HotCompileIdx;
- if (hotProject == null)
- {
- Debug.Assert(hotIdx == 0);
- }
- // Set position for breakpoints here only on first one.
- // For hotload we do it later.
- //if (!mDebugger.mIsRunning)
- //mDebugger.RehupBreakpoints(true);
-
- SaveClangFiles();
- if (compileKind == .RunAfter)
- {
- DeleteAndNullify!(mCompileAndRunStopwatch);
- mCompileAndRunStopwatch = new Stopwatch();
- mCompileAndRunStopwatch.Start();
- }
- //mBfBuildCompiler.QueueStartTiming();
- mBfBuildCompiler.ClearCompletionPercentage();
- BfPassInstance passInstance = null;
- passInstance = CompileBeef(hotProject, hotIdx, lastCompileHadMessages, let hadBeef);
- if (passInstance == null)
- {
- CompileFailed();
- return false;
- }
- ProcessBfCompileCmd processCompileCmd = new ProcessBfCompileCmd();
- processCompileCmd.mBfPassInstance = passInstance;
- processCompileCmd.mRunAfter = compileKind == .RunAfter;
- processCompileCmd.mHotProject = hotProject;
- processCompileCmd.mStopwatch = new Stopwatch();
- processCompileCmd.mStopwatch.Start();
- processCompileCmd.mHadBeef = hadBeef;
- mExecutionQueue.Add(processCompileCmd);
- return true;
- }
- void CheckDebugVisualizers()
- {
- scope AutoBeefPerf("CheckDebugVisualizers");
- String dbgVis = scope String();
- dbgVis.Append(mInstallDir, "BeefDbgVis.toml");
- mWorkspace.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource == null)
- return;
- if ((projectSource.mName.StartsWith("BeefDbgVis")) &&
- (projectSource.mName.EndsWith(".toml")))
- {
- dbgVis.Append("\n");
- projectSource.GetFullImportPath(dbgVis);
- }
- });
- mDebugger.LoadDebugVisualizers(dbgVis);
- //mDebugger.LoadDebugVisualizers(scope String(mInstallDir, "BeefDbgVis.toml"));
- }
- bool DebugProject(bool wasCompiled)
- {
- mProfilePanel.Clear();
- if (mWorkspace.mStartupProject == null)
- {
- OutputLineSmart("ERROR: No startup project started");
- return false;
- }
- var project = mWorkspace.mStartupProject;
- var workspaceOptions = GetCurWorkspaceOptions();
- var options = GetCurProjectOptions(project);
- if (options == null)
- {
- OutputLineSmart("ERROR: Startup project '{0}' not enabled", mWorkspace.mStartupProject.mProjectName);
- return false;
- }
- mDebugger.ClearInvalidBreakpoints();
- mTargetDidInitBreak = false;
- mTargetHadFirstBreak = false;
- //options.mDebugOptions.mCommand
- String launchPath = scope String();
- ResolveConfigString(mPlatformName, workspaceOptions, project, options, options.mDebugOptions.mCommand, "debug command", launchPath);
- String arguments = scope String();
- ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(Arguments)", "debug command arguments", arguments);
- String workingDirRel = scope String();
- ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(WorkingDir)", "debug working directory", workingDirRel);
- var workingDir = scope String();
- Path.GetAbsolutePath(workingDirRel, project.mProjectDir, workingDir);
- String targetPath = scope .();
- ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath);
- IDEUtils.FixFilePath(launchPath);
- IDEUtils.FixFilePath(targetPath);
- if (workingDir.IsEmpty)
- Path.GetDirectoryPath(launchPath, workingDir);
- if (!Directory.Exists(workingDir))
- {
- OutputErrorLine(scope String()..AppendF("Unable to locate working directory '{0}'", workingDir));
- return false;
- }
- var envVars = scope Dictionary<String, String>();
- defer { for (var kv in envVars) { delete kv.key; delete kv.value; } }
- Environment.GetEnvironmentVariables(envVars);
- for (var envVar in options.mDebugOptions.mEnvironmentVars)
- {
- int eqPos = envVar.IndexOf('=', 1);
- if (eqPos == -1)
- {
- OutputErrorLine("Invalid environment variable: {0}", envVar);
- }
- else
- {
- Environment.SetEnvironmentVariable(envVars, StringView(envVar, 0, eqPos), StringView(envVar, eqPos + 1));
- }
- }
- var envBlock = scope List<char8>();
- Environment.EncodeEnvironmentVariables(envVars, envBlock);
- if (launchPath.IsWhiteSpace)
- {
- Fail(scope String()..AppendF("No debug command specified in '{}' properties", project.mProjectName));
- return false;
- }
- if (!mDebugger.OpenFile(launchPath, targetPath, arguments, workingDir, envBlock, wasCompiled))
- {
- DeleteAndNullify!(mCompileAndRunStopwatch);
- return false;
- }
- CheckDebugVisualizers();
- mDebugger.mIsRunning = true;
- WithSourceViewPanels(scope (sourceView) =>
- {
- sourceView.RehupAlias();
- });
- mDebugger.RehupBreakpoints(true);
- mDebugger.Run();
- mModulePanel.ModulesChanged();
- if (mCompileAndRunStopwatch != null)
- {
- mCompileAndRunStopwatch.Stop();
- OutputLine("Compile-to-debug time: {0:0.00}s", mCompileAndRunStopwatch.ElapsedMilliseconds / 1000.0f);
- }
- if ((mTargetStartWithStep) && (mMainBreakpoint == null))
- {
- // The idea is that we don't want to step into static initializers, so we
- // temporarily break on _main and then we single step
- //mMainBreakpoint = mDebugger.CreateSymbolBreakpoint("_ZN3Hey4Dude3Bro9TestClass4MainEv");
- if ((project.mGeneralOptions.mTargetType == Project.TargetType.BeefConsoleApplication) ||
- (project.mGeneralOptions.mTargetType == Project.TargetType.BeefWindowsApplication))
- mMainBreakpoint = mDebugger.CreateSymbolBreakpoint("-BeefMain");
- else
- {
- mMainBreakpoint = mDebugger.CreateSymbolBreakpoint("-main");
- #if BF_PLATFORM_WINDOWS
- //mMainBreakpoint2 = mDebugger.CreateSymbolBreakpoint("-WinMain");
- #endif
- }
- }
- return true;
- }
- public void Attach(Process process, DebugManager.AttachFlags attachFlags)
- {
- UpdateTitle(process.ProcessName);
- OutputLine("Attaching to process id {0}: {1}", process.Id, process.ProcessName);
- mExecutionPaused = false;
- mTargetDidInitBreak = false;
- mTargetHadFirstBreak = false;
- if (mDebugger.mIsRunning)
- {
- Fail("Already debugging a target");
- return;
- }
- if (!mDebugger.Attach(process, attachFlags))
- {
- Fail("Failed to attach to process");
- return;
- }
- CheckDebugVisualizers();
- mDebugger.mIsRunning = true;
- mDebugger.RehupBreakpoints(true);
- mDebugger.Run();
- mIsAttachPendingSourceShow = true;
- }
- void ShowPanel(Widget panel, bool setFocus = true)
- {
- WithTabs(scope (tab) =>
- {
- if (tab.mContent == panel)
- tab.Activate(setFocus);
- });
- }
- void ShowStartupFile()
- {
- bool hasSourceShown = false;
- WithSourceViewPanels(scope [&] (panel) =>
- {
- hasSourceShown = true;
- });
- if (hasSourceShown)
- return;
- if (mWorkspace.mStartupProject != null)
- {
- bool didShow = false;
- mWorkspace.mStartupProject.WithProjectItems(scope [&] (item) =>
- {
- if (didShow)
- return;
- if ((item.mName.Equals("main.bf", .OrdinalIgnoreCase)) ||
- (item.mName.Equals("program.bf", .OrdinalIgnoreCase)))
- {
- ShowProjectItem(item, false);
- didShow = true;
- }
- });
- }
- }
- public void CreateDefaultLayout()
- {
- //TODO:
- //mConfigName.Set("Dbg");
- if ((!mRunningTestScript) && (!mIsFirstRun) && (LoadDefaultLayoutData()))
- {
- return;
- }
- bool docOnlyView = false;
-
- TabbedView projectTabbedView = CreateTabbedView();
- SetupTab(projectTabbedView, "Workspace", 0, mProjectPanel, false);
- projectTabbedView.SetRequestedSize(GS!(200), GS!(200));
- projectTabbedView.mWidth = GS!(200);
- //TabbedView propertiesView = CreateTabbedView();
- //propertiesView.AddTab("Properties", 0, mPropertiesPanel, false);
- //propertiesView.SetRequestedSize(250, 250);
- if (!docOnlyView)
- {
- mDockingFrame.AddDockedWidget(projectTabbedView, null, DockingFrame.WidgetAlign.Left);
- EnsureDocumentArea();
- //mDockingFrame.AddDockedWidget(propertiesView, null, DockingFrame.WidgetAlign.Right);
- }
- var outputTabbedView = CreateTabbedView();
- mDockingFrame.AddDockedWidget(outputTabbedView, null, DockingFrame.WidgetAlign.Bottom);
- outputTabbedView.SetRequestedSize(GS!(250), GS!(250));
-
- SetupTab(outputTabbedView, "Output", GS!(150), mOutputPanel, false);
- SetupTab(outputTabbedView, "Immediate", GS!(150), mImmediatePanel, false);
- //outputTabbedView.AddTab("Find Results", 150, mFindResultsPanel, false);
- var watchTabbedView = CreateTabbedView();
- watchTabbedView.SetRequestedSize(GS!(250), GS!(250));
- mDockingFrame.AddDockedWidget(watchTabbedView, outputTabbedView, DockingFrame.WidgetAlign.Left);
- SetupTab(watchTabbedView, "Auto", 150, mAutoWatchPanel, false);
- SetupTab(watchTabbedView, "Watch", 150, mWatchPanel, false);
- SetupTab(watchTabbedView, "Memory", 150, mMemoryPanel, false);
-
- SetupTab(outputTabbedView, "Call Stack", 150, mCallStackPanel, false);
- SetupTab(outputTabbedView, "Threads", 150, mThreadPanel, false);
- }
- protected void CreateBfSystems()
- {
- scope AutoBeefPerf("IDEApp.CreateBfSystems");
- #if !CLI
- if (!mNoResolve)
- {
- mBfResolveSystem = new BfSystem();
- mBfResolveCompiler = mBfResolveSystem.CreateCompiler(true);
- mBfResolveHelper = new BfResolveHelper();
- }
- #if IDE_C_SUPPORT
- mResolveClang = new ClangCompiler(true);
- #endif
- #endif
- mCompileSinceCleanCount = 0;
- mBfBuildSystem = new BfSystem();
- mBfBuildCompiler = mBfBuildSystem.CreateCompiler(false);
- #if IDE_C_SUPPORT
- mDepClang = new ClangCompiler(false);
- mDepClang.mPairedCompiler = mResolveClang;
- mResolveClang.mPairedCompiler = mDepClang;
- #endif
- }
-
- void UpdateTitle(StringView titleOverride = default)
- {
- String title = scope String();
- if ((mWorkspace != null) && (mWorkspace.mName != null))
- {
- title.Append(mWorkspace.mName);
- title.Append(" - ");
- }
- if (titleOverride.Ptr != null)
- {
- title.Append(titleOverride);
- title.Append(" - ");
- }
- title.Append("Beef IDE");
- String extraStr = scope .();
- String exePath = scope .();
- Environment.GetExecutableFilePath(exePath);
- if (exePath.Contains(@"\host\"))
- extraStr.Append("host");
- String exeFileName = scope .();
- Path.GetFileNameWithoutExtension(exePath, exeFileName);
- int slashPos = exeFileName.IndexOf('_');
- if (slashPos != -1)
- {
- if (!extraStr.IsEmpty)
- extraStr.Append(" ");
- extraStr.Append(exeFileName, slashPos + 1);
- }
- if (!extraStr.IsEmpty)
- title.AppendF(" [{}]", extraStr);
- mMainWindow.SetTitle(title);
- }
- public void CreateSpellChecker()
- {
- mSpellChecker = new SpellChecker();
- if (mSpellChecker.Init(scope String(mInstallDir, "en_US")) case .Err)
- {
- DeleteAndNullify!(mSpellChecker);
- }
- }
- public FileVersionInfo GetVersionInfo()
- {
- if (mVersionInfo == null)
- {
- String exeFilePath = scope .();
- Environment.GetExecutableFilePath(exeFilePath);
- mVersionInfo = new .();
- mVersionInfo.GetVersionInfo(exeFilePath).IgnoreError();
- }
- return mVersionInfo;
- }
- #if !CLI
- public override void Init()
- {
- scope AutoBeefPerf("IDEApp.Init");
- //int zag = 123;
- if (mVerbosity == .Default)
- mVerbosity = .Detailed;
- mStartedWithTestScript = mRunningTestScript;
- mCommands.Init();
- EnableGCCollect = mEnableGCCollect;
- if (mConfigName.IsEmpty)
- mConfigName.Set("Debug");
- if (mPlatformName.IsEmpty)
- mPlatformName.Set(sPlatform64Name);
- Directory.GetCurrentDirectory(mInitialCWD);
- #if DEBUG
- //mColorMatrix = Matrix4.Identity;
- #endif
- base.Init();
- mSettings.Apply();
- //Yoop();
- /*for (int i = 0; i < 100*1024*1024; i++)
- {
- mTestString.Append("Hey, this is a test string!");
- }*/
- mAutoDirty = false;
- WidgetWindow.sOnWindowClosed.Add(new => HandleWindowClosed);
- //mProjectDir = BFApp.mApp.mInstallDir + "../../";
- if (!mRunningTestScript)
- {
- // User setting can affect automated testing, so use default settings
- if (!mIsFirstRun)
- mSettings.Load();
- mSettings.Apply();
- mIsFirstRun = !mSettings.mLoadedSettings;
- #if !CLI && BF_PLATFORM_WINDOWS
- if (!mSettings.mTutorialsFinished.mRanDebug)
- {
- let exePath = scope String();
- Environment.GetExecutableFilePath(exePath);
- if (exePath.EndsWith("_d.exe", .OrdinalIgnoreCase))
- {
- if (Windows.MessageBoxA(default, "Are you sure you want to run the debug build of the Beef IDE? This is useful for debugging Beef issues but execution speed will be much slower.", "RUN DEBUG?",
- Windows.MB_ICONQUESTION | Windows.MB_YESNO) != Windows.IDYES)
- {
- Stop();
- return;
- }
- }
- mSettings.mTutorialsFinished.mRanDebug = true;
- }
- #endif
- }
- DarkTheme aTheme = new DarkTheme();
- aTheme.Init();
- ThemeFactory.mDefault = aTheme;
- mTinyCodeFont = new Font();
- mCodeFont = new Font();
- //mCodeFont = Font.LoadFromFile(BFApp.sApp.mInstallDir + "fonts/SourceCodePro32.fnt");
- //mCodeFont = Font.LoadFromFile(BFApp.sApp.mInstallDir + "fonts/SegoeUI24.fnt");
- mMainFrame = new MainFrame();
- mDockingFrame = mMainFrame.mDockingFrame;
-
- mSquiggleImage = Image.LoadFromFile(scope String(mInstallDir, "images/Squiggle.png"));
- mCircleImage = Image.LoadFromFile(scope String(mInstallDir, "images/Circle.png"));
-
- RehupScale();
- CreateBfSystems();
- if (mWantsClean)
- {
- mBfBuildCompiler.ClearBuildCache();
- mWantsClean = false;
- }
- mProjectPanel = new ProjectPanel();
- mProjectPanel.mAutoDelete = false;
- mClassViewPanel = new ClassViewPanel();
- mClassViewPanel.mAutoDelete = false;
- mOutputPanel = new OutputPanel(true);
- mOutputPanel.mAutoDelete = false;
- mImmediatePanel = new ImmediatePanel();
- mImmediatePanel.mAutoDelete = false;
- mFindResultsPanel = new FindResultsPanel();
- mFindResultsPanel.mAutoDelete = false;
- mAutoWatchPanel = new WatchPanel(true);
- mAutoWatchPanel.mAutoDelete = false;
- mWatchPanel = new WatchPanel(false);
- mWatchPanel.mAutoDelete = false;
- mMemoryPanel = new MemoryPanel();
- mMemoryPanel.mAutoDelete = false;
- mCallStackPanel = new CallStackPanel();
- mCallStackPanel.mAutoDelete = false;
- mBreakpointPanel = new BreakpointPanel();
- mBreakpointPanel.mAutoDelete = false;
- mModulePanel = new ModulePanel();
- mModulePanel.mAutoDelete = false;
- mThreadPanel = new ThreadPanel();
- mThreadPanel.mAutoDelete = false;
- mProfilePanel = new ProfilePanel();
- mProfilePanel.mAutoDelete = false;
- mPropertiesPanel = new PropertiesPanel();
- mPropertiesPanel.mAutoDelete = false;
- mAutoCompletePanel = new AutoCompletePanel();
- mAutoCompletePanel.mAutoDelete = false;
- GetVersionInfo();
- OutputLine("IDE Started. Version {}.", mVersionInfo.FileVersion);
- /*if (!mRunningTestScript)
- {
- LoadUserSettings(); // User setting can affect automated testing, so use default settings
- mSettings.Load();
- mSettings.Apply();
- }*/
- if (mWorkspace.mDir != null)
- {
- mWorkspace.mName = new String();
- Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
- LoadWorkspace(mVerb);
- }
- else if (mWorkspace.IsSingleFileWorkspace)
- {
- mWorkspace.mName = new String();
- Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName);
- LoadWorkspace(mVerb);
- }
- bool loadedWorkspaceUserData = false;
- if ((!mRunningTestScript) && (LoadWorkspaceUserData()))
- {
- loadedWorkspaceUserData = true;
- }
- WorkspaceLoaded();
- if ((mIsFirstRun) && (!loadedWorkspaceUserData))
- {
- GetWorkspaceRect(var workX, var workY, var workWidth, var workHeight);
- int32 height = (int32)(workHeight * 0.85f);
- int32 width = Math.Min(4 * height / 3, (int32)(workWidth * 0.85f));
- mRequestedWindowRect = .(workX + (workWidth - width)/2, workY + (workHeight - height)/2, width, height);
- }
- //
- {
- BFWindow.Flags flags = .Border | .ThickFrame | .Resizable | .SysMenu |
- .Caption | .Minimize | .Maximize | .QuitOnClose | .Menu;
- if (mRunningTestScript)
- flags |= .NoActivate;
- if (mRequestedShowKind == .Maximized)
- flags |= .ShowMaximized;
- scope AutoBeefPerf("IDEApp.Init:CreateMainWindow");
- mMainWindow = new WidgetWindow(null, "Beef IDE", (int32)mRequestedWindowRect.mX,
- (int32)mRequestedWindowRect.mY, (int32)mRequestedWindowRect.mWidth, (int32)mRequestedWindowRect.mHeight,
- flags, mMainFrame);
- }
- if (mIsFirstRun)
- {
- // If this is our first time running, set up a scale based on DPI
- int dpi = mMainWindow.GetDPI();
- if (dpi >= 120)
- {
- mSettings.mEditorSettings.mUIScale = 100 * Math.Min(dpi / 96.0f, 4.0f);
- mSettings.Apply();
- }
- }
- if (!loadedWorkspaceUserData)
- CreateDefaultLayout();
- UpdateTitle();
- mMainWindow.SetMinimumSize(GS!(480), GS!(360));
- mMainWindow.mIsMainWindow = true;
- mMainWindow.mOnWindowKeyDown.Add(new => SysKeyDown);
- mMainWindow.mOnWindowCloseQuery.Add(new => AllowClose);
- CreateMenu();
- UpdateRecentDisplayedFilesMenuItems();
- if (mRecentlyDisplayedFiles.Count > 0)
- ShowRecentFile(0);
-
- mProjectPanel.RebuildUI();
- if (mProcessAttachId != 0)
- {
- Process debugProcess = scope Process();
- switch (debugProcess.GetProcessById(mProcessAttachId))
- {
- case .Ok:
- case .Err:
- Fail(StackStringFormat!("Unable to locate process id {0}", mProcessAttachId));
- }
- if (debugProcess.IsAttached)
- {
- DebugManager.AttachFlags attachFlags = .None;
- String titleName = scope String();
- UpdateTitle(titleName);
- OutputLine("Attaching to process id {0}: {1}", mProcessAttachId, titleName);
- #if BF_PLATFORM_WINDOWS
- if (!mProcessAttachHandle.IsInvalid)
- attachFlags |= .ShutdownOnExit;
- #endif
-
- Attach(debugProcess, attachFlags);
- #if BF_PLATFORM_WINDOWS
- if (!mProcessAttachHandle.IsInvalid)
- {
- Windows.SetEvent(mProcessAttachHandle);
- mTargetDidInitBreak = true;
- mTargetHadFirstBreak = true;
- }
- #endif
- }
- }
- else if (mCrashDumpPath != null)
- {
- if (mDebugger.OpenMiniDump(mCrashDumpPath))
- {
- mDebugger.mIsRunning = true;
- mExecutionPaused = false; // Make this false so we can detect a Pause immediately
- mIsAttachPendingSourceShow = true;
- }
- else
- {
- Fail(StackStringFormat!("Failed to load minidump '{0}'", mCrashDumpPath));
- }
- }
- else if (mLaunchData != null)
- {
- LaunchDialog.DoLaunch(null, mLaunchData.mTargetPath, mLaunchData.mArgs ?? "", mLaunchData.mWorkingDir ?? "", "", mLaunchData.mPaused, true);
- }
- mInitialized = true;
- //Profiler.StopSampling();
- //if (IsMinidump)
- //ShowOutput();
- bool needSave = false;
- /*if (mWorkspace.mIsLegacyWorkspace)
- {
- mWorkspace.mIsLegacyWorkspace = false;
- mWorkspace.mHasChanged = true;
- needSave = true;
- }*/
- /*for (var project in mWorkspace.mProjects)
- {
- if (project.mIsLegacyProject)
- {
- int slashPos = project.mProjectPath.LastIndexOf('\\');
- if (slashPos != -1)
- {
- project.mProjectPath.RemoveToEnd(slashPos + 1);
- project.mProjectPath.Append("BeefProj.toml");
- project.mHasChanged = true;
- project.mIsLegacyProject = false;
- needSave = true;
- }
- //"BeefProj.toml"
- }
- }*/
- if (needSave)
- SaveAll();
- ShowPanel(mOutputPanel, false);
- UpdateRecentFileMenuItems();
- ShowStartupFile();
- if ((mIsFirstRun) && (!mWorkspace.IsInitialized))
- ShowWelcome();
- }
- #endif
- void ShowWelcome()
- {
- WelcomePanel welcomePanel = new .();
- TabbedView tabbedView = GetDefaultDocumentTabbedView();
- let tabButton = SetupTab(tabbedView, "Welcome", 0, welcomePanel, true);
- tabButton.Activate();
- }
- void LoadConfig()
- {
- delete mBeefConfig;
- mBeefConfig = new BeefConfig();
- if (mWorkspace.IsSingleFileWorkspace)
- {
- var dir = scope String();
- Path.GetDirectoryPath(mWorkspace.mCompositeFile.FilePath, dir);
- mBeefConfig.QueuePaths(dir);
- }
- else
- mBeefConfig.QueuePaths(mWorkspace.mDir);
- mBeefConfig.QueuePaths(mInstallDir);
- mBeefConfig.Load().IgnoreError();
- }
- void RehupScale()
- {
- if (mInitialized)
- Font.ClearCache();
- if (mCodeFont == null)
- return;
- float fontSize = DarkTheme.sScale * mSettings.mEditorSettings.mFontSize;
- float tinyFontSize = fontSize * 8.0f/9.0f;
- bool isFirstFont = true;
- for (let fontName in mSettings.mEditorSettings.mFonts)
- {
- if (isFirstFont)
- {
- mTinyCodeFont.Dispose(true);
- isFirstFont = !mTinyCodeFont.Load(fontName, tinyFontSize);
- mCodeFont.Dispose(true);
- mCodeFont.Load(fontName, fontSize);
- }
- else
- {
- mTinyCodeFont.AddAlternate(fontName, tinyFontSize).IgnoreError();
- mCodeFont.AddAlternate(fontName, fontSize).IgnoreError();
- }
- }
- if (mCodeFont.GetHeight() == 0)
- {
- mTinyCodeFont.Load("fonts/SourceCodePro-Regular.ttf", tinyFontSize);
- mCodeFont.Load("fonts/SourceCodePro-Regular.ttf", fontSize);
- }
- // Do we have an extended font?
- if (mCodeFont.GetWidth('😊') == 0)
- {
- mCodeFont.AddAlternate("Segoe UI", fontSize);
- mCodeFont.AddAlternate("Segoe UI Symbol", fontSize);
- mCodeFont.AddAlternate("Segoe UI Historic", fontSize).IgnoreError();
- mCodeFont.AddAlternate("Segoe UI Emoji", fontSize).IgnoreError();
- mTinyCodeFont.AddAlternate("Segoe UI", tinyFontSize);
- mTinyCodeFont.AddAlternate("Segoe UI Symbol", tinyFontSize);
- mTinyCodeFont.AddAlternate("Segoe UI Historic", tinyFontSize).IgnoreError();
- mTinyCodeFont.AddAlternate("Segoe UI Emoji", tinyFontSize).IgnoreError();
- /*mCodeFont.AddAlternate(new String("fonts/segoeui.ttf"), fontSize);
- mCodeFont.AddAlternate(new String("fonts/seguisym.ttf"), fontSize);
- mCodeFont.AddAlternate(new String("fonts/seguihis.ttf"), fontSize);
- mTinyCodeFont.AddAlternate(new String("fonts/segoeui.ttf"), tinyFontSize);
- mTinyCodeFont.AddAlternate(new String("fonts/seguisym.ttf"), tinyFontSize);
- mTinyCodeFont.AddAlternate(new String("fonts/seguihis.ttf"), tinyFontSize);*/
- }
- //mTinyCodeFont.Load(scope String(BFApp.sApp.mInstallDir, "fonts/SourceCodePro-Regular.ttf"), fontSize);
- float squiggleScale = DarkTheme.sScale;
- if (squiggleScale < 3.0f)
- squiggleScale = (float)Math.Round(squiggleScale);
- mSquiggleImage.Scale(squiggleScale);
- mCircleImage.Scale(DarkTheme.sScale);
- }
- void HandleWindowClosed(BFWindow window)
- {
- if (mWindowDatas.GetAndRemove(window) case .Ok((?, var windowData)))
- {
- delete windowData;
- }
- }
- WindowData GetWindowData(BFWindow window)
- {
- WindowData windowData;
- mWindowDatas.TryGetValue(window, out windowData);
- if (windowData == null)
- {
- windowData = new WindowData();
- mWindowDatas[window] = windowData;
- }
- return windowData;
- }
- public DrawLayer GetOverlayLayer(BFWindow window)
- {
- WindowData windowData = GetWindowData(window);
- if (windowData.mOverlayLayer == null)
- windowData.mOverlayLayer = new DrawLayer(window);
- return windowData.mOverlayLayer;
- }
- void UpdateDrawTracking()
- {
- }
- public enum EvalResult
- {
- Normal,
- Pending
- }
- public EvalResult DebugEvaluate(String expectedType, String expr, String outVal, int cursorPos = -1, DebugManager.Language language = .NotSet, DebugManager.EvalExpressionFlags expressionFlags = .None, Action<String> pendingHandler = null)
- {
- defer
- {
- if (mPendingDebugExprHandler != pendingHandler)
- delete pendingHandler;
- }
- mIsImmediateDebugExprEval = false;
- String evalStr = scope String();
- evalStr.Append(expr);
- if (expectedType != null)
- {
- evalStr.Append(", expectedType=");
- evalStr.Append(expectedType);
- }
- if (mDebugger.IsPaused())
- {
- String curMethodOwner = scope String();
- int32 stackLanguage = 0;
- mDebugger.GetStackMethodOwner(mDebugger.mActiveCallStackIdx, curMethodOwner, out stackLanguage);
- if ((curMethodOwner.Length > 0) && (stackLanguage == 2) && (mWorkspace.mStartupProject != null)) // Beef only
- {
- String namespaceSearch = scope String();
- if (mBfResolveSystem != null)
- {
- mBfResolveSystem.Lock(2);
- BfProject startupProject = mBfResolveSystem.GetBfProject(mWorkspace.mStartupProject);
- mBfResolveSystem.GetNamespaceSearch(curMethodOwner, namespaceSearch, startupProject);
- mBfResolveSystem.Unlock();
- }
- if (!namespaceSearch.IsEmpty)
- {
- evalStr.Append(", namespaceSearch=\"");
- int namespaceIdx = 0;
- for (var namespaceEntry in namespaceSearch.Split('\n'))
- {
- if (namespaceIdx > 0)
- evalStr.Append(",");
- evalStr.Append(namespaceEntry);
- namespaceIdx++;
- }
- evalStr.Append("\"");
- }
- }
- }
- mDebugger.Evaluate(evalStr, outVal, cursorPos, (int)language, expressionFlags);
- if (outVal == "!pending")
- {
- Debug.Assert(mPendingDebugExprHandler == null);
- mPendingDebugExprHandler = pendingHandler;
- return .Pending;
- }
- return .Normal;
- }
- void DebuggerPaused()
- {
- mDebugger.mActiveCallStackIdx = 0;
- mExecutionPaused = true;
- mDebugger.GetRunState();
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.SetDisabled(false);
- });
- mMemoryPanel.SetDisabled(false);
- mCallStackPanel.SetDisabled(false);
- }
- void WithWatchPanels(delegate void(WatchPanel watchPanel) dlg)
- {
- dlg(mWatchPanel);
- dlg(mAutoWatchPanel);
- for (let window in mWindows)
- {
- if (let widgetWindow = window as WidgetWindow)
- {
- if (let quickWatch = widgetWindow.mRootWidget as QuickWatchDialog)
- {
- dlg(quickWatch.[Friend]mWatchPanel);
- }
- }
- }
- }
- void DebuggerUnpaused()
- {
- // Leave target in background for a bit, incase we immediately
- // hit another breakpoint
- mDebugger.mActiveCallStackIdx = 0;
- mForegroundTargetCountdown = 30;
- mExecutionPaused = false;
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.SetDisabled(true);
- });
- mMemoryPanel.SetDisabled(true);
- mCallStackPanel.SetDisabled(true);
- // If hoverwatch is up, we need to close it so we refresh the value
- var sourceViewPanel = GetActiveSourceViewPanel();
- if ((sourceViewPanel != null) && (sourceViewPanel.mHoverWatch != null))
- {
- sourceViewPanel.mHoverWatch.Close();
- }
- mDebuggerContinueIdx++;
- }
- public void StepIntoSpecific(int addr)
- {
- if (mExecutionPaused)
- {
- DebuggerUnpaused();
- mDebugger.StepIntoSpecific(addr);
- }
- }
- void FinishPendingHotResolve()
- {
- List<uint8> typeData = scope .();
- String stackListStr = scope .();
- if (!mDebugger.GetHotResolveData(typeData, stackListStr))
- return;
-
- mBfBuildCompiler.HotResolve_Start((mHotResolveState == .Pending) ? .None : .HadDataChanges);
- mHotResolveState = .None;
- for (int typeId < typeData.Count)
- {
- if (typeData[typeId] != 0)
- mBfBuildCompiler.HotResolve_ReportType(typeId, .Heap);
- }
- String stackStr = scope .();
- for (let stackStrView in stackListStr.Split('\n'))
- {
- stackStr.Set(stackStrView);
- if (stackStr.StartsWith("D "))
- {
- stackStr.Remove(0, 2);
- mBfBuildCompiler.HotResolve_AddDelegateMethod(stackStr);
- }
- else
- mBfBuildCompiler.HotResolve_AddActiveMethod(stackStr);
- }
- String hotResult = scope String();
- mBfBuildCompiler.HotResolve_Finish(hotResult);
- if (hotResult.IsEmpty)
- {
- //OutputLineSmart("Hot type data changes have been resolved");
- ProcessBeefCompileResults(null, false, mWorkspace.mStartupProject, null);
- }
- else
- {
- if (mHotResolveTryIdx == 0)
- {
- OutputLineSmart("ERROR: Hot type data changes cannot be applied because of the following types");
- for (var line in hotResult.Split('\n'))
- {
- OutputLineSmart(" {0}", line);
- }
- OutputLineSmart("Revert changes or put the program into a state where the type is not actively being used");
- var compileInstance = mWorkspace.mCompileInstanceList.Back;
- Debug.Assert(compileInstance.mCompileResult == .PendingHotLoad);
- compileInstance.mCompileResult = .Failure;
- }
- }
- if (mHotResolveState == .None)
- {
- var compileInstance = mWorkspace.mCompileInstanceList.Back;
- if (compileInstance.mCompileResult == .PendingHotLoad)
- compileInstance.mCompileResult = .Success;
- }
- }
- void QueueProjectItems(Project project)
- {
- project.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource != null)
- {
- if (projectSource.mIncludeKind == .Ignore)
- return;
- var resolveCompiler = GetProjectCompilerForFile(projectSource.mPath);
- if (resolveCompiler == mBfResolveCompiler)
- resolveCompiler.QueueProjectSource(projectSource);
- projectSource.mHasChangedSinceLastCompile = true;
- }
- });
- }
- void RemoveProjectItems(Project project)
- {
- project.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource != null)
- {
- var resolveCompiler = GetProjectCompilerForFile(projectSource.mPath);
- if (resolveCompiler == mBfResolveCompiler)
- resolveCompiler.QueueProjectSourceRemoved(projectSource);
- if (IsBeefFile(projectSource.mPath))
- {
- mBfBuildCompiler.QueueProjectSourceRemoved(projectSource);
- }
- }
- });
- }
- void UpdateCompilersAndDebugger()
- {
- scope AutoBeefPerf("UpdateCompilersAndDebugger");
- var msg = scope String();
- while (true)
- {
- DebugManager.RunState runState = .NotStarted;
- if (mDebugger != null)
- {
- mDebugger.Update();
- runState = mDebugger.GetRunState();
- mDebuggerPerformingTask = (runState == .DebugEval) || (runState == .DebugEval_Done) || (runState == .SearchingSymSrv);
- if (mDebugAutoRun)
- {
- if (runState == DebugManager.RunState.NotStarted)
- {
- mOutputPanel.Clear();
- if ((mExecutionQueue.Count == 0) && (!mDebugger.mIsRunning))
- {
- mTargetStartWithStep = true;
- var startDbgCmd = new StartDebugCmd();
- startDbgCmd.mWasCompiled = true;
- startDbgCmd.mOnlyIfNotFailed = true;
- mExecutionQueue.Add(startDbgCmd);
- }
- }
- else if (runState == DebugManager.RunState.Paused)
- {
- mDebugger.Continue();
- //mDebugger.Terminate();
- }
- }
- if ((mPendingDebugExprHandler != null) && (runState != .DebugEval) && (runState != .SearchingSymSrv))
- {
- var evalResult = scope String();
- mDebugger.EvaluateContinue(evalResult);
- if (evalResult != "!pending")
- {
- mPendingDebugExprHandler(evalResult);
- DeleteAndNullify!(mPendingDebugExprHandler);
- }
- }
- if (mHotResolveState != .None)
- {
- FinishPendingHotResolve();
- }
- }
- if (mDebugAutoBuild)
- {
- if ((!mBfBuildCompiler.HasQueuedCommands()) && (mExecutionInstances.Count == 0) && (mExecutionQueue.Count == 0))
- {
- OutputLine("Autobuilding...");
- CompileBeef(null, 0, mLastCompileSucceeded, let hadBeef);
- }
- }
- bool didClean = false;
- if (mWantsBeefClean)
- {
- if ((!mBfBuildCompiler.HasQueuedCommands()) &&
- ((mBfResolveCompiler == null) || (!mBfResolveCompiler.HasQueuedCommands())))
- {
- didClean = true;
- OutputLine("Cleaned Beef.");
- delete mBfResolveCompiler;
- delete mBfResolveSystem;
- delete mBfResolveHelper;
- delete mBfBuildCompiler;
- delete mBfBuildSystem;
-
- ///
- mDebugger.FullReportMemory();
- var workspaceBuildDir = scope String();
- GetWorkspaceBuildDir(workspaceBuildDir);
- if (Directory.Exists(workspaceBuildDir))
- {
- var result = Utils.DelTree(workspaceBuildDir, scope (fileName) =>
- {
- return fileName.EndsWith("build.dat");
- });
- if (result case .Err)
- {
- var str = scope String("Failed to delete folder: ", workspaceBuildDir);
- Fail(str);
- }
- }
- //ResolveConfigString(project, options, "$(TargetPath)", error, targetPath);
- if (!mNoResolve)
- {
- mBfResolveSystem = new BfSystem();
- mBfResolveCompiler = mBfResolveSystem.CreateCompiler(true);
- mBfResolveHelper = new BfResolveHelper();
- }
- mCompileSinceCleanCount = 0;
- mBfBuildSystem = new BfSystem();
- mBfBuildCompiler = mBfBuildSystem.CreateCompiler(false);
- mBfBuildCompiler.ClearBuildCache();
- /*foreach (var project in mWorkspace.mProjects)
- {
- mBfBuildSystem.AddProject(project);
- if (mBfResolveSystem != null)
- mBfResolveSystem.AddProject(project);
- }
-
- foreach (var project in mWorkspace.mProjects)
- {
- project.WithProjectItems(scope (projectItem) =>
- {
- var projectSource = projectItem as ProjectSource;
- if (projectSource != null)
- {
- var resolveCompiler = GetProjectCompilerForFile(projectSource.mPath);
- if (resolveCompiler == mBfResolveCompiler)
- resolveCompiler.QueueProjectSource(projectSource);
- }
- });
- }
- mBfResolveCompiler.QueueDeferredResolveAll();
- CurrentWorkspaceConfigChanged();*/
- mWantsBeefClean = false;
- }
- }
- if (mWantsClean)
- {
- if ((!mBfBuildCompiler.HasQueuedCommands()) && (!mBfResolveCompiler.HasQueuedCommands())
- #if IDE_C_SUPPORT
- && (!mDepClang.HasQueuedCommands()) && (!mResolveClang.HasQueuedCommands())
- #endif
- )
- {
- OutputLine("Cleaned.");
- let workspaceOptions = GetCurWorkspaceOptions();
- delete mBfResolveHelper;
- delete mBfResolveCompiler;
- delete mBfResolveSystem;
- #if IDE_C_SUPPORT
- delete mResolveClang;
- #endif
- delete mBfBuildCompiler;
- delete mBfBuildSystem;
- #if IDE_C_SUPPORT
- delete mDepClang;
- #endif
- //
- CreateBfSystems();
- mBfBuildCompiler.ClearBuildCache();
- var workspaceBuildDir = scope String();
- GetWorkspaceBuildDir(workspaceBuildDir);
- if (Directory.Exists(workspaceBuildDir))
- {
- var result = Utils.DelTree(workspaceBuildDir);
- if (result case .Err)
- {
- var str = scope String("Failed to delete folder: ", workspaceBuildDir);
- //result.Exception.ToString(str);
- Fail(str);
- //result.Dispose();
- }
- }
- List<String> deleteFails = scope .();
- for (var project in mWorkspace.mProjects)
- {
- // Force running the "if files changed" commands
- project.mForceCustomCommands = true;
- project.mNeedsTargetRebuild = true;
- // Don't delete custom build artifacts
- if (project.mGeneralOptions.mTargetType == .CustomBuild)
- continue;
- List<String> projectFiles = scope .();
- defer ClearAndDeleteItems(projectFiles);
- let options = GetCurProjectOptions(project);
- if (options == null)
- continue;
- GetTargetPaths(project, mPlatformName, workspaceOptions, options, projectFiles);
- for (let filePath in projectFiles)
- {
- if (File.Delete(filePath) case .Err(let errVal))
- {
- if (File.Exists(filePath))
- deleteFails.Add(new String(filePath));
- }
- }
- }
- if (!deleteFails.IsEmpty)
- {
- String str = scope String();
- if (deleteFails.Count == 1)
- str.AppendF("Failed to delete file: {0}", deleteFails[0]);
- else
- {
- str.Append("Failed to delete files:");
- for (let fileName in deleteFails)
- {
- str.Append("\n ", fileName);
- }
- }
- Fail(str);
- }
- ClearAndDeleteItems(deleteFails);
- didClean = true;
- mWantsClean = false;
- mDbgCompileIdx = -1;
- mDbgHighestTime = default;
- }
- }
- if (didClean)
- {
- for (var project in mWorkspace.mProjects)
- {
- mBfBuildSystem.AddProject(project);
- if (mBfResolveSystem != null)
- mBfResolveSystem.AddProject(project);
- }
- if (mBfResolveSystem != null)
- {
- PreConfigureBeefSystem(mBfResolveSystem, mBfResolveCompiler);
- for (var project in mWorkspace.mProjects)
- {
- SetupBeefProjectSettings(mBfResolveSystem, mBfResolveCompiler, project);
- }
- }
- if (mBfResolveSystem != null)
- {
- for (var project in mWorkspace.mProjects)
- {
- if (IsProjectEnabled(project))
- QueueProjectItems(project);
- }
- mBfResolveCompiler.QueueDeferredResolveAll();
- }
- CurrentWorkspaceConfigChanged();
- }
- mBfBuildSystem.Update();
- mBfBuildCompiler.Update();
- while (true)
- {
- #if CLI
- if (mCompilingBeef)
- break;
- #endif
- msg.Clear();
- if (!mBfBuildCompiler.PopMessage(msg))
- break;
- OutputLine(msg);
- }
- if (mBfResolveSystem != null)
- {
- mBfResolveSystem.Update();
- mBfResolveCompiler.Update();
- mBfResolveCompiler.ClearMessages();
- mBfResolveHelper.Update();
- }
- #if IDE_C_SUPPORT
- mDepClang.Update();
- if ((!IsCompiling) && (!mDepClang.IsPerformingBackgroundOperation()))
- {
- // Only leave mCompileWaitsForQueueEmpty false for a fast initial build
- mDepClang.mCompileWaitsForQueueEmpty = true;
- }
- while (true)
- {
- msg.Clear();
- if (!mDepClang.PopMessage(msg))
- break;
- OutputLine(msg);
- }
- mResolveClang.Update();
- mResolveClang.ClearMessages();
- #endif
- bool wantDebuggerDetach = false;
- if ((mDebugger != null) && (runState == DebugManager.RunState.Terminated))
- {
- wantDebuggerDetach = true;
- }
- String deferredMsgType = scope String();
- String deferredOutput = scope String();
- bool hadMessages = false;
- while (mDebugger != null)
- {
- msg.Clear();
- if (!mDebugger.PopMessage(msg))
- {
- break;
- }
- hadMessages = true;
- int paramIdx = msg.IndexOf(' ');
- String cmd = scope String();
- String param = scope String();
- if (paramIdx > 0)
- {
- cmd.Append(msg, 0, paramIdx);
- param.Append(msg, paramIdx + 1);
- }
- else
- cmd.Append(msg);
- bool isOutput = (cmd == "msg") || (cmd == "dbgEvalMsg") || (cmd == "log");
- if (cmd == "msgLo")
- {
- if (mVerbosity < .Diagnostic)
- continue;
- isOutput = true;
- }
- if (isOutput)
- {
- if (deferredMsgType != cmd)
- {
- if (deferredOutput.Length > 0)
- {
- OutputFormatted(deferredOutput, deferredMsgType == "dbgEvalMsg");
- deferredOutput.Clear();
- }
- deferredMsgType.Set(cmd);
- }
-
- deferredOutput.Append(param);
- }
- else if (cmd == "error")
- {
- if ((mRunningTestScript) && (!IsCrashDump) && (!mScriptManager.IsErrorExpected(param)))
- mScriptManager.Fail(param);
- bool isFirstMsg = true;
- String tempStr = scope String();
- bool focusOutput = false;
- while (true)
- {
- String errorMsg = null;
- int infoPos = param.IndexOf("\x01");
- if (infoPos == 0)
- {
- Widget addWidget = null;
- LeakWidget leakWidget = null;
- int endPos = param.IndexOf("\n");
- if (endPos == -1)
- break;
- String leakStr = scope String(param, 1, endPos - 1);
- param.Remove(0, endPos + 1);
- int itemIdx = 0;
- for (var itemView in leakStr.Split('\t'))
- {
- var item = scope String(itemView);
- if (itemIdx == 0)
- {
- if (item == "LEAK")
- {
- focusOutput = true;
- leakWidget = new LeakWidget(mOutputPanel);
- leakWidget.Resize(0, GS!(-2), DarkTheme.sUnitSize, DarkTheme.sUnitSize);
- addWidget = leakWidget;
- }
- else if (item == "TEXT")
- {
- OutputLine(scope String(leakStr, @itemView.MatchPos + 1));
- break;
- }
- else
- break;
- }
- else if (itemIdx == 1)
- {
- leakWidget.mExpr = new String(item);
- }
- else
- {
- //leakWidget.mStackAddrs.Add()
- }
- itemIdx++;
- }
- if (addWidget != null)
- mOutputPanel.AddInlineWidget(addWidget);
- }
- else if (infoPos != -1)
- {
- tempStr.Clear();
- tempStr.Append(param, 0, infoPos);
- errorMsg = tempStr;
- param.Remove(0, infoPos);
- }
- else
- errorMsg = param;
- if (errorMsg != null)
- {
- if (isFirstMsg)
- {
- OutputLineSmart(scope String("ERROR: ", errorMsg));
- if (gApp.mRunningTestScript)
- {
- // The 'OutputLineSmart' would already call 'Fail' when running test scripts
- }
- else
- {
- Fail(errorMsg);
- }
- isFirstMsg = false;
- }
- else
- Output(errorMsg);
- }
- if (infoPos == -1)
- break;
- }
- if (focusOutput)
- ShowOutput();
- }
- else if (cmd == "memoryBreak")
- {
- Breakpoint breakpoint = null;
- int memoryAddress = (int)int64.Parse(param, System.Globalization.NumberStyles.HexNumber);
- for (var checkBreakpoint in mDebugger.mBreakpointList)
- {
- if (checkBreakpoint.mMemoryAddress == memoryAddress)
- breakpoint = checkBreakpoint;
- }
- String infoString = StackStringFormat!("Memory breakpoint hit: '0x{0:X08}'", (int64)memoryAddress);
- if (breakpoint != null)
- infoString = StackStringFormat!("Memory breakpoint hit: '0x{0:X08}' ({1})", (int64)memoryAddress, breakpoint.mMemoryWatchExpression);
- OutputLine(infoString);
- if (!mRunningTestScript)
- {
- MessageDialog("Breakpoint Hit", infoString);
- Beep(MessageBeepType.Information);
- }
- }
- else if (cmd == "newProfiler")
- {
- var profiler = mDebugger.PopProfiler();
- //ShowProfilePanel();
- mProfilePanel.Add(profiler);
- }
- else if (cmd == "showProfiler")
- {
- ShowProfilePanel();
- }
- else if (cmd == "clearOutput")
- {
- mOutputPanel.Clear();
- }
- else if (cmd == "dbgInfoLoaded")
- {
- //Debug.WriteLine("dbgInfoLoaded {0}", param);
- mWantsRehupCallstack = true;
- }
- else if (cmd == "rehupLoc")
- {
- mWantsRehupCallstack = true;
- }
- else if (cmd == "modulesChanged")
- {
- mModulePanel.ModulesChanged();
- }
- else if (cmd == "symsrv")
- {
- mSymSrvStatus.Set(param);
- }
- else
- {
- Runtime.FatalError("Invalid debugger message type");
- }
- }
- if (deferredOutput.Length > 0)
- {
- OutputFormatted(deferredOutput, deferredMsgType == "dbgEvalMsg");
- }
- /*if (hadMessages)
- mNoDebugMessagesTick = 0;
- else if (IDEApp.sApp.mIsUpdateBatchStart)
- mNoDebugMessagesTick++;
- if (mNoDebugMessagesTick < 10)
- wantDebuggerDetach = false; // Don't detach if we have messages*/
-
- if (wantDebuggerDetach)
- {
- OutputLine("Detached debugger");
- UpdateTitle();
- var disassemblyPanel = TryGetDisassemblyPanel(false);
- if (disassemblyPanel != null)
- disassemblyPanel.Disable();
- mDebugger.DisposeNativeBreakpoints();
- mDebugger.Detach();
- mDebugger.mIsRunning = false;
- mExecutionPaused = false;
- mHotResolveState = .None;
- mDebuggerPerformingTask = false;
- mWorkspace.StoppedRunning();
- mBreakpointPanel.BreakpointsChanged();
- mModulePanel.ModulesChanged();
- if (mPendingDebugExprHandler != null)
- {
- mPendingDebugExprHandler(null);
- DeleteAndNullify!(mPendingDebugExprHandler);
- }
- mMemoryPanel.SetDisabled(true);
- WithWatchPanels(scope (watchPanel) =>
- {
- watchPanel.SetDisabled(true);
- });
- mIsAttachPendingSourceShow = false;
- }
- if ((mDebugger != null) && (mDebugger.IsPaused()) && (!mDebugger.HasPendingDebugLoads()))
- {
- mForegroundTargetCountdown = 0;
- if (!mExecutionPaused)
- {
- if (!mTargetDidInitBreak)
- {
- mTargetDidInitBreak = true;
- bool wantsContinue = true;
- if (mTargetStartWithStep)
- {
- if ((mMainBreakpoint != null) && (!mMainBreakpoint.IsBound()))
- {
- BfLog.LogDbg("Deleting mMainBreakpoint 1\n");
- // Couldn't bind to main breakpoint, bind to entry point address
- // "." is the magic symbol for "entry point"
- String[] tryNames = scope .("WinMain", ".");
- for (let name in tryNames)
- {
- mDebugger.DeleteBreakpoint(mMainBreakpoint);
- mMainBreakpoint = mDebugger.CreateSymbolBreakpoint("WinMain");
- if ((name == ".") || (mMainBreakpoint.IsBound()))
- break;
- }
- }
- wantsContinue = true;
- }
- else
- {
- if (mMainBreakpoint != null)
- {
- if (mMainBreakpoint.IsActiveBreakpoint())
- wantsContinue = true;
- BfLog.LogDbg("Deleting mMainBreakpoint 2\n");
- mDebugger.DeleteBreakpoint(mMainBreakpoint);
- //mMainBreakpoint.Dispose();
- mMainBreakpoint = null;
- }
- }
- if (wantsContinue)
- {
- DebuggerUnpaused();
- mDebugger.Continue();
- }
- }
- else
- {
- if (mMainBreakpoint != null)
- {
- BfLog.LogDbg("Deleting mMainBreakpoint 3\n");
- mDebugger.DeleteBreakpoint(mMainBreakpoint);
- mMainBreakpoint = null;
- int addr;
- String fileName = null;
- mDebugger.UpdateCallStack();
- var stackInfo = scope String();
- mDebugger.GetStackFrameInfo(0, out addr, fileName, stackInfo);
- if (stackInfo.Contains("Main"))
- {
- // Okay, NOW we can do a "step into"
- if (!IsInDisassemblyMode())
- mDebugger.StepInto(false);
- return;
- }
- }
- if ((!HasModalDialogs()) && (!mRunningTestScript))
- mMainWindow.SetForeground();
- if (mRunTimingProfileId != 0)
- {
- mRunTimingProfileId.Dispose();
- mRunTimingProfileId = 0;
- }
- BeefPerf.Event("Debugger Paused", "");
- DebuggerPaused();
- PCChanged();
- mBreakpointPanel.MarkStatsDirty();
- mTargetHadFirstBreak = true;
- if (mDebugger.GetRunState() == DebugManager.RunState.Exception)
- {
- String exceptionLine = scope String();
- mDebugger.GetCurrentException(exceptionLine);
- var exceptionData = String.StackSplit!(exceptionLine, '\n');
- String exHeader = StackStringFormat!("Exception {0}", exceptionData[1]);
- if (exceptionData.Count >= 3)
- exHeader = exceptionData[2];
- String exString = StackStringFormat!("{0} at {1}", exHeader, exceptionData[0]);
- OutputLine(exString);
- if (!IsCrashDump)
- Fail(exString);
- }
- }
- }
- break;
- }
- else if (mDebuggerPerformingTask)
- {
- break;
- }
- else
- {
- if (mForegroundTargetCountdown > 0)
- {
- if ((--mForegroundTargetCountdown == 0) && (mDebugger.mIsRunning))
- mDebugger.ForegroundTarget();
- }
- if ((mDebugger != null) && (mExecutionPaused) && (mDebugger.mIsRunning))
- DebuggerUnpaused();
- break;
- }
- }
- if ((mDebugger != null) && ((mDebugger.IsPaused()) || (!mDebugger.mIsRunning)) && (!IsCompiling))
- {
- if (mDebugger.mRunToCursorBreakpoint != null)
- {
- BfLog.LogDbg("Stopped. Clearing mRunToCursorBreakpoint\n");
- mDebugger.DeleteBreakpoint(mDebugger.mRunToCursorBreakpoint);
- mDebugger.mRunToCursorBreakpoint = null;
- }
- }
- if ((mDebugger != null) && (mExecutionPaused) && (mDebugger.IsPaused()))
- {
- if (mWantsRehupCallstack)
- {
- mDebugger.RehupCallstack();
- if (var deferredShowPCRequest = mDeferredUserRequest as DeferredShowPCLocation)
- {
- //Debug.WriteLine("Had DeferredShowPCLocation");
- var stackIdx = deferredShowPCRequest.mStackIdx;
- IDEApp.sApp.mDebugger.mActiveCallStackIdx = stackIdx;
- ClearDeferredUserRequest();
- ShowPCLocation(stackIdx, false, true);
- StackPositionChanged();
- }
- mCallStackPanel.MarkCallStackDirty();
- mThreadPanel.MarkThreadsDirty();
- mModulePanel.ModulesChanged();
- mWantsRehupCallstack = false;
- }
- }
- if (mBuildContext != null)
- {
- mBuildContext.mUpdateCnt++;
- bool isCompiling = (!mExecutionInstances.IsEmpty) || (!mExecutionQueue.IsEmpty);
- if (mBuildContext.mScriptManager != null)
- {
- mBuildContext.mScriptManager.Update();
- if ((mBuildContext.mScriptManager.HasQueuedCommands) && (!mBuildContext.mScriptManager.mFailed))
- isCompiling = true;
- }
- if (!isCompiling)
- {
- DeleteAndNullify!(mBuildContext);
- }
- }
- }
- public void ShowPassOutput(BfPassInstance bfPassInstance)
- {
- while (true)
- {
- var outString = scope String();
- if (!bfPassInstance.PopOutString(outString))
- break;
- OutputLine(outString);
- }
- }
- /*public bool CheckMouseover(Widget checkWidget, int32 wantTicks, out Point mousePoint)
- {
- mousePoint = Point(Int32.MinValue, Int32.MinValue);
- if (checkWidget != mLastMouseWidget)
- return false;
- checkWidget.RootToSelfTranslate(mLastRelMousePos.x, mLastRelMousePos.y, out mousePoint.x, out mousePoint.y);
- return mMouseStillTicks == wantTicks;
- }
- void LastMouseWidgetDeleted(Widget widget)
- {
- if (mLastMouseWidget == widget)
- mLastMouseWidget = null;
- }
- void SetLastMouseWidget(Widget newWidget)
- {
- if (mLastMouseWidget != null)
- mLastMouseWidget.mDeletedHandler.Remove(scope => LastMouseWidgetDeleted, true);
- mLastMouseWidget = newWidget;
- if (mLastMouseWidget != null)
- mLastMouseWidget.mDeletedHandler.Add(new => LastMouseWidgetDeleted);
- }
- void UpdateMouseover()
- {
- if (mMouseStillTicks != -1)
- mMouseStillTicks++;
- Widget overWidget = null;
- int32 numOverWidgets = 0;
- foreach (var window in mWindows)
- {
- var widgetWindow = window as WidgetWindow;
-
- widgetWindow.RehupMouse(false);
- var windowOverWidget = widgetWindow.mCaptureWidget ?? widgetWindow.mOverWidget;
- if ((windowOverWidget != null) && (widgetWindow.mAlpha == 1.0f) && (widgetWindow.mCaptureWidget == null))
- {
- overWidget = windowOverWidget;
- numOverWidgets++;
- if (overWidget != mLastMouseWidget)
- {
- SetLastMouseWidget(overWidget);
- mMouseStillTicks = -1;
- }
- float actualX = widgetWindow.mClientX + widgetWindow.mMouseX;
- float actualY = widgetWindow.mClientY + widgetWindow.mMouseY;
- if ((mLastAbsMousePos.x != actualX) || (mLastAbsMousePos.y != actualY))
- {
- mMouseStillTicks = 0;
- mLastAbsMousePos.x = actualX;
- mLastAbsMousePos.y = actualY;
- }
- mLastRelMousePos.x = widgetWindow.mMouseX;
- mLastRelMousePos.y = widgetWindow.mMouseY;
- }
- }
- if (overWidget == null)
- {
- SetLastMouseWidget(null);
- mMouseStillTicks = -1;
- }
- if (numOverWidgets > 1)
- {
- //int a = 0;
- }
- Debug.Assert(numOverWidgets <= 1);
- }*/
- public void FileRenamed(ProjectFileItem projectFileItem, String oldPath, String newPath)
- {
- String newFileName = scope String();
- Path.GetFileName(newPath, newFileName);
- RenameEditData(oldPath, newPath);
- WithTabs(scope (tab) =>
- {
- var sourceViewPanel = tab.mContent as SourceViewPanel;
- if (sourceViewPanel != null)
- {
- if (Path.Equals(sourceViewPanel.mFilePath, oldPath))
- {
- var sourceViewTab = (IDEApp.SourceViewTab)tab;
- //TODO: We might have to resize the label here?
- //sourceViewPanel.mFilePath.Set(newPath);
- sourceViewPanel.PathChanged(newPath);
- tab.Label = newFileName;
- tab.mWantWidth = sourceViewTab.GetWantWidth();
- //tab.mTabbedView.Resize();
- }
- }
- });
- var recentFileList = mRecentlyDisplayedFiles;
- for (int32 recentFileIdx = 0; recentFileIdx < recentFileList.Count; recentFileIdx++)
- {
- if (recentFileList[recentFileIdx] == oldPath)
- recentFileList[recentFileIdx].Set(newPath);
- }
- UpdateRecentDisplayedFilesMenuItems();
- if (IsBeefFile(newPath) != IsBeefFile(oldPath))
- {
- if ((var projectSource = projectFileItem as ProjectSource) && (IsProjectSourceEnabled(projectSource)))
- {
- if (IsBeefFile(newPath))
- {
- mBfResolveCompiler.QueueProjectSource(projectSource);
- mBfBuildCompiler.QueueProjectSource(projectSource);
- }
- else
- {
- mBfResolveCompiler.QueueProjectSourceRemoved(projectSource);
- mBfBuildCompiler.QueueProjectSourceRemoved(projectSource);
- }
- mBfResolveCompiler.QueueDeferredResolveAll();
- mBfResolveCompiler.QueueRefreshViewCommand();
- }
- }
- }
- public void OnWatchedFileChanged(ProjectItem projectItem, WatcherChangeTypes changeType, String newPath)
- {
- ProjectListViewItem listViewItem;
- mProjectPanel.mProjectToListViewMap.TryGetValue(projectItem, out listViewItem);
- String newName = null;
- if (newPath != null)
- {
- newName = scope ::String();
- Path.GetFileName(newPath, newName);
- }
- if (changeType == .Renamed)
- {
- if (projectItem.mIncludeKind == .Auto)
- {
- let projectFileItem = projectItem as ProjectFileItem;
- listViewItem.Label = newName;
- String oldPath = scope String();
- projectFileItem.GetFullImportPath(oldPath);
- projectFileItem.Rename(newName);
- FileRenamed(projectFileItem, oldPath, newPath);
- mProjectPanel.SortItem((ProjectListViewItem)listViewItem.mParentItem);
- }
- }
- else if (changeType == .Deleted)
- {
- if (projectItem.mIncludeKind == .Auto)
- {
- mProjectPanel.DoDeleteItem(listViewItem, null, true);
- }
- }
- else if (changeType == .FileCreated)
- {
- let projectFolder = projectItem as ProjectFolder;
- if (projectFolder.IsAutoInclude())
- {
- if (!projectFolder.mChildMap.ContainsKey(newName))
- {
- let projectSource = new ProjectSource();
- Path.GetFileName(newPath, projectSource.mName);
- projectSource.mPath = new String(projectFolder.mPath);
- projectSource.mPath.Append(Path.DirectorySeparatorChar);
- projectSource.mPath.Append(projectSource.mName);
- projectSource.mProject = projectFolder.mProject;
- projectSource.mParentFolder = projectFolder;
- projectFolder.AddChild(projectSource);
- projectFolder.MarkAsUnsorted();
- mProjectPanel.AddProjectItem(projectSource);
- mProjectPanel.QueueSortItem(listViewItem);
- }
- }
- }
- else if (changeType == .DirectoryCreated)
- {
- let projectFolder = projectItem as ProjectFolder;
- if (projectFolder.IsAutoInclude())
- {
- if (!projectFolder.mChildMap.ContainsKey(newName))
- {
- let newFolder = new ProjectFolder();
- Path.GetFileName(newPath, newFolder.mName);
- newFolder.mPath = new String(projectFolder.mPath);
- newFolder.mPath.Append(Path.DirectorySeparatorChar);
- newFolder.mPath.Append(newFolder.mName);
- newFolder.mProject = projectFolder.mProject;
- newFolder.mParentFolder = projectFolder;
- projectFolder.AddChild(newFolder);
- projectFolder.MarkAsUnsorted();
- mProjectPanel.AddProjectItem(newFolder);
- mProjectPanel.QueueSortItem(listViewItem);
- newFolder.mAutoInclude = true;
- mProjectPanel.QueueRehupFolder(newFolder);
- }
- }
- }
- else if (changeType == .Failed)
- {
- if (let projectFolder = projectItem as ProjectFolder)
- mProjectPanel.QueueRehupFolder(projectFolder);
- }
- }
- void UpdateWorkspace()
- {
- mFileWatcher.Update();
- bool appHasFocus = false;
- for (var window in mWindows)
- appHasFocus |= window.mHasFocus;
- if (mRunningTestScript)
- appHasFocus = true;
- // Is this enough to get the behavior we want?
- if (!appHasFocus)
- return;
- if (mLastFileChangeId != mFileWatcher.mChangeId)
- {
- if ((mFileChangedDialog != null) && (!mFileChangedDialog.mClosed))
- {
- mFileChangedDialog.Rehup();
- }
- mLastFileChangeId = mFileWatcher.mChangeId;
- }
- var app = gApp;
- Debug.Assert(app != null);
- while (true)
- {
- var dep = mFileWatcher.PopChangedDependency();
- if (dep == null)
- break;
- var projectSourceDep = dep as ProjectSource;
- if (projectSourceDep != null)
- {
- // We process these projectSources directly from the filename below
- }
- }
- while (/*(appHasFocus) && */((mFileChangedDialog == null) || (mFileChangedDialog.mClosed)))
- {
- while (mExternalChangeDeferredOpen.Count > 0)
- {
- String filePath = mExternalChangeDeferredOpen.PopFront();
- ShowSourceFile(filePath);
- delete filePath;
- }
- var changedFile = mFileWatcher.PopChangedFile();
- if (changedFile == null)
- {
- if (mFileChangedDialog != null)
- mFileChangedDialog = null;
- break;
- }
- String fileName = changedFile.mPath;
- defer
- {
- delete changedFile;
- }
- #if IDE_C_SUPPORT
- if ((IsClangSourceFile(fileName)) || (IsClangSourceHeader(fileName)))
- {
- mDepClang.mDoDependencyCheck = true;
- }
- #endif
- FileChanged(fileName);
- var editData = GetEditData(fileName, false, false);
- if (editData == null)
- continue;
- //TODO: Check to see if this file is in the dependency list of the executing project
- if (!editData.mProjectSources.IsEmpty)
- mHaveSourcesChangedExternallySinceLastCompile = true;
- editData.SetSavedData(null, IdSpan());
- if (editData.mQueuedContent == null)
- editData.mQueuedContent = new String();
- editData.mQueuedContent.Clear();
- if (LoadTextFile(fileName, editData.mQueuedContent, false, scope() =>
- {
- if (editData.mLoadedHash.GetKind() != .None)
- {
- editData.mLoadedHash = SourceHash.Create(editData.mLoadedHash.GetKind(), editData.mQueuedContent);
- }
- }) case .Err(let err))
- {
- if (err case .FileOpenError(.SharingViolation))
- {
- // Put back on the list and try later
- mFileWatcher.AddChangedFile(changedFile);
- changedFile = null;
- break;
- }
- editData.mFileDeleted = true;
- }
- using (mMonitor.Enter())
- {
- for (var projectSource in editData.mProjectSources)
- {
- projectSource.HasChangedSinceLastCompile = true;
- }
- }
- var sourceViewPanel = FindSourceViewPanel(fileName);
- if (sourceViewPanel != null)
- {
- FileChangedDialog.DialogKind dialogKind = File.Exists(fileName) ? .Changed : .Deleted;
- if ((sourceViewPanel.mEditData != null) && (sourceViewPanel.mEditData.mFileDeleted))
- sourceViewPanel.mEditData.IsFileDeleted(); // Rehup
- if ((sourceViewPanel.HasUnsavedChanges()) || (dialogKind == .Deleted))
- {
- if ((mFileChangedDialog != null) && (mFileChangedDialog.mApplyAllResult[(int)dialogKind].HasValue))
- {
- bool closeAll = mFileChangedDialog.mApplyAllResult[(int)dialogKind].Value;
- if (closeAll)
- gApp.CloseDocument(sourceViewPanel);
- continue;
- }
- else
- {
- mFileChangedDialog = new FileChangedDialog();
- mFileChangedDialog.Show(sourceViewPanel);
- }
- break;
- }
- else
- {
- sourceViewPanel.Reload();
- //FileChanged(fileName);
- }
- }
- else
- {
- editData.Reload();
- FileChanged(editData);
- }
- }
- if (mWorkspace.IsSingleFileWorkspace)
- {
- if (mWorkspace.mCompositeFile.HasPendingSave)
- mWorkspace.mCompositeFile.Save();
- }
- }
- public void FileChanged(String path)
- {
- OpenFileInSolutionDialog.ClearWriteTime(path);
- }
- public void FileChanged(FileEditData editData)
- {
- if (!IsBeefFile(editData.mFilePath))
- return;
- using (mMonitor.Enter())
- {
- for (var projectSource in editData.mProjectSources)
- {
- if (mBfResolveCompiler != null)
- {
- mBfResolveCompiler.QueueProjectSource(projectSource);
- mBfResolveCompiler.QueueDeferredResolveAll();
- mBfResolveCompiler.QueueRefreshViewCommand();
- }
- }
- }
- }
- #if !CLI
- void UpdateIPC()
- {
- bool hasFocus = false;
- for (var window in mWindows)
- {
- if (window.mHasFocus)
- hasFocus = true;
- }
- bool gotFocus = hasFocus && !mIPCHadFocus;
- mIPCHadFocus = hasFocus;
- //hasFocus = true;
- if (gotFocus)
- {
- // Keep trying to create IPCHelper until we finally succeed
- if (mIPCHelper == null)
- {
- mIPCHelper = new IPCHelper();
- if (!mIPCHelper.Init("BF_IDE"))
- DeleteAndNullify!(mIPCHelper);
- else
- {
- #if !DEBUG
- OutputLine("IPC: Hosting");//
- #endif
- }
- }
- }
- if (mIPCHelper != null)
- {
- mIPCHelper.Update();
- var message = mIPCHelper.PopMessage();
- if (message != null)
- {
- defer delete message;
- var msgParts = String.StackSplit!(message, '|');
- if (msgParts.Count >= 0)
- {
- String cmd = scope String(msgParts[0]);
- if (cmd == "ShowFile")
- {
- // These loads any file changes before we try to do a goto
- mMainWindow.SetForeground();
- UpdateWorkspace();
- String fileName = scope String(msgParts[1]);
- int32 lineNum = int32.Parse(scope String(msgParts[2])).GetValueOrDefault();
- var sourceViewPanel = ShowSourceFileLocation(fileName, -1, IDEApp.sApp.mWorkspace.GetHighestCompileIdx(), lineNum - 1, 0, LocatorType.Always, false);
- if (sourceViewPanel != null)
- sourceViewPanel.mWidgetWindow.SetForeground();
- }
- else if (cmd == "StopIPC")
- {
- #if !DEBUG
- OutputLine("IPC: Stopping");
- #endif
- delete mIPCHelper;
- mIPCHelper = null;
- }
- }
- }
- }
- }
- #endif
- void DoLongUpdateCheck()
- {
- uint32 timeNow = Utils.GetTickCount();
- if (mLastLongUpdateCheck != 0)
- {
- int ticksDiff = (int32)(timeNow - mLastLongUpdateCheck);
- if (ticksDiff > 200)
- {
- int lastErrTicks = (int32)(timeNow - mLastLongUpdateCheckError);
- if (lastErrTicks > 2000)
- {
- // Show this profile!
- mLongUpdateProfileId.Dispose();
- mLongUpdateProfileId = Profiler.StartSampling("LongUpdate");
- mLastLongUpdateCheckError = timeNow;
- }
- }
- }
- Profiler.ClearSampling();
- mLastLongUpdateCheck = Utils.GetTickCount();
- }
- public void SetDeferredUserRequest(DeferredUserRequest deferredUserRequest)
- {
- //Debug.WriteLine("SetDeferredUserRequest");
- delete mDeferredUserRequest;
- mDeferredUserRequest = deferredUserRequest;
- }
- public void ClearDeferredUserRequest()
- {
- //Debug.WriteLine("ClearDeferredUserRequest");
- DeleteAndNullify!(mDeferredUserRequest);
- }
- void UpdateDeferredOpens()
- {
- void DoDeferredOpen(DeferredOpenKind openKind)
- {
- switch (openKind)
- {
- case .NewWorkspaceOrProject:
- var dialog = ThemeFactory.mDefault.CreateDialog("Create Workspace?",
- "Do you want to create an empty workspace or a new project?");
- dialog.AddButton("Empty Workspace", new (evt) =>
- {
- mDeferredOpen = .NewWorkspace;
- });
- dialog.AddButton("New Project", new (evt) =>
- {
- CloseWorkspace();
- FinishShowingNewWorkspace();
- Cmd_NewProject();
- });
- dialog.PopupWindow(GetActiveWindow());
- case .NewWorkspace:
- if (mDeferredOpenFileName != null)
- {
- let directoryPath = scope String();
- Path.GetDirectoryPath(mDeferredOpenFileName, directoryPath);
- if (File.Exists(mDeferredOpenFileName))
- {
- var dialog = ThemeFactory.mDefault.CreateDialog("Already Exists",
- scope String()..AppendF("A Beef workspace already exists at '{}'. Do you want to open it?", directoryPath),
- DarkTheme.sDarkTheme.mIconWarning);
- dialog.mDefaultButton = dialog.AddButton("Yes", new (evt) =>
- {
- DoOpenWorkspace();
- });
- dialog.AddButton("No", new (evt) =>
- {
- DeleteAndNullify!(mDeferredOpenFileName);
- });
- dialog.PopupWindow(GetActiveWindow());
- return;
- }
- else if (!IDEUtils.IsDirectoryEmpty(directoryPath))
- {
- var dialog = ThemeFactory.mDefault.CreateDialog("Already Exists",
- scope String()..AppendF("A non-empty directory already exists at '{}'. Are you sure you want to create a workspace there?", directoryPath),
- DarkTheme.sDarkTheme.mIconWarning);
- dialog.mDefaultButton = dialog.AddButton("Yes", new (evt) =>
- {
- DoOpenWorkspace();
- });
- dialog.AddButton("No", new (evt) =>
- {
- DeleteAndNullify!(mDeferredOpenFileName);
- });
- dialog.PopupWindow(GetActiveWindow());
- return;
- }
- }
- DoOpenWorkspace();
- if (mDeferredOpen != .None)
- mDeferredOpen = _;
- case .Workspace:
- DoOpenWorkspace();
- case .CrashDump:
- DoOpenCrashDump();
- default:
- }
- }
- var deferredOpen = mDeferredOpen;
- mDeferredOpen = .None;
- switch (deferredOpen)
- {
- case .File:
- DoOpenFile();
- case .CrashDump:
- DoOpenCrashDump();
- case .Workspace, .NewWorkspace, .NewWorkspaceOrProject:
- if ((mDeferredOpenFileName == null) && (deferredOpen == .Workspace))
- {
- DoDeferredOpen(_);
- break;
- }
- if (CheckCloseWorkspace(mMainWindow,
- new () =>
- {
- DoDeferredOpen(_);
- },
- new () =>
- {
- DoDeferredOpen(_);
- },
- new () =>
- {
- DeleteAndNullify!(mDeferredOpenFileName);
- }
- ))
- {
- DoDeferredOpen(_);
- }
- case .DebugSession:
- DoOpenDebugSession();
- default:
- }
- }
- public override void Update(bool batchStart)
- {
- scope AutoBeefPerf("IDEApp.Update");
- /*using (mWorkspace.mMonitor.Enter())
- {
- }*/
- if (mDbgFastUpdate)
- {
- RefreshRate = 240;
- MarkDirty();
- }
- else
- {
- RefreshRate = 60;
- }
- bool hasFocus = false;
- for (let window in mWindows)
- {
- hasFocus |= window.mHasFocus;
- }
- if (mEnableGCCollect)
- {
- /*if (hasFocus)
- GC.SetAutoCollectPeriod(10);
- else
- GC.SetAutoCollectPeriod(2000);*/
- }
- while (!mDeferredFails.IsEmpty)
- {
- var error = mDeferredFails.PopFront();
- Fail(error);
- delete error;
- }
- if (mStopping)
- return;
- if (batchStart)
- {
- //BFApp_CheckMemory();
- }
- #if !CLI
- if (mSettings.mEnableDevMode)
- UpdateIPC();
- #endif
- if (mRunTest)
- {
- if (mRunTestDelay > 0)
- {
- mRunTestDelay--;
- }
- else if (IsCompiling)
- {
- }
- else if (mDebugger.mIsRunning)
- {
- mDebugger.Terminate();
- mRunTestDelay = 30;
- }
- else
- {
- mTargetStartWithStep = false;
- CompileAndRun();
- mRunTestDelay = 200;
- }
- }
- if (mProfilePanel != null)
- mProfilePanel.ForcedUpdate();
- if (mLongUpdateProfileId != 0)
- DoLongUpdateCheck();
- if (mWakaTime != null)
- mWakaTime.Update();
- if (mFindResultsPanel != null)
- mFindResultsPanel.Update();
- if (mBfResolveSystem != null)
- mBfResolveSystem.PerfZoneStart("IDEApp.Update");
- UpdateWorkspace();
- if (ThemeFactory.mDefault != null)
- ThemeFactory.mDefault.Update();
- base.Update(batchStart);
- DarkTooltipManager.UpdateTooltip();
- mGlobalUndoManager.Update();
-
- for (var project in mWorkspace.mProjects)
- project.Update();
- UpdateCompilersAndDebugger();
- if (mScriptManager != null)
- mScriptManager.Update();
- if (mTestManager != null)
- {
- mTestManager.Update();
- if (mTestManager.mIsDone)
- {
- if (mMainFrame != null)
- mMainFrame.mStatusBar.SelectConfig(mTestManager.mPrevConfigName);
- DeleteAndNullify!(mTestManager);
- }
- }
-
- UpdateExecution();
- if (mBfResolveSystem != null)
- mBfResolveSystem.PerfZoneEnd();
- UpdateDeferredOpens();
- mHaveSourcesChangedInternallySinceLastCompile = false;
- WithSourceViewPanels(scope (sourceViewPanel) =>
- {
- mHaveSourcesChangedInternallySinceLastCompile |= sourceViewPanel.mHasChangedSinceLastCompile;
- });
- if ((mCloseDelay > 0) && (--mCloseDelay == 0))
- mMainWindow.Close();
- ProcessIdleDeferredDeletes();
- /*if ((mUpdateCnt % (60 * 3) == 0) && (mEnableGCCollect))
- {
- scope AutoBeefPerf("GC.Collect");
- GC.Collect();
- }*/
- if (mDebugAutoShutdownCounter > 0)
- {
- if (--mDebugAutoShutdownCounter == 0)
- Stop();
- }
- if ((mRunningTestScript) && (!IsCompiling) && (!AreTestsRunning()))
- {
- if ((mFailed) || (!mScriptManager.HasQueuedCommands))
- {
- if (++mScriptManager.mDoneTicks >= 2)
- {
- OutputLine("Total script time: {0}ms", mScriptManager.mTimeoutStopwatch.ElapsedMilliseconds);
- if (mExitWhenTestScriptDone)
- Stop();
- else
- mRunningTestScript = false;
- }
- }
- }
- for (var sourceViewPanel in mPostRemoveUpdatePanels)
- {
- if (sourceViewPanel.NeedsPostRemoveUpdate)
- {
- sourceViewPanel.Update();
- }
- else
- {
- //Debug.WriteLine("Removing sourceViewPanel from mPostRemoveUpdatePanel {0} from IDEApp.Update", sourceViewPanel);
- sourceViewPanel.[Friend]mInPostRemoveUpdatePanels = false;
- @sourceViewPanel.Remove();
- }
- }
- if (IDEApp.sApp.mSpellChecker != null)
- IDEApp.sApp.mSpellChecker.CheckThreadDone();
- ///
- //TODO: REMOVE
- //mDebugger.InitiateHotResolve(.ActiveMethods | .Allocations);
- }
- public override void Draw()
- {
- scope AutoBeefPerf("IDEApp.Draw");
- #if CLI
- return;
- #endif
- #unwarn
- if (mBfResolveSystem != null)
- {
- mBfResolveSystem.PerfZoneStart("IDEApp.Draw");
- base.Draw();
- mBfResolveSystem.PerfZoneEnd();
- if (mBfResolveSystem.mIsTiming)
- {
- mBfResolveSystem.StopTiming();
- mBfResolveSystem.DbgPrintTimings();
- }
- }
- else
- base.Draw();
- }
- public void DrawSquiggle(Graphics g, float x, float y, float width)
- {
- Image squiggleImage = IDEApp.sApp.mSquiggleImage;
- int32 segSize = 30;
- float height = mSquiggleImage.mHeight;
-
- float curX = x;
- float curWidth = width;
- float drawY = y + gApp.mCodeFont.GetHeight();
- while (curWidth > 0)
- {
- float drawWidth = Math.Min(curWidth, segSize - (curX % segSize));
- float u1 = ((int32)curX % segSize) / (float)squiggleImage.mSrcWidth;
- float u2 = u1 + drawWidth / (float)squiggleImage.mSrcWidth;
- g.DrawQuad(squiggleImage, curX, drawY, u1, 0, drawWidth, height, u2, 1.0f);
- curWidth -= drawWidth;
- curX += drawWidth;
- }
- }
- public enum MessageBeepType
- {
- Default = -1,
- Ok = 0x00000000,
- Error = 0x00000010,
- Question = 0x00000020,
- Warning = 0x00000030,
- Information = 0x00000040,
- }
-
- public static void Beep(MessageBeepType type)
- {
- #if BF_PLATFORM_WINDOWS
- MessageBeep(type);
- #endif
- }
- #if BF_PLATFORM_WINDOWS
- [Import("user32.lib"), CLink, StdCall]
- public static extern bool MessageBeep(MessageBeepType type);
- #endif
- }
- static
- {
- public static IDEApp gApp;
- /*public static mixin GS(int val)
- {
- (int)(val * DarkTheme.sScale)
- }
- public static mixin GS(float val)
- {
- float fVal = val * DarkTheme.sScale;
- fVal
- }*/
- }
- }
|