mainform.cpp 241 KB

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