mainform.ui.h 230 KB

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