mainform.ui.h 77 KB

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