mainform.ui.h 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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. fileTree->setSorting(-1);
  414. fileTree->setColumnWidthMode(0,QListView::Maximum);
  415. fileTree->header()->hide();
  416. rootListItem=new QListViewItem(fileTree);
  417. rootListItem->setText(0,"Project1");
  418. rootListItem->setPixmap(0,QPixmap::fromMimeSource("tpr.png"));
  419. rootListItem->setOpen(TRUE);
  420. rootListItem->setDragEnabled(TRUE);
  421. QListViewItem *folderListItem=new ListViewFolder(rootListItem);
  422. hFilesListItem=folderListItem;
  423. folderListItem->setText(0,"Header Files");
  424. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  425. cFilesListItem=folderListItem;
  426. folderListItem->setText(0,"C Files");
  427. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  428. sFilesListItem=folderListItem;
  429. folderListItem->setText(0,"GNU Assembly Files");
  430. char a68k_path[strlen(tigcc_base)+10];
  431. sprintf(a68k_path, "%s/bin/a68k", tigcc_base);
  432. if(access(a68k_path, F_OK) != -1) {
  433. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  434. asmFilesListItem=folderListItem;
  435. folderListItem->setText(0,"A68k Assembly Files");
  436. } else {
  437. qllFilesListItem=NULL;
  438. fileNewQuillSourceFileAction->setVisible(FALSE);
  439. }
  440. if (quill_drv) {
  441. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  442. qllFilesListItem=folderListItem;
  443. folderListItem->setText(0,"Quill Files");
  444. } else {
  445. qllFilesListItem=NULL;
  446. fileNewQuillSourceFileAction->setVisible(FALSE);
  447. }
  448. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  449. oFilesListItem=folderListItem;
  450. folderListItem->setText(0,"Object Files");
  451. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  452. aFilesListItem=folderListItem;
  453. folderListItem->setText(0,"Archive Files");
  454. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  455. txtFilesListItem=folderListItem;
  456. folderListItem->setText(0,"Text Files");
  457. folderListItem=new ListViewFolder(rootListItem,folderListItem);
  458. othFilesListItem=folderListItem;
  459. folderListItem->setText(0,"Other Files");
  460. khelpmenu=new KHelpMenu(this,pabout);
  461. assistant = new QAssistantClient("",this);
  462. QStringList args(QString("-profile"));
  463. args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
  464. assistant->setArguments(args);
  465. lastDirectory=TIGCCProjectDirectory;
  466. projectFileName="";
  467. projectIsDirty=FALSE;
  468. pconfig->setGroup("Recent files");
  469. if (parg)
  470. openProject(parg);
  471. else {
  472. QString mostrecent=pconfig->readEntry("Current project");
  473. if (!mostrecent.isNull() && !mostrecent.isEmpty())
  474. openProject(mostrecent);
  475. }
  476. updateRecent();
  477. startTimer(100);
  478. }
  479. void MainForm::destroy()
  480. {
  481. Kate::Document *doc=m_view->getDoc();
  482. delete m_view;
  483. delete doc;
  484. delete te_popup;
  485. delete leftStatusLabel;
  486. delete rowStatusLabel;
  487. delete colStatusLabel;
  488. delete charsStatusLabel;
  489. delete rightStatusLabel;
  490. delete rootListItem;
  491. delete khelpmenu;
  492. delete assistant;
  493. }
  494. void MainForm::te_popup_aboutToShow()
  495. {
  496. te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
  497. te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
  498. te_popup->setItemEnabled(2,editUndoAction->isEnabled());
  499. te_popup->setItemEnabled(3,editRedoAction->isEnabled());
  500. te_popup->setItemEnabled(4,editClearAction->isEnabled());
  501. te_popup->setItemEnabled(5,editCutAction->isEnabled());
  502. te_popup->setItemEnabled(6,editCopyAction->isEnabled());
  503. te_popup->setItemEnabled(7,editPasteAction->isEnabled());
  504. te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
  505. te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
  506. te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
  507. }
  508. void MainForm::clearProject()
  509. {
  510. rootListItem->setText(0,"Project1");
  511. projectFileName="";
  512. fileTreeClicked(rootListItem);
  513. QListViewItem *f, *next;
  514. for (f=hFilesListItem->firstChild();f;f=next) {
  515. next=f->nextSibling();
  516. delete f;
  517. }
  518. for (f=cFilesListItem->firstChild();f;f=next) {
  519. next=f->nextSibling();
  520. delete f;
  521. }
  522. for (f=sFilesListItem->firstChild();f;f=next) {
  523. next=f->nextSibling();
  524. delete f;
  525. }
  526. if (asmFilesListItem) {
  527. for (f=asmFilesListItem->firstChild();f;f=next) {
  528. next=f->nextSibling();
  529. delete f;
  530. }
  531. }
  532. if (qllFilesListItem) {
  533. for (f=qllFilesListItem->firstChild();f;f=next) {
  534. next=f->nextSibling();
  535. delete f;
  536. }
  537. }
  538. for (f=oFilesListItem->firstChild();f;f=next) {
  539. next=f->nextSibling();
  540. delete f;
  541. }
  542. for (f=aFilesListItem->firstChild();f;f=next) {
  543. next=f->nextSibling();
  544. delete f;
  545. }
  546. for (f=txtFilesListItem->firstChild();f;f=next) {
  547. next=f->nextSibling();
  548. delete f;
  549. }
  550. for (f=othFilesListItem->firstChild();f;f=next) {
  551. next=f->nextSibling();
  552. delete f;
  553. }
  554. fileCount=cFileCount=hFileCount=sFileCount=asmFileCount=qllFileCount=oFileCount=aFileCount=txtFileCount=othFileCount=0;
  555. projectIsDirty=FALSE;
  556. updateLeftStatusLabel();
  557. }
  558. void MainForm::fileNewProject()
  559. {
  560. clearProject();
  561. pconfig->setGroup("Recent files");
  562. pconfig->writeEntry("Current project","");
  563. }
  564. QString MainForm::findFilter(unsigned short job)
  565. {
  566. QString ret;
  567. if (job==TIGCCOpenProjectFileFilter)
  568. {
  569. ret="*.tpr *.h *.c *.s ";
  570. if (asmFilesListItem)
  571. ret+="*.asm ";
  572. if (qllFilesListItem)
  573. ret+="*.qll ";
  574. ret+="*.txt";
  575. ret+="|All TIGCC Files ("+ret+")\n"
  576. TIGCC_TPR_Filter TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  577. if (asmFilesListItem)
  578. ret+=TIGCC_ASM_Filter;
  579. if (qllFilesListItem)
  580. ret+=TIGCC_QLL_Filter;
  581. ret+=TIGCC_TXT_Filter TIGCCAllFilter;
  582. }
  583. else if (job==TIGCCAddFilesFilter)
  584. {
  585. ret="*.h *.c *.s ";
  586. if (asmFilesListItem)
  587. ret+="*.asm ";
  588. if (qllFilesListItem)
  589. ret+="*.qll ";
  590. ret+="*.o *.a *.txt";
  591. ret+="|All TIGCC Files ("+ret+")\n"
  592. TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
  593. if (asmFilesListItem)
  594. ret+=TIGCC_ASM_Filter;
  595. if (qllFilesListItem)
  596. ret+=TIGCC_QLL_Filter;
  597. ret+=TIGCC_O_Filter TIGCC_A_Filter TIGCC_TXT_Filter TIGCCAllFilter;
  598. }
  599. return ret;
  600. }
  601. QString MainForm::SGetFileName(int mode,const QString &fileFilter,const QString &caption,QWidget *parent)
  602. {
  603. QString ret;
  604. if (static_cast<KFileDialog::OperationMode>(mode)==KFileDialog::Opening)
  605. ret=KFileDialog::getOpenFileName(lastDirectory,fileFilter,parent,caption);
  606. else
  607. ret=KFileDialog::getSaveFileName(lastDirectory,fileFilter,parent,caption);
  608. if (!ret.isNull())
  609. {
  610. KURL dir;
  611. dir.setPath(ret);
  612. dir.setFileName("");
  613. lastDirectory=dir.path();
  614. }
  615. return ret;
  616. }
  617. //no mode, since it you can't save multiple.
  618. QStringList MainForm::SGetFileName_Multiple(const QString &fileFilter,const QString &caption,QWidget *parent)
  619. {
  620. QStringList ret;
  621. ret=KFileDialog::getOpenFileNames(lastDirectory,fileFilter,parent,caption);
  622. if (!ret.empty())
  623. {
  624. KURL dir;
  625. dir.setPath(ret[0]);
  626. dir.setFileName("");
  627. lastDirectory=dir.path();
  628. }
  629. return ret;
  630. }
  631. void MainForm::updateRecent()
  632. {
  633. pconfig->setGroup("Recent files");
  634. QString recent=pconfig->readEntry("Recent file 1");
  635. if (recent.isNull())
  636. fileRecent1Action->setVisible(FALSE);
  637. else {
  638. QString recentcut=recent.mid(recent.findRev('/')+1);
  639. recentcut.truncate(recentcut.findRev('.'));
  640. fileRecent1Action->setVisible(TRUE);
  641. fileRecent1Action->setText(recentcut);
  642. fileRecent1Action->setStatusTip(recent);
  643. }
  644. recent=pconfig->readEntry("Recent file 2");
  645. if (recent.isNull())
  646. fileRecent2Action->setVisible(FALSE);
  647. else {
  648. QString recentcut=recent.mid(recent.findRev('/')+1);
  649. recentcut.truncate(recentcut.findRev('.'));
  650. fileRecent2Action->setVisible(TRUE);
  651. fileRecent2Action->setText(recentcut);
  652. fileRecent2Action->setStatusTip(recent);
  653. }
  654. recent=pconfig->readEntry("Recent file 3");
  655. if (recent.isNull())
  656. fileRecent3Action->setVisible(FALSE);
  657. else {
  658. QString recentcut=recent.mid(recent.findRev('/')+1);
  659. recentcut.truncate(recentcut.findRev('.'));
  660. fileRecent3Action->setVisible(TRUE);
  661. fileRecent3Action->setText(recentcut);
  662. fileRecent3Action->setStatusTip(recent);
  663. }
  664. recent=pconfig->readEntry("Recent file 4");
  665. if (recent.isNull())
  666. fileRecent4Action->setVisible(FALSE);
  667. else {
  668. QString recentcut=recent.mid(recent.findRev('/')+1);
  669. recentcut.truncate(recentcut.findRev('.'));
  670. fileRecent4Action->setVisible(TRUE);
  671. fileRecent4Action->setText(recentcut);
  672. fileRecent4Action->setStatusTip(recent);
  673. }
  674. }
  675. void MainForm::addRecent(const QString &fileName)
  676. {
  677. unsigned i,j;
  678. pconfig->setGroup("Recent files");
  679. // Find recent file to overwrite. If it isn't one of the first 3, by
  680. // elimination, it is the last, thus the test only goes up to <4, not <=4.
  681. for (i=1;i<4;i++) {
  682. QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
  683. if (recenti.isNull() || !recenti.compare(fileName))
  684. break;
  685. }
  686. // Move entries up
  687. for (j=i;j>1;j--) {
  688. pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
  689. }
  690. // The first recent file is the current project.
  691. pconfig->writeEntry("Recent file 1",fileName);
  692. pconfig->writeEntry("Current project",fileName);
  693. updateRecent();
  694. }
  695. QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
  696. {
  697. QListViewItem *item=NULL, *next=parent->firstChild();
  698. for (; IS_FILE(next); next=item->nextSibling())
  699. item=next;
  700. ListViewFile *newFile=item?new ListViewFile(parent,item)
  701. :new ListViewFile(parent);
  702. newFile->isNew=FALSE;
  703. newFile->setText(0,fileCaption);
  704. newFile->setPixmap(0,QPixmap::fromMimeSource(
  705. category==cFilesListItem||category==qllFilesListItem?"filec.png":
  706. category==hFilesListItem?"fileh.png":
  707. category==sFilesListItem||category==asmFilesListItem?"files.png":
  708. category==txtFilesListItem?"filet.png":"filex.png"));
  709. if (IS_EDITABLE_CATEGORY(category)) {
  710. QString fileText=loadFileText(fileName);
  711. if (fileText.isNull()) {
  712. KMessageBox::sorry(this,QString("Can't open \'%1\'").arg(fileName),"Warning");
  713. fileText="";
  714. }
  715. newFile->textBuffer=fileText;
  716. }
  717. newFile->fileName=fileName;
  718. fileCount++;
  719. COUNTER_FOR_CATEGORY(category)++;
  720. return newFile;
  721. }
  722. QListViewItem *MainForm::createFolder(QListViewItem *parent,const QString &name)
  723. {
  724. QListViewItem *item=parent->firstChild();
  725. QListViewItem *startItem=item;
  726. QListViewItem *newItem;
  727. for (; item; item=item->nextSibling())
  728. {
  729. if (IS_FOLDER(item) && !item->text(0).compare(name))
  730. return item;
  731. }
  732. item=NULL;
  733. for (;startItem;startItem=item->nextSibling())
  734. item=startItem;
  735. newItem=item?new ListViewFolder(parent,item)
  736. :new ListViewFolder(parent);
  737. newItem->setText(0,name);
  738. newItem->setOpen(TRUE);
  739. return newItem;
  740. }
  741. void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *dir, const QString &open_file)
  742. {
  743. int i,e;
  744. int p;
  745. KURL tmp;
  746. TPRFileList *fileList=(TPRFileList*)fileListV;
  747. QString caption;
  748. QString treePath;
  749. QListViewItem *parent;
  750. e=fileList->path.count();
  751. if (e) category->setOpen(TRUE);
  752. for (i=0;i<e;i++)
  753. {
  754. tmp=*reinterpret_cast<const KURL *>(dir);
  755. kurlNewFileName(tmp,fileList->path[i]);
  756. caption=fileList->path[i];
  757. p=caption.findRev('.');
  758. if (p>=0) caption.truncate(p);
  759. p=caption.findRev('/');
  760. if (p>=0) caption.remove(0,p+1);
  761. treePath=fileList->folder[i].stripWhiteSpace();
  762. //check for a backslash at the end and remove it if it's there.
  763. if (treePath[treePath.length()-1]=='\\')
  764. treePath.truncate(treePath.length()-1);
  765. parent=category;
  766. if (!treePath.isEmpty())
  767. {
  768. while ((p=treePath.find('\\'))>=0)
  769. {
  770. parent=createFolder(parent,treePath.left(p));
  771. treePath.remove(0,p+1);
  772. }
  773. parent=createFolder(parent,treePath);
  774. }
  775. ListViewFile *newFile=static_cast<ListViewFile *>(openFile(category,parent,caption,tmp.path()));
  776. if (!newFile->fileName.compare(open_file))
  777. fileTreeClicked(newFile);
  778. }
  779. }
  780. void MainForm::openProject(const QString &fileName)
  781. {
  782. TPRDataStruct TPRData;
  783. KURL dir;
  784. dir.setPath(fileName);
  785. int ret=loadTPR(fileName, &TPRData);
  786. if (ret == -1) {
  787. KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
  788. return;
  789. }
  790. if (ret > 0) {
  791. KMessageBox::error(this,QString("Error at line %2 of \'%1\'").arg(fileName).arg(ret));
  792. return;
  793. }
  794. if (TPRData.asm_files.path.count() && !asmFilesListItem) {
  795. KMessageBox::error(this,"This project needs A68k, which is not installed.");
  796. return;
  797. }
  798. if (TPRData.quill_files.path.count() && !qllFilesListItem) {
  799. KMessageBox::error(this,"This project needs quill.drv, which is not installed.");
  800. return;
  801. }
  802. clearProject();
  803. fileOpen_addList(hFilesListItem,&TPRData.h_files,&dir,TPRData.open_file);
  804. fileOpen_addList(cFilesListItem,&TPRData.c_files,&dir,TPRData.open_file);
  805. fileOpen_addList(qllFilesListItem,&TPRData.quill_files,&dir,TPRData.open_file);
  806. fileOpen_addList(sFilesListItem,&TPRData.s_files,&dir,TPRData.open_file);
  807. fileOpen_addList(asmFilesListItem,&TPRData.asm_files,&dir,TPRData.open_file);
  808. fileOpen_addList(oFilesListItem,&TPRData.o_files,&dir,TPRData.open_file);
  809. fileOpen_addList(aFilesListItem,&TPRData.a_files,&dir,TPRData.open_file);
  810. fileOpen_addList(txtFilesListItem,&TPRData.txt_files,&dir,TPRData.open_file);
  811. fileOpen_addList(othFilesListItem,&TPRData.oth_files,&dir,TPRData.open_file);
  812. rootListItem->setText(0,TPRData.prj_name);
  813. projectFileName=fileName;
  814. settings=TPRData.settings;
  815. libopts=TPRData.libopts;
  816. updateLeftStatusLabel();
  817. updateRightStatusLabel();
  818. addRecent(fileName);
  819. }
  820. void MainForm::fileOpen()
  821. {
  822. QString fileName=SGetFileName(KFileDialog::Opening,findFilter(TIGCCOpenProjectFileFilter),"Open Project/File",this);
  823. KURL dir;
  824. dir.setPath(fileName);
  825. if (fileName.isEmpty())
  826. return;
  827. openProject(fileName);
  828. }
  829. void MainForm::fileRecent1()
  830. {
  831. openProject(fileRecent1Action->statusTip());
  832. }
  833. void MainForm::fileRecent2()
  834. {
  835. openProject(fileRecent2Action->statusTip());
  836. }
  837. void MainForm::fileRecent3()
  838. {
  839. openProject(fileRecent3Action->statusTip());
  840. }
  841. void MainForm::fileRecent4()
  842. {
  843. openProject(fileRecent4Action->statusTip());
  844. }
  845. void MainForm::fileSave_saveAs(QListViewItem *theItem)
  846. {
  847. if (!IS_FILE(theItem))
  848. return;
  849. CATEGORY_OF(category,theItem);
  850. QString saveFileName=SGetFileName(KFileDialog::Saving,
  851. category==hFilesListItem?TIGCC_H_Filter TIGCCAllFilter:
  852. category==cFilesListItem?TIGCC_C_Filter TIGCCAllFilter:
  853. category==sFilesListItem?TIGCC_S_Filter TIGCCAllFilter:
  854. category==asmFilesListItem?TIGCC_ASM_Filter TIGCCAllFilter:
  855. category==qllFilesListItem?TIGCC_QLL_Filter TIGCCAllFilter:
  856. category==oFilesListItem?TIGCC_O_Filter TIGCCAllFilter:
  857. category==aFilesListItem?TIGCC_A_Filter TIGCCAllFilter:
  858. category==txtFilesListItem?TIGCC_TXT_Filter TIGCCAllFilter:
  859. TIGCCAllFilter
  860. ,"Save Source File",this);
  861. ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
  862. if (saveFileName.isEmpty()
  863. || (!IS_EDITABLE_CATEGORY(category)
  864. && !saveFileName.compare(theFile->fileName)))
  865. return;
  866. if (IS_EDITABLE_CATEGORY(category)
  867. ?saveFileText(saveFileName,theFile->textBuffer)
  868. :copyFile(theFile->fileName,saveFileName))
  869. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
  870. else {
  871. theFile->fileName=saveFileName;
  872. theFile->isNew=FALSE;
  873. theFile->isDirty=FALSE;
  874. updateRightStatusLabel();
  875. projectIsDirty=TRUE;
  876. }
  877. }
  878. //loadList also saves the file contents
  879. void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const QString &base_dir,void *dir_new,QString *open_file)
  880. {
  881. if (!category)
  882. return;
  883. TPRFileList *fileList=(TPRFileList*)fileListV;
  884. KURL *new_dir=(KURL*)dir_new;
  885. KURL tmpPath;
  886. QListViewItem *item=category->firstChild();
  887. QListViewItem *next;
  888. QString folderSpec=QString::null;
  889. int o;
  890. while (item)
  891. {
  892. if (IS_FILE(item))
  893. {
  894. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  895. QString absPath=theFile->fileName;
  896. QString relPath=KURL::relativePath(base_dir,absPath);
  897. if (relPath.find("./")==0)
  898. {
  899. relPath=relPath.mid(2);
  900. }
  901. else if (relPath.find("../")==0)
  902. {
  903. relPath=absPath;
  904. }
  905. tmpPath=*new_dir;
  906. kurlNewFileName(tmpPath,relPath);
  907. if (tmpPath.path().compare(theFile->fileName)
  908. || (IS_EDITABLE_CATEGORY(category)
  909. && (theFile->isDirty || theFile->isNew))) {
  910. if (IS_EDITABLE_CATEGORY(category)
  911. ?saveFileText(tmpPath.path(),theFile->textBuffer)
  912. :copyFile(theFile->fileName,tmpPath.path()))
  913. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(tmpPath.path()));
  914. else {
  915. theFile->fileName=tmpPath.path();
  916. theFile->isNew=FALSE;
  917. theFile->isDirty=FALSE;
  918. projectIsDirty=TRUE; // in case saving the project fails
  919. }
  920. }
  921. fileList->path << relPath;
  922. fileList->folder << folderSpec;
  923. if (item==currentListItem)
  924. *open_file=theFile->fileName;
  925. }
  926. else if (IS_FOLDER(item))
  927. {
  928. next=item->firstChild();
  929. if (next)
  930. {
  931. if (folderSpec.isEmpty())
  932. folderSpec=item->text(0);
  933. else
  934. {
  935. folderSpec+='\\';
  936. folderSpec+=item->text(0);
  937. }
  938. item=next;
  939. continue;
  940. }
  941. }
  942. fsll_seeknext:
  943. next=item->nextSibling();
  944. if (!next)
  945. {
  946. next=item->parent();
  947. if (next==category||!next)
  948. break;
  949. item=next;
  950. o=folderSpec.findRev('\\');
  951. if (o>=0)
  952. folderSpec.truncate(o);
  953. else
  954. folderSpec.truncate(0);
  955. goto fsll_seeknext;
  956. }
  957. item=next;
  958. }
  959. }
  960. void MainForm::fileSave_fromto(const QString &lastProj,const QString &nextProj)
  961. {
  962. TPRDataStruct TPRData;
  963. QString open_file;
  964. KURL base_dir_k(lastProj);
  965. base_dir_k.setFileName("");
  966. QString base_dir=base_dir_k.path();
  967. KURL new_dir(nextProj);
  968. if (IS_FILE(currentListItem)) {
  969. //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
  970. CATEGORY_OF(category,currentListItem);
  971. if (IS_EDITABLE_CATEGORY(category))
  972. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  973. }
  974. fileSave_loadList(hFilesListItem,&TPRData.h_files,base_dir,&new_dir,&open_file);
  975. fileSave_loadList(cFilesListItem,&TPRData.c_files,base_dir,&new_dir,&open_file);
  976. fileSave_loadList(qllFilesListItem,&TPRData.quill_files,base_dir,&new_dir,&open_file);
  977. fileSave_loadList(sFilesListItem,&TPRData.s_files,base_dir,&new_dir,&open_file);
  978. fileSave_loadList(asmFilesListItem,&TPRData.asm_files,base_dir,&new_dir,&open_file);
  979. fileSave_loadList(oFilesListItem,&TPRData.o_files,base_dir,&new_dir,&open_file);
  980. fileSave_loadList(aFilesListItem,&TPRData.a_files,base_dir,&new_dir,&open_file);
  981. fileSave_loadList(txtFilesListItem,&TPRData.txt_files,base_dir,&new_dir,&open_file);
  982. fileSave_loadList(othFilesListItem,&TPRData.oth_files,base_dir,&new_dir,&open_file);
  983. TPRData.prj_name=rootListItem->text(0);
  984. TPRData.open_file=open_file;
  985. TPRData.settings=settings;
  986. TPRData.libopts=libopts;
  987. if (saveTPR(nextProj,&TPRData))
  988. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(nextProj));
  989. else {
  990. projectFileName=nextProj;
  991. projectIsDirty=FALSE;
  992. addRecent(nextProj);
  993. }
  994. updateRightStatusLabel();
  995. }
  996. void MainForm::fileSave()
  997. {
  998. if (projectFileName.isEmpty())
  999. fileSaveAs();
  1000. else
  1001. fileSave_fromto(projectFileName,projectFileName);
  1002. }
  1003. void MainForm::fileSaveAs()
  1004. {
  1005. QString fileName=SGetFileName(KFileDialog::Saving,TIGCC_TPR_Filter TIGCCAllFilter,"Save Project",this);
  1006. if (fileName.isEmpty())
  1007. return;
  1008. fileSave_fromto(projectFileName,fileName);
  1009. }
  1010. void MainForm::filePrint()
  1011. {
  1012. }
  1013. void MainForm::editUndo()
  1014. {
  1015. }
  1016. void MainForm::editRedo()
  1017. {
  1018. }
  1019. void MainForm::editCut()
  1020. {
  1021. }
  1022. void MainForm::editCopy()
  1023. {
  1024. }
  1025. void MainForm::editPaste()
  1026. {
  1027. }
  1028. void MainForm::editFind()
  1029. {
  1030. }
  1031. void MainForm::findFindSymbolDeclaration()
  1032. {
  1033. }
  1034. void MainForm::helpDocumentation()
  1035. {
  1036. assistant->openAssistant();
  1037. }
  1038. void MainForm::helpContents()
  1039. {
  1040. force_qt_assistant_page(0);
  1041. assistant->openAssistant();
  1042. }
  1043. void MainForm::helpIndex()
  1044. {
  1045. force_qt_assistant_page(1);
  1046. assistant->openAssistant();
  1047. }
  1048. void MainForm::helpSearch()
  1049. {
  1050. force_qt_assistant_page(3);
  1051. assistant->openAssistant();
  1052. }
  1053. void MainForm::helpNews()
  1054. {
  1055. }
  1056. void MainForm::helpAbout()
  1057. {
  1058. khelpmenu->aboutApplication();
  1059. }
  1060. void MainForm::updateSizes()
  1061. {
  1062. int leftSize=splitter->sizes().first();
  1063. int rightSize=splitter->sizes().last();
  1064. int totalSize=leftSize+rightSize;
  1065. int mySize=size().width();
  1066. leftStatusLabel->setMaximumWidth(leftSize*mySize/totalSize);
  1067. rightStatusLabel->setMaximumWidth(rightSize*mySize/totalSize-10>0?
  1068. rightSize*mySize/totalSize-10:0);
  1069. }
  1070. void MainForm::resizeEvent(QResizeEvent *event)
  1071. {
  1072. QMainWindow::resizeEvent(event);
  1073. if (event->size()==event->oldSize()) return;
  1074. updateSizes();
  1075. }
  1076. void MainForm::timerEvent(QTimerEvent *event)
  1077. {
  1078. static int lastSplitterPos=-1;
  1079. QMainWindow::timerEvent(event);
  1080. if (lastSplitterPos==splitter->sizes().first()) return;
  1081. lastSplitterPos=splitter->sizes().first();
  1082. updateSizes();
  1083. }
  1084. void MainForm::fileTreeClicked(QListViewItem *item)
  1085. {
  1086. if (!item) return;
  1087. if (IS_FOLDER(currentListItem))
  1088. currentListItem->setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
  1089. if (IS_FILE(currentListItem)) {
  1090. if (currentListItemEditable) {
  1091. static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
  1092. m_view->cursorPositionReal(&(static_cast<ListViewFile *>(currentListItem)->cursorLine),
  1093. &(static_cast<ListViewFile *>(currentListItem)->cursorCol));
  1094. }
  1095. }
  1096. if (IS_FOLDER(item)) {
  1097. item->setPixmap(0,QPixmap::fromMimeSource("folder2.png"));
  1098. fileNewFolderAction->setEnabled(TRUE);
  1099. m_view->setEnabled(FALSE);
  1100. m_view->getDoc()->setText("");
  1101. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1102. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1103. m_view->getDoc()->readConfig(&kconfig);
  1104. delete_temp_file("config.tmp");
  1105. m_view->getDoc()->setHlMode(0);
  1106. } else if (IS_FILE(item)) {
  1107. fileNewFolderAction->setEnabled(TRUE);
  1108. m_view->setEnabled(TRUE);
  1109. CATEGORY_OF(category,item->parent());
  1110. if (IS_EDITABLE_CATEGORY(category)) {
  1111. m_view->getDoc()->setText(static_cast<ListViewFile *>(item)->textBuffer);
  1112. const char *buffer=static_cast<ListViewFile *>(item)->textBuffer;
  1113. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=kate - Normal\n",0);
  1114. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1115. m_view->getDoc()->readConfig(&kconfig);
  1116. delete_temp_file("config.tmp");
  1117. uint cnt=m_view->getDoc()->hlModeCount(), i;
  1118. for (i=0; i<cnt; i++) {
  1119. if (!m_view->getDoc()->hlModeName(i).compare(
  1120. ((category==sFilesListItem||(category==hFilesListItem&&buffer&&*buffer=='|'))?
  1121. "GNU Assembler 68k":
  1122. (category==asmFilesListItem||(category==hFilesListItem&&buffer&&*buffer==';'))?
  1123. "Motorola Assembler 68k":
  1124. (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?
  1125. "C":
  1126. "None"))) break;
  1127. }
  1128. if (i==cnt) i=0;
  1129. m_view->getDoc()->setHlMode(i);
  1130. m_view->setCursorPositionReal(static_cast<ListViewFile *>(item)->cursorLine,
  1131. static_cast<ListViewFile *>(item)->cursorCol);
  1132. currentListItemEditable=TRUE;
  1133. } else {
  1134. m_view->getDoc()->setText("");
  1135. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1136. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1137. m_view->getDoc()->readConfig(&kconfig);
  1138. delete_temp_file("config.tmp");
  1139. m_view->getDoc()->setHlMode(0);
  1140. currentListItemEditable=FALSE;
  1141. }
  1142. } else {
  1143. fileNewFolderAction->setEnabled(FALSE);
  1144. m_view->setEnabled(FALSE);
  1145. m_view->getDoc()->setText("");
  1146. write_temp_file("config.tmp","[Kate Renderer Defaults]\nSchema=ktigcc - Grayed Out\n",0);
  1147. KConfig kconfig(QString(tempdir)+"/config.tmp",true);
  1148. m_view->getDoc()->readConfig(&kconfig);
  1149. delete_temp_file("config.tmp");
  1150. m_view->getDoc()->setHlMode(0);
  1151. }
  1152. currentListItem=item;
  1153. updateLeftStatusLabel();
  1154. updateRightStatusLabel();
  1155. }
  1156. void MainForm::fileNewFolder()
  1157. {
  1158. if (IS_FILE(currentListItem))
  1159. currentListItem=currentListItem->parent();
  1160. QListViewItem *item=NULL, *next=currentListItem->firstChild();
  1161. for (; next; next=item->nextSibling())
  1162. {
  1163. item=next;
  1164. }
  1165. QListViewItem *newFolder=item?new ListViewFolder(currentListItem,item)
  1166. :new ListViewFolder(currentListItem);
  1167. newFolder->setText(0,"NewFolder");
  1168. newFolder->setRenameEnabled(0,TRUE);
  1169. currentListItem->setOpen(TRUE);
  1170. fileTreeClicked(newFolder);
  1171. newFolder->startRename(0);
  1172. projectIsDirty=TRUE;
  1173. }
  1174. #define unused_col __attribute__((unused)) col /* stupid QT designer... */
  1175. void MainForm::fileTreeContextMenuRequested(QListViewItem *item,
  1176. const QPoint &pos,
  1177. int unused_col)
  1178. {
  1179. fileTreeClicked(item);
  1180. if (IS_FOLDER(item)) {
  1181. QPopupMenu menu;
  1182. menu.insertItem("New &Folder",0);
  1183. menu.insertItem("New F&ile",1);
  1184. CATEGORY_OF(category,item);
  1185. if (category==oFilesListItem || category==aFilesListItem
  1186. || category==othFilesListItem) menu.setItemEnabled(1,FALSE);
  1187. if (!IS_CATEGORY(item)) {
  1188. menu.insertSeparator();
  1189. menu.insertItem("&Remove",2);
  1190. menu.insertItem("Re&name",3);
  1191. }
  1192. switch (menu.exec(pos)) {
  1193. case 0:
  1194. fileNewFolder();
  1195. break;
  1196. case 1:
  1197. newFile(item);
  1198. break;
  1199. case 2:
  1200. delete item;
  1201. currentListItem=NULL;
  1202. fileTreeClicked(fileTree->currentItem());
  1203. break;
  1204. case 3:
  1205. item->startRename(0);
  1206. }
  1207. }
  1208. }
  1209. QStringList MainForm::extractAllFileNames(void)
  1210. {
  1211. QListViewItem *item=rootListItem->firstChild(),*next;
  1212. QStringList allFiles;
  1213. while (item)
  1214. {
  1215. if (IS_FOLDER(item))
  1216. {
  1217. next=item->firstChild();
  1218. if (next)
  1219. {
  1220. item=next;
  1221. continue;
  1222. }
  1223. }
  1224. if (IS_FILE(item))
  1225. {
  1226. allFiles << (static_cast<ListViewFile *>(item)->fileName);
  1227. }
  1228. next=item->nextSibling();
  1229. while (!next)
  1230. {
  1231. next=item->parent();
  1232. if (next==rootListItem||!next)
  1233. {
  1234. return allFiles;
  1235. }
  1236. item=next;
  1237. next=item->nextSibling();
  1238. }
  1239. item=next;
  1240. }
  1241. return allFiles;
  1242. }
  1243. //you put in parent, and it gives you the rest, but you must have a place to put it all.
  1244. void MainForm::extractFileTreeInfo(QListViewItem *parent,QListViewItem **p_category,QString *p_folderPath)
  1245. {
  1246. QListViewItem *item,*next;
  1247. QString tmp=QString::null;
  1248. int o;
  1249. CATEGORY_OF(category,parent);
  1250. *p_category=category;
  1251. item=category->firstChild();
  1252. while (item)
  1253. {
  1254. if (item==parent)
  1255. {
  1256. if (!tmp.isEmpty())
  1257. tmp+='/';
  1258. tmp+=item->text(0);
  1259. *p_folderPath=tmp;
  1260. }
  1261. if (IS_FOLDER(item))
  1262. {
  1263. next=item->firstChild();
  1264. if (next)
  1265. {
  1266. if (tmp.isEmpty())
  1267. tmp=item->text(0);
  1268. else
  1269. {
  1270. tmp+='/';
  1271. tmp+=item->text(0);
  1272. }
  1273. item=next;
  1274. continue;
  1275. }
  1276. }
  1277. mfnf_seeknext:
  1278. next=item->nextSibling();
  1279. if (!next)
  1280. {
  1281. next=item->parent();
  1282. if (next==category||!next)
  1283. break;
  1284. item=next;
  1285. o=tmp.findRev('/');
  1286. if (o>=0)
  1287. tmp.truncate(o);
  1288. else
  1289. tmp.truncate(0);
  1290. goto mfnf_seeknext;
  1291. }
  1292. item=next;
  1293. }
  1294. }
  1295. void MainForm::newFile( QListViewItem *parent, QString text, const char *iconName )
  1296. {
  1297. QListViewItem *item=NULL, *next=parent->firstChild();
  1298. QString tmp,oldtmp,suffix,caption;
  1299. QStringList allFiles=extractAllFileNames();
  1300. QListViewItem *category;
  1301. KURL tmpK;
  1302. int tryNum;
  1303. for (; IS_FILE(next); next=item->nextSibling())
  1304. item=next;
  1305. extractFileTreeInfo(parent,&category,&tmp);
  1306. suffix="";
  1307. if (category==hFilesListItem)
  1308. suffix="h";
  1309. else if (category==cFilesListItem)
  1310. suffix="c";
  1311. else if (category==sFilesListItem)
  1312. suffix="s";
  1313. else if (category==asmFilesListItem)
  1314. suffix="asm";
  1315. else if (category==qllFilesListItem) {
  1316. if (qllFileCount) {
  1317. KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
  1318. return;
  1319. }
  1320. suffix="qll";
  1321. } else if (category==oFilesListItem)
  1322. suffix="o";
  1323. else if (category==aFilesListItem)
  1324. suffix="a";
  1325. else if (category==txtFilesListItem)
  1326. suffix="txt";
  1327. suffix='.'+suffix;
  1328. if (!tmp.isEmpty())
  1329. tmp+='/';
  1330. tmp+="New File";
  1331. tmpK.setPath(projectFileName);
  1332. kurlNewFileName(tmpK,tmp);
  1333. tmp=tmpK.path();
  1334. if (projectFileName.isEmpty())
  1335. {
  1336. short o=0;
  1337. if (tmp[0]=='.')
  1338. o=1;
  1339. if (tmp[o]=='/')
  1340. tmp=tmp.mid(o+1);
  1341. }
  1342. caption="New File";
  1343. oldtmp=tmp+' ';
  1344. tmp+=suffix;
  1345. tryNum=1;
  1346. while (!checkFileName(tmp,allFiles))
  1347. {
  1348. tryNum++;
  1349. tmp=oldtmp+QString("%1").arg(tryNum)+suffix;
  1350. caption="New File "+QString("%1").arg(tryNum);
  1351. }
  1352. ListViewFile *newFile=item?new ListViewFile(parent,item)
  1353. :new ListViewFile(parent);
  1354. newFile->fileName=tmp;
  1355. newFile->setText(0,caption);
  1356. newFile->setPixmap(0,QPixmap::fromMimeSource(iconName));
  1357. parent->setOpen(TRUE);
  1358. newFile->textBuffer=text;
  1359. fileTreeClicked(newFile);
  1360. projectIsDirty=TRUE;
  1361. newFile->startRename(0);
  1362. m_view->getDoc()->setText(text);
  1363. fileCount++;
  1364. COUNTER_FOR_CATEGORY(category)++;
  1365. updateLeftStatusLabel();
  1366. }
  1367. void MainForm::newFile( QListViewItem *parent )
  1368. {
  1369. CATEGORY_OF(category,parent);
  1370. newFile(parent,category==txtFilesListItem?"":
  1371. ((category==hFilesListItem?"// Header File\n//":
  1372. category==cFilesListItem?"// C Source File\n//":
  1373. category==sFilesListItem?"| Assembly Source File\n|":
  1374. category==asmFilesListItem?"; Assembly Source File\n;":
  1375. category==qllFilesListItem?"// Quill Source File\n//":"???\n")
  1376. +QString(" Created ")
  1377. +QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n"+
  1378. QString(category==cFilesListItem?(cFileCount?
  1379. "\n#include <tigcclib.h>\n":
  1380. "\n// Delete or comment out the items you do not need.\n"
  1381. "#define COMMENT_STRING \"Place your comment here.\"\n"
  1382. "#define COMMENT_PROGRAM_NAME "
  1383. "\"Place your program name here.\"\n"
  1384. "#define COMMENT_VERSION_STRING "
  1385. "\"Place your version string here.\"\n"
  1386. "#define COMMENT_VERSION_NUMBER 0,0,0,0 "
  1387. "/* major, minor, revision, subrevision */\n"
  1388. "#define COMMENT_AUTHORS "
  1389. "\"Place your author name(s) here.\"\n"
  1390. "#define COMMENT_BW_ICON \\\n"
  1391. "\t{0b0000000000000000, \\\n"
  1392. "\t 0b0000000000000000, \\\n"
  1393. "\t 0b0000000000000000, \\\n"
  1394. "\t 0b0000000000000000, \\\n"
  1395. "\t 0b0000000000000000, \\\n"
  1396. "\t 0b0000000000000000, \\\n"
  1397. "\t 0b0000000000000000, \\\n"
  1398. "\t 0b0000000000000000, \\\n"
  1399. "\t 0b0000000000000000, \\\n"
  1400. "\t 0b0000000000000000, \\\n"
  1401. "\t 0b0000000000000000, \\\n"
  1402. "\t 0b0000000000000000, \\\n"
  1403. "\t 0b0000000000000000, \\\n"
  1404. "\t 0b0000000000000000, \\\n"
  1405. "\t 0b0000000000000000, \\\n"
  1406. "\t 0b0000000000000000}\n"
  1407. "#define COMMENT_GRAY_ICON \\\n"
  1408. "\t{0b0000000000000000, \\\n"
  1409. "\t 0b0000000000000000, \\\n"
  1410. "\t 0b0000000000000000, \\\n"
  1411. "\t 0b0000000000000000, \\\n"
  1412. "\t 0b0000000000000000, \\\n"
  1413. "\t 0b0000000000000000, \\\n"
  1414. "\t 0b0000000000000000, \\\n"
  1415. "\t 0b0000000000000000, \\\n"
  1416. "\t 0b0000000000000000, \\\n"
  1417. "\t 0b0000000000000000, \\\n"
  1418. "\t 0b0000000000000000, \\\n"
  1419. "\t 0b0000000000000000, \\\n"
  1420. "\t 0b0000000000000000, \\\n"
  1421. "\t 0b0000000000000000, \\\n"
  1422. "\t 0b0000000000000000, \\\n"
  1423. "\t 0b0000000000000000}, \\\n"
  1424. "\t{0b0000000000000000, \\\n"
  1425. "\t 0b0000000000000000, \\\n"
  1426. "\t 0b0000000000000000, \\\n"
  1427. "\t 0b0000000000000000, \\\n"
  1428. "\t 0b0000000000000000, \\\n"
  1429. "\t 0b0000000000000000, \\\n"
  1430. "\t 0b0000000000000000, \\\n"
  1431. "\t 0b0000000000000000, \\\n"
  1432. "\t 0b0000000000000000, \\\n"
  1433. "\t 0b0000000000000000, \\\n"
  1434. "\t 0b0000000000000000, \\\n"
  1435. "\t 0b0000000000000000, \\\n"
  1436. "\t 0b0000000000000000, \\\n"
  1437. "\t 0b0000000000000000, \\\n"
  1438. "\t 0b0000000000000000, \\\n"
  1439. "\t 0b0000000000000000}\n\n#include <tigcclib.h>\n\n"
  1440. "// Main Function\nvoid _main(void)\n{\n"
  1441. "\t// Place your code here.\n}\n"):"")),
  1442. category==cFilesListItem||category==qllFilesListItem
  1443. ?"filec.png":
  1444. category==hFilesListItem?"fileh.png":
  1445. category==sFilesListItem||category==asmFilesListItem
  1446. ?"files.png":
  1447. category==txtFilesListItem?"filet.png":"filex.png");
  1448. }
  1449. QListViewItem *MainForm::resolveParent(QListViewItem *category)
  1450. {
  1451. QListViewItem *ret=currentListItem;
  1452. if (!IS_FILE(ret)&&!IS_FOLDER(ret))
  1453. return category;
  1454. if (IS_FILE(ret))
  1455. ret=ret->parent();
  1456. QListViewItem *actualCategory=ret;
  1457. while (IS_FOLDER(actualCategory->parent())) actualCategory=actualCategory->parent();
  1458. if (actualCategory!=category)
  1459. return category;
  1460. return ret;
  1461. }
  1462. void MainForm::fileNewCHeader()
  1463. {
  1464. newFile(resolveParent(hFilesListItem),"// Header File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1465. }
  1466. void MainForm::fileNewGNUAssemblyHeader()
  1467. {
  1468. newFile(resolveParent(hFilesListItem),"| Header File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1469. }
  1470. void MainForm::fileNewA68kAssemblyHeader()
  1471. {
  1472. newFile(resolveParent(hFilesListItem),"; Header File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
  1473. }
  1474. void MainForm::fileNewCSourceFile()
  1475. {
  1476. newFile(resolveParent(cFilesListItem),"// C Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  1477. }
  1478. void MainForm::fileNewGNUAssemblySourceFile()
  1479. {
  1480. newFile(resolveParent(sFilesListItem),"| Assembly Source File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  1481. }
  1482. void MainForm::fileNewA68kAssemblySourceFile()
  1483. {
  1484. newFile(resolveParent(asmFilesListItem),"; Assembly Source File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
  1485. }
  1486. void MainForm::fileNewQuillSourceFile()
  1487. {
  1488. newFile(resolveParent(qllFilesListItem),"// Quill Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
  1489. }
  1490. void MainForm::fileNewTextFile()
  1491. {
  1492. newFile(resolveParent(txtFilesListItem),"","filet.png");
  1493. }
  1494. void MainForm::updateLeftStatusLabel()
  1495. {
  1496. QString text=QString::number(fileCount)+QString(" File")
  1497. +QString(fileCount!=1?"s":"")+QString(" Total");
  1498. if (IS_FOLDER(currentListItem)||IS_FILE(currentListItem)) {
  1499. CATEGORY_OF(category,currentListItem);
  1500. text+=QString(", ")+QString::number(COUNTER_FOR_CATEGORY(category))
  1501. +QString(" in Category");
  1502. }
  1503. leftStatusLabel->setText(text);
  1504. }
  1505. void MainForm::updateRightStatusLabel()
  1506. {
  1507. int leftSize=splitter->sizes().first();
  1508. int rightSize=splitter->sizes().last();
  1509. int totalSize=leftSize+rightSize;
  1510. int mySize=size().width();
  1511. int rightStatusSize=rightSize*mySize/totalSize-10>0?
  1512. rightSize*mySize/totalSize-10:0;
  1513. if (currentListItem==rootListItem) {
  1514. rowStatusLabel->hide();
  1515. colStatusLabel->hide();
  1516. charsStatusLabel->hide();
  1517. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1518. rightStatusLabel->setText(projectFileName);
  1519. } else if (IS_FOLDER(currentListItem)) {
  1520. rowStatusLabel->hide();
  1521. colStatusLabel->hide();
  1522. charsStatusLabel->hide();
  1523. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1524. rightStatusLabel->setText("");
  1525. } else if (IS_FILE(currentListItem)) {
  1526. CATEGORY_OF(category,currentListItem);
  1527. if (IS_EDITABLE_CATEGORY(category)) {
  1528. unsigned int line, col;
  1529. m_view->cursorPositionReal(&line,&col);
  1530. rowStatusLabel->show();
  1531. rowStatusLabel->setMaximumWidth(30);
  1532. rowStatusLabel->setText(QString("%1").arg(line));
  1533. colStatusLabel->show();
  1534. colStatusLabel->setMaximumWidth(30);
  1535. colStatusLabel->setText(QString("%1").arg(col+1));
  1536. charsStatusLabel->show();
  1537. charsStatusLabel->setMaximumWidth(100);
  1538. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  1539. rightStatusLabel->setMaximumWidth(rightStatusSize-160);
  1540. } else {
  1541. rowStatusLabel->hide();
  1542. colStatusLabel->hide();
  1543. charsStatusLabel->hide();
  1544. rightStatusLabel->setMaximumWidth(rightStatusSize);
  1545. }
  1546. rightStatusLabel->setText(static_cast<ListViewFile *>(currentListItem)->fileName);
  1547. }
  1548. }
  1549. void MainForm::m_view_cursorPositionChanged()
  1550. {
  1551. unsigned int line, col;
  1552. m_view->cursorPositionReal(&line,&col);
  1553. rowStatusLabel->setText(QString("%1").arg(line));
  1554. colStatusLabel->setText(QString("%1").arg(col+1));
  1555. }
  1556. void MainForm::m_view_textChanged()
  1557. {
  1558. if (IS_FILE(currentListItem))
  1559. static_cast<ListViewFile *>(currentListItem)->isDirty=TRUE;
  1560. charsStatusLabel->setText(QString("%1 Characters").arg(m_view->getDoc()->text().length()));
  1561. }
  1562. void MainForm::fileTreeItemRenamed( QListViewItem *item, int col, const QString &newName)
  1563. {
  1564. if (col)
  1565. return;
  1566. if (!IS_FILE(item))
  1567. return;
  1568. ListViewFile *theFile=static_cast<ListViewFile *>(item);
  1569. QString suffix;
  1570. QString oldLabel;
  1571. QString &fileNameRef=theFile->fileName;
  1572. QString oldFileName=fileNameRef;
  1573. QString newFileName=fileNameRef;
  1574. int o,s;
  1575. o=oldFileName.findRev('.');
  1576. s=oldFileName.findRev('/');
  1577. if (o>=0&&(s<0||o>s)) {
  1578. suffix=oldFileName.mid(o+1);
  1579. newFileName.truncate(o);
  1580. } else {
  1581. suffix=QString::null;
  1582. }
  1583. if (s>=0) {
  1584. oldLabel=newFileName.mid(s+1);
  1585. newFileName.truncate(s+1);
  1586. } else {
  1587. oldLabel=newFileName;
  1588. newFileName.truncate(0);
  1589. }
  1590. if (!oldLabel.compare(newName))
  1591. return; //no changes are needed, and we don't want it to complain about the file conflicting with itself!
  1592. newFileName+=newName;
  1593. newFileName+='.';
  1594. newFileName+=suffix;
  1595. if (checkFileName(newFileName,extractAllFileNames())) {
  1596. if (!theFile->isNew && !QDir().rename(oldFileName,newFileName)) {
  1597. KMessageBox::error(this,"Failed to rename the file.");
  1598. theFile->setText(0,oldLabel);
  1599. } else {
  1600. fileNameRef=newFileName;
  1601. projectIsDirty=TRUE;
  1602. }
  1603. } else {
  1604. KMessageBox::error(this,"The name you chose conflicts with that of another file.");
  1605. theFile->setText(0,oldLabel);
  1606. }
  1607. updateRightStatusLabel();
  1608. }
  1609. // Yes, this is an ugly hack... Any better suggestions?
  1610. #define QListView DnDListView