mainform.ui.h 56 KB

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