mainform.ui.h 239 KB

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