mainform.ui.h 238 KB

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