mainform.ui.h 178 KB

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