mainform.cpp 238 KB

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