~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/ctags2/ctags2_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2004 by Jens Dagerbo                                    *
3
 
 *   jens.dagerbo@swipnet.se                                               *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
10
 
 ***************************************************************************/
11
 
 
12
 
#include <qtimer.h>
13
 
#include <qlabel.h>
14
 
#include <qfileinfo.h>
15
 
#include <qdatetime.h>
16
 
#include <qfocusdata.h>
17
 
 
18
 
#include <klineedit.h>
19
 
#include <klistview.h>
20
 
#include <klocale.h>
21
 
#include <kdebug.h>
22
 
#include <kurl.h>
23
 
#include <kapplication.h>
24
 
 
25
 
#include <kdevproject.h>
26
 
#include <kdevpartcontroller.h>
27
 
 
28
 
#include "ctags2_widget.h"
29
 
#include "tags.h"
30
 
 
31
 
class TagItem : public QListViewItem
32
 
{
33
 
public:
34
 
    TagItem(QListView * lv, QString const & tag, QString const & type, QString const & file, QString const & pattern );
35
 
 
36
 
        QString tag;
37
 
        QString type;
38
 
        QString file;
39
 
        QString pattern;
40
 
};
41
 
 
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)
44
 
{
45
 
}
46
 
 
47
 
CTags2Widget::CTags2Widget( CTags2Part * part, const char* name, WFlags fl)
48
 
: CTags2WidgetBase(0,name,fl), _part(part)
49
 
{
50
 
    output_view->setColumnWidthMode(0,QListView::Maximum);
51
 
        output_view->setColumnWidthMode(1,QListView::Maximum);
52
 
        output_view->setColumnWidthMode(2,QListView::Maximum);
53
 
 
54
 
        _typeTimeout = new QTimer( this );
55
 
        connect( _typeTimeout, SIGNAL(timeout()), this, SLOT(line_edit_changed()) );
56
 
 
57
 
        connect( output_view, SIGNAL(executed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
58
 
        connect( output_view, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
59
 
 
60
 
        updateDBDateLabel();
61
 
}
62
 
 
63
 
CTags2Widget::~CTags2Widget()
64
 
{
65
 
}
66
 
 
67
 
void CTags2Widget::displayHits( Tags::TagList const & list )
68
 
{
69
 
        output_view->clear();
70
 
        showHitCount( list.count() );
71
 
 
72
 
        Tags::TagList::ConstIterator it = list.begin();
73
 
        while( it != list.end() )
74
 
        {
75
 
                new TagItem( output_view, (*it).tag, (*it).type, (*it).file, (*it).pattern );
76
 
                ++it;
77
 
        }
78
 
 
79
 
        output_view->adjustColumn(0);
80
 
        output_view->adjustColumn(1);
81
 
        output_view->adjustColumn(2);
82
 
 
83
 
}
84
 
 
85
 
void CTags2Widget::displayHitsAndClear( Tags::TagList const & list )
86
 
{
87
 
        input_edit->blockSignals( true );
88
 
        input_edit->clear();
89
 
        input_edit->blockSignals( false );
90
 
 
91
 
        displayHits( list );
92
 
}
93
 
 
94
 
void CTags2Widget::line_edit_changed( )
95
 
{
96
 
        displayHits( Tags::getPartialMatches( input_edit->text() ) );
97
 
}
98
 
 
99
 
void CTags2Widget::line_edit_changed_delayed( )
100
 
{
101
 
        showHitCount( calculateHitCount() );
102
 
        _typeTimeout->start( 500, true );
103
 
}
104
 
 
105
 
void CTags2Widget::showHitCount( int n )
106
 
{
107
 
        hitcount_label->setText( i18n("Hits: %1").arg( n ) );
108
 
}
109
 
 
110
 
int CTags2Widget::calculateHitCount( )
111
 
{
112
 
        return Tags::numberOfPartialMatches( input_edit->text() ) ;
113
 
}
114
 
 
115
 
void CTags2Widget::itemExecuted( QListViewItem * item )
116
 
{
117
 
        TagItem * tagItem = static_cast<TagItem*>( item );
118
 
 
119
 
        KURL url;
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;
124
 
        }
125
 
        else {
126
 
                fileWithTagInside = tagItem->file;
127
 
        }
128
 
 
129
 
        url.setPath(fileWithTagInside);
130
 
 
131
 
        _part->partController()->editDocument( url, _part->getFileLineFromPattern( url, tagItem->pattern ) );
132
 
}
133
 
 
134
 
void CTags2Widget::regeneratebutton_clicked()
135
 
{
136
 
        QApplication::setOverrideCursor(Qt::waitCursor);
137
 
 
138
 
        _part->createTagsFile();
139
 
 
140
 
        QApplication::restoreOverrideCursor();
141
 
 
142
 
        updateDBDateLabel();
143
 
}
144
 
 
145
 
void CTags2Widget::updateDBDateLabel( )
146
 
{
147
 
        QStringList tagFiles = Tags::getTagFiles();
148
 
        QFileInfo tagsdb(tagFiles[0]);
149
 
        if ( tagsdb.exists() )
150
 
        {
151
 
                datetime_label->setText( tagsdb.created().date().toString( Qt::ISODate ) );
152
 
        }
153
 
        else
154
 
        {
155
 
                datetime_label->setText( i18n("No CTags database found") );
156
 
        }
157
 
}
158
 
 
159
 
void CTags2Widget::focusInEvent( QFocusEvent* )
160
 
{
161
 
        updateDBDateLabel();
162
 
        input_edit->setFocus();
163
 
}
164
 
 
165
 
void CTags2Widget::goToNext( )
166
 
{
167
 
        QListViewItem * item = output_view->firstChild();
168
 
        while( item )
169
 
        {
170
 
                if ( item->isSelected() )
171
 
                {
172
 
                        // found the current, take the next
173
 
                        item->setSelected( false );
174
 
                        if ( (item = item->nextSibling()) != NULL )
175
 
                        {
176
 
                                item->setSelected( true );
177
 
                                output_view->repaint( true );
178
 
                                itemExecuted( item );
179
 
                                return;
180
 
                        }
181
 
                        else
182
 
                        {
183
 
                                break;
184
 
                        }
185
 
                }
186
 
                item = item->nextSibling();
187
 
        }
188
 
        // use the first
189
 
        if ( (item = output_view->firstChild()) != NULL )
190
 
        {
191
 
                item->setSelected( true );
192
 
                itemExecuted( item );
193
 
        }
194
 
}
195
 
 
196
 
#include "ctags2_widget.moc"
197
 
 
198
 
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
199