1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431 |
- /****************************************************************************
- ** ui.h extension file, included from the uic-generated form implementation.
- **
- ** If you wish to add, delete or rename slots use Qt Designer which will
- ** update this file, preserving your code. Create an init() slot in place of
- ** a constructor, and a destroy() slot in place of a destructor.
- *****************************************************************************/
- /*
- ktigcc - TIGCC IDE for KDE
- Copyright (C) 2004-2006 Kevin Kofler
- Copyright (C) 2006 Joey Adams
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- #include <qapplication.h>
- #include <qlabel.h>
- #include <qstatusbar.h>
- #include <qtimer.h>
- #include <qdatetime.h>
- #include <qdragobject.h>
- #include <qassistantclient.h>
- #include <qdir.h>
- #include <qclipboard.h>
- #include <qaccel.h>
- #include <kparts/factory.h>
- #include <klibloader.h>
- #include <kate/document.h>
- #include <kate/view.h>
- #include <kconfig.h>
- #include <ktexteditor/configinterfaceextension.h>
- #include <ktexteditor/dynwordwrapinterface.h>
- #include <kaboutdata.h>
- #include <khelpmenu.h>
- #include <kfiledialog.h>
- #include <kurl.h>
- #include <kmessagebox.h>
- #include <kdirwatch.h>
- #include <cstdio>
- #include <cstdlib>
- #include "ktigcc.h"
- #include "tpr.h"
- #include "preferences.h"
- #include "projectoptions.h"
- using std::puts;
- using std::exit;
- #define TIGCC_TPR_Filter "*.tpr|TIGCC Projects (*.tpr)\n"
- #define TIGCC_H_Filter "*.h|Header Files (*.h)\n"
- #define TIGCC_C_Filter "*.c|C Files (*.c)\n"
- #define TIGCC_S_Filter "*.s|GNU Assembly Files (*.s)\n"
- #define TIGCC_ASM_Filter "*.asm|A68k Assembly Files (*.asm)\n"
- #define TIGCC_QLL_Filter "*.qll|Quill Files (*.qll)\n"
- #define TIGCC_O_Filter "*.o|Object Files (*.o)\n"
- #define TIGCC_A_Filter "*.a|Archive Files (*.a)\n"
- #define TIGCC_TXT_Filter "*.txt|Text Files (*.txt)\n"
- #define TIGCCAllFilter "*|All Files (*)"
- enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
- #define TIGCCProjectDirectory "/usr/local/tigcc/projects"
- #define IS_CATEGORY(item) ((item) && ((item)==hFilesListItem \
- || (item)==cFilesListItem \
- || (item)==sFilesListItem \
- || (item)==asmFilesListItem \
- || (item)==qllFilesListItem \
- || (item)==oFilesListItem \
- || (item)==aFilesListItem \
- || (item)==txtFilesListItem \
- || (item)==othFilesListItem))
- #define IS_EDITABLE_CATEGORY(item) ((item) && ((item)==hFilesListItem \
- || (item)==cFilesListItem \
- || (item)==sFilesListItem \
- || (item)==asmFilesListItem \
- || (item)==qllFilesListItem \
- || (item)==txtFilesListItem))
- #define IS_FOLDER(item) ((item) && (item)->rtti()==0x716CC0)
- #define IS_FILE(item) ((item) && (item)->rtti()==0x716CC1)
- #define CATEGORY_OF(category,item) QListViewItem *category=(item); \
- while (category->parent()->rtti()==0x716CC0) \
- category=category->parent()
- #define COUNTER_FOR_CATEGORY(category) ((category)==hFilesListItem?hFileCount: \
- (category)==cFilesListItem?cFileCount: \
- (category)==sFilesListItem?sFileCount: \
- (category)==asmFilesListItem?asmFileCount: \
- (category)==qllFilesListItem?qllFileCount: \
- (category)==oFilesListItem?oFileCount: \
- (category)==aFilesListItem?aFileCount: \
- (category)==txtFilesListItem?txtFileCount: \
- othFileCount)
- #define CURRENT_VIEW (static_cast<Kate::View *>(widgetStack->visibleWidget()))
- // All the methods are inline because otherwise QT Designer will mistake them
- // for slots of the main form.
- class ListViewFolder : public QListViewItem {
- public:
- ListViewFolder(QListView *parent) : QListViewItem(parent)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- ListViewFolder(QListViewItem *parent) : QListViewItem(parent)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- ListViewFolder(QListView *parent, QListViewItem *after)
- : QListViewItem(parent, after)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDropEnabled(TRUE);
- setDragEnabled(TRUE);
- }
- ListViewFolder(QListViewItem *parent, QListViewItem *after)
- : QListViewItem(parent, after)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- virtual int rtti(void) const {return 0x716CC0;}
- protected:
- };
- class ListViewFile : public QListViewItem {
- public:
- ListViewFile(QListView *parent) : QListViewItem(parent),
- kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListViewItem *parent) : QListViewItem(parent),
- kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListView *parent, QListViewItem *after)
- : QListViewItem(parent, after), kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDropEnabled(TRUE);
- setDragEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListViewItem *parent, QListViewItem *after)
- : QListViewItem(parent, after), kateView(NULL),
- isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- virtual ~ListViewFile()
- {
- if (fileName[0]=='/')
- KDirWatch::self()->removeFile(fileName);
- if (kateView) {
- Kate::Document *doc=kateView->getDoc();
- delete kateView;
- delete doc;
- }
- }
- virtual int rtti(void) const {return 0x716CC1;}
- Kate::View *kateView;
- QString textBuffer; // for lazy loading
- QString fileName; // full name of the file
- bool isNew;
- protected:
- };
- // These should be instance variables in clean C++, but QT Designer won't let me
- // touch the class definition, so this is all I can do. And there is only one
- // instance of MainForm anyway.
- static QListViewItem *rootListItem;
- static QListViewItem *hFilesListItem;
- static QListViewItem *cFilesListItem;
- static QListViewItem *sFilesListItem;
- static QListViewItem *asmFilesListItem;
- static QListViewItem *qllFilesListItem;
- static QListViewItem *oFilesListItem;
- static QListViewItem *aFilesListItem;
- static QListViewItem *txtFilesListItem;
- static QListViewItem *othFilesListItem;
- static QListViewItem *currentListItem;
- static bool projectIsDirty;
- static QLabel *leftStatusLabel;
- static QLabel *rowStatusLabel;
- static QLabel *colStatusLabel;
- static QLabel *charsStatusLabel;
- static QLabel *rightStatusLabel;
- static KParts::Factory* factory;
- static KHelpMenu *khelpmenu;
- static QPopupMenu *te_popup;
- static QAssistantClient *assistant;
- static int fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
- tprSettings settings; //static is turned off here so ProjectOptions can access it.
- tprLibOpts libopts; //static is turned off here so ProgramOptions can access it.
- static QString projectFileName;
- static QString lastDirectory;
- static QClipboard *clipboard;
- static QAccel *accel;
- static TIGCCPrefs preferences;
- class DnDListView : public QListView {
- private:
- public:
- DnDListView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- : QListView(parent,name,f) {}
- protected:
- virtual QDragObject *dragObject() {
- QListViewItem *currItem=selectedItem();
- if (currItem==rootListItem || currItem->parent()==rootListItem)
- return NULL;
- QStoredDrag *storedDrag=new QStoredDrag("x-ktigcc-dnd", this);
- static QByteArray data(sizeof(QListViewItem*));
- data.duplicate(reinterpret_cast<char *>(&currItem),
- sizeof(QListViewItem*));
- storedDrag->setEncodedData(data);
- return storedDrag;
- }
- virtual void dropEvent (QDropEvent *e) {
- if (e->source()==this && e->provides("x-ktigcc-dnd")) {
- QListViewItem *currItem;
- currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
- if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
- // dropping folder
- // can only drop on folder or category
- QPoint vp=contentsToViewport(e->pos());
- QListViewItem *item=itemAt(vp);
- if (IS_FOLDER(item)) {
- // need same category
- CATEGORY_OF(srcCategory,currItem);
- CATEGORY_OF(destCategory,item);
- if (srcCategory == destCategory) {
- // can't move folder into itself
- for (QListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
- if (destFolder==currItem) goto ignore;
- }
- // move folder
- e->accept();
- currItem->parent()->takeItem(currItem);
- item->insertItem(currItem);
- // put it at the right place
- if (currItem->nextSibling()) {
- QListViewItem *lastItem=currItem->nextSibling();
- while(lastItem->nextSibling())
- lastItem=lastItem->nextSibling();
- currItem->moveItem(lastItem);
- }
- projectIsDirty=TRUE;
- } else {ignore: e->ignore();}
- } else e->ignore();
- } else if (IS_FILE(currItem)) {
- // dropping file
- QPoint vp=contentsToViewport(e->pos());
- QListViewItem *item=itemAt(vp);
- if (IS_FOLDER(item)) {
- // drop on folder
- // don't allow more than one Quill file per project
- CATEGORY_OF(srcCategory,currItem);
- CATEGORY_OF(destCategory,item);
- if (qllFilesListItem && srcCategory != qllFilesListItem
- && destCategory == qllFilesListItem && qllFileCount) {
- ignore2: e->ignore();
- } else {
- // moving from editable to non-editable category -
- // prompt for saving
- if (IS_EDITABLE_CATEGORY(srcCategory)
- && !IS_EDITABLE_CATEGORY(destCategory)) {
- if (static_cast<MainForm *>(parent()->parent()->parent())->fileSavePrompt(currItem))
- goto ignore2;
- if (static_cast<ListViewFile *>(currItem)->fileName[0]=='/')
- KDirWatch::self()->removeFile(static_cast<ListViewFile *>(currItem)->fileName);
- }
- // moving from non-editable to editable category
- if (!IS_EDITABLE_CATEGORY(srcCategory)
- && IS_EDITABLE_CATEGORY(destCategory)) {
- QString textBuffer=loadFileText(static_cast<ListViewFile *>(currItem)->fileName);
- if (textBuffer.isNull()) {
- KMessageBox::error(this,QString("Can't open \'%1\'").arg(static_cast<ListViewFile *>(currItem)->fileName));
- goto ignore2;
- }
- static_cast<ListViewFile *>(currItem)->kateView=reinterpret_cast<Kate::View *>(static_cast<MainForm *>(parent()->parent()->parent())->createView(static_cast<ListViewFile *>(currItem)->fileName,textBuffer,destCategory));
- // force reloading the text buffer
- if (currentListItem==currItem)
- currentListItem=NULL;
- }
- // move file
- e->accept();
- currItem->parent()->takeItem(currItem);
- COUNTER_FOR_CATEGORY(srcCategory)--;
- item->insertItem(currItem);
- COUNTER_FOR_CATEGORY(destCategory)++;
- // put it at the right place
- if (IS_FILE(currItem->nextSibling())) {
- QListViewItem *lastItem=currItem->nextSibling();
- while(IS_FILE(lastItem->nextSibling()))
- lastItem=lastItem->nextSibling();
- currItem->moveItem(lastItem);
- }
- projectIsDirty=TRUE;
- setSelected(currItem,TRUE);
- ensureItemVisible(currItem);
- // update editor and counters
- static_cast<MainForm *>(parent()->parent()->parent())->fileTreeClicked(currItem);
- // moving from non-editable to editable category
- if (!IS_EDITABLE_CATEGORY(srcCategory)
- && IS_EDITABLE_CATEGORY(destCategory)) {
- if (static_cast<ListViewFile *>(currItem)->fileName[0]=='/')
- KDirWatch::self()->addFile(static_cast<ListViewFile *>(currItem)->fileName);
- }
- // moving from editable to non-editable category
- if (IS_EDITABLE_CATEGORY(srcCategory)
- && !IS_EDITABLE_CATEGORY(destCategory)) {
- if (static_cast<ListViewFile *>(currItem)->kateView) {
- Kate::Document *doc=static_cast<ListViewFile *>(currItem)->kateView->getDoc();
- delete static_cast<ListViewFile *>(currItem)->kateView;
- delete doc;
- static_cast<ListViewFile *>(currItem)->kateView=NULL;
- } else static_cast<ListViewFile *>(currItem)->textBuffer=QString::null;
- }
- }
- } else if (IS_FILE(item)) {
- // drop on file
- // need same parent, but different items
- if (currItem->parent() == item->parent()
- && currItem != item) {
- // reorder files
- // figure out which one is the first
- for (QListViewItem *i=currItem->parent()->firstChild();i;
- i=i->nextSibling()) {
- if (i==currItem) {
- // currItem is first, move currItem after item
- e->accept();
- currItem->moveItem(item);
- projectIsDirty=TRUE;
- break;
- } else if (i==item) {
- // item is first, move currItem before item
- e->accept();
- currItem->moveItem(item);
- item->moveItem(currItem);
- projectIsDirty=TRUE;
- break;
- }
- }
- } else e->ignore();
- } else e->ignore();
- } else e->ignore();
- } else e->ignore();
- }
- virtual void dragEnterEvent (QDragEnterEvent *e) {
- if (e->source()==this&&(e->provides("x-ktigcc-dnd")))
- e->accept();
- }
- virtual void dragMoveEvent (QDragMoveEvent *e) {
- if (e->source()==this && e->provides("x-ktigcc-dnd")) {
- QListViewItem *currItem;
- currItem = *reinterpret_cast<QListViewItem * const *>((const char *)e->encodedData("x-ktigcc-dnd"));
- if (IS_FOLDER(currItem) && !IS_CATEGORY(currItem)) {
- // dropping folder
- // can only drop on folder or category
- QPoint vp=contentsToViewport(e->pos());
- QListViewItem *item=itemAt(vp);
- if (IS_FOLDER(item)) {
- // need same category
- CATEGORY_OF(srcCategory,currItem);
- CATEGORY_OF(destCategory,item);
- if (srcCategory == destCategory) {
- // can't move folder into itself
- for (QListViewItem *destFolder=item; IS_FOLDER(destFolder); destFolder=destFolder->parent()) {
- if (destFolder==currItem) goto ignore;
- }
- e->accept();
- } else {ignore: e->ignore();}
- } else e->ignore();
- } else if (IS_FILE(currItem)) {
- // dropping file
- QPoint vp=contentsToViewport(e->pos());
- QListViewItem *item=itemAt(vp);
- if (IS_FOLDER(item)) {
- // drop on folder
- // don't allow more than one Quill file per project
- CATEGORY_OF(srcCategory,currItem);
- CATEGORY_OF(destCategory,item);
- if (qllFilesListItem && srcCategory != qllFilesListItem
- && destCategory == qllFilesListItem && qllFileCount)
- e->ignore();
- else
- e->accept();
- } else if (IS_FILE(item)) {
- // drop on file
- // need same parent, but different items
- if (currItem->parent() == item->parent()
- && currItem != item) e->accept(); else e->ignore();
- } else e->ignore();
- } else e->ignore();
- } else e->ignore();
- }
- };
- void MainForm::init()
- {
- fileNewFolderAction->setEnabled(FALSE);
- factory = (KParts::Factory *)
- KLibLoader::self()->factory ("libkatepart");
- if (!factory) exit(1);
- te_popup = new QPopupMenu(this);
- te_popup->insertItem("&Open file at cursor",0);
- te_popup->insertItem("&Find symbol declaration",1);
- te_popup->insertSeparator();
- te_popup->insertItem("&Undo",2);
- te_popup->insertItem("&Redo",3);
- te_popup->insertSeparator();
- te_popup->insertItem("&Clear",4);
- te_popup->insertItem("Cu&t",5);
- te_popup->insertItem("Cop&y",6);
- te_popup->insertItem("&Paste",7);
- te_popup->insertSeparator();
- te_popup->insertItem("&Select all",8);
- te_popup->insertSeparator();
- te_popup->insertItem("&Increase indent",9);
- te_popup->insertItem("&Decrease indent",10);
- connect(te_popup,SIGNAL(aboutToShow()),this,SLOT(te_popup_aboutToShow()));
- connect(te_popup,SIGNAL(activated(int)),this,SLOT(te_popup_activated(int)));
- QValueList<int> list;
- list.append(150);
- list.append(500);
- splitter->setSizes(list);
- leftStatusLabel=new QLabel("0 Files Total",this);
- leftStatusLabel->setMaximumWidth(splitter->sizes().first());
- statusBar()->addWidget(leftStatusLabel,1);
- rowStatusLabel=new QLabel("",this);
- rowStatusLabel->setAlignment(Qt::AlignRight);
- statusBar()->addWidget(rowStatusLabel,1);
- rowStatusLabel->hide();
- colStatusLabel=new QLabel("",this);
- colStatusLabel->setAlignment(Qt::AlignRight);
- statusBar()->addWidget(colStatusLabel,1);
- colStatusLabel->hide();
- charsStatusLabel=new QLabel("",this);
- statusBar()->addWidget(charsStatusLabel,1);
- charsStatusLabel->hide();
- rightStatusLabel=new QLabel("",this);
- rightStatusLabel->setMaximumWidth(splitter->sizes().last());
- statusBar()->addWidget(rightStatusLabel,1);
- statusBar()->setSizeGripEnabled(FALSE);
- connect(statusBar(),SIGNAL(messageChanged(const QString &)),this,SLOT(statusBar_messageChanged(const QString &)));
- fileTree->setSorting(-1);
- fileTree->setColumnWidthMode(0,QListView::Maximum);
- fileTree->header()->hide();
- loadPreferences(&preferences,pconfig);
- rootListItem=new QListViewItem(fileTree);
- rootListItem->setText(0,"Project1");
- rootListItem->setPixmap(0,QPixmap::fromMimeSource("tpr.png"));
- rootListItem->setOpen(TRUE);
- rootListItem->setDragEnabled(TRUE);
- QListViewItem *folderListItem=new ListViewFolder(rootListItem);
- hFilesListItem=folderListItem;
- folderListItem->setText(0,"Header Files");
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- cFilesListItem=folderListItem;
- folderListItem->setText(0,"C Files");
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- sFilesListItem=folderListItem;
- folderListItem->setText(0,"GNU Assembly Files");
- char a68k_path[strlen(tigcc_base)+10];
- sprintf(a68k_path, "%s/bin/a68k", tigcc_base);
- if(access(a68k_path, F_OK) != -1) {
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- asmFilesListItem=folderListItem;
- folderListItem->setText(0,"A68k Assembly Files");
- } else {
- qllFilesListItem=NULL;
- fileNewQuillSourceFileAction->setVisible(FALSE);
- }
- if (quill_drv) {
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- qllFilesListItem=folderListItem;
- folderListItem->setText(0,"Quill Files");
- } else {
- qllFilesListItem=NULL;
- fileNewQuillSourceFileAction->setVisible(FALSE);
- }
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- oFilesListItem=folderListItem;
- folderListItem->setText(0,"Object Files");
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- aFilesListItem=folderListItem;
- folderListItem->setText(0,"Archive Files");
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- txtFilesListItem=folderListItem;
- folderListItem->setText(0,"Text Files");
- folderListItem=new ListViewFolder(rootListItem,folderListItem);
- othFilesListItem=folderListItem;
- folderListItem->setText(0,"Other Files");
- khelpmenu=new KHelpMenu(this,pabout);
- assistant = new QAssistantClient("",this);
- QStringList args(QString("-profile"));
- args.append(QString("%1/doc/html/qt-assistant.adp").arg(tigcc_base));
- assistant->setArguments(args);
- lastDirectory=TIGCCProjectDirectory;
- projectFileName="";
- projectIsDirty=FALSE;
- connect(KDirWatch::self(),SIGNAL(created(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
- connect(KDirWatch::self(),SIGNAL(dirty(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
- KDirWatch::self()->startScan();
- clipboard=QApplication::clipboard();
- connect(clipboard,SIGNAL(dataChanged()),this,SLOT(clipboard_dataChanged()));
- accel=new QAccel(this);
- accel->insertItem(ALT+Key_Backspace,0);
- accel->setItemEnabled(0,FALSE);
- accel->insertItem(SHIFT+ALT+Key_Backspace,1);
- accel->setItemEnabled(1,FALSE);
- accel->insertItem(SHIFT+Key_Delete,2);
- accel->setItemEnabled(2,FALSE);
- accel->insertItem(CTRL+Key_Insert,3);
- accel->setItemEnabled(3,FALSE);
- accel->insertItem(SHIFT+Key_Insert,4);
- accel->setItemEnabled(4,FALSE);
- connect(accel,SIGNAL(activated(int)),this,SLOT(accel_activated(int)));
- pconfig->setGroup("Recent files");
- if (parg)
- openProject(parg);
- else {
- QString mostrecent=pconfig->readEntry("Current project");
- if (!mostrecent.isNull() && !mostrecent.isEmpty())
- openProject(mostrecent);
- }
- updateRecent();
- startTimer(100);
- }
- void MainForm::destroy()
- {
- delete accel;
- delete te_popup;
- delete leftStatusLabel;
- delete rowStatusLabel;
- delete colStatusLabel;
- delete charsStatusLabel;
- delete rightStatusLabel;
- delete rootListItem;
- delete khelpmenu;
- delete assistant;
- }
- void MainForm::te_popup_aboutToShow()
- {
- te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
- te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
- te_popup->setItemEnabled(2,editUndoAction->isEnabled());
- te_popup->setItemEnabled(3,editRedoAction->isEnabled());
- te_popup->setItemEnabled(4,editClearAction->isEnabled());
- te_popup->setItemEnabled(5,editCutAction->isEnabled());
- te_popup->setItemEnabled(6,editCopyAction->isEnabled());
- te_popup->setItemEnabled(7,editPasteAction->isEnabled());
- te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
- te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
- te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
- }
- void MainForm::te_popup_activated(int index)
- {
- switch (index) {
- case 0: findOpenFileAtCursor(); break;
- case 1: findFindSymbolDeclaration(); break;
- case 2: editUndo(); break;
- case 3: editRedo(); break;
- case 4: editClear(); break;
- case 5: editCut(); break;
- case 6: editCopy(); break;
- case 7: editPaste(); break;
- case 8: editSelectAll(); break;
- case 9: editIncreaseIndent(); break;
- case 10: editDecreaseIndent(); break;
- default: break;
- }
- }
- void MainForm::accel_activated(int index)
- {
- // FIXME: This doesn't work for the text box you get when renaming.
- switch (index) {
- case 0: editUndo(); break;
- case 1: editRedo(); break;
- case 2: editCut(); break;
- case 3: editCopy(); break;
- case 4: editPaste(); break;
- default: break;
- }
- }
- void MainForm::clearProject()
- {
- newSettings(&settings,&libopts);
- rootListItem->setText(0,"Project1");
- projectFileName="";
- fileTreeClicked(rootListItem);
- QListViewItem *f, *next;
- for (f=hFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- for (f=cFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- for (f=sFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- if (asmFilesListItem) {
- for (f=asmFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- }
- if (qllFilesListItem) {
- for (f=qllFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- }
- for (f=oFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- for (f=aFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- for (f=txtFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- for (f=othFilesListItem->firstChild();f;f=next) {
- next=f->nextSibling();
- delete f;
- }
- fileCount=cFileCount=hFileCount=sFileCount=asmFileCount=qllFileCount=oFileCount=aFileCount=txtFileCount=othFileCount=0;
- projectIsDirty=FALSE;
- updateLeftStatusLabel();
- }
- void MainForm::fileNewProject()
- {
- if (savePrompt())
- return;
- clearProject();
- pconfig->setGroup("Recent files");
- pconfig->writeEntry("Current project","");
- }
- QString MainForm::findFilter(unsigned short job)
- {
- QString ret;
- if (job==TIGCCOpenProjectFileFilter)
- {
- ret="*.tpr *.h *.c *.s ";
- if (asmFilesListItem)
- ret+="*.asm ";
- if (qllFilesListItem)
- ret+="*.qll ";
- ret+="*.txt";
- ret+="|All TIGCC Files ("+ret+")\n"
- TIGCC_TPR_Filter TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
- if (asmFilesListItem)
- ret+=TIGCC_ASM_Filter;
- if (qllFilesListItem)
- ret+=TIGCC_QLL_Filter;
- ret+=TIGCC_TXT_Filter TIGCCAllFilter;
- }
- else if (job==TIGCCAddFilesFilter)
- {
- ret="*.h *.c *.s ";
- if (asmFilesListItem)
- ret+="*.asm ";
- if (qllFilesListItem)
- ret+="*.qll ";
- ret+="*.o *.a *.txt";
- ret+="|All TIGCC Files ("+ret+")\n"
- TIGCC_H_Filter TIGCC_C_Filter TIGCC_S_Filter;
- if (asmFilesListItem)
- ret+=TIGCC_ASM_Filter;
- if (qllFilesListItem)
- ret+=TIGCC_QLL_Filter;
- ret+=TIGCC_O_Filter TIGCC_A_Filter TIGCC_TXT_Filter TIGCCAllFilter;
- }
- return ret;
- }
- QString MainForm::SGetFileName(int mode,const QString &fileFilter,const QString &caption,QWidget *parent)
- {
- QString ret;
- if (static_cast<KFileDialog::OperationMode>(mode)==KFileDialog::Opening)
- ret=KFileDialog::getOpenFileName(lastDirectory,fileFilter,parent,caption);
- else
- ret=KFileDialog::getSaveFileName(lastDirectory,fileFilter,parent,caption);
- if (!ret.isNull())
- {
- KURL dir;
- dir.setPath(ret);
- dir.setFileName("");
- lastDirectory=dir.path();
- }
- return ret;
- }
- //no mode, since it you can't save multiple.
- QStringList MainForm::SGetFileName_Multiple(const QString &fileFilter,const QString &caption,QWidget *parent)
- {
- QStringList ret;
- ret=KFileDialog::getOpenFileNames(lastDirectory,fileFilter,parent,caption);
- if (!ret.empty())
- {
- KURL dir;
- dir.setPath(ret[0]);
- dir.setFileName("");
- lastDirectory=dir.path();
- }
- return ret;
- }
- void MainForm::updateRecent()
- {
- pconfig->setGroup("Recent files");
- QString recent=pconfig->readEntry("Recent file 1");
- if (recent.isNull())
- fileRecent1Action->setVisible(FALSE);
- else {
- QString recentcut=recent.mid(recent.findRev('/')+1);
- recentcut.truncate(recentcut.findRev('.'));
- fileRecent1Action->setVisible(TRUE);
- fileRecent1Action->setText(recentcut);
- fileRecent1Action->setStatusTip(recent);
- }
- recent=pconfig->readEntry("Recent file 2");
- if (recent.isNull())
- fileRecent2Action->setVisible(FALSE);
- else {
- QString recentcut=recent.mid(recent.findRev('/')+1);
- recentcut.truncate(recentcut.findRev('.'));
- fileRecent2Action->setVisible(TRUE);
- fileRecent2Action->setText(recentcut);
- fileRecent2Action->setStatusTip(recent);
- }
- recent=pconfig->readEntry("Recent file 3");
- if (recent.isNull())
- fileRecent3Action->setVisible(FALSE);
- else {
- QString recentcut=recent.mid(recent.findRev('/')+1);
- recentcut.truncate(recentcut.findRev('.'));
- fileRecent3Action->setVisible(TRUE);
- fileRecent3Action->setText(recentcut);
- fileRecent3Action->setStatusTip(recent);
- }
- recent=pconfig->readEntry("Recent file 4");
- if (recent.isNull())
- fileRecent4Action->setVisible(FALSE);
- else {
- QString recentcut=recent.mid(recent.findRev('/')+1);
- recentcut.truncate(recentcut.findRev('.'));
- fileRecent4Action->setVisible(TRUE);
- fileRecent4Action->setText(recentcut);
- fileRecent4Action->setStatusTip(recent);
- }
- }
- void MainForm::addRecent(const QString &fileName)
- {
- unsigned i,j;
- pconfig->setGroup("Recent files");
- // Find recent file to overwrite. If it isn't one of the first 3, by
- // elimination, it is the last, thus the test only goes up to <4, not <=4.
- for (i=1;i<4;i++) {
- QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
- if (recenti.isNull() || !recenti.compare(fileName))
- break;
- }
- // Move entries up
- for (j=i;j>1;j--) {
- pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
- }
- // The first recent file is the current project.
- pconfig->writeEntry("Recent file 1",fileName);
- pconfig->writeEntry("Current project",fileName);
- updateRecent();
- }
- QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
- {
- QString fileText;
- if (getPathType(fileName)!=PATH_FILE) {
- KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
- return NULL;
- }
- if (IS_EDITABLE_CATEGORY(category)) {
- fileText=loadFileText(fileName);
- if (fileText.isNull()) {
- KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
- return NULL;
- }
- }
- QListViewItem *item=NULL, *next=parent->firstChild();
- for (; IS_FILE(next); next=item->nextSibling())
- item=next;
- ListViewFile *newFile=item?new ListViewFile(parent,item)
- :new ListViewFile(parent);
- newFile->isNew=FALSE;
- newFile->setText(0,fileCaption);
- newFile->setPixmap(0,QPixmap::fromMimeSource(
- category==cFilesListItem||category==qllFilesListItem?"filec.png":
- category==hFilesListItem?"fileh.png":
- category==sFilesListItem||category==asmFilesListItem?"files.png":
- category==txtFilesListItem?"filet.png":"filex.png"));
- newFile->fileName=fileName;
- if (IS_EDITABLE_CATEGORY(category)) {
- if (preferences.lazyLoading)
- newFile->textBuffer=fileText;
- else
- newFile->kateView=reinterpret_cast<Kate::View *>(createView(fileName,fileText,category));
- KDirWatch::self()->addFile(fileName);
- }
- fileCount++;
- COUNTER_FOR_CATEGORY(category)++;
- return newFile;
- }
- QListViewItem *MainForm::createFolder(QListViewItem *parent,const QString &name)
- {
- QListViewItem *item=parent->firstChild();
- QListViewItem *startItem=item;
- QListViewItem *newItem;
- for (; item; item=item->nextSibling())
- {
- if (IS_FOLDER(item) && !item->text(0).compare(name))
- return item;
- }
- item=NULL;
- for (;startItem;startItem=item->nextSibling())
- item=startItem;
- newItem=item?new ListViewFolder(parent,item)
- :new ListViewFolder(parent);
- newItem->setText(0,name);
- newItem->setOpen(TRUE);
- return newItem;
- }
- void *MainForm::createView(const QString &fileName, const QString &fileText, QListViewItem *category)
- {
- // Create Document object.
- KTextEditor::Document *doc = (KTextEditor::Document *)
- factory->createPart( 0, "", this, "", "KTextEditor::Document" );
- // Set the file name for printing.
- doc->setModified(FALSE);
- if (doc->openStream("text/plain",fileName))
- doc->closeStream();
- // Create View object.
- Kate::View *newView = (Kate::View *) doc->createView( widgetStack, 0L );
- newView->hide();
- newView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored,0,0));
- // Set highlighting mode.
- uint cnt=newView->getDoc()->hlModeCount(), i;
- for (i=0; i<cnt; i++) {
- if (!newView->getDoc()->hlModeName(i).compare(
- ((category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
- "GNU Assembler 68k":
- (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
- "Motorola Assembler 68k":
- (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?
- "C":
- "None"))) break;
- }
- if (i==cnt) i=0;
- newView->getDoc()->setHlMode(i);
- // Set options.
- dynWordWrapInterface(newView)->setDynWordWrap(FALSE);
- newView->setTabWidth(
- (category==sFilesListItem||category==asmFilesListItem||((category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&(fileText[0]=='|'||fileText[0]==';'))))?preferences.tabWidthAsm:
- (category==cFilesListItem||category==qllFilesListItem||category==hFilesListItem)?preferences.tabWidthC:
- 8
- );
- connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
- connect(newView->getDoc(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
- connect(newView->getDoc(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
- connect(newView->getDoc(),SIGNAL(selectionChanged()),this,SLOT(current_view_selectionChanged()));
- newView->installPopup(te_popup);
- // Set text.
- newView->getDoc()->setText(fileText);
- newView->getDoc()->setModified(FALSE);
- newView->getDoc()->clearUndo();
- newView->getDoc()->clearRedo();
- newView->setCursorPositionReal(0,0);
- return newView;
- }
- void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *dir, const QString &open_file)
- {
- int i,e;
- int p,pslash;
- KURL tmp;
- TPRFileList *fileList=(TPRFileList*)fileListV;
- QString caption;
- QString treePath;
- QListViewItem *parent;
- e=fileList->path.count();
- if (e) category->setOpen(TRUE);
- for (i=0;i<e;i++)
- {
- tmp=*reinterpret_cast<const KURL *>(dir);
- kurlNewFileName(tmp,fileList->path[i]);
- caption=fileList->path[i];
- //fixed suffix truncation for file paths such as "/root/.dot/nodot" so it wouldn't truncate to "/root/"
- p=caption.findRev('.');
- pslash=caption.findRev('/');
- if (p>=0&&p>pslash) caption.truncate(p);
- if (pslash>=0) caption.remove(0,pslash+1);
- treePath=fileList->folder[i].stripWhiteSpace();
- //check for a backslash at the end and remove it if it's there.
- if (treePath[treePath.length()-1]=='\\')
- treePath.truncate(treePath.length()-1);
- parent=category;
- if (!treePath.isEmpty())
- {
- while ((p=treePath.find('\\'))>=0)
- {
- parent=createFolder(parent,treePath.left(p));
- treePath.remove(0,p+1);
- }
- parent=createFolder(parent,treePath);
- }
-
- ListViewFile *newFile=static_cast<ListViewFile *>(openFile(category,parent,caption,tmp.path()));
- if (!newFile) continue;
- if (!newFile->fileName.compare(open_file))
- fileTreeClicked(newFile);
- }
- }
- void MainForm::openProject(const QString &fileName)
- {
- TPRDataStruct TPRData;
- KURL dir;
- dir.setPath(fileName);
- if (getPathType(fileName)!=PATH_FILE) {
- KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
- return;
- }
- int ret=loadTPR(fileName, &TPRData);
- if (ret == -1) {
- KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
- return;
- }
- if (ret > 0) {
- KMessageBox::error(this,QString("Error at line %2 of \'%1\'").arg(fileName).arg(ret));
- return;
- }
- if (TPRData.asm_files.path.count() && !asmFilesListItem) {
- KMessageBox::error(this,"This project needs A68k, which is not installed.");
- return;
- }
- if (TPRData.quill_files.path.count() && !qllFilesListItem) {
- KMessageBox::error(this,"This project needs quill.drv, which is not installed.");
- return;
- }
- clearProject();
- fileOpen_addList(hFilesListItem,&TPRData.h_files,&dir,TPRData.open_file);
- fileOpen_addList(cFilesListItem,&TPRData.c_files,&dir,TPRData.open_file);
- fileOpen_addList(qllFilesListItem,&TPRData.quill_files,&dir,TPRData.open_file);
- fileOpen_addList(sFilesListItem,&TPRData.s_files,&dir,TPRData.open_file);
- fileOpen_addList(asmFilesListItem,&TPRData.asm_files,&dir,TPRData.open_file);
- fileOpen_addList(oFilesListItem,&TPRData.o_files,&dir,TPRData.open_file);
- fileOpen_addList(aFilesListItem,&TPRData.a_files,&dir,TPRData.open_file);
- fileOpen_addList(txtFilesListItem,&TPRData.txt_files,&dir,TPRData.open_file);
- fileOpen_addList(othFilesListItem,&TPRData.oth_files,&dir,TPRData.open_file);
- rootListItem->setText(0,TPRData.prj_name);
- projectFileName=fileName;
- settings=TPRData.settings;
- libopts=TPRData.libopts;
- updateLeftStatusLabel();
- updateRightStatusLabel();
- addRecent(fileName);
- }
- void MainForm::fileOpen()
- {
- if (savePrompt())
- return;
- QString fileName=SGetFileName(KFileDialog::Opening,findFilter(TIGCCOpenProjectFileFilter),"Open Project/File",this);
- KURL dir;
- dir.setPath(fileName);
- if (fileName.isEmpty())
- return;
- openProject(fileName);
- }
- void MainForm::fileRecent1()
- {
- if (savePrompt())
- return;
- openProject(fileRecent1Action->statusTip());
- }
- void MainForm::fileRecent2()
- {
- if (savePrompt())
- return;
- openProject(fileRecent2Action->statusTip());
- }
- void MainForm::fileRecent3()
- {
- if (savePrompt())
- return;
- openProject(fileRecent3Action->statusTip());
- }
- void MainForm::fileRecent4()
- {
- if (savePrompt())
- return;
- openProject(fileRecent4Action->statusTip());
- }
- int MainForm::fileSavePrompt(QListViewItem *fileItem)
- {
- int result;
- ListViewFile *theFile=static_cast<ListViewFile *>(fileItem);
- if (!theFile->kateView) return 0;
- while (theFile->kateView->getDoc()->isModified()) { // "while" in case saving fails!
- 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());
- if (result==KMessageBox::Yes)
- fileSave_save(fileItem);
- else if (result==KMessageBox::No)
- theFile->kateView->getDoc()->setModified(FALSE);
- else
- return 1;
- }
- return 0;
- }
- //returns 1 if the current project data should not be cleared out, 0 if it can be cleared out.
- int MainForm::savePrompt(void)
- {
- int result;
-
- while (projectIsDirty) {
- result=KMessageBox::questionYesNoCancel(this,"The current project has been modified. Do you want to save the changes?",QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
- if (result==KMessageBox::Yes)
- fileSave();
- else if (result==KMessageBox::No)
- projectIsDirty=FALSE;
- else
- return 1;
- }
-
- QListViewItem *item=rootListItem->firstChild(),*next;
- while (item)
- {
- if (IS_FOLDER(item))
- {
- next=item->firstChild();
- if (next)
- {
- item=next;
- continue;
- }
- }
- if (IS_FILE(item))
- {
- if (fileSavePrompt(item))
- return 1;
- }
- next=item->nextSibling();
- while (!next)
- {
- next=item->parent();
- if (next==rootListItem||!next)
- {
- return 0;
- }
- item=next;
- next=item->nextSibling();
- }
- item=next;
- }
-
- return 0;
- }
- void MainForm::fileSave_save(QListViewItem *theItem)
- {
- if (!IS_FILE(theItem))
- return;
- CATEGORY_OF(category,theItem);
- if (!IS_EDITABLE_CATEGORY(category))
- return;
- ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
- if (theFile->fileName[0]!='/') {
- fileSave_saveAs(theFile);
- }
- else {
- KDirWatch::self()->removeFile(theFile->fileName);
- if (saveFileText(theFile->fileName,theFile->kateView?theFile->kateView->getDoc()->text():theFile->textBuffer)) {
- KMessageBox::error(this,QString("Can't save to \'%1\'").arg(theFile->text(0)));
- KDirWatch::self()->addFile(theFile->fileName);
- }
- else {
- KDirWatch::self()->addFile(theFile->fileName);
- theFile->isNew=FALSE;
- if (theFile->kateView)
- theFile->kateView->getDoc()->setModified(FALSE);
- projectIsDirty=TRUE;
- }
- }
- }
- void MainForm::fileSave_saveAs(QListViewItem *theItem)
- {
- if (!IS_FILE(theItem))
- return;
- CATEGORY_OF(category,theItem);
- QString saveFileName=SGetFileName(KFileDialog::Saving,
- category==hFilesListItem?TIGCC_H_Filter TIGCCAllFilter:
- category==cFilesListItem?TIGCC_C_Filter TIGCCAllFilter:
- category==sFilesListItem?TIGCC_S_Filter TIGCCAllFilter:
- category==asmFilesListItem?TIGCC_ASM_Filter TIGCCAllFilter:
- category==qllFilesListItem?TIGCC_QLL_Filter TIGCCAllFilter:
- category==oFilesListItem?TIGCC_O_Filter TIGCCAllFilter:
- category==aFilesListItem?TIGCC_A_Filter TIGCCAllFilter:
- category==txtFilesListItem?TIGCC_TXT_Filter TIGCCAllFilter:
- TIGCCAllFilter
- ,"Save Source File",this);
- ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
- if (saveFileName.isEmpty()
- || (!IS_EDITABLE_CATEGORY(category)
- && !saveFileName.compare(theFile->fileName)))
- return;
- if (saveFileName.compare(theFile->fileName)
- && !checkFileName(saveFileName,extractAllFileNames())) {
- KMessageBox::error(this,"The name you chose conflicts with that of another file.");
- return;
- }
- if (theFile->fileName[0]=='/')
- KDirWatch::self()->removeFile(theFile->fileName);
- if (IS_EDITABLE_CATEGORY(category)
- ?saveFileText(saveFileName,theFile->kateView?theFile->kateView->getDoc()->text():theFile->textBuffer)
- :copyFile(theFile->fileName,saveFileName)) {
- KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
- if (IS_EDITABLE_CATEGORY(category) && theFile->fileName[0]=='/')
- KDirWatch::self()->addFile(theFile->fileName);
- } else {
- if (IS_EDITABLE_CATEGORY(category) && saveFileName.compare(theFile->fileName)
- && theFile->kateView) {
- // Update the file name for printing.
- unsigned int line,col,hlMode;
- QString fileText=theFile->kateView->getDoc()->text();
- hlMode=theFile->kateView->getDoc()->hlMode();
- theFile->kateView->cursorPositionReal(&line,&col);
- theFile->kateView->getDoc()->setModified(FALSE);
- if (theFile->kateView->getDoc()->openStream("text/plain",saveFileName))
- theFile->kateView->getDoc()->closeStream();
- theFile->kateView->getDoc()->setText(fileText);
- theFile->kateView->getDoc()->clearUndo();
- theFile->kateView->getDoc()->clearRedo();
- theFile->kateView->getDoc()->setHlMode(hlMode);
- theFile->kateView->setCursorPositionReal(line,col);
- }
- theFile->fileName=saveFileName;
- if (IS_EDITABLE_CATEGORY(category)) {
- KDirWatch::self()->addFile(saveFileName);
- if (theFile->kateView)
- theFile->kateView->getDoc()->setModified(FALSE);
- }
- theFile->isNew=FALSE;
- updateRightStatusLabel();
- projectIsDirty=TRUE;
- }
- }
- //loadList also saves the file contents
- void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const QString &base_dir,void *dir_new,QString *open_file)
- {
- if (!category)
- return;
- TPRFileList *fileList=(TPRFileList*)fileListV;
- KURL *new_dir=(KURL*)dir_new;
- KURL tmpPath;
- QListViewItem *item=category->firstChild();
- QListViewItem *next;
- QString folderSpec=QString::null;
- int o;
- while (item)
- {
- if (IS_FILE(item))
- {
- ListViewFile *theFile=static_cast<ListViewFile *>(item);
- QString absPath=theFile->fileName;
- QString relPath=KURL::relativePath(base_dir,absPath);
- if (relPath.find("./")==0)
- {
- relPath=relPath.mid(2);
- }
- else if (relPath.find("../")==0)
- {
- relPath=absPath;
- }
-
- tmpPath=*new_dir;
- kurlNewFileName(tmpPath,relPath);
- if (theFile->fileName[0]=='/')
- KDirWatch::self()->removeFile(theFile->fileName);
- if (tmpPath.path().compare(theFile->fileName)
- || (IS_EDITABLE_CATEGORY(category)
- && ((theFile->kateView && theFile->kateView->getDoc()->isModified()) || theFile->isNew))) {
- if (IS_EDITABLE_CATEGORY(category)
- ?saveFileText(tmpPath.path(),theFile->kateView?theFile->kateView->getDoc()->text():theFile->textBuffer)
- :copyFile(theFile->fileName,tmpPath.path())) {
- KMessageBox::error(this,QString("Can't save to \'%1\'").arg(tmpPath.path()));
- if (IS_EDITABLE_CATEGORY(category) && theFile->fileName[0]=='/')
- KDirWatch::self()->addFile(theFile->fileName);
- } else {
- QString saveFileName=tmpPath.path();
- if (IS_EDITABLE_CATEGORY(category) && saveFileName.compare(theFile->fileName)
- && theFile->kateView) {
- // Update the file name for printing.
- unsigned int line,col,hlMode;
- QString fileText=theFile->kateView->getDoc()->text();
- hlMode=theFile->kateView->getDoc()->hlMode();
- theFile->kateView->cursorPositionReal(&line,&col);
- theFile->kateView->getDoc()->setModified(FALSE);
- if (theFile->kateView->getDoc()->openStream("text/plain",saveFileName))
- theFile->kateView->getDoc()->closeStream();
- theFile->kateView->getDoc()->setText(fileText);
- theFile->kateView->getDoc()->clearUndo();
- theFile->kateView->getDoc()->clearRedo();
- theFile->kateView->getDoc()->setHlMode(hlMode);
- theFile->kateView->setCursorPositionReal(line,col);
- }
- theFile->fileName=saveFileName;
- if (IS_EDITABLE_CATEGORY(category)) {
- KDirWatch::self()->addFile(theFile->fileName);
- if (theFile->kateView)
- theFile->kateView->getDoc()->setModified(FALSE);
- }
- theFile->isNew=FALSE;
- projectIsDirty=TRUE; // in case saving the project fails
- }
- }
-
- fileList->path << relPath;
- fileList->folder << folderSpec;
-
- if (item==currentListItem)
- *open_file=theFile->fileName;
- }
- else if (IS_FOLDER(item))
- {
- next=item->firstChild();
- if (next)
- {
- if (folderSpec.isEmpty())
- folderSpec=item->text(0);
- else
- {
- folderSpec+='\\';
- folderSpec+=item->text(0);
- }
- item=next;
- continue;
- }
- }
- fsll_seeknext:
- next=item->nextSibling();
- if (!next)
- {
- next=item->parent();
- if (next==category||!next)
- break;
- item=next;
- o=folderSpec.findRev('\\');
- if (o>=0)
- folderSpec.truncate(o);
- else
- folderSpec.truncate(0);
- goto fsll_seeknext;
- }
- item=next;
- }
- }
- void MainForm::fileSave_fromto(const QString &lastProj,const QString &nextProj)
- {
- TPRDataStruct TPRData;
- QString open_file;
- KURL base_dir_k(lastProj);
- base_dir_k.setFileName("");
- QString base_dir=base_dir_k.path();
- KURL new_dir(nextProj);
-
- fileSave_loadList(hFilesListItem,&TPRData.h_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(cFilesListItem,&TPRData.c_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(qllFilesListItem,&TPRData.quill_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(sFilesListItem,&TPRData.s_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(asmFilesListItem,&TPRData.asm_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(oFilesListItem,&TPRData.o_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(aFilesListItem,&TPRData.a_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(txtFilesListItem,&TPRData.txt_files,base_dir,&new_dir,&open_file);
- fileSave_loadList(othFilesListItem,&TPRData.oth_files,base_dir,&new_dir,&open_file);
- TPRData.prj_name=rootListItem->text(0);
- TPRData.open_file=open_file;
- TPRData.settings=settings;
- TPRData.libopts=libopts;
-
- if (saveTPR(nextProj,&TPRData))
- KMessageBox::error(this,QString("Can't save to \'%1\'").arg(nextProj));
- else {
- projectFileName=nextProj;
- projectIsDirty=FALSE;
- addRecent(nextProj);
- }
- updateRightStatusLabel();
- }
- void MainForm::fileSave()
- {
- if (projectFileName.isEmpty())
- fileSaveAs();
- else
- fileSave_fromto(projectFileName,projectFileName);
- }
- void MainForm::fileSaveAs()
- {
- QString fileName=SGetFileName(KFileDialog::Saving,TIGCC_TPR_Filter TIGCCAllFilter,"Save Project",this);
- if (fileName.isEmpty())
- return;
- fileSave_fromto(projectFileName,fileName);
- }
- void MainForm::filePrint()
- {
- if (CURRENT_VIEW) CURRENT_VIEW->getDoc()->printDialog();
- }
- void MainForm::filePrintQuickly()
- {
- if (CURRENT_VIEW) CURRENT_VIEW->getDoc()->print();
- }
- void MainForm::filePreferences()
- {
-
- }
- void MainForm::editUndo()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->getDoc()->undo();
- }
- void MainForm::editRedo()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->getDoc()->redo();
- }
- void MainForm::editClear()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->getDoc()->removeSelectedText();
- }
- void MainForm::editCut()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->cut();
- }
- void MainForm::editCopy()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->copy();
- }
- void MainForm::editPaste()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->paste();
- }
- void MainForm::editSelectAll()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->getDoc()->selectAll();
- }
- void MainForm::editIncreaseIndent()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->indent();
- }
- void MainForm::editDecreaseIndent()
- {
- if (CURRENT_VIEW)
- CURRENT_VIEW->unIndent();
- }
- void MainForm::findFind()
- {
-
- }
- void MainForm::findReplace()
- {
-
- }
- void MainForm::findFunctions()
- {
-
- }
- void MainForm::findOpenFileAtCursor()
- {
-
- }
- void MainForm::findFindSymbolDeclaration()
- {
- }
- //returns 1 on success
- int MainForm::projectAddFiles_oneFile(const QString &fileName)
- {
- QListViewItem *category=othFilesListItem;
- QString suffix,caption;
- int p;
-
- p=fileName.findRev('/');
- if (p<0) p=-1;
- caption=fileName.mid(p+1);
- p=caption.findRev('.');
- if (p>=0) {
- suffix=caption.mid(p+1);
- caption.truncate(p);
- }
-
- if (!checkFileName(fileName,extractAllFileNames())) {
- KMessageBox::error(this,QString("The file \'%1\' is already included in the project.").arg(caption));
- return 0;
- }
- if (!suffix.compare("h"))
- category=hFilesListItem;
- else if (!suffix.compare("c"))
- category=cFilesListItem;
- else if (!suffix.compare("s"))
- category=sFilesListItem;
- else if (!suffix.compare("asm"))
- category=asmFilesListItem;
- else if (!suffix.compare("qll"))
- category=qllFilesListItem;
- else if (!suffix.compare("o"))
- category=oFilesListItem;
- else if (!suffix.compare("a"))
- category=aFilesListItem;
- else if (!suffix.compare("txt"))
- category=txtFilesListItem;
-
- if (qllFileCount) {
- KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
- return 0;
- }
- if (!category)
- category=othFilesListItem;
-
- if (openFile(category,category,caption,fileName))
- return 1;
- return 0;
- }
- void MainForm::projectAddFiles()
- {
- unsigned long i,e;
- int projectChanged=0;
- QStringList result=SGetFileName_Multiple(findFilter(TIGCCAddFilesFilter),"Add Files",this);
- e=result.count();
- for (i=0;i<e;i++) {
- if (projectAddFiles_oneFile(result[i]))
- projectChanged=TRUE;
- }
- if (projectChanged) {
- projectIsDirty=TRUE;
- }
- }
- void MainForm::projectCompile()
- {
-
- }
- void MainForm::projectMake()
- {
-
- }
- void MainForm::projectBuild()
- {
-
- }
- void MainForm::errorsAndWarnings()
- {
-
- }
- void MainForm::projectProgramOutput()
- {
-
- }
- void MainForm::projectOptions()
- {
- //You CANNOT create projectoptions in the stack. I tried it, and it causes a crash when you try to close the dialog.
- //PS: Last time I checked, sizeof(ProjectOptions)==508
- ProjectOptions *projectoptions=new ProjectOptions(this);
- projectoptions->exec();
- delete(projectoptions);
- }
- void MainForm::debugRun()
- {
-
- }
- void MainForm::debugPause()
- {
-
- }
- void MainForm::debugReset()
- {
-
- }
- void MainForm::toolsConfigure()
- {
-
- }
- void MainForm::helpDocumentation()
- {
- assistant->openAssistant();
- }
- void MainForm::helpContents()
- {
- force_qt_assistant_page(0);
- assistant->openAssistant();
- }
- void MainForm::helpIndex()
- {
- force_qt_assistant_page(1);
- assistant->openAssistant();
- }
- void MainForm::helpSearch()
- {
- force_qt_assistant_page(3);
- assistant->openAssistant();
- }
- void MainForm::helpNews()
- {
-
- }
- void MainForm::helpAbout()
- {
- khelpmenu->aboutApplication();
- }
- void MainForm::updateSizes()
- {
- int leftSize=splitter->sizes().first();
- int rightSize=splitter->sizes().last();
- int totalSize=leftSize+rightSize;
- int mySize=size().width();
- leftStatusLabel->setMaximumWidth(leftSize*mySize/totalSize);
- rightStatusLabel->setMaximumWidth(rightSize*mySize/totalSize-10>0?
- rightSize*mySize/totalSize-10:0);
- }
- void MainForm::resizeEvent(QResizeEvent *event)
- {
- QMainWindow::resizeEvent(event);
- if (event->size()==event->oldSize()) return;
- updateSizes();
- }
- void MainForm::timerEvent(QTimerEvent *event)
- {
- static int lastSplitterPos=-1;
- QMainWindow::timerEvent(event);
- if (lastSplitterPos==splitter->sizes().first()) return;
- lastSplitterPos=splitter->sizes().first();
- updateSizes();
- }
- void MainForm::fileTreeClicked(QListViewItem *item)
- {
- if (!item) return;
- if (IS_FOLDER(currentListItem))
- currentListItem->setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- if (IS_FILE(currentListItem)) {
- CATEGORY_OF(category,currentListItem);
- if (IS_EDITABLE_CATEGORY(category) && static_cast<ListViewFile *>(currentListItem)->kateView) {
- static_cast<ListViewFile *>(currentListItem)->kateView->hide();
- widgetStack->removeWidget(static_cast<ListViewFile *>(currentListItem)->kateView);
- widgetStack->raiseWidget(-1);
- }
- }
- if (IS_FOLDER(item)) {
- item->setPixmap(0,QPixmap::fromMimeSource("folder2.png"));
- fileNewFolderAction->setEnabled(TRUE);
- filePrintAction->setEnabled(FALSE);
- filePrintQuicklyAction->setEnabled(FALSE);
- editUndoAction->setEnabled(FALSE);
- editRedoAction->setEnabled(FALSE);
- editClearAction->setEnabled(FALSE);
- editCutAction->setEnabled(FALSE);
- editCopyAction->setEnabled(FALSE);
- editPasteAction->setEnabled(FALSE);
- editSelectAllAction->setEnabled(FALSE);
- editIncreaseIndentAction->setEnabled(FALSE);
- editDecreaseIndentAction->setEnabled(FALSE);
- accel->setItemEnabled(0,FALSE);
- accel->setItemEnabled(1,FALSE);
- accel->setItemEnabled(2,FALSE);
- accel->setItemEnabled(3,FALSE);
- accel->setItemEnabled(4,FALSE);
- } else if (IS_FILE(item)) {
- fileNewFolderAction->setEnabled(TRUE);
- CATEGORY_OF(category,item->parent());
- if (IS_EDITABLE_CATEGORY(category)) {
- Kate::View *kateView=static_cast<ListViewFile *>(item)->kateView;
- if (!kateView) { // lazy loading
- kateView=reinterpret_cast<Kate::View *>(createView(static_cast<ListViewFile *>(item)->fileName,static_cast<ListViewFile *>(item)->textBuffer,category));
- static_cast<ListViewFile *>(item)->textBuffer=QString::null;
- static_cast<ListViewFile *>(item)->kateView=kateView;
- }
- filePrintAction->setEnabled(TRUE);
- filePrintQuicklyAction->setEnabled(TRUE);
- widgetStack->addWidget(kateView);
- kateView->show();
- widgetStack->raiseWidget(kateView);
- editUndoAction->setEnabled(!!(kateView->getDoc()->undoCount()));
- editRedoAction->setEnabled(!!(kateView->getDoc()->redoCount()));
- editClearAction->setEnabled(kateView->getDoc()->hasSelection());
- editCutAction->setEnabled(kateView->getDoc()->hasSelection());
- editCopyAction->setEnabled(kateView->getDoc()->hasSelection());
- editPasteAction->setEnabled(!clipboard->text().isNull());
- editSelectAllAction->setEnabled(TRUE);
- editIncreaseIndentAction->setEnabled(TRUE);
- editDecreaseIndentAction->setEnabled(TRUE);
- accel->setItemEnabled(0,!!(kateView->getDoc()->undoCount()));
- accel->setItemEnabled(1,!!(kateView->getDoc()->redoCount()));
- accel->setItemEnabled(2,kateView->getDoc()->hasSelection());
- accel->setItemEnabled(3,kateView->getDoc()->hasSelection());
- accel->setItemEnabled(4,!clipboard->text().isNull());
- } else {
- filePrintAction->setEnabled(FALSE);
- filePrintQuicklyAction->setEnabled(FALSE);
- editUndoAction->setEnabled(FALSE);
- editRedoAction->setEnabled(FALSE);
- editClearAction->setEnabled(FALSE);
- editCutAction->setEnabled(FALSE);
- editCopyAction->setEnabled(FALSE);
- editPasteAction->setEnabled(FALSE);
- editSelectAllAction->setEnabled(FALSE);
- editIncreaseIndentAction->setEnabled(FALSE);
- editDecreaseIndentAction->setEnabled(FALSE);
- accel->setItemEnabled(0,FALSE);
- accel->setItemEnabled(1,FALSE);
- accel->setItemEnabled(2,FALSE);
- accel->setItemEnabled(3,FALSE);
- accel->setItemEnabled(4,FALSE);
- }
- } else {
- fileNewFolderAction->setEnabled(FALSE);
- filePrintAction->setEnabled(FALSE);
- filePrintQuicklyAction->setEnabled(FALSE);
- editUndoAction->setEnabled(FALSE);
- editRedoAction->setEnabled(FALSE);
- editClearAction->setEnabled(FALSE);
- editCutAction->setEnabled(FALSE);
- editCopyAction->setEnabled(FALSE);
- editPasteAction->setEnabled(FALSE);
- editSelectAllAction->setEnabled(FALSE);
- editIncreaseIndentAction->setEnabled(FALSE);
- editDecreaseIndentAction->setEnabled(FALSE);
- accel->setItemEnabled(0,FALSE);
- accel->setItemEnabled(1,FALSE);
- accel->setItemEnabled(2,FALSE);
- accel->setItemEnabled(3,FALSE);
- accel->setItemEnabled(4,FALSE);
- }
- currentListItem=item;
- updateLeftStatusLabel();
- updateRightStatusLabel();
- }
- void MainForm::fileNewFolder()
- {
- if (IS_FILE(currentListItem))
- currentListItem=currentListItem->parent();
- QListViewItem *item=NULL, *next=currentListItem->firstChild();
- for (; next; next=item->nextSibling())
- {
- item=next;
- }
- QListViewItem *newFolder=item?new ListViewFolder(currentListItem,item)
- :new ListViewFolder(currentListItem);
- newFolder->setText(0,"NewFolder");
- newFolder->setRenameEnabled(0,TRUE);
- currentListItem->setOpen(TRUE);
- fileTreeClicked(newFolder);
- newFolder->startRename(0);
- projectIsDirty=TRUE;
- }
- #define unused_col __attribute__((unused)) col /* stupid QT designer... */
- void MainForm::fileTreeContextMenuRequested(QListViewItem *item,
- const QPoint &pos,
- int unused_col)
- {
- fileTreeClicked(item);
- if (IS_FOLDER(item)) {
- QPopupMenu menu;
- menu.insertItem("New &Folder",0);
- menu.insertItem("New F&ile",1);
- CATEGORY_OF(category,item);
- if (!IS_EDITABLE_CATEGORY(category))
- menu.setItemEnabled(1,FALSE);
- if (!IS_CATEGORY(item)) {
- menu.insertSeparator();
- menu.insertItem("&Remove",2);
- menu.insertItem("Re&name",3);
- }
- switch (menu.exec(pos)) {
- case 0:
- fileNewFolder();
- break;
- case 1:
- newFile(item);
- break;
- case 2:
- delete item;
- currentListItem=NULL;
- fileTreeClicked(fileTree->currentItem());
- projectIsDirty=TRUE;
- break;
- case 3:
- item->startRename(0);
- }
- } else if (IS_FILE(item)) {
- QPopupMenu menu;
- ListViewFile *theFile=static_cast<ListViewFile *>(item);
- menu.insertItem("&Save",0);
- CATEGORY_OF(category,item);
- if (!IS_EDITABLE_CATEGORY(category))
- menu.setItemEnabled(0,FALSE);
- menu.insertItem("Save &As...",1);
- menu.insertSeparator();
- menu.insertItem("&Compile",2);
- if (category==txtFilesListItem
- || !IS_EDITABLE_CATEGORY(category))
- menu.setItemEnabled(2,FALSE);
- menu.insertSeparator();
- menu.insertItem("&Remove",3);
- menu.insertItem("&Delete",4);
- if (theFile->isNew)
- menu.setItemEnabled(4,FALSE);
- menu.insertSeparator();
- menu.insertItem("Re&name",5);
- switch (menu.exec(pos)) {
- case 0:
- fileSave_save(item);
- break;
- case 1:
- fileSave_saveAs(item);
- break;
- case 2:
- // compiling not implemented yet!
- break;
- case 3:
- if (!fileSavePrompt(item)) {
- delete item;
- currentListItem=NULL;
- fileTreeClicked(fileTree->currentItem());
- projectIsDirty=TRUE;
- }
- break;
- case 4:
- if (KMessageBox::questionYesNo(this,
- "Are you sure you want to delete this source file? "
- "You cannot undo this operation.","Confirm Deletion")
- ==KMessageBox::Yes) {
- QString fileName=theFile->fileName;
- KDirWatch::self()->removeFile(fileName);
- if (QDir().remove(fileName)) {
- delete item;
- currentListItem=NULL;
- fileTreeClicked(fileTree->currentItem());
- projectIsDirty=TRUE;
- } else {
- KMessageBox::error(this,
- QString("Error deleting file \'%1\'").arg(fileName));
- if (IS_EDITABLE_CATEGORY(category) && fileName[0]=='/')
- KDirWatch::self()->addFile(fileName);
- }
- }
- break;
- case 5:
- item->startRename(0);
- }
- }
- }
- QStringList MainForm::extractAllFileNames(void)
- {
- QListViewItem *item=rootListItem->firstChild(),*next;
- QStringList allFiles;
- while (item)
- {
- if (IS_FOLDER(item))
- {
- next=item->firstChild();
- if (next)
- {
- item=next;
- continue;
- }
- }
- if (IS_FILE(item))
- {
- allFiles << (static_cast<ListViewFile *>(item)->fileName);
- }
- next=item->nextSibling();
- while (!next)
- {
- next=item->parent();
- if (next==rootListItem||!next)
- {
- return allFiles;
- }
- item=next;
- next=item->nextSibling();
- }
- item=next;
- }
- return allFiles;
- }
- //you put in parent, and it gives you the rest, but you must have a place to put it all.
- void MainForm::extractFileTreeInfo(QListViewItem *parent,QListViewItem **p_category,QString *p_folderPath)
- {
- QListViewItem *item,*next;
- QString tmp=QString::null;
- int o;
- CATEGORY_OF(category,parent);
- *p_category=category;
- item=category->firstChild();
- while (item)
- {
- if (item==parent)
- {
- if (!tmp.isEmpty())
- tmp+='/';
- tmp+=item->text(0);
- *p_folderPath=tmp;
- }
- if (IS_FOLDER(item))
- {
- next=item->firstChild();
- if (next)
- {
- if (tmp.isEmpty())
- tmp=item->text(0);
- else
- {
- tmp+='/';
- tmp+=item->text(0);
- }
- item=next;
- continue;
- }
- }
- mfnf_seeknext:
- next=item->nextSibling();
- if (!next)
- {
- next=item->parent();
- if (next==category||!next)
- break;
- item=next;
- o=tmp.findRev('/');
- if (o>=0)
- tmp.truncate(o);
- else
- tmp.truncate(0);
- goto mfnf_seeknext;
- }
- item=next;
- }
- }
- void MainForm::newFile( QListViewItem *parent, QString text, const char *iconName )
- {
- QListViewItem *item=NULL, *next=parent->firstChild();
- QString tmp,oldtmp,suffix,caption;
- QStringList allFiles=extractAllFileNames();
- QListViewItem *category;
- KURL tmpK;
- int tryNum;
- for (; IS_FILE(next); next=item->nextSibling())
- item=next;
- extractFileTreeInfo(parent,&category,&tmp);
-
- suffix="";
- if (category==hFilesListItem)
- suffix="h";
- else if (category==cFilesListItem)
- suffix="c";
- else if (category==sFilesListItem)
- suffix="s";
- else if (category==asmFilesListItem)
- suffix="asm";
- else if (category==qllFilesListItem) {
- if (qllFileCount) {
- KMessageBox::error(this,"There may be only one Quill source file in each project.","Quill Error");
- return;
- }
- suffix="qll";
- } else if (category==oFilesListItem)
- suffix="o";
- else if (category==aFilesListItem)
- suffix="a";
- else if (category==txtFilesListItem)
- suffix="txt";
- suffix='.'+suffix;
-
- if (!tmp.isEmpty())
- tmp+='/';
- tmp+="New File";
- tmpK.setPath(projectFileName);
- kurlNewFileName(tmpK,tmp);
- tmp=tmpK.path();
- if (projectFileName.isEmpty())
- {
- short o=0;
- if (tmp[0]=='.')
- o=1;
- if (tmp[o]=='/')
- tmp=tmp.mid(o+1);
- }
-
- caption="New File";
- oldtmp=tmp+' ';
- tmp+=suffix;
- tryNum=1;
- while (!checkFileName(tmp,allFiles))
- {
- tryNum++;
- tmp=oldtmp+QString("%1").arg(tryNum)+suffix;
- caption="New File "+QString("%1").arg(tryNum);
- }
-
- ListViewFile *newFile=item?new ListViewFile(parent,item)
- :new ListViewFile(parent);
-
- newFile->fileName=tmp;
- if (IS_EDITABLE_CATEGORY(category) && tmp[0]=='/')
- KDirWatch::self()->addFile(tmp);
-
- newFile->setText(0,caption);
- newFile->setPixmap(0,QPixmap::fromMimeSource(iconName));
- parent->setOpen(TRUE);
- newFile->kateView=reinterpret_cast<Kate::View *>(createView(tmp,text,category));
- fileTreeClicked(newFile);
- projectIsDirty=TRUE;
- newFile->startRename(0);
-
- fileCount++;
-
- COUNTER_FOR_CATEGORY(category)++;
- updateLeftStatusLabel();
- }
- void MainForm::newFile( QListViewItem *parent )
- {
- CATEGORY_OF(category,parent);
- newFile(parent,category==txtFilesListItem?"":
- ((category==hFilesListItem?"// Header File\n//":
- category==cFilesListItem?"// C Source File\n//":
- category==sFilesListItem?"| Assembly Source File\n|":
- category==asmFilesListItem?"; Assembly Source File\n;":
- category==qllFilesListItem?"// Quill Source File\n//":"???\n")
- +QString(" Created ")
- +QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n"+
- QString(category==cFilesListItem?(cFileCount?
- "\n#include <tigcclib.h>\n":
- "\n// Delete or comment out the items you do not need.\n"
- "#define COMMENT_STRING \"Place your comment here.\"\n"
- "#define COMMENT_PROGRAM_NAME "
- "\"Place your program name here.\"\n"
- "#define COMMENT_VERSION_STRING "
- "\"Place your version string here.\"\n"
- "#define COMMENT_VERSION_NUMBER 0,0,0,0 "
- "/* major, minor, revision, subrevision */\n"
- "#define COMMENT_AUTHORS "
- "\"Place your author name(s) here.\"\n"
- "#define COMMENT_BW_ICON \\\n"
- "\t{0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000}\n"
- "#define COMMENT_GRAY_ICON \\\n"
- "\t{0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000}, \\\n"
- "\t{0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000, \\\n"
- "\t 0b0000000000000000}\n\n#include <tigcclib.h>\n\n"
- "// Main Function\nvoid _main(void)\n{\n"
- "\t// Place your code here.\n}\n"):"")),
- category==cFilesListItem||category==qllFilesListItem
- ?"filec.png":
- category==hFilesListItem?"fileh.png":
- category==sFilesListItem||category==asmFilesListItem
- ?"files.png":
- category==txtFilesListItem?"filet.png":"filex.png");
- }
- QListViewItem *MainForm::resolveParent(QListViewItem *category)
- {
- QListViewItem *ret=currentListItem;
- if (!IS_FILE(ret)&&!IS_FOLDER(ret))
- return category;
- if (IS_FILE(ret))
- ret=ret->parent();
- QListViewItem *actualCategory=ret;
- while (IS_FOLDER(actualCategory->parent())) actualCategory=actualCategory->parent();
- if (actualCategory!=category)
- return category;
- return ret;
- }
- void MainForm::fileNewCHeader()
- {
- newFile(resolveParent(hFilesListItem),"// Header File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
- }
- void MainForm::fileNewGNUAssemblyHeader()
- {
- newFile(resolveParent(hFilesListItem),"| Header File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
- }
- void MainForm::fileNewA68kAssemblyHeader()
- {
- newFile(resolveParent(hFilesListItem),"; Header File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","fileh.png");
- }
- void MainForm::fileNewCSourceFile()
- {
- newFile(resolveParent(cFilesListItem));
- }
- void MainForm::fileNewGNUAssemblySourceFile()
- {
- newFile(resolveParent(sFilesListItem),"| Assembly Source File\n| Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
- }
- void MainForm::fileNewA68kAssemblySourceFile()
- {
- newFile(resolveParent(asmFilesListItem),"; Assembly Source File\n; Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","files.png");
- }
- void MainForm::fileNewQuillSourceFile()
- {
- newFile(resolveParent(qllFilesListItem),"// Quill Source File\n// Created "+QDateTime::currentDateTime ().toString(Qt::LocalDate)+"\n","filec.png");
- }
- void MainForm::fileNewTextFile()
- {
- newFile(resolveParent(txtFilesListItem),"","filet.png");
- }
- void MainForm::updateLeftStatusLabel()
- {
- QString text=QString::number(fileCount)+QString(" File")
- +QString(fileCount!=1?"s":"")+QString(" Total");
- if (IS_FOLDER(currentListItem)||IS_FILE(currentListItem)) {
- CATEGORY_OF(category,currentListItem);
- text+=QString(", ")+QString::number(COUNTER_FOR_CATEGORY(category))
- +QString(" in Category");
- }
- leftStatusLabel->setText(text);
- }
- void MainForm::statusBar_messageChanged(const QString & message)
- {
- if (message.isNull())
- // Make sure no labels which should be hidden are shown.
- updateRightStatusLabel();
- }
- void MainForm::updateRightStatusLabel()
- {
- int leftSize=splitter->sizes().first();
- int rightSize=splitter->sizes().last();
- int totalSize=leftSize+rightSize;
- int mySize=size().width();
- int rightStatusSize=rightSize*mySize/totalSize-10>0?
- rightSize*mySize/totalSize-10:0;
- if (currentListItem==rootListItem) {
- rowStatusLabel->hide();
- colStatusLabel->hide();
- charsStatusLabel->hide();
- rightStatusLabel->setMaximumWidth(rightStatusSize);
- rightStatusLabel->setText(projectFileName);
- } else if (IS_FOLDER(currentListItem)) {
- rowStatusLabel->hide();
- colStatusLabel->hide();
- charsStatusLabel->hide();
- rightStatusLabel->setMaximumWidth(rightStatusSize);
- rightStatusLabel->setText("");
- } else if (IS_FILE(currentListItem)) {
- CATEGORY_OF(category,currentListItem);
- if (IS_EDITABLE_CATEGORY(category) && CURRENT_VIEW) {
- unsigned int line, col;
- CURRENT_VIEW->cursorPositionReal(&line,&col);
- rowStatusLabel->show();
- rowStatusLabel->setMaximumWidth(30);
- rowStatusLabel->setText(QString("%1").arg(line+1));
- colStatusLabel->show();
- colStatusLabel->setMaximumWidth(30);
- colStatusLabel->setText(QString("%1").arg(col+1));
- charsStatusLabel->show();
- charsStatusLabel->setMaximumWidth(100);
- charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->getDoc()->text().length()));
- rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
- } else {
- rowStatusLabel->hide();
- colStatusLabel->hide();
- charsStatusLabel->hide();
- rightStatusLabel->setMaximumWidth(rightStatusSize);
- }
- rightStatusLabel->setText(static_cast<ListViewFile *>(currentListItem)->fileName);
- }
- }
- void MainForm::current_view_cursorPositionChanged()
- {
- if (CURRENT_VIEW) {
- unsigned int line, col;
- CURRENT_VIEW->cursorPositionReal(&line,&col);
- rowStatusLabel->setText(QString("%1").arg(line+1));
- colStatusLabel->setText(QString("%1").arg(col+1));
- }
- }
- void MainForm::current_view_textChanged()
- {
- if (CURRENT_VIEW)
- charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->getDoc()->text().length()));
- }
- void MainForm::current_view_undoChanged()
- {
- if (CURRENT_VIEW) {
- editUndoAction->setEnabled(!!(CURRENT_VIEW->getDoc()->undoCount()));
- editRedoAction->setEnabled(!!(CURRENT_VIEW->getDoc()->redoCount()));
- accel->setItemEnabled(0,!!(CURRENT_VIEW->getDoc()->undoCount()));
- accel->setItemEnabled(1,!!(CURRENT_VIEW->getDoc()->redoCount()));
- }
- }
- void MainForm::current_view_selectionChanged()
- {
- if (CURRENT_VIEW) {
- editClearAction->setEnabled(CURRENT_VIEW->getDoc()->hasSelection());
- editCutAction->setEnabled(CURRENT_VIEW->getDoc()->hasSelection());
- editCopyAction->setEnabled(CURRENT_VIEW->getDoc()->hasSelection());
- accel->setItemEnabled(2,CURRENT_VIEW->getDoc()->hasSelection());
- accel->setItemEnabled(3,CURRENT_VIEW->getDoc()->hasSelection());
- }
- }
- void MainForm::clipboard_dataChanged()
- {
- if (CURRENT_VIEW) {
- editPasteAction->setEnabled(!clipboard->text().isNull());
- accel->setItemEnabled(4,!clipboard->text().isNull());
- }
- }
- void MainForm::fileTreeItemRenamed( QListViewItem *item, int col, const QString &newName)
- {
- if (col)
- return;
- if (!IS_FILE(item))
- return;
- ListViewFile *theFile=static_cast<ListViewFile *>(item);
- QString suffix;
- QString oldLabel;
- QString &fileNameRef=theFile->fileName;
- QString oldFileName=fileNameRef;
- QString newFileName=fileNameRef;
- int o,s;
-
- o=oldFileName.findRev('.');
- s=oldFileName.findRev('/');
- if (o>=0&&(s<0||o>s)) {
- suffix=oldFileName.mid(o+1);
- newFileName.truncate(o);
- } else {
- suffix=QString::null;
- }
- if (s>=0) {
- oldLabel=newFileName.mid(s+1);
- newFileName.truncate(s+1);
- } else {
- oldLabel=newFileName;
- newFileName.truncate(0);
- }
- if (!oldLabel.compare(newName))
- return; //no changes are needed, and we don't want it to complain about the file conflicting with itself!
- newFileName+=newName;
- newFileName+='.';
- newFileName+=suffix;
-
- if (checkFileName(newFileName,extractAllFileNames())) {
- CATEGORY_OF(category,item);
- if (oldFileName[0]=='/')
- KDirWatch::self()->removeFile(oldFileName);
- if (!theFile->isNew && !QDir().rename(oldFileName,newFileName)) {
- KMessageBox::error(this,"Failed to rename the file.");
- theFile->setText(0,oldLabel);
- if (IS_EDITABLE_CATEGORY(category) && oldFileName[0]=='/')
- KDirWatch::self()->addFile(oldFileName);
- } else {
- fileNameRef=newFileName;
- if (theFile->kateView) {
- // Update the file name for printing.
- unsigned int line,col,hlMode,modified;
- modified=theFile->kateView->getDoc()->isModified();
- QString fileText=theFile->kateView->getDoc()->text();
- hlMode=theFile->kateView->getDoc()->hlMode();
- theFile->kateView->cursorPositionReal(&line,&col);
- theFile->kateView->getDoc()->setModified(FALSE);
- if (theFile->kateView->getDoc()->openStream("text/plain",newFileName))
- theFile->kateView->getDoc()->closeStream();
- theFile->kateView->getDoc()->setText(fileText);
- theFile->kateView->getDoc()->clearUndo();
- theFile->kateView->getDoc()->clearRedo();
- theFile->kateView->getDoc()->setHlMode(hlMode);
- theFile->kateView->setCursorPositionReal(line,col);
- theFile->kateView->getDoc()->setModified(modified);
- }
- if (IS_EDITABLE_CATEGORY(category) && newFileName[0]=='/')
- KDirWatch::self()->addFile(newFileName);
- projectIsDirty=TRUE;
- }
- } else {
- KMessageBox::error(this,"The name you chose conflicts with that of another file.");
- theFile->setText(0,oldLabel);
- }
-
- updateRightStatusLabel();
- }
- void MainForm::closeEvent(QCloseEvent *e)
- {
- if (savePrompt())
- e->ignore();
- else {
- clearProject();
- e->accept();
- }
- }
- void MainForm::KDirWatch_dirty(const QString &fileName)
- {
- QListViewItem *item=rootListItem->firstChild(),*next;
- QStringList allFiles;
- while (item) {
- if (IS_FOLDER(item)) {
- next=item->firstChild();
- if (next) {
- item=next;
- continue;
- }
- }
- if (IS_FILE(item)) {
- if (!fileName.compare(static_cast<ListViewFile *>(item)->fileName)) {
- CATEGORY_OF(category,item);
- if (!IS_EDITABLE_CATEGORY(category)) {
- qWarning("KDirWatch_dirty called for non-editable file");
- return;
- }
- if (KMessageBox::questionYesNo(this,
- QString("The file \'%1\' has been changed by another program. "
- "Do you want to reload it?").arg(fileName),"File Changed")
- ==KMessageBox::Yes) {
- QString fileText=loadFileText(fileName);
- if (fileText.isNull()) {
- KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
- return;
- }
- static_cast<ListViewFile *>(item)->isNew=FALSE;
- if (static_cast<ListViewFile *>(item)->kateView) {
- static_cast<ListViewFile *>(item)->kateView->getDoc()->setText(fileText);
- static_cast<ListViewFile *>(item)->kateView->getDoc()->setModified(FALSE);
- static_cast<ListViewFile *>(item)->kateView->getDoc()->clearUndo();
- static_cast<ListViewFile *>(item)->kateView->getDoc()->clearRedo();
- } else {
- static_cast<ListViewFile *>(item)->textBuffer=fileText;
- }
- }
- return;
- }
- }
- next=item->nextSibling();
- while (!next) {
- next=item->parent();
- if (next==rootListItem||!next) {
- qWarning("KDirWatch_dirty called for file not in project tree");
- return;
- }
- item=next;
- next=item->nextSibling();
- }
- item=next;
- }
- qWarning("KDirWatch_dirty called for file not in project tree");
- return;
- }
- // Yes, this is an ugly hack... Any better suggestions?
- #define QListView DnDListView
|