KDevelop API Documentation

parts/ctags/ctagsdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 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 "ctagsdlg.h" 00013 00014 #include <qcheckbox.h> 00015 #include <qfile.h> 00016 #include <qhbox.h> 00017 #include <qheader.h> 00018 #include <qlabel.h> 00019 #include <qlayout.h> 00020 #include <qlineedit.h> 00021 #include <qlistview.h> 00022 #include <qpushbutton.h> 00023 #include <qtextstream.h> 00024 #include <qregexp.h> 00025 #include <kbuttonbox.h> 00026 #include <kdebug.h> 00027 #include <kdialog.h> 00028 #include <klistbox.h> 00029 #include <klocale.h> 00030 #include <kmessagebox.h> 00031 00032 #include "kdevplugin.h" 00033 #include "kdevcore.h" 00034 #include "kdevpartcontroller.h" 00035 #include "kdevproject.h" 00036 #include "ctagskinds.h" 00037 00038 00039 class CTagsResultItem : public QListBoxText 00040 { 00041 public: 00042 CTagsResultItem(QListBox *parent, const QString &fileName, const QString pattern, 00043 const QString &kindString) 00044 : QListBoxText(parent, QString("%1:%2 (%3)").arg(fileName).arg(pattern).arg(kindString)), 00045 m_fileName(fileName), m_pattern(pattern), m_kindString(kindString) 00046 {} 00047 00048 QString fileName() const 00049 { return m_fileName; } 00050 QString pattern() const 00051 { return m_pattern; } 00052 00053 private: 00054 QString m_fileName; 00055 QString m_pattern; 00056 QString m_kindString; 00057 }; 00058 00059 00060 CTagsDialog::CTagsDialog(CTagsPart *part) 00061 : QDialog(0, "ctags dialog", false) 00062 { 00063 setCaption(i18n("Search in Tags")); 00064 QFontMetrics fm(fontMetrics()); 00065 00066 QLabel *tagLabel = new QLabel(i18n("&Tag:"), this); 00067 00068 tagEdit = new QLineEdit(this); 00069 tagEdit->setFocus(); 00070 tagLabel->setBuddy(tagEdit); 00071 tagEdit->setMinimumWidth(fm.width('X')*30); 00072 00073 regexpBox = new QCheckBox(i18n("&Regular expression match"), this); 00074 regexpBox->setChecked(true); 00075 00076 QLabel *kindsLabel = new QLabel(i18n("&Kinds:"), this); 00077 00078 kindsListView = new QListView(this); 00079 kindsLabel->setBuddy(kindsListView); 00080 kindsListView->setResizeMode(QListView::LastColumn); 00081 kindsListView->addColumn(QString::null); 00082 kindsListView->header()->hide(); 00083 kindsListView->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); 00084 00085 KButtonBox *actionBox = new KButtonBox(this, Qt::Vertical); 00086 actionBox->addStretch(); 00087 QPushButton *regenerateButton = actionBox->addButton(i18n("&Regenerate")); 00088 regenerateButton->setDefault(true); 00089 QPushButton *cancelButton = actionBox->addButton(i18n("Close")); 00090 actionBox->addStretch(); 00091 actionBox->layout(); 00092 00093 resultsListBox = new KListBox(this); 00094 resultsListBox->setMinimumHeight(fm.lineSpacing()*10); 00095 resultsListBox->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding)); 00096 00097 QGridLayout *layout = new QGridLayout(this, 5, 2, KDialog::marginHint(), KDialog::spacingHint()); 00098 layout->addRowSpacing(3, 10); 00099 layout->addWidget(tagLabel, 0, 0); 00100 layout->addWidget(tagEdit, 0, 1); 00101 layout->addWidget(regexpBox, 1, 1); 00102 layout->addWidget(kindsLabel, 2, 0); 00103 layout->addWidget(kindsListView, 2, 1); 00104 layout->addMultiCellWidget(actionBox, 0, 2, 2, 2); 00105 layout->addMultiCellWidget(resultsListBox, 4, 4, 0, 2); 00106 00107 connect( tagEdit, SIGNAL(textChanged(const QString&)), 00108 this, SLOT(slotSearch()) ); 00109 connect( kindsListView, SIGNAL(clicked(QListViewItem*)), 00110 this, SLOT(slotSearch()) ); 00111 connect( kindsListView, SIGNAL(returnPressed(QListViewItem*)), 00112 this, SLOT(slotSearch()) ); 00113 connect( regexpBox, SIGNAL(toggled(bool)), 00114 this, SLOT(slotSearch()) ); 00115 connect( regenerateButton, SIGNAL(clicked()), 00116 this, SLOT(slotRegenerate()) ); 00117 connect( cancelButton, SIGNAL(clicked()), 00118 this, SLOT(reject()) ); 00119 connect( resultsListBox, SIGNAL(clicked(QListBoxItem*)), 00120 this, SLOT(slotResultClicked(QListBoxItem*)) ); 00121 connect( resultsListBox, SIGNAL(returnPressed(QListBoxItem*)), 00122 this, SLOT(slotResultClicked(QListBoxItem*)) ); 00123 00124 m_part = part; 00125 updateInfo(); 00126 } 00127 00128 00129 CTagsDialog::~CTagsDialog() 00130 {} 00131 00132 00133 void CTagsDialog::updateInfo() 00134 { 00135 m_tags = m_part->tags(); 00136 m_kindStrings = m_part->kindStrings(); 00137 00138 kindsListView->clear(); 00139 00140 QStringList::ConstIterator it; 00141 for (it = m_kindStrings.begin(); it != m_kindStrings.end(); ++it) { 00142 QCheckListItem *item = new QCheckListItem(kindsListView, (*it), QCheckListItem::CheckBox); 00143 item->setOn(true); 00144 } 00145 } 00146 00147 00148 void CTagsDialog::slotSearch() 00149 { 00150 kdDebug(9022) << "search tag" << endl; 00151 if (m_tags.isEmpty()) 00152 return; 00153 00154 // Collect wanted kinds 00155 QStringList kindStringList; 00156 QCheckListItem *clitem = static_cast<QCheckListItem*>(kindsListView->firstChild()); 00157 while (clitem) { 00158 if (clitem->isOn()) 00159 kindStringList.append(clitem->text()); 00160 clitem = static_cast<QCheckListItem*>(clitem->nextSibling()); 00161 } 00162 resultsListBox->clear(); 00163 00164 if (regexpBox->isChecked()) { 00165 // Do the regexp search 00166 QRegExp re(tagEdit->text()); 00167 CTagsMapConstIterator it; 00168 for (it = m_tags.begin(); it != m_tags.end(); ++it) 00169 if (re.exactMatch(it.key())) 00170 insertResult(it.data(), kindStringList); 00171 } else { 00172 // Do the exact search 00173 CTagsMapIterator result = m_tags.find(tagEdit->text()); 00174 if (result != m_tags.end()) 00175 insertResult(*result, kindStringList); 00176 } 00177 } 00178 00179 00180 void CTagsDialog::insertResult(const CTagsTagInfoList &result, const QStringList &kindStringList) 00181 { 00182 // Iterate over all found items, check if they have one of the wanted 00183 // kinds, and insert them in the result box 00184 CTagsTagInfoListConstIterator it; 00185 for (it = result.begin(); it != result.end(); ++it) { 00186 QString extension; 00187 if ((*it).fileName.right(9) == "/Makefile") 00188 extension = "mak"; 00189 else { 00190 int pos = (*it).fileName.findRev('.'); 00191 if (pos > 0) 00192 extension = (*it).fileName.mid(pos+1); 00193 } 00194 if (extension.isNull()) 00195 continue; 00196 QString kindString = CTagsKinds::findKind((*it).kind, extension); 00197 if (!kindStringList.contains(kindString)) 00198 continue; 00199 00200 new CTagsResultItem(resultsListBox, (*it).fileName, (*it).pattern, kindString); 00201 } 00202 } 00203 00204 00205 void CTagsDialog::slotRegenerate() 00206 { 00207 if (!m_part->createTagsFile()) { 00208 KMessageBox::sorry(this, i18n("Could not create tags file")); 00209 return; 00210 } 00211 00212 m_part->loadTagsFile(); 00213 00214 updateInfo(); 00215 } 00216 00217 00218 void CTagsDialog::slotResultClicked(QListBoxItem *item) 00219 { 00220 if (!item) 00221 return; 00222 00223 CTagsResultItem *ritem = static_cast<CTagsResultItem*>(item); 00224 QString fileName = ritem->fileName(); 00225 if (!fileName.startsWith("/")) 00226 fileName.prepend(m_part->project()->projectDirectory() + "/"); 00227 QString pattern = ritem->pattern(); 00228 bool ok; 00229 int lineNum = pattern.toInt(&ok); 00230 if (!ok) { 00231 KMessageBox::sorry(0, i18n("Currently, only tags with line numbers (option -n) are supported")); 00232 return; 00233 } 00234 00235 m_part->partController()->editDocument(fileName, lineNum-1); 00236 } 00237 00238 #include "ctagsdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:10 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003