mainform.cpp 238 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2007 Kevin Kofler
  4. Copyright (C) 2006 Joey Adams
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include <k3listview.h>
  18. class DnDListView : public K3ListView {
  19. private:
  20. public:
  21. DnDListView (QWidget * parent = 0) : K3ListView(parent) {}
  22. // Make my hand-coded drag&drop code work (public part).
  23. // Maybe the built-in drag&drop support in K3ListView could be made to work as
  24. // expected, but for now just bypass it to use the existing code I wrote for
  25. // QListView.
  26. virtual void takeItem(Q3ListViewItem *i) {Q3ListView::takeItem(i);}
  27. virtual void setAcceptDrops(bool on) {Q3ListView::setAcceptDrops(on);}
  28. protected:
  29. virtual Q3DragObject *dragObject();
  30. virtual void dropEvent (QDropEvent *e);
  31. virtual void dragEnterEvent (QDragEnterEvent *e);
  32. virtual void dragMoveEvent (QDragMoveEvent *e);
  33. // Make my hand-coded drag&drop code work (protected part).
  34. virtual void contentsDragMoveEvent(QDragMoveEvent *e) {
  35. Q3ListView::contentsDragMoveEvent(e);
  36. }
  37. virtual void contentsMouseMoveEvent(QMouseEvent *e) {
  38. Q3ListView::contentsMouseMoveEvent(e);
  39. }
  40. virtual void contentsDragLeaveEvent(QDragLeaveEvent *e) {
  41. Q3ListView::contentsDragLeaveEvent(e);
  42. }
  43. virtual void contentsDropEvent(QDropEvent *e) {
  44. Q3ListView::contentsDropEvent(e);
  45. }
  46. virtual void contentsDragEnterEvent(QDragEnterEvent *e) {
  47. Q3ListView::contentsDragEnterEvent(e);
  48. }
  49. virtual void startDrag() {
  50. Q3ListView::startDrag();
  51. }
  52. virtual void rename(Q3ListViewItem *item, int c);
  53. };
  54. // Yes, this is an ugly hack... Any better suggestions?
  55. #define K3ListView DnDListView
  56. #include "mainform.h"
  57. #undef K3ListView
  58. #include <QVariant>
  59. #include <QHash>
  60. #include <QImage>
  61. #include <QString>
  62. #include <QStringList>
  63. #include <QByteArray>
  64. #include <QPair>
  65. #include <QRegExp>
  66. #include <QApplication>
  67. #include <QLabel>
  68. #include <QStatusBar>
  69. #include <QTimer>
  70. #include <QDateTime>
  71. #include <Q3DragObject>
  72. #include <QDir>
  73. #include <QClipboard>
  74. #include <Q3Accel>
  75. #include <QEventLoop>
  76. #include <QCoreApplication>
  77. #include <QDockWidget>
  78. #include <QFileInfo>
  79. #include <QDateTime>
  80. #include <QTextCodec>
  81. #include <Q3StyleSheet>
  82. #include <QTimer>
  83. #include <QToolButton>
  84. #include <Q3ListBox>
  85. #include <QTimerEvent>
  86. #include <Q3PtrList>
  87. #include <QDragMoveEvent>
  88. #include <QDragLeaveEvent>
  89. #include <QKeyEvent>
  90. #include <QResizeEvent>
  91. #include <QEvent>
  92. #include <QDropEvent>
  93. #include <Q3PopupMenu>
  94. #include <QDragEnterEvent>
  95. #include <Q3ValueList>
  96. #include <QPixmap>
  97. #include <QMouseEvent>
  98. #include <QCloseEvent>
  99. #include <QAssistantClient>
  100. #include <QDBusConnection>
  101. #include <QDBusReply>
  102. #include <kapplication.h>
  103. #include <kparts/factory.h>
  104. #include <klibloader.h>
  105. #include <ktexteditor/editor.h>
  106. #include <ktexteditor/document.h>
  107. #include <ktexteditor/view.h>
  108. #include <ktexteditor/cursor.h>
  109. #include <ktexteditor/range.h>
  110. #include <ktexteditor/smartcursor.h>
  111. #include <ktexteditor/smartinterface.h>
  112. #include <ktexteditor/commandinterface.h>
  113. #include <ktexteditor/configinterface.h>
  114. #include <ktexteditor/highlightinginterface.h>
  115. #include <kconfig.h>
  116. #include <kconfiggroup.h>
  117. #include <ktexteditor/configpage.h>
  118. #include <kaboutdata.h>
  119. #include <khelpmenu.h>
  120. #include <kfiledialog.h>
  121. #include <kurl.h>
  122. #include <kmessagebox.h>
  123. #include <kdirwatch.h>
  124. #include <kfinddialog.h>
  125. #include <kfind.h>
  126. #include <kreplacedialog.h>
  127. #include <kreplace.h>
  128. #include <kglobal.h>
  129. #include <kicontheme.h>
  130. #include <kicon.h>
  131. #include <kiconloader.h>
  132. #include <kprocio.h>
  133. #include <kshell.h>
  134. #include <ktextbrowser.h>
  135. #include <krun.h>
  136. #include <kpushbutton.h>
  137. #include <kmacroexpander.h>
  138. #include <kstandardaction.h>
  139. #include <cstdio>
  140. #include <cstdlib>
  141. #include <cstring>
  142. #include <unistd.h>
  143. #include <glib.h>
  144. #include <ticonv.h>
  145. #include <ticables.h>
  146. #include <tifiles.h>
  147. #include <ticalcs.h>
  148. #include "ktigcc.h"
  149. #include "srcfile.h"
  150. #include "tpr.h"
  151. #include "preferences.h"
  152. #include "projectoptions.h"
  153. #include "errorlist.h"
  154. #include "programoutput.h"
  155. #include "tiemu.h"
  156. #include "callbacks.h"
  157. #include "parsing.h"
  158. #include "functions.h"
  159. #include "toolsdlg.h"
  160. #include "newsdlg.h"
  161. #include "completion.h"
  162. #if defined(Q_WS_X11)
  163. #include <kwin.h>
  164. #define ACTIVATE_WINDOW(winid) KWin::activateWindow(winid)
  165. #elif defined(Q_WS_WIN)
  166. #include <windows.h>
  167. #define ACTIVATE_WINDOW(winid) SetForegroundWindow(winid)
  168. #else
  169. #define ACTIVATE_WINDOW(winid) ((void)0)
  170. #endif
  171. using std::puts;
  172. using std::exit;
  173. #define TIGCC_TPR_Filter "*.tpr|TIGCC Projects (*.tpr)\n"
  174. #define TIGCC_H_Filter "*.h|Header Files (*.h)\n"
  175. #define TIGCC_C_Filter "*.c|C Files (*.c)\n"
  176. #define TIGCC_S_Filter "*.s|GNU Assembly Files (*.s)\n"
  177. #define TIGCC_ASM_Filter "*.asm|A68k Assembly Files (*.asm)\n"
  178. #define TIGCC_QLL_Filter "*.qll|Quill Files (*.qll)\n"
  179. #define TIGCC_O_Filter "*.o|Object Files (*.o)\n"
  180. #define TIGCC_A_Filter "*.a|Archive Files (*.a)\n"
  181. #define TIGCC_TXT_Filter "*.txt|Text Files (*.txt)\n"
  182. #define TIGCCAllFilter "*|All Files (*)"
  183. enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
  184. #define IS_CATEGORY(item) ((item) && ((item)==hFilesListItem \
  185. || (item)==cFilesListItem \
  186. || (item)==sFilesListItem \
  187. || (item)==asmFilesListItem \
  188. || (item)==qllFilesListItem \
  189. || (item)==oFilesListItem \
  190. || (item)==aFilesListItem \
  191. || (item)==txtFilesListItem \
  192. || (item)==othFilesListItem))
  193. #define IS_EDITABLE_CATEGORY(item) ((item) && ((item)==hFilesListItem \
  194. || (item)==cFilesListItem \
  195. || (item)==sFilesListItem \
  196. || (item)==asmFilesListItem \
  197. || (item)==qllFilesListItem \
  198. || (item)==txtFilesListItem))
  199. #define IS_FOLDER(item) ((item) && (item)->rtti()==0x716CC0)
  200. #define IS_FILE(item) ((item) && (item)->rtti()==0x716CC1)
  201. #define CATEGORY_OF(category,item) Q3ListViewItem *category=(item); \
  202. while (category->parent()->rtti()==0x716CC0) \
  203. category=category->parent()
  204. #define COUNTER_FOR_CATEGORY(category) ((category)==hFilesListItem?hFileCount: \
  205. (category)==cFilesListItem?cFileCount: \
  206. (category)==sFilesListItem?sFileCount: \
  207. (category)==asmFilesListItem?asmFileCount: \
  208. (category)==qllFilesListItem?qllFileCount: \
  209. (category)==oFilesListItem?oFileCount: \
  210. (category)==aFilesListItem?aFileCount: \
  211. (category)==txtFilesListItem?txtFileCount: \
  212. othFileCount)
  213. #define CURRENT_VIEW (static_cast<KTextEditor::View *>(widgetStack->visibleWidget()))
  214. #define SYSICON(sysname,name) (preferences.useSystemIcons?KIconLoader::global()->loadIcon((sysname),K3Icon::Small,K3Icon::SizeSmall):QPixmap(":/images/" name))
  215. #define SET_TEXT_SAFE(doc,text) do { \
  216. disableViewEvents=TRUE; \
  217. (doc)->setText((text)); \
  218. disableViewEvents=FALSE; \
  219. } while(0)
  220. // For some reason, this flag is not in the public ConfigFlags enum.
  221. #define CF_REMOVE_TRAILING_DYN 0x4000000
  222. static Q3ListViewItem *currentListItem;
  223. static Q3ListViewItem *replaceCurrentDocument;
  224. static int replaceCurrentLine;
  225. static bool compiling;
  226. class KReplaceWithSelection : public KReplace {
  227. public:
  228. KReplaceWithSelection(const QString &pattern, const QString &replacement,
  229. long options, QWidget *parent=0) :
  230. KReplace(pattern,replacement,options,parent), m_haveSelection(FALSE) {}
  231. void setSelection(int selStartLine, int selStartCol,
  232. int selEndLine, int selEndCol)
  233. {
  234. m_haveSelection=TRUE;
  235. m_selStartLine=selStartLine;
  236. m_selStartCol=selStartCol;
  237. m_selEndLine=selEndLine;
  238. m_selEndCol=selEndCol;
  239. }
  240. void setSelection(const KTextEditor::Range &selRange)
  241. {
  242. m_haveSelection=TRUE;
  243. selRange.start().position(m_selStartLine,m_selStartCol);
  244. selRange.end().position(m_selEndLine,m_selEndCol);
  245. }
  246. void invalidateSelection() {m_haveSelection=FALSE;}
  247. bool haveSelection() {
  248. // If another document was put under the cursor, invalidate selection.
  249. // The m_haveSelection&& is technically redundant, but necessary to avoid
  250. // possible undefined behavior if replaceCurrentDocument has been deleted.
  251. if (m_haveSelection&&currentListItem!=replaceCurrentDocument)
  252. m_haveSelection=FALSE;
  253. return m_haveSelection;
  254. }
  255. int selStartLine() {return m_selStartLine;}
  256. int selStartCol() {return m_selStartCol;}
  257. int selEndLine() {return m_selEndLine;}
  258. int selEndCol() {return m_selEndCol;}
  259. // Override to ask for restarting when replacing in a selection.
  260. bool shouldRestart(bool forceAsking=FALSE, bool showNumMatches=TRUE)
  261. {
  262. return KReplace::shouldRestart(forceAsking||m_haveSelection,showNumMatches);
  263. }
  264. protected:
  265. virtual bool validateMatch(const QString &text, int index, int matchedlength)
  266. {
  267. if (!KReplace::validateMatch(text,index,matchedlength)) return FALSE;
  268. // If another document was put under the cursor, invalidate selection.
  269. // The m_haveSelection&& is technically redundant, but necessary to avoid
  270. // possible undefined behavior if replaceCurrentDocument has been deleted.
  271. if (m_haveSelection&&currentListItem!=replaceCurrentDocument)
  272. m_haveSelection=FALSE;
  273. if (!m_haveSelection) return TRUE;
  274. if (replaceCurrentLine==m_selStartLine && replaceCurrentLine==m_selEndLine)
  275. return (index>=m_selStartCol)&&(index+matchedlength<=m_selEndCol);
  276. else if (replaceCurrentLine==m_selStartLine)
  277. return (index>=m_selStartCol);
  278. else if (replaceCurrentLine==m_selEndLine)
  279. return (index+matchedlength<=m_selEndCol);
  280. else
  281. return (replaceCurrentLine>=m_selStartLine&&replaceCurrentLine<=m_selEndLine);
  282. }
  283. private:
  284. bool m_haveSelection;
  285. int m_selStartLine, m_selStartCol, m_selEndLine, m_selEndCol;
  286. };
  287. static KReplaceWithSelection *kreplace;
  288. // All the methods are inline because otherwise QT Designer will mistake them
  289. // for slots of the main form.
  290. class ListViewFolder : public K3ListViewItem {
  291. public:
  292. ListViewFolder(Q3ListView *parent) : K3ListViewItem(parent)
  293. {
  294. setPixmap(0,SYSICON("folder","folder1.png"));
  295. setDragEnabled(TRUE);
  296. setDropEnabled(TRUE);
  297. }
  298. ListViewFolder(Q3ListViewItem *parent) : K3ListViewItem(parent)
  299. {
  300. setPixmap(0,SYSICON("folder","folder1.png"));
  301. setDragEnabled(TRUE);
  302. setDropEnabled(TRUE);
  303. }
  304. ListViewFolder(Q3ListView *parent, Q3ListViewItem *after)
  305. : K3ListViewItem(parent, after)
  306. {
  307. setPixmap(0,SYSICON("folder","folder1.png"));
  308. setDropEnabled(TRUE);
  309. setDragEnabled(TRUE);
  310. }
  311. ListViewFolder(Q3ListViewItem *parent, Q3ListViewItem *after)
  312. : K3ListViewItem(parent, after)
  313. {
  314. setPixmap(0,SYSICON("folder","folder1.png"));
  315. setDragEnabled(TRUE);
  316. setDropEnabled(TRUE);
  317. }
  318. virtual int rtti(void) const {return 0x716CC0;}
  319. // Work around gratuitous API difference. Why do I have to do this? That's
  320. // what startRename is a virtual method for. K3ListViewItem should do this.
  321. virtual void startRename(int col)
  322. {
  323. static_cast<K3ListView *>(listView())->rename(this,col);
  324. }
  325. protected:
  326. };
  327. class ListViewFile : public K3ListViewItem {
  328. public:
  329. ListViewFile(Q3ListView *parent) : K3ListViewItem(parent),
  330. kateView(NULL), isNew(TRUE),
  331. modifiedSinceLastCompile(TRUE)
  332. {
  333. setPixmap(0,SYSICON("unknown","filex.png"));
  334. setDragEnabled(TRUE);
  335. setDropEnabled(TRUE);
  336. setRenameEnabled(0,TRUE);
  337. }
  338. ListViewFile(Q3ListViewItem *parent) : K3ListViewItem(parent),
  339. kateView(NULL), isNew(TRUE),
  340. modifiedSinceLastCompile(TRUE)
  341. {
  342. setPixmap(0,SYSICON("unknown","filex.png"));
  343. setDragEnabled(TRUE);
  344. setDropEnabled(TRUE);
  345. setRenameEnabled(0,TRUE);
  346. }
  347. ListViewFile(Q3ListView *parent, Q3ListViewItem *after)
  348. : K3ListViewItem(parent, after), kateView(NULL), isNew(TRUE),
  349. modifiedSinceLastCompile(TRUE)
  350. {
  351. setPixmap(0,SYSICON("unknown","filex.png"));
  352. setDropEnabled(TRUE);
  353. setDragEnabled(TRUE);
  354. setRenameEnabled(0,TRUE);
  355. }
  356. ListViewFile(Q3ListViewItem *parent, Q3ListViewItem *after)
  357. : K3ListViewItem(parent, after), kateView(NULL),
  358. isNew(TRUE), modifiedSinceLastCompile(TRUE)
  359. {
  360. setPixmap(0,SYSICON("unknown","filex.png"));
  361. setDragEnabled(TRUE);
  362. setDropEnabled(TRUE);
  363. setRenameEnabled(0,TRUE);
  364. }
  365. virtual ~ListViewFile()
  366. {
  367. MainForm::deleteErrorsForLVFile(this);
  368. if (kreplace && replaceCurrentDocument==this) {
  369. replaceCurrentDocument=static_cast<Q3ListViewItem *>(NULL);
  370. kreplace->invalidateSelection();
  371. }
  372. if (!fileName.isEmpty() && fileName[0]=='/')
  373. KDirWatch::self()->removeFile(fileName);
  374. if (kateView) {
  375. KTextEditor::Document *doc=kateView->document();
  376. delete kateView;
  377. delete doc;
  378. }
  379. }
  380. virtual int rtti(void) const {return 0x716CC1;}
  381. KTextEditor::View *kateView;
  382. QString fileName; // full name of the file
  383. bool isNew;
  384. bool modifiedSinceLastCompile;
  385. LineStartList lineStartList;
  386. // Work around gratuitous API difference. Why do I have to do this? That's
  387. // what startRename is a virtual method for. K3ListViewItem should do this.
  388. virtual void startRename(int col)
  389. {
  390. static_cast<K3ListView *>(listView())->rename(this,col);
  391. }
  392. protected:
  393. };
  394. class ListViewRoot : public K3ListViewItem {
  395. public:
  396. ListViewRoot(Q3ListView *parent) : K3ListViewItem(parent)
  397. {
  398. setRenameEnabled(0,TRUE);
  399. // dragging not really allowed, but don't let the cursor run around when dragged
  400. setDragEnabled(TRUE);
  401. }
  402. ListViewRoot(Q3ListViewItem *parent) : K3ListViewItem(parent)
  403. {
  404. setRenameEnabled(0,TRUE);
  405. // dragging not really allowed, but don't let the cursor run around when dragged
  406. setDragEnabled(TRUE);
  407. }
  408. ListViewRoot(Q3ListView *parent, Q3ListViewItem *after)
  409. : K3ListViewItem(parent, after)
  410. {
  411. setRenameEnabled(0,TRUE);
  412. // dragging not really allowed, but don't let the cursor run around when dragged
  413. setDragEnabled(TRUE);
  414. }
  415. ListViewRoot(Q3ListViewItem *parent, Q3ListViewItem *after)
  416. : K3ListViewItem(parent, after)
  417. {
  418. setRenameEnabled(0,TRUE);
  419. // dragging not really allowed, but don't let the cursor run around when dragged
  420. setDragEnabled(TRUE);
  421. }
  422. // Work around gratuitous API difference. Why do I have to do this? That's
  423. // what startRename is a virtual method for. K3ListViewItem should do this.
  424. virtual void startRename(int col)
  425. {
  426. static_cast<K3ListView *>(listView())->rename(this,col);
  427. }
  428. protected:
  429. };
  430. // These should be instance variables in clean C++, but QT Designer won't let me
  431. // touch the class definition, so this is all I can do. And there is only one
  432. // instance of MainForm anyway.
  433. static Q3ListViewItem *rootListItem;
  434. static Q3ListViewItem *hFilesListItem;
  435. static Q3ListViewItem *cFilesListItem;
  436. static Q3ListViewItem *sFilesListItem;
  437. static Q3ListViewItem *asmFilesListItem;
  438. static Q3ListViewItem *qllFilesListItem;
  439. static Q3ListViewItem *oFilesListItem;
  440. static Q3ListViewItem *aFilesListItem;
  441. static Q3ListViewItem *txtFilesListItem;
  442. static Q3ListViewItem *othFilesListItem;
  443. static bool projectIsDirty, projectNeedsRelink;
  444. static QLabel *leftStatusLabel;
  445. static QLabel *rowStatusLabel;
  446. static QLabel *colStatusLabel;
  447. static QLabel *charsStatusLabel;
  448. static QLabel *rightStatusLabel;
  449. static KHelpMenu *khelpmenu;
  450. static Q3PopupMenu *te_popup;
  451. static bool headersModified;
  452. static QDockWidget *errorListDock;
  453. static ErrorList *errorList;
  454. static unsigned errorCountTotal=0,errorCountErrors=0,errorCountWarnings=0;
  455. static QString programOutput;
  456. QAssistantClient *assistant;
  457. static unsigned fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
  458. tprSettings settings;
  459. tprLibOpts libopts;
  460. static QString projectFileName;
  461. static QString lastDirectory;
  462. QClipboard *clipboard;
  463. static Q3Accel *accel, *fileTreeAccel;
  464. static KFindDialog *kfinddialog;
  465. QStringList findHistory, replacementHistory;
  466. static Q3ListViewItem *findCurrentDocument;
  467. static int findCurrentLine;
  468. Q3PtrList<SourceFile> sourceFiles;
  469. static Q3PopupMenu *findFunctionsPopup;
  470. bool have_usb;
  471. Tools tools, tempTools;
  472. int toolIndex;
  473. bool disableViewEvents=FALSE;
  474. Q3DragObject *DnDListView::dragObject() {
  475. Q3ListViewItem *currItem=selectedItem();
  476. if (currItem==rootListItem || currItem->parent()==rootListItem)
  477. return NULL;
  478. Q3StoredDrag *storedDrag=new Q3StoredDrag("x-ktigcc-dnd", this);
  479. static QByteArray data(sizeof(Q3ListViewItem*));
  480. data.duplicate(reinterpret_cast<char *>(&currItem),
  481. sizeof(Q3ListViewItem*));
  482. storedDrag->setEncodedData(data);
  483. return storedDrag;
  484. }
  485. void DnDListView::dropEvent(QDropEvent *e) {
  486. if (!compiling && e->source()==this && e->provides("x-ktigcc-dnd")) {
  487. Q3ListViewItem *currItem;
  488. currItem = *reinterpret_cast<Q3ListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  489. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  490. // dropping folder
  491. // can only drop on folder or category
  492. Q3ListViewItem *item=itemAt(e->pos());
  493. if (IS_FOLDER(item)) {
  494. // need same category
  495. CATEGORY_OF(srcCategory,currItem);
  496. CATEGORY_OF(destCategory,item);
  497. if (srcCategory == destCategory) {
  498. // can't move folder into itself
  499. for (Q3ListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
  500. if (destFolder==currItem) goto ignore;
  501. }
  502. // move folder
  503. e->accept();
  504. currItem->parent()->takeItem(currItem);
  505. item->insertItem(currItem);
  506. // put it at the right place
  507. if (currItem->nextSibling()) {
  508. Q3ListViewItem *lastItem=currItem->nextSibling();
  509. while(lastItem->nextSibling())
  510. lastItem=lastItem->nextSibling();
  511. currItem->moveItem(lastItem);
  512. }
  513. projectIsDirty=TRUE;
  514. projectNeedsRelink=TRUE;
  515. } else {ignore: e->ignore();}
  516. } else e->ignore();
  517. } else if (IS_FILE(currItem)) {
  518. // dropping file
  519. Q3ListViewItem *item=itemAt(e->pos());
  520. if (IS_FOLDER(item)) {
  521. // drop on folder
  522. // don't allow more than one Quill file per project
  523. CATEGORY_OF(srcCategory,currItem);
  524. CATEGORY_OF(destCategory,item);
  525. if (qllFilesListItem && srcCategory != qllFilesListItem
  526. && destCategory == qllFilesListItem && qllFileCount) {
  527. ignore2: e->ignore();
  528. } else {
  529. // moving from editable to non-editable category -
  530. // prompt for saving
  531. if (IS_EDITABLE_CATEGORY(srcCategory)
  532. && !IS_EDITABLE_CATEGORY(destCategory)) {
  533. if (static_cast<MainForm *>(parent()->parent()->parent())->fileSavePrompt(currItem))
  534. goto ignore2;
  535. if (!static_cast<ListViewFile *>(currItem)->fileName.isEmpty()
  536. && static_cast<ListViewFile *>(currItem)->fileName[0]=='/')
  537. KDirWatch::self()->removeFile(static_cast<ListViewFile *>(currItem)->fileName);
  538. }
  539. // moving from non-editable to editable category
  540. if (!IS_EDITABLE_CATEGORY(srcCategory)
  541. && IS_EDITABLE_CATEGORY(destCategory)) {
  542. static_cast<ListViewFile *>(currItem)->kateView=reinterpret_cast<KTextEditor::View *>(static_cast<MainForm *>(parent()->parent()->parent())->createView(static_cast<ListViewFile *>(currItem)->fileName,QString::null,destCategory));
  543. MainForm::createErrorCursorsForSourceFile(currItem);
  544. // force reloading the text buffer
  545. if (currentListItem==currItem)
  546. currentListItem=NULL;
  547. }
  548. // move file
  549. e->accept();
  550. currItem->parent()->takeItem(currItem);
  551. COUNTER_FOR_CATEGORY(srcCategory)--;
  552. item->insertItem(currItem);
  553. COUNTER_FOR_CATEGORY(destCategory)++;
  554. // put it at the right place
  555. if (IS_FILE(currItem->nextSibling())) {
  556. Q3ListViewItem *lastItem=currItem->nextSibling();
  557. while(IS_FILE(lastItem->nextSibling()))
  558. lastItem=lastItem->nextSibling();
  559. currItem->moveItem(lastItem);
  560. }
  561. projectIsDirty=TRUE;
  562. projectNeedsRelink=TRUE;
  563. setSelected(currItem,TRUE);
  564. ensureItemVisible(currItem);
  565. // update editor and counters
  566. static_cast<MainForm *>(parent()->parent()->parent())->fileTreeClicked(currItem);
  567. // moving from non-editable to editable category
  568. if (!IS_EDITABLE_CATEGORY(srcCategory)
  569. && IS_EDITABLE_CATEGORY(destCategory)) {
  570. if (!static_cast<ListViewFile *>(currItem)->fileName.isEmpty()
  571. && static_cast<ListViewFile *>(currItem)->fileName[0]=='/')
  572. KDirWatch::self()->addFile(static_cast<ListViewFile *>(currItem)->fileName);
  573. }
  574. // moving from editable to non-editable category
  575. if (IS_EDITABLE_CATEGORY(srcCategory)
  576. && !IS_EDITABLE_CATEGORY(destCategory)) {
  577. KTextEditor::Document *doc=static_cast<ListViewFile *>(currItem)->kateView->document();
  578. delete static_cast<ListViewFile *>(currItem)->kateView;
  579. delete doc;
  580. static_cast<ListViewFile *>(currItem)->kateView=NULL;
  581. }
  582. // moving from editable to editable category
  583. if (IS_EDITABLE_CATEGORY(srcCategory)
  584. && IS_EDITABLE_CATEGORY(destCategory)
  585. && srcCategory!=destCategory) {
  586. // update highlighting mode
  587. KTextEditor::HighlightingInterface *hliface
  588. =qobject_cast<KTextEditor::HighlightingInterface*>(
  589. static_cast<ListViewFile *>(currItem)->kateView->document());
  590. QString fileText=static_cast<ListViewFile *>(currItem)->kateView->document()->text();
  591. hliface->setHighlighting(
  592. (destCategory==qllFilesListItem?
  593. QLL_HL_MODE:
  594. (destCategory==sFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
  595. S_HL_MODE:
  596. (destCategory==asmFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
  597. ASM_HL_MODE:
  598. (destCategory==cFilesListItem||destCategory==hFilesListItem)?
  599. C_HL_MODE:
  600. "None"));
  601. }
  602. // update icon
  603. currItem->setPixmap(0,
  604. destCategory==cFilesListItem||destCategory==qllFilesListItem?SYSICON("source_c","filec.png"):
  605. destCategory==hFilesListItem?SYSICON("source_h","fileh.png"):
  606. destCategory==sFilesListItem||destCategory==asmFilesListItem?SYSICON("source_s","files.png"):
  607. destCategory==txtFilesListItem?SYSICON("txt","filet.png"):
  608. destCategory==oFilesListItem||destCategory==aFilesListItem?SYSICON("binary","fileo.png"):
  609. SYSICON("unknown","filex.png"));
  610. }
  611. } else if (IS_FILE(item)) {
  612. // drop on file
  613. // need same parent, but different items
  614. if (currItem->parent() == item->parent()
  615. && currItem != item) {
  616. // reorder files
  617. // figure out which one is the first
  618. for (Q3ListViewItem *i=currItem->parent()->firstChild();i;
  619. i=i->nextSibling()) {
  620. if (i==currItem) {
  621. // currItem is first, move currItem after item
  622. e->accept();
  623. currItem->moveItem(item);
  624. projectIsDirty=TRUE;
  625. projectNeedsRelink=TRUE;
  626. break;
  627. } else if (i==item) {
  628. // item is first, move currItem before item
  629. e->accept();
  630. currItem->moveItem(item);
  631. item->moveItem(currItem);
  632. projectIsDirty=TRUE;
  633. projectNeedsRelink=TRUE;
  634. break;
  635. }
  636. }
  637. } else e->ignore();
  638. } else e->ignore();
  639. } else e->ignore();
  640. } else e->ignore();
  641. }
  642. void DnDListView::dragEnterEvent(QDragEnterEvent *e) {
  643. if (!compiling && e->source()==this&&(e->provides("x-ktigcc-dnd")))
  644. e->accept();
  645. }
  646. void DnDListView::dragMoveEvent(QDragMoveEvent *e) {
  647. if (!compiling && e->source()==this && e->provides("x-ktigcc-dnd")) {
  648. Q3ListViewItem *currItem;
  649. currItem = *reinterpret_cast<Q3ListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  650. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  651. // dropping folder
  652. // can only drop on folder or category
  653. Q3ListViewItem *item=itemAt(e->pos());
  654. if (IS_FOLDER(item)) {
  655. // need same category
  656. CATEGORY_OF(srcCategory,currItem);
  657. CATEGORY_OF(destCategory,item);
  658. if (srcCategory == destCategory) {
  659. // can't move folder into itself
  660. for (Q3ListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
  661. if (destFolder==currItem) goto ignore;
  662. }
  663. e->accept();
  664. } else {ignore: e->ignore();}
  665. } else e->ignore();
  666. } else if (IS_FILE(currItem)) {
  667. // dropping file
  668. Q3ListViewItem *item=itemAt(e->pos());
  669. if (IS_FOLDER(item)) {
  670. // drop on folder
  671. // don't allow more than one Quill file per project
  672. CATEGORY_OF(srcCategory,currItem);
  673. CATEGORY_OF(destCategory,item);
  674. if (qllFilesListItem && srcCategory != qllFilesListItem
  675. && destCategory == qllFilesListItem && qllFileCount)
  676. e->ignore();
  677. else
  678. e->accept();
  679. } else if (IS_FILE(item)) {
  680. // drop on file
  681. // need same parent, but different items
  682. if (currItem->parent() == item->parent()
  683. && currItem != item) e->accept(); else e->ignore();
  684. } else e->ignore();
  685. } else e->ignore();
  686. } else e->ignore();
  687. }
  688. // K3ListView::rename won't work properly if I don't do this. :-/
  689. void DnDListView::rename(Q3ListViewItem *item, int c) {
  690. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  691. ensureItemVisible(item);
  692. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  693. K3ListView::rename(item,c);
  694. }
  695. enum ErrorTypes {etError, etWarning, etInfo};
  696. class ErrorListItem : public K3ListViewItem {
  697. public:
  698. ErrorListItem(MainForm *pMainForm, ErrorTypes errType,
  699. const QString &errFile, const QString &errFunc,
  700. const QString &errMsg, int errLine, int errColumn)
  701. : K3ListViewItem(errorList->errorListView,
  702. errorList->errorListView->lastItem()),
  703. lvFile(0), srcFile(0), cursor(0), errorLine(-1), errorColumn(0),
  704. mainForm(pMainForm), errorType(errType)
  705. {
  706. QString errMessage=errMsg.trimmed();
  707. if (!errMessage.isEmpty()) errMessage[0]=errMessage[0].toUpper();
  708. switch(errType) {
  709. case etError:
  710. setPixmap(0,SYSICON("messagebox_critical","error.png"));
  711. break;
  712. case etWarning:
  713. setPixmap(0,SYSICON("messagebox_warning","warning.png"));
  714. break;
  715. default:
  716. setPixmap(0,SYSICON("messagebox_info","info.png"));
  717. break;
  718. }
  719. setText(0,errMessage);
  720. setText(1,errFile);
  721. setText(2,errFunc=="__exit"?"_exit":
  722. (errFunc=="__main"?"_main":errFunc));
  723. if (!errFile.isEmpty() && !errFile.endsWith(".a")) {
  724. // Look for the source file with the error.
  725. if (!findSourceFile(errFile) && errFile.endsWith(".o")) {
  726. QString errSrcFile=errFile;
  727. int lengthWoExt=errSrcFile.length()-2;
  728. errSrcFile.truncate(lengthWoExt);
  729. errSrcFile.append(".c");
  730. if (!findSourceFile(errSrcFile)) {
  731. errSrcFile.truncate(lengthWoExt);
  732. errSrcFile.append(".s");
  733. if (!findSourceFile(errSrcFile)) {
  734. errSrcFile.truncate(lengthWoExt);
  735. errSrcFile.append(".asm");
  736. findSourceFile(errSrcFile);
  737. }
  738. }
  739. }
  740. // Not found. Try to open it instead.
  741. // Don't do this if the name ends with ".tpr" because that would cause
  742. // openProject to close the current project and load the new one instead.
  743. if (!lvFile && !srcFile && !errFile.endsWith(".tpr",FALSE)) {
  744. if (errFile.contains('/')&&getPathType(errFile)==PATH_FILE)
  745. mainForm->openProject(errFile);
  746. else if (getPathType(QString("%1/include/c/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
  747. mainForm->openProject(QString("%1/include/c/%2").arg(tigcc_base).arg(errFile));
  748. else if (getPathType(QString("%1/include/asm/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
  749. mainForm->openProject(QString("%1/include/asm/%2").arg(tigcc_base).arg(errFile));
  750. else if (getPathType(QString("%1/include/s/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
  751. mainForm->openProject(QString("%1/include/s/%2").arg(tigcc_base).arg(errFile));
  752. findSourceFile(errFile);
  753. }
  754. }
  755. if (errLine!=-1 && (lvFile || srcFile)) {
  756. if (errColumn==-1) errColumn=0;
  757. const LineStartList &lineStartList=lvFile?lvFile->lineStartList
  758. :srcFile->lineStartList;
  759. if (lineStartList.isEmpty()) {
  760. errorLine=errLine;
  761. errorColumn=errColumn;
  762. } else if (errLine<lineStartList.count()) {
  763. QPair<unsigned,unsigned> pos=lineStartList[errLine];
  764. errorLine=(int)pos.first;
  765. errorColumn=(int)pos.second+errColumn;
  766. }
  767. createCursor();
  768. }
  769. if (preferences.jumpToError && errType==etError
  770. && errorList->errorListView->selectedItems().isEmpty()) {
  771. errorList->errorListView->setSelected(this,TRUE);
  772. jumpToLocation();
  773. }
  774. errorCountTotal++;
  775. if (errType==etError) errorCountErrors++;
  776. if (errType==etWarning) errorCountWarnings++;
  777. errorList->errorCount->setText(QString::number(errorCountErrors));
  778. errorList->warningCount->setText(QString::number(errorCountWarnings));
  779. mainForm->projectErrorsAndWarningsAction->setEnabled(TRUE);
  780. mainForm->projectErrorsAndWarnings(TRUE);
  781. }
  782. virtual ~ErrorListItem()
  783. {
  784. if (errorType==etError) errorCountErrors--;
  785. if (errorType==etWarning) errorCountWarnings--;
  786. errorList->errorCount->setText(QString::number(errorCountErrors));
  787. errorList->warningCount->setText(QString::number(errorCountWarnings));
  788. if (!--errorCountTotal) {
  789. mainForm->projectErrorsAndWarnings(FALSE);
  790. mainForm->projectErrorsAndWarningsAction->setEnabled(FALSE);
  791. }
  792. }
  793. virtual int rtti(void) const {return static_cast<int>(errorType);}
  794. void createCursor(void)
  795. {
  796. if (errorLine!=-1) {
  797. KTextEditor::View *kateView=lvFile?lvFile->kateView:(srcFile?srcFile->kateView
  798. :static_cast<KTextEditor::View *>(NULL));
  799. if (kateView && errorLine<kateView->document()->lines()) {
  800. // Extract the main token for the error message.
  801. QString errMessage=text(0);
  802. int quotePos=errMessage.find('\'');
  803. if (quotePos>=0) {
  804. QString token=errMessage.mid(quotePos+1);
  805. int quotePos2=token.find('\'');
  806. if (quotePos2>=0) {
  807. token.truncate(quotePos2);
  808. if (!token.isEmpty()) {
  809. // Skip whitespace up to this token. TIGCC IDE does that too. Must
  810. // have something to do with how source splitting works.
  811. int i=errorColumn;
  812. QString textLine=kateView->document()->line(errorLine);
  813. int lineLength=kateView->document()->lineLength(errorLine);
  814. int tokenLength=token.length();
  815. while ((i<lineLength) && textLine[i].isSpace()
  816. && textLine.mid(i,tokenLength)!=token) i++;
  817. if (textLine.mid(i,tokenLength)==token) errorColumn=i;
  818. }
  819. }
  820. }
  821. KTextEditor::SmartInterface* smart =
  822. qobject_cast<KTextEditor::SmartInterface*>(kateView->document());
  823. cursor=smart->newSmartCursor(errorLine,errorColumn);
  824. }
  825. }
  826. }
  827. void jumpToLocation(void)
  828. {
  829. // If the error corresponds to a list view file, select it. This will also
  830. // instantiate the Kate view and call createCursor for us.
  831. if (lvFile) mainForm->fileTreeClicked(lvFile);
  832. // If it corresponds to an external source file, activate the window.
  833. if (srcFile) ACTIVATE_WINDOW(srcFile->winId());
  834. // Now jump to the cursor's location if we have one.
  835. KTextEditor::View *kateView=lvFile?lvFile->kateView:(srcFile?srcFile->kateView
  836. :static_cast<KTextEditor::View *>(NULL));
  837. if (cursor && kateView)
  838. kateView->setCursorPosition(*cursor);
  839. }
  840. ListViewFile *lvFile;
  841. SourceFile *srcFile;
  842. KTextEditor::SmartCursor *cursor;
  843. private:
  844. int errorLine;
  845. int errorColumn;
  846. MainForm *mainForm;
  847. ErrorTypes errorType;
  848. bool findSourceFile(const QString &fileName)
  849. {
  850. bool inProject;
  851. void *sourceFile;
  852. bool found=mainForm->findSourceFile(inProject,sourceFile,fileName);
  853. if (found) {
  854. if (inProject)
  855. lvFile=reinterpret_cast<ListViewFile *>(sourceFile);
  856. else
  857. srcFile=reinterpret_cast<SourceFile *>(sourceFile);
  858. }
  859. return found;
  860. }
  861. };
  862. // This static helper function is needed because of limitations of both .ui.h
  863. // files and C++: we can't have methods of other classes than MainForm here
  864. // unless we write them into the class definition or Qt Designer gets confused,
  865. // and C++ won't let 2 classes reference each other in methods declared within
  866. // the class definition. And item is of type QListViewItem rather than
  867. // ListViewFile because of another Qt Designer limitation: It isn't possible to
  868. // use custom types in a .ui file method because it doesn't forward-declare them
  869. // properly.
  870. void MainForm::deleteErrorsForLVFile(Q3ListViewItem *item)
  871. {
  872. Q3ListViewItemIterator lvit(errorList->errorListView);
  873. Q3ListViewItem *errorItem;
  874. while ((errorItem=lvit.current())) {
  875. ++lvit;
  876. if (static_cast<ErrorListItem *>(errorItem)->lvFile
  877. ==static_cast<ListViewFile *>(item))
  878. delete errorItem;
  879. }
  880. }
  881. // Another static helper function, in this case because srcfilewin.ui.h doesn't
  882. // have access to ErrorListItem for similar reasons. (I'd have to duplicate the
  883. // class definition, one time with inline functions and one time without.)
  884. void MainForm::deleteErrorsForSrcFile(void *srcFile)
  885. {
  886. Q3ListViewItemIterator lvit(errorList->errorListView);
  887. Q3ListViewItem *errorItem;
  888. while ((errorItem=lvit.current())) {
  889. ++lvit;
  890. if (static_cast<ErrorListItem *>(errorItem)->srcFile
  891. ==reinterpret_cast<SourceFile *>(srcFile))
  892. delete errorItem;
  893. }
  894. }
  895. // And another.
  896. void MainForm::createErrorCursorsForSourceFile(Q3ListViewItem *item)
  897. {
  898. Q3ListViewItemIterator lvit(errorList->errorListView);
  899. Q3ListViewItem *errorItem;
  900. for (errorItem=lvit.current();errorItem;errorItem=(++lvit).current()) {
  901. if (static_cast<ErrorListItem *>(errorItem)->lvFile
  902. ==static_cast<ListViewFile *>(item))
  903. static_cast<ErrorListItem *>(errorItem)->createCursor();
  904. }
  905. }
  906. // And the last.
  907. void MainForm::deleteOverwrittenErrorsIn(void *srcFile)
  908. {
  909. SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
  910. Q3ListViewItemIterator lvit(errorList->errorListView);
  911. ErrorListItem *errorItem;
  912. while ((errorItem=static_cast<ErrorListItem *>(lvit.current()))) {
  913. ++lvit;
  914. if (errorItem->srcFile==sourceFile && errorItem->cursor) {
  915. int line,col;
  916. errorItem->cursor->position(line,col);
  917. int curline,curcol;
  918. sourceFile->kateView->cursorPosition().position(curline,curcol);
  919. if (curline==line && curcol==col)
  920. delete errorItem;
  921. }
  922. }
  923. }
  924. void MainForm::errorListView_clicked(Q3ListViewItem *item)
  925. {
  926. if (item) {
  927. static_cast<ErrorListItem *>(item)->jumpToLocation();
  928. errorList->setFocus();
  929. }
  930. }
  931. bool MainForm::findSourceFile(bool &inProject, void *&srcFile, const QString &fileName)
  932. {
  933. bool compareAbsPaths=fileName.contains('/');
  934. Q3ListViewItemIterator lvit(fileTree);
  935. Q3ListViewItem *item;
  936. for (item=lvit.current();item;item=(++lvit).current()) {
  937. if (IS_FILE(item)
  938. && (compareAbsPaths?fileName==static_cast<ListViewFile *>(item)->fileName
  939. :fileName==QFileInfo(static_cast<ListViewFile *>(item)->fileName).fileName())) {
  940. inProject=TRUE;
  941. srcFile=static_cast<ListViewFile *>(item);
  942. return TRUE;
  943. }
  944. }
  945. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  946. SourceFile *sourceFile;
  947. for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  948. if (compareAbsPaths?fileName==sourceFile->fileName
  949. :fileName==QFileInfo(sourceFile->fileName).fileName()) {
  950. inProject=FALSE;
  951. srcFile=sourceFile;
  952. return TRUE;
  953. }
  954. }
  955. return FALSE;
  956. }
  957. void sendCommand(KTextEditor::View *view, const QString &cmd)
  958. {
  959. KTextEditor::CommandInterface *cmdIface=
  960. qobject_cast<KTextEditor::CommandInterface*>(view->document()->editor());
  961. KTextEditor::Command *command=cmdIface->queryCommand(cmd);
  962. QString msg; // thrown away
  963. command->exec(view,cmd,msg);
  964. }
  965. void setTabWidth(KTextEditor::View *view, unsigned tabWidth)
  966. {
  967. sendCommand(view,QString("set-tab-width %1").arg(tabWidth));
  968. }
  969. void MainForm::init()
  970. {
  971. QPixmap smallIcon(":/images/ktigcc.png");
  972. QPixmap largeIcon(":/images/icon.png");
  973. QIcon windowIcon(smallIcon);
  974. windowIcon.addPixmap(largeIcon);
  975. setWindowIcon(windowIcon);
  976. #ifdef Q_WS_X11
  977. KWin::setIcons(winId(),largeIcon,smallIcon);
  978. #endif
  979. ticables_library_init();
  980. tifiles_library_init();
  981. ticalcs_library_init();
  982. have_usb=ticables_is_usb_enabled();
  983. compiling=FALSE;
  984. headersModified=FALSE;
  985. loadPreferences();
  986. loadSystemHeaderCompletion();
  987. fileNewFolderAction->setEnabled(FALSE);
  988. te_popup = new Q3PopupMenu(this);
  989. te_popup->insertItem("&Open file at cursor",0);
  990. te_popup->insertItem("&Find symbol declaration",1);
  991. te_popup->insertSeparator();
  992. te_popup->insertItem("&Undo",2);
  993. te_popup->insertItem("&Redo",3);
  994. te_popup->insertSeparator();
  995. te_popup->insertItem("&Clear",4);
  996. te_popup->insertItem("Cu&t",5);
  997. te_popup->insertItem("Cop&y",6);
  998. te_popup->insertItem("&Paste",7);
  999. te_popup->insertSeparator();
  1000. te_popup->insertItem("&Select all",8);
  1001. te_popup->insertSeparator();
  1002. te_popup->insertItem("&Increase indent",9);
  1003. te_popup->insertItem("&Decrease indent",10);
  1004. connect(te_popup,SIGNAL(aboutToShow()),this,SLOT(te_popup_aboutToShow()));
  1005. connect(te_popup,SIGNAL(activated(int)),this,SLOT(te_popup_activated(int)));
  1006. Q3ValueList<int> list;
  1007. list.append(150);
  1008. list.append(500);
  1009. splitter->setSizes(list);
  1010. leftStatusLabel=new QLabel("0 Files Total",this);
  1011. leftStatusLabel->setMaximumWidth(splitter->sizes().first());
  1012. statusBar()->addWidget(leftStatusLabel,1);
  1013. rowStatusLabel=new QLabel("",this);
  1014. rowStatusLabel->setAlignment(Qt::AlignRight);
  1015. statusBar()->addWidget(rowStatusLabel,1);
  1016. rowStatusLabel->hide();
  1017. colStatusLabel=new QLabel("",this);
  1018. colStatusLabel->setAlignment(Qt::AlignRight);
  1019. statusBar()->addWidget(colStatusLabel,1);
  1020. colStatusLabel->hide();
  1021. charsStatusLabel=new QLabel("",this);
  1022. statusBar()->addWidget(charsStatusLabel,1);
  1023. charsStatusLabel->hide();
  1024. rightStatusLabel=new QLabel("",this);
  1025. rightStatusLabel->setMaximumWidth(splitter->sizes().last());
  1026. statusBar()->addWidget(rightStatusLabel,1);
  1027. statusBar()->setSizeGripEnabled(FALSE);
  1028. connect(statusBar(),SIGNAL(messageChanged(const QString &)),this,SLOT(statusBar_messageChanged(const QString &)));
  1029. fileTree->setSorting(-1);
  1030. fileTree->setColumnWidthMode(0,Q3ListView::Maximum);
  1031. fileTree->header()->hide();
  1032. fileTree->setAlternateBackground(QColor());
  1033. rootListItem=new ListViewRoot(fileTree);
  1034. rootListItem->setText(0,"Project1");
  1035. rootListItem->setPixmap(0,SYSICON("exec","tpr.png"));
  1036. rootListItem->setOpen(TRUE);
  1037. Q3ListViewItem *folderListItem=new ListViewFolder(rootListItem);
  1038. hFilesListItem=folderListItem;
  1039. folderListItem->setText(0,"Header Files");
  1040. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1041. cFilesListItem=folderListItem;
  1042. folderListItem->setText(0,"C Files");
  1043. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1044. sFilesListItem=folderListItem;
  1045. folderListItem->setText(0,"GNU Assembly Files");
  1046. char a68k_path[strlen(tigcc_base)+10];
  1047. sprintf(a68k_path, "%s/bin/a68k", tigcc_base);
  1048. if(access(a68k_path, F_OK) != -1) {
  1049. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1050. asmFilesListItem=folderListItem;
  1051. folderListItem->setText(0,"A68k Assembly Files");
  1052. } else {
  1053. qllFilesListItem=NULL;
  1054. fileNewQuillSourceFileAction->setVisible(FALSE);
  1055. }
  1056. if (quill_drv) {
  1057. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1058. qllFilesListItem=folderListItem;
  1059. folderListItem->setText(0,"Quill Files");
  1060. } else {
  1061. qllFilesListItem=NULL;
  1062. fileNewQuillSourceFileAction->setVisible(FALSE);
  1063. }
  1064. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1065. oFilesListItem=folderListItem;
  1066. folderListItem->setText(0,"Object Files");
  1067. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1068. aFilesListItem=folderListItem;
  1069. folderListItem->setText(0,"Archive Files");
  1070. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1071. txtFilesListItem=folderListItem;
  1072. folderListItem->setText(0,"Text Files");
  1073. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  1074. othFilesListItem=folderListItem;
  1075. folderListItem->setText(0,"Other Files");
  1076. khelpmenu=new KHelpMenu(this,pabout);
  1077. assistant=new QAssistantClient("",this);
  1078. QStringList args(QString("-profile"));
  1079. args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
  1080. assistant->setArguments(args);
  1081. lastDirectory=QString("%1/tigcc-projects").arg(QDir::homePath());
  1082. if (!QDir(lastDirectory).exists() && !QDir().mkdir(lastDirectory))
  1083. lastDirectory=QString("%1/projects").arg(tigcc_base);
  1084. projectFileName="";
  1085. projectIsDirty=FALSE;
  1086. projectNeedsRelink=FALSE;
  1087. connect(KDirWatch::self(),SIGNAL(created(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  1088. connect(KDirWatch::self(),SIGNAL(dirty(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  1089. KDirWatch::self()->startScan();
  1090. clipboard=QApplication::clipboard();
  1091. connect(clipboard,SIGNAL(dataChanged()),this,SLOT(clipboard_dataChanged()));
  1092. accel=new Q3Accel(this);
  1093. accel->insertItem(Qt::ALT+Qt::Key_Backspace,0);
  1094. accel->setItemEnabled(0,FALSE);
  1095. accel->insertItem(Qt::SHIFT+Qt::ALT+Qt::Key_Backspace,1);
  1096. accel->setItemEnabled(1,FALSE);
  1097. accel->insertItem(Qt::SHIFT+Qt::Key_Delete,2);
  1098. accel->setItemEnabled(2,FALSE);
  1099. accel->insertItem(Qt::CTRL+Qt::Key_Insert,3);
  1100. accel->setItemEnabled(3,FALSE);
  1101. accel->insertItem(Qt::SHIFT+Qt::Key_Insert,4);
  1102. accel->setItemEnabled(4,FALSE);
  1103. accel->insertItem(Qt::Key_F1,5);
  1104. accel->setItemEnabled(5,FALSE);
  1105. accel->insertItem(Qt::Key_Enter,6);
  1106. accel->setItemEnabled(6,FALSE);
  1107. accel->insertItem(Qt::Key_Return,7);
  1108. accel->setItemEnabled(7,FALSE);
  1109. accel->insertItem(Qt::CTRL+Qt::Key_J,8);
  1110. accel->setItemEnabled(8,FALSE);
  1111. accel->insertItem(Qt::CTRL+Qt::Key_Space,9);
  1112. accel->setItemEnabled(9,FALSE);
  1113. accel->insertItem(Qt::CTRL+Qt::Key_M,10);
  1114. accel->setItemEnabled(10,FALSE);
  1115. accel->insertItem(Qt::CTRL+Qt::Key_Tab,11);
  1116. accel->setItemEnabled(11,TRUE);
  1117. accel->insertItem(Qt::CTRL+Qt::Key_G,12);
  1118. accel->setItemEnabled(12,TRUE);
  1119. accel->insertItem(Qt::SHIFT+Qt::CTRL+Qt::ALT+Qt::Key_F9,13);
  1120. accel->setItemEnabled(13,TRUE);
  1121. accel->insertItem(Qt::SHIFT+Qt::ALT+Qt::Key_F8,14);
  1122. accel->setItemEnabled(14,TRUE);
  1123. accel->insertItem(Qt::CTRL+Qt::ALT+Qt::Key_F9,15);
  1124. accel->setItemEnabled(15,TRUE);
  1125. accel->insertItem(Qt::CTRL+Qt::Key_F9,16);
  1126. accel->setItemEnabled(16,TRUE);
  1127. connect(accel,SIGNAL(activated(int)),this,SLOT(accel_activated(int)));
  1128. fileTreeAccel=new Q3Accel(this);
  1129. fileTreeAccel->insertItem(Qt::Key_Delete,0);
  1130. connect(fileTreeAccel,SIGNAL(activated(int)),
  1131. this,SLOT(fileTreeAccel_activated(int)));
  1132. kfinddialog = static_cast<KFindDialog *>(NULL);
  1133. kreplace = static_cast<KReplaceWithSelection *>(NULL);
  1134. connect(fileNewAction,SIGNAL(triggered()),this,SLOT(fileNewProject()));
  1135. if (preferences.useSystemIcons) {
  1136. // Set the preferred icon size so system toolbar icons don't get annoying
  1137. // padding.
  1138. int toolbarIconSize=KIconLoader().currentSize(K3Icon::MainToolbar);
  1139. setIconSize(QSize(toolbarIconSize,toolbarIconSize));
  1140. fileNewAction->setIcon(KIcon("filenew"));
  1141. fileNewMenu->menuAction()->setIcon(KIcon("filenew"));
  1142. fileOpenAction->setIcon(KIcon("fileopen"));
  1143. fileSaveAllAction->setIcon(KIcon("filesave"));
  1144. filePrintAction->setIcon(KIcon("fileprint"));
  1145. filePrintQuicklyAction->setIcon(KIcon("fileprint"));
  1146. editClearAction->setIcon(KIcon("editdelete"));
  1147. editCutAction->setIcon(KIcon("editcut"));
  1148. editCopyAction->setIcon(KIcon("editcopy"));
  1149. editPasteAction->setIcon(KIcon("editpaste"));
  1150. projectAddFilesAction->setIcon(KIcon("edit_add"));
  1151. projectCompileAction->setIcon(KIcon("compfile"));
  1152. projectMakeAction->setIcon(KIcon("make_kdevelop"));
  1153. projectBuildAction->setIcon(KIcon("rebuild"));
  1154. helpContentsAction->setIcon(KIcon("help"));
  1155. helpDocumentationAction->setIcon(KIcon("help"));
  1156. helpSearchAction->setIcon(KIcon("filefind"));
  1157. findFindAction->setIcon(KIcon("filefind"));
  1158. if (KIconLoader::global()->iconPath("stock-find-and-replace",K3Icon::Small,TRUE).isEmpty())
  1159. findReplaceAction->setIcon(QIcon(QPixmap(":/images/filereplace.png")));
  1160. else
  1161. findReplaceAction->setIcon(KIcon("stock-find-and-replace"));
  1162. helpIndexAction->setIcon(KIcon("contents"));
  1163. editUndoAction->setIcon(KIcon("undo"));
  1164. editRedoAction->setIcon(KIcon("redo"));
  1165. findFunctionsAction->setIcon(KIcon("view_tree"));
  1166. editIncreaseIndentAction->setIcon(KIcon("indent"));
  1167. editDecreaseIndentAction->setIcon(KIcon("unindent"));
  1168. projectStopCompilationAction->setIcon(KIcon("stop"));
  1169. projectForceQuitAction->setIcon(KIcon("button_cancel"));
  1170. helpNewsAction->setIcon(KIcon("kontact_news"));
  1171. debugRunAction->setIcon(KIcon("player_play"));
  1172. debugPauseAction->setIcon(KIcon("player_pause"));
  1173. toolsConfigureAction->setIcon(KIcon("configure"));
  1174. debugResetAction->setIcon(KIcon("player_stop"));
  1175. } else fileNewMenu->menuAction()->setIcon(QIcon(QPixmap(":/images/00.png")));
  1176. QToolButton *fileNewButton=static_cast<QToolButton *>(toolBar
  1177. ->widgetForAction(fileNewAction));
  1178. fileNewButton->setPopupMode(QToolButton::MenuButtonPopup);
  1179. fileNewButton->setMenu(fileNewMenu);
  1180. QToolButton *fileOpenButton=static_cast<QToolButton *>(toolBar
  1181. ->widgetForAction(fileOpenAction));
  1182. QMenu *fileOpenMenu=new QMenu(this);
  1183. fileOpenMenu->setObjectName(QString::fromUtf8("fileOpenMenu"));
  1184. fileOpenMenu->addAction(fileRecent1Action);
  1185. fileOpenMenu->addAction(fileRecent2Action);
  1186. fileOpenMenu->addAction(fileRecent3Action);
  1187. fileOpenMenu->addAction(fileRecent4Action);
  1188. fileOpenButton->setPopupMode(QToolButton::MenuButtonPopup);
  1189. fileOpenButton->setMenu(fileOpenMenu);
  1190. QToolButton *findFunctionsButton=static_cast<QToolButton *>(toolBar
  1191. ->widgetForAction(findFunctionsAction));
  1192. findFunctionsPopup=new Q3PopupMenu(findFunctionsButton);
  1193. connect(findFunctionsPopup,SIGNAL(aboutToShow()),
  1194. this,SLOT(findFunctionsPopup_aboutToShow()));
  1195. connect(findFunctionsPopup,SIGNAL(aboutToHide()),
  1196. this,SLOT(findFunctionsPopup_aboutToHide()));
  1197. connect(findFunctionsPopup,SIGNAL(activated(int)),
  1198. this,SLOT(findFunctionsPopup_activated(int)));
  1199. findFunctionsButton->setPopupMode(QToolButton::MenuButtonPopup);
  1200. findFunctionsButton->setMenu(findFunctionsPopup);
  1201. errorListDock=new QDockWidget("Errors and Warnings",this);
  1202. errorListDock->setFloating(false);
  1203. errorListDock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable);
  1204. errorListDock->setAllowedAreas(Qt::BottomDockWidgetArea);
  1205. errorList=new ErrorList(errorListDock);
  1206. errorListDock->setWidget(errorList);
  1207. addDockWidget(Qt::BottomDockWidgetArea,errorListDock);
  1208. errorList->show();
  1209. errorListDock->hide();
  1210. connect(errorListDock->toggleViewAction(),SIGNAL(toggled(bool)),
  1211. this,SLOT(projectErrorsAndWarnings(bool)));
  1212. errorList->errorListView->setSorting(-1);
  1213. errorList->errorListView->setAlternateBackground(QColor());
  1214. connect(errorList->errorListView,SIGNAL(clicked(Q3ListViewItem *)),
  1215. this,SLOT(errorListView_clicked(Q3ListViewItem *)));
  1216. if (preferences.linkTarget!=LT_TIEMU) {
  1217. debugPauseAction->setEnabled(FALSE);
  1218. debugResetAction->setEnabled(FALSE);
  1219. }
  1220. if (preferences.linkTarget==LT_NONE) {
  1221. menuBar()->setItemVisible(5,FALSE); //debugMenu
  1222. debugRunAction->setVisible(FALSE);
  1223. debugPauseAction->setVisible(FALSE);
  1224. }
  1225. pconfig->setGroup("Recent files");
  1226. if (parg) {
  1227. QString fileName=QDir().absoluteFilePath(parg);
  1228. if (!openProject(fileName)) goto openRecent;
  1229. } else {
  1230. openRecent:;
  1231. QString mostrecent=pconfig->readEntry("Current project");
  1232. if (!mostrecent.isNull() && !mostrecent.isEmpty())
  1233. openProject(mostrecent);
  1234. }
  1235. updateRecent();
  1236. pconfig->setGroup("Tools");
  1237. unsigned toolCount=pconfig->readUnsignedNumEntry("Count",0);
  1238. tools.resize(toolCount);
  1239. for (unsigned idx=0; idx<toolCount; idx++) {
  1240. pconfig->setGroup(QString("Tool %1").arg(idx));
  1241. Tool &tool=tools[idx];
  1242. tool.title=pconfig->readEntry("Title");
  1243. tool.commandLine=pconfig->readEntry("Command Line");
  1244. tool.workingDirectory=pconfig->readEntry("Working Directory");
  1245. tool.runInTerminal=pconfig->readBoolEntry("Terminal");
  1246. }
  1247. updateToolsMenu();
  1248. connect(toolsMenu,SIGNAL(activated(int)),this,SLOT(toolsMenu_activated(int)));
  1249. startTimer(100);
  1250. if (preferences.downloadHeadlines) {
  1251. NewsDialog newsDialog(this);
  1252. if (newsDialog.loadNews())
  1253. newsDialog.exec();
  1254. }
  1255. }
  1256. void MainForm::destroy()
  1257. {
  1258. while (!sourceFiles.isEmpty()) {
  1259. delete sourceFiles.getFirst();
  1260. }
  1261. if (kreplace) delete kreplace;
  1262. if (kfinddialog) delete kfinddialog;
  1263. delete fileTreeAccel;
  1264. delete accel;
  1265. delete te_popup;
  1266. delete leftStatusLabel;
  1267. delete rowStatusLabel;
  1268. delete colStatusLabel;
  1269. delete charsStatusLabel;
  1270. delete rightStatusLabel;
  1271. delete rootListItem;
  1272. delete khelpmenu;
  1273. delete assistant;
  1274. delete errorList;
  1275. delete errorListDock;
  1276. ticalcs_library_exit();
  1277. tifiles_library_exit();
  1278. ticables_library_exit();
  1279. }
  1280. void MainForm::te_popup_aboutToShow()
  1281. {
  1282. te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
  1283. te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
  1284. te_popup->setItemEnabled(2,editUndoAction->isEnabled());
  1285. te_popup->setItemEnabled(3,editRedoAction->isEnabled());
  1286. te_popup->setItemEnabled(4,editClearAction->isEnabled());
  1287. te_popup->setItemEnabled(5,editCutAction->isEnabled());
  1288. te_popup->setItemEnabled(6,editCopyAction->isEnabled());
  1289. te_popup->setItemEnabled(7,editPasteAction->isEnabled());
  1290. te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
  1291. te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
  1292. te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
  1293. }
  1294. void MainForm::te_popup_activated(int index)
  1295. {
  1296. switch (index) {
  1297. case 0: findOpenFileAtCursor(); break;
  1298. case 1: findFindSymbolDeclaration(); break;
  1299. case 2: editUndo(); break;
  1300. case 3: editRedo(); break;
  1301. case 4: editClear(); break;
  1302. case 5: editCut(); break;
  1303. case 6: editCopy(); break;
  1304. case 7: editPaste(); break;
  1305. case 8: editSelectAll(); break;
  1306. case 9: editIncreaseIndent(); break;
  1307. case 10: editDecreaseIndent(); break;
  1308. default: break;
  1309. }
  1310. }
  1311. void MainForm::accel_activated(int index)
  1312. {
  1313. if (CURRENT_VIEW && CURRENT_VIEW->hasFocus()) {
  1314. switch (index) {
  1315. case 0: editUndo(); break;
  1316. case 1: editRedo(); break;
  1317. case 2: editCut(); break;
  1318. case 3: editCopy(); break;
  1319. case 4: editPaste(); break;
  1320. case 5: // F1 context help
  1321. {
  1322. int line,col,i;
  1323. CURRENT_VIEW->cursorPosition().position(line,col);
  1324. QString textLine=CURRENT_VIEW->document()->line(line);
  1325. QString wordUnderCursor;
  1326. for (i=col-1;i>=0;i--) {
  1327. QChar c=textLine[i];
  1328. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  1329. || c=='_' || c=='$' || c=='#')
  1330. wordUnderCursor.prepend(c);
  1331. }
  1332. int len=textLine.length();
  1333. for (i=col;i<len;i++) {
  1334. QChar c=textLine[i];
  1335. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  1336. || c=='_' || c=='$' || c=='#')
  1337. wordUnderCursor.append(c);
  1338. }
  1339. // always open at least the index
  1340. force_qt_assistant_page(1);
  1341. assistant->openAssistant();
  1342. if (wordUnderCursor.isEmpty()) return;
  1343. QString docFile=lookup_doc_keyword(wordUnderCursor);
  1344. if (docFile.isEmpty()) return;
  1345. // wait for Qt Assistant to actually open
  1346. while (!assistant->isOpen())
  1347. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  1348. assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
  1349. break;
  1350. }
  1351. case 6:
  1352. case 7:
  1353. // FIXME: Send ENTER key in some way, or replace newLineHook with a
  1354. // better solution altogether.
  1355. CURRENT_VIEW->document()->startEditing();
  1356. CURRENT_VIEW->removeSelectionText();
  1357. CURRENT_VIEW->insertText("\n");
  1358. CURRENT_VIEW->document()->endEditing();
  1359. current_view_newLineHook();
  1360. break;
  1361. case 8:
  1362. new TemplatePopup(CURRENT_VIEW);
  1363. break;
  1364. case 9:
  1365. case 10:
  1366. if (IS_FILE(currentListItem)
  1367. && CURRENT_VIEW==static_cast<ListViewFile *>(currentListItem)->kateView) {
  1368. QString fileText=CURRENT_VIEW->document()->text();
  1369. CATEGORY_OF(category,currentListItem);
  1370. // Completion only operates on C files.
  1371. if (category==cFilesListItem || category==qllFilesListItem
  1372. || (category==hFilesListItem && !fileText.isEmpty()
  1373. && fileText[0]!='|' && fileText[0]!=';')) {
  1374. // Disable newLineHook.
  1375. accel->setItemEnabled(6,FALSE);
  1376. accel->setItemEnabled(7,FALSE);
  1377. new CompletionPopup(CURRENT_VIEW,pathInProject(currentListItem),this,this);
  1378. }
  1379. }
  1380. break;
  1381. case 11: // next file
  1382. case 12:
  1383. case_11:
  1384. {
  1385. Q3ListViewItem *item=currentListItem;
  1386. if (!item) item=rootListItem;
  1387. Q3ListViewItem *origItem=item;
  1388. do {
  1389. item=item->itemBelow();
  1390. if (!item) item=rootListItem;
  1391. if (item==origItem) return; // no suitable items to select
  1392. } while (item==rootListItem || IS_CATEGORY(item));
  1393. fileTreeClicked(item);
  1394. if (CURRENT_VIEW) CURRENT_VIEW->setFocus();
  1395. break;
  1396. }
  1397. case 13: // switch transfer target
  1398. case 14:
  1399. case_13:
  1400. {
  1401. preferences.linkTarget=(preferences.linkTarget==LT_TIEMU)?LT_REALCALC:LT_TIEMU;
  1402. savePreferences();
  1403. // Apply the preferences to the debug menu.
  1404. debugPauseAction->setEnabled(!compiling&&preferences.linkTarget==LT_TIEMU);
  1405. debugResetAction->setEnabled(!compiling&&preferences.linkTarget==LT_TIEMU);
  1406. bool runnable=!settings.archive&&!settings.flash_os&&preferences.linkTarget!=LT_NONE;
  1407. menuBar()->setItemVisible(5,runnable); //debugMenu
  1408. debugRunAction->setVisible(runnable);
  1409. debugPauseAction->setVisible(runnable);
  1410. break;
  1411. }
  1412. case 15: projectCompile(); break;
  1413. case 16: projectMake(); break;
  1414. default: break;
  1415. }
  1416. } else {
  1417. switch (index) {
  1418. case 6:
  1419. case 7:
  1420. {
  1421. QKeyEvent *keyEvent=new QKeyEvent(QEvent::KeyPress,Qt::Key_Return,'\n',0,"\n");
  1422. QApplication::postEvent(focusWidget(),keyEvent);
  1423. break;
  1424. }
  1425. case 11: goto case_11;
  1426. case 12: goto case_11;
  1427. case 13: goto case_13;
  1428. case 14: goto case_13;
  1429. case 15: projectCompile(); break;
  1430. case 16: projectMake(); break;
  1431. default: break;
  1432. }
  1433. }
  1434. }
  1435. void MainForm::completionPopup_closed()
  1436. {
  1437. if (IS_FILE(currentListItem)) {
  1438. CATEGORY_OF(category,currentListItem->parent());
  1439. if (IS_EDITABLE_CATEGORY(category)) {
  1440. // Restore newLineHook.
  1441. accel->setItemEnabled(6,TRUE);
  1442. accel->setItemEnabled(7,TRUE);
  1443. }
  1444. }
  1445. }
  1446. void MainForm::fileTreeAccel_activated(int index)
  1447. {
  1448. Q3ListViewItem *item=fileTree->currentItem();
  1449. if (!index && item) removeItem(item);
  1450. }
  1451. void MainForm::clearProject()
  1452. {
  1453. headersModified=FALSE;
  1454. newSettings(&settings,&libopts);
  1455. rootListItem->setText(0,"Project1");
  1456. projectFileName="";
  1457. fileTreeClicked(rootListItem);
  1458. // Better do this now or the file destructors will have to iterate over the
  1459. // error list each time, and I'd have to clear the list at the end anyway
  1460. // because an error might not have a source file assigned.
  1461. errorList->errorListView->clear();
  1462. programOutput=QString::null;
  1463. projectProgramOutputAction->setEnabled(FALSE);
  1464. Q3ListViewItem *f, *next;
  1465. for (f=hFilesListItem->firstChild();f;f=next) {
  1466. next=f->nextSibling();
  1467. delete f;
  1468. }
  1469. for (f=cFilesListItem->firstChild();f;f=next) {
  1470. next=f->nextSibling();
  1471. delete f;
  1472. }
  1473. for (f=sFilesListItem->firstChild();f;f=next) {
  1474. next=f->nextSibling();
  1475. delete f;
  1476. }
  1477. if (asmFilesListItem) {
  1478. for (f=asmFilesListItem->firstChild();f;f=next) {
  1479. next=f->nextSibling();
  1480. delete f;
  1481. }
  1482. }
  1483. if (qllFilesListItem) {
  1484. for (f=qllFilesListItem->firstChild();f;f=next) {
  1485. next=f->nextSibling();
  1486. delete f;
  1487. }
  1488. }
  1489. for (f=oFilesListItem->firstChild();f;f=next) {
  1490. next=f->nextSibling();
  1491. delete f;
  1492. }
  1493. for (f=aFilesListItem->firstChild();f;f=next) {
  1494. next=f->nextSibling();
  1495. delete f;
  1496. }
  1497. for (f=txtFilesListItem->firstChild();f;f=next) {
  1498. next=f->nextSibling();
  1499. delete f;
  1500. }
  1501. for (f=othFilesListItem->firstChild();f;f=next) {
  1502. next=f->nextSibling();
  1503. delete f;
  1504. }
  1505. fileCount=cFileCount=hFileCount=sFileCount=asmFileCount=qllFileCount=oFileCount=aFileCount=txtFileCount=othFileCount=0;
  1506. projectCompletion.clear();
  1507. projectIsDirty=FALSE;
  1508. projectNeedsRelink=FALSE;
  1509. menuBar()->setItemVisible(5,preferences.linkTarget!=LT_NONE); //debugMenu
  1510. debugRunAction->setVisible(preferences.linkTarget!=LT_NONE);
  1511. debugPauseAction->setVisible(preferences.linkTarget!=LT_NONE);
  1512. updateLeftStatusLabel();
  1513. }
  1514. void MainForm::fileNewProject()
  1515. {
  1516. if (compiling || savePrompt())
  1517. return;
  1518. clearProject();
  1519. pconfig->setGroup("Recent files");
  1520. pconfig->writeEntry("Current project","");
  1521. pconfig->sync();
  1522. }
  1523. QString MainForm::findFilter(unsigned short job)
  1524. {
  1525. QString ret;
  1526. if (job==TIGCCOpenProjectFileFilter)
  1527. {
  1528. ret="*.tpr *.h *.c *.s ";
  1529. if (asmFilesListItem)
  1530. ret+="*.asm ";
  1531. if (qllFilesListItem)
  1532. ret+="*.qll ";
  1533. ret+="*.txt";
  1534. ret+="|All TIGCC Files ("+ret+")\n"
  1535. TIGCC_TPR_Filter TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  1536. if (asmFilesListItem)
  1537. ret+=TIGCC_ASM_Filter;
  1538. if (qllFilesListItem)
  1539. ret+=TIGCC_QLL_Filter;
  1540. ret+=TIGCC_TXT_Filter TIGCCAllFilter;
  1541. }
  1542. else if (job==TIGCCAddFilesFilter)
  1543. {
  1544. ret="*.h *.c *.s ";
  1545. if (asmFilesListItem)
  1546. ret+="*.asm ";
  1547. if (qllFilesListItem)
  1548. ret+="*.qll ";
  1549. ret+="*.o *.a *.txt";
  1550. ret+="|All TIGCC Files ("+ret+")\n"
  1551. TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  1552. if (asmFilesListItem)
  1553. ret+=TIGCC_ASM_Filter;
  1554. if (qllFilesListItem)
  1555. ret+=TIGCC_QLL_Filter;
  1556. ret+=TIGCC_O_Filter TIGCC_A_Filter TIGCC_TXT_Filter TIGCCAllFilter;
  1557. }
  1558. return ret;
  1559. }
  1560. QString MainForm::SGetFileName(int mode,const QString &fileFilter,const QString &caption,QWidget *parent)
  1561. {
  1562. QString ret;
  1563. if (static_cast<KFileDialog::OperationMode>(mode)==KFileDialog::Opening)
  1564. ret=KFileDialog::getOpenFileName(lastDirectory,fileFilter,parent,caption);
  1565. else
  1566. ret=KFileDialog::getSaveFileName(lastDirectory,fileFilter,parent,caption);
  1567. if (!ret.isNull())
  1568. {
  1569. KUrl dir;
  1570. dir.setPath(ret);
  1571. dir.setFileName("");
  1572. lastDirectory=dir.path();
  1573. }
  1574. return ret;
  1575. }
  1576. //no mode, since it you can't save multiple.
  1577. QStringList MainForm::SGetFileName_Multiple(const QString &fileFilter,const QString &caption,QWidget *parent)
  1578. {
  1579. QStringList ret;
  1580. ret=KFileDialog::getOpenFileNames(lastDirectory,fileFilter,parent,caption);
  1581. if (!ret.empty())
  1582. {
  1583. KUrl dir;
  1584. dir.setPath(ret[0]);
  1585. dir.setFileName("");
  1586. lastDirectory=dir.path();
  1587. }
  1588. return ret;
  1589. }
  1590. void MainForm::updateRecent()
  1591. {
  1592. pconfig->setGroup("Recent files");
  1593. QString recent=pconfig->readEntry("Recent file 1");
  1594. if (recent.isNull())
  1595. fileRecent1Action->setVisible(FALSE);
  1596. else {
  1597. QString recentcut=recent.mid(recent.findRev('/')+1);
  1598. recentcut.truncate(recentcut.findRev('.'));
  1599. fileRecent1Action->setVisible(TRUE);
  1600. fileRecent1Action->setText(recentcut);
  1601. fileRecent1Action->setStatusTip(recent);
  1602. }
  1603. recent=pconfig->readEntry("Recent file 2");
  1604. if (recent.isNull())
  1605. fileRecent2Action->setVisible(FALSE);
  1606. else {
  1607. QString recentcut=recent.mid(recent.findRev('/')+1);
  1608. recentcut.truncate(recentcut.findRev('.'));
  1609. fileRecent2Action->setVisible(TRUE);
  1610. fileRecent2Action->setText(recentcut);
  1611. fileRecent2Action->setStatusTip(recent);
  1612. }
  1613. recent=pconfig->readEntry("Recent file 3");
  1614. if (recent.isNull())
  1615. fileRecent3Action->setVisible(FALSE);
  1616. else {
  1617. QString recentcut=recent.mid(recent.findRev('/')+1);
  1618. recentcut.truncate(recentcut.findRev('.'));
  1619. fileRecent3Action->setVisible(TRUE);
  1620. fileRecent3Action->setText(recentcut);
  1621. fileRecent3Action->setStatusTip(recent);
  1622. }
  1623. recent=pconfig->readEntry("Recent file 4");
  1624. if (recent.isNull())
  1625. fileRecent4Action->setVisible(FALSE);
  1626. else {
  1627. QString recentcut=recent.mid(recent.findRev('/')+1);
  1628. recentcut.truncate(recentcut.findRev('.'));
  1629. fileRecent4Action->setVisible(TRUE);
  1630. fileRecent4Action->setText(recentcut);
  1631. fileRecent4Action->setStatusTip(recent);
  1632. }
  1633. }
  1634. void MainForm::addRecent(const QString &fileName)
  1635. {
  1636. unsigned i,j;
  1637. pconfig->setGroup("Recent files");
  1638. // Find recent file to overwrite. If it isn't one of the first 3, by
  1639. // elimination, it is the last, thus the test only goes up to <4, not <=4.
  1640. for (i=1;i<4;i++) {
  1641. QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
  1642. if (recenti.isNull() || !recenti.compare(fileName))
  1643. break;
  1644. }
  1645. // Move entries up
  1646. for (j=i;j>1;j--) {
  1647. pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
  1648. }
  1649. // The first recent file is the current project.
  1650. pconfig->writeEntry("Recent file 1",fileName);
  1651. pconfig->writeEntry("Current project",fileName);
  1652. pconfig->sync();
  1653. updateRecent();
  1654. }
  1655. Q3ListViewItem * MainForm::openFile(Q3ListViewItem * category, Q3ListViewItem * parent, const QString &fileCaption, const QString &fileName)
  1656. {
  1657. switch (getPathType(fileName)) {
  1658. case PATH_FILE: // OK
  1659. break;
  1660. case PATH_NOTFOUND:
  1661. KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
  1662. return NULL;
  1663. default:
  1664. KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
  1665. return NULL;
  1666. }
  1667. Q3ListViewItem *item=NULL, *next=parent->firstChild();
  1668. for (; IS_FILE(next); next=item->nextSibling())
  1669. item=next;
  1670. ListViewFile *newFile=item?new ListViewFile(parent,item)
  1671. :new ListViewFile(parent);
  1672. newFile->isNew=FALSE;
  1673. newFile->modifiedSinceLastCompile=FALSE;
  1674. newFile->setText(0,fileCaption);
  1675. newFile->setPixmap(0,
  1676. category==cFilesListItem||category==qllFilesListItem?SYSICON("source_c","filec.png"):
  1677. category==hFilesListItem?SYSICON("source_h","fileh.png"):
  1678. category==sFilesListItem||category==asmFilesListItem?SYSICON("source_s","files.png"):
  1679. category==txtFilesListItem?SYSICON("txt","filet.png"):
  1680. category==oFilesListItem||category==aFilesListItem?SYSICON("binary","fileo.png"):
  1681. SYSICON("unknown","filex.png"));
  1682. newFile->fileName=fileName;
  1683. if (IS_EDITABLE_CATEGORY(category)) {
  1684. newFile->kateView=reinterpret_cast<KTextEditor::View *>(createView(fileName,QString::null,category));
  1685. KDirWatch::self()->addFile(fileName);
  1686. }
  1687. fileCount++;
  1688. COUNTER_FOR_CATEGORY(category)++;
  1689. return newFile;
  1690. }
  1691. Q3ListViewItem *MainForm::createFolder(Q3ListViewItem *parent,const QString &name)
  1692. {
  1693. Q3ListViewItem *item=parent->firstChild();
  1694. Q3ListViewItem *startItem=item;
  1695. Q3ListViewItem *newItem;
  1696. for (; item; item=item->nextSibling())
  1697. {
  1698. if (IS_FOLDER(item) && !item->text(0).compare(name))
  1699. return item;
  1700. }
  1701. item=NULL;
  1702. for (;startItem;startItem=item->nextSibling())
  1703. item=startItem;
  1704. newItem=item?new ListViewFolder(parent,item)
  1705. :new ListViewFolder(parent);
  1706. newItem->setText(0,name);
  1707. newItem->setOpen(TRUE);
  1708. return newItem;
  1709. }
  1710. void *MainForm::createView(const QString &fileName, const QString &fileText, Q3ListViewItem *category)
  1711. {
  1712. // Create Document object.
  1713. KParts::Factory *factory = (KParts::Factory *)
  1714. KLibLoader::self()->factory ("katepart");
  1715. if (!factory) qFatal("Failed to load KatePart");
  1716. KTextEditor::Document *doc = (KTextEditor::Document *)
  1717. factory->createPart(0,this,"KTextEditor::Document");
  1718. // Open the file.
  1719. doc->setEncoding(preferences.useCalcCharset?"TI-89":QTextCodec::codecForLocale()->name());
  1720. if (!fileName.isNull()) doc->openUrl(KUrl(fileName));
  1721. // Set text.
  1722. if (!fileText.isNull()) {
  1723. SET_TEXT_SAFE(doc,fileText);
  1724. doc->setModified(FALSE);
  1725. // FIXME
  1726. // newView->document()->clearUndo();
  1727. // newView->document()->clearRedo();
  1728. }
  1729. // Create View object.
  1730. KTextEditor::View *newView = (KTextEditor::View *) doc->createView(widgetStack);
  1731. newView->hide();
  1732. newView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored,0,0));
  1733. // Set highlighting mode.
  1734. KTextEditor::HighlightingInterface *hliface
  1735. =qobject_cast<KTextEditor::HighlightingInterface*>(newView->document());
  1736. QString firstLine;
  1737. if (doc->lines()) firstLine=doc->line(0);
  1738. hliface->setHighlighting(
  1739. (category==qllFilesListItem?
  1740. QLL_HL_MODE:
  1741. (category==sFilesListItem||(category==hFilesListItem&&!firstLine.isEmpty()&&firstLine[0]=='|'))?
  1742. S_HL_MODE:
  1743. (category==asmFilesListItem||(category==hFilesListItem&&!firstLine.isEmpty()&&firstLine[0]==';'))?
  1744. ASM_HL_MODE:
  1745. (category==cFilesListItem||category==hFilesListItem)?
  1746. C_HL_MODE:
  1747. "None"));
  1748. // Set options.
  1749. KTextEditor::ConfigInterface *configiface
  1750. =qobject_cast<KTextEditor::ConfigInterface*>(newView);
  1751. configiface->setConfigValue("dynamic-word-wrap",false);
  1752. if (preferences.removeTrailingSpaces) {
  1753. sendCommand(newView,"set-remove-trailing-space 1");
  1754. sendCommand(newView,"set-remove-trailing-space-save 1");
  1755. } else {
  1756. sendCommand(newView,"set-remove-trailing-space 0");
  1757. sendCommand(newView,"set-remove-trailing-space-save 0");
  1758. }
  1759. setTabWidth(newView,
  1760. (category==sFilesListItem||category==asmFilesListItem||((category==hFilesListItem&&!firstLine.isEmpty()&&(firstLine[0]=='|'||firstLine[0]==';'))))?preferences.tabWidthAsm:
  1761. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?preferences.tabWidthC:
  1762. 8
  1763. );
  1764. connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
  1765. connect(newView->document(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
  1766. connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
  1767. connect(newView->document(),SIGNAL(selectionChanged()),this,SLOT(current_view_selectionChanged()));
  1768. connect(newView->document(),SIGNAL(charactersInteractivelyInserted(int,int,const QString&)),this,SLOT(current_view_charactersInteractivelyInserted(int,int,const QString&)));
  1769. newView->setContextMenu(te_popup);
  1770. newView->setCursorPosition(KTextEditor::Cursor(0,0));
  1771. return newView;
  1772. }
  1773. void MainForm::adoptSourceFile(void *srcFile)
  1774. {
  1775. if (compiling) return;
  1776. SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
  1777. QString fileName=sourceFile->fileName;
  1778. KTextEditor::View *newView=sourceFile->kateView;
  1779. // Determine category and caption.
  1780. Q3ListViewItem *category=othFilesListItem;
  1781. QString suffix,caption;
  1782. int p;
  1783. p=fileName.findRev('/');
  1784. if (p<0) p=-1;
  1785. caption=fileName.mid(p+1);
  1786. p=caption.findRev('.');
  1787. if (p>=0) {
  1788. suffix=caption.mid(p+1);
  1789. caption.truncate(p);
  1790. }
  1791. if (!checkFileName(fileName,extractAllFileNames())) {
  1792. KMessageBox::error(this,QString("The file \'%1\' is already included in the project.").arg(caption));
  1793. return;
  1794. }
  1795. if (!suffix.compare("h"))
  1796. category=hFilesListItem;
  1797. else if (!suffix.compare("c"))
  1798. category=cFilesListItem;
  1799. else if (!suffix.compare("s"))
  1800. category=sFilesListItem;
  1801. else if (!suffix.compare("asm"))
  1802. category=asmFilesListItem;
  1803. else if (!suffix.compare("qll"))
  1804. category=qllFilesListItem;
  1805. else
  1806. category=txtFilesListItem;
  1807. if (category && category==qllFilesListItem && qllFileCount) {
  1808. KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
  1809. return;
  1810. }
  1811. if (!category)
  1812. category=txtFilesListItem;
  1813. // Create file tree entry.
  1814. Q3ListViewItem *item=NULL, *next=category->firstChild();
  1815. for (; IS_FILE(next); next=item->nextSibling())
  1816. item=next;
  1817. ListViewFile *newFile=item?new ListViewFile(category,item)
  1818. :new ListViewFile(category);
  1819. newFile->isNew=FALSE;
  1820. newFile->setText(0,caption);
  1821. newFile->setPixmap(0,
  1822. category==cFilesListItem||category==qllFilesListItem?SYSICON("source_c","filec.png"):
  1823. category==hFilesListItem?SYSICON("source_h","fileh.png"):
  1824. category==sFilesListItem||category==asmFilesListItem?SYSICON("source_s","files.png"):
  1825. SYSICON("txt","filet.png"));
  1826. newFile->fileName=fileName;
  1827. newFile->modifiedSinceLastCompile=newView->document()->isModified();
  1828. // Adopt View object.
  1829. newFile->kateView=newView;
  1830. newView->hide();
  1831. newView->reparent(widgetStack,QPoint());
  1832. newView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored,0,0));
  1833. KDirWatch::self()->addFile(fileName);
  1834. fileCount++;
  1835. COUNTER_FOR_CATEGORY(category)++;
  1836. // Set highlighting mode.
  1837. QString fileText=newView->document()->text();
  1838. KTextEditor::HighlightingInterface *hliface
  1839. =qobject_cast<KTextEditor::HighlightingInterface*>(newView->document());
  1840. hliface->setHighlighting(
  1841. (category==qllFilesListItem?
  1842. QLL_HL_MODE:
  1843. (category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
  1844. S_HL_MODE:
  1845. (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
  1846. ASM_HL_MODE:
  1847. (category==cFilesListItem||category==hFilesListItem)?
  1848. C_HL_MODE:
  1849. "None"));
  1850. // Set options.
  1851. setTabWidth(newView,
  1852. (category==sFilesListItem||category==asmFilesListItem||((category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&(fileText[0]=='|'||fileText[0]==';'))))?preferences.tabWidthAsm:
  1853. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?preferences.tabWidthC:
  1854. 8
  1855. );
  1856. connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
  1857. connect(newView->document(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
  1858. connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
  1859. connect(newView->document(),SIGNAL(selectionChanged()),this,SLOT(current_view_selectionChanged()));
  1860. connect(newView->document(),SIGNAL(charactersInteractivelyInserted(int,int,const QString&)),this,SLOT(current_view_charactersInteractivelyInserted(int,int,const QString&)));
  1861. newView->setContextMenu(te_popup);
  1862. // Mark project dirty.
  1863. projectIsDirty=TRUE;
  1864. projectNeedsRelink=TRUE;
  1865. // Select file.
  1866. fileTreeClicked(newFile);
  1867. // Update errors to point to the in-project source file instead of the
  1868. // external one.
  1869. Q3ListViewItemIterator lvit(errorList->errorListView);
  1870. Q3ListViewItem *errorItem;
  1871. for (errorItem=lvit.current();errorItem;errorItem=(++lvit).current()) {
  1872. if (static_cast<ErrorListItem *>(errorItem)->srcFile==sourceFile) {
  1873. static_cast<ErrorListItem *>(errorItem)->srcFile=static_cast<SourceFile *>(NULL);
  1874. static_cast<ErrorListItem *>(errorItem)->lvFile=newFile;
  1875. }
  1876. }
  1877. // Close separate source view.
  1878. sourceFile->kateView=static_cast<KTextEditor::View *>(NULL);
  1879. sourceFile->deleteLater();
  1880. }
  1881. void MainForm::fileOpen_addList(Q3ListViewItem *category,void *fileListV,void *dir, const QString &open_file)
  1882. {
  1883. int i,e;
  1884. int p,pslash;
  1885. KUrl tmp;
  1886. TPRFileList *fileList=(TPRFileList*)fileListV;
  1887. QString caption;
  1888. QString treePath;
  1889. Q3ListViewItem *parent;
  1890. e=fileList->path.count();
  1891. if (e) category->setOpen(TRUE);
  1892. for (i=0;i<e;i++)
  1893. {
  1894. tmp=*reinterpret_cast<const KUrl *>(dir);
  1895. kurlNewFileName(tmp,fileList->path[i]);
  1896. caption=fileList->path[i];
  1897. //fixed suffix truncation for file paths such as "/root/.dot/nodot" so it wouldn't truncate to "/root/"
  1898. p=caption.findRev('.');
  1899. pslash=caption.findRev('/');
  1900. if (p>=0&&p>pslash) caption.truncate(p);
  1901. if (pslash>=0) caption.remove(0,pslash+1);
  1902. treePath=fileList->folder[i].trimmed();
  1903. //check for a backslash at the end and remove it if it's there.
  1904. if (!treePath.isEmpty() && treePath[treePath.length()-1]=='\\')
  1905. treePath.truncate(treePath.length()-1);
  1906. parent=category;
  1907. if (!treePath.isEmpty())
  1908. {
  1909. while ((p=treePath.find('\\'))>=0)
  1910. {
  1911. parent=createFolder(parent,treePath.left(p));
  1912. treePath.remove(0,p+1);
  1913. }
  1914. parent=createFolder(parent,treePath);
  1915. }
  1916. ListViewFile *newFile=static_cast<ListViewFile *>(openFile(category,parent,caption,tmp.path()));
  1917. if (!newFile) continue;
  1918. if (!newFile->fileName.compare(open_file))
  1919. fileTreeClicked(newFile);
  1920. }
  1921. }
  1922. // Returns TRUE if the file is a project, FALSE if the file is a source file.
  1923. bool MainForm::openProject(const QString &fileName)
  1924. {
  1925. TPRDataStruct TPRData;
  1926. KUrl dir;
  1927. bool isProject=fileName.endsWith(".tpr",FALSE);
  1928. dir.setPath(fileName);
  1929. switch (getPathType(fileName)) {
  1930. case PATH_FILE: // OK
  1931. break;
  1932. case PATH_NOTFOUND:
  1933. KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
  1934. return isProject;
  1935. default:
  1936. KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
  1937. return isProject;
  1938. }
  1939. if (isProject) {
  1940. int ret=loadTPR(fileName, &TPRData);
  1941. if (ret == -1) {
  1942. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  1943. return TRUE;
  1944. }
  1945. if (ret > 0) {
  1946. KMessageBox::error(this,QString("Error at line %2 of \'%1\'").arg(fileName).arg(ret));
  1947. return TRUE;
  1948. }
  1949. if (TPRData.asm_files.path.count() && !asmFilesListItem) {
  1950. KMessageBox::error(this,"This project needs A68k, which is not installed.");
  1951. return TRUE;
  1952. }
  1953. if (TPRData.quill_files.path.count() && !qllFilesListItem) {
  1954. KMessageBox::error(this,"This project needs quill.drv, which is not installed.");
  1955. return TRUE;
  1956. }
  1957. if (TPRData.settings.fargo && !have_fargo) {
  1958. KMessageBox::error(this,"This project needs fargo.a, which is not installed.");
  1959. return TRUE;
  1960. }
  1961. if (TPRData.settings.flash_os && !have_flashos) {
  1962. KMessageBox::error(this,"This project needs flashos.a, which is not installed.");
  1963. return TRUE;
  1964. }
  1965. clearProject();
  1966. fileOpen_addList(hFilesListItem,&TPRData.h_files,&dir,TPRData.open_file);
  1967. fileOpen_addList(cFilesListItem,&TPRData.c_files,&dir,TPRData.open_file);
  1968. fileOpen_addList(qllFilesListItem,&TPRData.quill_files,&dir,TPRData.open_file);
  1969. fileOpen_addList(sFilesListItem,&TPRData.s_files,&dir,TPRData.open_file);
  1970. fileOpen_addList(asmFilesListItem,&TPRData.asm_files,&dir,TPRData.open_file);
  1971. fileOpen_addList(oFilesListItem,&TPRData.o_files,&dir,TPRData.open_file);
  1972. fileOpen_addList(aFilesListItem,&TPRData.a_files,&dir,TPRData.open_file);
  1973. fileOpen_addList(txtFilesListItem,&TPRData.txt_files,&dir,TPRData.open_file);
  1974. fileOpen_addList(othFilesListItem,&TPRData.oth_files,&dir,TPRData.open_file);
  1975. rootListItem->setText(0,TPRData.prj_name);
  1976. projectFileName=fileName;
  1977. settings=TPRData.settings;
  1978. libopts=TPRData.libopts;
  1979. bool runnable=!settings.archive&&!settings.flash_os&&preferences.linkTarget!=LT_NONE;
  1980. menuBar()->setItemVisible(5,runnable); //debugMenu
  1981. debugRunAction->setVisible(runnable);
  1982. debugPauseAction->setVisible(runnable);
  1983. updateLeftStatusLabel();
  1984. updateRightStatusLabel();
  1985. addRecent(fileName);
  1986. return TRUE;
  1987. } else {
  1988. Q3ListViewItem *category=othFilesListItem;
  1989. QString suffix,caption;
  1990. int p;
  1991. p=fileName.findRev('/');
  1992. if (p<0) p=-1;
  1993. caption=fileName.mid(p+1);
  1994. p=caption.findRev('.');
  1995. if (p>=0) {
  1996. suffix=caption.mid(p+1);
  1997. caption.truncate(p);
  1998. }
  1999. if (extractAllFileNames().contains(fileName)) {
  2000. KMessageBox::error(this,QString("The file \'%1\' is already included in the project.").arg(caption));
  2001. return FALSE;
  2002. }
  2003. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  2004. SourceFile *sourceFile;
  2005. for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  2006. if (!fileName.compare(sourceFile->fileName)) {
  2007. ACTIVATE_WINDOW(sourceFile->winId());
  2008. return FALSE;
  2009. }
  2010. }
  2011. if (!suffix.compare("h"))
  2012. category=hFilesListItem;
  2013. else if (!suffix.compare("c"))
  2014. category=cFilesListItem;
  2015. else if (!suffix.compare("s"))
  2016. category=sFilesListItem;
  2017. else if (!suffix.compare("asm") && asmFilesListItem)
  2018. category=asmFilesListItem;
  2019. else if (!suffix.compare("qll") && qllFilesListItem)
  2020. category=qllFilesListItem;
  2021. else if (!suffix.compare("txt"))
  2022. category=txtFilesListItem;
  2023. else {
  2024. KMessageBox::error(this,QString("\'%1\' is not a valid file for opening.").arg(fileName));
  2025. return FALSE;
  2026. }
  2027. int firstChar=peekFirstChar(fileName);
  2028. if (firstChar==-2) {
  2029. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  2030. return FALSE;
  2031. }
  2032. int type=((category==sFilesListItem||(category==hFilesListItem&&firstChar=='|'))?
  2033. 2:
  2034. (category==asmFilesListItem||(category==hFilesListItem&&firstChar==';'))?
  2035. 3:
  2036. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?
  2037. 1:
  2038. 0);
  2039. new SourceFile(this,fileName,
  2040. (category==qllFilesListItem)?QLL_ENABLED_HL_MODE:
  2041. (type==2)?S_ENABLED_HL_MODE:
  2042. (type==3)?ASM_ENABLED_HL_MODE:
  2043. (type==1)?C_ENABLED_HL_MODE:
  2044. "None",
  2045. (category==qllFilesListItem)?&(preferences.synQll.enabled):
  2046. (type==2)?&(preferences.synS.enabled):
  2047. (type==3)?&(preferences.synAsm.enabled):
  2048. (type==1)?&(preferences.synC.enabled):
  2049. NULL,category,(type==1),(type>1),category==txtFilesListItem);
  2050. return FALSE;
  2051. }
  2052. }
  2053. void MainForm::fileOpen()
  2054. {
  2055. if (compiling || savePrompt())
  2056. return;
  2057. QString fileName=SGetFileName(KFileDialog::Opening,findFilter(TIGCCOpenProjectFileFilter),"Open Project/File",this);
  2058. KUrl dir;
  2059. dir.setPath(fileName);
  2060. if (fileName.isEmpty())
  2061. return;
  2062. openProject(fileName);
  2063. }
  2064. void MainForm::fileRecent1()
  2065. {
  2066. if (compiling || savePrompt())
  2067. return;
  2068. openProject(fileRecent1Action->statusTip());
  2069. }
  2070. void MainForm::fileRecent2()
  2071. {
  2072. if (compiling || savePrompt())
  2073. return;
  2074. openProject(fileRecent2Action->statusTip());
  2075. }
  2076. void MainForm::fileRecent3()
  2077. {
  2078. if (compiling || savePrompt())
  2079. return;
  2080. openProject(fileRecent3Action->statusTip());
  2081. }
  2082. void MainForm::fileRecent4()
  2083. {
  2084. if (compiling || savePrompt())
  2085. return;
  2086. openProject(fileRecent4Action->statusTip());
  2087. }
  2088. int MainForm::fileSavePrompt(Q3ListViewItem *fileItem)
  2089. {
  2090. int result;
  2091. ListViewFile *theFile=static_cast<ListViewFile *>(fileItem);
  2092. if (!theFile->kateView) return 0;
  2093. while (theFile->kateView->document()->isModified()) { // "while" in case saving fails!
  2094. result=KMessageBox::questionYesNoCancel(this,QString("The file \'%1\' has been modified. Do you want to save the changes?").arg(theFile->text(0)),QString::null,KStandardGuiItem::save(),KStandardGuiItem::discard());
  2095. if (result==KMessageBox::Yes)
  2096. fileSave_save(fileItem);
  2097. else if (result==KMessageBox::No)
  2098. return 0;
  2099. else
  2100. return 1;
  2101. }
  2102. return 0;
  2103. }
  2104. //returns 1 if the current project data should not be cleared out, 0 if it can be cleared out.
  2105. int MainForm::savePrompt(void)
  2106. {
  2107. int result;
  2108. while (projectIsDirty) {
  2109. result=KMessageBox::questionYesNoCancel(this,"The current project has been modified. Do you want to save the changes?",QString::null,KStandardGuiItem::save(),KStandardGuiItem::discard());
  2110. if (result==KMessageBox::Yes)
  2111. fileSave();
  2112. else if (result==KMessageBox::No)
  2113. return 0;
  2114. else
  2115. return 1;
  2116. }
  2117. Q3ListViewItem *item=rootListItem->firstChild(),*next;
  2118. while (item)
  2119. {
  2120. if (IS_FOLDER(item))
  2121. {
  2122. next=item->firstChild();
  2123. if (next)
  2124. {
  2125. item=next;
  2126. continue;
  2127. }
  2128. }
  2129. if (IS_FILE(item))
  2130. {
  2131. if (fileSavePrompt(item))
  2132. return 1;
  2133. }
  2134. next=item->nextSibling();
  2135. while (!next)
  2136. {
  2137. next=item->parent();
  2138. if (next==rootListItem||!next)
  2139. {
  2140. return 0;
  2141. }
  2142. item=next;
  2143. next=item->nextSibling();
  2144. }
  2145. item=next;
  2146. }
  2147. return 0;
  2148. }
  2149. void MainForm::removeTrailingSpacesFromView(void *view)
  2150. {
  2151. if (!preferences.removeTrailingSpaces) return;
  2152. KTextEditor::View *kateView=reinterpret_cast<KTextEditor::View *>(view);
  2153. KTextEditor::Document *doc=kateView->document();
  2154. doc->startEditing();
  2155. int numLines=doc->lines();
  2156. for (int i=0; i<numLines; i++) {
  2157. QString line=doc->line(i);
  2158. int whitespace=line.find(QRegExp("\\s+$"));
  2159. if (whitespace>=0) doc->removeText(KTextEditor::Range(i,whitespace,i,line.length()));
  2160. }
  2161. doc->endEditing();
  2162. }
  2163. void MainForm::fileSave_save(Q3ListViewItem *theItem)
  2164. {
  2165. if (!IS_FILE(theItem))
  2166. return;
  2167. CATEGORY_OF(category,theItem);
  2168. if (!IS_EDITABLE_CATEGORY(category))
  2169. return;
  2170. ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
  2171. if (!theFile->fileName.isEmpty() && theFile->fileName[0]!='/') {
  2172. fileSave_saveAs(theFile);
  2173. }
  2174. else {
  2175. KDirWatch::self()->removeFile(theFile->fileName);
  2176. if (!theFile->kateView->document()->save()) {
  2177. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(theFile->text(0)));
  2178. KDirWatch::self()->addFile(theFile->fileName);
  2179. }
  2180. else {
  2181. KDirWatch::self()->addFile(theFile->fileName);
  2182. theFile->isNew=FALSE;
  2183. if (theFile->kateView) {
  2184. removeTrailingSpacesFromView(theFile->kateView);
  2185. theFile->kateView->document()->setModified(FALSE);
  2186. }
  2187. projectIsDirty=TRUE;
  2188. projectNeedsRelink=TRUE;
  2189. }
  2190. }
  2191. }
  2192. void MainForm::fileSave_saveAs(Q3ListViewItem *theItem)
  2193. {
  2194. if (!IS_FILE(theItem))
  2195. return;
  2196. CATEGORY_OF(category,theItem);
  2197. QString saveFileName=SGetFileName(KFileDialog::Saving,
  2198. category==hFilesListItem?TIGCC_H_Filter TIGCCAllFilter:
  2199. category==cFilesListItem?TIGCC_C_Filter TIGCCAllFilter:
  2200. category==sFilesListItem?TIGCC_S_Filter TIGCCAllFilter:
  2201. category==asmFilesListItem?TIGCC_ASM_Filter TIGCCAllFilter:
  2202. category==qllFilesListItem?TIGCC_QLL_Filter TIGCCAllFilter:
  2203. category==oFilesListItem?TIGCC_O_Filter TIGCCAllFilter:
  2204. category==aFilesListItem?TIGCC_A_Filter TIGCCAllFilter:
  2205. category==txtFilesListItem?TIGCC_TXT_Filter TIGCCAllFilter:
  2206. TIGCCAllFilter
  2207. ,"Save Source File",this);
  2208. ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
  2209. if (saveFileName.isEmpty()
  2210. || (!IS_EDITABLE_CATEGORY(category)
  2211. && !saveFileName.compare(theFile->fileName)))
  2212. return;
  2213. if (saveFileName.compare(theFile->fileName)
  2214. && !checkFileName(saveFileName,extractAllFileNames())) {
  2215. KMessageBox::error(this,"The name you chose conflicts with that of another file.");
  2216. return;
  2217. }
  2218. if (!theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
  2219. KDirWatch::self()->removeFile(theFile->fileName);
  2220. mkdir_multi(saveFileName);
  2221. if (IS_EDITABLE_CATEGORY(category)
  2222. ?!theFile->kateView->document()->saveAs(saveFileName)
  2223. :copyFile(theFile->fileName,saveFileName)) {
  2224. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
  2225. if (IS_EDITABLE_CATEGORY(category) && !theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
  2226. KDirWatch::self()->addFile(theFile->fileName);
  2227. } else {
  2228. theFile->fileName=saveFileName;
  2229. if (IS_EDITABLE_CATEGORY(category)) {
  2230. KDirWatch::self()->addFile(saveFileName);
  2231. removeTrailingSpacesFromView(theFile->kateView);
  2232. theFile->kateView->document()->setModified(FALSE);
  2233. }
  2234. theFile->isNew=FALSE;
  2235. updateRightStatusLabel();
  2236. projectIsDirty=TRUE;
  2237. projectNeedsRelink=TRUE;
  2238. }
  2239. }
  2240. //loadList also saves the file contents
  2241. void MainForm::fileSave_loadList(Q3ListViewItem *category,void *fileListV,const QString &base_dir,void *dir_new,QString *open_file)
  2242. {
  2243. if (!category)
  2244. return;
  2245. TPRFileList *fileList=(TPRFileList*)fileListV;
  2246. KUrl *new_dir=(KUrl*)dir_new;
  2247. KUrl tmpPath;
  2248. Q3ListViewItem *item=category->firstChild();
  2249. Q3ListViewItem *next;
  2250. QString folderSpec=QString::null;
  2251. int o;
  2252. while (item)
  2253. {
  2254. if (IS_FILE(item))
  2255. {
  2256. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  2257. QString absPath=theFile->fileName;
  2258. QString relPath=KUrl::relativePath(base_dir,absPath);
  2259. if (relPath.startsWith("./"))
  2260. {
  2261. relPath=relPath.mid(2);
  2262. }
  2263. else if (relPath.startsWith("../"))
  2264. {
  2265. relPath=absPath;
  2266. }
  2267. tmpPath=*new_dir;
  2268. kurlNewFileName(tmpPath,relPath);
  2269. if (!theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
  2270. KDirWatch::self()->removeFile(theFile->fileName);
  2271. if (tmpPath.path().compare(theFile->fileName)
  2272. || (IS_EDITABLE_CATEGORY(category)
  2273. && (theFile->kateView->document()->isModified() || theFile->isNew))) {
  2274. mkdir_multi(tmpPath.path());
  2275. if (IS_EDITABLE_CATEGORY(category)
  2276. ?!theFile->kateView->document()->saveAs(tmpPath.path())
  2277. :copyFile(theFile->fileName,tmpPath.path())) {
  2278. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(tmpPath.path()));
  2279. if (IS_EDITABLE_CATEGORY(category) && !theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
  2280. KDirWatch::self()->addFile(theFile->fileName);
  2281. } else {
  2282. QString saveFileName=tmpPath.path();
  2283. theFile->fileName=saveFileName;
  2284. if (IS_EDITABLE_CATEGORY(category)) {
  2285. KDirWatch::self()->addFile(theFile->fileName);
  2286. removeTrailingSpacesFromView(theFile->kateView);
  2287. theFile->kateView->document()->setModified(FALSE);
  2288. }
  2289. theFile->isNew=FALSE;
  2290. projectIsDirty=TRUE; // in case saving the project fails
  2291. projectNeedsRelink=TRUE;
  2292. }
  2293. }
  2294. fileList->path << relPath;
  2295. fileList->folder << folderSpec;
  2296. if (item==currentListItem)
  2297. *open_file=theFile->fileName;
  2298. }
  2299. else if (IS_FOLDER(item))
  2300. {
  2301. next=item->firstChild();
  2302. if (next)
  2303. {
  2304. if (folderSpec.isEmpty())
  2305. folderSpec=item->text(0);
  2306. else
  2307. {
  2308. folderSpec+='\\';
  2309. folderSpec+=item->text(0);
  2310. }
  2311. item=next;
  2312. continue;
  2313. }
  2314. }
  2315. fsll_seeknext:
  2316. next=item->nextSibling();
  2317. if (!next)
  2318. {
  2319. next=item->parent();
  2320. if (next==category||!next)
  2321. break;
  2322. item=next;
  2323. o=folderSpec.findRev('\\');
  2324. if (o>=0)
  2325. folderSpec.truncate(o);
  2326. else
  2327. folderSpec.truncate(0);
  2328. goto fsll_seeknext;
  2329. }
  2330. item=next;
  2331. }
  2332. }
  2333. void MainForm::fileSave_fromto(const QString &lastProj,const QString &nextProj)
  2334. {
  2335. TPRDataStruct TPRData;
  2336. QString open_file;
  2337. KUrl base_dir_k(lastProj);
  2338. base_dir_k.setFileName("");
  2339. QString base_dir=base_dir_k.path();
  2340. KUrl new_dir(nextProj);
  2341. fileSave_loadList(hFilesListItem,&TPRData.h_files,base_dir,&new_dir,&open_file);
  2342. fileSave_loadList(cFilesListItem,&TPRData.c_files,base_dir,&new_dir,&open_file);
  2343. fileSave_loadList(qllFilesListItem,&TPRData.quill_files,base_dir,&new_dir,&open_file);
  2344. fileSave_loadList(sFilesListItem,&TPRData.s_files,base_dir,&new_dir,&open_file);
  2345. fileSave_loadList(asmFilesListItem,&TPRData.asm_files,base_dir,&new_dir,&open_file);
  2346. fileSave_loadList(oFilesListItem,&TPRData.o_files,base_dir,&new_dir,&open_file);
  2347. fileSave_loadList(aFilesListItem,&TPRData.a_files,base_dir,&new_dir,&open_file);
  2348. fileSave_loadList(txtFilesListItem,&TPRData.txt_files,base_dir,&new_dir,&open_file);
  2349. fileSave_loadList(othFilesListItem,&TPRData.oth_files,base_dir,&new_dir,&open_file);
  2350. if (projectFileName.isEmpty() && rootListItem->text(0)=="Project1")
  2351. fileTreeItemRenamed(rootListItem,QFileInfo(nextProj).baseName(),0);
  2352. TPRData.prj_name=rootListItem->text(0);
  2353. TPRData.open_file=open_file;
  2354. TPRData.settings=settings;
  2355. TPRData.libopts=libopts;
  2356. if (saveTPR(nextProj,&TPRData)) {
  2357. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(nextProj));
  2358. updateRightStatusLabel();
  2359. return;
  2360. } else {
  2361. projectFileName=nextProj;
  2362. projectIsDirty=FALSE;
  2363. addRecent(nextProj);
  2364. }
  2365. updateRightStatusLabel();
  2366. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  2367. for (SourceFile *sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  2368. if (sourceFile->kateView->document()->isModified())
  2369. sourceFile->fileSave();
  2370. }
  2371. }
  2372. bool MainForm::fileSave()
  2373. {
  2374. if (projectFileName.isEmpty())
  2375. return fileSaveAs();
  2376. else {
  2377. fileSave_fromto(projectFileName,projectFileName);
  2378. return TRUE;
  2379. }
  2380. }
  2381. bool MainForm::fileSaveAs()
  2382. {
  2383. QString fileName=SGetFileName(KFileDialog::Saving,TIGCC_TPR_Filter TIGCCAllFilter,"Save Project",this);
  2384. if (fileName.isEmpty())
  2385. return FALSE;
  2386. fileSave_fromto(projectFileName.isEmpty()?fileName:projectFileName,fileName);
  2387. return TRUE;
  2388. }
  2389. void MainForm::filePrint()
  2390. {
  2391. if (CURRENT_VIEW) CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Print))->trigger();
  2392. }
  2393. void MainForm::filePrintQuickly()
  2394. {
  2395. // This still shows the print dialog, but then KDE 3.5 Kate did that too
  2396. // despite having 2 nominally different APIs (print and printDialog).
  2397. if (CURRENT_VIEW) CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Print))->trigger();
  2398. }
  2399. void MainForm::filePreferences()
  2400. {
  2401. if (showPreferencesDialog(this,!!asmFilesListItem,!!qllFilesListItem)
  2402. ==QDialog::Accepted) {
  2403. // Apply the KatePart preferences and treeview icons.
  2404. Q3ListViewItemIterator it(fileTree);
  2405. Q3ListViewItem *item;
  2406. // Kate seems really insisting on making it a pain to update syntax highlighting settings.
  2407. for (item=it.current();item;item=(++it).current()) {
  2408. if (IS_FILE(item)) {
  2409. KTextEditor::View *kateView=static_cast<ListViewFile *>(item)->kateView;
  2410. if (kateView) {
  2411. KTextEditor::HighlightingInterface *hliface
  2412. =qobject_cast<KTextEditor::HighlightingInterface*>(kateView->document());
  2413. hliface->setHighlighting("None");
  2414. }
  2415. }
  2416. }
  2417. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  2418. SourceFile *sourceFile;
  2419. for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  2420. KTextEditor::HighlightingInterface *hliface
  2421. =qobject_cast<KTextEditor::HighlightingInterface*>(
  2422. sourceFile->kateView->document());
  2423. hliface->setHighlighting("None");
  2424. }
  2425. KParts::Factory *factory=(KParts::Factory *)
  2426. KLibLoader::self()->factory("katepart");
  2427. if (!factory) qFatal("Failed to load KatePart");
  2428. KTextEditor::Document *doc=(KTextEditor::Document *)
  2429. factory->createPart(0,this,"KTextEditor::Document");
  2430. KTextEditor::HighlightingInterface *hliface
  2431. =qobject_cast<KTextEditor::HighlightingInterface*>(doc);
  2432. hliface->setHighlighting("Asm6502"); // Don't ask...
  2433. hliface->setHighlighting("None");
  2434. KTextEditor::Editor *editor=doc->editor();
  2435. int numConfigPages=editor->configPages();
  2436. for (int i=0; i<numConfigPages; i++) {
  2437. if (editor->configPageName(i)=="Fonts & Colors") {
  2438. KTextEditor::ConfigPage *configPage=editor->configPage(i,this);
  2439. configPage->apply();
  2440. delete configPage;
  2441. break;
  2442. }
  2443. }
  2444. delete doc;
  2445. it=Q3ListViewItemIterator(fileTree);
  2446. for (item=it.current();item;item=(++it).current()) {
  2447. if (item == rootListItem) {
  2448. item->setPixmap(0,SYSICON("exec","tpr.png"));
  2449. } else if (IS_FOLDER(item)) {
  2450. // Bluecurve's "folder_open" isn't actually more open than "folder".
  2451. item->setPixmap(0,(item==currentListItem)?SYSICON(KIconTheme::current().compare("Bluecurve")?"folder_open":"folder-accept","folder2.png")
  2452. :SYSICON("folder","folder1.png"));
  2453. } else if (IS_FILE(item)) {
  2454. CATEGORY_OF(category,item);
  2455. KTextEditor::View *kateView=static_cast<ListViewFile *>(item)->kateView;
  2456. if (kateView) {
  2457. QString fileText=kateView->document()->text();
  2458. CATEGORY_OF(category,item);
  2459. if (preferences.removeTrailingSpaces) {
  2460. sendCommand(kateView,"set-remove-trailing-space 1");
  2461. sendCommand(kateView,"set-remove-trailing-space-save 1");
  2462. } else {
  2463. sendCommand(kateView,"set-remove-trailing-space 0");
  2464. sendCommand(kateView,"set-remove-trailing-space-save 0");
  2465. }
  2466. setTabWidth(kateView,
  2467. (category==sFilesListItem||category==asmFilesListItem||((category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&(fileText[0]=='|'||fileText[0]==';'))))?preferences.tabWidthAsm:
  2468. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?preferences.tabWidthC:
  2469. 8
  2470. );
  2471. // Kate seems really insisting on making it a pain to update syntax highlighting settings.
  2472. KTextEditor::HighlightingInterface *hliface
  2473. =qobject_cast<KTextEditor::HighlightingInterface*>(kateView->document());
  2474. hliface->setHighlighting(
  2475. (category==qllFilesListItem?
  2476. QLL_HL_MODE:
  2477. (category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
  2478. S_HL_MODE:
  2479. (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
  2480. ASM_HL_MODE:
  2481. (category==cFilesListItem||category==hFilesListItem)?
  2482. C_HL_MODE:
  2483. "None"));
  2484. }
  2485. item->setPixmap(0,
  2486. category==cFilesListItem||category==qllFilesListItem?SYSICON("source_c","filec.png"):
  2487. category==hFilesListItem?SYSICON("source_h","fileh.png"):
  2488. category==sFilesListItem||category==asmFilesListItem?SYSICON("source_s","files.png"):
  2489. category==txtFilesListItem?SYSICON("txt","filet.png"):
  2490. category==oFilesListItem||category==aFilesListItem?SYSICON("binary","fileo.png"):
  2491. SYSICON("unknown","filex.png"));
  2492. } else qWarning("Internal error: What's this item?");
  2493. }
  2494. KTextEditor::View *currView=CURRENT_VIEW;
  2495. if (currView) {
  2496. // Force redrawing to get the tab width right, repaint() is ignored for some reason.
  2497. currView->hide();
  2498. currView->show();
  2499. }
  2500. // Apply the icon preferences.
  2501. if (preferences.useSystemIcons) {
  2502. // Set the preferred icon size so system toolbar icons don't get annoying
  2503. // padding.
  2504. int toolbarIconSize=KIconLoader().currentSize(K3Icon::MainToolbar);
  2505. setIconSize(QSize(toolbarIconSize,toolbarIconSize));
  2506. fileNewAction->setIcon(KIcon("filenew"));
  2507. fileNewMenu->menuAction()->setIcon(KIcon("filenew"));
  2508. fileOpenAction->setIcon(KIcon("fileopen"));
  2509. fileSaveAllAction->setIcon(KIcon("filesave"));
  2510. filePrintAction->setIcon(KIcon("fileprint"));
  2511. filePrintQuicklyAction->setIcon(KIcon("fileprint"));
  2512. editClearAction->setIcon(KIcon("editdelete"));
  2513. editCutAction->setIcon(KIcon("editcut"));
  2514. editCopyAction->setIcon(KIcon("editcopy"));
  2515. editPasteAction->setIcon(KIcon("editpaste"));
  2516. projectAddFilesAction->setIcon(KIcon("edit_add"));
  2517. projectCompileAction->setIcon(KIcon("compfile"));
  2518. projectMakeAction->setIcon(KIcon("make_kdevelop"));
  2519. projectBuildAction->setIcon(KIcon("rebuild"));
  2520. helpContentsAction->setIcon(KIcon("help"));
  2521. helpDocumentationAction->setIcon(KIcon("help"));
  2522. helpSearchAction->setIcon(KIcon("filefind"));
  2523. findFindAction->setIcon(KIcon("filefind"));
  2524. if (KIconLoader::global()->iconPath("stock-find-and-replace",K3Icon::Small,TRUE).isEmpty())
  2525. findReplaceAction->setIcon(QIcon(QPixmap(":/images/filereplace.png")));
  2526. else
  2527. findReplaceAction->setIcon(KIcon("stock-find-and-replace"));
  2528. helpIndexAction->setIcon(KIcon("contents"));
  2529. editUndoAction->setIcon(KIcon("undo"));
  2530. editRedoAction->setIcon(KIcon("redo"));
  2531. findFunctionsAction->setIcon(KIcon("view_tree"));
  2532. editIncreaseIndentAction->setIcon(KIcon("indent"));
  2533. editDecreaseIndentAction->setIcon(KIcon("unindent"));
  2534. projectStopCompilationAction->setIcon(KIcon("stop"));
  2535. projectForceQuitAction->setIcon(KIcon("button_cancel"));
  2536. helpNewsAction->setIcon(KIcon("kontact_news"));
  2537. debugRunAction->setIcon(KIcon("player_play"));
  2538. debugPauseAction->setIcon(KIcon("player_pause"));
  2539. toolsConfigureAction->setIcon(KIcon("configure"));
  2540. debugResetAction->setIcon(KIcon("player_stop"));
  2541. } else {
  2542. setIconSize(QSize(20,20));
  2543. fileNewAction->setIcon(QIcon(QPixmap(":/images/00.png")));
  2544. fileNewMenu->menuAction()->setIcon(QIcon(QPixmap(":/images/00.png")));
  2545. fileOpenAction->setIcon(QIcon(QPixmap(":/images/01.png")));
  2546. fileSaveAllAction->setIcon(QIcon(QPixmap(":/images/02.png")));
  2547. filePrintAction->setIcon(QIcon(QPixmap(":/images/03.png")));
  2548. filePrintQuicklyAction->setIcon(QIcon(QPixmap(":/images/03.png")));
  2549. editClearAction->setIcon(QIcon(QPixmap(":/images/04.png")));
  2550. editCutAction->setIcon(QIcon(QPixmap(":/images/05.png")));
  2551. editCopyAction->setIcon(QIcon(QPixmap(":/images/06.png")));
  2552. editPasteAction->setIcon(QIcon(QPixmap(":/images/07.png")));
  2553. projectAddFilesAction->setIcon(QIcon(QPixmap(":/images/08.png")));
  2554. projectCompileAction->setIcon(QIcon(QPixmap(":/images/09.png")));
  2555. projectMakeAction->setIcon(QIcon(QPixmap(":/images/10.png")));
  2556. projectBuildAction->setIcon(QIcon(QPixmap(":/images/11.png")));
  2557. helpContentsAction->setIcon(QIcon(QPixmap(":/images/12.png")));
  2558. helpDocumentationAction->setIcon(QIcon(QPixmap(":/images/12.png")));
  2559. helpSearchAction->setIcon(QIcon(QPixmap(":/images/13.png")));
  2560. findFindAction->setIcon(QIcon(QPixmap(":/images/13.png")));
  2561. findReplaceAction->setIcon(QIcon(QPixmap(":/images/14.png")));
  2562. helpIndexAction->setIcon(QIcon(QPixmap(":/images/15.png")));
  2563. editUndoAction->setIcon(QIcon(QPixmap(":/images/16.png")));
  2564. editRedoAction->setIcon(QIcon(QPixmap(":/images/17.png")));
  2565. findFunctionsAction->setIcon(QIcon(QPixmap(":/images/18.png")));
  2566. editIncreaseIndentAction->setIcon(QIcon(QPixmap(":/images/19.png")));
  2567. editDecreaseIndentAction->setIcon(QIcon(QPixmap(":/images/20.png")));
  2568. projectStopCompilationAction->setIcon(QIcon(QPixmap(":/images/21.png")));
  2569. projectForceQuitAction->setIcon(QIcon(QPixmap(":/images/22.png")));
  2570. helpNewsAction->setIcon(QIcon(QPixmap(":/images/23.png")));
  2571. debugRunAction->setIcon(QIcon(QPixmap(":/images/24.png")));
  2572. debugPauseAction->setIcon(QIcon(QPixmap(":/images/25.png")));
  2573. toolsConfigureAction->setIcon(QIcon(QPixmap(":/images/26.png")));
  2574. debugResetAction->setIcon(QIcon(QPixmap(":/images/27.png")));
  2575. }
  2576. it=Q3ListViewItemIterator(errorList->errorListView);
  2577. for (item=it.current();item;item=(++it).current()) {
  2578. switch(item->rtti()) {
  2579. case etError:
  2580. item->setPixmap(0,SYSICON("messagebox_critical","error.png"));
  2581. break;
  2582. case etWarning:
  2583. item->setPixmap(0,SYSICON("messagebox_warning","warning.png"));
  2584. break;
  2585. default:
  2586. item->setPixmap(0,SYSICON("messagebox_info","info.png"));
  2587. break;
  2588. }
  2589. }
  2590. // Apply the preferences to the source file windows.
  2591. sfit=Q3PtrListIterator<SourceFile>(sourceFiles);
  2592. for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  2593. sourceFile->applyPreferences();
  2594. }
  2595. // Apply the preferences to the debug menu.
  2596. debugPauseAction->setEnabled(!compiling&&preferences.linkTarget==LT_TIEMU);
  2597. debugResetAction->setEnabled(!compiling&&preferences.linkTarget==LT_TIEMU);
  2598. bool runnable=!settings.archive&&!settings.flash_os&&preferences.linkTarget!=LT_NONE;
  2599. menuBar()->setItemVisible(5,runnable); //debugMenu
  2600. debugRunAction->setVisible(runnable);
  2601. debugPauseAction->setVisible(runnable);
  2602. }
  2603. }
  2604. void MainForm::editUndo()
  2605. {
  2606. if (CURRENT_VIEW)
  2607. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->trigger();
  2608. }
  2609. void MainForm::editRedo()
  2610. {
  2611. if (CURRENT_VIEW)
  2612. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->trigger();
  2613. }
  2614. void MainForm::editClear()
  2615. {
  2616. if (CURRENT_VIEW)
  2617. CURRENT_VIEW->removeSelectionText();
  2618. }
  2619. void MainForm::editCut()
  2620. {
  2621. if (CURRENT_VIEW)
  2622. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Cut))->trigger();
  2623. }
  2624. void MainForm::editCopy()
  2625. {
  2626. if (CURRENT_VIEW)
  2627. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Copy))->trigger();
  2628. }
  2629. void MainForm::editPaste()
  2630. {
  2631. if (CURRENT_VIEW)
  2632. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::PasteText))->trigger();
  2633. }
  2634. void MainForm::editSelectAll()
  2635. {
  2636. if (CURRENT_VIEW)
  2637. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::SelectAll))->trigger();
  2638. }
  2639. void MainForm::editIncreaseIndent()
  2640. {
  2641. if (CURRENT_VIEW)
  2642. CURRENT_VIEW->action("tools_indent")->trigger();
  2643. }
  2644. void MainForm::editDecreaseIndent()
  2645. {
  2646. if (CURRENT_VIEW)
  2647. CURRENT_VIEW->action("tools_unindent")->trigger();
  2648. }
  2649. void MainForm::findFind()
  2650. {
  2651. if (kfinddialog)
  2652. ACTIVATE_WINDOW(kfinddialog->winId());
  2653. else {
  2654. // Never set hasSelection because finding in selection doesn't really make
  2655. // sense with my non-modal find dialog setup.
  2656. kfinddialog=new KFindDialog(false,this,0,KFind::FromCursor,findHistory);
  2657. connect(kfinddialog, SIGNAL(okClicked()), this, SLOT(findFind_next()));
  2658. connect(kfinddialog, SIGNAL(cancelClicked()), this, SLOT(findFind_stop()));
  2659. kfinddialog->show();
  2660. }
  2661. }
  2662. void MainForm::findFind_next()
  2663. {
  2664. // Use a local KFind object. The search will need to be restarted next time
  2665. // this function is called because of the non-modality of the find dialog.
  2666. KFind *kfind=new KFind(kfinddialog->pattern(),kfinddialog->options(),this,kfinddialog);
  2667. // Initialize.
  2668. bool findBackwards=!!(kfinddialog->options()&KFind::FindBackwards);
  2669. int findCurrentCol;
  2670. kfind=new KFind(kfinddialog->pattern(),kfinddialog->options(),this,kfinddialog);
  2671. kfind->closeFindNextDialog(); // don't use this, a non-modal KFindDialog is used instead
  2672. connect(kfind,SIGNAL(highlight(const QString &,int,int)),
  2673. this,SLOT(findFind_highlight(const QString &,int,int)));
  2674. // Make sure we have a valid currentListItem.
  2675. if (!currentListItem) fileTreeClicked(rootListItem);
  2676. findCurrentDocument=currentListItem;
  2677. if (CURRENT_VIEW) {
  2678. if (kfinddialog->options()&KFind::FromCursor) {
  2679. if (CURRENT_VIEW->selection()) {
  2680. if (findBackwards) {
  2681. CURRENT_VIEW->selectionRange().start().position(findCurrentLine,findCurrentCol);
  2682. if ((--findCurrentCol)==-1) {
  2683. if (!findCurrentLine) goto skip_data;
  2684. findCurrentLine--;
  2685. }
  2686. } else {
  2687. CURRENT_VIEW->selectionRange().end().position(findCurrentLine,findCurrentCol);
  2688. }
  2689. } else {
  2690. CURRENT_VIEW->cursorPosition().position(findCurrentLine,findCurrentCol);
  2691. }
  2692. } else {
  2693. findCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  2694. findCurrentCol=-1;
  2695. }
  2696. kfind->setData(CURRENT_VIEW->document()->line(findCurrentLine),findCurrentCol);
  2697. } else findCurrentLine=0;
  2698. skip_data:;
  2699. // Now find the next occurrence.
  2700. KFind::Result result;
  2701. KTextEditor::View *currView=CURRENT_VIEW;
  2702. // We never have a currBuffer here, the current list item is always either
  2703. // non-editable or instantiated.
  2704. QStringList currBuffer;
  2705. int currNumLines=0;
  2706. if (CURRENT_VIEW) currNumLines=CURRENT_VIEW->document()->lines();
  2707. do {
  2708. if (kfind->needData()) {
  2709. if (findBackwards?!findCurrentLine:(findCurrentLine>=currNumLines)) {
  2710. if (findBackwards) {
  2711. // Traverse the file tree in order backwards, restart from the end if
  2712. // the first file was reached. Stop at currentListItem.
  2713. if (findCurrentDocument) {
  2714. Q3ListViewItemIterator lvit(fileTree);
  2715. Q3PtrList<Q3ListViewItem> lst;
  2716. Q3ListViewItem *item;
  2717. for (item=lvit.current();item&&item!=findCurrentDocument;
  2718. item=(++lvit).current()) {
  2719. lst.prepend(item);
  2720. }
  2721. Q3PtrListIterator<Q3ListViewItem> it(lst);
  2722. for (findCurrentDocument=it.current();
  2723. findCurrentDocument&&findCurrentDocument!=currentListItem;
  2724. findCurrentDocument=++it) {
  2725. if (IS_FILE(findCurrentDocument)) {
  2726. CATEGORY_OF(category,findCurrentDocument);
  2727. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2728. }
  2729. }
  2730. if (findCurrentDocument) goto not_found;
  2731. }
  2732. Q3ListViewItemIterator lvit(currentListItem);
  2733. Q3PtrList<Q3ListViewItem> lst;
  2734. Q3ListViewItem *item;
  2735. for (item=(++lvit).current();item;item=(++lvit).current()) {
  2736. lst.prepend(item);
  2737. }
  2738. Q3PtrListIterator<Q3ListViewItem> it(lst);
  2739. for (findCurrentDocument=it.current();findCurrentDocument;
  2740. findCurrentDocument=++it) {
  2741. if (IS_FILE(findCurrentDocument)) {
  2742. CATEGORY_OF(category,findCurrentDocument);
  2743. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2744. }
  2745. }
  2746. goto not_found;
  2747. } else {
  2748. // Traverse the file tree in order, restart from the beginning if
  2749. // the last file was reached. Stop at currentListItem.
  2750. if (findCurrentDocument) {
  2751. Q3ListViewItemIterator it(findCurrentDocument);
  2752. for (findCurrentDocument=(++it).current();
  2753. findCurrentDocument&&findCurrentDocument!=currentListItem;
  2754. findCurrentDocument=(++it).current()) {
  2755. if (IS_FILE(findCurrentDocument)) {
  2756. CATEGORY_OF(category,findCurrentDocument);
  2757. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2758. }
  2759. }
  2760. if (findCurrentDocument) goto not_found;
  2761. }
  2762. {
  2763. Q3ListViewItemIterator it(fileTree);
  2764. for (findCurrentDocument=it.current();
  2765. findCurrentDocument&&findCurrentDocument!=currentListItem;
  2766. findCurrentDocument=(++it).current()) {
  2767. if (IS_FILE(findCurrentDocument)) {
  2768. CATEGORY_OF(category,findCurrentDocument);
  2769. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2770. }
  2771. }
  2772. }
  2773. not_found:
  2774. // No find in all files. Try currentListItem again because it hasn't
  2775. // been fully searched yet.
  2776. if (IS_FILE(currentListItem)) {
  2777. // currentListItem is always either instantiated or not editable
  2778. currView=static_cast<ListViewFile *>(currentListItem)->kateView;
  2779. if (currView) {
  2780. currNumLines=currView->document()->lines();
  2781. findCurrentLine=findBackwards?currNumLines-1:0;
  2782. do {
  2783. if (kfind->needData()) {
  2784. if (findBackwards?!findCurrentLine:(findCurrentLine>=currNumLines))
  2785. goto not_found_current;
  2786. if (findBackwards) findCurrentLine--; else findCurrentLine++;
  2787. kfind->setData(currView->document()->line(findCurrentLine));
  2788. }
  2789. result=kfind->find();
  2790. } while (result==KFind::NoMatch);
  2791. break;
  2792. }
  2793. }
  2794. not_found_current:
  2795. KMessageBox::error(this,QString("Text \'%1\' not found").arg(kfinddialog->pattern()));
  2796. delete kfind;
  2797. return;
  2798. file_found:
  2799. currView=static_cast<ListViewFile *>(findCurrentDocument)->kateView;
  2800. currNumLines=currView->document()->lines();
  2801. findCurrentLine=findBackwards?currNumLines-1:0;
  2802. }
  2803. } else if (findBackwards) findCurrentLine--; else findCurrentLine++;
  2804. if (currView)
  2805. kfind->setData(currView->document()->line(findCurrentLine));
  2806. else
  2807. kfind->setData(currBuffer[findCurrentLine]);
  2808. }
  2809. result=kfind->find();
  2810. } while (result==KFind::NoMatch);
  2811. delete kfind;
  2812. }
  2813. #define unused_text text __attribute__((unused))
  2814. void MainForm::findFind_highlight(const QString &unused_text, int matchingindex, int matchedlength)
  2815. {
  2816. if (currentListItem!=findCurrentDocument) fileTreeClicked(findCurrentDocument);
  2817. if (!CURRENT_VIEW) qFatal("CURRENT_VIEW should be set here!");
  2818. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(findCurrentLine,matchingindex+matchedlength));
  2819. CURRENT_VIEW->setSelection(KTextEditor::Range(findCurrentLine,matchingindex,
  2820. findCurrentLine,matchingindex+matchedlength));
  2821. }
  2822. void MainForm::findFind_stop()
  2823. {
  2824. if (kfinddialog) {
  2825. findHistory=kfinddialog->findHistory();
  2826. kfinddialog->deleteLater();
  2827. }
  2828. kfinddialog=static_cast<KFindDialog *>(NULL);
  2829. }
  2830. void MainForm::findReplace()
  2831. {
  2832. if (kreplace) {
  2833. KDialog *replaceNextDialog=kreplace->replaceNextDialog();
  2834. if (replaceNextDialog)
  2835. ACTIVATE_WINDOW(replaceNextDialog->winId());
  2836. return;
  2837. }
  2838. KReplaceDialog kreplacedialog(this,0,((CURRENT_VIEW&&CURRENT_VIEW->selection()
  2839. &&!CURRENT_VIEW->selectionRange().onSingleLine())?
  2840. KFind::SelectedText:0)|KFind::FromCursor,
  2841. findHistory,replacementHistory,
  2842. CURRENT_VIEW&&CURRENT_VIEW->selection());
  2843. if (kreplacedialog.exec()!=QDialog::Accepted)
  2844. return;
  2845. findHistory=kreplacedialog.findHistory();
  2846. replacementHistory=kreplacedialog.replacementHistory();
  2847. kreplace=new KReplaceWithSelection(kreplacedialog.pattern(),kreplacedialog.replacement(),
  2848. kreplacedialog.options(),this);
  2849. // Connect signals to code which handles highlighting of found text, and
  2850. // on-the-fly replacement.
  2851. connect(kreplace,SIGNAL(highlight(const QString &,int,int)),
  2852. this,SLOT(findReplace_highlight(const QString &,int,int)));
  2853. // Connect findNext signal - called when pressing the button in the dialog.
  2854. connect(kreplace,SIGNAL(findNext()),this,SLOT(findReplace_next()));
  2855. // Connect replace signal - called when doing a replacement.
  2856. connect(kreplace,SIGNAL(replace(const QString &,int,int,int)),
  2857. this,SLOT(findReplace_replace(const QString &,int,int,int)));
  2858. // Connect dialogClosed signal - called when closing the Replace Next dialog.
  2859. connect(kreplace,SIGNAL(dialogClosed()),this,SLOT(findReplace_stop()));
  2860. // Initialize.
  2861. bool findBackwards=!!(kreplace->options()&KFind::FindBackwards);
  2862. int replaceCurrentCol;
  2863. // Make sure we have a valid currentListItem.
  2864. if (!currentListItem) fileTreeClicked(rootListItem);
  2865. replaceCurrentDocument=currentListItem;
  2866. if (CURRENT_VIEW) {
  2867. if (kreplace->options()&KFind::SelectedText) {
  2868. kreplace->setSelection(CURRENT_VIEW->selectionRange());
  2869. if (findBackwards) {
  2870. replaceCurrentLine=kreplace->selEndLine();
  2871. replaceCurrentCol=kreplace->selEndCol();
  2872. } else {
  2873. replaceCurrentLine=kreplace->selStartLine();
  2874. replaceCurrentCol=kreplace->selStartCol();
  2875. }
  2876. kreplace->setOptions(kreplace->options()&~KFind::FromCursor);
  2877. } else if (kreplace->options()&KFind::FromCursor) {
  2878. if (CURRENT_VIEW->selection()) {
  2879. if (findBackwards) {
  2880. CURRENT_VIEW->selectionRange().start().position(replaceCurrentLine,
  2881. replaceCurrentCol);
  2882. if ((--replaceCurrentCol)==-1) {
  2883. if (!replaceCurrentLine) goto skip_data;
  2884. replaceCurrentLine--;
  2885. }
  2886. } else {
  2887. CURRENT_VIEW->selectionRange().end().position(replaceCurrentLine,
  2888. replaceCurrentCol);
  2889. }
  2890. } else {
  2891. CURRENT_VIEW->cursorPosition().position(replaceCurrentLine,replaceCurrentCol);
  2892. // Don't prompt for restarting if we actually searched the entire document.
  2893. if (findBackwards?(replaceCurrentLine==(CURRENT_VIEW->document()->lines()-1)
  2894. && replaceCurrentCol==(CURRENT_VIEW->document()->lineLength(replaceCurrentLine)))
  2895. :(!replaceCurrentLine&&!replaceCurrentCol))
  2896. kreplace->setOptions(kreplace->options()&~KFind::FromCursor);
  2897. }
  2898. } else {
  2899. replaceCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  2900. replaceCurrentCol=-1;
  2901. }
  2902. kreplace->setData(CURRENT_VIEW->document()->line(replaceCurrentLine),replaceCurrentCol);
  2903. }
  2904. skip_data:
  2905. // Now find the next occurrence.
  2906. findReplace_next(TRUE);
  2907. }
  2908. void MainForm::findReplace_next()
  2909. {
  2910. findReplace_next(FALSE);
  2911. }
  2912. void MainForm::findReplace_next(bool firstTime)
  2913. {
  2914. // Replace All only works on the current file. Also, if we have a selection,
  2915. // we only want to work on the file containing the selection.
  2916. bool global=(kreplace->options()&KReplaceDialog::PromptOnReplace)&&!kreplace->haveSelection();
  2917. bool findBackwards=!!(kreplace->options()&KFind::FindBackwards);
  2918. // Reinitialize.
  2919. if (!firstTime) {
  2920. int replaceCurrentCol;
  2921. // Make sure we have a valid currentListItem.
  2922. if (!currentListItem) fileTreeClicked(rootListItem);
  2923. replaceCurrentDocument=currentListItem;
  2924. if (CURRENT_VIEW) {
  2925. // Non-first-time always continues from cursor.
  2926. if (CURRENT_VIEW->selection()) {
  2927. if (findBackwards) {
  2928. CURRENT_VIEW->selectionRange().start().position(replaceCurrentLine,
  2929. replaceCurrentCol);
  2930. if ((--replaceCurrentCol)==-1) {
  2931. if (!replaceCurrentLine) goto skip_data;
  2932. replaceCurrentLine--;
  2933. }
  2934. } else {
  2935. CURRENT_VIEW->selectionRange().end().position(replaceCurrentLine,
  2936. replaceCurrentCol);
  2937. }
  2938. } else {
  2939. CURRENT_VIEW->cursorPosition().position(replaceCurrentLine,replaceCurrentCol);
  2940. }
  2941. kreplace->setData(CURRENT_VIEW->document()->line(replaceCurrentLine),replaceCurrentCol);
  2942. } else replaceCurrentLine=0;
  2943. }
  2944. skip_data:;
  2945. // Now find the next occurrence.
  2946. KFind::Result result;
  2947. KTextEditor::View *currView=CURRENT_VIEW;
  2948. // We never have a currBuffer here, the current list item is always either
  2949. // non-editable or instantiated.
  2950. QStringList currBuffer;
  2951. int currNumLines=0;
  2952. if (CURRENT_VIEW) currNumLines=CURRENT_VIEW->document()->lines();
  2953. do {
  2954. if (kreplace->needData()) {
  2955. if (global) {
  2956. if (findBackwards?!replaceCurrentLine:(replaceCurrentLine>=currNumLines)) {
  2957. if (findBackwards) {
  2958. // Traverse the file tree in order backwards, restart from the end if
  2959. // the first file was reached. Stop at currentListItem.
  2960. if (replaceCurrentDocument) {
  2961. Q3ListViewItemIterator lvit(fileTree);
  2962. Q3PtrList<Q3ListViewItem> lst;
  2963. Q3ListViewItem *item;
  2964. for (item=lvit.current();item&&item!=replaceCurrentDocument;
  2965. item=(++lvit).current()) {
  2966. lst.prepend(item);
  2967. }
  2968. Q3PtrListIterator<Q3ListViewItem> it(lst);
  2969. for (replaceCurrentDocument=it.current();
  2970. replaceCurrentDocument&&replaceCurrentDocument!=currentListItem;
  2971. replaceCurrentDocument=++it) {
  2972. if (IS_FILE(replaceCurrentDocument)) {
  2973. CATEGORY_OF(category,replaceCurrentDocument);
  2974. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2975. }
  2976. }
  2977. if (replaceCurrentDocument) goto not_found;
  2978. }
  2979. Q3ListViewItemIterator lvit(currentListItem);
  2980. Q3PtrList<Q3ListViewItem> lst;
  2981. Q3ListViewItem *item;
  2982. for (item=(++lvit).current();item;item=(++lvit).current()) {
  2983. lst.prepend(item);
  2984. }
  2985. Q3PtrListIterator<Q3ListViewItem> it(lst);
  2986. for (replaceCurrentDocument=it.current();replaceCurrentDocument;
  2987. replaceCurrentDocument=++it) {
  2988. if (IS_FILE(replaceCurrentDocument)) {
  2989. CATEGORY_OF(category,replaceCurrentDocument);
  2990. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  2991. }
  2992. }
  2993. goto not_found;
  2994. } else {
  2995. // Traverse the file tree in order, restart from the beginning if
  2996. // the last file was reached. Stop at currentListItem.
  2997. if (replaceCurrentDocument) {
  2998. Q3ListViewItemIterator it(replaceCurrentDocument);
  2999. for (replaceCurrentDocument=(++it).current();
  3000. replaceCurrentDocument&&replaceCurrentDocument!=currentListItem;
  3001. replaceCurrentDocument=(++it).current()) {
  3002. if (IS_FILE(replaceCurrentDocument)) {
  3003. CATEGORY_OF(category,replaceCurrentDocument);
  3004. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  3005. }
  3006. }
  3007. if (replaceCurrentDocument) goto not_found;
  3008. }
  3009. {
  3010. Q3ListViewItemIterator it(fileTree);
  3011. for (replaceCurrentDocument=it.current();
  3012. replaceCurrentDocument&&replaceCurrentDocument!=currentListItem;
  3013. replaceCurrentDocument=(++it).current()) {
  3014. if (IS_FILE(replaceCurrentDocument)) {
  3015. CATEGORY_OF(category,replaceCurrentDocument);
  3016. if (IS_EDITABLE_CATEGORY(category)) goto file_found;
  3017. }
  3018. }
  3019. }
  3020. not_found:
  3021. // No find in all files. Try currentListItem again because it hasn't
  3022. // been fully searched yet.
  3023. if (IS_FILE(currentListItem)) {
  3024. // currentListItem is always either instantiated or not editable
  3025. currView=static_cast<ListViewFile *>(currentListItem)->kateView;
  3026. if (currView) {
  3027. currNumLines=currView->document()->lines();
  3028. replaceCurrentLine=findBackwards?currNumLines-1:0;
  3029. do {
  3030. if (kreplace->needData()) {
  3031. if (findBackwards?!replaceCurrentLine:(replaceCurrentLine>=currNumLines))
  3032. goto not_found_current;
  3033. if (findBackwards) replaceCurrentLine--; else replaceCurrentLine++;
  3034. kreplace->setData(currView->document()->line(replaceCurrentLine));
  3035. }
  3036. result=kreplace->replace();
  3037. } while (result==KFind::NoMatch);
  3038. break;
  3039. }
  3040. }
  3041. not_found_current:
  3042. kreplace->displayFinalDialog();
  3043. findReplace_stop();
  3044. return;
  3045. file_found:
  3046. currView=static_cast<ListViewFile *>(replaceCurrentDocument)->kateView;
  3047. currNumLines=currView->document()->lines();
  3048. replaceCurrentLine=findBackwards?currNumLines-1:0;
  3049. }
  3050. } else if (findBackwards) replaceCurrentLine--; else replaceCurrentLine++;
  3051. if (currView)
  3052. kreplace->setData(currView->document()->line(replaceCurrentLine));
  3053. else
  3054. kreplace->setData(currBuffer[replaceCurrentLine]);
  3055. } else { // if not global
  3056. if (kreplace->haveSelection()
  3057. ?(findBackwards?(replaceCurrentLine<=kreplace->selStartLine())
  3058. :(replaceCurrentLine>=kreplace->selEndLine()))
  3059. :(findBackwards?!replaceCurrentLine:(replaceCurrentLine>=currNumLines))) {
  3060. // It makes no sense to prompt for restarting if we aren't actually
  3061. // searching anywhere.
  3062. if (CURRENT_VIEW) {
  3063. if (kreplace->shouldRestart()) {
  3064. // Drop "From cursor" and "Selected text" options.
  3065. kreplace->setOptions(kreplace->options()&~(KFind::FromCursor
  3066. |KFind::SelectedText));
  3067. kreplace->invalidateSelection();
  3068. // Reinitialize.
  3069. replaceCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  3070. kreplace->setData(CURRENT_VIEW->document()->line(replaceCurrentLine));
  3071. // Start again as if it was the first time.
  3072. findReplace_next(TRUE);
  3073. return;
  3074. } else {
  3075. findReplace_stop();
  3076. return;
  3077. }
  3078. } else goto not_found_current;
  3079. } else if (findBackwards) replaceCurrentLine--; else replaceCurrentLine++;
  3080. if (currView)
  3081. kreplace->setData(currView->document()->line(replaceCurrentLine));
  3082. else
  3083. kreplace->setData(currBuffer[replaceCurrentLine]);
  3084. }
  3085. }
  3086. result=kreplace->replace();
  3087. } while (result==KFind::NoMatch);
  3088. }
  3089. void MainForm::findReplace_highlight(const QString &unused_text, int matchingindex, int matchedlength)
  3090. {
  3091. if (currentListItem!=replaceCurrentDocument) fileTreeClicked(replaceCurrentDocument);
  3092. if (!CURRENT_VIEW) qFatal("CURRENT_VIEW should be set here!");
  3093. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(replaceCurrentLine,matchingindex+matchedlength));
  3094. CURRENT_VIEW->setSelection(KTextEditor::Range(replaceCurrentLine,matchingindex,
  3095. replaceCurrentLine,matchingindex+matchedlength));
  3096. }
  3097. void MainForm::findReplace_replace(const QString &text, int replacementIndex, int replacedLength, int matchedLength)
  3098. {
  3099. if (currentListItem!=replaceCurrentDocument) fileTreeClicked(replaceCurrentDocument);
  3100. if (!CURRENT_VIEW) qFatal("CURRENT_VIEW should be set here!");
  3101. bool update=!!(kreplace->options()&KReplaceDialog::PromptOnReplace);
  3102. bool haveSelection=kreplace->haveSelection();
  3103. // The initializations are redundant, but g++ doesn't understand this, and the
  3104. // self-initialization trick doesn't work either (-Wno-init-self is ignored).
  3105. int selStartLine=0, selStartCol=0, selEndLine=0, selEndCol=0;
  3106. if (haveSelection) {
  3107. selStartLine=kreplace->selStartLine();
  3108. selStartCol=kreplace->selStartCol();
  3109. selEndLine=kreplace->selEndLine();
  3110. selEndCol=kreplace->selEndCol();
  3111. }
  3112. CURRENT_VIEW->document()->startEditing();
  3113. CURRENT_VIEW->document()->insertText(KTextEditor::Cursor(replaceCurrentLine,replacementIndex),
  3114. text.mid(replacementIndex,replacedLength));
  3115. // We can't put the cursor back now because this breaks editBegin/editEnd.
  3116. int line,col;
  3117. CURRENT_VIEW->cursorPosition().position(line,col);
  3118. bool updateCursor=(line==replaceCurrentLine && col==replacementIndex+replacedLength);
  3119. CURRENT_VIEW->document()->removeText(KTextEditor::Range(replaceCurrentLine,replacementIndex+replacedLength,
  3120. replaceCurrentLine,replacementIndex+replacedLength+matchedLength));
  3121. CURRENT_VIEW->document()->endEditing();
  3122. if (updateCursor)
  3123. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(replaceCurrentLine,replacementIndex));
  3124. if (update) {
  3125. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(replaceCurrentLine,replacementIndex+replacedLength));
  3126. CURRENT_VIEW->setSelection(KTextEditor::Range(replaceCurrentLine,replacementIndex,
  3127. replaceCurrentLine,replacementIndex+replacedLength));
  3128. CURRENT_VIEW->repaint();
  3129. }
  3130. if (haveSelection) {
  3131. // Restore selection, updating coordinates if necessary.
  3132. kreplace->setSelection(selStartLine,selStartCol,selEndLine,
  3133. (replaceCurrentLine==selEndLine)
  3134. ?(selEndCol+replacedLength-matchedLength)
  3135. :selEndCol);
  3136. }
  3137. }
  3138. void MainForm::findReplace_stop()
  3139. {
  3140. if (kreplace) kreplace->deleteLater();
  3141. kreplace=static_cast<KReplaceWithSelection *>(NULL);
  3142. }
  3143. static SourceFileFunctions sourceFileFunctions;
  3144. static FunctionDialog *functionDialog;
  3145. void MainForm::findFunctions()
  3146. {
  3147. if (CURRENT_VIEW) {
  3148. functionDialog=new FunctionDialog(this);
  3149. connect(functionDialog->functionListBox,SIGNAL(highlighted(int)),
  3150. this,SLOT(findFunctions_functionListBox_highlighted(int)));
  3151. connect(functionDialog->functionListBox,SIGNAL(selected(int)),
  3152. this,SLOT(findFunctions_functionListBox_selected(int)));
  3153. connect(functionDialog->prototypeButton,SIGNAL(clicked()),
  3154. this,SLOT(findFunctions_prototypeButton_clicked()));
  3155. connect(functionDialog->implementationButton,SIGNAL(clicked()),
  3156. this,SLOT(findFunctions_implementationButton_clicked()));
  3157. functionDialog->functionListBox->clear();
  3158. CATEGORY_OF(category,currentListItem);
  3159. sourceFileFunctions=getFunctions(CURRENT_VIEW->document()->text(),
  3160. category==asmFilesListItem||category==sFilesListItem);
  3161. for (SourceFileFunctions::Iterator it=sourceFileFunctions.begin();
  3162. it!=sourceFileFunctions.end(); ++it)
  3163. functionDialog->functionListBox->insertItem((*it).name);
  3164. functionDialog->exec();
  3165. delete functionDialog;
  3166. }
  3167. }
  3168. void MainForm::findFunctions_functionListBox_highlighted(int index)
  3169. {
  3170. if (index>=0) {
  3171. functionDialog->prototypeButton->setEnabled(
  3172. sourceFileFunctions[index].prototypeLine>=0);
  3173. functionDialog->implementationButton->setEnabled(
  3174. sourceFileFunctions[index].implementationLine>=0);
  3175. } else {
  3176. functionDialog->prototypeButton->setEnabled(FALSE);
  3177. functionDialog->implementationButton->setEnabled(FALSE);
  3178. }
  3179. }
  3180. void MainForm::findFunctions_functionListBox_selected(int index)
  3181. {
  3182. if (index>=0) {
  3183. int line=sourceFileFunctions[index].implementationLine>=0
  3184. ?sourceFileFunctions[index].implementationLine
  3185. :sourceFileFunctions[index].prototypeLine;
  3186. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,0));
  3187. functionDialog->accept();
  3188. }
  3189. }
  3190. void MainForm::findFunctions_prototypeButton_clicked()
  3191. {
  3192. int index=functionDialog->functionListBox->currentItem();
  3193. if (index>=0 && sourceFileFunctions[index].prototypeLine>=0) {
  3194. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(
  3195. sourceFileFunctions[index].prototypeLine,0));
  3196. functionDialog->accept();
  3197. }
  3198. }
  3199. void MainForm::findFunctions_implementationButton_clicked()
  3200. {
  3201. int index=functionDialog->functionListBox->currentItem();
  3202. if (index>=0 && sourceFileFunctions[index].implementationLine>=0) {
  3203. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(
  3204. sourceFileFunctions[index].implementationLine,0));
  3205. functionDialog->accept();
  3206. }
  3207. }
  3208. void MainForm::findFunctionsPopup_aboutToShow()
  3209. {
  3210. findFunctionsPopup->clear();
  3211. if (CURRENT_VIEW) {
  3212. CATEGORY_OF(category,currentListItem);
  3213. sourceFileFunctions=getFunctions(CURRENT_VIEW->document()->text(),
  3214. category==asmFilesListItem||category==sFilesListItem);
  3215. int idx=0;
  3216. for (SourceFileFunctions::Iterator it=sourceFileFunctions.begin();
  3217. it!=sourceFileFunctions.end(); ++it,++idx)
  3218. findFunctionsPopup->insertItem((*it).name,idx);
  3219. }
  3220. }
  3221. void MainForm::findFunctionsPopup_aboutToHide()
  3222. {
  3223. QTimer::singleShot(0,this,SLOT(findFunctionsPopup_aboutToHide_async()));
  3224. }
  3225. void MainForm::findFunctionsPopup_aboutToHide_async()
  3226. {
  3227. findFunctionsPopup->clear();
  3228. }
  3229. void MainForm::findFunctionsPopup_activated(int id)
  3230. {
  3231. if (CURRENT_VIEW) {
  3232. int line=sourceFileFunctions[id].implementationLine>=0
  3233. ?sourceFileFunctions[id].implementationLine
  3234. :sourceFileFunctions[id].prototypeLine;
  3235. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,0));
  3236. }
  3237. }
  3238. void MainForm::findAndOpenFile(const QString &fileName, void *category)
  3239. {
  3240. // Look for the source file with the given name.
  3241. QString fileNameNoPath=QFileInfo(fileName).fileName();
  3242. bool inProject;
  3243. void *sourceFile;
  3244. if (findSourceFile(inProject,sourceFile,fileNameNoPath)) {
  3245. if (inProject)
  3246. fileTreeClicked(reinterpret_cast<ListViewFile *>(sourceFile));
  3247. else
  3248. ACTIVATE_WINDOW(reinterpret_cast<SourceFile *>(sourceFile)->winId());
  3249. } else {
  3250. // Not found. Try to open it instead.
  3251. // Don't do this if the name ends with ".tpr" because that would cause
  3252. // openProject to close the current project and load the new one instead.
  3253. if (!fileName.endsWith(".tpr",FALSE)) {
  3254. QString fileNameFull=QFileInfo(projectFileName).dir().filePath(fileName);
  3255. if (getPathType(fileNameFull)==PATH_FILE) {
  3256. openProject(fileNameFull);
  3257. if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject)
  3258. ACTIVATE_WINDOW(reinterpret_cast<SourceFile *>(sourceFile)->winId());
  3259. } else {
  3260. Q3ListViewItem *cat=reinterpret_cast<Q3ListViewItem *>(category);
  3261. QString includeDir=(cat==asmFilesListItem)?"asm":
  3262. (cat==sFilesListItem)?"s":"c";
  3263. fileNameFull=QDir(QString("%1/include/%2/").arg(tigcc_base)
  3264. .arg(includeDir)).filePath(fileName);
  3265. if (getPathType(fileNameFull)==PATH_FILE) {
  3266. openProject(fileNameFull);
  3267. if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject)
  3268. ACTIVATE_WINDOW(reinterpret_cast<SourceFile *>(sourceFile)->winId());
  3269. } else {
  3270. KMessageBox::error(this,QString("File \'%1\' not found.").arg(fileName),
  3271. "Search Failed");
  3272. }
  3273. }
  3274. }
  3275. }
  3276. }
  3277. void MainForm::findOpenFileAtCursor()
  3278. {
  3279. if (CURRENT_VIEW && IS_FILE(currentListItem)) {
  3280. int line,col,i;
  3281. CURRENT_VIEW->cursorPosition().position(line,col);
  3282. QString textLine=CURRENT_VIEW->document()->line(line);
  3283. int l=textLine.length();
  3284. bool quotesInLine=textLine.contains("\"");
  3285. QString fileName;
  3286. for (i=col;i>=0;i--) {
  3287. QChar c=textLine[i];
  3288. if (!((quotesInLine && c==' ') || (c>='A' && c<='Z') || (c>='a' && c<='z')
  3289. || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
  3290. break;
  3291. fileName.prepend(c);
  3292. }
  3293. for (i=col+1;i<l;i++) {
  3294. QChar c=textLine[i];
  3295. if (!((quotesInLine && c==' ') || (c>='A' && c<='Z') || (c>='a' && c<='z')
  3296. || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
  3297. break;
  3298. fileName.append(c);
  3299. }
  3300. CATEGORY_OF(category,currentListItem);
  3301. findAndOpenFile(fileName,category);
  3302. }
  3303. }
  3304. void MainForm::openHeader(const QString &fileName, bool systemHeader,
  3305. int lineno)
  3306. {
  3307. if (systemHeader) {
  3308. // Don't do this if the name ends with ".tpr" because that would cause
  3309. // openProject to close the current project and load the new one instead.
  3310. if (!fileName.endsWith(".tpr",FALSE)) {
  3311. bool inProject;
  3312. void *sourceFile;
  3313. QString fileNameFull=QDir(QString("%1/include/c/").arg(tigcc_base))
  3314. .filePath(fileName);
  3315. if (findSourceFile(inProject,sourceFile,fileNameFull)) {
  3316. if (inProject) {
  3317. fileTreeClicked(reinterpret_cast<ListViewFile *>(sourceFile));
  3318. if (reinterpret_cast<ListViewFile *>(sourceFile)->kateView)
  3319. reinterpret_cast<ListViewFile *>(sourceFile)->kateView->setCursorPosition(KTextEditor::Cursor(lineno,0));
  3320. } else {
  3321. reinterpret_cast<SourceFile *>(sourceFile)->kateView->setCursorPosition(KTextEditor::Cursor(lineno,0));
  3322. ACTIVATE_WINDOW(reinterpret_cast<SourceFile *>(sourceFile)->winId());
  3323. }
  3324. } else {
  3325. if (getPathType(fileNameFull)==PATH_FILE) {
  3326. openProject(fileNameFull);
  3327. if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject) {
  3328. reinterpret_cast<SourceFile *>(sourceFile)->kateView->setCursorPosition(KTextEditor::Cursor(lineno,0));
  3329. ACTIVATE_WINDOW(reinterpret_cast<SourceFile *>(sourceFile)->winId());
  3330. }
  3331. } else {
  3332. KMessageBox::error(this,QString("File \'%1\' not found.").arg(fileName),
  3333. "Search Failed");
  3334. }
  3335. }
  3336. }
  3337. } else {
  3338. QString name=fileName;
  3339. int pos;
  3340. Q3ListViewItem *item=hFilesListItem;
  3341. while ((pos=name.find('/'))>=0) {
  3342. QString folder=name.left(pos);
  3343. name.remove(0,pos+1);
  3344. for (item=item->firstChild();item;item=item->nextSibling()) {
  3345. if (IS_FOLDER(item)) {
  3346. if (item->text(0)==folder) break;
  3347. }
  3348. }
  3349. if (!item) return;
  3350. }
  3351. for (item=item->firstChild();item;item=item->nextSibling()) {
  3352. if (IS_FILE(item)) {
  3353. ListViewFile *fileItem=static_cast<ListViewFile *>(item);
  3354. if (QFileInfo(fileItem->fileName).fileName()==name) {
  3355. fileTreeClicked(item);
  3356. if (fileItem->kateView)
  3357. fileItem->kateView->setCursorPosition(KTextEditor::Cursor(lineno,0));
  3358. return;
  3359. }
  3360. }
  3361. }
  3362. }
  3363. }
  3364. void MainForm::findFindSymbolDeclaration()
  3365. {
  3366. if (IS_FILE(currentListItem) && CURRENT_VIEW) {
  3367. QString fileText=CURRENT_VIEW->document()->text();
  3368. CATEGORY_OF(category,currentListItem);
  3369. // "Find symbol declaration" only operates on C files.
  3370. if (category==cFilesListItem || category==qllFilesListItem
  3371. || (category==hFilesListItem && !fileText.isEmpty()
  3372. && fileText[0]!='|' && fileText[0]!=';')) {
  3373. QString fileName=pathInProject(currentListItem);
  3374. QString symbolFile;
  3375. unsigned symbolLine;
  3376. bool systemHeader;
  3377. int line,col,i;
  3378. CURRENT_VIEW->cursorPosition().position(line,col);
  3379. QString textLine=CURRENT_VIEW->document()->line(line);
  3380. QString wordUnderCursor;
  3381. for (i=col-1;i>=0;i--) {
  3382. QChar c=textLine[i];
  3383. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  3384. || c=='_' || c=='$' || c=='#')
  3385. wordUnderCursor.prepend(c);
  3386. }
  3387. int len=textLine.length();
  3388. for (i=col;i<len;i++) {
  3389. QChar c=textLine[i];
  3390. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  3391. || c=='_' || c=='$' || c=='#')
  3392. wordUnderCursor.append(c);
  3393. }
  3394. if (findSymbolInFile(wordUnderCursor,fileText,fileName,this,symbolFile,
  3395. symbolLine,systemHeader)
  3396. && !symbolFile.isNull()) {
  3397. if (symbolFile==fileName)
  3398. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(symbolLine,0));
  3399. else
  3400. openHeader(symbolFile,systemHeader,symbolLine);
  3401. }
  3402. }
  3403. }
  3404. }
  3405. //returns 1 on success
  3406. int MainForm::projectAddFiles_oneFile(const QString &fileName)
  3407. {
  3408. Q3ListViewItem *category=othFilesListItem;
  3409. QString suffix,caption;
  3410. int p;
  3411. p=fileName.findRev('/');
  3412. if (p<0) p=-1;
  3413. caption=fileName.mid(p+1);
  3414. p=caption.findRev('.');
  3415. if (p>=0) {
  3416. suffix=caption.mid(p+1);
  3417. caption.truncate(p);
  3418. }
  3419. if (!checkFileName(fileName,extractAllFileNames())) {
  3420. KMessageBox::error(this,QString("The file \'%1\' is already included in the project.").arg(caption));
  3421. return 0;
  3422. }
  3423. if (!suffix.compare("h"))
  3424. category=hFilesListItem;
  3425. else if (!suffix.compare("c"))
  3426. category=cFilesListItem;
  3427. else if (!suffix.compare("s"))
  3428. category=sFilesListItem;
  3429. else if (!suffix.compare("asm"))
  3430. category=asmFilesListItem;
  3431. else if (!suffix.compare("qll"))
  3432. category=qllFilesListItem;
  3433. else if (!suffix.compare("o"))
  3434. category=oFilesListItem;
  3435. else if (!suffix.compare("a"))
  3436. category=aFilesListItem;
  3437. else if (!suffix.compare("txt"))
  3438. category=txtFilesListItem;
  3439. if (category && category==qllFilesListItem && qllFileCount) {
  3440. KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
  3441. return 0;
  3442. }
  3443. if (!category)
  3444. category=othFilesListItem;
  3445. if (openFile(category,category,caption,fileName))
  3446. return 1;
  3447. return 0;
  3448. }
  3449. void MainForm::projectAddFiles()
  3450. {
  3451. unsigned long i,e;
  3452. int projectChanged=0;
  3453. if (compiling) return;
  3454. QStringList result=SGetFileName_Multiple(findFilter(TIGCCAddFilesFilter),"Add Files",this);
  3455. e=result.count();
  3456. for (i=0;i<e;i++) {
  3457. if (projectAddFiles_oneFile(result[i]))
  3458. projectChanged=TRUE;
  3459. }
  3460. if (projectChanged) {
  3461. projectIsDirty=TRUE;
  3462. projectNeedsRelink=TRUE;
  3463. }
  3464. }
  3465. static bool stopCompilingFlag, errorsCompilingFlag;
  3466. static bool ti89_targeted, ti92p_targeted, v200_targeted, dataFileGenerated;
  3467. static QString compileStats;
  3468. static QDateTime newestHeaderTimestamp;
  3469. static QStringList objectFiles;
  3470. static QStringList deletableObjectFiles;
  3471. static QStringList deletableAsmFiles;
  3472. static KProcIO *procio;
  3473. QString MainForm::writeTempSourceFile(void *srcFile, bool inProject)
  3474. {
  3475. const QString *origFileName;
  3476. Q3ListViewItem *category;
  3477. QString fileName;
  3478. QString fileText;
  3479. LineStartList *pLineStartList=0;
  3480. if (inProject) {
  3481. ListViewFile *sourceFile=reinterpret_cast<ListViewFile *>(srcFile);
  3482. origFileName=&(sourceFile->fileName);
  3483. CATEGORY_OF(cat,sourceFile);
  3484. category=cat;
  3485. QString folder;
  3486. Q3ListViewItem *item=sourceFile->parent();
  3487. while (!IS_CATEGORY(item)) {
  3488. folder.prepend('/');
  3489. folder.prepend(item->text(0));
  3490. item=item->parent();
  3491. }
  3492. QString ext;
  3493. // Some categories need fixed extensions.
  3494. if (category==cFilesListItem) {
  3495. ext=".c";
  3496. } else if (category==sFilesListItem) {
  3497. ext=".s";
  3498. } else if (category==asmFilesListItem) {
  3499. ext=".asm";
  3500. } else if (category==qllFilesListItem) {
  3501. ext=".qll";
  3502. } else if (category==oFilesListItem) {
  3503. ext=".o";
  3504. } else if (category==aFilesListItem) {
  3505. ext=".a";
  3506. } else {
  3507. // For others (header files in particular), we need to keep whatever
  3508. // extension the user supplied.
  3509. int dotPos=origFileName->findRev('.');
  3510. int slashPos=origFileName->findRev('/');
  3511. if (dotPos>slashPos) ext=origFileName->mid(dotPos);
  3512. }
  3513. fileName=QString("%1/%2%3%4").arg(tempdir).arg(folder)
  3514. .arg(sourceFile->text(0)).arg(ext);
  3515. if (IS_EDITABLE_CATEGORY(category)) {
  3516. fileText=sourceFile->kateView->document()->text();
  3517. pLineStartList=&(sourceFile->lineStartList);
  3518. } else {
  3519. if (copyFile(origFileName->ascii(),fileName.ascii())) {
  3520. KMessageBox::error(this,"Failed to copy file to temporary directory.");
  3521. stopCompilingFlag=TRUE;
  3522. }
  3523. return fileName;
  3524. }
  3525. } else {
  3526. SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
  3527. origFileName=&(sourceFile->fileName);
  3528. category=reinterpret_cast<Q3ListViewItem *>(sourceFile->category);
  3529. fileName=QString("%1%2").arg(tempdir)
  3530. .arg(origFileName->mid(origFileName->findRev('/')));
  3531. fileText=sourceFile->kateView->document()->text();
  3532. pLineStartList=&(sourceFile->lineStartList);
  3533. }
  3534. if (saveAndSplitFileText(fileName.ascii(),fileText,(category==cFilesListItem),
  3535. (category==cFilesListItem||category==qllFilesListItem),
  3536. (category==sFilesListItem),*origFileName,pLineStartList)) {
  3537. KMessageBox::error(this,"Failed to write source file to temporary directory.");
  3538. stopCompilingFlag=TRUE;
  3539. }
  3540. return fileName;
  3541. }
  3542. void MainForm::startCompiling()
  3543. {
  3544. if (preferences.autoSave) {
  3545. if (!fileSave()) {
  3546. stopCompilingFlag=TRUE;
  3547. return;
  3548. }
  3549. } else {
  3550. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  3551. for (SourceFile *sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  3552. sourceFile->fileSave();
  3553. }
  3554. }
  3555. fileNewMenu->menuAction()->setEnabled(FALSE);
  3556. fileNewAction->setEnabled(FALSE);
  3557. fileOpenAction->setEnabled(FALSE);
  3558. fileRecent1Action->setEnabled(FALSE);
  3559. fileRecent2Action->setEnabled(FALSE);
  3560. fileRecent3Action->setEnabled(FALSE);
  3561. fileRecent4Action->setEnabled(FALSE);
  3562. fileExitAction->setEnabled(FALSE);
  3563. projectAddFilesAction->setEnabled(FALSE);
  3564. projectCompileAction->setVisible(FALSE);
  3565. projectMakeAction->setVisible(FALSE);
  3566. projectBuildAction->setVisible(FALSE);
  3567. projectCompileAction->setEnabled(FALSE);
  3568. accel->setItemEnabled(15,FALSE);
  3569. projectMakeAction->setEnabled(FALSE);
  3570. accel->setItemEnabled(16,FALSE);
  3571. projectBuildAction->setEnabled(FALSE);
  3572. projectStopCompilationAction->setEnabled(TRUE);
  3573. projectForceQuitAction->setEnabled(TRUE);
  3574. projectStopCompilationAction->setVisible(TRUE);
  3575. projectForceQuitAction->setVisible(TRUE);
  3576. debugRunAction->setEnabled(FALSE);
  3577. debugPauseAction->setEnabled(FALSE);
  3578. debugResetAction->setEnabled(FALSE);
  3579. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  3580. for (SourceFile *sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  3581. sourceFile->fileAddToProjectAction->setEnabled(FALSE);
  3582. sourceFile->fileCompileAction->setEnabled(FALSE);
  3583. }
  3584. compiling=TRUE;
  3585. stopCompilingFlag=FALSE;
  3586. errorsCompilingFlag=FALSE;
  3587. newestHeaderTimestamp=QDateTime();
  3588. objectFiles.clear();
  3589. deletableObjectFiles.clear();
  3590. deletableAsmFiles.clear();
  3591. errorList->errorListView->clear();
  3592. programOutput=QString::null;
  3593. ti89_targeted=ti92p_targeted=v200_targeted=dataFileGenerated=FALSE;
  3594. compileStats=QString::null;
  3595. projectProgramOutputAction->setEnabled(FALSE);
  3596. procio=static_cast<KProcIO *>(NULL);
  3597. // Write all the headers and incbin files to the temporary directory.
  3598. Q3ListViewItemIterator lvit(hFilesListItem);
  3599. Q3ListViewItem *item;
  3600. for (item=(++lvit).current();item&&!IS_CATEGORY(item);
  3601. item=(++lvit).current()) {
  3602. if (IS_FILE(item)) {
  3603. if (static_cast<ListViewFile *>(item)->modifiedSinceLastCompile)
  3604. headersModified=TRUE;
  3605. if (!headersModified) {
  3606. QDateTime headerTimestamp=QFileInfo(static_cast<ListViewFile *>(item)->fileName).lastModified();
  3607. if (!newestHeaderTimestamp.isValid()
  3608. || (headerTimestamp.isValid()
  3609. && headerTimestamp>newestHeaderTimestamp))
  3610. newestHeaderTimestamp=headerTimestamp;
  3611. }
  3612. writeTempSourceFile(static_cast<ListViewFile *>(item),TRUE);
  3613. if (stopCompilingFlag) return;
  3614. }
  3615. }
  3616. lvit=Q3ListViewItemIterator(othFilesListItem);
  3617. for (item=(++lvit).current();item&&!IS_CATEGORY(item);
  3618. item=(++lvit).current()) {
  3619. if (IS_FILE(item)) {
  3620. if (!headersModified) {
  3621. QDateTime headerTimestamp=QFileInfo(static_cast<ListViewFile *>(item)->fileName).lastModified();
  3622. if (!newestHeaderTimestamp.isValid()
  3623. || (headerTimestamp.isValid()
  3624. && headerTimestamp>newestHeaderTimestamp))
  3625. newestHeaderTimestamp=headerTimestamp;
  3626. }
  3627. writeTempSourceFile(static_cast<ListViewFile *>(item),TRUE);
  3628. if (stopCompilingFlag) return;
  3629. }
  3630. }
  3631. }
  3632. void MainForm::stopCompiling()
  3633. {
  3634. clear_temp_dir();
  3635. stopCompilingFlag=FALSE;
  3636. errorsCompilingFlag=FALSE;
  3637. compiling=FALSE;
  3638. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  3639. for (SourceFile *sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  3640. sourceFile->fileAddToProjectAction->setEnabled(TRUE);
  3641. sourceFile->fileCompileAction->setEnabled(TRUE);
  3642. sourceFile->fileCloseAction->setEnabled(TRUE);
  3643. }
  3644. debugRunAction->setEnabled(TRUE);
  3645. debugPauseAction->setEnabled(preferences.linkTarget==LT_TIEMU);
  3646. debugResetAction->setEnabled(preferences.linkTarget==LT_TIEMU);
  3647. projectStopCompilationAction->setVisible(FALSE);
  3648. projectForceQuitAction->setVisible(FALSE);
  3649. projectStopCompilationAction->setEnabled(FALSE);
  3650. projectForceQuitAction->setEnabled(FALSE);
  3651. projectCompileAction->setEnabled(TRUE);
  3652. accel->setItemEnabled(15,TRUE);
  3653. projectMakeAction->setEnabled(TRUE);
  3654. accel->setItemEnabled(16,TRUE);
  3655. projectBuildAction->setEnabled(TRUE);
  3656. projectCompileAction->setVisible(TRUE);
  3657. projectMakeAction->setVisible(TRUE);
  3658. projectBuildAction->setVisible(TRUE);
  3659. projectAddFilesAction->setEnabled(TRUE);
  3660. fileExitAction->setEnabled(TRUE);
  3661. fileRecent1Action->setEnabled(TRUE);
  3662. fileRecent2Action->setEnabled(TRUE);
  3663. fileRecent3Action->setEnabled(TRUE);
  3664. fileRecent4Action->setEnabled(TRUE);
  3665. fileOpenAction->setEnabled(TRUE);
  3666. fileNewAction->setEnabled(TRUE);
  3667. fileNewMenu->menuAction()->setEnabled(TRUE);
  3668. statusBar()->clear();
  3669. }
  3670. static QString errorFunction;
  3671. static bool errorFlag;
  3672. static unsigned ldTigccStatPhase=0;
  3673. void MainForm::procio_processExited()
  3674. {
  3675. // If we're in a modal dialog, let it complete or exiting the event loop will
  3676. // crash.
  3677. if (QCoreApplication::loopLevel()>2) {
  3678. QTimer::singleShot(100,this,SLOT(procio_processExited()));
  3679. return;
  3680. }
  3681. errorFunction=QString::null;
  3682. ldTigccStatPhase=0;
  3683. QCoreApplication::exit_loop();
  3684. }
  3685. void MainForm::procio_readReady()
  3686. {
  3687. static int a68kErrorLine=0; // A68k errors are split onto several lines.
  3688. static int errorLine, errorColumn;
  3689. static QString errorFile;
  3690. QString line;
  3691. while (procio->readln(line)>=0) {
  3692. // ld-tigcc doesn't currently know the difference between host charset and
  3693. // calculator charset, so the variable name won't display properly if it
  3694. // contains non-ASCII characters. Fix that up.
  3695. if (ldTigccStatPhase==1
  3696. && line.trimmed().startsWith("Program Variable Name:",FALSE)) {
  3697. int pos=line.find(':');
  3698. while (line[++pos]==' ');
  3699. line.truncate(pos);
  3700. if (!rootListItem->text(0).contains('\\')) line.append("main\\");
  3701. line.append(rootListItem->text(0));
  3702. }
  3703. programOutput.append(line);
  3704. programOutput.append('\n');
  3705. projectProgramOutputAction->setEnabled(TRUE);
  3706. if (line.isEmpty()) continue;
  3707. // Parse the error message
  3708. switch (ldTigccStatPhase) {
  3709. default: // should not happen
  3710. ldTigccStatPhase=0;
  3711. case 0:
  3712. switch (a68kErrorLine) {
  3713. default: // should not happen
  3714. a68kErrorLine=0;
  3715. case 0:
  3716. errorLine=-1;
  3717. errorColumn=-1;
  3718. errorFile=QString::null;
  3719. case 1:
  3720. if (line.contains(QRegExp(" line [0-9]+$",FALSE))) {
  3721. if (line.contains("(user macro)",FALSE))
  3722. errorColumn=0;
  3723. else if (errorFile.isEmpty()) {
  3724. errorFile=QFileInfo(line.left(line.findRev(" line ",-1,FALSE)))
  3725. .fileName();
  3726. errorLine=line.mid(line.findRev(' ')+1).toInt()-1;
  3727. }
  3728. errorFunction=QString::null;
  3729. a68kErrorLine=1;
  3730. } else if (a68kErrorLine==1) {
  3731. // This line contains only a copy of the source line, skip it.
  3732. a68kErrorLine=2;
  3733. } else {
  3734. if (line.contains("Fatal errors - assembly aborted",FALSE)) break;
  3735. // Not an A68k error, so parse it as a standard *nix-style error.
  3736. // Normalize characters and strip whitespace
  3737. line=line.trimmed();
  3738. line.replace('`','\''); // backtick
  3739. line.replace(QChar(0xb4),'\''); // forward apostrophe
  3740. line.replace('\"','\''); // quote
  3741. if (line.contains("assembler messages:",FALSE)
  3742. || line.startsWith("from ",FALSE)
  3743. || (!preferences.allowImplicitDeclaration
  3744. && (line.contains("previous implicit declaration",FALSE)
  3745. || line.contains("previously implicitly declared",FALSE))))
  3746. break;
  3747. // ld-tigcc statistics start here, don't display them as errors.
  3748. if (line.toLower()=="target calculators:") {
  3749. ldTigccStatPhase=1;
  3750. break;
  3751. }
  3752. if (line.startsWith("in file",FALSE))
  3753. errorFunction=QString::null;
  3754. else {
  3755. // The regex also supports Windows file names, in case KTIGCC ever
  3756. // encounters them. Hopefully nobody will try giving it MacOS <=9
  3757. // file names.
  3758. int pos=line.find(QRegExp(":(?![/\\\\])"));
  3759. if (pos>=0) errorFile=line.left(pos);
  3760. if (errorFile.isEmpty()) {
  3761. if (!line.endsWith("."))
  3762. line.append('.');
  3763. errorFlag=TRUE;
  3764. new ErrorListItem(this,line.startsWith("please fill out ",FALSE)?
  3765. etInfo:etError,QString::null,QString::null,line,
  3766. errorLine,errorColumn);
  3767. } else {
  3768. QString errorMessage;
  3769. if (errorFile.toLower()=="error"||errorFile.toLower()=="warning") {
  3770. errorFile=QString::null;
  3771. errorMessage=line;
  3772. } else {
  3773. errorFile=QFileInfo(errorFile).fileName();
  3774. errorMessage=line.mid(pos+1);
  3775. }
  3776. if (!errorMessage.isEmpty() && errorMessage[0]>='0'
  3777. && errorMessage[0]<='9') {
  3778. pos=errorMessage.find(':');
  3779. if (pos>=0) {
  3780. bool ok;
  3781. errorLine=errorMessage.left(pos).toInt(&ok)-1;
  3782. if (ok) {
  3783. errorMessage.remove(0,pos+1);
  3784. if (!errorMessage.isEmpty() && errorMessage[0]>='0'
  3785. && errorMessage[0]<='9') {
  3786. pos=errorMessage.find(':');
  3787. if (pos>=0) {
  3788. errorColumn=errorMessage.left(pos).toInt(&ok)-1;
  3789. if (ok) errorMessage.remove(0,pos+1);
  3790. }
  3791. }
  3792. }
  3793. }
  3794. errorMessage=errorMessage.trimmed();
  3795. ErrorTypes errorType=etError;
  3796. if (errorMessage.startsWith("warning:",FALSE)) {
  3797. errorMessage.remove(0,8);
  3798. errorMessage=errorMessage.trimmed();
  3799. errorType=etWarning;
  3800. } else if (errorMessage.startsWith("error:",FALSE)) {
  3801. errorMessage.remove(0,6);
  3802. errorMessage=errorMessage.trimmed();
  3803. }
  3804. if (errorMessage.startsWith("#warning ",FALSE)) {
  3805. errorMessage.remove(0,9);
  3806. errorType=etWarning;
  3807. } else if (errorMessage.startsWith("#error ",FALSE))
  3808. errorMessage.remove(0,7);
  3809. if (errorMessage.startsWith("previous declaration of ",FALSE)
  3810. || errorMessage.startsWith("possible real start of ",FALSE)
  3811. || errorMessage.startsWith("unused variable ",FALSE)
  3812. || errorMessage.startsWith("unused parameter ",FALSE)
  3813. || errorMessage.contains("previously declared here",FALSE)
  3814. || errorMessage.contains("location of the previous definition",FALSE))
  3815. errorType=etInfo;
  3816. if (!preferences.allowImplicitDeclaration)
  3817. errorMessage.replace(QRegExp("^implicit declaration of ",FALSE),
  3818. "Undefined reference to ");
  3819. if (!errorMessage.endsWith("."))
  3820. errorMessage.append('.');
  3821. if (errorType==etError) errorFlag=TRUE;
  3822. new ErrorListItem(this,errorType,errorFile,errorFunction,
  3823. errorMessage,errorLine,errorColumn);
  3824. } else {
  3825. if (errorMessage.startsWith(" in function \'",FALSE)
  3826. && errorMessage.count('\'')>1) {
  3827. errorFunction=errorMessage.mid(14,errorMessage.find('\'',14)-14);
  3828. } else if (errorMessage.startsWith(" at top level",FALSE)) {
  3829. errorFunction=QString::null;
  3830. } else {
  3831. ErrorTypes errorType=etError;
  3832. if (errorMessage.startsWith("warning:",FALSE)) {
  3833. errorMessage.remove(0,8);
  3834. errorMessage=errorMessage.trimmed();
  3835. errorType=etWarning;
  3836. } else if (errorMessage.startsWith("error:",FALSE)) {
  3837. errorMessage.remove(0,6);
  3838. errorMessage=errorMessage.trimmed();
  3839. }
  3840. if (!errorMessage.endsWith("."))
  3841. errorMessage.append('.');
  3842. if (errorType==etError) errorFlag=TRUE;
  3843. new ErrorListItem(this,errorType,errorFile,QString::null,
  3844. errorMessage,errorLine,errorColumn);
  3845. }
  3846. }
  3847. }
  3848. }
  3849. }
  3850. break;
  3851. case 2:
  3852. if (line.contains(QRegExp("^\\s*\\^"))) {
  3853. int caretPos=line.find('^');
  3854. if (errorLine>=0 && errorColumn<0)
  3855. errorColumn=caretPos-1; // there's an extra tab at the beginning
  3856. QString errorMessage=line.mid(caretPos+2);
  3857. if (!errorMessage.endsWith("."))
  3858. errorMessage.append('.');
  3859. errorFlag=TRUE;
  3860. new ErrorListItem(this,etError,errorFile,QString::null,errorMessage,
  3861. errorLine,errorColumn);
  3862. }
  3863. a68kErrorLine=0;
  3864. break;
  3865. }
  3866. break;
  3867. case 1:
  3868. line=line.trimmed();
  3869. // Collect targets (the data file renaming needs to know them).
  3870. if (line=="TI-89") ti89_targeted=TRUE;
  3871. else if (line=="TI-92 Plus") ti92p_targeted=TRUE;
  3872. else if (line=="V200") v200_targeted=TRUE;
  3873. // The next line is the first one to display in the dialog. (TIGCC IDE
  3874. // does the same.)
  3875. else if (line.startsWith("Program Variable Name:",FALSE))
  3876. ldTigccStatPhase=2;
  3877. break;
  3878. case 2:
  3879. compileStats.append(line.simplified());
  3880. compileStats.append('\n');
  3881. if (line.trimmed().startsWith("Data Variable Size:",FALSE))
  3882. dataFileGenerated=TRUE;
  3883. break;
  3884. }
  3885. }
  3886. if (errorFlag) {
  3887. errorsCompilingFlag=TRUE;
  3888. if (preferences.stopAtFirstError) stopCompilingFlag=TRUE;
  3889. }
  3890. }
  3891. void MainForm::procio_readReady_recordOnly()
  3892. {
  3893. QString line;
  3894. while (procio->readln(line)>=0) {
  3895. programOutput.append(line);
  3896. programOutput.append('\n');
  3897. projectProgramOutputAction->setEnabled(TRUE);
  3898. }
  3899. }
  3900. void MainForm::compileFile(void *srcFile, bool inProject, bool force)
  3901. {
  3902. Q3ListViewItem *category;
  3903. const QString *origFileName;
  3904. bool modified=FALSE;
  3905. QString shortFileName;
  3906. if (stopCompilingFlag) return;
  3907. errorFlag=FALSE;
  3908. if (inProject) {
  3909. ListViewFile *sourceFile=reinterpret_cast<ListViewFile *>(srcFile);
  3910. CATEGORY_OF(cat,sourceFile);
  3911. category=cat;
  3912. origFileName=&(sourceFile->fileName);
  3913. if (sourceFile->modifiedSinceLastCompile)
  3914. modified=TRUE;
  3915. shortFileName=sourceFile->text(0);
  3916. } else {
  3917. SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
  3918. category=reinterpret_cast<Q3ListViewItem *>(sourceFile->category);
  3919. origFileName=&(sourceFile->fileName);
  3920. if (sourceFile->kateView->document()->isModified())
  3921. modified=TRUE;
  3922. shortFileName=sourceFile->fileName;
  3923. }
  3924. if (category==cFilesListItem || category==sFilesListItem
  3925. || category==asmFilesListItem || category==qllFilesListItem) {
  3926. QString objectFile=*origFileName;
  3927. int dotPos=origFileName->findRev('.');
  3928. int slashPos=origFileName->findRev('/');
  3929. if (dotPos>slashPos) objectFile.truncate(dotPos);
  3930. // Compute correct file names for unsaved files.
  3931. if (!objectFile.isEmpty() && objectFile[0]!='/') {
  3932. if (inProject) {
  3933. ListViewFile *sourceFile=reinterpret_cast<ListViewFile *>(srcFile);
  3934. Q3ListViewItem *item=sourceFile->parent();
  3935. while (!IS_CATEGORY(item)) {
  3936. objectFile.prepend('/');
  3937. objectFile.prepend(item->text(0));
  3938. item=item->parent();
  3939. }
  3940. }
  3941. if (!projectFileName.isEmpty()) {
  3942. objectFile.prepend('/');
  3943. objectFile.prepend(QFileInfo(projectFileName).absolutePath());
  3944. }
  3945. }
  3946. QString asmFile=objectFile;
  3947. objectFile.append(".o");
  3948. deletableObjectFiles.append(objectFile);
  3949. objectFiles.append(objectFile);
  3950. asmFile.append(".s");
  3951. mkdir_multi(objectFile);
  3952. if (category==cFilesListItem || category==qllFilesListItem)
  3953. deletableAsmFiles.append(asmFile);
  3954. // Figure out whether to recompile the file.
  3955. if (!force && !modified && !headersModified) {
  3956. QFileInfo objectFileInfo(objectFile);
  3957. if (objectFileInfo.exists()) {
  3958. QDateTime timestamp=objectFileInfo.lastModified();
  3959. if (timestamp.isValid() && (!newestHeaderTimestamp.isValid()
  3960. || timestamp>=newestHeaderTimestamp)) {
  3961. QDateTime sourceTimestamp=QFileInfo(*origFileName).lastModified();
  3962. if (sourceTimestamp.isValid() && timestamp>=sourceTimestamp) {
  3963. return;
  3964. }
  3965. }
  3966. }
  3967. }
  3968. if (category==sFilesListItem||category==asmFilesListItem)
  3969. statusBar()->message(QString("Assembling File \'%1\'...").arg(shortFileName));
  3970. else
  3971. statusBar()->message(QString("Compiling File \'%1\'...").arg(shortFileName));
  3972. projectNeedsRelink=TRUE;
  3973. QString fileName=writeTempSourceFile(srcFile,inProject);
  3974. if (stopCompilingFlag) return;
  3975. QString tempObjectFile=fileName;
  3976. dotPos=fileName.findRev('.');
  3977. slashPos=fileName.findRev('/');
  3978. if (dotPos>slashPos) tempObjectFile.truncate(dotPos);
  3979. QString tempAsmFile=tempObjectFile;
  3980. tempObjectFile.append(".o");
  3981. tempAsmFile.append(".s");
  3982. QString fileDir=QFileInfo(fileName).absolutePath();
  3983. QDir qdir;
  3984. if (category==asmFilesListItem) {
  3985. // Assemble A68k file
  3986. int err;
  3987. QStringList args=KShell::splitArgs(settings.a68k_switches,
  3988. KShell::TildeExpand|KShell::AbortOnMeta,
  3989. &err);
  3990. if (err) {
  3991. new ErrorListItem(this,etError,QString::null,QString::null,
  3992. "Invalid A68k assembler command line options.",-1,-1);
  3993. stopCompilingFlag=TRUE;
  3994. }
  3995. if (!stopCompilingFlag) {
  3996. // The QTextCodec has to be passed explicitly, or it will default to
  3997. // ISO-8859-1 regardless of the locale, which is just broken.
  3998. procio=new KProcIO(QTextCodec::codecForLocale());
  3999. // Use MergedStderr instead of Stderr so the messages get ordered
  4000. // properly.
  4001. procio->setComm(static_cast<KProcess::Communication>(
  4002. KProcess::Stdout|KProcess::MergedStderr));
  4003. procio->setWorkingDirectory(fileDir);
  4004. *procio<<(QString("%1/bin/a68k").arg(tigcc_base))
  4005. <<fileName<<(QString("-o%1").arg(tempObjectFile))
  4006. <<(QString("-i%1/include/asm/").arg(tigcc_base))<<"-q"<<args;
  4007. if (settings.cut_ranges||settings.archive)
  4008. *procio<<"-a"; // all relocs
  4009. if (settings.optimize_returns||settings.archive)
  4010. *procio<<"-d"; // keep locals
  4011. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4012. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4013. procio->start();
  4014. // We need to block here, but events still need to be handled. The most
  4015. // effective way to do this is to enter the event loop recursively,
  4016. // even though it is not recommended by Qt.
  4017. QCoreApplication::enter_loop();
  4018. // This will be reached only after exitLoop() is called.
  4019. delete procio;
  4020. procio=static_cast<KProcIO *>(NULL);
  4021. }
  4022. } else {
  4023. bool deleteTempAsmFile=FALSE;
  4024. QString fileNameToAssemble;
  4025. if (category==sFilesListItem) {
  4026. fileNameToAssemble=fileName;
  4027. } else /* C or Quill */ {
  4028. // Compile C/Quill file to assembly
  4029. int err;
  4030. QStringList args=KShell::splitArgs(settings.cc_switches,
  4031. KShell::TildeExpand|KShell::AbortOnMeta,
  4032. &err);
  4033. if (err) {
  4034. new ErrorListItem(this,etError,QString::null,QString::null,
  4035. "Invalid C compiler command line options.",-1,-1);
  4036. stopCompilingFlag=TRUE;
  4037. }
  4038. if (!stopCompilingFlag) {
  4039. // The QTextCodec has to be passed explicitly, or it will default to
  4040. // ISO-8859-1 regardless of the locale, which is just broken.
  4041. procio=new KProcIO(QTextCodec::codecForLocale());
  4042. // Use MergedStderr instead of Stderr so the messages get ordered
  4043. // properly.
  4044. procio->setComm(static_cast<KProcess::Communication>(
  4045. KProcess::Stdout|KProcess::MergedStderr));
  4046. procio->setWorkingDirectory(fileDir);
  4047. *procio<<(QString("%1/bin/gcc").arg(tigcc_base))
  4048. <<"-S"<<"-I"<<fileDir
  4049. <<"-B"<<(QString("%1/bin/").arg(tigcc_base))<<"-I-"
  4050. <<"-I"<<(QString("%1/include/c").arg(tigcc_base))<<args;
  4051. if (category==qllFilesListItem) { // Quill needs special switches.
  4052. *procio<<"-I"<<(QString("%1/include/quill").arg(tigcc_base))
  4053. <<"-include"<<quill_drv;
  4054. }
  4055. if (settings.use_data_var)
  4056. *procio<<"-mno-merge-sections";
  4057. if (!preferences.allowImplicitDeclaration)
  4058. *procio<<"-Werror-implicit-function-declaration";
  4059. if (settings.debug_info)
  4060. *procio<<"-gdwarf-2"<<"-g3"<<"-fasynchronous-unwind-tables";
  4061. if (settings.fargo)
  4062. *procio<<"-DFARGO";
  4063. else if (settings.flash_os)
  4064. *procio<<"-DFLASH_OS";
  4065. else if (!settings.archive) { // This leaves only regular programs.
  4066. *procio<<process_libopts();
  4067. }
  4068. *procio<<fileName<<"-o"<<tempAsmFile;
  4069. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4070. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4071. procio->start();
  4072. // We need to block here, but events still need to be handled. The most
  4073. // effective way to do this is to enter the event loop recursively,
  4074. // even though it is not recommended by Qt.
  4075. QCoreApplication::enter_loop();
  4076. // This will be reached only after exitLoop() is called.
  4077. delete procio;
  4078. procio=static_cast<KProcIO *>(NULL);
  4079. }
  4080. if (!stopCompilingFlag && qdir.exists(tempAsmFile)) {
  4081. // Run patcher.
  4082. // The QTextCodec has to be passed explicitly, or it will default to
  4083. // ISO-8859-1 regardless of the locale, which is just broken.
  4084. procio=new KProcIO(QTextCodec::codecForLocale());
  4085. // Use MergedStderr instead of Stderr so the messages get ordered
  4086. // properly.
  4087. procio->setComm(static_cast<KProcess::Communication>(
  4088. KProcess::Stdout|KProcess::MergedStderr));
  4089. procio->setWorkingDirectory(fileDir);
  4090. *procio<<(QString("%1/bin/patcher").arg(tigcc_base))
  4091. <<tempAsmFile<<"-o"<<tempAsmFile;
  4092. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4093. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4094. procio->start();
  4095. // We need to block here, but events still need to be handled. The most
  4096. // effective way to do this is to enter the event loop recursively,
  4097. // even though it is not recommended by Qt.
  4098. QCoreApplication::enter_loop();
  4099. // This will be reached only after exitLoop() is called.
  4100. delete procio;
  4101. procio=static_cast<KProcIO *>(NULL);
  4102. }
  4103. if (qdir.exists(tempAsmFile)) {
  4104. if (!stopCompilingFlag) {
  4105. fileNameToAssemble=tempAsmFile;
  4106. qdir.remove(asmFile);
  4107. if (copyFile(tempAsmFile.ascii(),asmFile.ascii())) {
  4108. new ErrorListItem(this,etError,QString::null,QString::null,
  4109. "Failed to copy assembly file from temporary directory.",
  4110. -1,-1);
  4111. stopCompilingFlag=TRUE;
  4112. }
  4113. }
  4114. deleteTempAsmFile=TRUE;
  4115. } else {
  4116. errorFlag=TRUE;
  4117. errorsCompilingFlag=TRUE;
  4118. if (preferences.stopAtFirstError) stopCompilingFlag=TRUE;
  4119. }
  4120. }
  4121. // Assemble GNU as file
  4122. if (!stopCompilingFlag && !fileNameToAssemble.isNull()) {
  4123. int err;
  4124. QStringList args=KShell::splitArgs(settings.as_switches,
  4125. KShell::TildeExpand|KShell::AbortOnMeta,
  4126. &err);
  4127. if (err) {
  4128. new ErrorListItem(this,etError,QString::null,QString::null,
  4129. "Invalid GNU assembler command line options.",-1,-1);
  4130. stopCompilingFlag=TRUE;
  4131. }
  4132. if (!stopCompilingFlag) {
  4133. // The QTextCodec has to be passed explicitly, or it will default to
  4134. // ISO-8859-1 regardless of the locale, which is just broken.
  4135. procio=new KProcIO(QTextCodec::codecForLocale());
  4136. // Use MergedStderr instead of Stderr so the messages get ordered
  4137. // properly.
  4138. procio->setComm(static_cast<KProcess::Communication>(
  4139. KProcess::Stdout|KProcess::MergedStderr));
  4140. procio->setWorkingDirectory(fileDir);
  4141. *procio<<(QString("%1/bin/as").arg(tigcc_base))
  4142. <<"-I"<<fileDir<<"-mc68000"
  4143. <<"-I"<<(QString("%1/include/s").arg(tigcc_base))<<args;
  4144. if (settings.cut_ranges||settings.archive)
  4145. *procio<<"--all-relocs";
  4146. if (settings.optimize_returns||settings.archive)
  4147. *procio<<"--keep-locals";
  4148. if (settings.debug_info)
  4149. *procio<<"--gdwarf2";
  4150. *procio<<fileNameToAssemble<<"-o"<<tempObjectFile;
  4151. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4152. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4153. procio->start();
  4154. // We need to block here, but events still need to be handled. The most
  4155. // effective way to do this is to enter the event loop recursively,
  4156. // even though it is not recommended by Qt.
  4157. QCoreApplication::enter_loop();
  4158. // This will be reached only after exitLoop() is called.
  4159. delete procio;
  4160. procio=static_cast<KProcIO *>(NULL);
  4161. }
  4162. }
  4163. if (deleteTempAsmFile) qdir.remove(tempAsmFile);
  4164. }
  4165. qdir.remove(fileName);
  4166. if (qdir.exists(tempObjectFile)) {
  4167. qdir.remove(objectFile);
  4168. if (copyFile(tempObjectFile.ascii(),objectFile.ascii())) {
  4169. new ErrorListItem(this,etError,QString::null,QString::null,
  4170. "Failed to copy object file from temporary directory.",
  4171. -1,-1);
  4172. stopCompilingFlag=TRUE;
  4173. }
  4174. qdir.remove(tempObjectFile);
  4175. } else {
  4176. errorFlag=TRUE;
  4177. errorsCompilingFlag=TRUE;
  4178. if (preferences.stopAtFirstError) stopCompilingFlag=TRUE;
  4179. }
  4180. } else if (category==oFilesListItem || category==aFilesListItem) {
  4181. objectFiles.append(*origFileName);
  4182. } // else do nothing (ignore all other categories)
  4183. if (inProject && !errorFlag && !stopCompilingFlag)
  4184. reinterpret_cast<ListViewFile *>(srcFile)->modifiedSinceLastCompile=FALSE;
  4185. }
  4186. void MainForm::compileProject(bool forceAll)
  4187. {
  4188. Q3ListViewItemIterator lvit(fileTree);
  4189. Q3ListViewItem *item;
  4190. for (item=lvit.current(); item&&!stopCompilingFlag; item=(++lvit).current()) {
  4191. if (IS_FILE(item))
  4192. compileFile(static_cast<ListViewFile *>(item),TRUE,forceAll);
  4193. }
  4194. if (!errorsCompilingFlag && !stopCompilingFlag) headersModified=FALSE;
  4195. }
  4196. void MainForm::linkProject()
  4197. {
  4198. errorFlag=FALSE;
  4199. QString projectBaseName=projectFileName;
  4200. if (projectBaseName.endsWith(".tpr",FALSE))
  4201. projectBaseName.truncate(projectBaseName.length()-4);
  4202. QString projectDir=QFileInfo(projectFileName).absolutePath();
  4203. statusBar()->message(QString("Linking Project \'%1\'...")
  4204. .arg(QFileInfo(projectFileName).baseName()));
  4205. if (settings.archive) {
  4206. // Link static library using ar-tigcc.
  4207. // The QTextCodec has to be passed explicitly, or it will default to
  4208. // ISO-8859-1 regardless of the locale, which is just broken.
  4209. procio=new KProcIO(QTextCodec::codecForLocale());
  4210. // Use MergedStderr instead of Stderr so the messages get ordered
  4211. // properly.
  4212. procio->setComm(static_cast<KProcess::Communication>(
  4213. KProcess::Stdout|KProcess::MergedStderr));
  4214. procio->setWorkingDirectory(projectDir);
  4215. *procio<<(QString("%1/bin/ar-tigcc").arg(tigcc_base))
  4216. <<"-o"<<(projectBaseName+".a")<<"--no-names"<<objectFiles;
  4217. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4218. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4219. procio->start();
  4220. // We need to block here, but events still need to be handled. The most
  4221. // effective way to do this is to enter the event loop recursively,
  4222. // even though it is not recommended by Qt.
  4223. QCoreApplication::enter_loop();
  4224. // This will be reached only after exitLoop() is called.
  4225. delete procio;
  4226. procio=static_cast<KProcIO *>(NULL);
  4227. if (errorsCompilingFlag || stopCompilingFlag) return;
  4228. QFileInfo fileInfo(projectBaseName+".a");
  4229. if (fileInfo.exists())
  4230. compileStats=QString("Archive Size: %1 Bytes\n").arg(fileInfo.size());
  4231. else
  4232. errorsCompilingFlag=TRUE;
  4233. } else {
  4234. // Link executable using ld-tigcc.
  4235. QString linkOutput=settings.pack?QString("%1/tempprog").arg(tempdir)
  4236. :projectBaseName;
  4237. QByteArray projectName, dataVarName, packFolder, packName;
  4238. QStringList linkerOptions=process_settings(rootListItem->text(0),
  4239. projectName,dataVarName,
  4240. packFolder,packName);
  4241. // The QTextCodec has to be passed explicitly, or it will default to
  4242. // ISO-8859-1 regardless of the locale, which is just broken.
  4243. procio=new KProcIO(QTextCodec::codecForLocale());
  4244. // Use MergedStderr instead of Stderr so the messages get ordered
  4245. // properly.
  4246. procio->setComm(static_cast<KProcess::Communication>(
  4247. KProcess::Stdout|KProcess::MergedStderr));
  4248. procio->setWorkingDirectory(projectDir);
  4249. *procio<<(QString("%1/bin/ld-tigcc").arg(tigcc_base))
  4250. <<"-v"<<"-o"<<linkOutput<<"-n"<<projectName;
  4251. if (!dataVarName.isNull()) *procio<<"-d"<<dataVarName;
  4252. *procio<<linkerOptions<<objectFiles;
  4253. if (settings.std_lib)
  4254. *procio<<QString(settings.flash_os?"%1/lib/flashos.a"
  4255. :(settings.fargo?"%1/lib/fargo.a"
  4256. :"%1/lib/tigcc.a"))
  4257. .arg(tigcc_base);
  4258. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4259. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4260. procio->start();
  4261. // We need to block here, but events still need to be handled. The most
  4262. // effective way to do this is to enter the event loop recursively,
  4263. // even though it is not recommended by Qt.
  4264. QCoreApplication::enter_loop();
  4265. // This will be reached only after exitLoop() is called.
  4266. delete procio;
  4267. procio=static_cast<KProcIO *>(NULL);
  4268. if (errorsCompilingFlag || stopCompilingFlag) return;
  4269. // Rename the data file so it doesn't conflict with PPGs.
  4270. if (dataFileGenerated) {
  4271. QDir qdir;
  4272. const int numTargets=3;
  4273. bool targeted[numTargets]={ti89_targeted,ti92p_targeted,v200_targeted};
  4274. static const char dextsbin[numTargets][5]={".y89",".y9x",".yv2"};
  4275. static const char dextswrapped[numTargets][5]={".89y",".9xy",".v2y"};
  4276. static const char (*dexts)[5]=(settings.outputbin&&!settings.pack)?dextsbin:dextswrapped;
  4277. for (int target=0; target<numTargets; target++) {
  4278. if (targeted[numTargets]) {
  4279. qdir.remove(projectBaseName+"-data"+dexts[target]);
  4280. if (!moveFile(linkOutput+dexts[target],
  4281. projectBaseName+"-data"+dexts[target])) {
  4282. new ErrorListItem(this,etError,QString::null,QString::null,
  4283. "Failed to rename data file.",-1,-1);
  4284. errorsCompilingFlag=TRUE;
  4285. }
  4286. if (errorsCompilingFlag || stopCompilingFlag) return;
  4287. }
  4288. }
  4289. }
  4290. if (settings.pack) {
  4291. // Copy over the .dbg file from the temporary directory if it exists.
  4292. // Current TiEmu can't handle compressed programs, but maybe some day.
  4293. if (QFileInfo(linkOutput+".dbg").exists()) {
  4294. if (copyFile(linkOutput+".dbg",
  4295. projectBaseName+".dbg")) {
  4296. new ErrorListItem(this,etError,QString::null,QString::null,
  4297. "Failed to copy debug info file from temporary directory.",
  4298. -1,-1);
  4299. errorsCompilingFlag=TRUE;
  4300. }
  4301. }
  4302. if (errorsCompilingFlag || stopCompilingFlag) return;
  4303. statusBar()->message("Compressing...");
  4304. const int numTargets=3;
  4305. static const char binexts[numTargets][5]={".z89",".z9x",".zv2"};
  4306. static const char exts[numTargets][5]={".89z",".9xz",".v2z"};
  4307. static const char cbinexts[numTargets][5]={".y89",".y9x",".yv2"};
  4308. static const char cexts[numTargets][5]={".89y",".9xy",".v2y"};
  4309. // ttbin2oth STILL has no V200 support. Work around that.
  4310. static const char ttbin2othflag[numTargets][4]={"-89","-92","-92"};
  4311. static const char ttbin2othexts[numTargets][5]={".89y",".9xy",".9xy"};
  4312. bool targeted[numTargets];
  4313. for (int target=0; target<numTargets; target++) {
  4314. targeted[target]=QFileInfo(linkOutput+binexts[target]).exists();
  4315. if (targeted[target]) {
  4316. // Compress binary using ttpack.
  4317. // The QTextCodec has to be passed explicitly, or it will default to
  4318. // ISO-8859-1 regardless of the locale, which is just broken.
  4319. procio=new KProcIO(QTextCodec::codecForLocale());
  4320. // Use MergedStderr instead of Stderr so the messages get ordered
  4321. // properly.
  4322. procio->setComm(static_cast<KProcess::Communication>(
  4323. KProcess::Stdout|KProcess::MergedStderr));
  4324. procio->setWorkingDirectory(tempdir);
  4325. // It is not possible to pass an absolute POSIX path to ttpack because
  4326. // it mistakes it for a switch.
  4327. *procio<<(QString("%1/bin/ttpack").arg(tigcc_base))
  4328. <<"-quiet"<<(QString("tempprog")+binexts[target])
  4329. <<(QString("tempprog")+cbinexts[target]);
  4330. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4331. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4332. procio->start();
  4333. // We need to block here, but events still need to be handled. The most
  4334. // effective way to do this is to enter the event loop recursively,
  4335. // even though it is not recommended by Qt.
  4336. QCoreApplication::enter_loop();
  4337. // This will be reached only after exitLoop() is called.
  4338. delete procio;
  4339. procio=static_cast<KProcIO *>(NULL);
  4340. if (!QFileInfo(linkOutput+cbinexts[target]).exists())
  4341. errorsCompilingFlag=TRUE;
  4342. if (errorsCompilingFlag || stopCompilingFlag) return;
  4343. // Wrap binary using ttbin2oth.
  4344. // The QTextCodec has to be passed explicitly, or it will default to
  4345. // ISO-8859-1 regardless of the locale, which is just broken.
  4346. procio=new KProcIO(QTextCodec::codecForLocale());
  4347. // Use MergedStderr instead of Stderr so the messages get ordered
  4348. // properly.
  4349. procio->setComm(static_cast<KProcess::Communication>(
  4350. KProcess::Stdout|KProcess::MergedStderr));
  4351. procio->setWorkingDirectory(tempdir);
  4352. // ttbin2oth tries to use the calculator file name as the host file
  4353. // name. This is bad because the calculator charset is not necessarily
  4354. // the same as the host charset, and files which are not valid host
  4355. // charset names may be corrupted by the file system if it uses
  4356. // Unicode internally (e.g. FAT). So use "tempprog" and then change
  4357. // the name. Moreover, it is not possible to pass an absolute POSIX
  4358. // path to ttbin2oth because it mistakes it for a switch.
  4359. *procio<<(QString("%1/bin/ttbin2oth").arg(tigcc_base))
  4360. <<"-quiet"<<ttbin2othflag[target]<<"ppg"
  4361. <<(QString("tempprog")+cbinexts[target])<<"tempprog";
  4362. if (!packFolder.isNull()) *procio<<packFolder;
  4363. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4364. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4365. procio->start();
  4366. // We need to block here, but events still need to be handled. The most
  4367. // effective way to do this is to enter the event loop recursively,
  4368. // even though it is not recommended by Qt.
  4369. QCoreApplication::enter_loop();
  4370. // This will be reached only after exitLoop() is called.
  4371. delete procio;
  4372. procio=static_cast<KProcIO *>(NULL);
  4373. if (!QFileInfo(linkOutput+ttbin2othexts[target]).exists())
  4374. errorsCompilingFlag=TRUE;
  4375. if (errorsCompilingFlag || stopCompilingFlag) return;
  4376. if (insertName(linkOutput+ttbin2othexts[target],
  4377. projectBaseName+cexts[target],packName)) {
  4378. new ErrorListItem(this,etError,QString::null,QString::null,
  4379. "Failed to copy PPG from temporary directory.",
  4380. -1,-1);
  4381. errorsCompilingFlag=TRUE;
  4382. }
  4383. if (errorsCompilingFlag || stopCompilingFlag) return;
  4384. }
  4385. }
  4386. // Prepare the pstarter.
  4387. QString pstarterBaseName=QString("%1/pstarter").arg(tempdir);
  4388. if (insertName(QString("%1/lib/pstarter.o").arg(tigcc_base),
  4389. pstarterBaseName+".o",packName)) {
  4390. new ErrorListItem(this,etError,QString::null,QString::null,
  4391. "Failed to copy pstarter.o to temporary directory.",
  4392. -1,-1);
  4393. errorsCompilingFlag=TRUE;
  4394. }
  4395. if (errorsCompilingFlag || stopCompilingFlag) return;
  4396. // Link the pstarter with ld-tigcc.
  4397. // The QTextCodec has to be passed explicitly, or it will default to
  4398. // ISO-8859-1 regardless of the locale, which is just broken.
  4399. procio=new KProcIO(QTextCodec::codecForLocale());
  4400. // Use MergedStderr instead of Stderr so the messages get ordered
  4401. // properly.
  4402. procio->setComm(static_cast<KProcess::Communication>(
  4403. KProcess::Stdout|KProcess::MergedStderr));
  4404. procio->setWorkingDirectory(projectDir);
  4405. *procio<<(QString("%1/bin/ld-tigcc").arg(tigcc_base))
  4406. <<"-o"<<pstarterBaseName<<"-n"<<projectName
  4407. <<(pstarterBaseName+".o");
  4408. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4409. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady()));
  4410. procio->start();
  4411. // We need to block here, but events still need to be handled. The most
  4412. // effective way to do this is to enter the event loop recursively,
  4413. // even though it is not recommended by Qt.
  4414. QCoreApplication::enter_loop();
  4415. // This will be reached only after exitLoop() is called.
  4416. delete procio;
  4417. procio=static_cast<KProcIO *>(NULL);
  4418. if (errorsCompilingFlag || stopCompilingFlag) return;
  4419. // Now copy those pstarters actually requested.
  4420. for (int target=0; target<numTargets; target++) {
  4421. if (targeted[target]) {
  4422. if (copyFile(pstarterBaseName+exts[target],
  4423. projectBaseName+exts[target])) {
  4424. new ErrorListItem(this,etError,QString::null,QString::null,
  4425. "Failed to copy pstarter from temporary directory.",
  4426. -1,-1);
  4427. errorsCompilingFlag=TRUE;
  4428. }
  4429. if (errorsCompilingFlag || stopCompilingFlag) return;
  4430. }
  4431. }
  4432. // Remove any leftover "-titanium" launchers if the TI-89 is targeted.
  4433. if (*targeted) {
  4434. QDir qdir;
  4435. qdir.remove(projectBaseName+"-titanium.89z");
  4436. qdir.remove(projectBaseName+"-Titanium.89z");
  4437. }
  4438. }
  4439. }
  4440. if (errorsCompilingFlag || stopCompilingFlag) return;
  4441. if (!settings.post_build.isEmpty()) {
  4442. // Post-build processing.
  4443. statusBar()->message("Calling User-Defined Program...");
  4444. QString postBuild=settings.post_build;
  4445. // Remove double quotes for TIGCC IDE compatibility. Single quotes will be
  4446. // added instead.
  4447. postBuild.replace("\"($TI89FILE)\"","($TI89FILE)",FALSE);
  4448. postBuild.replace("\"($TI89TIFILE)\"","($TI89TIFILE)",FALSE);
  4449. postBuild.replace("\"($TI92PLUSFILE)\"","($TI92PLUSFILE)",FALSE);
  4450. postBuild.replace("\"($V200FILE)\"","($V200FILE)",FALSE);
  4451. postBuild.replace("\"($TI92FILE)\"","($TI92FILE)",FALSE);
  4452. postBuild.replace("($TI89FILE)",
  4453. KProcess::quote(libopts.use_ti89?projectBaseName+(
  4454. settings.archive?".a":settings.flash_os?"-89.tib":settings.pack?".89y":
  4455. settings.outputbin?".z89":".89z"
  4456. ):""),FALSE);
  4457. postBuild.replace("($TI89TIFILE)",
  4458. KProcess::quote(libopts.use_ti89?projectBaseName+(
  4459. settings.archive?".a":settings.flash_os?"-89ti.tib":settings.pack?".89y":
  4460. settings.outputbin?".z89":".89z"
  4461. ):""),FALSE);
  4462. postBuild.replace("($TI92PLUSFILE)",
  4463. KProcess::quote(libopts.use_ti92p?projectBaseName+(
  4464. settings.archive?".a":settings.flash_os?"-9x.tib":settings.pack?".9xy":
  4465. settings.outputbin?".z9x":".9xz"
  4466. ):""),FALSE);
  4467. postBuild.replace("($V200FILE)",
  4468. KProcess::quote(libopts.use_v200?projectBaseName+(
  4469. settings.archive?".a":settings.flash_os?"-v2.tib":settings.pack?".v2y":
  4470. settings.outputbin?".zv2":".v2z"
  4471. ):""),FALSE);
  4472. postBuild.replace("($TI92FILE)",
  4473. KProcess::quote(settings.fargo?projectBaseName+(
  4474. settings.outputbin?".p92":".92p"
  4475. ):""),FALSE);
  4476. int err;
  4477. QStringList args=KShell::splitArgs(postBuild,
  4478. KShell::TildeExpand|KShell::AbortOnMeta,
  4479. &err);
  4480. if (err) {
  4481. new ErrorListItem(this,etError,QString::null,QString::null,
  4482. "Invalid post-build command line.",-1,-1);
  4483. errorsCompilingFlag=TRUE;
  4484. }
  4485. if (errorsCompilingFlag || stopCompilingFlag) return;
  4486. // The QTextCodec has to be passed explicitly, or it will default to
  4487. // ISO-8859-1 regardless of the locale, which is just broken.
  4488. procio=new KProcIO(QTextCodec::codecForLocale());
  4489. // Use MergedStderr instead of Stderr so the messages get ordered
  4490. // properly.
  4491. procio->setComm(static_cast<KProcess::Communication>(
  4492. KProcess::Stdout|KProcess::MergedStderr));
  4493. procio->setWorkingDirectory(projectDir);
  4494. *procio<<args;
  4495. connect(procio,SIGNAL(processExited(KProcess*)),this,SLOT(procio_processExited()));
  4496. connect(procio,SIGNAL(readReady(KProcIO*)),this,SLOT(procio_readReady_recordOnly()));
  4497. procio->start();
  4498. // We need to block here, but events still need to be handled. The most
  4499. // effective way to do this is to enter the event loop recursively,
  4500. // even though it is not recommended by Qt.
  4501. QCoreApplication::enter_loop();
  4502. // This will be reached only after exitLoop() is called.
  4503. delete procio;
  4504. procio=static_cast<KProcIO *>(NULL);
  4505. if (errorsCompilingFlag || stopCompilingFlag) return;
  4506. }
  4507. // Delete object and/or assembly files.
  4508. QDir qdir;
  4509. if (preferences.deleteObjFiles) {
  4510. for (QStringList::Iterator it=deletableObjectFiles.begin();
  4511. it!=deletableObjectFiles.end(); ++it) {
  4512. qdir.remove(*it);
  4513. }
  4514. }
  4515. if (preferences.deleteAsmFiles) {
  4516. for (QStringList::Iterator it=deletableAsmFiles.begin();
  4517. it!=deletableAsmFiles.end(); ++it) {
  4518. qdir.remove(*it);
  4519. }
  4520. }
  4521. projectNeedsRelink=FALSE;
  4522. }
  4523. void MainForm::showStats()
  4524. {
  4525. // KMessageBox also takes plain text, but it interprets \n as paragraph breaks
  4526. // and always renders them as \n\n, no matter whether there is actually just
  4527. // one, two or more than two \n characters. Thus the
  4528. // QStyleSheet::convertFromPlainText. Sadly, that replaces the spaces with
  4529. // strange non-BMP characters (from a Private Use Area) which don't display
  4530. // properly in KMessageBox, so fix up those surrogate pairs.
  4531. if (KMessageBox::questionYesNo(this,Qt::convertFromPlainText(
  4532. QString("The project has been compiled successfully.\n\n%1\n"
  4533. "Do you want to open the project folder?").arg(compileStats))
  4534. .replace(QString(QChar(56319))+QString(QChar(56992))," "),
  4535. "Compilation Successful")==KMessageBox::Yes) {
  4536. KUrl projectDir(projectFileName);
  4537. projectDir.setFileName("");
  4538. KRun::runUrl(projectDir,"inode/directory",this);
  4539. }
  4540. }
  4541. void MainForm::projectCompile()
  4542. {
  4543. if (compiling) return;
  4544. startCompiling();
  4545. compileProject(FALSE);
  4546. stopCompiling();
  4547. }
  4548. void MainForm::projectMake()
  4549. {
  4550. if (compiling) return;
  4551. // Can't link a project without saving it first.
  4552. if (projectFileName.isEmpty()) {
  4553. if (!fileSave() || projectFileName.isEmpty()) return;
  4554. }
  4555. startCompiling();
  4556. compileProject(FALSE);
  4557. if (!errorsCompilingFlag && !stopCompilingFlag) linkProject();
  4558. bool success=(!errorsCompilingFlag && !stopCompilingFlag);
  4559. stopCompiling();
  4560. if (success && preferences.successMessage)
  4561. showStats();
  4562. }
  4563. void MainForm::projectBuild()
  4564. {
  4565. if (compiling) return;
  4566. // Can't link a project without saving it first.
  4567. if (projectFileName.isEmpty()) {
  4568. if (!fileSave() || projectFileName.isEmpty()) return;
  4569. }
  4570. startCompiling();
  4571. compileProject(TRUE);
  4572. if (!errorsCompilingFlag && !stopCompilingFlag) linkProject();
  4573. bool success=(!errorsCompilingFlag && !stopCompilingFlag);
  4574. stopCompiling();
  4575. if (success && preferences.successMessage)
  4576. showStats();
  4577. }
  4578. void MainForm::compileSourceFile(void *srcFile)
  4579. {
  4580. if (compiling) return;
  4581. SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
  4582. sourceFile->fileCloseAction->setEnabled(FALSE);
  4583. startCompiling();
  4584. compileFile(sourceFile,FALSE,TRUE);
  4585. stopCompiling();
  4586. }
  4587. void MainForm::projectStopCompilation()
  4588. {
  4589. if (!compiling) return;
  4590. stopCompilingFlag=TRUE;
  4591. projectStopCompilationAction->setEnabled(FALSE);
  4592. }
  4593. void MainForm::projectForceQuit()
  4594. {
  4595. if (!compiling) return;
  4596. stopCompilingFlag=TRUE;
  4597. if (procio && procio->isRunning()) {
  4598. procio->kill();
  4599. }
  4600. }
  4601. void MainForm::projectErrorsAndWarnings(bool on)
  4602. {
  4603. static bool lock=FALSE;
  4604. if (!lock) {
  4605. lock=TRUE;
  4606. if (!projectErrorsAndWarningsAction->isEnabled()) on=FALSE;
  4607. projectErrorsAndWarningsAction->setOn(on);
  4608. if (on)
  4609. errorListDock->show();
  4610. else
  4611. errorListDock->hide();
  4612. lock=FALSE;
  4613. }
  4614. }
  4615. void MainForm::projectProgramOutput()
  4616. {
  4617. ProgramOutput programOutputDialog;
  4618. programOutputDialog.textBrowser->setText(programOutput);
  4619. programOutputDialog.exec();
  4620. }
  4621. void MainForm::projectOptions()
  4622. {
  4623. ProjectOptions *projectoptions=new ProjectOptions(this);
  4624. projectoptions->exec();
  4625. if (projectoptions->result()==QDialog::Accepted) {
  4626. projectIsDirty=TRUE;
  4627. projectNeedsRelink=TRUE;
  4628. headersModified=TRUE; // force complete rebuild
  4629. }
  4630. delete(projectoptions);
  4631. bool runnable=!settings.archive&&!settings.flash_os&&preferences.linkTarget!=LT_NONE;
  4632. menuBar()->setItemVisible(5,runnable); //debugMenu
  4633. debugRunAction->setVisible(runnable);
  4634. debugPauseAction->setVisible(runnable);
  4635. }
  4636. bool MainForm::tiemuInstance(TiEmuDBus *&instance)
  4637. {
  4638. QDBusConnection connection=QDBusConnection::sessionBus();
  4639. if (!connection.isConnected()) {
  4640. KMessageBox::error(this,"Can\'t attach to D-Bus.");
  4641. instance=NULL;
  4642. return FALSE;
  4643. }
  4644. instance=new TiEmuDBus("org.ticalc.lpg.tiemu.TiEmuDBus",
  4645. "/org/ticalc/lpg/tiemu/TiEmuDBus",connection,this);
  4646. if (!instance->isValid()) {
  4647. delete instance;
  4648. instance=NULL;
  4649. }
  4650. return TRUE;
  4651. }
  4652. // Same values as TIGCC, except for CALCULATOR_INVALID.
  4653. enum CalculatorModels {CALCULATOR_TI89, CALCULATOR_TI92P, CALCULATOR_TI92,
  4654. CALCULATOR_V200, CALCULATOR_INVALID=-1};
  4655. QString MainForm::tilibsErrorMessage(int err)
  4656. {
  4657. if (!err) return "No error. (This is a bug, please report.)";
  4658. char *msg=0;
  4659. if ((err=ticables_error_get(err,&msg))
  4660. && (err=tifiles_error_get(err,&msg))
  4661. && (err=ticalcs_error_get(err,&msg)))
  4662. return "Invalid error code. (This is a bug, please report.)";
  4663. QString ret=msg;
  4664. g_free(msg);
  4665. return ret;
  4666. }
  4667. void MainForm::debugRun()
  4668. {
  4669. if (compiling) return;
  4670. // Can't link a project without saving it first.
  4671. if (projectFileName.isEmpty()) {
  4672. if (!fileSave() || projectFileName.isEmpty()) return;
  4673. }
  4674. startCompiling();
  4675. compileProject(FALSE);
  4676. if (!errorsCompilingFlag && !stopCompilingFlag && projectNeedsRelink)
  4677. linkProject();
  4678. bool success=(!errorsCompilingFlag && !stopCompilingFlag);
  4679. stopCompiling();
  4680. QString projectBaseName=projectFileName;
  4681. if (projectBaseName.endsWith(".tpr",FALSE))
  4682. projectBaseName.truncate(projectBaseName.length()-4);
  4683. if (success && (QFileInfo(projectBaseName+".89z").exists()
  4684. || QFileInfo(projectBaseName+".9xz").exists()
  4685. || QFileInfo(projectBaseName+".v2z").exists()
  4686. || QFileInfo(projectBaseName+".92p").exists())) {
  4687. QStringList files;
  4688. if (settings.fargo)
  4689. files.append(projectBaseName+".92p");
  4690. else {
  4691. files.append(projectBaseName+".89z");
  4692. if (settings.pack) files.append(projectBaseName+".89y");
  4693. if (settings.use_data_var) files.append(projectBaseName+"-data.89y");
  4694. }
  4695. if (files.isEmpty()) return;
  4696. // Detect model of linked calculator.
  4697. CalculatorModels model=CALCULATOR_INVALID;
  4698. TiEmuDBus *tiemuDBus=0;
  4699. CableHandle *cable=0;
  4700. CalcHandle *calc=0;
  4701. switch (preferences.linkTarget) {
  4702. case LT_TIEMU:
  4703. {
  4704. // Fire up TiEmu if it isn't running yet.
  4705. if (!tiemuInstance(tiemuDBus)) return;
  4706. if (!tiemuDBus) {
  4707. if (!KRun::runCommand("tiemu")) {
  4708. KMessageBox::error(this,"Can't run TiEmu.");
  4709. return;
  4710. }
  4711. do {
  4712. usleep(100000);
  4713. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,100);
  4714. if (!tiemuInstance(tiemuDBus)) return;
  4715. } while (!tiemuDBus);
  4716. }
  4717. // Wait for TiEmu to get ready.
  4718. bool ready=false;
  4719. do {
  4720. usleep(100000);
  4721. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,100);
  4722. QDBusReply<bool> reply=tiemuDBus->ready_for_transfers();
  4723. if (!reply.isValid()) {
  4724. KMessageBox::error(this,"D-Bus function call failed.");
  4725. delete tiemuDBus;
  4726. return;
  4727. }
  4728. ready=reply.value();
  4729. } while (!ready);
  4730. // Now obtain the model from TiEmu.
  4731. QDBusReply<int> reply=tiemuDBus->emulated_calc_type();
  4732. int tiemuCalcType;
  4733. if (!reply.isValid() || !(tiemuCalcType=reply.value())) {
  4734. KMessageBox::error(this,"D-Bus function call failed.");
  4735. delete tiemuDBus;
  4736. return;
  4737. }
  4738. switch (tiemuCalcType) {
  4739. case TIEMU_CALC_TI89:
  4740. case TIEMU_CALC_TI89t:
  4741. model=CALCULATOR_TI89;
  4742. break;
  4743. case TIEMU_CALC_TI92p:
  4744. model=CALCULATOR_TI92P;
  4745. break;
  4746. case TIEMU_CALC_V200:
  4747. model=CALCULATOR_V200;
  4748. break;
  4749. case TIEMU_CALC_TI92:
  4750. model=CALCULATOR_TI92;
  4751. break;
  4752. default:
  4753. KMessageBox::error(this,"Unsupported calculator model.");
  4754. return;
  4755. }
  4756. }
  4757. break;
  4758. case LT_REALCALC:
  4759. {
  4760. // Probe for the connected model.
  4761. CalcModel tilibsCalcModel=CALC_NONE;
  4762. int err;
  4763. if ((err=ticalcs_probe(preferences.linkCable,preferences.linkPort,
  4764. &tilibsCalcModel,TRUE))) {
  4765. KMessageBox::error(this,tilibsErrorMessage(err));
  4766. return;
  4767. }
  4768. switch (tilibsCalcModel) {
  4769. case CALC_TI89:
  4770. case CALC_TI89T:
  4771. case CALC_TI89T_USB:
  4772. model=CALCULATOR_TI89;
  4773. break;
  4774. case CALC_TI92P:
  4775. model=CALCULATOR_TI92P;
  4776. break;
  4777. case CALC_V200:
  4778. model=CALCULATOR_V200;
  4779. break;
  4780. case CALC_TI92:
  4781. model=CALCULATOR_TI92;
  4782. break;
  4783. default:
  4784. KMessageBox::error(this,"Unsupported calculator model.");
  4785. return;
  4786. }
  4787. // Allocate handle for the cable.
  4788. cable=ticables_handle_new(preferences.linkCable,preferences.linkPort);
  4789. if (!cable) {
  4790. KMessageBox::error(this,"Failed to allocate cable handle.");
  4791. return;
  4792. }
  4793. // Allocate handle for the calculator.
  4794. calc=ticalcs_handle_new(tilibsCalcModel);
  4795. if (!calc) {
  4796. KMessageBox::error(this,"Failed to allocate calculator handle.");
  4797. ticables_handle_del(cable);
  4798. return;
  4799. }
  4800. // Attach the calculator handle to the cable handle.
  4801. if ((err=ticalcs_cable_attach(calc,cable))) {
  4802. KMessageBox::error(this,tilibsErrorMessage(err));
  4803. ticalcs_handle_del(calc);
  4804. ticables_handle_del(cable);
  4805. return;
  4806. }
  4807. }
  4808. break;
  4809. default:
  4810. qWarning("Bug: debugRun called with no link target.");
  4811. return;
  4812. }
  4813. // Select the correct files for the model.
  4814. if (model!=CALCULATOR_TI92 && settings.fargo) {
  4815. KMessageBox::error(this,"Can't send Fargo program to a TI-89/89Ti/92+/V200.");
  4816. return;
  4817. }
  4818. if ((model==CALCULATOR_TI92 || model==CALCULATOR_INVALID) && !settings.fargo) {
  4819. KMessageBox::error(this,"Can't send AMS program to a TI-92.");
  4820. return;
  4821. }
  4822. for (QStringList::Iterator it=files.begin(); it!=files.end(); ++it) {
  4823. if (model==CALCULATOR_TI92P) (*it).replace(QRegExp("\\.89(?=.$)"),".9x");
  4824. else if (model==CALCULATOR_V200) (*it).replace(QRegExp("\\.89(?=.$)"),".v2");
  4825. if (!QFileInfo(*it).exists()) {
  4826. KMessageBox::error(this,"The program was not compiled for the linked calculator.");
  4827. return;
  4828. }
  4829. }
  4830. // Now send the files.
  4831. switch (preferences.linkTarget) {
  4832. case LT_TIEMU:
  4833. // Send the files.
  4834. if (settings.debug_info && !settings.pack
  4835. && QFileInfo(projectBaseName+".dbg").exists()) {
  4836. QString mainFile=files.first();
  4837. files.pop_front();
  4838. QDBusReply<bool> reply=tiemuDBus->debug_file(mainFile);
  4839. if (!reply.isValid() || !reply.value()) {
  4840. KMessageBox::error(this,"D-Bus function call failed.");
  4841. delete tiemuDBus;
  4842. return;
  4843. }
  4844. }
  4845. {
  4846. QDBusReply<bool> reply=tiemuDBus->send_files(files);
  4847. if (!reply.isValid() || !reply.value()) {
  4848. KMessageBox::error(this,"D-Bus function call failed.");
  4849. delete tiemuDBus;
  4850. return;
  4851. }
  4852. }
  4853. break;
  4854. case LT_REALCALC:
  4855. ticables_options_set_timeout(cable,DFLT_TIMEOUT<<2);
  4856. ticalcs_update_set(calc,&ticalcsUpdate);
  4857. for (QStringList::Iterator it=files.begin(); it!=files.end(); ++it) {
  4858. const char *file=*it;
  4859. int err;
  4860. // libticalcs2 does NO validation on the file, so better do it now.
  4861. if (!tifiles_file_is_single(file)
  4862. || !tifiles_calc_is_ti9x(tifiles_file_get_model(file))) {
  4863. KMessageBox::error(this,QString("File \'%1\' has an invalid format.").arg(file));
  4864. ticalcs_handle_del(calc);
  4865. ticables_handle_del(cable);
  4866. return;
  4867. }
  4868. // Send the file.
  4869. callbacksInit(this);
  4870. if ((err=ticalcs_calc_send_var2(calc,MODE_NORMAL,file))) {
  4871. bool cancelled=ticalcsUpdate.cancel;
  4872. callbacksCleanup();
  4873. if (!cancelled) KMessageBox::error(this,tilibsErrorMessage(err));
  4874. ticalcs_handle_del(calc);
  4875. ticables_handle_del(cable);
  4876. return;
  4877. }
  4878. callbacksCleanup();
  4879. }
  4880. break;
  4881. default:
  4882. qFatal("Bug: This code in debugRun should be unreachable!");
  4883. return;
  4884. }
  4885. // And finally run the program.
  4886. QString command=(QString("%1%2(%3)")
  4887. .arg(rootListItem->text(0).contains('\\')?"":"main\\")
  4888. .arg(rootListItem->text(0)).arg(settings.cmd_line));
  4889. switch (preferences.linkTarget) {
  4890. case LT_TIEMU:
  4891. {
  4892. // Execute the command.
  4893. QDBusReply<bool> reply=tiemuDBus->execute_command(command);
  4894. if (!reply.isValid() || !reply.value())
  4895. KMessageBox::error(this,"D-Bus function call failed.");
  4896. delete tiemuDBus;
  4897. }
  4898. break;
  4899. case LT_REALCALC:
  4900. {
  4901. int err;
  4902. // Convert the command to the calculator charset.
  4903. char *ti=ticonv_charset_utf16_to_ti(CALC_TI89,command.utf16());
  4904. // Send it character by character.
  4905. #define SEND_CHAR(c) \
  4906. if ((err=ticalcs_calc_send_key(calc,(c)))) { \
  4907. KMessageBox::error(this,tilibsErrorMessage(err)); \
  4908. g_free(ti); \
  4909. ticalcs_handle_del(calc); \
  4910. ticables_handle_del(cable); \
  4911. return; \
  4912. }
  4913. SEND_CHAR(264); // KEY_ESC
  4914. SEND_CHAR(264); // KEY_ESC
  4915. SEND_CHAR(model?8273:277); // KEY_HOME
  4916. SEND_CHAR(263); // KEY_CLEAR
  4917. SEND_CHAR(263); // KEY_CLEAR
  4918. for (unsigned char *p=reinterpret_cast<unsigned char *>(ti); *p; p++) {
  4919. SEND_CHAR(*p);
  4920. }
  4921. SEND_CHAR(13); // KEY_ENTER
  4922. #undef SEND_CHAR
  4923. g_free(ti);
  4924. }
  4925. ticalcs_handle_del(calc);
  4926. ticables_handle_del(cable);
  4927. break;
  4928. default:
  4929. qFatal("Bug: This code in debugRun should be unreachable!");
  4930. return;
  4931. }
  4932. }
  4933. }
  4934. void MainForm::debugPause()
  4935. {
  4936. // This is enabled only for LT_TIEMU. Run the TiEmu debugger.
  4937. TiEmuDBus *tiemuDBus;
  4938. if (!tiemuInstance(tiemuDBus) || !tiemuDBus) return;
  4939. if (!tiemuDBus->enter_debugger().isValid())
  4940. KMessageBox::error(this,"D-Bus function call failed.");
  4941. delete tiemuDBus;
  4942. }
  4943. void MainForm::debugReset()
  4944. {
  4945. // This is enabled only for LT_TIEMU. Reset TiEmu.
  4946. TiEmuDBus *tiemuDBus;
  4947. if (!tiemuInstance(tiemuDBus) || !tiemuDBus) return;
  4948. if (!tiemuDBus->reset_calc(FALSE).isValid())
  4949. KMessageBox::error(this,"D-Bus function call failed.");
  4950. delete tiemuDBus;
  4951. }
  4952. void MainForm::toolsConfigure()
  4953. {
  4954. ToolsDialog toolsDialog(this);
  4955. toolsDialog.exec();
  4956. if (toolsDialog.result()==QDialog::Accepted) {
  4957. pconfig->setGroup("Tools");
  4958. unsigned toolCount=tools.count();
  4959. pconfig->writeEntry("Count",toolCount);
  4960. for (unsigned idx=0; idx<toolCount; idx++) {
  4961. pconfig->setGroup(QString("Tool %1").arg(idx));
  4962. Tool &tool=tools[idx];
  4963. pconfig->writeEntry("Title",tool.title);
  4964. pconfig->writeEntry("Command Line",tool.commandLine);
  4965. pconfig->writeEntry("Working Directory",tool.workingDirectory);
  4966. pconfig->writeEntry("Terminal",tool.runInTerminal);
  4967. pconfig->sync();
  4968. }
  4969. updateToolsMenu();
  4970. }
  4971. }
  4972. void MainForm::updateToolsMenu()
  4973. {
  4974. toolsMenu->clear();
  4975. toolsConfigureAction->addTo(toolsMenu);
  4976. unsigned toolCount=tools.count();
  4977. if (toolCount) toolsMenu->insertSeparator();
  4978. for (unsigned idx=0; idx<toolCount; idx++)
  4979. toolsMenu->insertItem(tools[idx].title,idx);
  4980. disconnect(toolsMenu,SIGNAL(highlighted(int)),0,0);
  4981. connect(toolsMenu,SIGNAL(highlighted(int)),
  4982. this,SLOT(toolsMenu_highlighted(int)));
  4983. disconnect(toolsMenu,SIGNAL(aboutToHide()),0,0);
  4984. connect(toolsMenu,SIGNAL(aboutToHide()),this,SLOT(toolsMenu_aboutToHide()));
  4985. }
  4986. void MainForm::toolsMenu_highlighted(int id)
  4987. {
  4988. if (id==toolsMenu->idAt(0))
  4989. statusBar()->message(toolsConfigureAction->statusTip());
  4990. else if (id!=toolsMenu->idAt(1))
  4991. statusBar()->message(tools[id].commandLine);
  4992. }
  4993. void MainForm::toolsMenu_activated(int id)
  4994. {
  4995. if (id!=toolsMenu->idAt(0) && id!=toolsMenu->idAt(1)) {
  4996. const Tool &tool=tools[id];
  4997. KProcess process(this);
  4998. int err;
  4999. QStringList args=KShell::splitArgs(tool.commandLine,
  5000. KShell::TildeExpand|KShell::AbortOnMeta,
  5001. &err);
  5002. if (err) {
  5003. KMessageBox::error(this,"Invalid command line.");
  5004. return;
  5005. }
  5006. if (tool.runInTerminal) {
  5007. KConfigGroup globalConfigGeneral(KGlobal::config(),"General");
  5008. QString terminal=globalConfigGeneral.readPathEntry("TerminalApplication",
  5009. "konsole");
  5010. if (terminal=="konsole")
  5011. terminal+=" -caption=%c";
  5012. QHash<QChar,QString> map;
  5013. map.insert('c',tool.title);
  5014. map.insert('i',"");
  5015. map.insert('m',"");
  5016. terminal=KMacroExpander::expandMacrosShellQuote(terminal,map);
  5017. if (terminal.isNull()) {
  5018. KMessageBox::error(this,"Invalid terminal specification.");
  5019. return;
  5020. }
  5021. QStringList termargs=KShell::splitArgs(terminal,
  5022. KShell::TildeExpand|KShell::AbortOnMeta,
  5023. &err);
  5024. if (err) {
  5025. KMessageBox::error(this,"Invalid terminal specification.");
  5026. return;
  5027. }
  5028. process << termargs << "-e" << "sh" << "-c"
  5029. << (tool.commandLine+" ; echo Press Return to close... ; read");
  5030. } else
  5031. process << args;
  5032. if (!tool.workingDirectory.isEmpty())
  5033. process.setWorkingDirectory(tool.workingDirectory);
  5034. if (!process.start(KProcess::DontCare))
  5035. KMessageBox::error(this,QString("Can't run \'%1\'.").arg(tool.commandLine));
  5036. }
  5037. }
  5038. void MainForm::toolsMenu_aboutToHide()
  5039. {
  5040. statusBar()->clear();
  5041. }
  5042. void MainForm::helpDocumentation()
  5043. {
  5044. assistant->openAssistant();
  5045. }
  5046. void MainForm::helpContents()
  5047. {
  5048. force_qt_assistant_page(0);
  5049. assistant->openAssistant();
  5050. }
  5051. void MainForm::helpIndex()
  5052. {
  5053. force_qt_assistant_page(1);
  5054. assistant->openAssistant();
  5055. }
  5056. void MainForm::helpSearch()
  5057. {
  5058. force_qt_assistant_page(3);
  5059. assistant->openAssistant();
  5060. }
  5061. void MainForm::helpNews()
  5062. {
  5063. NewsDialog newsDialog(this);
  5064. newsDialog.loadNews();
  5065. newsDialog.exec();
  5066. }
  5067. void MainForm::helpAbout()
  5068. {
  5069. khelpmenu->aboutApplication();
  5070. }
  5071. void MainForm::updateSizes()
  5072. {
  5073. int leftSize=splitter->sizes().first();
  5074. int rightSize=splitter->sizes().last();
  5075. int totalSize=leftSize+rightSize;
  5076. int mySize=size().width();
  5077. leftStatusLabel->setMaximumWidth(leftSize*mySize/totalSize);
  5078. rightStatusLabel->setMaximumWidth(rightSize*mySize/totalSize-10>0?
  5079. rightSize*mySize/totalSize-10:0);
  5080. }
  5081. void MainForm::resizeEvent(QResizeEvent *event)
  5082. {
  5083. QMainWindow::resizeEvent(event);
  5084. if (event->size()==event->oldSize()) return;
  5085. updateSizes();
  5086. }
  5087. void MainForm::timerEvent(QTimerEvent *event)
  5088. {
  5089. static int lastSplitterPos=-1;
  5090. QMainWindow::timerEvent(event);
  5091. if (lastSplitterPos==splitter->sizes().first()) return;
  5092. lastSplitterPos=splitter->sizes().first();
  5093. updateSizes();
  5094. }
  5095. void MainForm::fileTreeClicked(Q3ListViewItem *item)
  5096. {
  5097. if (!item) return;
  5098. if (fileTree->selectedItem()!=item) {
  5099. fileTree->setSelected(item,TRUE);
  5100. fileTree->ensureItemVisible(item);
  5101. }
  5102. if (IS_FOLDER(currentListItem))
  5103. currentListItem->setPixmap(0,SYSICON("folder","folder1.png"));
  5104. if (IS_FILE(currentListItem)) {
  5105. CATEGORY_OF(category,currentListItem);
  5106. if (IS_EDITABLE_CATEGORY(category)) {
  5107. static_cast<ListViewFile *>(currentListItem)->kateView->hide();
  5108. widgetStack->removeWidget(static_cast<ListViewFile *>(currentListItem)->kateView);
  5109. widgetStack->raiseWidget(-1);
  5110. }
  5111. }
  5112. if (IS_FOLDER(item)) {
  5113. // Bluecurve's "folder_open" isn't actually more open than "folder".
  5114. item->setPixmap(0,SYSICON(KIconTheme::current().compare("Bluecurve")?"folder_open":"folder-accept","folder2.png"));
  5115. fileNewFolderAction->setEnabled(TRUE);
  5116. filePrintAction->setEnabled(FALSE);
  5117. filePrintQuicklyAction->setEnabled(FALSE);
  5118. editUndoAction->setEnabled(FALSE);
  5119. editRedoAction->setEnabled(FALSE);
  5120. editClearAction->setEnabled(FALSE);
  5121. editCutAction->setEnabled(FALSE);
  5122. editCopyAction->setEnabled(FALSE);
  5123. editPasteAction->setEnabled(FALSE);
  5124. editSelectAllAction->setEnabled(FALSE);
  5125. editIncreaseIndentAction->setEnabled(FALSE);
  5126. editDecreaseIndentAction->setEnabled(FALSE);
  5127. findFunctionsAction->setEnabled(FALSE);
  5128. findOpenFileAtCursorAction->setEnabled(FALSE);
  5129. findFindSymbolDeclarationAction->setEnabled(FALSE);
  5130. accel->setItemEnabled(0,FALSE);
  5131. accel->setItemEnabled(1,FALSE);
  5132. accel->setItemEnabled(2,FALSE);
  5133. accel->setItemEnabled(3,FALSE);
  5134. accel->setItemEnabled(4,FALSE);
  5135. accel->setItemEnabled(5,FALSE);
  5136. accel->setItemEnabled(6,FALSE);
  5137. accel->setItemEnabled(7,FALSE);
  5138. accel->setItemEnabled(8,FALSE);
  5139. accel->setItemEnabled(9,FALSE);
  5140. accel->setItemEnabled(10,FALSE);
  5141. } else if (IS_FILE(item)) {
  5142. fileNewFolderAction->setEnabled(TRUE);
  5143. CATEGORY_OF(category,item->parent());
  5144. if (IS_EDITABLE_CATEGORY(category)) {
  5145. KTextEditor::View *kateView=static_cast<ListViewFile *>(item)->kateView;
  5146. filePrintAction->setEnabled(TRUE);
  5147. filePrintQuicklyAction->setEnabled(TRUE);
  5148. widgetStack->addWidget(kateView);
  5149. kateView->show();
  5150. widgetStack->raiseWidget(kateView);
  5151. editUndoAction->setEnabled(kateView->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  5152. editRedoAction->setEnabled(kateView->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  5153. editClearAction->setEnabled(kateView->selection());
  5154. editCutAction->setEnabled(kateView->selection());
  5155. editCopyAction->setEnabled(kateView->selection());
  5156. editPasteAction->setEnabled(!clipboard->text().isNull());
  5157. editSelectAllAction->setEnabled(TRUE);
  5158. editIncreaseIndentAction->setEnabled(TRUE);
  5159. editDecreaseIndentAction->setEnabled(TRUE);
  5160. findFunctionsAction->setEnabled(category!=txtFilesListItem);
  5161. findOpenFileAtCursorAction->setEnabled(TRUE);
  5162. findFindSymbolDeclarationAction->setEnabled(TRUE);
  5163. accel->setItemEnabled(0,kateView->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  5164. accel->setItemEnabled(1,kateView->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  5165. accel->setItemEnabled(2,kateView->selection());
  5166. accel->setItemEnabled(3,kateView->selection());
  5167. accel->setItemEnabled(4,!clipboard->text().isNull());
  5168. accel->setItemEnabled(5,TRUE);
  5169. accel->setItemEnabled(6,TRUE);
  5170. accel->setItemEnabled(7,TRUE);
  5171. accel->setItemEnabled(8,TRUE);
  5172. accel->setItemEnabled(9,TRUE);
  5173. accel->setItemEnabled(10,TRUE);
  5174. } else {
  5175. filePrintAction->setEnabled(FALSE);
  5176. filePrintQuicklyAction->setEnabled(FALSE);
  5177. editUndoAction->setEnabled(FALSE);
  5178. editRedoAction->setEnabled(FALSE);
  5179. editClearAction->setEnabled(FALSE);
  5180. editCutAction->setEnabled(FALSE);
  5181. editCopyAction->setEnabled(FALSE);
  5182. editPasteAction->setEnabled(FALSE);
  5183. editSelectAllAction->setEnabled(FALSE);
  5184. editIncreaseIndentAction->setEnabled(FALSE);
  5185. editDecreaseIndentAction->setEnabled(FALSE);
  5186. findFunctionsAction->setEnabled(FALSE);
  5187. findOpenFileAtCursorAction->setEnabled(FALSE);
  5188. findFindSymbolDeclarationAction->setEnabled(FALSE);
  5189. accel->setItemEnabled(0,FALSE);
  5190. accel->setItemEnabled(1,FALSE);
  5191. accel->setItemEnabled(2,FALSE);
  5192. accel->setItemEnabled(3,FALSE);
  5193. accel->setItemEnabled(4,FALSE);
  5194. accel->setItemEnabled(5,FALSE);
  5195. accel->setItemEnabled(6,FALSE);
  5196. accel->setItemEnabled(7,FALSE);
  5197. accel->setItemEnabled(8,FALSE);
  5198. accel->setItemEnabled(9,FALSE);
  5199. accel->setItemEnabled(10,FALSE);
  5200. }
  5201. } else {
  5202. fileNewFolderAction->setEnabled(FALSE);
  5203. filePrintAction->setEnabled(FALSE);
  5204. filePrintQuicklyAction->setEnabled(FALSE);
  5205. editUndoAction->setEnabled(FALSE);
  5206. editRedoAction->setEnabled(FALSE);
  5207. editClearAction->setEnabled(FALSE);
  5208. editCutAction->setEnabled(FALSE);
  5209. editCopyAction->setEnabled(FALSE);
  5210. editPasteAction->setEnabled(FALSE);
  5211. editSelectAllAction->setEnabled(FALSE);
  5212. editIncreaseIndentAction->setEnabled(FALSE);
  5213. editDecreaseIndentAction->setEnabled(FALSE);
  5214. findFunctionsAction->setEnabled(FALSE);
  5215. findOpenFileAtCursorAction->setEnabled(FALSE);
  5216. findFindSymbolDeclarationAction->setEnabled(FALSE);
  5217. accel->setItemEnabled(0,FALSE);
  5218. accel->setItemEnabled(1,FALSE);
  5219. accel->setItemEnabled(2,FALSE);
  5220. accel->setItemEnabled(3,FALSE);
  5221. accel->setItemEnabled(4,FALSE);
  5222. accel->setItemEnabled(5,FALSE);
  5223. accel->setItemEnabled(6,FALSE);
  5224. accel->setItemEnabled(7,FALSE);
  5225. accel->setItemEnabled(8,FALSE);
  5226. accel->setItemEnabled(9,FALSE);
  5227. accel->setItemEnabled(10,FALSE);
  5228. }
  5229. currentListItem=item;
  5230. updateLeftStatusLabel();
  5231. updateRightStatusLabel();
  5232. }
  5233. void MainForm::fileNewFolder()
  5234. {
  5235. if (compiling) return;
  5236. if (IS_FILE(currentListItem))
  5237. currentListItem=currentListItem->parent();
  5238. Q3ListViewItem *item=NULL, *next=currentListItem->firstChild();
  5239. for (; next; next=item->nextSibling())
  5240. {
  5241. item=next;
  5242. }
  5243. Q3ListViewItem *newFolder=item?new ListViewFolder(currentListItem,item)
  5244. :new ListViewFolder(currentListItem);
  5245. newFolder->setText(0,"NewFolder");
  5246. newFolder->setRenameEnabled(0,TRUE);
  5247. currentListItem->setOpen(TRUE);
  5248. fileTreeClicked(newFolder);
  5249. newFolder->startRename(0);
  5250. projectIsDirty=TRUE;
  5251. projectNeedsRelink=TRUE;
  5252. }
  5253. bool MainForm::removeItem(Q3ListViewItem *item)
  5254. {
  5255. if (IS_FOLDER(item) && !IS_CATEGORY(item)) {
  5256. Q3ListViewItem *child=item->firstChild();
  5257. while (child) {
  5258. Q3ListViewItem *nextChild=child->nextSibling();
  5259. if (!removeItem(child)) return FALSE;
  5260. child=nextChild;
  5261. }
  5262. delete item;
  5263. currentListItem=NULL;
  5264. fileTreeClicked(fileTree->currentItem());
  5265. projectIsDirty=TRUE;
  5266. projectNeedsRelink=TRUE;
  5267. return TRUE;
  5268. } else if (IS_FILE(item)) {
  5269. if (!fileSavePrompt(item)) {
  5270. delete item;
  5271. currentListItem=NULL;
  5272. fileTreeClicked(fileTree->currentItem());
  5273. projectIsDirty=TRUE;
  5274. projectNeedsRelink=TRUE;
  5275. return TRUE;
  5276. } else return FALSE;
  5277. } else return FALSE;
  5278. }
  5279. #define unused_col __attribute__((unused)) col /* stupid QT designer... */
  5280. void MainForm::fileTreeContextMenuRequested(Q3ListViewItem *item,
  5281. const QPoint &pos,
  5282. int unused_col)
  5283. {
  5284. fileTreeClicked(item);
  5285. if (IS_FOLDER(item)) {
  5286. Q3PopupMenu menu;
  5287. menu.insertItem("New &Folder",0);
  5288. menu.insertItem("New F&ile",1);
  5289. if (compiling) {
  5290. menu.setItemEnabled(0,FALSE);
  5291. menu.setItemEnabled(1,FALSE);
  5292. }
  5293. CATEGORY_OF(category,item);
  5294. if (!IS_EDITABLE_CATEGORY(category))
  5295. menu.setItemEnabled(1,FALSE);
  5296. if (!IS_CATEGORY(item)) {
  5297. menu.insertSeparator();
  5298. menu.insertItem("&Remove",2);
  5299. if (compiling) menu.setItemEnabled(2,FALSE);
  5300. menu.insertItem("Re&name",3);
  5301. }
  5302. switch (menu.exec(pos)) {
  5303. case 0:
  5304. fileNewFolder();
  5305. break;
  5306. case 1:
  5307. newFile(item);
  5308. break;
  5309. case 2:
  5310. removeItem(item);
  5311. break;
  5312. case 3:
  5313. item->startRename(0);
  5314. }
  5315. } else if (IS_FILE(item)) {
  5316. Q3PopupMenu menu;
  5317. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  5318. menu.insertItem("&Save",0);
  5319. CATEGORY_OF(category,item);
  5320. if (!IS_EDITABLE_CATEGORY(category))
  5321. menu.setItemEnabled(0,FALSE);
  5322. menu.insertItem("Save &As...",1);
  5323. menu.insertSeparator();
  5324. menu.insertItem("&Compile",2);
  5325. if (compiling || category==txtFilesListItem
  5326. || !IS_EDITABLE_CATEGORY(category))
  5327. menu.setItemEnabled(2,FALSE);
  5328. menu.insertSeparator();
  5329. menu.insertItem("&Remove",3);
  5330. menu.insertItem("&Delete",4);
  5331. if (compiling) {
  5332. menu.setItemEnabled(3,FALSE);
  5333. menu.setItemEnabled(4,FALSE);
  5334. }
  5335. if (theFile->isNew)
  5336. menu.setItemEnabled(4,FALSE);
  5337. menu.insertSeparator();
  5338. menu.insertItem("Re&name",5);
  5339. switch (menu.exec(pos)) {
  5340. case 0:
  5341. fileSave_save(item);
  5342. break;
  5343. case 1:
  5344. fileSave_saveAs(item);
  5345. break;
  5346. case 2:
  5347. if (compiling) return;
  5348. startCompiling();
  5349. compileFile(theFile,TRUE,TRUE);
  5350. stopCompiling();
  5351. break;
  5352. case 3:
  5353. removeItem(item);
  5354. break;
  5355. case 4:
  5356. if (KMessageBox::questionYesNo(this,
  5357. "Are you sure you want to delete this source file? "
  5358. "You cannot undo this operation.","Confirm Deletion")
  5359. ==KMessageBox::Yes) {
  5360. QString fileName=theFile->fileName;
  5361. KDirWatch::self()->removeFile(fileName);
  5362. if (QDir().remove(fileName)) {
  5363. delete item;
  5364. currentListItem=NULL;
  5365. fileTreeClicked(fileTree->currentItem());
  5366. projectIsDirty=TRUE;
  5367. projectNeedsRelink=TRUE;
  5368. } else {
  5369. KMessageBox::error(this,
  5370. QString("Error deleting file \'%1\'").arg(fileName));
  5371. if (IS_EDITABLE_CATEGORY(category) && !fileName.isEmpty() && fileName[0]=='/')
  5372. KDirWatch::self()->addFile(fileName);
  5373. }
  5374. }
  5375. break;
  5376. case 5:
  5377. item->startRename(0);
  5378. }
  5379. }
  5380. }
  5381. QStringList MainForm::extractAllFileNames(void)
  5382. {
  5383. Q3ListViewItem *item=rootListItem->firstChild(),*next;
  5384. QStringList allFiles;
  5385. while (item)
  5386. {
  5387. if (IS_FOLDER(item))
  5388. {
  5389. next=item->firstChild();
  5390. if (next)
  5391. {
  5392. item=next;
  5393. continue;
  5394. }
  5395. }
  5396. if (IS_FILE(item))
  5397. {
  5398. allFiles << (static_cast<ListViewFile *>(item)->fileName);
  5399. }
  5400. next=item->nextSibling();
  5401. while (!next)
  5402. {
  5403. next=item->parent();
  5404. if (next==rootListItem||!next)
  5405. {
  5406. return allFiles;
  5407. }
  5408. item=next;
  5409. next=item->nextSibling();
  5410. }
  5411. item=next;
  5412. }
  5413. return allFiles;
  5414. }
  5415. //you put in parent, and it gives you the rest, but you must have a place to put it all.
  5416. void MainForm::extractFileTreeInfo(Q3ListViewItem *parent,Q3ListViewItem **p_category,QString *p_folderPath)
  5417. {
  5418. Q3ListViewItem *item,*next;
  5419. QString tmp=QString::null;
  5420. int o;
  5421. CATEGORY_OF(category,parent);
  5422. *p_category=category;
  5423. item=category->firstChild();
  5424. while (item)
  5425. {
  5426. if (item==parent)
  5427. {
  5428. if (!tmp.isEmpty())
  5429. tmp+='/';
  5430. tmp+=item->text(0);
  5431. *p_folderPath=tmp;
  5432. }
  5433. if (IS_FOLDER(item))
  5434. {
  5435. next=item->firstChild();
  5436. if (next)
  5437. {
  5438. if (tmp.isEmpty())
  5439. tmp=item->text(0);
  5440. else
  5441. {
  5442. tmp+='/';
  5443. tmp+=item->text(0);
  5444. }
  5445. item=next;
  5446. continue;
  5447. }
  5448. }
  5449. mfnf_seeknext:
  5450. next=item->nextSibling();
  5451. if (!next)
  5452. {
  5453. next=item->parent();
  5454. if (next==category||!next)
  5455. break;
  5456. item=next;
  5457. o=tmp.findRev('/');
  5458. if (o>=0)
  5459. tmp.truncate(o);
  5460. else
  5461. tmp.truncate(0);
  5462. goto mfnf_seeknext;
  5463. }
  5464. item=next;
  5465. }
  5466. }
  5467. void MainForm::newFile(Q3ListViewItem *parent, QString text, const QPixmap &pixmap)
  5468. {
  5469. Q3ListViewItem *item=NULL, *next=parent->firstChild();
  5470. QString tmp,oldtmp,suffix,caption;
  5471. QStringList allFiles=extractAllFileNames();
  5472. Q3ListViewItem *category;
  5473. KUrl tmpK;
  5474. int tryNum;
  5475. for (; IS_FILE(next); next=item->nextSibling())
  5476. item=next;
  5477. extractFileTreeInfo(parent,&category,&tmp);
  5478. suffix="";
  5479. if (category==hFilesListItem)
  5480. suffix="h";
  5481. else if (category==cFilesListItem)
  5482. suffix="c";
  5483. else if (category==sFilesListItem)
  5484. suffix="s";
  5485. else if (category==asmFilesListItem)
  5486. suffix="asm";
  5487. else if (category==qllFilesListItem) {
  5488. if (qllFileCount) {
  5489. KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
  5490. return;
  5491. }
  5492. suffix="qll";
  5493. } else if (category==oFilesListItem)
  5494. suffix="o";
  5495. else if (category==aFilesListItem)
  5496. suffix="a";
  5497. else if (category==txtFilesListItem)
  5498. suffix="txt";
  5499. suffix='.'+suffix;
  5500. if (!tmp.isEmpty())
  5501. tmp+='/';
  5502. tmp+="New File";
  5503. tmpK.setPath(projectFileName);
  5504. kurlNewFileName(tmpK,tmp);
  5505. tmp=tmpK.path();
  5506. if (projectFileName.isEmpty() && !tmp.isEmpty())
  5507. {
  5508. short o=0;
  5509. if (tmp[0]=='.')
  5510. o=1;
  5511. if (tmp[o]=='/')
  5512. tmp=tmp.mid(o+1);
  5513. }
  5514. caption="New File";
  5515. oldtmp=tmp+' ';
  5516. tmp+=suffix;
  5517. tryNum=1;
  5518. while (!checkFileName(tmp,allFiles))
  5519. {
  5520. tryNum++;
  5521. tmp=oldtmp+QString("%1").arg(tryNum)+suffix;
  5522. caption="New File "+QString("%1").arg(tryNum);
  5523. }
  5524. ListViewFile *newFile=item?new ListViewFile(parent,item)
  5525. :new ListViewFile(parent);
  5526. newFile->fileName=tmp;
  5527. if (IS_EDITABLE_CATEGORY(category) && !tmp.isEmpty() && tmp[0]=='/')
  5528. KDirWatch::self()->addFile(tmp);
  5529. newFile->setText(0,caption);
  5530. newFile->setPixmap(0,pixmap);
  5531. parent->setOpen(TRUE);
  5532. newFile->kateView=reinterpret_cast<KTextEditor::View *>(createView(QString::null,text,category));
  5533. fileTreeClicked(newFile);
  5534. projectIsDirty=TRUE;
  5535. projectNeedsRelink=TRUE;
  5536. newFile->startRename(0);
  5537. fileCount++;
  5538. COUNTER_FOR_CATEGORY(category)++;
  5539. updateLeftStatusLabel();
  5540. }
  5541. void MainForm::newFile( Q3ListViewItem *parent )
  5542. {
  5543. CATEGORY_OF(category,parent);
  5544. newFile(parent,category==txtFilesListItem?"":
  5545. ((category==hFilesListItem?"// Header File\n//":
  5546. category==cFilesListItem?"// C Source File\n//":
  5547. category==sFilesListItem?"| Assembly Source File\n|":
  5548. category==asmFilesListItem?"; Assembly Source File\n;":
  5549. category==qllFilesListItem?"// Quill Source File\n//":"???\n")
  5550. +QString(" Created ")
  5551. +QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n"+
  5552. QString(category==cFilesListItem?(cFileCount?
  5553. "\n#include <tigcclib.h>\n":
  5554. "\n// Delete or comment out the items you do not need.\n"
  5555. "#define COMMENT_STRING \"Place your comment here.\"\n"
  5556. "#define COMMENT_PROGRAM_NAME "
  5557. "\"Place your program name here.\"\n"
  5558. "#define COMMENT_VERSION_STRING "
  5559. "\"Place your version string here.\"\n"
  5560. "#define COMMENT_VERSION_NUMBER 0,0,0,0 "
  5561. "/* major, minor, revision, subrevision */\n"
  5562. "#define COMMENT_AUTHORS "
  5563. "\"Place your author name(s) here.\"\n"
  5564. "#define COMMENT_BW_ICON \\\n"
  5565. "\t{0b0000000000000000, \\\n"
  5566. "\t 0b0000000000000000, \\\n"
  5567. "\t 0b0000000000000000, \\\n"
  5568. "\t 0b0000000000000000, \\\n"
  5569. "\t 0b0000000000000000, \\\n"
  5570. "\t 0b0000000000000000, \\\n"
  5571. "\t 0b0000000000000000, \\\n"
  5572. "\t 0b0000000000000000, \\\n"
  5573. "\t 0b0000000000000000, \\\n"
  5574. "\t 0b0000000000000000, \\\n"
  5575. "\t 0b0000000000000000, \\\n"
  5576. "\t 0b0000000000000000, \\\n"
  5577. "\t 0b0000000000000000, \\\n"
  5578. "\t 0b0000000000000000, \\\n"
  5579. "\t 0b0000000000000000, \\\n"
  5580. "\t 0b0000000000000000}\n"
  5581. "#define COMMENT_GRAY_ICON \\\n"
  5582. "\t{0b0000000000000000, \\\n"
  5583. "\t 0b0000000000000000, \\\n"
  5584. "\t 0b0000000000000000, \\\n"
  5585. "\t 0b0000000000000000, \\\n"
  5586. "\t 0b0000000000000000, \\\n"
  5587. "\t 0b0000000000000000, \\\n"
  5588. "\t 0b0000000000000000, \\\n"
  5589. "\t 0b0000000000000000, \\\n"
  5590. "\t 0b0000000000000000, \\\n"
  5591. "\t 0b0000000000000000, \\\n"
  5592. "\t 0b0000000000000000, \\\n"
  5593. "\t 0b0000000000000000, \\\n"
  5594. "\t 0b0000000000000000, \\\n"
  5595. "\t 0b0000000000000000, \\\n"
  5596. "\t 0b0000000000000000, \\\n"
  5597. "\t 0b0000000000000000}, \\\n"
  5598. "\t{0b0000000000000000, \\\n"
  5599. "\t 0b0000000000000000, \\\n"
  5600. "\t 0b0000000000000000, \\\n"
  5601. "\t 0b0000000000000000, \\\n"
  5602. "\t 0b0000000000000000, \\\n"
  5603. "\t 0b0000000000000000, \\\n"
  5604. "\t 0b0000000000000000, \\\n"
  5605. "\t 0b0000000000000000, \\\n"
  5606. "\t 0b0000000000000000, \\\n"
  5607. "\t 0b0000000000000000, \\\n"
  5608. "\t 0b0000000000000000, \\\n"
  5609. "\t 0b0000000000000000, \\\n"
  5610. "\t 0b0000000000000000, \\\n"
  5611. "\t 0b0000000000000000, \\\n"
  5612. "\t 0b0000000000000000, \\\n"
  5613. "\t 0b0000000000000000}\n\n#include <tigcclib.h>\n\n"
  5614. "// Main Function\nvoid _main(void)\n{\n"
  5615. "\t// Place your code here.\n}\n"):"")),
  5616. category==cFilesListItem||category==qllFilesListItem
  5617. ?SYSICON("source_c","filec.png"):
  5618. category==hFilesListItem?SYSICON("source_h","fileh.png"):
  5619. category==sFilesListItem||category==asmFilesListItem
  5620. ?SYSICON("source_s","files.png"):
  5621. category==txtFilesListItem?SYSICON("txt","filet.png"):SYSICON("unknown","filex.png"));
  5622. }
  5623. Q3ListViewItem *MainForm::resolveParent(Q3ListViewItem *category)
  5624. {
  5625. Q3ListViewItem *ret=currentListItem;
  5626. if (!IS_FILE(ret)&&!IS_FOLDER(ret))
  5627. return category;
  5628. if (IS_FILE(ret))
  5629. ret=ret->parent();
  5630. Q3ListViewItem *actualCategory=ret;
  5631. while (IS_FOLDER(actualCategory->parent())) actualCategory=actualCategory->parent();
  5632. if (actualCategory!=category)
  5633. return category;
  5634. return ret;
  5635. }
  5636. void MainForm::fileNewCHeader()
  5637. {
  5638. if (compiling) return;
  5639. newFile(resolveParent(hFilesListItem),"// Header File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_h","fileh.png"));
  5640. }
  5641. void MainForm::fileNewGNUAssemblyHeader()
  5642. {
  5643. if (compiling) return;
  5644. newFile(resolveParent(hFilesListItem),"| Header File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_h","fileh.png"));
  5645. }
  5646. void MainForm::fileNewA68kAssemblyHeader()
  5647. {
  5648. if (compiling) return;
  5649. newFile(resolveParent(hFilesListItem),"; Header File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_h","fileh.png"));
  5650. }
  5651. void MainForm::fileNewCSourceFile()
  5652. {
  5653. if (compiling) return;
  5654. newFile(resolveParent(cFilesListItem));
  5655. }
  5656. void MainForm::fileNewGNUAssemblySourceFile()
  5657. {
  5658. if (compiling) return;
  5659. newFile(resolveParent(sFilesListItem),"| Assembly Source File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_s","files.png"));
  5660. }
  5661. void MainForm::fileNewA68kAssemblySourceFile()
  5662. {
  5663. if (compiling) return;
  5664. newFile(resolveParent(asmFilesListItem),"; Assembly Source File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_s","files.png"));
  5665. }
  5666. void MainForm::fileNewQuillSourceFile()
  5667. {
  5668. if (compiling) return;
  5669. newFile(resolveParent(qllFilesListItem),"// Quill Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n",SYSICON("source_c","filec.png"));
  5670. }
  5671. void MainForm::fileNewTextFile()
  5672. {
  5673. if (compiling) return;
  5674. newFile(resolveParent(txtFilesListItem),"",SYSICON("txt","filet.png"));
  5675. }
  5676. void MainForm::updateLeftStatusLabel()
  5677. {
  5678. QString text=QString::number(fileCount)+QString(" File")
  5679. +QString(fileCount!=1?"s":"")+QString(" Total");
  5680. if (IS_FOLDER(currentListItem)||IS_FILE(currentListItem)) {
  5681. CATEGORY_OF(category,currentListItem);
  5682. text+=QString(", ")+QString::number(COUNTER_FOR_CATEGORY(category))
  5683. +QString(" in Category");
  5684. }
  5685. leftStatusLabel->setText(text);
  5686. }
  5687. void MainForm::statusBar_messageChanged(const QString & message)
  5688. {
  5689. if (message.isNull())
  5690. // Make sure no labels which should be hidden are shown.
  5691. updateRightStatusLabel();
  5692. }
  5693. void MainForm::updateRightStatusLabel()
  5694. {
  5695. int leftSize=splitter->sizes().first();
  5696. int rightSize=splitter->sizes().last();
  5697. int totalSize=leftSize+rightSize;
  5698. int mySize=size().width();
  5699. int rightStatusSize=rightSize*mySize/totalSize-10>0?
  5700. rightSize*mySize/totalSize-10:0;
  5701. if (currentListItem==rootListItem) {
  5702. rowStatusLabel->hide();
  5703. colStatusLabel->hide();
  5704. charsStatusLabel->hide();
  5705. rightStatusLabel->setMaximumWidth(rightStatusSize);
  5706. rightStatusLabel->setText(projectFileName);
  5707. } else if (IS_FOLDER(currentListItem)) {
  5708. rowStatusLabel->hide();
  5709. colStatusLabel->hide();
  5710. charsStatusLabel->hide();
  5711. rightStatusLabel->setMaximumWidth(rightStatusSize);
  5712. rightStatusLabel->setText("");
  5713. } else if (IS_FILE(currentListItem)) {
  5714. CATEGORY_OF(category,currentListItem);
  5715. if (IS_EDITABLE_CATEGORY(category) && CURRENT_VIEW) {
  5716. int line, col;
  5717. CURRENT_VIEW->cursorPosition().position(line,col);
  5718. rowStatusLabel->show();
  5719. rowStatusLabel->setMaximumWidth(30);
  5720. rowStatusLabel->setText(QString("%1").arg(line+1));
  5721. colStatusLabel->show();
  5722. colStatusLabel->setMaximumWidth(30);
  5723. colStatusLabel->setText(QString("%1").arg(col+1));
  5724. charsStatusLabel->show();
  5725. charsStatusLabel->setMaximumWidth(100);
  5726. charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->document()->text().length()));
  5727. rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
  5728. } else {
  5729. rowStatusLabel->hide();
  5730. colStatusLabel->hide();
  5731. charsStatusLabel->hide();
  5732. rightStatusLabel->setMaximumWidth(rightStatusSize);
  5733. }
  5734. rightStatusLabel->setText(static_cast<ListViewFile *>(currentListItem)->fileName);
  5735. }
  5736. }
  5737. void MainForm::current_view_cursorPositionChanged()
  5738. {
  5739. if (CURRENT_VIEW && !disableViewEvents) {
  5740. int line, col;
  5741. CURRENT_VIEW->cursorPosition().position(line,col);
  5742. rowStatusLabel->setText(QString("%1").arg(line+1));
  5743. colStatusLabel->setText(QString("%1").arg(col+1));
  5744. }
  5745. }
  5746. void MainForm::current_view_textChanged()
  5747. {
  5748. if (disableViewEvents) return;
  5749. if (CURRENT_VIEW) {
  5750. charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->document()->text().length()));
  5751. if (IS_FILE(currentListItem)) {
  5752. static_cast<ListViewFile *>(currentListItem)->modifiedSinceLastCompile=TRUE;
  5753. QString fileName=pathInProject(currentListItem);
  5754. if (projectCompletion.contains(fileName))
  5755. projectCompletion[fileName].dirty=TRUE;
  5756. }
  5757. if (preferences.deleteOverwrittenErrors && IS_FILE(currentListItem)
  5758. && CURRENT_VIEW==static_cast<ListViewFile *>(currentListItem)->kateView) {
  5759. ListViewFile *lvFile=static_cast<ListViewFile *>(currentListItem);
  5760. Q3ListViewItemIterator lvit(errorList->errorListView);
  5761. ErrorListItem *errorItem;
  5762. while ((errorItem=static_cast<ErrorListItem *>(lvit.current()))) {
  5763. ++lvit;
  5764. if (errorItem->lvFile==lvFile && errorItem->cursor) {
  5765. int line,col;
  5766. errorItem->cursor->position(line,col);
  5767. int curline,curcol;
  5768. lvFile->kateView->cursorPosition().position(curline,curcol);
  5769. if (curline==line && curcol==col)
  5770. delete errorItem;
  5771. }
  5772. }
  5773. }
  5774. }
  5775. if (kreplace) kreplace->invalidateSelection();
  5776. }
  5777. void MainForm::current_view_undoChanged()
  5778. {
  5779. if (CURRENT_VIEW && !disableViewEvents) {
  5780. editUndoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  5781. editRedoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  5782. accel->setItemEnabled(0,CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  5783. accel->setItemEnabled(1,CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  5784. }
  5785. }
  5786. void MainForm::current_view_selectionChanged()
  5787. {
  5788. if (CURRENT_VIEW && !disableViewEvents) {
  5789. editClearAction->setEnabled(CURRENT_VIEW->selection());
  5790. editCutAction->setEnabled(CURRENT_VIEW->selection());
  5791. editCopyAction->setEnabled(CURRENT_VIEW->selection());
  5792. accel->setItemEnabled(2,CURRENT_VIEW->selection());
  5793. accel->setItemEnabled(3,CURRENT_VIEW->selection());
  5794. }
  5795. }
  5796. void MainForm::current_view_charactersInteractivelyInserted(int line, int col, const QString &characters)
  5797. {
  5798. if (CURRENT_VIEW) {
  5799. if (preferences.autoBlocks && characters=="{"
  5800. && col==CURRENT_VIEW->document()->lineLength(line)-1) {
  5801. KTextEditor::Document *doc=CURRENT_VIEW->document();
  5802. CATEGORY_OF(category,currentListItem);
  5803. QString fileText=doc->text();
  5804. // Only for C files.
  5805. if (category==cFilesListItem||category==qllFilesListItem
  5806. ||(category==hFilesListItem&&(fileText.isNull()||fileText.isEmpty()||(fileText[0]!='|'&&fileText[0]!=';')))) {
  5807. QString indent=doc->line(line);
  5808. // Only if the line was all whitespace, otherwise wait for Enter to be
  5809. // pressed (prevents annoying the user while typing a string or something).
  5810. if (indent.contains(QRegExp("^\\s*\\{$"))) {
  5811. indent=indent.remove('{');
  5812. QString cursorLine=indent+"\t";
  5813. doc->startEditing();
  5814. doc->insertLine(line+1,cursorLine);
  5815. doc->insertLine(line+2,indent+"}");
  5816. doc->endEditing();
  5817. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
  5818. }
  5819. }
  5820. }
  5821. if (IS_FILE(currentListItem)
  5822. && CURRENT_VIEW==static_cast<ListViewFile *>(currentListItem)->kateView
  5823. && characters=="(") {
  5824. QString fileText=CURRENT_VIEW->document()->text();
  5825. CATEGORY_OF(category,currentListItem);
  5826. // Completion only operates on C files.
  5827. if (category==cFilesListItem || category==qllFilesListItem
  5828. || (category==hFilesListItem && !fileText.isEmpty()
  5829. && fileText[0]!='|' && fileText[0]!=';')) {
  5830. new ArgHintPopup(CURRENT_VIEW,pathInProject(currentListItem),this);
  5831. }
  5832. }
  5833. }
  5834. }
  5835. void MainForm::current_view_newLineHook()
  5836. {
  5837. int line,col;
  5838. CURRENT_VIEW->cursorPosition().position(line,col);
  5839. KTextEditor::Document *doc=CURRENT_VIEW->document();
  5840. if (preferences.autoBlocks && line && doc->line(line-1).endsWith("{")) {
  5841. CATEGORY_OF(category,currentListItem);
  5842. QString fileText=doc->text();
  5843. // Only for C files.
  5844. if (category==cFilesListItem||category==qllFilesListItem
  5845. ||(category==hFilesListItem&&(fileText.isNull()||fileText.isEmpty()||(fileText[0]!='|'&&fileText[0]!=';')))) {
  5846. QString indent=doc->line(line-1);
  5847. // Remove everything starting from the first non-whitespace character.
  5848. indent=indent.remove(QRegExp("(?!\\s).*$"));
  5849. QString cursorLine=indent+"\t";
  5850. doc->startEditing();
  5851. doc->removeText(KTextEditor::Range(line,0,line,col));
  5852. doc->insertLine(line,cursorLine);
  5853. doc->insertText(KTextEditor::Cursor(line+1,0),indent+"}");
  5854. doc->endEditing();
  5855. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,cursorLine.length()));
  5856. }
  5857. }
  5858. }
  5859. void MainForm::clipboard_dataChanged()
  5860. {
  5861. if (CURRENT_VIEW) {
  5862. editPasteAction->setEnabled(!clipboard->text().isNull());
  5863. accel->setItemEnabled(4,!clipboard->text().isNull());
  5864. }
  5865. }
  5866. void MainForm::fileTreeItemRenamed( Q3ListViewItem *item, const QString &newName, int col)
  5867. {
  5868. if (col)
  5869. return;
  5870. if (item==rootListItem) {
  5871. // validate name, fix if invalid
  5872. Q3ValueList<QChar> validInVarname;
  5873. #define V(i) validInVarname.append(QChar(i))
  5874. #define VR(m,n) for(unsigned i=m;i<=n;i++)V(i)
  5875. VR(48,57); // 0..9
  5876. VR(65,90); // A..Z
  5877. V(95); // _
  5878. VR(97,122); // a..z
  5879. V(181); // mu
  5880. VR(192,214); // À..Ö
  5881. VR(216,246); // Ø..ö
  5882. VR(248,255); // ø..ÿ
  5883. VR(0x3b1,0x3b6);V(0x3b8);V(0x3bb);V(0x3be);V(0x3c1);V(0x3c3);V(0x3c4);
  5884. V(0x3c6);V(0x3c8);V(0x3c9); // small Greek letters
  5885. V(0x393);V(0x394);V(0x3a0);V(0x3a3);V(0x3a9); // capital Greek letters
  5886. #undef VR
  5887. #undef V
  5888. bool hasFolder=false;
  5889. int i;
  5890. QString prjName=newName;
  5891. for (i=prjName.length();i>=0;i--) {
  5892. if (prjName[i]=='\\') {
  5893. if (hasFolder)
  5894. prjName.remove(i,1);
  5895. else
  5896. hasFolder=true;
  5897. } else if (!validInVarname.contains(prjName[i]))
  5898. prjName.remove(i,1);
  5899. }
  5900. if (!prjName.isEmpty() && prjName[0]=='\\') prjName.remove(0,1);
  5901. if (prjName.isEmpty()) prjName="Project1";
  5902. if ((prjName[0]>='0'&&prjName[0]<='9')||prjName[0]=='_')
  5903. prjName.prepend('X');
  5904. i=prjName.find('\\');
  5905. if (i>=0) {
  5906. if (i>8) {
  5907. prjName.remove(8,i-8);
  5908. i=8;
  5909. }
  5910. if ((prjName[i+1]>='0'&&prjName[i+1]<='9')||prjName[i+1]=='_')
  5911. prjName.insert(i+1,'X');
  5912. prjName.truncate(i+9);
  5913. if (prjName.length()==i+1) prjName.append("Project1");
  5914. } else prjName.truncate(8);
  5915. item->setText(0,prjName);
  5916. projectIsDirty=true;
  5917. projectNeedsRelink=TRUE;
  5918. return;
  5919. }
  5920. if (!IS_FILE(item))
  5921. return;
  5922. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  5923. QString suffix;
  5924. QString oldLabel;
  5925. QString &fileNameRef=theFile->fileName;
  5926. QString oldFileName=fileNameRef;
  5927. QString newFileName=fileNameRef;
  5928. int o,s;
  5929. o=oldFileName.findRev('.');
  5930. s=oldFileName.findRev('/');
  5931. if (o>=0&&(s<0||o>s)) {
  5932. suffix=oldFileName.mid(o+1);
  5933. newFileName.truncate(o);
  5934. } else {
  5935. suffix=QString::null;
  5936. }
  5937. if (s>=0) {
  5938. oldLabel=newFileName.mid(s+1);
  5939. newFileName.truncate(s+1);
  5940. } else {
  5941. oldLabel=newFileName;
  5942. newFileName.truncate(0);
  5943. }
  5944. if (!oldLabel.compare(newName))
  5945. return; //no changes are needed, and we don't want it to complain about the file conflicting with itself!
  5946. newFileName+=newName;
  5947. newFileName+='.';
  5948. newFileName+=suffix;
  5949. if (checkFileName(newFileName,extractAllFileNames())) {
  5950. CATEGORY_OF(category,item);
  5951. if (IS_EDITABLE_CATEGORY(category)) {
  5952. if (!oldFileName.isEmpty() && oldFileName[0]=='/')
  5953. KDirWatch::self()->removeFile(oldFileName);
  5954. if (newFileName.isEmpty() || newFileName[0]!='/')
  5955. newFileName.prepend(QFileInfo(projectFileName).absolutePath()+"/");
  5956. mkdir_multi(newFileName);
  5957. if (!theFile->kateView->document()->saveAs(newFileName)) {
  5958. KMessageBox::error(this,"Failed to rename the file.");
  5959. theFile->setText(0,oldLabel);
  5960. if (!oldFileName.isEmpty() && oldFileName[0]=='/')
  5961. KDirWatch::self()->addFile(oldFileName);
  5962. } else {
  5963. if (!theFile->isNew && !oldFileName.isEmpty() && oldFileName[0]=='/')
  5964. QDir().remove(oldFileName);
  5965. fileNameRef=newFileName;
  5966. KDirWatch::self()->addFile(newFileName);
  5967. removeTrailingSpacesFromView(theFile->kateView);
  5968. theFile->kateView->document()->setModified(FALSE);
  5969. theFile->isNew=FALSE;
  5970. projectIsDirty=TRUE;
  5971. projectNeedsRelink=TRUE;
  5972. }
  5973. } else {
  5974. mkdir_multi(newFileName);
  5975. if (!moveFile(oldFileName,newFileName)) {
  5976. KMessageBox::error(this,"Failed to rename the file.");
  5977. theFile->setText(0,oldLabel);
  5978. } else {
  5979. fileNameRef=newFileName;
  5980. projectIsDirty=TRUE;
  5981. projectNeedsRelink=TRUE;
  5982. }
  5983. }
  5984. } else {
  5985. KMessageBox::error(this,"The name you chose conflicts with that of another file.");
  5986. theFile->setText(0,oldLabel);
  5987. }
  5988. updateRightStatusLabel();
  5989. }
  5990. void MainForm::closeEvent(QCloseEvent *e)
  5991. {
  5992. if (compiling || savePrompt())
  5993. e->ignore();
  5994. else {
  5995. Q3PtrListIterator<SourceFile> sfit(sourceFiles);
  5996. SourceFile *sourceFile;
  5997. for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
  5998. if (sourceFile->savePrompt()) {
  5999. e->ignore();
  6000. return;
  6001. }
  6002. }
  6003. clearProject();
  6004. e->accept();
  6005. }
  6006. }
  6007. void MainForm::KDirWatch_dirty(const QString &fileName)
  6008. {
  6009. Q3ListViewItem *item=rootListItem->firstChild(),*next;
  6010. QStringList allFiles;
  6011. while (item) {
  6012. if (IS_FOLDER(item)) {
  6013. next=item->firstChild();
  6014. if (next) {
  6015. item=next;
  6016. continue;
  6017. }
  6018. }
  6019. if (IS_FILE(item)) {
  6020. if (!fileName.compare(static_cast<ListViewFile *>(item)->fileName)) {
  6021. CATEGORY_OF(category,item);
  6022. if (!IS_EDITABLE_CATEGORY(category)) {
  6023. qWarning("KDirWatch_dirty called for non-editable file");
  6024. return;
  6025. }
  6026. if (KMessageBox::questionYesNo(this,
  6027. QString("The file \'%1\' has been changed by another program. "
  6028. "Do you want to reload it?").arg(fileName),"File Changed")
  6029. ==KMessageBox::Yes) {
  6030. static_cast<ListViewFile *>(item)->isNew=FALSE;
  6031. static_cast<ListViewFile *>(item)->kateView->document()->setModified(FALSE);
  6032. disableViewEvents=TRUE;
  6033. static_cast<ListViewFile *>(item)->kateView->document()->documentReload();
  6034. disableViewEvents=FALSE;
  6035. updateRightStatusLabel();
  6036. }
  6037. return;
  6038. }
  6039. }
  6040. next=item->nextSibling();
  6041. while (!next) {
  6042. next=item->parent();
  6043. if (next==rootListItem||!next) {
  6044. return;
  6045. }
  6046. item=next;
  6047. next=item->nextSibling();
  6048. }
  6049. item=next;
  6050. }
  6051. return;
  6052. }
  6053. QString MainForm::pathInProject(Q3ListViewItem *item)
  6054. {
  6055. QString path=QFileInfo(static_cast<ListViewFile *>(item)->fileName).fileName();
  6056. item=item->parent();
  6057. while (!IS_CATEGORY(item)) {
  6058. path.prepend('/');
  6059. path.prepend(item->text(0));
  6060. item=item->parent();
  6061. }
  6062. return path;
  6063. }
  6064. QString MainForm::textForHeader(const QString &fileName)
  6065. {
  6066. QString name=fileName;
  6067. int pos;
  6068. Q3ListViewItem *item=hFilesListItem;
  6069. while ((pos=name.find('/'))>=0) {
  6070. QString folder=name.left(pos);
  6071. name.remove(0,pos+1);
  6072. for (item=item->firstChild();item;item=item->nextSibling()) {
  6073. if (IS_FOLDER(item)) {
  6074. if (item->text(0)==folder) break;
  6075. }
  6076. }
  6077. if (!item) return QString::null;
  6078. }
  6079. for (item=item->firstChild();item;item=item->nextSibling()) {
  6080. if (IS_FILE(item)) {
  6081. ListViewFile *fileItem=static_cast<ListViewFile *>(item);
  6082. if (QFileInfo(fileItem->fileName).fileName()==name)
  6083. return fileItem->kateView->document()->text();
  6084. }
  6085. }
  6086. return QString::null;
  6087. }
  6088. /*
  6089. * Constructs a MainForm as a child of 'parent', with the
  6090. * name 'name' and widget flags set to 'f'.
  6091. *
  6092. */
  6093. MainForm::MainForm(QWidget* parent, const char* name, Qt::WindowFlags fl)
  6094. : QMainWindow(parent, name, fl)
  6095. {
  6096. setupUi(this);
  6097. (void)statusBar();
  6098. init();
  6099. }
  6100. /*
  6101. * Destroys the object and frees any allocated resources
  6102. */
  6103. MainForm::~MainForm()
  6104. {
  6105. destroy();
  6106. // no need to delete child widgets, Qt does it all for us
  6107. }
  6108. /*
  6109. * Sets the strings of the subwidgets using the current
  6110. * language.
  6111. */
  6112. void MainForm::languageChange()
  6113. {
  6114. retranslateUi(this);
  6115. }