mainform.cpp 238 KB

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