mainform.cpp 242 KB

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