mainform.ui.h 141 KB

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