KDevelop API Documentation

ctags2_widget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Jens Dagerbo                                    *
00003  *   jens.dagerbo@swipnet.se                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include <qtimer.h>
00013 #include <qlineedit.h>
00014 #include <qlabel.h>
00015 #include <qfileinfo.h>
00016 #include <qdatetime.h>
00017 #include <qfocusdata.h>
00018 
00019 #include <klistview.h>
00020 #include <klocale.h>
00021 #include <kdebug.h>
00022 #include <kurl.h>
00023 #include <kapplication.h>
00024 
00025 #include <kdevproject.h>
00026 #include <kdevpartcontroller.h>
00027 
00028 #include "ctags2_widget.h"
00029 #include "tags.h"
00030 
00031 class TagItem : public QListViewItem
00032 {
00033 public:
00034     TagItem(QListView * lv, QString const & tag, QString const & type, QString const & file, QString const & pattern );
00035 
00036     QString tag;
00037     QString type;
00038     QString file;
00039     QString pattern;
00040 };
00041 
00042 TagItem::TagItem( QListView * lv, QString const & tag, QString const & type, QString const & file, QString const & pattern )
00043     : QListViewItem( lv, tag, type, file ), tag(tag), type(type), file(file), pattern(pattern)
00044 {}
00045 
00046 CTags2Widget::CTags2Widget( CTags2Part * part, const char* name, WFlags fl)
00047 : CTags2WidgetBase(0,name,fl), _part(part)
00048 {
00049     _typeTimeout = new QTimer( this );
00050     connect( _typeTimeout, SIGNAL(timeout()), this, SLOT(line_edit_changed()) );
00051     
00052     connect( output_view, SIGNAL(executed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
00053     connect( output_view, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(itemExecuted(QListViewItem*)) );
00054     
00055     updateDBDateLabel();    
00056 }
00057 
00058 CTags2Widget::~CTags2Widget()
00059 {
00060 }
00061 
00062 void CTags2Widget::displayHits( Tags::TagList const & list )
00063 {
00064     output_view->clear();
00065     showHitCount( list.count() );
00066     
00067     Tags::TagList::ConstIterator it = list.begin();
00068     while( it != list.end() )
00069     {
00070         new TagItem( output_view, (*it).tag, (*it).type, (*it).file, (*it).pattern );
00071         ++it;
00072     }   
00073 }
00074 
00075 void CTags2Widget::displayHitsAndClear( Tags::TagList const & list )
00076 {
00077     input_edit->blockSignals( true );
00078     input_edit->clear();
00079     input_edit->blockSignals( false );
00080     
00081     displayHits( list );
00082 }
00083 
00084 void CTags2Widget::line_edit_changed( )
00085 {
00086     displayHits( Tags::getPartialMatches( input_edit->text() ) );   
00087 }
00088 
00089 void CTags2Widget::line_edit_changed_delayed( )
00090 {
00091     showHitCount( calculateHitCount() );
00092     _typeTimeout->start( 500, true );
00093 }
00094 
00095 void CTags2Widget::showHitCount( int n )
00096 {
00097     hitcount_label->setText( i18n("Hits: ") + QString::number( n ) );
00098 }
00099 
00100 int CTags2Widget::calculateHitCount( )
00101 {
00102     return Tags::numberOfPartialMatches( input_edit->text() ) ;
00103 }
00104 
00105 void CTags2Widget::itemExecuted( QListViewItem * item )
00106 {
00107     TagItem * tagItem = static_cast<TagItem*>( item );
00108     
00109     KURL url;
00110     url.setPath( _part->project()->projectDirectory() + "/" + tagItem->file );
00111     
00112     _part->partController()->editDocument( url, _part->getFileLineFromPattern( url, tagItem->pattern ) );
00113 }
00114 
00115 void CTags2Widget::regeneratebutton_clicked()
00116 {
00117     kdDebug() << k_funcinfo << endl;
00118 
00119     QApplication::setOverrideCursor(Qt::waitCursor);
00120     
00121     _part->createTagsFile();
00122     
00123     QApplication::restoreOverrideCursor();
00124     
00125     updateDBDateLabel();
00126 }
00127 
00128 void CTags2Widget::updateDBDateLabel( )
00129 {
00130     QFileInfo tagsdb( Tags::getTagsFile() );
00131     if ( tagsdb.exists() )
00132     {
00133         datetime_label->setText( tagsdb.created().date().toString( Qt::ISODate ) );
00134     }
00135     else
00136     {
00137         datetime_label->setText( i18n("No CTAGS database found") );
00138     }
00139 }
00140 
00141 void CTags2Widget::focusInEvent( QFocusEvent * /*e*/ )
00142 {
00143     input_edit->setFocus();
00144 /*  QFocusData *fd = focusData();
00145     QWidget *next = fd->next();
00146     if (next)
00147         next->setFocus();*/
00148 }
00149 
00150 #include "ctags2_widget.moc"
00151 
00152 // kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
00153 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:38 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003