mainform.ui.h 140 KB

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