mainform.cpp 242 KB

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