mainform.ui.h 239 KB

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