mainform.ui.h 79 KB

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