diff --git a/plugins/grepview/grepdialog.h b/plugins/grepview/grepdialog.h --- a/plugins/grepview/grepdialog.h +++ b/plugins/grepview/grepdialog.h @@ -53,7 +53,8 @@ ///Check if all projects have been loaded bool checkProjectsOpened(); ///Call the next element in m_jobs_history or close the dialog if all jobs are done - void nextHistory(); + ///\param[in] next if false, skip pending jobs + void nextHistory(bool next); ///Opens the dialog to select a directory to search in, and inserts it into Location(s) field. void selectDirectoryDialog(); diff --git a/plugins/grepview/grepdialog.cpp b/plugins/grepview/grepdialog.cpp --- a/plugins/grepview/grepdialog.cpp +++ b/plugins/grepview/grepdialog.cpp @@ -423,14 +423,14 @@ // do the grep jobs one by one connect(m_plugin, &GrepViewPlugin::grepJobFinished, this, &GrepDialog::nextHistory); - QTimer::singleShot(0, this, &GrepDialog::nextHistory); + QTimer::singleShot(0, this, [=]() {nextHistory(true);}); return true; } -void GrepDialog::nextHistory() +void GrepDialog::nextHistory(bool next) { - if (!m_historyJobSettings.empty()) { + if (next && !m_historyJobSettings.empty()) { m_settings = m_historyJobSettings.takeFirst(); startSearch(); } else { diff --git a/plugins/grepview/grepoutputview.h b/plugins/grepview/grepoutputview.h --- a/plugins/grepview/grepoutputview.h +++ b/plugins/grepview/grepoutputview.h @@ -96,6 +96,7 @@ void showDialog(); void refresh(); void expandElements( const QModelIndex & parent ); + void updateButtonState(bool enable); void rowsRemoved(); void clearSearchHistory(); void modelSelectorContextMenu(const QPoint& pos); diff --git a/plugins/grepview/grepoutputview.cpp b/plugins/grepview/grepoutputview.cpp --- a/plugins/grepview/grepoutputview.cpp +++ b/plugins/grepview/grepoutputview.cpp @@ -71,13 +71,10 @@ setWindowIcon(QIcon::fromTheme(QStringLiteral("edit-find"), windowIcon())); m_prev = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), i18n("&Previous Item"), this); - m_prev->setEnabled(false); m_next = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), i18n("&Next Item"), this); - m_next->setEnabled(false); m_collapseAll = new QAction(QIcon::fromTheme(QStringLiteral("arrow-left-double")), i18n("C&ollapse All"), this); // TODO change icon - m_collapseAll->setEnabled(false); m_expandAll = new QAction(QIcon::fromTheme(QStringLiteral("arrow-right-double")), i18n("&Expand All"), this); // TODO change icon - m_expandAll->setEnabled(false); + updateButtonState(false); QAction *separator = new QAction(this); separator->setSeparator(true); QAction *newSearchAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("New &Search"), this); @@ -273,6 +270,9 @@ !replacementCombo->currentText().isEmpty()); if(model()->hasResults()) expandElements(QModelIndex()); + else { + updateButtonState(false); + } } updateCheckable(); @@ -346,14 +346,19 @@ void GrepOutputView::expandElements(const QModelIndex& index) { - m_prev->setEnabled(true); - m_next->setEnabled(true); - m_collapseAll->setEnabled(true); - m_expandAll->setEnabled(true); + updateButtonState(true); resultsTreeView->expand(index); } +void GrepOutputView::updateButtonState(bool enable) +{ + m_prev->setEnabled(enable); + m_next->setEnabled(enable); + m_collapseAll->setEnabled(enable); + m_expandAll->setEnabled(enable); +} + void GrepOutputView::selectPreviousItem() { if (!model()) { @@ -386,8 +391,10 @@ // Collapse everything resultsTreeView->collapseAll(); - // Now reopen the first children, which correspond to the files. - resultsTreeView->expand(resultsTreeView->model()->index(0, 0)); + if (resultsTreeView->model()) { + // Now reopen the first children, which correspond to the files. + resultsTreeView->expand(resultsTreeView->model()->index(0, 0)); + } } void GrepOutputView::expandAllItems() @@ -397,8 +404,7 @@ void GrepOutputView::rowsRemoved() { - m_prev->setEnabled(model()->rowCount()); - m_next->setEnabled(model()->rowCount()); + updateButtonState(model()->rowCount() > 0); } void GrepOutputView::updateApplyState(const QModelIndex& topLeft, const QModelIndex& bottomRight) @@ -428,6 +434,7 @@ GrepJob *runningJob = m_plugin->grepJob(); if(runningJob) { + connect(runningJob, &GrepJob::finished, this, [=]() {updateButtonState(false);}); runningJob->kill(); } while(modelSelector->count() > 0) @@ -440,6 +447,8 @@ m_settingsHistory.clear(); applyButton->setEnabled(false); + + updateButtonState(false); m_refresh->setEnabled(false); m_clearSearchHistory->setEnabled(false); m_statusLabel->setText(QString()); diff --git a/plugins/grepview/grepviewplugin.h b/plugins/grepview/grepviewplugin.h --- a/plugins/grepview/grepviewplugin.h +++ b/plugins/grepview/grepviewplugin.h @@ -55,7 +55,7 @@ Q_SCRIPTABLE void startSearch(QString pattern, QString directory, bool show); Q_SIGNALS: - void grepJobFinished(); + void grepJobFinished(bool success); private Q_SLOTS: void showDialogFromMenu(); diff --git a/plugins/grepview/grepviewplugin.cpp b/plugins/grepview/grepviewplugin.cpp --- a/plugins/grepview/grepviewplugin.cpp +++ b/plugins/grepview/grepviewplugin.cpp @@ -238,6 +238,6 @@ if(job == m_currentJob) { m_currentJob = nullptr; - emit grepJobFinished(); + emit grepJobFinished(job->error() == KJob::NoError); } }