mainform.ui.h 239 KB

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