mainform.cpp 238 KB

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