Changeset View
Changeset View
Standalone View
Standalone View
plugins/grepview/grepdialog.cpp
Show All 9 Lines | |||||
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * | ||
11 | * * | 11 | * * | ||
12 | ***************************************************************************/ | 12 | ***************************************************************************/ | ||
13 | 13 | | |||
14 | #include "grepdialog.h" | 14 | #include "grepdialog.h" | ||
15 | 15 | | |||
16 | #include <algorithm> | 16 | #include <algorithm> | ||
17 | 17 | | |||
18 | #include <QCloseEvent> | ||||
18 | #include <QDialogButtonBox> | 19 | #include <QDialogButtonBox> | ||
19 | #include <QDir> | 20 | #include <QDir> | ||
20 | #include <QFileDialog> | 21 | #include <QFileDialog> | ||
21 | #include <QLineEdit> | 22 | #include <QLineEdit> | ||
22 | #include <QMenu> | 23 | #include <QMenu> | ||
23 | #include <QPushButton> | 24 | #include <QPushButton> | ||
25 | #include <QShowEvent> | ||||
24 | #include <QStringList> | 26 | #include <QStringList> | ||
27 | #include <QTimer> | ||||
25 | 28 | | |||
26 | #include <KComboBox> | 29 | #include <KComboBox> | ||
27 | #include <KCompletion> | 30 | #include <KCompletion> | ||
28 | #include <KConfigGroup> | 31 | #include <KConfigGroup> | ||
29 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
30 | #include <KUrlCompletion> | 33 | #include <KUrlCompletion> | ||
31 | 34 | | |||
32 | #include <interfaces/icore.h> | 35 | #include <interfaces/icore.h> | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
102 | inline QStringList excludepatterns() { return QStringList() | 105 | inline QStringList excludepatterns() { return QStringList() | ||
103 | << QStringLiteral("/CVS/,/SCCS/,/.svn/,/_darcs/,/build/,/.git/") | 106 | << QStringLiteral("/CVS/,/SCCS/,/.svn/,/_darcs/,/build/,/.git/") | ||
104 | << QLatin1String(""); | 107 | << QLatin1String(""); | ||
105 | } | 108 | } | ||
106 | 109 | | |||
107 | ///Separator used to separate search paths. | 110 | ///Separator used to separate search paths. | ||
108 | inline QString pathsSeparator() { return (QStringLiteral(";")); } | 111 | inline QString pathsSeparator() { return (QStringLiteral(";")); } | ||
109 | 112 | | |||
113 | ///Returns the chosen directories or files (only the top directories, not subfiles) | ||||
114 | QList<QUrl> getDirectoryChoice(const QString& text) | ||||
115 | { | ||||
116 | QList<QUrl> ret; | ||||
117 | if (text == allOpenFilesString()) { | ||||
118 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) | ||||
119 | ret << doc->url(); | ||||
120 | } else if (text == allOpenProjectsString()) { | ||||
121 | foreach(IProject* project, ICore::self()->projectController()->projects()) | ||||
122 | ret << project->path().toUrl(); | ||||
123 | } else { | ||||
124 | QStringList semicolonSeparatedFileList = text.split(pathsSeparator()); | ||||
125 | if (!semicolonSeparatedFileList.isEmpty() && QFileInfo::exists(semicolonSeparatedFileList[0])) { | ||||
126 | // We use QFileInfo to make sure this is really a semicolon-separated file list, not a file containing | ||||
127 | // a semicolon in the name. | ||||
128 | foreach(const QString& file, semicolonSeparatedFileList) | ||||
129 | ret << QUrl::fromLocalFile(file).adjusted(QUrl::StripTrailingSlash); | ||||
130 | } else { | ||||
131 | ret << QUrl::fromUserInput(text).adjusted(QUrl::StripTrailingSlash); | ||||
132 | } | ||||
133 | } | ||||
134 | return ret; | ||||
135 | } | ||||
136 | | ||||
137 | ///Check if all directories are part of a project | ||||
138 | bool directoriesInProject(const QString& dir) | ||||
139 | { | ||||
140 | foreach (const QUrl& url, getDirectoryChoice(dir)) { | ||||
141 | IProject *proj = ICore::self()->projectController()->findProjectForUrl(url); | ||||
142 | if (!proj || !proj->path().toUrl().isLocalFile()) { | ||||
143 | return false; | ||||
144 | } | ||||
145 | } | ||||
146 | | ||||
147 | return true; | ||||
148 | } | ||||
149 | | ||||
croick: I made these static from the former directoryChanged and getDirectoryChoice member functions | |||||
110 | ///Max number of items in paths combo box. | 150 | ///Max number of items in paths combo box. | ||
111 | const int pathsMaxCount = 25; | 151 | const int pathsMaxCount = 25; | ||
112 | } | 152 | } | ||
113 | 153 | | |||
114 | GrepDialog::GrepDialog( GrepViewPlugin * plugin, QWidget *parent ) | 154 | GrepDialog::GrepDialog(GrepViewPlugin *plugin, QWidget *parent, bool show) | ||
115 | : QDialog(parent), Ui::GrepWidget(), m_plugin( plugin ) | 155 | : QDialog(parent), Ui::GrepWidget(), m_plugin(plugin), m_show(show) | ||
116 | { | 156 | { | ||
117 | setAttribute(Qt::WA_DeleteOnClose); | 157 | setAttribute(Qt::WA_DeleteOnClose); | ||
158 | | ||||
159 | // if we don't intend on showing the dialog, we can skip all UI setup | ||||
160 | if (!m_show) { | ||||
161 | return; | ||||
162 | } | ||||
163 | | ||||
118 | setWindowTitle( i18n("Find/Replace in Files") ); | 164 | setWindowTitle( i18n("Find/Replace in Files") ); | ||
119 | 165 | | |||
120 | setupUi(this); | 166 | setupUi(this); | ||
121 | adjustSize(); | 167 | adjustSize(); | ||
122 | 168 | | |||
123 | auto searchButton = buttonBox->button(QDialogButtonBox::Ok); | 169 | auto searchButton = buttonBox->button(QDialogButtonBox::Ok); | ||
124 | Q_ASSERT(searchButton); | 170 | Q_ASSERT(searchButton); | ||
125 | searchButton->setText(i18nc("@action:button", "Search...")); | 171 | searchButton->setText(i18nc("@action:button", "Search...")); | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 221 | connect(patternCombo, &QComboBox::editTextChanged, | |||
176 | this, &GrepDialog::patternComboEditTextChanged); | 222 | this, &GrepDialog::patternComboEditTextChanged); | ||
177 | patternComboEditTextChanged( patternCombo->currentText() ); | 223 | patternComboEditTextChanged( patternCombo->currentText() ); | ||
178 | patternCombo->setFocus(); | 224 | patternCombo->setFocus(); | ||
179 | 225 | | |||
180 | connect(searchPaths, static_cast<void(KComboBox::*)(const QString&)>(&KComboBox::activated), this, &GrepDialog::setSearchLocations); | 226 | connect(searchPaths, static_cast<void(KComboBox::*)(const QString&)>(&KComboBox::activated), this, &GrepDialog::setSearchLocations); | ||
181 | 227 | | |||
182 | directorySelector->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); | 228 | directorySelector->setIcon(QIcon::fromTheme(QStringLiteral("document-open"))); | ||
183 | connect(directorySelector, &QPushButton::clicked, this, &GrepDialog::selectDirectoryDialog ); | 229 | connect(directorySelector, &QPushButton::clicked, this, &GrepDialog::selectDirectoryDialog ); | ||
184 | directoryChanged(directorySelector->text()); | | |||
185 | } | 230 | } | ||
186 | 231 | | |||
187 | void GrepDialog::selectDirectoryDialog() | 232 | void GrepDialog::selectDirectoryDialog() | ||
188 | { | 233 | { | ||
189 | const QString dirName = QFileDialog::getExistingDirectory( | 234 | const QString dirName = QFileDialog::getExistingDirectory( | ||
190 | this, i18nc("@title:window", "Select directory to search in"), | 235 | this, i18nc("@title:window", "Select directory to search in"), | ||
191 | searchPaths->lineEdit()->text()); | 236 | searchPaths->lineEdit()->text()); | ||
192 | if (!dirName.isEmpty()) { | 237 | if (!dirName.isEmpty()) { | ||
Show All 23 Lines | |||||
216 | } | 261 | } | ||
217 | 262 | | |||
218 | QMenu* GrepDialog::createSyncButtonMenu() | 263 | QMenu* GrepDialog::createSyncButtonMenu() | ||
219 | { | 264 | { | ||
220 | QMenu* ret = new QMenu(this); | 265 | QMenu* ret = new QMenu(this); | ||
221 | 266 | | |||
222 | QSet<Path> hadUrls; | 267 | QSet<Path> hadUrls; | ||
223 | 268 | | |||
224 | IDocument *doc = m_plugin->core()->documentController()->activeDocument(); | 269 | IDocument* doc = m_plugin->core()->documentController()->activeDocument(); | ||
225 | if ( doc ) | 270 | if (doc) { | ||
226 | { | | |||
227 | Path url = Path(doc->url()).parent(); | 271 | Path url = Path(doc->url()).parent(); | ||
228 | 272 | | |||
229 | // always add the current file's parent directory | 273 | // always add the current file's parent directory | ||
230 | hadUrls.insert(url); | 274 | hadUrls.insert(url); | ||
231 | addUrlToMenu(ret, url.toUrl()); | 275 | addUrlToMenu(ret, url.toUrl()); | ||
232 | 276 | | |||
233 | url = url.parent(); | 277 | url = url.parent(); | ||
234 | 278 | | |||
235 | while(m_plugin->core()->projectController()->findProjectForUrl(url.toUrl())) | 279 | while (m_plugin->core()->projectController()->findProjectForUrl(url.toUrl()) && | ||
236 | { | 280 | !hadUrls.contains(url)) { | ||
237 | if(hadUrls.contains(url)) | | |||
238 | break; | | |||
239 | hadUrls.insert(url); | 281 | hadUrls.insert(url); | ||
240 | addUrlToMenu(ret, url.toUrl()); | 282 | addUrlToMenu(ret, url.toUrl()); | ||
241 | url = url.parent(); | 283 | url = url.parent(); | ||
242 | } | 284 | } | ||
243 | } | 285 | } | ||
244 | 286 | | |||
245 | QVector<QUrl> otherProjectUrls; | 287 | QVector<QUrl> otherProjectUrls; | ||
246 | foreach(IProject* project, m_plugin->core()->projectController()->projects()) | 288 | foreach (IProject* project, m_plugin->core()->projectController()->projects()) { | ||
247 | { | | |||
248 | if (!hadUrls.contains(project->path())) { | 289 | if (!hadUrls.contains(project->path())) { | ||
249 | otherProjectUrls.append(project->path().toUrl()); | 290 | otherProjectUrls.append(project->path().toUrl()); | ||
250 | } | 291 | } | ||
251 | } | 292 | } | ||
252 | 293 | | |||
253 | // sort the remaining project URLs alphabetically | 294 | // sort the remaining project URLs alphabetically | ||
254 | std::sort(otherProjectUrls.begin(), otherProjectUrls.end()); | 295 | std::sort(otherProjectUrls.begin(), otherProjectUrls.end()); | ||
255 | foreach(const QUrl& url, otherProjectUrls) | 296 | foreach (const QUrl& url, otherProjectUrls) { | ||
256 | { | | |||
257 | addUrlToMenu(ret, url); | 297 | addUrlToMenu(ret, url); | ||
258 | } | 298 | } | ||
259 | 299 | | |||
260 | ret->addSeparator(); | 300 | ret->addSeparator(); | ||
261 | addStringToMenu(ret, allOpenFilesString()); | 301 | addStringToMenu(ret, allOpenFilesString()); | ||
262 | addStringToMenu(ret, allOpenProjectsString()); | 302 | addStringToMenu(ret, allOpenProjectsString()); | ||
263 | return ret; | 303 | return ret; | ||
264 | } | 304 | } | ||
265 | 305 | | |||
266 | void GrepDialog::directoryChanged(const QString& dir) | 306 | GrepDialog::~GrepDialog() | ||
267 | { | 307 | { | ||
268 | QUrl currentUrl = QUrl::fromLocalFile(dir); | | |||
269 | if( !currentUrl.isValid() ) { | | |||
270 | m_settings.projectFilesOnly = false; | | |||
271 | return; | | |||
272 | } | 308 | } | ||
273 | 309 | | |||
274 | bool projectAvailable = true; | 310 | void GrepDialog::setVisible(bool visible) | ||
275 | | ||||
276 | foreach(const QUrl& url, getDirectoryChoice()) | | |||
277 | { | | |||
278 | IProject *proj = ICore::self()->projectController()->findProjectForUrl( url ); | | |||
279 | if( !proj || !proj->path().toUrl().isLocalFile() ) | | |||
280 | projectAvailable = false; | | |||
281 | } | | |||
282 | | ||||
283 | m_settings.projectFilesOnly = projectAvailable; | | |||
284 | } | | |||
285 | | ||||
286 | GrepDialog::~GrepDialog() | | |||
287 | { | 311 | { | ||
312 | QDialog::setVisible(visible && m_show); | ||||
288 | } | 313 | } | ||
289 | 314 | | |||
290 | void GrepDialog::closeEvent(QCloseEvent* closeEvent) | 315 | void GrepDialog::closeEvent(QCloseEvent* closeEvent) | ||
291 | { | 316 | { | ||
292 | Q_UNUSED(closeEvent); | 317 | Q_UNUSED(closeEvent); | ||
293 | 318 | | |||
319 | if (!m_show) { | ||||
320 | return; | ||||
321 | } | ||||
322 | | ||||
294 | KConfigGroup cg = ICore::self()->activeSession()->config()->group( "GrepDialog" ); | 323 | KConfigGroup cg = ICore::self()->activeSession()->config()->group( "GrepDialog" ); | ||
295 | // memorize the last patterns and paths | 324 | // memorize the last patterns and paths | ||
296 | cg.writeEntry("LastSearchItems", qCombo2StringList(patternCombo)); | 325 | cg.writeEntry("LastSearchItems", qCombo2StringList(patternCombo)); | ||
297 | cg.writeEntry("regexp", regexCheck->isChecked()); | 326 | cg.writeEntry("regexp", regexCheck->isChecked()); | ||
298 | cg.writeEntry("depth", depthSpin->value()); | 327 | cg.writeEntry("depth", depthSpin->value()); | ||
299 | cg.writeEntry("search_project_files", limitToProjectCheck->isChecked()); | 328 | cg.writeEntry("search_project_files", limitToProjectCheck->isChecked()); | ||
300 | cg.writeEntry("case_sens", caseSensitiveCheck->isChecked()); | 329 | cg.writeEntry("case_sens", caseSensitiveCheck->isChecked()); | ||
301 | cg.writeEntry("exclude_patterns", qCombo2StringList(excludeCombo)); | 330 | cg.writeEntry("exclude_patterns", qCombo2StringList(excludeCombo)); | ||
Show All 24 Lines | 346 | { | |||
326 | // Note: everything else is set by a user | 355 | // Note: everything else is set by a user | ||
327 | } | 356 | } | ||
328 | 357 | | |||
329 | GrepJobSettings GrepDialog::settings() const | 358 | GrepJobSettings GrepDialog::settings() const | ||
330 | { | 359 | { | ||
331 | return m_settings; | 360 | return m_settings; | ||
332 | } | 361 | } | ||
333 | 362 | | |||
363 | void GrepDialog::historySearch(QList<GrepJobSettings> &settingsHistory) | ||||
364 | { | ||||
365 | // clear the current settings history and pass it to a job list | ||||
366 | m_historyJobSettings.clear(); | ||||
367 | m_historyJobSettings.swap(settingsHistory); | ||||
368 | | ||||
369 | // check if anything is do be done and if all projects are loaded | ||||
370 | if (!m_historyJobSettings.empty() && !checkProjectsOpened()) { | ||||
371 | connect(KDevelop::ICore::self()->projectController(), | ||||
372 | &KDevelop::IProjectController::projectOpened, | ||||
373 | this, &GrepDialog::checkProjectsOpened); | ||||
374 | } | ||||
375 | } | ||||
376 | | ||||
334 | void GrepDialog::setSearchLocations(const QString &dir) | 377 | void GrepDialog::setSearchLocations(const QString& dir) | ||
335 | { | 378 | { | ||
336 | if(!dir.isEmpty()) { | 379 | if (!dir.isEmpty()) { | ||
337 | if(QDir::isAbsolutePath(dir)) | 380 | if (m_show) { | ||
338 | { | 381 | if (QDir::isAbsolutePath(dir)) { | ||
339 | static_cast<KUrlCompletion*>(searchPaths->completionObject())->setDir( QUrl::fromLocalFile(dir) ); | 382 | static_cast<KUrlCompletion*>(searchPaths->completionObject())->setDir( QUrl::fromLocalFile(dir) ); | ||
340 | } | 383 | } | ||
341 | 384 | | |||
342 | if (searchPaths->contains(dir)) { | 385 | if (searchPaths->contains(dir)) { | ||
343 | searchPaths->removeItem(searchPaths->findText(dir)); | 386 | searchPaths->removeItem(searchPaths->findText(dir)); | ||
344 | } | 387 | } | ||
345 | 388 | | |||
346 | searchPaths->insertItem(0, dir); | 389 | searchPaths->insertItem(0, dir); | ||
347 | searchPaths->setCurrentItem(dir); | 390 | searchPaths->setCurrentItem(dir); | ||
348 | 391 | | |||
349 | if (searchPaths->count() > pathsMaxCount) { | 392 | if (searchPaths->count() > pathsMaxCount) { | ||
350 | searchPaths->removeItem(searchPaths->count() - 1); | 393 | searchPaths->removeItem(searchPaths->count() - 1); | ||
351 | } | 394 | } | ||
395 | } else { | ||||
396 | m_settings.searchPaths = dir; | ||||
397 | } | ||||
352 | } | 398 | } | ||
353 | directoryChanged(dir); | 399 | m_settings.projectFilesOnly = directoriesInProject(dir); | ||
354 | } | 400 | } | ||
355 | 401 | | |||
356 | void GrepDialog::patternComboEditTextChanged( const QString& text) | 402 | void GrepDialog::patternComboEditTextChanged(const QString& text) | ||
357 | { | 403 | { | ||
358 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); | 404 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); | ||
359 | } | 405 | } | ||
360 | 406 | | |||
361 | QList< QUrl > GrepDialog::getDirectoryChoice() const | 407 | bool GrepDialog::checkProjectsOpened() | ||
362 | { | 408 | { | ||
363 | QList< QUrl > ret; | 409 | // only proceed if all projects have been opened | ||
364 | QString text = searchPaths->currentText(); | 410 | if (KDevelop::ICore::self()->activeSession()->config()->group("General Options").readEntry("Open Projects", QList<QUrl>()).count() != | ||
I wonder if there is a better way to get the number of staged projects. croick: I wonder if there is a better way to get the number of staged projects. | |||||
365 | if(text == allOpenFilesString()) | 411 | KDevelop::ICore::self()->projectController()->projects().count()) | ||
366 | { | 412 | return false; | ||
367 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) | 413 | | ||
368 | ret << doc->url(); | 414 | foreach (IProject* p, KDevelop::ICore::self()->projectController()->projects()) { | ||
369 | }else if(text == allOpenProjectsString()) | 415 | if (!p->isReady()) | ||
370 | { | 416 | return false; | ||
371 | foreach(IProject* project, ICore::self()->projectController()->projects()) | 417 | } | ||
372 | ret << project->path().toUrl(); | 418 | | ||
373 | }else{ | 419 | // do the grep jobs one by one | ||
374 | QStringList semicolonSeparatedFileList = text.split(pathsSeparator()); | 420 | connect(m_plugin, &GrepViewPlugin::grepJobFinished, this, &GrepDialog::nextHistory); | ||
375 | if(!semicolonSeparatedFileList.isEmpty() && QFileInfo::exists(semicolonSeparatedFileList[0])) | 421 | QTimer::singleShot(0, this, &GrepDialog::nextHistory); | ||
422 | | ||||
423 | return true; | ||||
424 | } | ||||
425 | | ||||
426 | void GrepDialog::nextHistory() | ||||
376 | { | 427 | { | ||
377 | // We use QFileInfo to make sure this is really a semicolon-separated file list, not a file containing | 428 | if (!m_historyJobSettings.empty()) { | ||
378 | // a semicolon in the name. | 429 | m_settings = m_historyJobSettings.takeFirst(); | ||
379 | foreach(const QString& file, semicolonSeparatedFileList) | 430 | startSearch(); | ||
380 | ret << QUrl::fromLocalFile(file).adjusted(QUrl::StripTrailingSlash); | | |||
381 | }else{ | 431 | } else { | ||
382 | ret << QUrl::fromUserInput(searchPaths->currentText()).adjusted(QUrl::StripTrailingSlash); | 432 | close(); | ||
383 | } | | |||
384 | } | 433 | } | ||
385 | return ret; | | |||
386 | } | 434 | } | ||
387 | 435 | | |||
388 | bool GrepDialog::isPartOfChoice(QUrl url) const | 436 | bool GrepDialog::isPartOfChoice(QUrl url) const | ||
389 | { | 437 | { | ||
390 | foreach(const QUrl& choice, getDirectoryChoice()) | 438 | foreach(const QUrl& choice, getDirectoryChoice(m_settings.searchPaths)) { | ||
391 | if(choice.isParentOf(url) || choice == url) | 439 | if(choice.isParentOf(url) || choice == url) | ||
392 | return true; | 440 | return true; | ||
441 | } | ||||
393 | return false; | 442 | return false; | ||
394 | } | 443 | } | ||
395 | 444 | | |||
396 | void GrepDialog::startSearch() | 445 | void GrepDialog::startSearch() | ||
397 | { | 446 | { | ||
447 | // if m_show is false, all settings are fixed in m_settings | ||||
448 | if (m_show) | ||||
398 | updateSettings(); | 449 | updateSettings(); | ||
399 | 450 | | |||
451 | const QStringList include = GrepFindFilesThread::parseInclude(m_settings.files); | ||||
452 | const QStringList exclude = GrepFindFilesThread::parseExclude(m_settings.exclude); | ||||
453 | | ||||
400 | // search for unsaved documents | 454 | // search for unsaved documents | ||
401 | QList<IDocument*> unsavedFiles; | 455 | QList<IDocument*> unsavedFiles; | ||
402 | QStringList include = GrepFindFilesThread::parseInclude(m_settings.files); | 456 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) { | ||
403 | QStringList exclude = GrepFindFilesThread::parseExclude(m_settings.exclude); | | |||
404 | | ||||
405 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) | | |||
406 | { | | |||
407 | QUrl docUrl = doc->url(); | 457 | QUrl docUrl = doc->url(); | ||
408 | if(doc->state() != IDocument::Clean && isPartOfChoice(docUrl) && | 458 | if (doc->state() != IDocument::Clean && | ||
409 | QDir::match(include, docUrl.fileName()) && !QDir::match(exclude, docUrl.toLocalFile())) | 459 | isPartOfChoice(docUrl) && | ||
410 | { | 460 | QDir::match(include, docUrl.fileName()) && | ||
461 | !QDir::match(exclude, docUrl.toLocalFile()) | ||||
462 | ) { | ||||
411 | unsavedFiles << doc; | 463 | unsavedFiles << doc; | ||
412 | } | 464 | } | ||
413 | } | 465 | } | ||
414 | 466 | | |||
415 | if(!ICore::self()->documentController()->saveSomeDocuments(unsavedFiles)) | 467 | if(!ICore::self()->documentController()->saveSomeDocuments(unsavedFiles)) { | ||
416 | { | | |||
417 | close(); | 468 | close(); | ||
418 | return; | 469 | return; | ||
419 | } | 470 | } | ||
420 | 471 | | |||
421 | QList<QUrl> choice = getDirectoryChoice(); | 472 | const QString descriptionOrUrl(m_settings.searchPaths); | ||
473 | QList<QUrl> choice = getDirectoryChoice(descriptionOrUrl); | ||||
474 | QString description = descriptionOrUrl; | ||||
422 | 475 | | |||
423 | GrepJob* job = m_plugin->newGrepJob(); | 476 | GrepJob* job = m_plugin->newGrepJob(); | ||
424 | | ||||
425 | const QString descriptionOrUrl(searchPaths->currentText()); | | |||
426 | QString description = descriptionOrUrl; | | |||
427 | // Shorten the description | 477 | // Shorten the description | ||
428 | if(descriptionOrUrl != allOpenFilesString() && descriptionOrUrl != allOpenProjectsString()) { | 478 | if(descriptionOrUrl != allOpenFilesString() && descriptionOrUrl != allOpenProjectsString()) { | ||
429 | auto prettyFileName = [](const QUrl& url) { | 479 | auto prettyFileName = [](const QUrl& url) { | ||
430 | return ICore::self()->projectController()->prettyFileName(url, KDevelop::IProjectController::FormatPlain); | 480 | return ICore::self()->projectController()->prettyFileName(url, KDevelop::IProjectController::FormatPlain); | ||
431 | }; | 481 | }; | ||
432 | 482 | | |||
433 | if (choice.size() > 1) { | 483 | if (choice.size() > 1) { | ||
434 | description = i18np("%2, and %1 more item", "%2, and %1 more items", choice.size() - 1, prettyFileName(choice[0])); | 484 | description = i18np("%2, and %1 more item", "%2, and %1 more items", choice.size() - 1, prettyFileName(choice[0])); | ||
435 | } else if (!choice.isEmpty()) { | 485 | } else if (!choice.isEmpty()) { | ||
436 | description = prettyFileName(choice[0]); | 486 | description = prettyFileName(choice[0]); | ||
437 | } | 487 | } | ||
438 | } | 488 | } | ||
439 | 489 | | |||
440 | GrepOutputView *toolView = (GrepOutputView*)ICore::self()->uiController()-> | 490 | GrepOutputView* toolView = (GrepOutputView*)ICore::self()->uiController()-> | ||
441 | findToolView(i18n("Find/Replace in Files"), m_plugin->toolViewFactory(), IUiController::CreateAndRaise); | 491 | findToolView(i18n("Find/Replace in Files"), m_plugin->toolViewFactory(), IUiController::CreateAndRaise); | ||
442 | GrepOutputModel* outputModel = toolView->renewModel(m_settings.pattern, description); | 492 | GrepOutputModel* outputModel = toolView->renewModel(m_settings, description); | ||
443 | 493 | | |||
444 | connect(job, &GrepJob::showErrorMessage, | 494 | connect(job, &GrepJob::showErrorMessage, | ||
445 | toolView, &GrepOutputView::showErrorMessage); | 495 | toolView, &GrepOutputView::showErrorMessage); | ||
446 | //the GrepOutputModel gets the 'showMessage' signal to store it and forward | 496 | //the GrepOutputModel gets the 'showMessage' signal to store it and forward | ||
447 | //it to toolView | 497 | //it to toolView | ||
448 | connect(job, &GrepJob::showMessage, | 498 | connect(job, &GrepJob::showMessage, | ||
449 | outputModel, &GrepOutputModel::showMessageSlot); | 499 | outputModel, &GrepOutputModel::showMessageSlot); | ||
450 | connect(outputModel, &GrepOutputModel::showMessage, | 500 | connect(outputModel, &GrepOutputModel::showMessage, | ||
451 | toolView, &GrepOutputView::showMessage); | 501 | toolView, &GrepOutputView::showMessage); | ||
452 | 502 | | |||
453 | connect(toolView, &GrepOutputView::outputViewIsClosed, job, [=]() {job->kill();}); | 503 | connect(toolView, &GrepOutputView::outputViewIsClosed, job, [=]() {job->kill();}); | ||
454 | 504 | | |||
455 | job->setOutputModel(outputModel); | 505 | job->setOutputModel(outputModel); | ||
456 | job->setDirectoryChoice(choice); | 506 | job->setDirectoryChoice(choice); | ||
457 | 507 | | |||
458 | job->setSettings(m_settings); | 508 | job->setSettings(m_settings); | ||
459 | 509 | | |||
460 | ICore::self()->runController()->registerJob(job); | 510 | ICore::self()->runController()->registerJob(job); | ||
461 | 511 | | |||
462 | m_plugin->rememberSearchDirectory(descriptionOrUrl); | 512 | m_plugin->rememberSearchDirectory(descriptionOrUrl); | ||
463 | 513 | | |||
514 | // if m_show is false, the dialog is closed somewhere else | ||||
515 | if (m_show) | ||||
464 | close(); | 516 | close(); | ||
465 | } | 517 | } | ||
466 | 518 | | |||
467 | void GrepDialog::updateSettings() | 519 | void GrepDialog::updateSettings() | ||
468 | { | 520 | { | ||
469 | if (limitToProjectCheck->isEnabled()) | 521 | if (limitToProjectCheck->isEnabled()) | ||
470 | m_settings.projectFilesOnly = limitToProjectCheck->isChecked(); | 522 | m_settings.projectFilesOnly = limitToProjectCheck->isChecked(); | ||
471 | 523 | | |||
472 | m_settings.caseSensitive = caseSensitiveCheck->isChecked(); | 524 | m_settings.caseSensitive = caseSensitiveCheck->isChecked(); | ||
473 | m_settings.regexp = regexCheck->isChecked(); | 525 | m_settings.regexp = regexCheck->isChecked(); | ||
474 | 526 | | |||
475 | m_settings.depth = depthSpin->value(); | 527 | m_settings.depth = depthSpin->value(); | ||
476 | 528 | | |||
477 | m_settings.pattern = patternCombo->currentText(); | 529 | m_settings.pattern = patternCombo->currentText(); | ||
478 | m_settings.searchTemplate = templateEdit->currentText().isEmpty() ? QStringLiteral("%s") : templateEdit->currentText(); | 530 | m_settings.searchTemplate = templateEdit->currentText().isEmpty() ? QStringLiteral("%s") : templateEdit->currentText(); | ||
479 | m_settings.replacementTemplate = replacementTemplateEdit->currentText(); | 531 | m_settings.replacementTemplate = replacementTemplateEdit->currentText(); | ||
480 | m_settings.files = filesCombo->currentText(); | 532 | m_settings.files = filesCombo->currentText(); | ||
481 | m_settings.exclude = excludeCombo->currentText(); | 533 | m_settings.exclude = excludeCombo->currentText(); | ||
534 | | ||||
535 | m_settings.searchPaths = searchPaths->currentText(); | ||||
482 | } | 536 | } | ||
483 | 537 | |
I made these static from the former directoryChanged and getDirectoryChoice member functions