mainform.ui.h 126 KB

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