mainform.ui.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. */
  24. #include <qlabel.h>
  25. #include <qstatusbar.h>
  26. #include <qtimer.h>
  27. #include <qdatetime.h>
  28. #include <qdragobject.h>
  29. #include <qassistantclient.h>
  30. #include <qdir.h>
  31. #include <kparts/factory.h>
  32. #include <klibloader.h>
  33. #include <kate/document.h>
  34. #include <kate/view.h>
  35. #include <kconfig.h>
  36. #include <ktexteditor/configinterfaceextension.h>
  37. #include <ktexteditor/dynwordwrapinterface.h>
  38. #include <kaboutdata.h>
  39. #include <khelpmenu.h>
  40. #include <kfiledialog.h>
  41. #include <kurl.h>
  42. #include <kmessagebox.h>
  43. #include <kdirwatch.h>
  44. #include <cstdio>
  45. #include <cstdlib>
  46. #include "ktigcc.h"
  47. #include "tpr.h"
  48. using std::puts;
  49. using std::exit;
  50. #define TIGCC_TPR_Filter "*.tpr|TIGCC Projects (*.tpr)\n"
  51. #define TIGCC_H_Filter "*.h|Header Files (*.h)\n"
  52. #define TIGCC_C_Filter "*.c|C Files (*.c)\n"
  53. #define TIGCC_S_Filter "*.s|GNU Assembly Files (*.s)\n"
  54. #define TIGCC_ASM_Filter "*.asm|A68k Assembly Files (*.asm)\n"
  55. #define TIGCC_QLL_Filter "*.qll|Quill Files (*.qll)\n"
  56. #define TIGCC_O_Filter "*.o|Object Files (*.o)\n"
  57. #define TIGCC_A_Filter "*.a|Archive Files (*.a)\n"
  58. #define TIGCC_TXT_Filter "*.txt|Text Files (*.txt)\n"
  59. #define TIGCCAllFilter "*|All Files (*)"
  60. enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
  61. #define TIGCCProjectDirectory "/usr/local/tigcc/projects"
  62. #define IS_CATEGORY(item) ((item) && ((item)==hFilesListItem \
  63. || (item)==cFilesListItem \
  64. || (item)==sFilesListItem \
  65. || (item)==asmFilesListItem \
  66. || (item)==qllFilesListItem \
  67. || (item)==oFilesListItem \
  68. || (item)==aFilesListItem \
  69. || (item)==txtFilesListItem \
  70. || (item)==othFilesListItem))
  71. #define IS_EDITABLE_CATEGORY(item) ((item) && ((item)==hFilesListItem \
  72. || (item)==cFilesListItem \
  73. || (item)==sFilesListItem \
  74. || (item)==asmFilesListItem \
  75. || (item)==qllFilesListItem \
  76. || (item)==txtFilesListItem))
  77. #define IS_FOLDER(item) ((item) && (item)->rtti()==0x716CC0)
  78. #define IS_FILE(item) ((item) && (item)->rtti()==0x716CC1)
  79. #define CATEGORY_OF(category,item) QListViewItem *category=(item); \
  80. while (category->parent()->rtti()==0x716CC0) \
  81. category=category->parent()
  82. #define COUNTER_FOR_CATEGORY(category) ((category)==hFilesListItem?hFileCount: \
  83. (category)==cFilesListItem?cFileCount: \
  84. (category)==sFilesListItem?sFileCount: \
  85. (category)==asmFilesListItem?asmFileCount: \
  86. (category)==qllFilesListItem?qllFileCount: \
  87. (category)==oFilesListItem?oFileCount: \
  88. (category)==aFilesListItem?aFileCount: \
  89. (category)==txtFilesListItem?txtFileCount: \
  90. othFileCount)
  91. // All the methods are inline because otherwise QT Designer will mistake them
  92. // for slots of the main form.
  93. class ListViewFolder : public QListViewItem {
  94. public:
  95. ListViewFolder(QListView *parent) : QListViewItem(parent)
  96. {
  97. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  98. setDragEnabled(TRUE);
  99. setDropEnabled(TRUE);
  100. }
  101. ListViewFolder(QListViewItem *parent) : QListViewItem(parent)
  102. {
  103. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  104. setDragEnabled(TRUE);
  105. setDropEnabled(TRUE);
  106. }
  107. ListViewFolder(QListView *parent, QListViewItem *after)
  108. : QListViewItem(parent, after)
  109. {
  110. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  111. setDropEnabled(TRUE);
  112. setDragEnabled(TRUE);
  113. }
  114. ListViewFolder(QListViewItem *parent, QListViewItem *after)
  115. : QListViewItem(parent, after)
  116. {
  117. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  118. setDragEnabled(TRUE);
  119. setDropEnabled(TRUE);
  120. }
  121. virtual int rtti(void) const {return 0x716CC0;}
  122. protected:
  123. };
  124. class ListViewFile : public QListViewItem {
  125. public:
  126. ListViewFile(QListView *parent) : QListViewItem(parent),
  127. cursorLine(1), cursorCol(0),
  128. isNew(TRUE), isDirty(FALSE)
  129. {
  130. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  131. setDragEnabled(TRUE);
  132. setDropEnabled(TRUE);
  133. setRenameEnabled(0,TRUE);
  134. }
  135. ListViewFile(QListViewItem *parent) : QListViewItem(parent),
  136. cursorLine(1), cursorCol(0),
  137. isNew(TRUE), isDirty(FALSE)
  138. {
  139. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  140. setDragEnabled(TRUE);
  141. setDropEnabled(TRUE);
  142. setRenameEnabled(0,TRUE);
  143. }
  144. ListViewFile(QListView *parent, QListViewItem *after)
  145. : QListViewItem(parent, after), cursorLine(1), cursorCol(0),
  146. isNew(TRUE), isDirty(FALSE)
  147. {
  148. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  149. setDropEnabled(TRUE);
  150. setDragEnabled(TRUE);
  151. setRenameEnabled(0,TRUE);
  152. }
  153. ListViewFile(QListViewItem *parent, QListViewItem *after)
  154. : QListViewItem(parent, after), cursorLine(1), cursorCol(0),
  155. isNew(TRUE), isDirty(FALSE)
  156. {
  157. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  158. setDragEnabled(TRUE);
  159. setDropEnabled(TRUE);
  160. setRenameEnabled(0,TRUE);
  161. }
  162. virtual ~ListViewFile()
  163. {
  164. if (fileName[0]=='/')
  165. KDirWatch::self()->removeFile(fileName);
  166. }
  167. virtual int rtti(void) const {return 0x716CC1;}
  168. QString textBuffer;
  169. unsigned int cursorLine, cursorCol;
  170. QString fileName; // full name of the file
  171. bool isNew;
  172. bool isDirty;
  173. protected:
  174. };
  175. // These should be instance variables in clean C++, but QT Designer won't let me
  176. // touch the class definition, so this is all I can do. And there is only one
  177. // instance of MainForm anyway.
  178. static QListViewItem *rootListItem;
  179. static QListViewItem *hFilesListItem;
  180. static QListViewItem *cFilesListItem;
  181. static QListViewItem *sFilesListItem;
  182. static QListViewItem *asmFilesListItem;
  183. static QListViewItem *qllFilesListItem;
  184. static QListViewItem *oFilesListItem;
  185. static QListViewItem *aFilesListItem;
  186. static QListViewItem *txtFilesListItem;
  187. static QListViewItem *othFilesListItem;
  188. static QListViewItem *currentListItem;
  189. static bool currentListItemEditable;
  190. static bool projectIsDirty;
  191. static QLabel *leftStatusLabel;
  192. static QLabel *rowStatusLabel;
  193. static QLabel *colStatusLabel;
  194. static QLabel *charsStatusLabel;
  195. static QLabel *rightStatusLabel;
  196. static Kate::View* m_view;
  197. static KHelpMenu *khelpmenu;
  198. static QPopupMenu *te_popup;
  199. static QAssistantClient *assistant;
  200. static int fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
  201. static tprSettings settings;
  202. static tprLibOpts libopts;
  203. static QString projectFileName;
  204. static QString lastDirectory;
  205. class DnDListView : public QListView {
  206. private:
  207. public:
  208. DnDListView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
  209. : QListView(parent,name,f) {}
  210. protected:
  211. virtual QDragObject *dragObject() {
  212. QListViewItem *currItem=selectedItem();
  213. if (currItem==rootListItem || currItem->parent()==rootListItem)
  214. return NULL;
  215. QStoredDrag *storedDrag=new QStoredDrag("x-ktigcc-dnd", this);
  216. static QByteArray data(sizeof(QListViewItem*));
  217. data.duplicate(reinterpret_cast<char *>(&currItem),
  218. sizeof(QListViewItem*));
  219. storedDrag->setEncodedData(data);
  220. return storedDrag;
  221. }
  222. virtual void dropEvent (QDropEvent *e) {
  223. if (e->source()==this && e->provides("x-ktigcc-dnd")) {
  224. QListViewItem *currItem;
  225. currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  226. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  227. // dropping folder
  228. // can only drop on folder or category
  229. QPoint vp=contentsToViewport(e->pos());
  230. QListViewItem *item=itemAt(vp);
  231. if (IS_FOLDER(item)) {
  232. // need same category
  233. CATEGORY_OF(srcCategory,currItem);
  234. CATEGORY_OF(destCategory,item);
  235. if (srcCategory == destCategory) {
  236. // can't move folder into itself
  237. for (QListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
  238. if (destFolder==currItem) goto ignore;
  239. }
  240. // move folder
  241. e->accept();
  242. currItem->parent()->takeItem(currItem);
  243. item->insertItem(currItem);
  244. // put it at the right place
  245. if (currItem->nextSibling()) {
  246. QListViewItem *lastItem=currItem->nextSibling();
  247. while(lastItem->nextSibling())
  248. lastItem=lastItem->nextSibling();
  249. currItem->moveItem(lastItem);
  250. }
  251. projectIsDirty=TRUE;
  252. } else {ignore: e->ignore();}
  253. } else e->ignore();
  254. } else if (IS_FILE(currItem)) {
  255. // dropping file
  256. QPoint vp=contentsToViewport(e->pos());
  257. QListViewItem *item=itemAt(vp);
  258. if (IS_FOLDER(item)) {
  259. // drop on folder
  260. // don't allow more than one Quill file per project
  261. CATEGORY_OF(srcCategory,currItem);
  262. CATEGORY_OF(destCategory,item);
  263. if (qllFilesListItem && srcCategory != qllFilesListItem
  264. && destCategory == qllFilesListItem && qllFileCount)
  265. e->ignore();
  266. else {
  267. // move file
  268. e->accept();
  269. currItem->parent()->takeItem(currItem);
  270. COUNTER_FOR_CATEGORY(srcCategory)--;
  271. item->insertItem(currItem);
  272. COUNTER_FOR_CATEGORY(destCategory)++;
  273. // put it at the right place
  274. if (IS_FILE(currItem->nextSibling())) {
  275. QListViewItem *lastItem=currItem->nextSibling();
  276. while(IS_FILE(lastItem->nextSibling()))
  277. lastItem=lastItem->nextSibling();
  278. currItem->moveItem(lastItem);
  279. }
  280. // we changed the counters
  281. static_cast<MainForm *>(parent())->updateLeftStatusLabel();
  282. projectIsDirty=TRUE;
  283. }
  284. } else if (IS_FILE(item)) {
  285. // drop on file
  286. // need same parent, but different items
  287. if (currItem->parent() == item->parent()
  288. && currItem != item) {
  289. // reorder files
  290. // figure out which one is the first
  291. for (QListViewItem *i=currItem->parent()->firstChild();i;
  292. i=i->nextSibling()) {
  293. if (i==currItem) {
  294. // currItem is first, move currItem after item
  295. e->accept();
  296. currItem->moveItem(item);
  297. projectIsDirty=TRUE;
  298. break;
  299. } else if (i==item) {
  300. // item is first, move currItem before item
  301. e->accept();
  302. currItem->moveItem(item);
  303. item->moveItem(currItem);
  304. projectIsDirty=TRUE;
  305. break;
  306. }
  307. }
  308. } else e->ignore();
  309. } else e->ignore();
  310. } else e->ignore();
  311. } else e->ignore();
  312. }
  313. virtual void dragEnterEvent (QDragEnterEvent *e) {
  314. if (e->source()==this&&(e->provides("x-ktigcc-dnd")))
  315. e->accept();
  316. }
  317. virtual void dragMoveEvent (QDragMoveEvent *e) {
  318. if (e->source()==this && e->provides("x-ktigcc-dnd")) {
  319. QListViewItem *currItem;
  320. currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  321. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  322. // dropping folder
  323. // can only drop on folder or category
  324. QPoint vp=contentsToViewport(e->pos());
  325. QListViewItem *item=itemAt(vp);
  326. if (IS_FOLDER(item)) {
  327. // need same category
  328. CATEGORY_OF(srcCategory,currItem);
  329. CATEGORY_OF(destCategory,item);
  330. if (srcCategory == destCategory) {
  331. // can't move folder into itself
  332. for (QListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
  333. if (destFolder==currItem) goto ignore;
  334. }
  335. e->accept();
  336. } else {ignore: e->ignore();}
  337. } else e->ignore();
  338. } else if (IS_FILE(currItem)) {
  339. // dropping file
  340. QPoint vp=contentsToViewport(e->pos());
  341. QListViewItem *item=itemAt(vp);
  342. if (IS_FOLDER(item)) {
  343. // drop on folder
  344. // don't allow more than one Quill file per project
  345. CATEGORY_OF(srcCategory,currItem);
  346. CATEGORY_OF(destCategory,item);
  347. if (qllFilesListItem && srcCategory != qllFilesListItem
  348. && destCategory == qllFilesListItem && qllFileCount)
  349. e->ignore();
  350. else
  351. e->accept();
  352. } else if (IS_FILE(item)) {
  353. // drop on file
  354. // need same parent, but different items
  355. if (currItem->parent() == item->parent()
  356. && currItem != item) e->accept(); else e->ignore();
  357. } else e->ignore();
  358. } else e->ignore();
  359. } else e->ignore();
  360. }
  361. };
  362. void MainForm::init()
  363. {
  364. fileNewFolderAction->setEnabled(FALSE);
  365. KParts::Factory* factory = (KParts::Factory *)
  366. KLibLoader::self()->factory ("libkatepart");
  367. if (!factory) exit(1);
  368. KTextEditor::Document *doc = (KTextEditor::Document *)
  369. factory->createPart( 0, "", this, "", "KTextEditor::Document" );
  370. m_view = (Kate::View *) doc->createView( splitter, 0L );
  371. m_view->setEnabled(FALSE);
  372. m_view->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding,0,0));
  373. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  374. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  375. m_view->getDoc()->readConfig(&kconfig);
  376. delete_temp_file("config.tmp");
  377. m_view->getDoc()->setHlMode(0);
  378. dynWordWrapInterface(m_view)->setDynWordWrap(FALSE);
  379. connect(m_view,SIGNAL(cursorPositionChanged()),this,SLOT(m_view_cursorPositionChanged()));
  380. connect(m_view->getDoc(),SIGNAL(textChanged()),this,SLOT(m_view_textChanged()));
  381. te_popup = new QPopupMenu(this);
  382. te_popup->insertItem("&Open file at cursor",0);
  383. te_popup->insertItem("&Find symbol declaration",1);
  384. te_popup->insertSeparator();
  385. te_popup->insertItem("&Undo",2);
  386. te_popup->insertItem("&Redo",3);
  387. te_popup->insertSeparator();
  388. te_popup->insertItem("&Clear",4);
  389. te_popup->insertItem("Cu&t",5);
  390. te_popup->insertItem("Cop&y",6);
  391. te_popup->insertItem("&Paste",7);
  392. te_popup->insertSeparator();
  393. te_popup->insertItem("&Select all",8);
  394. te_popup->insertSeparator();
  395. te_popup->insertItem("&Increase indent",9);
  396. te_popup->insertItem("&Decrease indent",10);
  397. m_view->installPopup(te_popup);
  398. connect(te_popup,SIGNAL(aboutToShow()),this,SLOT(te_popup_aboutToShow()));
  399. QValueList<int> list;
  400. list.append(150);
  401. list.append(500);
  402. splitter->setSizes(list);
  403. leftStatusLabel=new QLabel("0 Files Total",this);
  404. leftStatusLabel->setMaximumWidth(splitter->sizes().first());
  405. statusBar()->addWidget(leftStatusLabel,1);
  406. rowStatusLabel=new QLabel("",this);
  407. rowStatusLabel->setAlignment(Qt::AlignRight);
  408. statusBar()->addWidget(rowStatusLabel,1);
  409. rowStatusLabel->hide();
  410. colStatusLabel=new QLabel("",this);
  411. colStatusLabel->setAlignment(Qt::AlignRight);
  412. statusBar()->addWidget(colStatusLabel,1);
  413. colStatusLabel->hide();
  414. charsStatusLabel=new QLabel("",this);
  415. statusBar()->addWidget(charsStatusLabel,1);
  416. charsStatusLabel->hide();
  417. rightStatusLabel=new QLabel("",this);
  418. rightStatusLabel->setMaximumWidth(splitter->sizes().last());
  419. statusBar()->addWidget(rightStatusLabel,1);
  420. statusBar()->setSizeGripEnabled(FALSE);
  421. connect(statusBar(),SIGNAL(messageChanged(const QString &)),this,SLOT(statusBar_messageChanged(const QString &)));
  422. fileTree->setSorting(-1);
  423. fileTree->setColumnWidthMode(0,QListView::Maximum);
  424. fileTree->header()->hide();
  425. rootListItem=new QListViewItem(fileTree);
  426. rootListItem->setText(0,"Project1");
  427. rootListItem->setPixmap(0,QPixmap::fromMimeSource("tpr.png"));
  428. rootListItem->setOpen(TRUE);
  429. rootListItem->setDragEnabled(TRUE);
  430. QListViewItem *folderListItem=new ListViewFolder(rootListItem);
  431. hFilesListItem=folderListItem;
  432. folderListItem->setText(0,"Header Files");
  433. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  434. cFilesListItem=folderListItem;
  435. folderListItem->setText(0,"C Files");
  436. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  437. sFilesListItem=folderListItem;
  438. folderListItem->setText(0,"GNU Assembly Files");
  439. char a68k_path[strlen(tigcc_base)+10];
  440. sprintf(a68k_path, "%s/bin/a68k", tigcc_base);
  441. if(access(a68k_path, F_OK) != -1) {
  442. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  443. asmFilesListItem=folderListItem;
  444. folderListItem->setText(0,"A68k Assembly Files");
  445. } else {
  446. qllFilesListItem=NULL;
  447. fileNewQuillSourceFileAction->setVisible(FALSE);
  448. }
  449. if (quill_drv) {
  450. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  451. qllFilesListItem=folderListItem;
  452. folderListItem->setText(0,"Quill Files");
  453. } else {
  454. qllFilesListItem=NULL;
  455. fileNewQuillSourceFileAction->setVisible(FALSE);
  456. }
  457. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  458. oFilesListItem=folderListItem;
  459. folderListItem->setText(0,"Object Files");
  460. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  461. aFilesListItem=folderListItem;
  462. folderListItem->setText(0,"Archive Files");
  463. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  464. txtFilesListItem=folderListItem;
  465. folderListItem->setText(0,"Text Files");
  466. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  467. othFilesListItem=folderListItem;
  468. folderListItem->setText(0,"Other Files");
  469. khelpmenu=new KHelpMenu(this,pabout);
  470. assistant = new QAssistantClient("",this);
  471. QStringList args(QString("-profile"));
  472. args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
  473. assistant->setArguments(args);
  474. lastDirectory=TIGCCProjectDirectory;
  475. projectFileName="";
  476. projectIsDirty=FALSE;
  477. connect(KDirWatch::self(),SIGNAL(created(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  478. connect(KDirWatch::self(),SIGNAL(dirty(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  479. KDirWatch::self()->startScan();
  480. pconfig->setGroup("Recent files");
  481. if (parg)
  482. openProject(parg);
  483. else {
  484. QString mostrecent=pconfig->readEntry("Current project");
  485. if (!mostrecent.isNull() && !mostrecent.isEmpty())
  486. openProject(mostrecent);
  487. }
  488. updateRecent();
  489. startTimer(100);
  490. }
  491. void MainForm::destroy()
  492. {
  493. Kate::Document *doc=m_view->getDoc();
  494. delete m_view;
  495. delete doc;
  496. delete te_popup;
  497. delete leftStatusLabel;
  498. delete rowStatusLabel;
  499. delete colStatusLabel;
  500. delete charsStatusLabel;
  501. delete rightStatusLabel;
  502. delete rootListItem;
  503. delete khelpmenu;
  504. delete assistant;
  505. }
  506. void MainForm::te_popup_aboutToShow()
  507. {
  508. te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
  509. te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
  510. te_popup->setItemEnabled(2,editUndoAction->isEnabled());
  511. te_popup->setItemEnabled(3,editRedoAction->isEnabled());
  512. te_popup->setItemEnabled(4,editClearAction->isEnabled());
  513. te_popup->setItemEnabled(5,editCutAction->isEnabled());
  514. te_popup->setItemEnabled(6,editCopyAction->isEnabled());
  515. te_popup->setItemEnabled(7,editPasteAction->isEnabled());
  516. te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
  517. te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
  518. te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
  519. }
  520. void MainForm::clearProject()
  521. {
  522. rootListItem->setText(0,"Project1");
  523. projectFileName="";
  524. fileTreeClicked(rootListItem);
  525. QListViewItem *f, *next;
  526. for (f=hFilesListItem->firstChild();f;f=next) {
  527. next=f->nextSibling();
  528. delete f;
  529. }
  530. for (f=cFilesListItem->firstChild();f;f=next) {
  531. next=f->nextSibling();
  532. delete f;
  533. }
  534. for (f=sFilesListItem->firstChild();f;f=next) {
  535. next=f->nextSibling();
  536. delete f;
  537. }
  538. if (asmFilesListItem) {
  539. for (f=asmFilesListItem->firstChild();f;f=next) {
  540. next=f->nextSibling();
  541. delete f;
  542. }
  543. }
  544. if (qllFilesListItem) {
  545. for (f=qllFilesListItem->firstChild();f;f=next) {
  546. next=f->nextSibling();
  547. delete f;
  548. }
  549. }
  550. for (f=oFilesListItem->firstChild();f;f=next) {
  551. next=f->nextSibling();
  552. delete f;
  553. }
  554. for (f=aFilesListItem->firstChild();f;f=next) {
  555. next=f->nextSibling();
  556. delete f;
  557. }
  558. for (f=txtFilesListItem->firstChild();f;f=next) {
  559. next=f->nextSibling();
  560. delete f;
  561. }
  562. for (f=othFilesListItem->firstChild();f;f=next) {
  563. next=f->nextSibling();
  564. delete f;
  565. }
  566. fileCount=cFileCount=hFileCount=sFileCount=asmFileCount=qllFileCount=oFileCount=aFileCount=txtFileCount=othFileCount=0;
  567. projectIsDirty=FALSE;
  568. updateLeftStatusLabel();
  569. }
  570. void MainForm::fileNewProject()
  571. {
  572. if (savePrompt())
  573. return;
  574. clearProject();
  575. pconfig->setGroup("Recent files");
  576. pconfig->writeEntry("Current project","");
  577. }
  578. QString MainForm::findFilter(unsigned short job)
  579. {
  580. QString ret;
  581. if (job==TIGCCOpenProjectFileFilter)
  582. {
  583. ret="*.tpr *.h *.c *.s ";
  584. if (asmFilesListItem)
  585. ret+="*.asm ";
  586. if (qllFilesListItem)
  587. ret+="*.qll ";
  588. ret+="*.txt";
  589. ret+="|All TIGCC Files ("+ret+")\n"
  590. TIGCC_TPR_Filter TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  591. if (asmFilesListItem)
  592. ret+=TIGCC_ASM_Filter;
  593. if (qllFilesListItem)
  594. ret+=TIGCC_QLL_Filter;
  595. ret+=TIGCC_TXT_Filter TIGCCAllFilter;
  596. }
  597. else if (job==TIGCCAddFilesFilter)
  598. {
  599. ret="*.h *.c *.s ";
  600. if (asmFilesListItem)
  601. ret+="*.asm ";
  602. if (qllFilesListItem)
  603. ret+="*.qll ";
  604. ret+="*.o *.a *.txt";
  605. ret+="|All TIGCC Files ("+ret+")\n"
  606. TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  607. if (asmFilesListItem)
  608. ret+=TIGCC_ASM_Filter;
  609. if (qllFilesListItem)
  610. ret+=TIGCC_QLL_Filter;
  611. ret+=TIGCC_O_Filter TIGCC_A_Filter TIGCC_TXT_Filter TIGCCAllFilter;
  612. }
  613. return ret;
  614. }
  615. QString MainForm::SGetFileName(int mode,const QString &fileFilter,const QString &caption,QWidget *parent)
  616. {
  617. QString ret;
  618. if (static_cast<KFileDialog::OperationMode>(mode)==KFileDialog::Opening)
  619. ret=KFileDialog::getOpenFileName(lastDirectory,fileFilter,parent,caption);
  620. else
  621. ret=KFileDialog::getSaveFileName(lastDirectory,fileFilter,parent,caption);
  622. if (!ret.isNull())
  623. {
  624. KURL dir;
  625. dir.setPath(ret);
  626. dir.setFileName("");
  627. lastDirectory=dir.path();
  628. }
  629. return ret;
  630. }
  631. //no mode, since it you can't save multiple.
  632. QStringList MainForm::SGetFileName_Multiple(const QString &fileFilter,const QString &caption,QWidget *parent)
  633. {
  634. QStringList ret;
  635. ret=KFileDialog::getOpenFileNames(lastDirectory,fileFilter,parent,caption);
  636. if (!ret.empty())
  637. {
  638. KURL dir;
  639. dir.setPath(ret[0]);
  640. dir.setFileName("");
  641. lastDirectory=dir.path();
  642. }
  643. return ret;
  644. }
  645. void MainForm::updateRecent()
  646. {
  647. pconfig->setGroup("Recent files");
  648. QString recent=pconfig->readEntry("Recent file 1");
  649. if (recent.isNull())
  650. fileRecent1Action->setVisible(FALSE);
  651. else {
  652. QString recentcut=recent.mid(recent.findRev('/')+1);
  653. recentcut.truncate(recentcut.findRev('.'));
  654. fileRecent1Action->setVisible(TRUE);
  655. fileRecent1Action->setText(recentcut);
  656. fileRecent1Action->setStatusTip(recent);
  657. }
  658. recent=pconfig->readEntry("Recent file 2");
  659. if (recent.isNull())
  660. fileRecent2Action->setVisible(FALSE);
  661. else {
  662. QString recentcut=recent.mid(recent.findRev('/')+1);
  663. recentcut.truncate(recentcut.findRev('.'));
  664. fileRecent2Action->setVisible(TRUE);
  665. fileRecent2Action->setText(recentcut);
  666. fileRecent2Action->setStatusTip(recent);
  667. }
  668. recent=pconfig->readEntry("Recent file 3");
  669. if (recent.isNull())
  670. fileRecent3Action->setVisible(FALSE);
  671. else {
  672. QString recentcut=recent.mid(recent.findRev('/')+1);
  673. recentcut.truncate(recentcut.findRev('.'));
  674. fileRecent3Action->setVisible(TRUE);
  675. fileRecent3Action->setText(recentcut);
  676. fileRecent3Action->setStatusTip(recent);
  677. }
  678. recent=pconfig->readEntry("Recent file 4");
  679. if (recent.isNull())
  680. fileRecent4Action->setVisible(FALSE);
  681. else {
  682. QString recentcut=recent.mid(recent.findRev('/')+1);
  683. recentcut.truncate(recentcut.findRev('.'));
  684. fileRecent4Action->setVisible(TRUE);
  685. fileRecent4Action->setText(recentcut);
  686. fileRecent4Action->setStatusTip(recent);
  687. }
  688. }
  689. void MainForm::addRecent(const QString &fileName)
  690. {
  691. unsigned i,j;
  692. pconfig->setGroup("Recent files");
  693. // Find recent file to overwrite. If it isn't one of the first 3, by
  694. // elimination, it is the last, thus the test only goes up to <4, not <=4.
  695. for (i=1;i<4;i++) {
  696. QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
  697. if (recenti.isNull() || !recenti.compare(fileName))
  698. break;
  699. }
  700. // Move entries up
  701. for (j=i;j>1;j--) {
  702. pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
  703. }
  704. // The first recent file is the current project.
  705. pconfig->writeEntry("Recent file 1",fileName);
  706. pconfig->writeEntry("Current project",fileName);
  707. updateRecent();
  708. }
  709. QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
  710. {
  711. QString fileText;
  712. if (getPathType(fileName)!=PATH_FILE) {
  713. KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
  714. return NULL;
  715. }
  716. if (IS_EDITABLE_CATEGORY(category)) {
  717. fileText=loadFileText(fileName);
  718. if (fileText.isNull()) {
  719. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  720. return NULL;
  721. }
  722. }
  723. QListViewItem *item=NULL, *next=parent->firstChild();
  724. for (; IS_FILE(next); next=item->nextSibling())
  725. item=next;
  726. ListViewFile *newFile=item?new ListViewFile(parent,item)
  727. :new ListViewFile(parent);
  728. newFile->isNew=FALSE;
  729. newFile->setText(0,fileCaption);
  730. newFile->setPixmap(0,QPixmap::fromMimeSource(
  731. category==cFilesListItem||category==qllFilesListItem?"filec.png":
  732. category==hFilesListItem?"fileh.png":
  733. category==sFilesListItem||category==asmFilesListItem?"files.png":
  734. category==txtFilesListItem?"filet.png":"filex.png"));
  735. if (IS_EDITABLE_CATEGORY(category))
  736. newFile->textBuffer=fileText;
  737. newFile->fileName=fileName;
  738. KDirWatch::self()->addFile(fileName);
  739. fileCount++;
  740. COUNTER_FOR_CATEGORY(category)++;
  741. return newFile;
  742. }
  743. QListViewItem *MainForm::createFolder(QListViewItem *parent,const QString &name)
  744. {
  745. QListViewItem *item=parent->firstChild();
  746. QListViewItem *startItem=item;
  747. QListViewItem *newItem;
  748. for (; item; item=item->nextSibling())
  749. {
  750. if (IS_FOLDER(item) && !item->text(0).compare(name))
  751. return item;
  752. }
  753. item=NULL;
  754. for (;startItem;startItem=item->nextSibling())
  755. item=startItem;
  756. newItem=item?new ListViewFolder(parent,item)
  757. :new ListViewFolder(parent);
  758. newItem->setText(0,name);
  759. newItem->setOpen(TRUE);
  760. return newItem;
  761. }
  762. void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *dir, const QString &open_file)
  763. {
  764. int i,e;
  765. int p,pslash;
  766. KURL tmp;
  767. TPRFileList *fileList=(TPRFileList*)fileListV;
  768. QString caption;
  769. QString treePath;
  770. QListViewItem *parent;
  771. e=fileList->path.count();
  772. if (e) category->setOpen(TRUE);
  773. for (i=0;i<e;i++)
  774. {
  775. tmp=*reinterpret_cast<const KURL *>(dir);
  776. kurlNewFileName(tmp,fileList->path[i]);
  777. caption=fileList->path[i];
  778. //fixed suffix truncation for file paths such as "/root/.dot/nodot" so it wouldn't truncate to "/root/"
  779. p=caption.findRev('.');
  780. pslash=caption.findRev('/');
  781. if (p>=0&&p>pslash) caption.truncate(p);
  782. if (pslash>=0) caption.remove(0,pslash+1);
  783. treePath=fileList->folder[i].stripWhiteSpace();
  784. //check for a backslash at the end and remove it if it's there.
  785. if (treePath[treePath.length()-1]=='\\')
  786. treePath.truncate(treePath.length()-1);
  787. parent=category;
  788. if (!treePath.isEmpty())
  789. {
  790. while ((p=treePath.find('\\'))>=0)
  791. {
  792. parent=createFolder(parent,treePath.left(p));
  793. treePath.remove(0,p+1);
  794. }
  795. parent=createFolder(parent,treePath);
  796. }
  797. ListViewFile *newFile=static_cast<ListViewFile *>(openFile(category,parent,caption,tmp.path()));
  798. if (!newFile) continue;
  799. if (!newFile->fileName.compare(open_file))
  800. fileTreeClicked(newFile);
  801. }
  802. }
  803. void MainForm::openProject(const QString &fileName)
  804. {
  805. TPRDataStruct TPRData;
  806. KURL dir;
  807. dir.setPath(fileName);
  808. if (getPathType(fileName)!=PATH_FILE) {
  809. KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
  810. return;
  811. }
  812. int ret=loadTPR(fileName, &TPRData);
  813. if (ret == -1) {
  814. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  815. return;
  816. }
  817. if (ret > 0) {
  818. KMessageBox::error(this,QString("Error at line %2 of \'%1\'").arg(fileName).arg(ret));
  819. return;
  820. }
  821. if (TPRData.asm_files.path.count() && !asmFilesListItem) {
  822. KMessageBox::error(this,"This project needs A68k, which is not installed.");
  823. return;
  824. }
  825. if (TPRData.quill_files.path.count() && !qllFilesListItem) {
  826. KMessageBox::error(this,"This project needs quill.drv, which is not installed.");
  827. return;
  828. }
  829. clearProject();
  830. fileOpen_addList(hFilesListItem,&TPRData.h_files,&dir,TPRData.open_file);
  831. fileOpen_addList(cFilesListItem,&TPRData.c_files,&dir,TPRData.open_file);
  832. fileOpen_addList(qllFilesListItem,&TPRData.quill_files,&dir,TPRData.open_file);
  833. fileOpen_addList(sFilesListItem,&TPRData.s_files,&dir,TPRData.open_file);
  834. fileOpen_addList(asmFilesListItem,&TPRData.asm_files,&dir,TPRData.open_file);
  835. fileOpen_addList(oFilesListItem,&TPRData.o_files,&dir,TPRData.open_file);
  836. fileOpen_addList(aFilesListItem,&TPRData.a_files,&dir,TPRData.open_file);
  837. fileOpen_addList(txtFilesListItem,&TPRData.txt_files,&dir,TPRData.open_file);
  838. fileOpen_addList(othFilesListItem,&TPRData.oth_files,&dir,TPRData.open_file);
  839. rootListItem->setText(0,TPRData.prj_name);
  840. projectFileName=fileName;
  841. settings=TPRData.settings;
  842. libopts=TPRData.libopts;
  843. updateLeftStatusLabel();
  844. updateRightStatusLabel();
  845. addRecent(fileName);
  846. }
  847. void MainForm::fileOpen()
  848. {
  849. if (savePrompt())
  850. return;
  851. QString fileName=SGetFileName(KFileDialog::Opening,findFilter(TIGCCOpenProjectFileFilter),"Open Project/File",this);
  852. KURL dir;
  853. dir.setPath(fileName);
  854. if (fileName.isEmpty())
  855. return;
  856. openProject(fileName);
  857. }
  858. void MainForm::fileRecent1()
  859. {
  860. if (savePrompt())
  861. return;
  862. openProject(fileRecent1Action->statusTip());
  863. }
  864. void MainForm::fileRecent2()
  865. {
  866. if (savePrompt())
  867. return;
  868. openProject(fileRecent2Action->statusTip());
  869. }
  870. void MainForm::fileRecent3()
  871. {
  872. if (savePrompt())
  873. return;
  874. openProject(fileRecent3Action->statusTip());
  875. }
  876. void MainForm::fileRecent4()
  877. {
  878. if (savePrompt())
  879. return;
  880. openProject(fileRecent4Action->statusTip());
  881. }
  882. int MainForm::fileSavePrompt(QListViewItem *fileItem)
  883. {
  884. int result;
  885. ListViewFile *theFile=static_cast<ListViewFile *>(fileItem);
  886. while (theFile->isDirty) { // "while" in case saving fails!
  887. 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());
  888. if (result==KMessageBox::Yes)
  889. fileSave_save(fileItem);
  890. else if (result==KMessageBox::No)
  891. theFile->isDirty=FALSE;
  892. else
  893. return 1;
  894. }
  895. return 0;
  896. }
  897. //returns 1 if the current project data should not be cleared out, 0 if it can be cleared out.
  898. int MainForm::savePrompt(void)
  899. {
  900. int result;
  901. while (projectIsDirty) {
  902. result=KMessageBox::questionYesNoCancel(this,"The current project has been modified. Do you want to save the changes?",QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
  903. if (result==KMessageBox::Yes)
  904. fileSave();
  905. else if (result==KMessageBox::No)
  906. projectIsDirty=FALSE;
  907. else
  908. return 1;
  909. }
  910. QListViewItem *item=rootListItem->firstChild(),*next;
  911. while (item)
  912. {
  913. if (IS_FOLDER(item))
  914. {
  915. next=item->firstChild();
  916. if (next)
  917. {
  918. item=next;
  919. continue;
  920. }
  921. }
  922. if (IS_FILE(item))
  923. {
  924. if (fileSavePrompt(item))
  925. return 1;
  926. }
  927. next=item->nextSibling();
  928. while (!next)
  929. {
  930. next=item->parent();
  931. if (next==rootListItem||!next)
  932. {
  933. return 0;
  934. }
  935. item=next;
  936. next=item->nextSibling();
  937. }
  938. item=next;
  939. }
  940. return 0;
  941. }
  942. void MainForm::fileSave_save(QListViewItem *theItem)
  943. {
  944. if (!IS_FILE(theItem))
  945. return;
  946. CATEGORY_OF(category,theItem);
  947. if (!IS_EDITABLE_CATEGORY(category))
  948. return;
  949. //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
  950. if (theItem==currentListItem)
  951. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  952. ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
  953. if (theFile->fileName[0]!='/') {
  954. fileSave_saveAs(theFile);
  955. }
  956. else {
  957. KDirWatch::self()->removeFile(theFile->fileName);
  958. if (saveFileText(theFile->fileName,theFile->textBuffer)) {
  959. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(theFile->text(0)));
  960. KDirWatch::self()->addFile(theFile->fileName);
  961. }
  962. else {
  963. KDirWatch::self()->addFile(theFile->fileName);
  964. theFile->isNew=FALSE;
  965. theFile->isDirty=FALSE;
  966. projectIsDirty=TRUE;
  967. }
  968. }
  969. }
  970. void MainForm::fileSave_saveAs(QListViewItem *theItem)
  971. {
  972. if (!IS_FILE(theItem))
  973. return;
  974. CATEGORY_OF(category,theItem);
  975. //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
  976. if (theItem==currentListItem && IS_EDITABLE_CATEGORY(category))
  977. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  978. QString saveFileName=SGetFileName(KFileDialog::Saving,
  979. category==hFilesListItem?TIGCC_H_Filter TIGCCAllFilter:
  980. category==cFilesListItem?TIGCC_C_Filter TIGCCAllFilter:
  981. category==sFilesListItem?TIGCC_S_Filter TIGCCAllFilter:
  982. category==asmFilesListItem?TIGCC_ASM_Filter TIGCCAllFilter:
  983. category==qllFilesListItem?TIGCC_QLL_Filter TIGCCAllFilter:
  984. category==oFilesListItem?TIGCC_O_Filter TIGCCAllFilter:
  985. category==aFilesListItem?TIGCC_A_Filter TIGCCAllFilter:
  986. category==txtFilesListItem?TIGCC_TXT_Filter TIGCCAllFilter:
  987. TIGCCAllFilter
  988. ,"Save Source File",this);
  989. ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
  990. if (saveFileName.isEmpty()
  991. || (!IS_EDITABLE_CATEGORY(category)
  992. && !saveFileName.compare(theFile->fileName)))
  993. return;
  994. if (theFile->fileName[0]=='/')
  995. KDirWatch::self()->removeFile(theFile->fileName);
  996. if (IS_EDITABLE_CATEGORY(category)
  997. ?saveFileText(saveFileName,theFile->textBuffer)
  998. :copyFile(theFile->fileName,saveFileName)) {
  999. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
  1000. if (theFile->fileName[0]=='/')
  1001. KDirWatch::self()->addFile(theFile->fileName);
  1002. } else {
  1003. theFile->fileName=saveFileName;
  1004. KDirWatch::self()->addFile(saveFileName);
  1005. theFile->isNew=FALSE;
  1006. theFile->isDirty=FALSE;
  1007. updateRightStatusLabel();
  1008. projectIsDirty=TRUE;
  1009. }
  1010. }
  1011. //loadList also saves the file contents
  1012. void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const QString &base_dir,void *dir_new,QString *open_file)
  1013. {
  1014. if (!category)
  1015. return;
  1016. TPRFileList *fileList=(TPRFileList*)fileListV;
  1017. KURL *new_dir=(KURL*)dir_new;
  1018. KURL tmpPath;
  1019. QListViewItem *item=category->firstChild();
  1020. QListViewItem *next;
  1021. QString folderSpec=QString::null;
  1022. int o;
  1023. while (item)
  1024. {
  1025. if (IS_FILE(item))
  1026. {
  1027. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  1028. QString absPath=theFile->fileName;
  1029. QString relPath=KURL::relativePath(base_dir,absPath);
  1030. if (relPath.find("./")==0)
  1031. {
  1032. relPath=relPath.mid(2);
  1033. }
  1034. else if (relPath.find("../")==0)
  1035. {
  1036. relPath=absPath;
  1037. }
  1038. tmpPath=*new_dir;
  1039. kurlNewFileName(tmpPath,relPath);
  1040. if (theFile->fileName[0]=='/')
  1041. KDirWatch::self()->removeFile(theFile->fileName);
  1042. if (tmpPath.path().compare(theFile->fileName)
  1043. || (IS_EDITABLE_CATEGORY(category)
  1044. && (theFile->isDirty || theFile->isNew))) {
  1045. if (IS_EDITABLE_CATEGORY(category)
  1046. ?saveFileText(tmpPath.path(),theFile->textBuffer)
  1047. :copyFile(theFile->fileName,tmpPath.path())) {
  1048. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(tmpPath.path()));
  1049. if (theFile->fileName[0]=='/')
  1050. KDirWatch::self()->addFile(theFile->fileName);
  1051. } else {
  1052. theFile->fileName=tmpPath.path();
  1053. KDirWatch::self()->addFile(theFile->fileName);
  1054. theFile->isNew=FALSE;
  1055. theFile->isDirty=FALSE;
  1056. projectIsDirty=TRUE; // in case saving the project fails
  1057. }
  1058. }
  1059. fileList->path << relPath;
  1060. fileList->folder << folderSpec;
  1061. if (item==currentListItem)
  1062. *open_file=theFile->fileName;
  1063. }
  1064. else if (IS_FOLDER(item))
  1065. {
  1066. next=item->firstChild();
  1067. if (next)
  1068. {
  1069. if (folderSpec.isEmpty())
  1070. folderSpec=item->text(0);
  1071. else
  1072. {
  1073. folderSpec+='\\';
  1074. folderSpec+=item->text(0);
  1075. }
  1076. item=next;
  1077. continue;
  1078. }
  1079. }
  1080. fsll_seeknext:
  1081. next=item->nextSibling();
  1082. if (!next)
  1083. {
  1084. next=item->parent();
  1085. if (next==category||!next)
  1086. break;
  1087. item=next;
  1088. o=folderSpec.findRev('\\');
  1089. if (o>=0)
  1090. folderSpec.truncate(o);
  1091. else
  1092. folderSpec.truncate(0);
  1093. goto fsll_seeknext;
  1094. }
  1095. item=next;
  1096. }
  1097. }
  1098. void MainForm::fileSave_fromto(const QString &lastProj,const QString &nextProj)
  1099. {
  1100. TPRDataStruct TPRData;
  1101. QString open_file;
  1102. KURL base_dir_k(lastProj);
  1103. base_dir_k.setFileName("");
  1104. QString base_dir=base_dir_k.path();
  1105. KURL new_dir(nextProj);
  1106. if (IS_FILE(currentListItem)) {
  1107. //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
  1108. CATEGORY_OF(category,currentListItem);
  1109. if (IS_EDITABLE_CATEGORY(category))
  1110. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  1111. }
  1112. fileSave_loadList(hFilesListItem,&TPRData.h_files,base_dir,&new_dir,&open_file);
  1113. fileSave_loadList(cFilesListItem,&TPRData.c_files,base_dir,&new_dir,&open_file);
  1114. fileSave_loadList(qllFilesListItem,&TPRData.quill_files,base_dir,&new_dir,&open_file);
  1115. fileSave_loadList(sFilesListItem,&TPRData.s_files,base_dir,&new_dir,&open_file);
  1116. fileSave_loadList(asmFilesListItem,&TPRData.asm_files,base_dir,&new_dir,&open_file);
  1117. fileSave_loadList(oFilesListItem,&TPRData.o_files,base_dir,&new_dir,&open_file);
  1118. fileSave_loadList(aFilesListItem,&TPRData.a_files,base_dir,&new_dir,&open_file);
  1119. fileSave_loadList(txtFilesListItem,&TPRData.txt_files,base_dir,&new_dir,&open_file);
  1120. fileSave_loadList(othFilesListItem,&TPRData.oth_files,base_dir,&new_dir,&open_file);
  1121. TPRData.prj_name=rootListItem->text(0);
  1122. TPRData.open_file=open_file;
  1123. TPRData.settings=settings;
  1124. TPRData.libopts=libopts;
  1125. if (saveTPR(nextProj,&TPRData))
  1126. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(nextProj));
  1127. else {
  1128. projectFileName=nextProj;
  1129. projectIsDirty=FALSE;
  1130. addRecent(nextProj);
  1131. }
  1132. updateRightStatusLabel();
  1133. }
  1134. void MainForm::fileSave()
  1135. {
  1136. if (projectFileName.isEmpty())
  1137. fileSaveAs();
  1138. else
  1139. fileSave_fromto(projectFileName,projectFileName);
  1140. }
  1141. void MainForm::fileSaveAs()
  1142. {
  1143. QString fileName=SGetFileName(KFileDialog::Saving,TIGCC_TPR_Filter TIGCCAllFilter,"Save Project",this);
  1144. if (fileName.isEmpty())
  1145. return;
  1146. fileSave_fromto(projectFileName,fileName);
  1147. }
  1148. void MainForm::filePrint()
  1149. {
  1150. m_view->getDoc()->printDialog();
  1151. }
  1152. void MainForm::filePrintQuickly()
  1153. {
  1154. m_view->getDoc()->print();
  1155. }
  1156. void MainForm::filePreferences()
  1157. {
  1158. }
  1159. void MainForm::editClear()
  1160. {
  1161. }
  1162. void MainForm::editUndo()
  1163. {
  1164. }
  1165. void MainForm::editRedo()
  1166. {
  1167. }
  1168. void MainForm::editCut()
  1169. {
  1170. }
  1171. void MainForm::editCopy()
  1172. {
  1173. }
  1174. void MainForm::editPaste()
  1175. {
  1176. }
  1177. void MainForm::editFind()
  1178. {
  1179. }
  1180. void MainForm::findFindSymbolDeclaration()
  1181. {
  1182. }
  1183. void MainForm::editSelectAll()
  1184. {
  1185. }
  1186. void MainForm::increaseIndent()
  1187. {
  1188. }
  1189. void MainForm::decreaseIndent()
  1190. {
  1191. }
  1192. void MainForm::editReplace()
  1193. {
  1194. }
  1195. void MainForm::findFunctions()
  1196. {
  1197. }
  1198. void MainForm::openFileAtCursor()
  1199. {
  1200. }
  1201. //returns 1 on success
  1202. int MainForm::projectAddFiles_oneFile(const QString &fileName)
  1203. {
  1204. QListViewItem *category=othFilesListItem;
  1205. QString suffix,caption;
  1206. int p;
  1207. p=fileName.findRev('/');
  1208. if (p<0) p=-1;
  1209. caption=fileName.mid(p+1);
  1210. p=caption.findRev('.');
  1211. if (p>=0) {
  1212. suffix=caption.mid(p+1);
  1213. caption.truncate(p);
  1214. }
  1215. if (!suffix.compare("h"))
  1216. category=hFilesListItem;
  1217. else if (!suffix.compare("c"))
  1218. category=cFilesListItem;
  1219. else if (!suffix.compare("s"))
  1220. category=sFilesListItem;
  1221. else if (!suffix.compare("asm"))
  1222. category=asmFilesListItem;
  1223. else if (!suffix.compare("qll"))
  1224. category=qllFilesListItem;
  1225. else if (!suffix.compare("o"))
  1226. category=oFilesListItem;
  1227. else if (!suffix.compare("a"))
  1228. category=aFilesListItem;
  1229. else if (!suffix.compare("txt"))
  1230. category=txtFilesListItem;
  1231. if (!category)
  1232. category=othFilesListItem;
  1233. if (openFile(category,category,caption,fileName))
  1234. return 1;
  1235. return 0;
  1236. }
  1237. void MainForm::projectAddFiles()
  1238. {
  1239. unsigned long i,e;
  1240. int projectChanged=0;
  1241. QStringList result=SGetFileName_Multiple(findFilter(TIGCCAddFilesFilter),"Add Files",this);
  1242. e=result.count();
  1243. for (i=0;i<e;i++) {
  1244. if (projectAddFiles_oneFile(result[i]))
  1245. projectChanged=TRUE;
  1246. }
  1247. if (projectChanged) {
  1248. projectIsDirty=TRUE;
  1249. }
  1250. }
  1251. void MainForm::projectCompile()
  1252. {
  1253. }
  1254. void MainForm::projectMake()
  1255. {
  1256. }
  1257. void MainForm::projectBuild()
  1258. {
  1259. }
  1260. void MainForm::errorsAndWarnings()
  1261. {
  1262. }
  1263. void MainForm::projectProgramOutput()
  1264. {
  1265. }
  1266. void MainForm::projectOptions()
  1267. {
  1268. }
  1269. void MainForm::debugRun()
  1270. {
  1271. }
  1272. void MainForm::debugPause()
  1273. {
  1274. }
  1275. void MainForm::debugReset()
  1276. {
  1277. }
  1278. void MainForm::toolsConfigure()
  1279. {
  1280. }
  1281. void MainForm::helpDocumentation()
  1282. {
  1283. assistant->openAssistant();
  1284. }
  1285. void MainForm::helpContents()
  1286. {
  1287. force_qt_assistant_page(0);
  1288. assistant->openAssistant();
  1289. }
  1290. void MainForm::helpIndex()
  1291. {
  1292. force_qt_assistant_page(1);
  1293. assistant->openAssistant();
  1294. }
  1295. void MainForm::helpSearch()
  1296. {
  1297. force_qt_assistant_page(3);
  1298. assistant->openAssistant();
  1299. }
  1300. void MainForm::helpNews()
  1301. {
  1302. }
  1303. void MainForm::helpAbout()
  1304. {
  1305. khelpmenu->aboutApplication();
  1306. }
  1307. void MainForm::updateSizes()
  1308. {
  1309. int leftSize=splitter->sizes().first();
  1310. int rightSize=splitter->sizes().last();
  1311. int totalSize=leftSize+rightSize;
  1312. int mySize=size().width();
  1313. leftStatusLabel->setMaximumWidth(leftSize*mySize/totalSize);
  1314. rightStatusLabel->setMaximumWidth(rightSize*mySize/totalSize-10>0?
  1315. rightSize*mySize/totalSize-10:0);
  1316. }
  1317. void MainForm::resizeEvent(QResizeEvent *event)
  1318. {
  1319. QMainWindow::resizeEvent(event);
  1320. if (event->size()==event->oldSize()) return;
  1321. updateSizes();
  1322. }
  1323. void MainForm::timerEvent(QTimerEvent *event)
  1324. {
  1325. static int lastSplitterPos=-1;
  1326. QMainWindow::timerEvent(event);
  1327. if (lastSplitterPos==splitter->sizes().first()) return;
  1328. lastSplitterPos=splitter->sizes().first();
  1329. updateSizes();
  1330. }
  1331. void MainForm::fileTreeClicked(QListViewItem *item)
  1332. {
  1333. if (!item) return;
  1334. if (IS_FOLDER(currentListItem))
  1335. currentListItem->setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  1336. if (IS_FILE(currentListItem)) {
  1337. if (currentListItemEditable) {
  1338. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  1339. m_view->cursorPositionReal(&(static_cast<ListViewFile *>(currentListItem)->cursorLine),
  1340. &(static_cast<ListViewFile *>(currentListItem)->cursorCol));
  1341. }
  1342. }
  1343. // Reset currentListItem so setting the text of the editor won't mark a
  1344. // file dirty.
  1345. currentListItem=NULL;
  1346. // This hack sets the file name for printing.
  1347. #define SETFILENAME(fn) m_view->getDoc()->setModified(FALSE); \
  1348. if (m_view->getDoc()->openStream("text/plain",(fn))) \
  1349. m_view->getDoc()->closeStream()
  1350. if (IS_FOLDER(item)) {
  1351. item->setPixmap(0,QPixmap::fromMimeSource("folder2.png"));
  1352. fileNewFolderAction->setEnabled(TRUE);
  1353. filePrintAction->setEnabled(FALSE);
  1354. filePrintQuicklyAction->setEnabled(FALSE);
  1355. m_view->setEnabled(FALSE);
  1356. SETFILENAME("");
  1357. m_view->getDoc()->setText("");
  1358. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1359. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1360. m_view->getDoc()->readConfig(&kconfig);
  1361. delete_temp_file("config.tmp");
  1362. m_view->getDoc()->setHlMode(0);
  1363. } else if (IS_FILE(item)) {
  1364. fileNewFolderAction->setEnabled(TRUE);
  1365. m_view->setEnabled(TRUE);
  1366. CATEGORY_OF(category,item->parent());
  1367. if (IS_EDITABLE_CATEGORY(category)) {
  1368. filePrintAction->setEnabled(TRUE);
  1369. filePrintQuicklyAction->setEnabled(TRUE);
  1370. SETFILENAME(static_cast<ListViewFile *>(item)->fileName);
  1371. m_view->getDoc()->setText(static_cast<ListViewFile *>(item)->textBuffer);
  1372. const char *buffer=static_cast<ListViewFile *>(item)->textBuffer;
  1373. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=kate - Normal\n",0);
  1374. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1375. m_view->getDoc()->readConfig(&kconfig);
  1376. delete_temp_file("config.tmp");
  1377. uint cnt=m_view->getDoc()->hlModeCount(), i;
  1378. for (i=0; i<cnt; i++) {
  1379. if (!m_view->getDoc()->hlModeName(i).compare(
  1380. ((category==sFilesListItem||(category==hFilesListItem&&buffer&&*buffer=='|'))?
  1381. "GNU Assembler 68k":
  1382. (category==asmFilesListItem||(category==hFilesListItem&&buffer&&*buffer==';'))?
  1383. "Motorola Assembler 68k":
  1384. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?
  1385. "C":
  1386. "None"))) break;
  1387. }
  1388. if (i==cnt) i=0;
  1389. m_view->getDoc()->setHlMode(i);
  1390. m_view->setCursorPositionReal(static_cast<ListViewFile *>(item)->cursorLine,
  1391. static_cast<ListViewFile *>(item)->cursorCol);
  1392. currentListItemEditable=TRUE;
  1393. } else {
  1394. filePrintAction->setEnabled(FALSE);
  1395. filePrintQuicklyAction->setEnabled(FALSE);
  1396. SETFILENAME("");
  1397. m_view->getDoc()->setText("");
  1398. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1399. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1400. m_view->getDoc()->readConfig(&kconfig);
  1401. delete_temp_file("config.tmp");
  1402. m_view->getDoc()->setHlMode(0);
  1403. currentListItemEditable=FALSE;
  1404. }
  1405. } else {
  1406. fileNewFolderAction->setEnabled(FALSE);
  1407. filePrintAction->setEnabled(FALSE);
  1408. filePrintQuicklyAction->setEnabled(FALSE);
  1409. m_view->setEnabled(FALSE);
  1410. SETFILENAME("");
  1411. m_view->getDoc()->setText("");
  1412. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1413. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1414. m_view->getDoc()->readConfig(&kconfig);
  1415. delete_temp_file("config.tmp");
  1416. m_view->getDoc()->setHlMode(0);
  1417. }
  1418. #undef SETFILENAME
  1419. currentListItem=item;
  1420. updateLeftStatusLabel();
  1421. updateRightStatusLabel();
  1422. }
  1423. void MainForm::fileNewFolder()
  1424. {
  1425. if (IS_FILE(currentListItem))
  1426. currentListItem=currentListItem->parent();
  1427. QListViewItem *item=NULL, *next=currentListItem->firstChild();
  1428. for (; next; next=item->nextSibling())
  1429. {
  1430. item=next;
  1431. }
  1432. QListViewItem *newFolder=item?new ListViewFolder(currentListItem,item)
  1433. :new ListViewFolder(currentListItem);
  1434. newFolder->setText(0,"NewFolder");
  1435. newFolder->setRenameEnabled(0,TRUE);
  1436. currentListItem->setOpen(TRUE);
  1437. fileTreeClicked(newFolder);
  1438. newFolder->startRename(0);
  1439. projectIsDirty=TRUE;
  1440. }
  1441. #define unused_col __attribute__((unused)) col /* stupid QT designer... */
  1442. void MainForm::fileTreeContextMenuRequested(QListViewItem *item,
  1443. const QPoint &pos,
  1444. int unused_col)
  1445. {
  1446. fileTreeClicked(item);
  1447. if (IS_FOLDER(item)) {
  1448. QPopupMenu menu;
  1449. menu.insertItem("New &Folder",0);
  1450. menu.insertItem("New F&ile",1);
  1451. CATEGORY_OF(category,item);
  1452. if (!IS_EDITABLE_CATEGORY(category))
  1453. menu.setItemEnabled(1,FALSE);
  1454. if (!IS_CATEGORY(item)) {
  1455. menu.insertSeparator();
  1456. menu.insertItem("&Remove",2);
  1457. menu.insertItem("Re&name",3);
  1458. }
  1459. switch (menu.exec(pos)) {
  1460. case 0:
  1461. fileNewFolder();
  1462. break;
  1463. case 1:
  1464. newFile(item);
  1465. break;
  1466. case 2:
  1467. delete item;
  1468. currentListItem=NULL;
  1469. fileTreeClicked(fileTree->currentItem());
  1470. projectIsDirty=TRUE;
  1471. break;
  1472. case 3:
  1473. item->startRename(0);
  1474. }
  1475. } else if (IS_FILE(item)) {
  1476. QPopupMenu menu;
  1477. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  1478. menu.insertItem("&Save",0);
  1479. CATEGORY_OF(category,item);
  1480. if (!IS_EDITABLE_CATEGORY(category))
  1481. menu.setItemEnabled(0,FALSE);
  1482. menu.insertItem("Save &As...",1);
  1483. menu.insertSeparator();
  1484. menu.insertItem("&Compile",2);
  1485. if (category==txtFilesListItem
  1486. || !IS_EDITABLE_CATEGORY(category))
  1487. menu.setItemEnabled(2,FALSE);
  1488. menu.insertSeparator();
  1489. menu.insertItem("&Remove",3);
  1490. menu.insertItem("&Delete",4);
  1491. if (theFile->isNew)
  1492. menu.setItemEnabled(4,FALSE);
  1493. menu.insertSeparator();
  1494. menu.insertItem("Re&name",5);
  1495. switch (menu.exec(pos)) {
  1496. case 0:
  1497. fileSave_save(item);
  1498. break;
  1499. case 1:
  1500. fileSave_saveAs(item);
  1501. break;
  1502. case 2:
  1503. // compiling not implemented yet!
  1504. break;
  1505. case 3:
  1506. if (!fileSavePrompt(item)) {
  1507. delete item;
  1508. currentListItem=NULL;
  1509. fileTreeClicked(fileTree->currentItem());
  1510. projectIsDirty=TRUE;
  1511. }
  1512. break;
  1513. case 4:
  1514. if (KMessageBox::questionYesNo(this,
  1515. "Are you sure you want to delete this source file? "
  1516. "You cannot undo this operation.","Confirm Deletion")
  1517. ==KMessageBox::Yes) {
  1518. QString fileName=theFile->fileName;
  1519. KDirWatch::self()->removeFile(fileName);
  1520. if (QDir().remove(fileName)) {
  1521. delete item;
  1522. currentListItem=NULL;
  1523. fileTreeClicked(fileTree->currentItem());
  1524. projectIsDirty=TRUE;
  1525. } else {
  1526. KMessageBox::error(this,
  1527. QString("Error deleting file \'%1\'").arg(fileName));
  1528. if (fileName[0]=='/')
  1529. KDirWatch::self()->addFile(fileName);
  1530. }
  1531. }
  1532. break;
  1533. case 5:
  1534. item->startRename(0);
  1535. }
  1536. }
  1537. }
  1538. QStringList MainForm::extractAllFileNames(void)
  1539. {
  1540. QListViewItem *item=rootListItem->firstChild(),*next;
  1541. QStringList allFiles;
  1542. while (item)
  1543. {
  1544. if (IS_FOLDER(item))
  1545. {
  1546. next=item->firstChild();
  1547. if (next)
  1548. {
  1549. item=next;
  1550. continue;
  1551. }
  1552. }
  1553. if (IS_FILE(item))
  1554. {
  1555. allFiles << (static_cast<ListViewFile *>(item)->fileName);
  1556. }
  1557. next=item->nextSibling();
  1558. while (!next)
  1559. {
  1560. next=item->parent();
  1561. if (next==rootListItem||!next)
  1562. {
  1563. return allFiles;
  1564. }
  1565. item=next;
  1566. next=item->nextSibling();
  1567. }
  1568. item=next;
  1569. }
  1570. return allFiles;
  1571. }
  1572. //you put in parent, and it gives you the rest, but you must have a place to put it all.
  1573. void MainForm::extractFileTreeInfo(QListViewItem *parent,QListViewItem **p_category,QString *p_folderPath)
  1574. {
  1575. QListViewItem *item,*next;
  1576. QString tmp=QString::null;
  1577. int o;
  1578. CATEGORY_OF(category,parent);
  1579. *p_category=category;
  1580. item=category->firstChild();
  1581. while (item)
  1582. {
  1583. if (item==parent)
  1584. {
  1585. if (!tmp.isEmpty())
  1586. tmp+='/';
  1587. tmp+=item->text(0);
  1588. *p_folderPath=tmp;
  1589. }
  1590. if (IS_FOLDER(item))
  1591. {
  1592. next=item->firstChild();
  1593. if (next)
  1594. {
  1595. if (tmp.isEmpty())
  1596. tmp=item->text(0);
  1597. else
  1598. {
  1599. tmp+='/';
  1600. tmp+=item->text(0);
  1601. }
  1602. item=next;
  1603. continue;
  1604. }
  1605. }
  1606. mfnf_seeknext:
  1607. next=item->nextSibling();
  1608. if (!next)
  1609. {
  1610. next=item->parent();
  1611. if (next==category||!next)
  1612. break;
  1613. item=next;
  1614. o=tmp.findRev('/');
  1615. if (o>=0)
  1616. tmp.truncate(o);
  1617. else
  1618. tmp.truncate(0);
  1619. goto mfnf_seeknext;
  1620. }
  1621. item=next;
  1622. }
  1623. }
  1624. void MainForm::newFile( QListViewItem *parent, QString text, const char *iconName )
  1625. {
  1626. QListViewItem *item=NULL, *next=parent->firstChild();
  1627. QString tmp,oldtmp,suffix,caption;
  1628. QStringList allFiles=extractAllFileNames();
  1629. QListViewItem *category;
  1630. KURL tmpK;
  1631. int tryNum;
  1632. for (; IS_FILE(next); next=item->nextSibling())
  1633. item=next;
  1634. extractFileTreeInfo(parent,&category,&tmp);
  1635. suffix="";
  1636. if (category==hFilesListItem)
  1637. suffix="h";
  1638. else if (category==cFilesListItem)
  1639. suffix="c";
  1640. else if (category==sFilesListItem)
  1641. suffix="s";
  1642. else if (category==asmFilesListItem)
  1643. suffix="asm";
  1644. else if (category==qllFilesListItem) {
  1645. if (qllFileCount) {
  1646. KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
  1647. return;
  1648. }
  1649. suffix="qll";
  1650. } else if (category==oFilesListItem)
  1651. suffix="o";
  1652. else if (category==aFilesListItem)
  1653. suffix="a";
  1654. else if (category==txtFilesListItem)
  1655. suffix="txt";
  1656. suffix='.'+suffix;
  1657. if (!tmp.isEmpty())
  1658. tmp+='/';
  1659. tmp+="New File";
  1660. tmpK.setPath(projectFileName);
  1661. kurlNewFileName(tmpK,tmp);
  1662. tmp=tmpK.path();
  1663. if (projectFileName.isEmpty())
  1664. {
  1665. short o=0;
  1666. if (tmp[0]=='.')
  1667. o=1;
  1668. if (tmp[o]=='/')
  1669. tmp=tmp.mid(o+1);
  1670. }
  1671. caption="New File";
  1672. oldtmp=tmp+' ';
  1673. tmp+=suffix;
  1674. tryNum=1;
  1675. while (!checkFileName(tmp,allFiles))
  1676. {
  1677. tryNum++;
  1678. tmp=oldtmp+QString("%1").arg(tryNum)+suffix;
  1679. caption="New File "+QString("%1").arg(tryNum);
  1680. }
  1681. ListViewFile *newFile=item?new ListViewFile(parent,item)
  1682. :new ListViewFile(parent);
  1683. newFile->fileName=tmp;
  1684. if (tmp[0]=='/')
  1685. KDirWatch::self()->addFile(tmp);
  1686. newFile->setText(0,caption);
  1687. newFile->setPixmap(0,QPixmap::fromMimeSource(iconName));
  1688. parent->setOpen(TRUE);
  1689. newFile->textBuffer=text;
  1690. fileTreeClicked(newFile);
  1691. projectIsDirty=TRUE;
  1692. newFile->startRename(0);
  1693. m_view->getDoc()->setText(text);
  1694. fileCount++;
  1695. COUNTER_FOR_CATEGORY(category)++;
  1696. updateLeftStatusLabel();
  1697. }
  1698. void MainForm::newFile( QListViewItem *parent )
  1699. {
  1700. CATEGORY_OF(category,parent);
  1701. newFile(parent,category==txtFilesListItem?"":
  1702. ((category==hFilesListItem?"// Header File\n//":
  1703. category==cFilesListItem?"// C Source File\n//":
  1704. category==sFilesListItem?"| Assembly Source File\n|":
  1705. category==asmFilesListItem?"; Assembly Source File\n;":
  1706. category==qllFilesListItem?"// Quill Source File\n//":"???\n")
  1707. +QString(" Created ")
  1708. +QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n"+
  1709. QString(category==cFilesListItem?(cFileCount?
  1710. "\n#include <tigcclib.h>\n":
  1711. "\n// Delete or comment out the items you do not need.\n"
  1712. "#define COMMENT_STRING \"Place your comment here.\"\n"
  1713. "#define COMMENT_PROGRAM_NAME "
  1714. "\"Place your program name here.\"\n"
  1715. "#define COMMENT_VERSION_STRING "
  1716. "\"Place your version string here.\"\n"
  1717. "#define COMMENT_VERSION_NUMBER 0,0,0,0 "
  1718. "/* major, minor, revision, subrevision */\n"
  1719. "#define COMMENT_AUTHORS "
  1720. "\"Place your author name(s) here.\"\n"
  1721. "#define COMMENT_BW_ICON \\\n"
  1722. "\t{0b0000000000000000, \\\n"
  1723. "\t 0b0000000000000000, \\\n"
  1724. "\t 0b0000000000000000, \\\n"
  1725. "\t 0b0000000000000000, \\\n"
  1726. "\t 0b0000000000000000, \\\n"
  1727. "\t 0b0000000000000000, \\\n"
  1728. "\t 0b0000000000000000, \\\n"
  1729. "\t 0b0000000000000000, \\\n"
  1730. "\t 0b0000000000000000, \\\n"
  1731. "\t 0b0000000000000000, \\\n"
  1732. "\t 0b0000000000000000, \\\n"
  1733. "\t 0b0000000000000000, \\\n"
  1734. "\t 0b0000000000000000, \\\n"
  1735. "\t 0b0000000000000000, \\\n"
  1736. "\t 0b0000000000000000, \\\n"
  1737. "\t 0b0000000000000000}\n"
  1738. "#define COMMENT_GRAY_ICON \\\n"
  1739. "\t{0b0000000000000000, \\\n"
  1740. "\t 0b0000000000000000, \\\n"
  1741. "\t 0b0000000000000000, \\\n"
  1742. "\t 0b0000000000000000, \\\n"
  1743. "\t 0b0000000000000000, \\\n"
  1744. "\t 0b0000000000000000, \\\n"
  1745. "\t 0b0000000000000000, \\\n"
  1746. "\t 0b0000000000000000, \\\n"
  1747. "\t 0b0000000000000000, \\\n"
  1748. "\t 0b0000000000000000, \\\n"
  1749. "\t 0b0000000000000000, \\\n"
  1750. "\t 0b0000000000000000, \\\n"
  1751. "\t 0b0000000000000000, \\\n"
  1752. "\t 0b0000000000000000, \\\n"
  1753. "\t 0b0000000000000000, \\\n"
  1754. "\t 0b0000000000000000}, \\\n"
  1755. "\t{0b0000000000000000, \\\n"
  1756. "\t 0b0000000000000000, \\\n"
  1757. "\t 0b0000000000000000, \\\n"
  1758. "\t 0b0000000000000000, \\\n"
  1759. "\t 0b0000000000000000, \\\n"
  1760. "\t 0b0000000000000000, \\\n"
  1761. "\t 0b0000000000000000, \\\n"
  1762. "\t 0b0000000000000000, \\\n"
  1763. "\t 0b0000000000000000, \\\n"
  1764. "\t 0b0000000000000000, \\\n"
  1765. "\t 0b0000000000000000, \\\n"
  1766. "\t 0b0000000000000000, \\\n"
  1767. "\t 0b0000000000000000, \\\n"
  1768. "\t 0b0000000000000000, \\\n"
  1769. "\t 0b0000000000000000, \\\n"
  1770. "\t 0b0000000000000000}\n\n#include <tigcclib.h>\n\n"
  1771. "// Main Function\nvoid _main(void)\n{\n"
  1772. "\t// Place your code here.\n}\n"):"")),
  1773. category==cFilesListItem||category==qllFilesListItem
  1774. ?"filec.png":
  1775. category==hFilesListItem?"fileh.png":
  1776. category==sFilesListItem||category==asmFilesListItem
  1777. ?"files.png":
  1778. category==txtFilesListItem?"filet.png":"filex.png");
  1779. }
  1780. QListViewItem *MainForm::resolveParent(QListViewItem *category)
  1781. {
  1782. QListViewItem *ret=currentListItem;
  1783. if (!IS_FILE(ret)&&!IS_FOLDER(ret))
  1784. return category;
  1785. if (IS_FILE(ret))
  1786. ret=ret->parent();
  1787. QListViewItem *actualCategory=ret;
  1788. while (IS_FOLDER(actualCategory->parent())) actualCategory=actualCategory->parent();
  1789. if (actualCategory!=category)
  1790. return category;
  1791. return ret;
  1792. }
  1793. void MainForm::fileNewCHeader()
  1794. {
  1795. newFile(resolveParent(hFilesListItem),"// Header File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1796. }
  1797. void MainForm::fileNewGNUAssemblyHeader()
  1798. {
  1799. newFile(resolveParent(hFilesListItem),"| Header File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1800. }
  1801. void MainForm::fileNewA68kAssemblyHeader()
  1802. {
  1803. newFile(resolveParent(hFilesListItem),"; Header File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1804. }
  1805. void MainForm::fileNewCSourceFile()
  1806. {
  1807. newFile(resolveParent(cFilesListItem),"// C Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  1808. }
  1809. void MainForm::fileNewGNUAssemblySourceFile()
  1810. {
  1811. newFile(resolveParent(sFilesListItem),"| Assembly Source File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  1812. }
  1813. void MainForm::fileNewA68kAssemblySourceFile()
  1814. {
  1815. newFile(resolveParent(asmFilesListItem),"; Assembly Source File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  1816. }
  1817. void MainForm::fileNewQuillSourceFile()
  1818. {
  1819. newFile(resolveParent(qllFilesListItem),"// Quill Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  1820. }
  1821. void MainForm::fileNewTextFile()
  1822. {
  1823. newFile(resolveParent(txtFilesListItem),"","filet.png");
  1824. }
  1825. void MainForm::updateLeftStatusLabel()
  1826. {
  1827. QString text=QString::number(fileCount)+QString(" File")
  1828. +QString(fileCount!=1?"s":"")+QString(" Total");
  1829. if (IS_FOLDER(currentListItem)||IS_FILE(currentListItem)) {
  1830. CATEGORY_OF(category,currentListItem);
  1831. text+=QString(", ")+QString::number(COUNTER_FOR_CATEGORY(category))
  1832. +QString(" in Category");
  1833. }
  1834. leftStatusLabel->setText(text);
  1835. }
  1836. void MainForm::statusBar_messageChanged(const QString & message)
  1837. {
  1838. if (message.isNull())
  1839. // Make sure no labels which should be hidden are shown.
  1840. updateRightStatusLabel();
  1841. }
  1842. void MainForm::updateRightStatusLabel()
  1843. {
  1844. int leftSize=splitter->sizes().first();
  1845. int rightSize=splitter->sizes().last();
  1846. int totalSize=leftSize+rightSize;
  1847. int mySize=size().width();
  1848. int rightStatusSize=rightSize*mySize/totalSize-10>0?
  1849. rightSize*mySize/totalSize-10:0;
  1850. if (currentListItem==rootListItem) {
  1851. rowStatusLabel->hide();
  1852. colStatusLabel->hide();
  1853. charsStatusLabel->hide();
  1854. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1855. rightStatusLabel->setText(projectFileName);
  1856. } else if (IS_FOLDER(currentListItem)) {
  1857. rowStatusLabel->hide();
  1858. colStatusLabel->hide();
  1859. charsStatusLabel->hide();
  1860. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1861. rightStatusLabel->setText("");
  1862. } else if (IS_FILE(currentListItem)) {
  1863. CATEGORY_OF(category,currentListItem);
  1864. if (IS_EDITABLE_CATEGORY(category)) {
  1865. unsigned int line, col;
  1866. m_view->cursorPositionReal(&line,&col);
  1867. rowStatusLabel->show();
  1868. rowStatusLabel->setMaximumWidth(30);
  1869. rowStatusLabel->setText(QString("%1").arg(line));
  1870. colStatusLabel->show();
  1871. colStatusLabel->setMaximumWidth(30);
  1872. colStatusLabel->setText(QString("%1").arg(col+1));
  1873. charsStatusLabel->show();
  1874. charsStatusLabel->setMaximumWidth(100);
  1875. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  1876. rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
  1877. } else {
  1878. rowStatusLabel->hide();
  1879. colStatusLabel->hide();
  1880. charsStatusLabel->hide();
  1881. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1882. }
  1883. rightStatusLabel->setText(static_cast<ListViewFile *>(currentListItem)->fileName);
  1884. }
  1885. }
  1886. void MainForm::m_view_cursorPositionChanged()
  1887. {
  1888. unsigned int line, col;
  1889. m_view->cursorPositionReal(&line,&col);
  1890. rowStatusLabel->setText(QString("%1").arg(line));
  1891. colStatusLabel->setText(QString("%1").arg(col+1));
  1892. }
  1893. void MainForm::m_view_textChanged()
  1894. {
  1895. if (IS_FILE(currentListItem))
  1896. static_cast<ListViewFile *>(currentListItem)->isDirty=TRUE;
  1897. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  1898. }
  1899. void MainForm::fileTreeItemRenamed( QListViewItem *item, int col, const QString &newName)
  1900. {
  1901. if (col)
  1902. return;
  1903. if (!IS_FILE(item))
  1904. return;
  1905. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  1906. QString suffix;
  1907. QString oldLabel;
  1908. QString &fileNameRef=theFile->fileName;
  1909. QString oldFileName=fileNameRef;
  1910. QString newFileName=fileNameRef;
  1911. int o,s;
  1912. o=oldFileName.findRev('.');
  1913. s=oldFileName.findRev('/');
  1914. if (o>=0&&(s<0||o>s)) {
  1915. suffix=oldFileName.mid(o+1);
  1916. newFileName.truncate(o);
  1917. } else {
  1918. suffix=QString::null;
  1919. }
  1920. if (s>=0) {
  1921. oldLabel=newFileName.mid(s+1);
  1922. newFileName.truncate(s+1);
  1923. } else {
  1924. oldLabel=newFileName;
  1925. newFileName.truncate(0);
  1926. }
  1927. if (!oldLabel.compare(newName))
  1928. return; //no changes are needed, and we don't want it to complain about the file conflicting with itself!
  1929. newFileName+=newName;
  1930. newFileName+='.';
  1931. newFileName+=suffix;
  1932. if (checkFileName(newFileName,extractAllFileNames())) {
  1933. if (oldFileName[0]=='/')
  1934. KDirWatch::self()->removeFile(oldFileName);
  1935. if (!theFile->isNew && !QDir().rename(oldFileName,newFileName)) {
  1936. KMessageBox::error(this,"Failed to rename the file.");
  1937. theFile->setText(0,oldLabel);
  1938. if (oldFileName[0]=='/')
  1939. KDirWatch::self()->addFile(oldFileName);
  1940. } else {
  1941. fileNameRef=newFileName;
  1942. if (newFileName[0]=='/')
  1943. KDirWatch::self()->addFile(newFileName);
  1944. projectIsDirty=TRUE;
  1945. }
  1946. } else {
  1947. KMessageBox::error(this,"The name you chose conflicts with that of another file.");
  1948. theFile->setText(0,oldLabel);
  1949. }
  1950. updateRightStatusLabel();
  1951. }
  1952. void MainForm::closeEvent(QCloseEvent *e)
  1953. {
  1954. if (savePrompt())
  1955. e->ignore();
  1956. else {
  1957. clearProject();
  1958. e->accept();
  1959. }
  1960. }
  1961. void MainForm::KDirWatch_dirty(const QString &fileName)
  1962. {
  1963. QListViewItem *item=rootListItem->firstChild(),*next;
  1964. QStringList allFiles;
  1965. while (item) {
  1966. if (IS_FOLDER(item)) {
  1967. next=item->firstChild();
  1968. if (next) {
  1969. item=next;
  1970. continue;
  1971. }
  1972. }
  1973. if (IS_FILE(item)) {
  1974. if (!fileName.compare(static_cast<ListViewFile *>(item)->fileName)) {
  1975. if (KMessageBox::questionYesNo(this,
  1976. QString("The file \'%1\' has been changed by another program. "
  1977. "Do you want to reload it?").arg(fileName),"File Changed")
  1978. ==KMessageBox::Yes) {
  1979. QString fileText=loadFileText(fileName);
  1980. if (fileText.isNull()) {
  1981. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  1982. return;
  1983. }
  1984. if (item==currentListItem)
  1985. m_view->getDoc()->setText(fileText);
  1986. else
  1987. static_cast<ListViewFile *>(item)->textBuffer=fileText;
  1988. }
  1989. return;
  1990. }
  1991. }
  1992. next=item->nextSibling();
  1993. while (!next) {
  1994. next=item->parent();
  1995. if (next==rootListItem||!next) {
  1996. puts("Warning: KDirWatch_dirty called for file not in project tree");
  1997. return;
  1998. }
  1999. item=next;
  2000. next=item->nextSibling();
  2001. }
  2002. item=next;
  2003. }
  2004. puts("Warning: KDirWatch_dirty called for file not in project tree");
  2005. return;
  2006. }
  2007. // Yes, this is an ugly hack... Any better suggestions?
  2008. #define QListView DnDListView