mainform.ui.h 161 KB

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