mainform.ui.h 225 KB

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