mainform.cpp 238 KB

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