mainform.ui.h 49 KB

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