mainform.ui.h 238 KB

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