mainform.ui.h 239 KB

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