mainform.ui.h 62 KB

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