mainform.cpp 237 KB

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