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