mainform.ui.h 237 KB

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