mainform.ui.h 52 KB

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