mainform.ui.h 78 KB

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