12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453 |
- /****************************************************************************
- ** 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 KListViewItem {
- public:
- ListViewFolder(QListView *parent) : KListViewItem(parent)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- ListViewFolder(QListViewItem *parent) : KListViewItem(parent)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- ListViewFolder(QListView *parent, QListViewItem *after)
- : KListViewItem(parent, after)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDropEnabled(TRUE);
- setDragEnabled(TRUE);
- }
- ListViewFolder(QListViewItem *parent, QListViewItem *after)
- : KListViewItem(parent, after)
- {
- setPixmap(0,QPixmap::fromMimeSource("folder1.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- }
- virtual int rtti(void) const {return 0x716CC0;}
- protected:
- };
- class ListViewFile : public KListViewItem {
- public:
- ListViewFile(QListView *parent) : KListViewItem(parent),
- kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListViewItem *parent) : KListViewItem(parent),
- kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDragEnabled(TRUE);
- setDropEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListView *parent, QListViewItem *after)
- : KListViewItem(parent, after), kateView(NULL), isNew(TRUE)
- {
- setPixmap(0,QPixmap::fromMimeSource("filex.png"));
- setDropEnabled(TRUE);
- setDragEnabled(TRUE);
- setRenameEnabled(0,TRUE);
- }
- ListViewFile(QListViewItem *parent, QListViewItem *after)
- : KListViewItem(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;
- 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 KListView {
- private:
- public:
- DnDListView ( QWidget * parent = 0, const char * name = 0)
- : KListView(parent,name) {}
- 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.
- if (CURRENT_VIEW && CURRENT_VIEW->hasFocus()) {
- 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;
- switch (getPathType(fileName)) {
- case PATH_FILE: // OK
- break;
- case PATH_NOTFOUND:
- KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
- return NULL;
- default:
- 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);
- switch (getPathType(fileName)) {
- case PATH_FILE: // OK
- break;
- case PATH_NOTFOUND:
- KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
- return;
- default:
- 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;
- }
- if (TPRData.settings.fargo && !have_fargo) {
- KMessageBox::error(this,"This project needs fargo.a, which is not installed.");
- return;
- }
- if (TPRData.settings.flash_os && !have_flashos) {
- KMessageBox::error(this,"This project needs flashos.a, 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()
- {
- ProjectOptions *projectoptions=new ProjectOptions(this);
- projectoptions->exec();
- if (projectoptions->result()==QDialog::Accepted)
- projectIsDirty=TRUE;
- 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 KListView DnDListView
|