mainform.ui.h 230 KB

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