mainform.ui.h 238 KB

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