mainform.cpp 242 KB

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