mainform.ui.h 221 KB

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