mainform.cpp 241 KB

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