mainform.ui.h 74 KB

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