1
/***************************************************************************
2
* Copyright (C) 2004 by Jens Dagerbo *
3
* jens.dagerbo@swipnet.se *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
14
#include <qfileinfo.h>
15
#include <qdatetime.h>
16
#include <qfocusdata.h>
18
#include <klineedit.h>
19
#include <klistview.h>
23
#include <kapplication.h>
25
#include <kdevproject.h>
26
#include <kdevpartcontroller.h>
28
#include "ctags2_widget.h"
31
class TagItem : public QListViewItem
34
TagItem(QListView * lv, QString const & tag, QString const & type, QString const & file, QString const & pattern );
42
TagItem::TagItem( QListView * lv, QString const & tag, QString const & type, QString const & file, QString const & pattern )
43
: QListViewItem( lv, tag, type, file ), tag(tag), type(type), file(file), pattern(pattern)
47
CTags2Widget::CTags2Widget( CTags2Part * part, const char* name, WFlags fl)
48
: CTags2WidgetBase(0,name,fl), _part(part)
50
output_view->setColumnWidthMode(0,QListView::Maximum);
51
output_view->setColumnWidthMode(1,QListView::Maximum);
52
output_view->setColumnWidthMode(2,QListView::Maximum);
54
_typeTimeout = new QTimer( this );
55
connect( _typeTimeout, SIGNAL(timeout()), this, SLOT(line_edit_changed()) );
57
connect( output_view, SIGNAL(executed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
58
connect( output_view, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
63
CTags2Widget::~CTags2Widget()
67
void CTags2Widget::displayHits( Tags::TagList const & list )
70
showHitCount( list.count() );
72
Tags::TagList::ConstIterator it = list.begin();
73
while( it != list.end() )
75
new TagItem( output_view, (*it).tag, (*it).type, (*it).file, (*it).pattern );
79
output_view->adjustColumn(0);
80
output_view->adjustColumn(1);
81
output_view->adjustColumn(2);
85
void CTags2Widget::displayHitsAndClear( Tags::TagList const & list )
87
input_edit->blockSignals( true );
89
input_edit->blockSignals( false );
94
void CTags2Widget::line_edit_changed( )
96
displayHits( Tags::getPartialMatches( input_edit->text() ) );
99
void CTags2Widget::line_edit_changed_delayed( )
101
showHitCount( calculateHitCount() );
102
_typeTimeout->start( 500, true );
105
void CTags2Widget::showHitCount( int n )
107
hitcount_label->setText( i18n("Hits: %1").arg( n ) );
110
int CTags2Widget::calculateHitCount( )
112
return Tags::numberOfPartialMatches( input_edit->text() ) ;
115
void CTags2Widget::itemExecuted( QListViewItem * item )
117
TagItem * tagItem = static_cast<TagItem*>( item );
120
QString fileWithTagInside;
121
// assume relative path to project directory if path does not start with slash
122
if (tagItem->file[0] != '/') {
123
fileWithTagInside = _part->project()->projectDirectory() + "/" + tagItem->file;
126
fileWithTagInside = tagItem->file;
129
url.setPath(fileWithTagInside);
131
_part->partController()->editDocument( url, _part->getFileLineFromPattern( url, tagItem->pattern ) );
134
void CTags2Widget::regeneratebutton_clicked()
136
QApplication::setOverrideCursor(Qt::waitCursor);
138
_part->createTagsFile();
140
QApplication::restoreOverrideCursor();
145
void CTags2Widget::updateDBDateLabel( )
147
QStringList tagFiles = Tags::getTagFiles();
148
QFileInfo tagsdb(tagFiles[0]);
149
if ( tagsdb.exists() )
151
datetime_label->setText( tagsdb.created().date().toString( Qt::ISODate ) );
155
datetime_label->setText( i18n("No CTags database found") );
159
void CTags2Widget::focusInEvent( QFocusEvent* )
162
input_edit->setFocus();
165
void CTags2Widget::goToNext( )
167
QListViewItem * item = output_view->firstChild();
170
if ( item->isSelected() )
172
// found the current, take the next
173
item->setSelected( false );
174
if ( (item = item->nextSibling()) != NULL )
176
item->setSelected( true );
177
output_view->repaint( true );
178
itemExecuted( item );
186
item = item->nextSibling();
189
if ( (item = output_view->firstChild()) != NULL )
191
item->setSelected( true );
192
itemExecuted( item );
196
#include "ctags2_widget.moc"
198
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;