mainform.ui.h 229 KB

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