mainform.cpp 238 KB

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