mainform.ui.h 66 KB

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