mainform.cpp 241 KB

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