mainform.ui.h 222 KB

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