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
|
/*
Copyright (C) 2002 by Roberto Raggi <roberto@tdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
version 2, License as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "problemreporter.h"
#include "cppsupportpart.h"
#include "configproblemreporter.h"
#include "backgroundparser.h"
#include <kdevpartcontroller.h>
#include <kdevmainwindow.h>
#include <kdevproject.h>
#include <tdeversion.h>
#include <tdeparts/part.h>
#include <tdetexteditor/editinterface.h>
#include <tdetexteditor/document.h>
#include <tdetexteditor/markinterface.h>
#include <tdetexteditor/markinterfaceextension.h>
#include <tdetexteditor/view.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstatusbar.h>
#include <kurl.h>
#include <tdeapplication.h>
#include <kiconloader.h>
#include <kdialogbase.h>
#include <tdeconfig.h>
#include <tqtimer.h>
#include <tqregexp.h>
#include <tqvbox.h>
#include <tqfileinfo.h>
#include <tqwhatsthis.h>
#include <tqtabbar.h>
#include <tqwidgetstack.h>
#include <tqlayout.h>
#include <tqlineedit.h>
class ProblemItem: public TDEListViewItem
{
public:
ProblemItem( TQListView* parent, const TQString& problem,
const TQString& file, const TQString& line, const TQString& column )
: TDEListViewItem( parent, problem, file, line, column )
{}
ProblemItem( TQListViewItem* parent, const TQString& problem,
const TQString& file, const TQString& line, const TQString& column )
: TDEListViewItem( parent, problem, file, line, column )
{}
int compare( TQListViewItem* item, int column, bool ascending ) const
{
if ( column == 1 || column == 2 )
{
int a = text( column ).toInt();
int b = item->text( column ).toInt();
if ( a == b )
return 0;
return ( a > b ? 1 : -1 );
}
return TDEListViewItem::compare( item, column, ascending );
}
};
ProblemReporter::ProblemReporter( CppSupportPart* part, TQWidget* parent, const char* name )
: TQWidget( parent, name ? name : "problemreporter" ),
m_cppSupport( part ),
// m_document( 0 ),
m_markIface( 0 )
{
TQWhatsThis::add(this, i18n("<b>Problem reporter</b><p>This window shows various \"problems\" in your project. "
"It displays TODO entries, FIXME's and errors reported by a language parser. "
"To add a TODO or FIXME entry, just type<br>"
"<tt>//@todo my todo</tt><br>"
"<tt>//TODO: my todo</tt><br>"
"<tt>//FIXME fix this</tt>"));
m_initCurrentTimer = new TQTimer( this );
connect( m_initCurrentTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(initCurrentList()) );
m_gridLayout = new TQGridLayout(this,2,3);
m_errorList = new TDEListView(this);
m_warningList = new TDEListView(this);
m_fixmeList = new TDEListView(this);
m_todoList = new TDEListView(this);
m_filteredList = new TDEListView(this);
m_currentList = new TDEListView(this);
m_filteredList->addColumn( i18n("Level") );
m_currentList->addColumn( i18n("Level") );
//addColumn( i18n("Level") );
InitListView(m_warningList);
InitListView(m_errorList);
InitListView(m_fixmeList);
InitListView(m_todoList);
InitListView(m_filteredList);
InitListView(m_currentList);
m_currentList->removeColumn(1);
m_widgetStack = new TQWidgetStack(this);
m_widgetStack->addWidget(m_currentList,0);
m_widgetStack->addWidget(m_errorList,1);
m_widgetStack->addWidget(m_warningList,2);
m_widgetStack->addWidget(m_fixmeList,3);
m_widgetStack->addWidget(m_todoList,4);
m_widgetStack->addWidget(m_filteredList,5);
m_tabBar = new TQTabBar(this);
m_tabBar->insertTab(new TQTab(i18n("Current")),0);
m_tabBar->insertTab(new TQTab(i18n("Errors")),1);
m_tabBar->insertTab(new TQTab(i18n("Warnings")),2);
m_tabBar->insertTab(new TQTab(i18n("Fixme")),3);
m_tabBar->insertTab(new TQTab(i18n("Todo")),4);
m_tabBar->insertTab(new TQTab(i18n("Filtered")),5);
m_tabBar->setTabEnabled(0,false);
m_tabBar->setTabEnabled(5,false);
m_filterEdit = new KLineEdit(this);
TQLabel* m_filterLabel = new TQLabel(i18n("Lookup:"),this);
m_gridLayout->addWidget(m_tabBar,0,0);
m_gridLayout->addMultiCellWidget(m_widgetStack,1,1,0,2);
m_gridLayout->addWidget(m_filterLabel,0,1,TQt::AlignRight);
m_gridLayout->addWidget(m_filterEdit,0,2,TQt::AlignLeft);
connect( m_filterEdit, TQT_SIGNAL(returnPressed()),
this, TQT_SLOT(slotFilter()) );
connect( m_filterEdit, TQT_SIGNAL(textChanged( const TQString & )),
this, TQT_SLOT(slotFilter()) );
connect( m_tabBar, TQT_SIGNAL(selected(int)),
this, TQT_SLOT(slotTabSelected(int)) );
connect( part->partController(), TQT_SIGNAL(activePartChanged(KParts::Part*)),
this, TQT_SLOT(slotActivePartChanged(KParts::Part*)) );
connect( part->partController(), TQT_SIGNAL(partAdded(KParts::Part*)),
this, TQT_SLOT(slotPartAdded(KParts::Part*)) );
// any editors that were open when we loaded the project needs to have their markType07 icon set too..
TQPtrListIterator<KParts::Part> it( *m_cppSupport->partController()->parts() );
while( it.current() )
{
if ( KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( it.current() ) )
{
iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
}
++it;
}
slotActivePartChanged( part->partController()->activePart() );
}
void ProblemReporter::slotFilter()
{
if(!m_tabBar->isTabEnabled(5))
m_tabBar->setTabEnabled(5,true);
m_tabBar->tab(5)->setText(i18n("Filtered: %1").arg( m_filterEdit->text() ));
m_tabBar->setCurrentTab(5);
m_filteredList->clear();
if ( m_filterEdit->text().isEmpty() )
{
m_tabBar->setTabEnabled( 5, false );
return;
}
filterList(m_errorList,i18n("Error"));
filterList(m_warningList,i18n("Warning"));
filterList(m_fixmeList,i18n("Fixme"));
filterList(m_todoList,i18n("Todo"));
}
void ProblemReporter::configWidget( KDialogBase* dlg )
{
}
void ProblemReporter::filterList(TDEListView* listview, const TQString& level)
{
TQListViewItemIterator it( listview );
while ( it.current() )
{
if ( it.current()->text(3).contains(m_filterEdit->text(),false))
{
new TDEListViewItem(m_filteredList,level,
it.current()->text(0), it.current()->text(1),
it.current()->text(2), it.current()->text(3));
}
++it;
}
}
void ProblemReporter::slotTabSelected( int tabindex )
{
m_widgetStack->raiseWidget(tabindex);
}
void ProblemReporter::InitListView(TDEListView* listview)
{
listview->addColumn( i18n("File") );
listview->addColumn( i18n("Line") );
listview->addColumn( i18n("Column") );
listview->addColumn( i18n("Problem") );
listview->setAllColumnsShowFocus( TRUE );
connect( listview, TQT_SIGNAL(executed(TQListViewItem*)),
this, TQT_SLOT(slotSelected(TQListViewItem*)) );
connect( listview, TQT_SIGNAL(returnPressed(TQListViewItem*)),
this, TQT_SLOT(slotSelected(TQListViewItem* )) );
}
ProblemReporter::~ProblemReporter()
{
}
void ProblemReporter::slotActivePartChanged( KParts::Part* part )
{
m_currentList->clear();
KParts::ReadOnlyPart * ro_part = dynamic_cast<KParts::ReadOnlyPart*>( part );
m_markIface = dynamic_cast<KTextEditor::MarkInterface*>( part );
if ( !ro_part )
{
m_tabBar->setTabEnabled(0,false);
return;
}
m_fileName = ro_part->url().path();
initCurrentList();
}
void EfficientTDEListView::limitSize( int size )
{
if( m_map.size() <= size + 50 ) return;
TQMap<int, HashedString> backMap;
for( InsertionMap::const_iterator it = m_insertionNumbers.begin(); it != m_insertionNumbers.end(); ++it )
backMap[ (*it).second ] = (*it).first;
for( TQMap<int, HashedString>::const_iterator it = backMap.begin(); it != backMap.end() && m_map.size() > size; ++it )
removeAllItems( (*it).str() );
}
void EfficientTDEListView::removeAllItems( const TQString& str )
{
HashedString h(str);
m_insertionNumbers.erase( h ) ;
std::pair<Map::iterator, Map::iterator> p = m_map.equal_range( h );
for( Map::iterator it = p.first; it != p.second; ++it ) {
delete( (*it).second );
}
m_map.erase( p.first, p.second );
}
void ProblemReporter::removeAllProblems( const TQString& filename )
{
TQString relFileName = m_cppSupport->project()->relativeProjectFile(filename);
kdDebug(9007) << "ProblemReporter::removeAllProblems()" << relFileName << endl;
m_errorList.limitSize( 300 );
m_warningList.limitSize( 300 );
m_fixmeList.limitSize( 300 );
m_todoList.limitSize( 300 );
m_warningList.removeAllItems( relFileName );
m_errorList.removeAllItems( relFileName );
m_fixmeList.removeAllItems( relFileName );
m_todoList.removeAllItems( relFileName );
if( m_markIface )
{
TQPtrList<KTextEditor::Mark> marks = m_markIface->marks();
TQPtrListIterator<KTextEditor::Mark> it( marks );
while( it.current() )
{
m_markIface->removeMark( it.current()->line, KTextEditor::MarkInterface::markType07 );
++it;
}
}
m_initCurrentTimer->start(500, true);
}
void ProblemReporter::initCurrentList()
{
m_tabBar->setTabEnabled(0,true);
TQString relFileName = m_cppSupport->project()->relativeProjectFile(m_fileName);
m_currentList->clear();
updateCurrentWith(m_errorList, i18n("Error"),relFileName);
updateCurrentWith(m_warningList, i18n("Warning"),relFileName);
updateCurrentWith(m_fixmeList,i18n("Fixme"),relFileName);
updateCurrentWith(m_todoList,i18n("Todo"),relFileName);
// m_tabBar->setCurrentTab(0);
}
void ProblemReporter::updateCurrentWith(EfficientTDEListView& listview, const TQString& level, const TQString& filename)
{
EfficientTDEListView::Range r = listview.getRange( filename );
for( ; r.first != r.second; ++r.first )
new ProblemItem(m_currentList,level,(*r.first).second->text(1),(*r.first).second->text(2),(*r.first).second->text(3));
}
void ProblemReporter::slotSelected( TQListViewItem* item )
{
bool is_filtered = false;
bool is_current = false;
if(item->listView() == m_filteredList)
is_filtered = true;
else if(item->listView() == m_currentList)
is_current = true;
//either use current file m_fileName or assemble a new one from current item (relative path) and projectDirectory
KURL url( is_current ? m_fileName : m_cppSupport->project()->projectDirectory() + "/" + item->text(0 + is_filtered) );
int line = item->text( 1 + is_filtered).toInt();
// int column = item->text( 3 ).toInt();
m_cppSupport->partController()->editDocument( url, line-1 );
}
bool ProblemReporter::hasErrors( const TQString& fileName ) {
return m_errorList.hasItem( fileName );
}
void ProblemReporter::reportProblem( const TQString& fileName, const Problem& p )
{
int markType = levelToMarkType( p.level() );
if( markType != -1 && m_markIface && m_fileName == fileName )
m_markIface->addMark( p.line(), markType );
TQString msg = p.text();
msg = msg.replace( TQRegExp("\n"), "" );
TQString relFileName = m_cppSupport->project()->relativeProjectFile(fileName);
EfficientTDEListView* list;
switch( p.level() )
{
case Problem::Level_Error:
list = &m_errorList;
break;
case Problem::Level_Warning:
list = &m_warningList;
break;
case Problem::Level_Todo:
list = &m_todoList;
break;
case Problem::Level_Fixme:
list = &m_fixmeList;
break;
default:
list = NULL;
}
if(list)
{
list->addItem( relFileName, new ProblemItem( *list,
relFileName,
TQString::number( p.line() + 1 ),
TQString::number( p.column() + 1 ),
msg ) );
}
m_initCurrentTimer->start( 500, true );
}
void ProblemReporter::slotPartAdded( KParts::Part* part )
{
KTextEditor::MarkInterfaceExtension* iface = dynamic_cast<KTextEditor::MarkInterfaceExtension*>( part );
if( !iface )
return;
iface->setPixmap( KTextEditor::MarkInterface::markType07, SmallIcon("stop") );
}
TQString ProblemReporter::levelToString( int level ) const
{
switch( level )
{
case Problem::Level_Error:
return TQString( i18n("Error") );
case Problem::Level_Warning:
return TQString( i18n("Warning") );
case Problem::Level_Todo:
return TQString( i18n("Todo") );
case Problem::Level_Fixme:
return TQString( i18n("Fixme") );
default:
return TQString();
}
}
int ProblemReporter::levelToMarkType( int level ) const
{
switch( level )
{
case Problem::Level_Error:
return KTextEditor::MarkInterface::markType07;
case Problem::Level_Warning:
return -1;
case Problem::Level_Todo:
return -1;
case Problem::Level_Fixme:
return -1;
default:
return -1;
}
}
#include "problemreporter.moc"
//kate: indent-mode csands; tab-width 4; space-indent off;
|