Changeset View
Changeset View
Standalone View
Standalone View
plugins/grepview/grepdialog.cpp
Show All 32 Lines | |||||
33 | #include <interfaces/iruncontroller.h> | 33 | #include <interfaces/iruncontroller.h> | ||
34 | #include <interfaces/iproject.h> | 34 | #include <interfaces/iproject.h> | ||
35 | #include <interfaces/iprojectcontroller.h> | 35 | #include <interfaces/iprojectcontroller.h> | ||
36 | #include <interfaces/isession.h> | 36 | #include <interfaces/isession.h> | ||
37 | 37 | | |||
38 | #include <util/path.h> | 38 | #include <util/path.h> | ||
39 | 39 | | |||
40 | #include "grepviewplugin.h" | 40 | #include "grepviewplugin.h" | ||
41 | #include "grepjob.h" | | |||
42 | #include "grepoutputview.h" | 41 | #include "grepoutputview.h" | ||
43 | #include "grepfindthread.h" | 42 | #include "grepfindthread.h" | ||
44 | #include "greputil.h" | 43 | #include "greputil.h" | ||
45 | 44 | | |||
46 | 45 | | |||
47 | using namespace KDevelop; | 46 | using namespace KDevelop; | ||
48 | 47 | | |||
49 | namespace { | 48 | namespace { | ||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Line(s) | 217 | { | |||
252 | addStringToMenu(ret, allOpenProjectsString()); | 251 | addStringToMenu(ret, allOpenProjectsString()); | ||
253 | return ret; | 252 | return ret; | ||
254 | } | 253 | } | ||
255 | 254 | | |||
256 | void GrepDialog::directoryChanged(const QString& dir) | 255 | void GrepDialog::directoryChanged(const QString& dir) | ||
257 | { | 256 | { | ||
258 | QUrl currentUrl = QUrl::fromLocalFile(dir); | 257 | QUrl currentUrl = QUrl::fromLocalFile(dir); | ||
259 | if( !currentUrl.isValid() ) { | 258 | if( !currentUrl.isValid() ) { | ||
260 | setEnableProjectBox(false); | 259 | m_settings.projectFilesOnly = false; | ||
261 | return; | 260 | return; | ||
262 | } | 261 | } | ||
263 | 262 | | |||
264 | bool projectAvailable = true; | 263 | bool projectAvailable = true; | ||
265 | 264 | | |||
266 | foreach(const QUrl& url, getDirectoryChoice()) | 265 | foreach(const QUrl& url, getDirectoryChoice()) | ||
267 | { | 266 | { | ||
268 | IProject *proj = ICore::self()->projectController()->findProjectForUrl( url ); | 267 | IProject *proj = ICore::self()->projectController()->findProjectForUrl( url ); | ||
269 | if( !proj || !proj->path().toUrl().isLocalFile() ) | 268 | if( !proj || !proj->path().toUrl().isLocalFile() ) | ||
270 | projectAvailable = false; | 269 | projectAvailable = false; | ||
271 | } | 270 | } | ||
272 | 271 | | |||
273 | setEnableProjectBox(projectAvailable); | 272 | m_settings.projectFilesOnly = projectAvailable; | ||
274 | } | 273 | } | ||
275 | 274 | | |||
276 | GrepDialog::~GrepDialog() | 275 | GrepDialog::~GrepDialog() | ||
277 | { | 276 | { | ||
278 | KConfigGroup cg = ICore::self()->activeSession()->config()->group( "GrepDialog" ); | 277 | KConfigGroup cg = ICore::self()->activeSession()->config()->group( "GrepDialog" ); | ||
279 | // memorize the last patterns and paths | 278 | // memorize the last patterns and paths | ||
280 | cg.writeEntry("LastSearchItems", qCombo2StringList(patternCombo)); | 279 | cg.writeEntry("LastSearchItems", qCombo2StringList(patternCombo)); | ||
281 | cg.writeEntry("regexp", regexCheck->isChecked()); | 280 | cg.writeEntry("regexp", regexCheck->isChecked()); | ||
Show All 10 Lines | |||||
292 | } | 291 | } | ||
293 | 292 | | |||
294 | void GrepDialog::templateTypeComboActivated(int index) | 293 | void GrepDialog::templateTypeComboActivated(int index) | ||
295 | { | 294 | { | ||
296 | templateEdit->setCurrentItem( template_str().at(index), true ); | 295 | templateEdit->setCurrentItem( template_str().at(index), true ); | ||
297 | replacementTemplateEdit->setCurrentItem( repl_template().at(index), true ); | 296 | replacementTemplateEdit->setCurrentItem( repl_template().at(index), true ); | ||
298 | } | 297 | } | ||
299 | 298 | | |||
300 | void GrepDialog::setEnableProjectBox(bool enable) | 299 | void GrepDialog::setSettings(const GrepJobSettings& settings) | ||
301 | { | 300 | { | ||
302 | limitToProjectCheck->setEnabled(enable); | 301 | patternCombo->setEditText(settings.pattern); | ||
303 | limitToProjectLabel->setEnabled(enable); | 302 | patternComboEditTextChanged(settings.pattern); | ||
303 | m_settings.pattern = settings.pattern; | ||||
304 | | ||||
305 | limitToProjectCheck->setEnabled(settings.projectFilesOnly); | ||||
306 | limitToProjectLabel->setEnabled(settings.projectFilesOnly); | ||||
307 | m_settings.projectFilesOnly = settings.projectFilesOnly; | ||||
308 | | ||||
309 | // Note: everything else is set by a user | ||||
304 | } | 310 | } | ||
305 | 311 | | |||
306 | void GrepDialog::setPattern(const QString &pattern) | 312 | GrepJobSettings GrepDialog::settings() const | ||
307 | { | 313 | { | ||
308 | patternCombo->setEditText(pattern); | 314 | return m_settings; | ||
309 | patternComboEditTextChanged(pattern); | | |||
310 | } | 315 | } | ||
311 | 316 | | |||
312 | void GrepDialog::setSearchLocations(const QString &dir) | 317 | void GrepDialog::setSearchLocations(const QString &dir) | ||
313 | { | 318 | { | ||
314 | if(!dir.isEmpty()) { | 319 | if(!dir.isEmpty()) { | ||
315 | if(QDir::isAbsolutePath(dir)) | 320 | if(QDir::isAbsolutePath(dir)) | ||
316 | { | 321 | { | ||
317 | static_cast<KUrlCompletion*>(searchPaths->completionObject())->setDir( QUrl::fromLocalFile(dir) ); | 322 | static_cast<KUrlCompletion*>(searchPaths->completionObject())->setDir( QUrl::fromLocalFile(dir) ); | ||
318 | } | 323 | } | ||
319 | 324 | | |||
320 | if (searchPaths->contains(dir)) { | 325 | if (searchPaths->contains(dir)) { | ||
321 | searchPaths->removeItem(searchPaths->findText(dir)); | 326 | searchPaths->removeItem(searchPaths->findText(dir)); | ||
322 | } | 327 | } | ||
323 | 328 | | |||
324 | searchPaths->insertItem(0, dir); | 329 | searchPaths->insertItem(0, dir); | ||
325 | searchPaths->setCurrentItem(dir); | 330 | searchPaths->setCurrentItem(dir); | ||
326 | 331 | | |||
327 | if (searchPaths->count() > pathsMaxCount) { | 332 | if (searchPaths->count() > pathsMaxCount) { | ||
328 | searchPaths->removeItem(searchPaths->count() - 1); | 333 | searchPaths->removeItem(searchPaths->count() - 1); | ||
329 | } | 334 | } | ||
330 | } | 335 | } | ||
331 | directoryChanged(dir); | 336 | directoryChanged(dir); | ||
332 | } | 337 | } | ||
333 | 338 | | |||
334 | QString GrepDialog::patternString() const | | |||
335 | { | | |||
336 | return patternCombo->currentText(); | | |||
337 | } | | |||
338 | | ||||
339 | QString GrepDialog::templateString() const | | |||
340 | { | | |||
341 | return templateEdit->currentText().isEmpty() ? QStringLiteral("%s") : templateEdit->currentText(); | | |||
342 | } | | |||
343 | | ||||
344 | QString GrepDialog::replacementTemplateString() const | | |||
345 | { | | |||
346 | return replacementTemplateEdit->currentText(); | | |||
347 | } | | |||
348 | | ||||
349 | QString GrepDialog::filesString() const | | |||
350 | { | | |||
351 | return filesCombo->currentText(); | | |||
352 | } | | |||
353 | | ||||
354 | QString GrepDialog::excludeString() const | | |||
355 | { | | |||
356 | return excludeCombo->currentText(); | | |||
357 | } | | |||
358 | | ||||
359 | bool GrepDialog::useProjectFilesFlag() const | | |||
360 | { | | |||
361 | if (!limitToProjectCheck->isEnabled()) return false; | | |||
362 | return limitToProjectCheck->isChecked(); | | |||
363 | } | | |||
364 | | ||||
365 | bool GrepDialog::regexpFlag() const | | |||
366 | { | | |||
367 | return regexCheck->isChecked(); | | |||
368 | } | | |||
369 | | ||||
370 | int GrepDialog::depthValue() const | | |||
371 | { | | |||
372 | return depthSpin->value(); | | |||
373 | } | | |||
374 | | ||||
375 | bool GrepDialog::caseSensitiveFlag() const | | |||
376 | { | | |||
377 | return caseSensitiveCheck->isChecked(); | | |||
378 | } | | |||
379 | | ||||
380 | void GrepDialog::patternComboEditTextChanged( const QString& text) | 339 | void GrepDialog::patternComboEditTextChanged( const QString& text) | ||
381 | { | 340 | { | ||
382 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); | 341 | buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); | ||
383 | } | 342 | } | ||
384 | 343 | | |||
385 | QList< QUrl > GrepDialog::getDirectoryChoice() const | 344 | QList< QUrl > GrepDialog::getDirectoryChoice() const | ||
386 | { | 345 | { | ||
387 | QList< QUrl > ret; | 346 | QList< QUrl > ret; | ||
Show All 26 Lines | 372 | { | |||
414 | foreach(const QUrl& choice, getDirectoryChoice()) | 373 | foreach(const QUrl& choice, getDirectoryChoice()) | ||
415 | if(choice.isParentOf(url) || choice == url) | 374 | if(choice.isParentOf(url) || choice == url) | ||
416 | return true; | 375 | return true; | ||
417 | return false; | 376 | return false; | ||
418 | } | 377 | } | ||
419 | 378 | | |||
420 | void GrepDialog::startSearch() | 379 | void GrepDialog::startSearch() | ||
421 | { | 380 | { | ||
381 | updateSettings(); | ||||
382 | | ||||
422 | // search for unsaved documents | 383 | // search for unsaved documents | ||
423 | QList<IDocument*> unsavedFiles; | 384 | QList<IDocument*> unsavedFiles; | ||
424 | QStringList include = GrepFindFilesThread::parseInclude(filesString()); | 385 | QStringList include = GrepFindFilesThread::parseInclude(m_settings.files); | ||
425 | QStringList exclude = GrepFindFilesThread::parseExclude(excludeString()); | 386 | QStringList exclude = GrepFindFilesThread::parseExclude(m_settings.exclude); | ||
426 | 387 | | |||
427 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) | 388 | foreach(IDocument* doc, ICore::self()->documentController()->openDocuments()) | ||
428 | { | 389 | { | ||
429 | QUrl docUrl = doc->url(); | 390 | QUrl docUrl = doc->url(); | ||
430 | if(doc->state() != IDocument::Clean && isPartOfChoice(docUrl) && | 391 | if(doc->state() != IDocument::Clean && isPartOfChoice(docUrl) && | ||
431 | QDir::match(include, docUrl.fileName()) && !QDir::match(exclude, docUrl.toLocalFile())) | 392 | QDir::match(include, docUrl.fileName()) && !QDir::match(exclude, docUrl.toLocalFile())) | ||
432 | { | 393 | { | ||
433 | unsavedFiles << doc; | 394 | unsavedFiles << doc; | ||
Show All 22 Lines | 416 | if (choice.size() > 1) { | |||
456 | description = i18np("%2, and %1 more item", "%2, and %1 more items", choice.size() - 1, prettyFileName(choice[0])); | 417 | description = i18np("%2, and %1 more item", "%2, and %1 more items", choice.size() - 1, prettyFileName(choice[0])); | ||
457 | } else if (!choice.isEmpty()) { | 418 | } else if (!choice.isEmpty()) { | ||
458 | description = prettyFileName(choice[0]); | 419 | description = prettyFileName(choice[0]); | ||
459 | } | 420 | } | ||
460 | } | 421 | } | ||
461 | 422 | | |||
462 | GrepOutputView *toolView = (GrepOutputView*)ICore::self()->uiController()-> | 423 | GrepOutputView *toolView = (GrepOutputView*)ICore::self()->uiController()-> | ||
463 | findToolView(i18n("Find/Replace in Files"), m_plugin->toolViewFactory(), IUiController::CreateAndRaise); | 424 | findToolView(i18n("Find/Replace in Files"), m_plugin->toolViewFactory(), IUiController::CreateAndRaise); | ||
464 | GrepOutputModel* outputModel = toolView->renewModel(patternString(), description); | 425 | GrepOutputModel* outputModel = toolView->renewModel(m_settings.pattern, description); | ||
465 | 426 | | |||
466 | connect(job, &GrepJob::showErrorMessage, | 427 | connect(job, &GrepJob::showErrorMessage, | ||
467 | toolView, &GrepOutputView::showErrorMessage); | 428 | toolView, &GrepOutputView::showErrorMessage); | ||
468 | //the GrepOutputModel gets the 'showMessage' signal to store it and forward | 429 | //the GrepOutputModel gets the 'showMessage' signal to store it and forward | ||
469 | //it to toolView | 430 | //it to toolView | ||
470 | connect(job, &GrepJob::showMessage, | 431 | connect(job, &GrepJob::showMessage, | ||
471 | outputModel, &GrepOutputModel::showMessageSlot); | 432 | outputModel, &GrepOutputModel::showMessageSlot); | ||
472 | connect(outputModel, &GrepOutputModel::showMessage, | 433 | connect(outputModel, &GrepOutputModel::showMessage, | ||
473 | toolView, &GrepOutputView::showMessage); | 434 | toolView, &GrepOutputView::showMessage); | ||
474 | 435 | | |||
475 | connect(toolView, &GrepOutputView::outputViewIsClosed, job, [=]() {job->kill();}); | 436 | connect(toolView, &GrepOutputView::outputViewIsClosed, job, [=]() {job->kill();}); | ||
476 | 437 | | |||
477 | job->setOutputModel(outputModel); | 438 | job->setOutputModel(outputModel); | ||
478 | job->setPatternString(patternString()); | | |||
479 | job->setReplacementTemplateString(replacementTemplateString()); | | |||
480 | job->setTemplateString(templateString()); | | |||
481 | job->setFilesString(filesString()); | | |||
482 | job->setExcludeString(excludeString()); | | |||
483 | job->setDirectoryChoice(choice); | 439 | job->setDirectoryChoice(choice); | ||
484 | 440 | | |||
485 | job->setProjectFilesFlag( useProjectFilesFlag() ); | 441 | job->setSettings(m_settings); | ||
486 | job->setRegexpFlag( regexpFlag() ); | | |||
487 | job->setDepth( depthValue() ); | | |||
488 | job->setCaseSensitive( caseSensitiveFlag() ); | | |||
489 | 442 | | |||
ematirov: Unneeded indentation change. | |||||
490 | ICore::self()->runController()->registerJob(job); | 443 | ICore::self()->runController()->registerJob(job); | ||
491 | 444 | | |||
492 | m_plugin->rememberSearchDirectory(descriptionOrUrl); | 445 | m_plugin->rememberSearchDirectory(descriptionOrUrl); | ||
493 | 446 | | |||
494 | close(); | 447 | close(); | ||
495 | } | 448 | } | ||
496 | 449 | | |||
450 | void GrepDialog::updateSettings() | ||||
451 | { | ||||
452 | if (limitToProjectCheck->isEnabled()) | ||||
kfunk: `filesOnly = enabled && checked`? | |||||
453 | m_settings.projectFilesOnly = limitToProjectCheck->isChecked(); | ||||
454 | | ||||
455 | m_settings.caseSensitive = caseSensitiveCheck->isChecked(); | ||||
456 | m_settings.regexp = regexCheck->isChecked(); | ||||
457 | | ||||
458 | m_settings.depth = depthSpin->value(); | ||||
459 | | ||||
460 | m_settings.pattern = patternCombo->currentText(); | ||||
461 | m_settings.searchTemplate = templateEdit->currentText().isEmpty() ? QStringLiteral("%s") : templateEdit->currentText(); | ||||
462 | m_settings.replacementTemplate = replacementTemplateEdit->currentText(); | ||||
463 | m_settings.files = filesCombo->currentText(); | ||||
464 | m_settings.exclude = excludeCombo->currentText(); | ||||
465 | } | ||||
497 | 466 | |
Unneeded indentation change.