mainform.ui.h 238 KB

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