mainform.ui.h 140 KB

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