-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainform.ui.h
6306 lines (6081 loc) · 239 KB
/
mainform.ui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
** 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-2009 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 <qstring.h>
#include <qstringlist.h>
#include <qcstring.h>
#include <qpair.h>
#include <qregexp.h>
#include <qapplication.h>
#include <qlabel.h>
#include <qstatusbar.h>
#include <qtimer.h>
#include <qdatetime.h>
#include <qdragobject.h>
#include <qdir.h>
#include <qclipboard.h>
#include <qaccel.h>
#include <qeventloop.h>
#include <qdockwindow.h>
#include <qfileinfo.h>
#include <qdatetime.h>
#include <qtextcodec.h>
#include <qstylesheet.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qlistbox.h>
#include <kapplication.h>
#include <kparts/factory.h>
#include <klibloader.h>
#include <kate/document.h>
#include <kate/view.h>
#include <kconfig.h>
#include <ktexteditor/editinterfaceext.h>
#include <ktexteditor/configinterfaceextension.h>
#include <kaboutdata.h>
#include <khelpmenu.h>
#include <kfiledialog.h>
#include <kurl.h>
#include <kmessagebox.h>
#include <kdirwatch.h>
#include <kfinddialog.h>
#include <kfind.h>
#include <kreplacedialog.h>
#include <kreplace.h>
#include <kwin.h>
#include <kglobal.h>
#include <kicontheme.h>
#include <kiconloader.h>
#include <kprocio.h>
#include <kshell.h>
#include <ktextbrowser.h>
#include <krun.h>
#include <kpushbutton.h>
#include <kmacroexpander.h>
#include <dcopclient.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <glib.h>
#include <ticonv.h>
#include <ticables.h>
#include <tifiles.h>
#include <ticalcs.h>
#include "ktigcc.h"
#include "srcfile.h"
#include "tpr.h"
#include "preferences.h"
#include "projectoptions.h"
#include "errorlist.h"
#include "programoutput.h"
#include "tiemu.h"
#include "callbacks.h"
#include "parsing.h"
#include "functions.h"
#include "toolsdlg.h"
#include "newsdlg.h"
#include "completion.h"
#include "assistant.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 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()))
#define LOAD_ICON(name) (QIconSet(KGlobal::iconLoader()->loadIcon((name),KIcon::Small),KGlobal::iconLoader()->loadIcon((name),KIcon::MainToolbar)))
#define SYSICON(sysname,name) (preferences.useSystemIcons?KGlobal::iconLoader()->loadIcon((sysname),KIcon::Small,KIcon::SizeSmall):QPixmap::fromMimeSource((name)))
#define SET_TEXT_SAFE(doc,text) do { \
disableViewEvents=TRUE; \
(doc)->setText((text)); \
disableViewEvents=FALSE; \
} while(0)
// For some reason, this flag is not in the public ConfigFlags enum.
#define CF_REMOVE_TRAILING_DYN 0x4000000
static QListViewItem *currentListItem;
static QListViewItem *replaceCurrentDocument;
static unsigned replaceCurrentLine;
static bool compiling;
class KReplaceWithSelection : public KReplace {
public:
KReplaceWithSelection(const QString &pattern, const QString &replacement,
long options, QWidget *parent=0) :
KReplace(pattern,replacement,options,parent), m_haveSelection(FALSE) {}
void setSelection(unsigned selStartLine, unsigned selStartCol,
unsigned selEndLine, unsigned selEndCol)
{
m_haveSelection=TRUE;
m_selStartLine=selStartLine;
m_selStartCol=selStartCol;
m_selEndLine=selEndLine;
m_selEndCol=selEndCol;
}
void invalidateSelection() {m_haveSelection=FALSE;}
bool haveSelection() {
// If another document was put under the cursor, invalidate selection.
// The m_haveSelection&& is technically redundant, but necessary to avoid
// possible undefined behavior if replaceCurrentDocument has been deleted.
if (m_haveSelection&¤tListItem!=replaceCurrentDocument)
m_haveSelection=FALSE;
return m_haveSelection;
}
unsigned selStartLine() {return m_selStartLine;}
unsigned selStartCol() {return m_selStartCol;}
unsigned selEndLine() {return m_selEndLine;}
unsigned selEndCol() {return m_selEndCol;}
// Override to ask for restarting when replacing in a selection.
bool shouldRestart(bool forceAsking=FALSE, bool showNumMatches=TRUE)
{
return KReplace::shouldRestart(forceAsking||m_haveSelection,showNumMatches);
}
protected:
virtual bool validateMatch(const QString &text, int index, int matchedlength)
{
if (!KReplace::validateMatch(text,index,matchedlength)) return FALSE;
// If another document was put under the cursor, invalidate selection.
// The m_haveSelection&& is technically redundant, but necessary to avoid
// possible undefined behavior if replaceCurrentDocument has been deleted.
if (m_haveSelection&¤tListItem!=replaceCurrentDocument)
m_haveSelection=FALSE;
if (!m_haveSelection) return TRUE;
if (replaceCurrentLine==m_selStartLine && replaceCurrentLine==m_selEndLine)
return ((unsigned)index>=m_selStartCol)&&((unsigned)index+(unsigned)matchedlength<=m_selEndCol);
else if (replaceCurrentLine==m_selStartLine)
return ((unsigned)index>=m_selStartCol);
else if (replaceCurrentLine==m_selEndLine)
return ((unsigned)index+(unsigned)matchedlength<=m_selEndCol);
else
return (replaceCurrentLine>=m_selStartLine&&replaceCurrentLine<=m_selEndLine);
}
private:
bool m_haveSelection;
unsigned m_selStartLine, m_selStartCol, m_selEndLine, m_selEndCol;
};
static KReplaceWithSelection *kreplace;
// 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,SYSICON("folder","folder1.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
}
ListViewFolder(QListViewItem *parent) : KListViewItem(parent)
{
setPixmap(0,SYSICON("folder","folder1.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
}
ListViewFolder(QListView *parent, QListViewItem *after)
: KListViewItem(parent, after)
{
setPixmap(0,SYSICON("folder","folder1.png"));
setDropEnabled(TRUE);
setDragEnabled(TRUE);
}
ListViewFolder(QListViewItem *parent, QListViewItem *after)
: KListViewItem(parent, after)
{
setPixmap(0,SYSICON("folder","folder1.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
}
virtual int rtti(void) const {return 0x716CC0;}
// Work around gratuitous API difference. Why do I have to do this? That's
// what startRename is a virtual method for. KListViewItem should do this.
virtual void startRename(int col)
{
static_cast<KListView *>(listView())->rename(this,col);
}
protected:
};
class ListViewFile : public KListViewItem {
public:
ListViewFile(QListView *parent) : KListViewItem(parent),
kateView(NULL), isNew(TRUE),
modifiedSinceLastCompile(TRUE)
{
setPixmap(0,SYSICON("unknown","filex.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
setRenameEnabled(0,TRUE);
}
ListViewFile(QListViewItem *parent) : KListViewItem(parent),
kateView(NULL), isNew(TRUE),
modifiedSinceLastCompile(TRUE)
{
setPixmap(0,SYSICON("unknown","filex.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
setRenameEnabled(0,TRUE);
}
ListViewFile(QListView *parent, QListViewItem *after)
: KListViewItem(parent, after), kateView(NULL), isNew(TRUE),
modifiedSinceLastCompile(TRUE)
{
setPixmap(0,SYSICON("unknown","filex.png"));
setDropEnabled(TRUE);
setDragEnabled(TRUE);
setRenameEnabled(0,TRUE);
}
ListViewFile(QListViewItem *parent, QListViewItem *after)
: KListViewItem(parent, after), kateView(NULL),
isNew(TRUE), modifiedSinceLastCompile(TRUE)
{
setPixmap(0,SYSICON("unknown","filex.png"));
setDragEnabled(TRUE);
setDropEnabled(TRUE);
setRenameEnabled(0,TRUE);
}
virtual ~ListViewFile()
{
MainForm::deleteErrorsForLVFile(this);
if (kreplace && replaceCurrentDocument==this) {
replaceCurrentDocument=static_cast<QListViewItem *>(NULL);
kreplace->invalidateSelection();
}
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;
bool modifiedSinceLastCompile;
LineStartList lineStartList;
// Work around gratuitous API difference. Why do I have to do this? That's
// what startRename is a virtual method for. KListViewItem should do this.
virtual void startRename(int col)
{
static_cast<KListView *>(listView())->rename(this,col);
}
protected:
};
class ListViewRoot : public KListViewItem {
public:
ListViewRoot(QListView *parent) : KListViewItem(parent)
{
setRenameEnabled(0,TRUE);
// dragging not really allowed, but don't let the cursor run around when dragged
setDragEnabled(TRUE);
}
ListViewRoot(QListViewItem *parent) : KListViewItem(parent)
{
setRenameEnabled(0,TRUE);
// dragging not really allowed, but don't let the cursor run around when dragged
setDragEnabled(TRUE);
}
ListViewRoot(QListView *parent, QListViewItem *after)
: KListViewItem(parent, after)
{
setRenameEnabled(0,TRUE);
// dragging not really allowed, but don't let the cursor run around when dragged
setDragEnabled(TRUE);
}
ListViewRoot(QListViewItem *parent, QListViewItem *after)
: KListViewItem(parent, after)
{
setRenameEnabled(0,TRUE);
// dragging not really allowed, but don't let the cursor run around when dragged
setDragEnabled(TRUE);
}
// Work around gratuitous API difference. Why do I have to do this? That's
// what startRename is a virtual method for. KListViewItem should do this.
virtual void startRename(int col)
{
static_cast<KListView *>(listView())->rename(this,col);
}
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 bool projectIsDirty, projectNeedsRelink;
static QLabel *leftStatusLabel;
static QLabel *rowStatusLabel;
static QLabel *colStatusLabel;
static QLabel *charsStatusLabel;
static QLabel *rightStatusLabel;
static KHelpMenu *khelpmenu;
static QPopupMenu *te_popup;
static bool headersModified;
static QDockWindow *errorListDock;
static ErrorList *errorList;
static unsigned errorCountTotal=0,errorCountErrors=0,errorCountWarnings=0;
static QString programOutput;
AssistantClient *assistant;
static unsigned fileCount=0, hFileCount=0, cFileCount=0, sFileCount=0, asmFileCount=0, qllFileCount=0, oFileCount=0, aFileCount=0, txtFileCount=0, othFileCount=0;
tprSettings settings;
tprLibOpts libopts;
static QString projectFileName;
static QString lastDirectory;
QClipboard *clipboard;
static QAccel *accel, *fileTreeAccel;
static KFindDialog *kfinddialog;
QStringList findHistory, replacementHistory;
static QListViewItem *findCurrentDocument;
static unsigned findCurrentLine;
QPtrList<SourceFile> sourceFiles;
static QPopupMenu *findFunctionsPopup;
bool have_usb;
Tools tools, tempTools;
int toolIndex;
bool disableViewEvents=FALSE;
class DnDListView : public KListView {
private:
public:
DnDListView ( QWidget * parent = 0, const char * name = 0)
: KListView(parent,name) {}
// Make my hand-coded drag&drop code work (public part).
// Maybe the built-in drag&drop support in KListView could be made to work as
// expected, but for now just bypass it to use the existing code I wrote for
// QListView.
virtual void takeItem(QListViewItem *i) {QListView::takeItem(i);}
virtual void setAcceptDrops(bool on) {QListView::setAcceptDrops(on);}
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 (!compiling && 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
QListViewItem *item=itemAt(e->pos());
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;
projectNeedsRelink=TRUE;
} else {ignore: e->ignore();}
} else e->ignore();
} else if (IS_FILE(currItem)) {
// dropping file
QListViewItem *item=itemAt(e->pos());
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));
MainForm::createErrorCursorsForSourceFile(currItem);
// 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;
projectNeedsRelink=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;
}
// moving from editable to editable category
if (IS_EDITABLE_CATEGORY(srcCategory)
&& IS_EDITABLE_CATEGORY(destCategory)
&& srcCategory!=destCategory
&& static_cast<ListViewFile *>(currItem)->kateView) {
// update highlighting mode
uint cnt=static_cast<ListViewFile *>(currItem)->kateView->getDoc()->hlModeCount(), i;
QString fileText=static_cast<ListViewFile *>(currItem)->kateView->getDoc()->text();
for (i=0; i<cnt; i++) {
if (!static_cast<ListViewFile *>(currItem)->kateView->getDoc()->hlModeName(i).compare(
(destCategory==qllFilesListItem?
QLL_HL_MODE:
(destCategory==sFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
S_HL_MODE:
(destCategory==asmFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
ASM_HL_MODE:
(destCategory==cFilesListItem||destCategory==hFilesListItem)?
C_HL_MODE:
"None"))) break;
}
if (i==cnt) i=0;
static_cast<ListViewFile *>(currItem)->kateView->getDoc()->setHlMode(i);
}
// update icon
currItem->setPixmap(0,
destCategory==cFilesListItem||destCategory==qllFilesListItem?SYSICON("source_c","filec.png"):
destCategory==hFilesListItem?SYSICON("source_h","fileh.png"):
destCategory==sFilesListItem||destCategory==asmFilesListItem?SYSICON("source_s","files.png"):
destCategory==txtFilesListItem?SYSICON("txt","filet.png"):
destCategory==oFilesListItem||destCategory==aFilesListItem?SYSICON("binary","fileo.png"):
SYSICON("unknown","filex.png"));
}
} 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;
projectNeedsRelink=TRUE;
break;
} else if (i==item) {
// item is first, move currItem before item
e->accept();
currItem->moveItem(item);
item->moveItem(currItem);
projectIsDirty=TRUE;
projectNeedsRelink=TRUE;
break;
}
}
} else e->ignore();
} else e->ignore();
} else e->ignore();
} else e->ignore();
}
virtual void dragEnterEvent (QDragEnterEvent *e) {
if (!compiling && e->source()==this&&(e->provides("x-ktigcc-dnd")))
e->accept();
}
virtual void dragMoveEvent (QDragMoveEvent *e) {
if (!compiling && 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
QListViewItem *item=itemAt(e->pos());
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
QListViewItem *item=itemAt(e->pos());
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();
}
// Make my hand-coded drag&drop code work (protected part).
virtual void contentsDragMoveEvent(QDragMoveEvent *e) {
QListView::contentsDragMoveEvent(e);
}
virtual void contentsMouseMoveEvent(QMouseEvent *e) {
QListView::contentsMouseMoveEvent(e);
}
virtual void contentsDragLeaveEvent(QDragLeaveEvent *e) {
QListView::contentsDragLeaveEvent(e);
}
virtual void contentsDropEvent(QDropEvent *e) {
QListView::contentsDropEvent(e);
}
virtual void contentsDragEnterEvent(QDragEnterEvent *e) {
QListView::contentsDragEnterEvent(e);
}
virtual void startDrag() {
QListView::startDrag();
}
// KListView::rename won't work properly if I don't do this. :-/
virtual void rename(QListViewItem *item, int c) {
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
ensureItemVisible(item);
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
KListView::rename(item,c);
}
};
enum ErrorTypes {etError, etWarning, etInfo};
class ErrorListItem : public KListViewItem {
public:
ErrorListItem(MainForm *pMainForm, ErrorTypes errType,
const QString &errFile, const QString &errFunc,
const QString &errMsg, unsigned errLine, unsigned errColumn)
: KListViewItem(errorList->errorListView,
errorList->errorListView->lastItem()),
lvFile(0), srcFile(0), cursor(0), errorLine((unsigned)-1), errorColumn(0),
mainForm(pMainForm), errorType(errType)
{
QString errMessage=errMsg.stripWhiteSpace();
if (!errMessage.isEmpty()) errMessage[0]=errMessage[0].upper();
switch(errType) {
case etError:
setPixmap(0,SYSICON("messagebox_critical","error.png"));
break;
case etWarning:
setPixmap(0,SYSICON("messagebox_warning","warning.png"));
break;
default:
setPixmap(0,SYSICON("messagebox_info","info.png"));
break;
}
setText(0,errMessage);
setText(1,errFile);
setText(2,errFunc=="__exit"?"_exit":
(errFunc=="__main"?"_main":errFunc));
if (!errFile.isEmpty() && !errFile.endsWith(".a")) {
// Look for the source file with the error.
if (!findSourceFile(errFile) && errFile.endsWith(".o")) {
QString errSrcFile=errFile;
int lengthWoExt=errSrcFile.length()-2;
errSrcFile.truncate(lengthWoExt);
errSrcFile.append(".c");
if (!findSourceFile(errSrcFile)) {
errSrcFile.truncate(lengthWoExt);
errSrcFile.append(".s");
if (!findSourceFile(errSrcFile)) {
errSrcFile.truncate(lengthWoExt);
errSrcFile.append(".asm");
findSourceFile(errSrcFile);
}
}
}
// Not found. Try to open it instead.
// Don't do this if the name ends with ".tpr" because that would cause
// openProject to close the current project and load the new one instead.
if (!lvFile && !srcFile && !errFile.endsWith(".tpr",FALSE)) {
if (errFile.contains('/')&&getPathType(errFile)==PATH_FILE)
mainForm->openProject(errFile);
else if (getPathType(QString("%1/include/c/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
mainForm->openProject(QString("%1/include/c/%2").arg(tigcc_base).arg(errFile));
else if (getPathType(QString("%1/include/asm/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
mainForm->openProject(QString("%1/include/asm/%2").arg(tigcc_base).arg(errFile));
else if (getPathType(QString("%1/include/s/%2").arg(tigcc_base).arg(errFile))==PATH_FILE)
mainForm->openProject(QString("%1/include/s/%2").arg(tigcc_base).arg(errFile));
findSourceFile(errFile);
}
}
if (errLine!=(unsigned)-1 && (lvFile || srcFile)) {
if (errColumn==(unsigned)-1) errColumn=0;
const LineStartList &lineStartList=lvFile?lvFile->lineStartList
:srcFile->lineStartList;
if (lineStartList.isEmpty()) {
errorLine=errLine;
errorColumn=errColumn;
} else if (errLine<lineStartList.count()) {
QPair<unsigned,unsigned> pos=lineStartList[errLine];
errorLine=pos.first;
errorColumn=pos.second+errColumn;
}
createCursor();
}
if (preferences.jumpToError && errType==etError
&& errorList->errorListView->selectedItems().isEmpty()) {
errorList->errorListView->setSelected(this,TRUE);
jumpToLocation();
}
errorCountTotal++;
if (errType==etError) errorCountErrors++;
if (errType==etWarning) errorCountWarnings++;
errorList->errorCount->setText(QString::number(errorCountErrors));
errorList->warningCount->setText(QString::number(errorCountWarnings));
mainForm->projectErrorsAndWarningsAction->setEnabled(TRUE);
mainForm->projectErrorsAndWarnings(TRUE);
}
virtual ~ErrorListItem()
{
if (errorType==etError) errorCountErrors--;
if (errorType==etWarning) errorCountWarnings--;
errorList->errorCount->setText(QString::number(errorCountErrors));
errorList->warningCount->setText(QString::number(errorCountWarnings));
if (!--errorCountTotal) {
mainForm->projectErrorsAndWarnings(FALSE);
mainForm->projectErrorsAndWarningsAction->setEnabled(FALSE);
}
}
virtual int rtti(void) const {return static_cast<int>(errorType);}
void createCursor(void)
{
if (errorLine!=(unsigned)-1) {
Kate::View *kateView=lvFile?lvFile->kateView:(srcFile?srcFile->kateView
:static_cast<Kate::View *>(NULL));
if (kateView && errorLine<kateView->getDoc()->numLines()) {
// Extract the main token for the error message.
QString errMessage=text(0);
int quotePos=errMessage.find('\'');
if (quotePos>=0) {
QString token=errMessage.mid(quotePos+1);
int quotePos2=token.find('\'');
if (quotePos2>=0) {
token.truncate(quotePos2);
if (!token.isEmpty()) {
// Skip whitespace up to this token. TIGCC IDE does that too. Must
// have something to do with how source splitting works.
unsigned i=errorColumn;
QString textLine=kateView->getDoc()->textLine(errorLine);
unsigned lineLength=kateView->getDoc()->lineLength(errorLine);
unsigned tokenLength=token.length();
while ((i<lineLength) && textLine[i].isSpace()
&& textLine.mid(i,tokenLength)!=token) i++;
if (textLine.mid(i,tokenLength)==token) errorColumn=i;
}
}
}
cursor=kateView->getDoc()->createCursor();
cursor->setPosition(errorLine,errorColumn);
}
}
}
void jumpToLocation(void)
{
// If the error corresponds to a list view file, select it. This will also
// instantiate the Kate view and call createCursor for us.
if (lvFile) mainForm->fileTreeClicked(lvFile);
// If it corresponds to an external source file, activate the window.
if (srcFile) KWin::activateWindow(srcFile->winId());
// Now jump to the cursor's location if we have one.
Kate::View *kateView=lvFile?lvFile->kateView:(srcFile?srcFile->kateView
:static_cast<Kate::View *>(NULL));
if (cursor && kateView) {
unsigned line,col;
cursor->position(&line,&col);
kateView->setCursorPositionReal(line,col);
}
}
ListViewFile *lvFile;
SourceFile *srcFile;
KTextEditor::Cursor *cursor;
private:
unsigned errorLine;
unsigned errorColumn;
MainForm *mainForm;
ErrorTypes errorType;
bool findSourceFile(const QString &fileName)
{
bool inProject;
void *sourceFile;
bool found=mainForm->findSourceFile(inProject,sourceFile,fileName);
if (found) {
if (inProject)
lvFile=reinterpret_cast<ListViewFile *>(sourceFile);
else
srcFile=reinterpret_cast<SourceFile *>(sourceFile);
}
return found;
}
};
// This static helper function is needed because of limitations of both .ui.h
// files and C++: we can't have methods of other classes than MainForm here
// unless we write them into the class definition or Qt Designer gets confused,
// and C++ won't let 2 classes reference each other in methods declared within
// the class definition. And item is of type QListViewItem rather than
// ListViewFile because of another Qt Designer limitation: It isn't possible to
// use custom types in a .ui file method because it doesn't forward-declare them
// properly.
void MainForm::deleteErrorsForLVFile(QListViewItem *item)
{
QListViewItemIterator lvit(errorList->errorListView);
QListViewItem *errorItem;
while ((errorItem=lvit.current())) {
++lvit;
if (static_cast<ErrorListItem *>(errorItem)->lvFile
==static_cast<ListViewFile *>(item))
delete errorItem;
}
}
// Another static helper function, in this case because srcfilewin.ui.h doesn't
// have access to ErrorListItem for similar reasons. (I'd have to duplicate the
// class definition, one time with inline functions and one time without.)
void MainForm::deleteErrorsForSrcFile(void *srcFile)
{
QListViewItemIterator lvit(errorList->errorListView);
QListViewItem *errorItem;
while ((errorItem=lvit.current())) {
++lvit;
if (static_cast<ErrorListItem *>(errorItem)->srcFile
==reinterpret_cast<SourceFile *>(srcFile))
delete errorItem;
}
}
// And another.
void MainForm::createErrorCursorsForSourceFile(QListViewItem *item)
{
QListViewItemIterator lvit(errorList->errorListView);
QListViewItem *errorItem;
for (errorItem=lvit.current();errorItem;errorItem=(++lvit).current()) {
if (static_cast<ErrorListItem *>(errorItem)->lvFile
==static_cast<ListViewFile *>(item))
static_cast<ErrorListItem *>(errorItem)->createCursor();
}
}
// And the last.
void MainForm::deleteOverwrittenErrorsIn(void *srcFile)
{
SourceFile *sourceFile=reinterpret_cast<SourceFile *>(srcFile);
QListViewItemIterator lvit(errorList->errorListView);
ErrorListItem *errorItem;
while ((errorItem=static_cast<ErrorListItem *>(lvit.current()))) {
++lvit;
if (errorItem->srcFile==sourceFile && errorItem->cursor) {
unsigned line,col;
errorItem->cursor->position(&line,&col);
if (sourceFile->kateView->cursorLine()==line
&& sourceFile->kateView->cursorColumnReal()==col)
delete errorItem;
}
}
}
void MainForm::errorListView_clicked(QListViewItem *item)
{
if (item) {
static_cast<ErrorListItem *>(item)->jumpToLocation();
errorList->setFocus();
}
}
bool MainForm::findSourceFile(bool &inProject, void *&srcFile, const QString &fileName)
{
bool compareAbsPaths=fileName.contains('/');
QListViewItemIterator lvit(fileTree);
QListViewItem *item;
for (item=lvit.current();item;item=(++lvit).current()) {
if (IS_FILE(item)
&& (compareAbsPaths?fileName==static_cast<ListViewFile *>(item)->fileName
:fileName==QFileInfo(static_cast<ListViewFile *>(item)->fileName).fileName())) {
inProject=TRUE;
srcFile=static_cast<ListViewFile *>(item);
return TRUE;
}
}
QPtrListIterator<SourceFile> sfit(sourceFiles);
SourceFile *sourceFile;
for (sourceFile=sfit.current();sourceFile;sourceFile=++sfit) {
if (compareAbsPaths?fileName==sourceFile->fileName
:fileName==QFileInfo(sourceFile->fileName).fileName()) {
inProject=FALSE;
srcFile=sourceFile;
return TRUE;
}
}
return FALSE;
}
void MainForm::init()
{
setIcon(QPixmap::fromMimeSource("icon.png"));
KWin::setIcons(winId(),*(icon()),QPixmap::fromMimeSource("ktigcc.png"));
ticables_library_init();
tifiles_library_init();
ticalcs_library_init();
have_usb=ticables_is_usb_enabled();
compiling=FALSE;
headersModified=FALSE;
loadPreferences();
loadSystemHeaderCompletion();
fileNewFolderAction->setEnabled(FALSE);
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());