mainform.ui.h 181 KB

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