00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "grepdlg.h"
00013
00014
#include <qlayout.h>
00015
#include <qpushbutton.h>
00016
#include <qregexp.h>
00017
#include <qhbox.h>
00018
#include <qwhatsthis.h>
00019
#include <qstringlist.h>
00020
#include <kfiledialog.h>
00021
#include <kbuttonbox.h>
00022
#include <kpushbutton.h>
00023
#include <kapplication.h>
00024
#include <kiconloader.h>
00025
#include <klocale.h>
00026
#include <kconfig.h>
00027
#include <kmessagebox.h>
00028
#include <kdebug.h>
00029
#include <kdeversion.h>
00030
#include <qlabel.h>
00031
#include <kcombobox.h>
00032
#include <kurlcompletion.h>
00033
#include <kurlrequester.h>
00034
#include <kstdguiitem.h>
00035
00036
#include "grepviewpart.h"
00037
00038
00039 const char *
template_desc[] = {
00040
"verbatim",
00041
"assignment",
00042
"->MEMBER(",
00043
"class::MEMBER(",
00044
"OBJECT->member(",
00045
"[OBJECT method",
00046 0
00047 };
00048
00049 const char *
template_str[] = {
00050
"%s",
00051
"\\<%s\\>[\\t ]*=[^=]",
00052
"\\->[\\t ]*\\<%s\\>[\\t ]*\\(",
00053
"[a-z0-9_$]\\+[\\t ]*::[\\t ]*\\<%s\\>[\\t ]*\\(",
00054
"\\<%s\\>[\\t ]*\\->[\\t ]*[a-z0-9_$]\\+[\\t ]*\\(",
00055
"\\[[\\t ]*\\<%s\\>[\\t ]*[a-zA-Z0-9_$:]",
00056 0
00057 };
00058
00059 const char *
filepatterns[] = {
00060
"*.h,*.hxx,*.hpp,*.hh,*.h++,*.H,*.tlh,*.cpp,*.cc,*.C,*.c++,*.cxx,*.inl,*.idl,*.c,*.m,*.mm,*.M",
00061
"*.cpp,*.cc,*.C,*.c++,*.cxx,*.inl,*.c,*.m,*.mm,*.M",
00062
"*.h,*.hxx,*.hpp,*.hh,*.h++,*.H,*.tlh,*.idl",
00063
"*.java",
00064
"*",
00065 0
00066 };
00067
00068
00069 GrepDialog::GrepDialog(
QWidget *parent,
const char *name)
00070 :
QDialog(parent, name, false)
00071 {
00072 setCaption(i18n(
"Search in Files"));
00073
00074
config = GrepViewFactory::instance()->config();
00075
config->
setGroup(
"GrepDialog");
00076
00077
QGridLayout *layout =
new QGridLayout(
this, 6, 2, 10, 4);
00078 layout->addRowSpacing(4, 10);
00079 layout->setRowStretch(4, 0);
00080 layout->setColStretch(0, 0);
00081 layout->setColStretch(1, 20);
00082
00083
QLabel *pattern_label =
new QLabel(i18n(
"&Pattern:"),
this);
00084 layout->addWidget(pattern_label, 0, 0, AlignRight | AlignVCenter);
00085
00086
pattern_combo =
new QComboBox(
true,
this);
00087 pattern_label->setBuddy(
pattern_combo);
00088
pattern_combo->setFocus();
00089
pattern_combo->insertStringList(
config->
readListEntry(
"LastSearchItems"));
00090
pattern_combo->setInsertionPolicy(QComboBox::NoInsertion);
00091 layout->addWidget(
pattern_combo, 0, 1);
00092
00093 QLabel *template_label =
new QLabel(i18n(
"&Template:"),
this);
00094 layout->addWidget(template_label, 1, 0, AlignRight | AlignVCenter);
00095
00096
QBoxLayout *template_layout =
new QHBoxLayout(4);
00097 layout->addLayout(template_layout, 1, 1);
00098
00099
template_edit =
new QLineEdit(
this);
00100 template_label->setBuddy(
template_edit);
00101
template_edit->setText(
template_str[0]);
00102 template_layout->
addWidget(
template_edit, 1);
00103
00104 QComboBox *template_combo =
new QComboBox(
false,
this);
00105 template_combo->insertStrList(
template_desc);
00106 template_layout->
addWidget(template_combo, 0);
00107
00108 QLabel *files_label =
new QLabel(i18n(
"&Files:"),
this);
00109 layout->addWidget(files_label, 2, 0, AlignRight | AlignVCenter);
00110
00111
files_combo =
new QComboBox(
true,
this);
00112 files_label->setBuddy(
files_combo->focusProxy());
00113
files_combo->insertStrList(
filepatterns);
00114 layout->addWidget(
files_combo, 2, 1);
00115
00116 QLabel *dir_label =
new QLabel(i18n(
"&Directory:"),
this);
00117 layout->addWidget(dir_label, 3, 0, AlignRight | AlignVCenter);
00118
00119
QBoxLayout *dir_layout =
new QHBoxLayout(4);
00120 layout->addLayout(dir_layout, 3, 1);
00121
00122
dir_combo =
new KComboBox(
true,
this );
00123
#if KDE_VERSION >= 0x030103
00124
dir_combo->insertStringList(
config->
readPathListEntry(
"LastSearchPaths"));
00125
#else
00126
dir_combo->insertStringList(
config->
readListEntry(
"LastSearchPaths"));
00127
#endif
00128
dir_combo->setInsertionPolicy(QComboBox::NoInsertion);
00129
dir_combo->setEditText(QDir::homeDirPath());
00130
00131
url_requester =
new KURLRequester(
dir_combo,
this );
00132
url_requester->
completionObject()->
setMode(KURLCompletion::DirCompletion);
00133
url_requester->
setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
00134
00135 dir_label->setBuddy(
url_requester );
00136
dir_combo->setMinimumWidth(
dir_combo->fontMetrics().maxWidth()*25);
00137 dir_layout->
addWidget(
url_requester, 10 );
00138
00139
recursive_box =
new QCheckBox(i18n(
"&Recursive"),
this);
00140
recursive_box->setChecked(
true);
00141 dir_layout->addSpacing(10);
00142 dir_layout->
addWidget(
recursive_box);
00143
00144
# ifdef IGNORE_SCM_DIRS
00145
ignore_scm_box =
new QCheckBox(i18n(
"S&kip VCS dirs"),
this);
00146
ignore_scm_box->setChecked(
true);
00147 dir_layout->addSpacing(10);
00148 dir_layout->
addWidget(
ignore_scm_box);
00149
# endif
00150
00151
QBoxLayout *button_layout =
new QHBoxLayout(4);
00152 layout->addLayout(button_layout, 5, 1);
00153
search_button =
new QPushButton(i18n(
"&Search"),
this);
00154
search_button->setDefault(
true);
00155
KPushButton *done_button =
new KPushButton(KStdGuiItem::cancel(),
this);
00156 button_layout->addStretch();
00157 button_layout->
addWidget(
search_button);
00158 button_layout->
addWidget(done_button);
00159
00160 resize(sizeHint());
00161
00162 QWhatsThis::add(
pattern_combo,
00163 i18n(
"<qt>Enter the regular expression you want to search for here.<p>"
00164
"Possible meta characters are:"
00165
"<ul>"
00166
"<li><b>.</b> - Matches any character"
00167
"<li><b>^</b> - Matches the beginning of a line"
00168
"<li><b>$</b> - Matches the end of a line"
00169
"<li><b>\\<</b> - Matches the beginning of a word"
00170
"<li><b>\\></b> - Matches the end of a word"
00171
"</ul>"
00172
"The following repetition operators exist:"
00173
"<ul>"
00174
"<li><b>?</b> - The preceding item is matched at most once"
00175
"<li><b>*</b> - The preceding item is matched zero or more times"
00176
"<li><b>+</b> - The preceding item is matched one or more times"
00177
"<li><b>{<i>n</i>}</b> - The preceding item is matched exactly <i>n</i> times"
00178
"<li><b>{<i>n</i>,}</b> - The preceding item is matched <i>n</i> or more times"
00179
"<li><b>{,<i>n</i>}</b> - The preceding item is matched at most <i>n</i> times"
00180
"<li><b>{<i>n</i>,<i>m</i>}</b> - The preceding item is matched at least <i>n</i>, "
00181
"but at most <i>m</i> times."
00182
"</ul>"
00183
"Furthermore, backreferences to bracketed subexpressions are "
00184
"available via the notation \\<i>n</i>.</qt>"
00185 ));
00186 QWhatsThis::add(
files_combo,
00187 i18n(
"Enter the file name pattern of the files to search here. "
00188
"You may give several patterns separated by commas"));
00189 QWhatsThis::add(
template_edit,
00190 i18n(
"You can choose a template for the pattern from the combo box "
00191
"and edit it here. The string %s in the template is replaced "
00192
"by the pattern input field, resulting in the regular expression "
00193
"to search for."));
00194
00195 connect( template_combo, SIGNAL(activated(
int)),
00196 SLOT(
templateActivated(
int)) );
00197 connect(
search_button, SIGNAL(clicked()),
00198 SLOT(
slotSearchClicked()) );
00199 connect( done_button, SIGNAL(clicked()),
00200 SLOT(hide()) );
00201 connect(
pattern_combo->lineEdit(), SIGNAL( textChanged (
const QString & ) ),
00202 SLOT(
slotPatternChanged(
const QString & ) ) );
00203
slotPatternChanged(
pattern_combo->currentText() );
00204 }
00205
00206
00207 static QStringList qCombo2StringList(
QComboBox* combo )
00208 {
00209
QStringList list;
00210
if (!combo)
00211
return list;
00212
for (
int i = 0; i < combo->count(); ++i ) {
00213 list << combo->text(i);
00214 }
00215
return list;
00216 }
00217
00218 GrepDialog::~GrepDialog()
00219 {
00220
config->
setGroup(
"GrepDialog");
00221
00222
config->
writeEntry(
"LastSearchItems",
qCombo2StringList(
pattern_combo));
00223
#if KDE_VERSION >= 0x030103
00224
config->
writePathEntry(
"LastSearchPaths",
qCombo2StringList(
dir_combo));
00225
#else
00226
config->
writeEntry(
"LastSearchPaths",
qCombo2StringList(
dir_combo));
00227
#endif
00228
}
00229
00230 void GrepDialog::slotPatternChanged(
const QString & _text )
00231 {
00232
search_button->setEnabled( !_text.isEmpty() );
00233 }
00234
00235 void GrepDialog::templateActivated(
int index)
00236 {
00237
template_edit->setText(
template_str[index]);
00238 }
00239
00240
00241 static bool qComboContains(
const QString& s,
QComboBox* combo )
00242 {
00243
if (!combo)
00244
return false;
00245
for (
int i = 0; i < combo->count(); ++i ) {
00246
if (combo->text(i) == s) {
00247
return true;
00248 }
00249 }
00250
return false;
00251 }
00252
00253 void GrepDialog::slotSearchClicked()
00254 {
00255
if (
pattern_combo->currentText().isEmpty()) {
00256 KMessageBox::sorry(
this, i18n(
"Please enter a search pattern"));
00257
pattern_combo->setFocus();
00258
return;
00259 }
00260
00261
if (!
qComboContains(
pattern_combo->currentText(),
pattern_combo)) {
00262
pattern_combo->insertItem(
pattern_combo->currentText(), 0);
00263 }
00264
if (
pattern_combo->count() > 15) {
00265
pattern_combo->removeItem(15);
00266 }
00267
if (!
qComboContains(
dir_combo->currentText(),
dir_combo)) {
00268
dir_combo->insertItem(
dir_combo->currentText(), 0);
00269 }
00270
if (
dir_combo->count() > 15) {
00271
dir_combo->removeItem(15);
00272 }
00273
00274 emit
searchClicked();
00275 hide();
00276 }
00277
00278 void GrepDialog::show()
00279 {
00280
00281
00282
if (isVisible())
00283 QDialog::hide();
00284 QDialog::show();
00285
pattern_combo->setFocus();
00286 }
00287
00288
#include "grepdlg.moc"