mainform.ui.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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-2005 Kevin Kofler
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2, or (at your option)
  14. any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software Foundation,
  21. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <qlabel.h>
  24. #include <qstatusbar.h>
  25. #include <qtimer.h>
  26. #include <qdatetime.h>
  27. #include <qdragobject.h>
  28. #include <qassistantclient.h>
  29. #include <kparts/factory.h>
  30. #include <klibloader.h>
  31. #include <kate/document.h>
  32. #include <kate/view.h>
  33. #include <kconfig.h>
  34. #include <ktexteditor/configinterfaceextension.h>
  35. #include <kaboutdata.h>
  36. #include <khelpmenu.h>
  37. #include <kfiledialog.h>
  38. #include <kurl.h>
  39. #include <cstdio>
  40. #include <cstdlib>
  41. #include "tpr.h"
  42. using std::puts;
  43. using std::exit;
  44. enum {TIGCCOpenProjectFileFilter=0,TIGCCSaveProjectFilter};
  45. static const char *TIGCCFileFilters[2]=
  46. {
  47. "*.tpr *.h *.c *.s *.asm *.txt|All TIGCC Files (*.tpr *.h *.c *.s *.asm *.txt)\n*.tpr|TIGCC Projects (*.tpr)\n*.h|Header Files (*.h)\n*.c|C Files (*.c)\n*.s|GNU Assembly Files (*.s)\n*.asm|A68k Assembly Files (*.asm)\nText Files (*.txt)\n*.*|All Files (*.*)",
  48. "*.tpr|TIGCC Projects (*.tpr)\n*.*|All Files (*.*)"
  49. };
  50. static const char *TIGCCProjectDirectory="/usr/local/tigcc/projects";
  51. static QString lastDirectory;
  52. extern const char *tigcc_base;
  53. extern const char *quill_drv;
  54. extern char tempdir[];
  55. extern void write_temp_file(const char *filename, const char *data, const size_t len);
  56. extern void delete_temp_file(const char *filename);
  57. extern void force_qt_assistant_page(int n);
  58. extern KAboutData *pabout;
  59. #define IS_CATEGORY(item) ((item) && ((item)==hFilesListItem \
  60. || (item)==cFilesListItem \
  61. || (item)==sFilesListItem \
  62. || (item)==asmFilesListItem \
  63. || (item)==qllFilesListItem \
  64. || (item)==oFilesListItem \
  65. || (item)==aFilesListItem \
  66. || (item)==txtFilesListItem \
  67. || (item)==othFilesListItem))
  68. #define IS_FOLDER(item) ((item) && (item)->rtti()==0x716CC0)
  69. #define IS_FILE(item) ((item) && (item)->rtti()==0x716CC1)
  70. // All the methods are inline because otherwise QT Designer will mistake them
  71. // for slots of the main form.
  72. class ListViewFolder : public QListViewItem {
  73. public:
  74. ListViewFolder(QListView *parent) : QListViewItem(parent)
  75. {
  76. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  77. setDragEnabled(TRUE);
  78. setDropEnabled(TRUE);
  79. }
  80. ListViewFolder(QListViewItem *parent) : QListViewItem(parent)
  81. {
  82. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  83. setDragEnabled(TRUE);
  84. setDropEnabled(TRUE);
  85. }
  86. ListViewFolder(QListView *parent, QListViewItem *after)
  87. : QListViewItem(parent, after)
  88. {
  89. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  90. setDropEnabled(TRUE);
  91. setDragEnabled(TRUE);
  92. }
  93. ListViewFolder(QListViewItem *parent, QListViewItem *after)
  94. : QListViewItem(parent, after)
  95. {
  96. setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  97. setDragEnabled(TRUE);
  98. setDropEnabled(TRUE);
  99. }
  100. virtual int rtti(void) const {return 0x716CC0;}
  101. protected:
  102. };
  103. class ListViewFile : public QListViewItem {
  104. public:
  105. ListViewFile(QListView *parent) : QListViewItem(parent),
  106. cursorLine(1), cursorCol(0)
  107. {
  108. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  109. setDragEnabled(TRUE);
  110. setDropEnabled(TRUE);
  111. setRenameEnabled(0,TRUE);
  112. }
  113. ListViewFile(QListViewItem *parent) : QListViewItem(parent),
  114. cursorLine(1), cursorCol(0)
  115. {
  116. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  117. setDragEnabled(TRUE);
  118. setDropEnabled(TRUE);
  119. setRenameEnabled(0,TRUE);
  120. }
  121. ListViewFile(QListView *parent, QListViewItem *after)
  122. : QListViewItem(parent, after), cursorLine(1), cursorCol(0)
  123. {
  124. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  125. setDropEnabled(TRUE);
  126. setDragEnabled(TRUE);
  127. setRenameEnabled(0,TRUE);
  128. }
  129. ListViewFile(QListViewItem *parent, QListViewItem *after)
  130. : QListViewItem(parent, after), cursorLine(1), cursorCol(0)
  131. {
  132. setPixmap(0,QPixmap::fromMimeSource("filex.png"));
  133. setDragEnabled(TRUE);
  134. setDropEnabled(TRUE);
  135. setRenameEnabled(0,TRUE);
  136. }
  137. virtual int rtti(void) const {return 0x716CC1;}
  138. QString textBuffer;
  139. unsigned int cursorLine, cursorCol;
  140. QString fileName; // full name of the file
  141. protected:
  142. };
  143. // These should be instance variables in clean C++, but QT Designer won't let me
  144. // touch the class definition, so this is all I can do. And there is only one
  145. // instance of MainForm anyway.
  146. static QListViewItem *rootListItem;
  147. static QListViewItem *hFilesListItem;
  148. static QListViewItem *cFilesListItem;
  149. static QListViewItem *sFilesListItem;
  150. static QListViewItem *asmFilesListItem;
  151. static QListViewItem *qllFilesListItem;
  152. static QListViewItem *oFilesListItem;
  153. static QListViewItem *aFilesListItem;
  154. static QListViewItem *txtFilesListItem;
  155. static QListViewItem *othFilesListItem;
  156. static QListViewItem *currentListItem;
  157. static QLabel *leftStatusLabel;
  158. static QLabel *rowStatusLabel;
  159. static QLabel *colStatusLabel;
  160. static QLabel *charsStatusLabel;
  161. static QLabel *rightStatusLabel;
  162. static Kate::View* m_view;
  163. static KHelpMenu *khelpmenu;
  164. static QPopupMenu *te_popup;
  165. static QAssistantClient *assistant;
  166. static int fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
  167. class DnDListView : public QListView {
  168. private:
  169. public:
  170. DnDListView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
  171. : QListView(parent,name,f) {}
  172. protected:
  173. virtual QDragObject *dragObject() {
  174. QListViewItem *currItem=selectedItem();
  175. if (currItem==rootListItem || currItem->parent()==rootListItem)
  176. return NULL;
  177. QStoredDrag *storedDrag=new QStoredDrag("x-ktigcc-dnd", this);
  178. static QByteArray data(sizeof(QListViewItem*));
  179. data.duplicate(reinterpret_cast<char *>(&currItem),
  180. sizeof(QListViewItem*));
  181. storedDrag->setEncodedData(data);
  182. return storedDrag;
  183. }
  184. virtual void dropEvent (QDropEvent *e) {
  185. if (e->source()==this && e->provides("x-ktigcc-dnd")) {
  186. QListViewItem *currItem;
  187. currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  188. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  189. // dropping folder
  190. // can only drop on folder or category
  191. QPoint vp=contentsToViewport(e->pos());
  192. QListViewItem *item=itemAt(vp);
  193. if (IS_FOLDER(item)) {
  194. // need same category
  195. QListViewItem *srcCategory=currItem;
  196. while (srcCategory->parent()->rtti()==0x716CC0) srcCategory=srcCategory->parent();
  197. QListViewItem *destCategory=item;
  198. while (destCategory->parent()->rtti()==0x716CC0) destCategory=destCategory->parent();
  199. if (srcCategory == destCategory) {
  200. // can't move folder into itself
  201. for (QListViewItem *destFolder=item; destFolder->rtti()==0x716CC0; destFolder=destFolder->parent()) {
  202. if (destFolder==currItem) goto ignore;
  203. }
  204. // move folder
  205. e->accept();
  206. currItem->parent()->takeItem(currItem);
  207. item->insertItem(currItem);
  208. } else {ignore: e->ignore();}
  209. } else e->ignore();
  210. } else if (IS_FILE(currItem)) {
  211. // dropping file
  212. QPoint vp=contentsToViewport(e->pos());
  213. QListViewItem *item=itemAt(vp);
  214. if (IS_FOLDER(item)) {
  215. // drop on folder
  216. // move file
  217. e->accept();
  218. currItem->parent()->takeItem(currItem);
  219. item->insertItem(currItem);
  220. } else if (IS_FILE(item)) {
  221. // drop on file
  222. // need same parent, but different items
  223. if (currItem->parent() == item->parent()
  224. && currItem != item) {
  225. // reorder files
  226. // figure out which one is the first
  227. for (QListViewItem *i=currItem->parent()->firstChild();i;
  228. i=i->nextSibling()) {
  229. if (i==currItem) {
  230. // currItem is first, move currItem after item
  231. e->accept();
  232. currItem->moveItem(item);
  233. break;
  234. } else if (i==item) {
  235. // item is first, move currItem before item
  236. e->accept();
  237. currItem->moveItem(item);
  238. item->moveItem(currItem);
  239. break;
  240. }
  241. }
  242. } else e->ignore();
  243. } else e->ignore();
  244. } else e->ignore();
  245. } else e->ignore();
  246. }
  247. virtual void dragEnterEvent (QDragEnterEvent *e) {
  248. if (e->source()==this&&(e->provides("x-ktigcc-dnd")))
  249. e->accept();
  250. }
  251. virtual void dragMoveEvent (QDragMoveEvent *e) {
  252. if (e->source()==this && e->provides("x-ktigcc-dnd")) {
  253. QListViewItem *currItem;
  254. currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
  255. if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
  256. // dropping folder
  257. // can only drop on folder or category
  258. QPoint vp=contentsToViewport(e->pos());
  259. QListViewItem *item=itemAt(vp);
  260. if (IS_FOLDER(item)) {
  261. // need same category
  262. QListViewItem *srcCategory=currItem;
  263. while (srcCategory->parent()->rtti()==0x716CC0) srcCategory=srcCategory->parent();
  264. QListViewItem *destCategory=item;
  265. while (destCategory->parent()->rtti()==0x716CC0) destCategory=destCategory->parent();
  266. if (srcCategory == destCategory) {
  267. // can't move folder into itself
  268. for (QListViewItem *destFolder=item; destFolder->rtti()==0x716CC0; destFolder=destFolder->parent()) {
  269. if (destFolder==currItem) goto ignore;
  270. }
  271. e->accept();
  272. } else {ignore: e->ignore();}
  273. } else e->ignore();
  274. } else if (IS_FILE(currItem)) {
  275. // dropping file
  276. QPoint vp=contentsToViewport(e->pos());
  277. QListViewItem *item=itemAt(vp);
  278. if (IS_FOLDER(item)) {
  279. // drop on folder
  280. e->accept();
  281. } else if (IS_FILE(item)) {
  282. // drop on file
  283. // need same parent, but different items
  284. if (currItem->parent() == item->parent()
  285. && currItem != item) e->accept(); else e->ignore();
  286. } else e->ignore();
  287. } else e->ignore();
  288. } else e->ignore();
  289. }
  290. };
  291. void MainForm::init()
  292. {
  293. fileNewFolderAction->setEnabled(FALSE);
  294. KParts::Factory* factory = (KParts::Factory *)
  295. KLibLoader::self()->factory ("libkatepart");
  296. if (!factory) exit(1);
  297. KTextEditor::Document *doc = (KTextEditor::Document *)
  298. factory->createPart( 0, "", this, "", "KTextEditor::Document" );
  299. m_view = (Kate::View *) doc->createView( splitter, 0L );
  300. m_view->setEnabled(FALSE);
  301. m_view->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding,0,0));
  302. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  303. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  304. m_view->getDoc()->readConfig(&kconfig);
  305. delete_temp_file("config.tmp");
  306. m_view->getDoc()->setHlMode(0);
  307. connect(m_view,SIGNAL(cursorPositionChanged()),this,SLOT(m_view_cursorPositionChanged()));
  308. connect(m_view->getDoc(),SIGNAL(textChanged()),this,SLOT(m_view_textChanged()));
  309. te_popup = new QPopupMenu(this);
  310. te_popup->insertItem("&Open file at cursor",0);
  311. te_popup->insertItem("&Find symbol declaration",1);
  312. te_popup->insertSeparator();
  313. te_popup->insertItem("&Undo",2);
  314. te_popup->insertItem("&Redo",3);
  315. te_popup->insertSeparator();
  316. te_popup->insertItem("&Clear",4);
  317. te_popup->insertItem("Cu&t",5);
  318. te_popup->insertItem("Cop&y",6);
  319. te_popup->insertItem("&Paste",7);
  320. te_popup->insertSeparator();
  321. te_popup->insertItem("&Select all",8);
  322. te_popup->insertSeparator();
  323. te_popup->insertItem("&Increase indent",9);
  324. te_popup->insertItem("&Decrease indent",10);
  325. m_view->installPopup(te_popup);
  326. connect(te_popup,SIGNAL(aboutToShow()),this,SLOT(te_popup_aboutToShow()));
  327. QValueList<int> list;
  328. list.append(150);
  329. list.append(500);
  330. splitter->setSizes(list);
  331. leftStatusLabel=new QLabel("0 Files Total",this);
  332. leftStatusLabel->setMaximumWidth(splitter->sizes().first());
  333. statusBar()->addWidget(leftStatusLabel,1);
  334. rowStatusLabel=new QLabel("",this);
  335. rowStatusLabel->setAlignment(Qt::AlignRight);
  336. statusBar()->addWidget(rowStatusLabel,1);
  337. rowStatusLabel->hide();
  338. colStatusLabel=new QLabel("",this);
  339. colStatusLabel->setAlignment(Qt::AlignRight);
  340. statusBar()->addWidget(colStatusLabel,1);
  341. colStatusLabel->hide();
  342. charsStatusLabel=new QLabel("",this);
  343. statusBar()->addWidget(charsStatusLabel,1);
  344. charsStatusLabel->hide();
  345. rightStatusLabel=new QLabel("",this);
  346. rightStatusLabel->setMaximumWidth(splitter->sizes().last());
  347. statusBar()->addWidget(rightStatusLabel,1);
  348. statusBar()->setSizeGripEnabled(FALSE);
  349. fileTree->setSorting(-1);
  350. fileTree->setColumnWidthMode(0,QListView::Maximum);
  351. fileTree->header()->hide();
  352. rootListItem=new QListViewItem(fileTree);
  353. rootListItem->setText(0,"Project1");
  354. rootListItem->setPixmap(0,QPixmap::fromMimeSource("tpr.png"));
  355. rootListItem->setOpen(TRUE);
  356. rootListItem->setDragEnabled(TRUE);
  357. QListViewItem *folderListItem=new ListViewFolder(rootListItem);
  358. hFilesListItem=folderListItem;
  359. folderListItem->setText(0,"Header Files");
  360. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  361. cFilesListItem=folderListItem;
  362. folderListItem->setText(0,"C Files");
  363. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  364. sFilesListItem=folderListItem;
  365. folderListItem->setText(0,"GNU Assembly Files");
  366. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  367. asmFilesListItem=folderListItem;
  368. folderListItem->setText(0,"A68k Assembly Files");
  369. if (quill_drv) {
  370. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  371. qllFilesListItem=folderListItem;
  372. folderListItem->setText(0,"Quill Files");
  373. } else {
  374. qllFilesListItem=NULL;
  375. fileNewQuillSourceFileAction->setVisible(FALSE);
  376. }
  377. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  378. oFilesListItem=folderListItem;
  379. folderListItem->setText(0,"Object Files");
  380. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  381. aFilesListItem=folderListItem;
  382. folderListItem->setText(0,"Archive Files");
  383. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  384. txtFilesListItem=folderListItem;
  385. folderListItem->setText(0,"Text Files");
  386. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  387. othFilesListItem=folderListItem;
  388. folderListItem->setText(0,"Other Files");
  389. khelpmenu=new KHelpMenu(this,pabout);
  390. assistant = new QAssistantClient("",this);
  391. QStringList args(QString("-profile"));
  392. args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
  393. assistant->setArguments(args);
  394. lastDirectory=TIGCCProjectDirectory;
  395. startTimer(100);
  396. }
  397. void MainForm::destroy()
  398. {
  399. Kate::Document *doc=m_view->getDoc();
  400. delete m_view;
  401. delete doc;
  402. delete te_popup;
  403. delete leftStatusLabel;
  404. delete rowStatusLabel;
  405. delete colStatusLabel;
  406. delete charsStatusLabel;
  407. delete rightStatusLabel;
  408. delete rootListItem;
  409. delete khelpmenu;
  410. delete assistant;
  411. }
  412. void MainForm::te_popup_aboutToShow()
  413. {
  414. te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
  415. te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
  416. te_popup->setItemEnabled(2,editUndoAction->isEnabled());
  417. te_popup->setItemEnabled(3,editRedoAction->isEnabled());
  418. te_popup->setItemEnabled(4,editClearAction->isEnabled());
  419. te_popup->setItemEnabled(5,editCutAction->isEnabled());
  420. te_popup->setItemEnabled(6,editCopyAction->isEnabled());
  421. te_popup->setItemEnabled(7,editPasteAction->isEnabled());
  422. te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
  423. te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
  424. te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
  425. }
  426. void MainForm::fileNewProject()
  427. {
  428. rootListItem->setText(0,"Project1");
  429. fileTreeClicked(rootListItem);
  430. QListViewItem *f, *next;
  431. for (f=hFilesListItem->firstChild();f;f=next) {
  432. next=f->nextSibling();
  433. delete f;
  434. }
  435. for (f=cFilesListItem->firstChild();f;f=next) {
  436. next=f->nextSibling();
  437. delete f;
  438. }
  439. for (f=sFilesListItem->firstChild();f;f=next) {
  440. next=f->nextSibling();
  441. delete f;
  442. }
  443. for (f=asmFilesListItem->firstChild();f;f=next) {
  444. next=f->nextSibling();
  445. delete f;
  446. }
  447. if (qllFilesListItem) {
  448. for (f=qllFilesListItem->firstChild();f;f=next) {
  449. next=f->nextSibling();
  450. delete f;
  451. }
  452. }
  453. for (f=oFilesListItem->firstChild();f;f=next) {
  454. next=f->nextSibling();
  455. delete f;
  456. }
  457. for (f=aFilesListItem->firstChild();f;f=next) {
  458. next=f->nextSibling();
  459. delete f;
  460. }
  461. for (f=txtFilesListItem->firstChild();f;f=next) {
  462. next=f->nextSibling();
  463. delete f;
  464. }
  465. for (f=othFilesListItem->firstChild();f;f=next) {
  466. next=f->nextSibling();
  467. delete f;
  468. }
  469. fileCount=cFileCount=hFileCount=sFileCount=asmFileCount=qllFileCount=oFileCount=aFileCount=txtFileCount=othFileCount=0;
  470. updateLeftStatusLabel();
  471. }
  472. QString MainForm::SGetFileName(int mode,short fileFilter,const QString &caption,QWidget *parent)
  473. {
  474. QString ret;
  475. if (static_cast<KFileDialog::OperationMode>(mode)==KFileDialog::Opening)
  476. ret=KFileDialog::getOpenFileName(lastDirectory,TIGCCFileFilters[fileFilter],parent,caption);
  477. else
  478. ret=KFileDialog::getSaveFileName(lastDirectory,TIGCCFileFilters[fileFilter],parent,caption);
  479. if (!ret.isNull())
  480. {
  481. KURL dir;
  482. dir.setPath(ret);
  483. dir.setFileName("");
  484. lastDirectory=dir.path();
  485. }
  486. return ret;
  487. }
  488. //no mode, since it you can't save multiple.
  489. QStringList MainForm::SGetFileName_Multiple(short fileFilter,const QString &caption,QWidget *parent)
  490. {
  491. QStringList ret;
  492. ret=KFileDialog::getOpenFileNames(lastDirectory,TIGCCFileFilters[fileFilter],parent,caption);
  493. if (!ret.empty())
  494. {
  495. KURL dir;
  496. dir.setPath(ret[0]);
  497. dir.setFileName("");
  498. lastDirectory=dir.path();
  499. }
  500. return ret;
  501. }
  502. void MainForm::fileOpen_addList(QListViewItem **parent,void *fileListV,void *dir)
  503. {
  504. int i,e;
  505. KURL tmp;
  506. TPRFileList *fileList=(TPRFileList*)fileListV;
  507. e=fileList->path.count();
  508. for (i=0;i<e;i++)
  509. {
  510. tmp=*reinterpret_cast<const KURL *>(dir);
  511. tmp.setFileName(fileList->path[i]);
  512. newFile(*parent,fileList->path[i],tmp.path(),loadFileText(tmp.path()),"fileh.png");
  513. /*eventually, there will be different file icons,
  514. but that's not in the way of functionality*/
  515. }
  516. }
  517. void MainForm::fileOpen()
  518. {
  519. QString fileName=SGetFileName(KFileDialog::Opening,TIGCCOpenProjectFileFilter,"Open Project/File",this);
  520. KURL dir;
  521. dir.setPath(fileName);
  522. if (!loadTPR(fileName))
  523. {
  524. fileOpen_addList(&hFilesListItem,&TPRData.h_files,&dir);
  525. fileOpen_addList(&cFilesListItem,&TPRData.c_files,&dir);
  526. fileOpen_addList(&cFilesListItem,&TPRData.quill_files,&dir); //Give quills the special behavior they need later on.
  527. fileOpen_addList(&sFilesListItem,&TPRData.s_files,&dir);
  528. fileOpen_addList(&asmFilesListItem,&TPRData.asm_files,&dir);
  529. fileOpen_addList(&oFilesListItem,&TPRData.o_files,&dir);
  530. fileOpen_addList(&aFilesListItem,&TPRData.a_files,&dir);
  531. fileOpen_addList(&txtFilesListItem,&TPRData.txt_files,&dir);
  532. fileOpen_addList(&othFilesListItem,&TPRData.oth_files,&dir);
  533. }
  534. }
  535. void MainForm::fileSave()
  536. {
  537. }
  538. void MainForm::fileSaveAs()
  539. {
  540. QString fileName=SGetFileName(KFileDialog::Saving,TIGCCSaveProjectFilter,"Save Project",this);
  541. }
  542. void MainForm::filePrint()
  543. {
  544. }
  545. void MainForm::editUndo()
  546. {
  547. }
  548. void MainForm::editRedo()
  549. {
  550. }
  551. void MainForm::editCut()
  552. {
  553. }
  554. void MainForm::editCopy()
  555. {
  556. }
  557. void MainForm::editPaste()
  558. {
  559. }
  560. void MainForm::editFind()
  561. {
  562. }
  563. void MainForm::findFindSymbolDeclaration()
  564. {
  565. }
  566. void MainForm::helpDocumentation()
  567. {
  568. assistant->openAssistant();
  569. }
  570. void MainForm::helpContents()
  571. {
  572. force_qt_assistant_page(0);
  573. assistant->openAssistant();
  574. }
  575. void MainForm::helpIndex()
  576. {
  577. force_qt_assistant_page(1);
  578. assistant->openAssistant();
  579. }
  580. void MainForm::helpSearch()
  581. {
  582. force_qt_assistant_page(3);
  583. assistant->openAssistant();
  584. }
  585. void MainForm::helpNews()
  586. {
  587. }
  588. void MainForm::helpAbout()
  589. {
  590. khelpmenu->aboutApplication();
  591. }
  592. void MainForm::updateSizes()
  593. {
  594. int leftSize=splitter->sizes().first();
  595. int rightSize=splitter->sizes().last();
  596. int totalSize=leftSize+rightSize;
  597. int mySize=size().width();
  598. leftStatusLabel->setMaximumWidth(leftSize*mySize/totalSize);
  599. rightStatusLabel->setMaximumWidth(rightSize*mySize/totalSize-10>0?
  600. rightSize*mySize/totalSize-10:0);
  601. }
  602. void MainForm::resizeEvent(QResizeEvent *event)
  603. {
  604. QMainWindow::resizeEvent(event);
  605. if (event->size()==event->oldSize()) return;
  606. updateSizes();
  607. }
  608. void MainForm::timerEvent(QTimerEvent *event)
  609. {
  610. static int lastSplitterPos=-1;
  611. QMainWindow::timerEvent(event);
  612. if (lastSplitterPos==splitter->sizes().first()) return;
  613. lastSplitterPos=splitter->sizes().first();
  614. updateSizes();
  615. }
  616. void MainForm::fileTreeClicked(QListViewItem *item)
  617. {
  618. if (!item) return;
  619. if (IS_FOLDER(currentListItem))
  620. currentListItem->setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  621. if (IS_FILE(currentListItem)) {
  622. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  623. m_view->cursorPositionReal(&(static_cast<ListViewFile *>(currentListItem)->cursorLine),
  624. &(static_cast<ListViewFile *>(currentListItem)->cursorCol));
  625. }
  626. if (IS_FOLDER(item)) {
  627. item->setPixmap(0,QPixmap::fromMimeSource("folder2.png"));
  628. fileNewFolderAction->setEnabled(TRUE);
  629. m_view->setEnabled(FALSE);
  630. m_view->getDoc()->setText("");
  631. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  632. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  633. m_view->getDoc()->readConfig(&kconfig);
  634. delete_temp_file("config.tmp");
  635. m_view->getDoc()->setHlMode(0);
  636. } else if (IS_FILE(item)) {
  637. fileNewFolderAction->setEnabled(TRUE);
  638. m_view->setEnabled(TRUE);
  639. m_view->getDoc()->setText(static_cast<ListViewFile *>(item)->textBuffer);
  640. QListViewItem *category=item->parent();
  641. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  642. const char *buffer=static_cast<ListViewFile *>(item)->textBuffer;
  643. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=kate - Normal\n",0);
  644. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  645. m_view->getDoc()->readConfig(&kconfig);
  646. delete_temp_file("config.tmp");
  647. uint cnt=m_view->getDoc()->hlModeCount(), i;
  648. for (i=0; i<cnt; i++) {
  649. if (!m_view->getDoc()->hlModeName(i).compare(
  650. ((category==sFilesListItem||(category==hFilesListItem&&buffer&&*buffer=='|'))?
  651. "GNU Assembler 68k":
  652. (category==asmFilesListItem||(category==hFilesListItem&&buffer&&*buffer==';'))?
  653. "Motorola Assembler 68k":
  654. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?
  655. "C":
  656. "None"))) break;
  657. }
  658. if (i==cnt) i=0;
  659. m_view->getDoc()->setHlMode(i);
  660. m_view->setCursorPositionReal(static_cast<ListViewFile *>(item)->cursorLine,
  661. static_cast<ListViewFile *>(item)->cursorCol);
  662. } else {
  663. fileNewFolderAction->setEnabled(FALSE);
  664. m_view->setEnabled(FALSE);
  665. m_view->getDoc()->setText("");
  666. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  667. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  668. m_view->getDoc()->readConfig(&kconfig);
  669. delete_temp_file("config.tmp");
  670. m_view->getDoc()->setHlMode(0);
  671. }
  672. currentListItem=item;
  673. updateLeftStatusLabel();
  674. updateRightStatusLabel();
  675. }
  676. void MainForm::fileNewFolder()
  677. {
  678. if (IS_FILE(currentListItem))
  679. currentListItem=currentListItem->parent();
  680. QListViewItem *item=NULL, *next=currentListItem->firstChild();
  681. for (; IS_FOLDER(next); next=item->nextSibling())
  682. item=next;
  683. QListViewItem *newFolder=item?new ListViewFolder(currentListItem,item)
  684. :new ListViewFolder(currentListItem);
  685. newFolder->setText(0,"NewFolder");
  686. newFolder->setRenameEnabled(0,TRUE);
  687. currentListItem->setOpen(TRUE);
  688. fileTreeClicked(newFolder);
  689. newFolder->startRename(0);
  690. }
  691. #define unused_col __attribute__((unused)) col /* stupid QT designer... */
  692. void MainForm::fileTreeContextMenuRequested(QListViewItem *item,
  693. const QPoint &pos,
  694. int unused_col)
  695. {
  696. fileTreeClicked(item);
  697. if (IS_FOLDER(item)) {
  698. QPopupMenu menu;
  699. menu.insertItem("New &Folder",0);
  700. menu.insertItem("New F&ile",1);
  701. QListViewItem *category=item;
  702. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  703. if (category==oFilesListItem || category==aFilesListItem
  704. || category==othFilesListItem) menu.setItemEnabled(1,FALSE);
  705. if (!IS_CATEGORY(item)) {
  706. menu.insertSeparator();
  707. menu.insertItem("&Remove",2);
  708. menu.insertItem("Re&name",3);
  709. }
  710. switch (menu.exec(pos)) {
  711. case 0:
  712. fileNewFolder();
  713. break;
  714. case 1:
  715. newFile(item);
  716. break;
  717. case 2:
  718. delete item;
  719. currentListItem=NULL;
  720. fileTreeClicked(fileTree->currentItem());
  721. break;
  722. case 3:
  723. item->startRename(0);
  724. }
  725. }
  726. }
  727. void MainForm::newFile( QListViewItem * parent, const QString &fileCaption, const QString &fileName,const QString &text, const char * iconName )
  728. {
  729. QListViewItem *item=NULL, *next=parent->firstChild();
  730. for (; next; next=item->nextSibling())
  731. item=next;
  732. ListViewFile *newFile=item?new ListViewFile(parent,item)
  733. :new ListViewFile(parent);
  734. newFile->setText(0,fileCaption);
  735. newFile->setPixmap(0,QPixmap::fromMimeSource(iconName));
  736. parent->setOpen(TRUE);
  737. newFile->textBuffer=text;
  738. newFile->fileName=fileName;
  739. fileTreeClicked(newFile);
  740. newFile->startRename(0);
  741. m_view->getDoc()->setText(text);
  742. fileCount++;
  743. QListViewItem *category=parent;
  744. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  745. (category==hFilesListItem?hFileCount:category==cFilesListItem?cFileCount:
  746. category==sFilesListItem?sFileCount:category==asmFilesListItem?asmFileCount:
  747. category==qllFilesListItem?qllFileCount:category==oFilesListItem?oFileCount:
  748. category==aFilesListItem?aFileCount:category==txtFilesListItem?txtFileCount:
  749. othFileCount)++;
  750. updateLeftStatusLabel();
  751. }
  752. void MainForm::newFile( QListViewItem *parent, QString text, const char *iconName )
  753. {
  754. newFile(parent,"New File",QString::null,text,iconName);
  755. }
  756. void MainForm::newFile( QListViewItem *parent )
  757. {
  758. QListViewItem *category=parent;
  759. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  760. newFile(parent,category==txtFilesListItem?"":
  761. ((category==hFilesListItem?"// Header File\n//":
  762. category==cFilesListItem?"// C Source File\n//":
  763. category==sFilesListItem?"| Assembly Source File\n|":
  764. category==asmFilesListItem?"; Assembly Source File\n;":
  765. category==qllFilesListItem?"// Quill Source File\n//":"???\n")
  766. +QString(" Created ")
  767. +QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n"+
  768. QString(category==cFilesListItem?(cFileCount?
  769. "\n#include <tigcclib.h>\n":
  770. "\n// Delete or comment out the items you do not need.\n"
  771. "#define COMMENT_STRING \"Place your comment here.\"\n"
  772. "#define COMMENT_PROGRAM_NAME "
  773. "\"Place your program name here.\"\n"
  774. "#define COMMENT_VERSION_STRING "
  775. "\"Place your version string here.\"\n"
  776. "#define COMMENT_VERSION_NUMBER 0,0,0,0 "
  777. "/* major, minor, revision, subrevision */\n"
  778. "#define COMMENT_AUTHORS "
  779. "\"Place your author name(s) here.\"\n"
  780. "#define COMMENT_BW_ICON \\\n"
  781. "\t{0b0000000000000000, \\\n"
  782. "\t 0b0000000000000000, \\\n"
  783. "\t 0b0000000000000000, \\\n"
  784. "\t 0b0000000000000000, \\\n"
  785. "\t 0b0000000000000000, \\\n"
  786. "\t 0b0000000000000000, \\\n"
  787. "\t 0b0000000000000000, \\\n"
  788. "\t 0b0000000000000000, \\\n"
  789. "\t 0b0000000000000000, \\\n"
  790. "\t 0b0000000000000000, \\\n"
  791. "\t 0b0000000000000000, \\\n"
  792. "\t 0b0000000000000000, \\\n"
  793. "\t 0b0000000000000000, \\\n"
  794. "\t 0b0000000000000000, \\\n"
  795. "\t 0b0000000000000000, \\\n"
  796. "\t 0b0000000000000000}\n"
  797. "#define COMMENT_GRAY_ICON \\\n"
  798. "\t{0b0000000000000000, \\\n"
  799. "\t 0b0000000000000000, \\\n"
  800. "\t 0b0000000000000000, \\\n"
  801. "\t 0b0000000000000000, \\\n"
  802. "\t 0b0000000000000000, \\\n"
  803. "\t 0b0000000000000000, \\\n"
  804. "\t 0b0000000000000000, \\\n"
  805. "\t 0b0000000000000000, \\\n"
  806. "\t 0b0000000000000000, \\\n"
  807. "\t 0b0000000000000000, \\\n"
  808. "\t 0b0000000000000000, \\\n"
  809. "\t 0b0000000000000000, \\\n"
  810. "\t 0b0000000000000000, \\\n"
  811. "\t 0b0000000000000000, \\\n"
  812. "\t 0b0000000000000000, \\\n"
  813. "\t 0b0000000000000000}, \\\n"
  814. "\t{0b0000000000000000, \\\n"
  815. "\t 0b0000000000000000, \\\n"
  816. "\t 0b0000000000000000, \\\n"
  817. "\t 0b0000000000000000, \\\n"
  818. "\t 0b0000000000000000, \\\n"
  819. "\t 0b0000000000000000, \\\n"
  820. "\t 0b0000000000000000, \\\n"
  821. "\t 0b0000000000000000, \\\n"
  822. "\t 0b0000000000000000, \\\n"
  823. "\t 0b0000000000000000, \\\n"
  824. "\t 0b0000000000000000, \\\n"
  825. "\t 0b0000000000000000, \\\n"
  826. "\t 0b0000000000000000, \\\n"
  827. "\t 0b0000000000000000, \\\n"
  828. "\t 0b0000000000000000, \\\n"
  829. "\t 0b0000000000000000}\n\n#include <tigcclib.h>\n\n"
  830. "// Main Function\nvoid _main(void)\n{\n"
  831. "\t// Place your code here.\n}\n"):"")),
  832. category==cFilesListItem||category==qllFilesListItem
  833. ?"filec.png":
  834. category==hFilesListItem?"fileh.png":
  835. category==sFilesListItem||category==asmFilesListItem
  836. ?"files.png":
  837. category==txtFilesListItem?"filet.png":"filex.png");
  838. }
  839. void MainForm::fileNewCHeader()
  840. {
  841. newFile(hFilesListItem,"// Header File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  842. }
  843. void MainForm::fileNewGNUAssemblyHeader()
  844. {
  845. newFile(hFilesListItem,"| Header File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  846. }
  847. void MainForm::fileNewA68kAssemblyHeader()
  848. {
  849. newFile(hFilesListItem,"; Header File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  850. }
  851. void MainForm::fileNewCSourceFile()
  852. {
  853. newFile(cFilesListItem,"// C Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  854. }
  855. void MainForm::fileNewGNUAssemblySourceFile()
  856. {
  857. newFile(sFilesListItem,"| Assembly Source File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  858. }
  859. void MainForm::fileNewA68kAssemblySourceFile()
  860. {
  861. newFile(asmFilesListItem,"; Assembly Source File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  862. }
  863. void MainForm::fileNewQuillSourceFile()
  864. {
  865. newFile(qllFilesListItem,"// Quill Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  866. }
  867. void MainForm::fileNewTextFile()
  868. {
  869. newFile(txtFilesListItem,"","filet.png");
  870. }
  871. void MainForm::updateLeftStatusLabel()
  872. {
  873. QString text=QString::number(fileCount)+QString(" File")
  874. +QString(fileCount!=1?"s":"")+QString(" Total");
  875. QListViewItem *category=currentListItem;
  876. if (IS_FOLDER(currentListItem)||IS_FILE(currentListItem)) {
  877. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  878. text+=QString(", ")+QString::number(category==hFilesListItem?hFileCount:
  879. category==cFilesListItem?cFileCount:
  880. category==sFilesListItem?sFileCount:
  881. category==asmFilesListItem?asmFileCount:
  882. category==qllFilesListItem?qllFileCount:
  883. category==oFilesListItem?oFileCount:
  884. category==aFilesListItem?aFileCount:
  885. category==txtFilesListItem?txtFileCount:
  886. othFileCount)
  887. +QString(" in Category");
  888. }
  889. leftStatusLabel->setText(text);
  890. }
  891. void MainForm::updateRightStatusLabel()
  892. {
  893. int leftSize=splitter->sizes().first();
  894. int rightSize=splitter->sizes().last();
  895. int totalSize=leftSize+rightSize;
  896. int mySize=size().width();
  897. int rightStatusSize=rightSize*mySize/totalSize-10>0?
  898. rightSize*mySize/totalSize-10:0;
  899. if (currentListItem==rootListItem) {
  900. rowStatusLabel->hide();
  901. colStatusLabel->hide();
  902. charsStatusLabel->hide();
  903. rightStatusLabel->setMaximumWidth(rightStatusSize);
  904. rightStatusLabel->setText("project file name");
  905. } else if (IS_FOLDER(currentListItem)) {
  906. rowStatusLabel->hide();
  907. colStatusLabel->hide();
  908. charsStatusLabel->hide();
  909. rightStatusLabel->setMaximumWidth(rightStatusSize);
  910. rightStatusLabel->setText("");
  911. } else if (IS_FILE(currentListItem)) {
  912. QListViewItem *category=currentListItem;
  913. while (category->parent()->rtti()==0x716CC0) category=category->parent();
  914. if (category==hFilesListItem||category==cFilesListItem
  915. ||category==sFilesListItem||category==asmFilesListItem
  916. ||category==qllFilesListItem||category==txtFilesListItem) {
  917. unsigned int line, col;
  918. m_view->cursorPositionReal(&line,&col);
  919. rowStatusLabel->show();
  920. rowStatusLabel->setMaximumWidth(30);
  921. rowStatusLabel->setText(QString("%1").arg(line));
  922. colStatusLabel->show();
  923. colStatusLabel->setMaximumWidth(30);
  924. colStatusLabel->setText(QString("%1").arg(col+1));
  925. charsStatusLabel->show();
  926. charsStatusLabel->setMaximumWidth(100);
  927. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  928. rightStatusLabel->setMaximumWidth(rightStatusSize-160);
  929. } else {
  930. rowStatusLabel->hide();
  931. colStatusLabel->hide();
  932. charsStatusLabel->hide();
  933. rightStatusLabel->setMaximumWidth(rightStatusSize);
  934. }
  935. rightStatusLabel->setText(static_cast<ListViewFile *>(currentListItem)->fileName);
  936. }
  937. }
  938. void MainForm::m_view_cursorPositionChanged()
  939. {
  940. unsigned int line, col;
  941. m_view->cursorPositionReal(&line,&col);
  942. rowStatusLabel->setText(QString("%1").arg(line));
  943. colStatusLabel->setText(QString("%1").arg(col+1));
  944. }
  945. void MainForm::m_view_textChanged()
  946. {
  947. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  948. }
  949. // Yes, this is an ugly hack... Any better suggestions?
  950. #define QListView DnDListView