mainform.ui.h 79 KB

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