mainform.ui.h 72 KB

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