mainform.cpp 240 KB

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