mainform.ui.h 62 KB

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