mainform.ui.h 225 KB

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