Commit a2b3b77f authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Display GrepDialog results in the GrepOutputView that creates it

GrepOutputView creates a hidden GrepDialog on start to restore search
settings from history. GrepOutputView also creates a hidden GrepDialog
when its Refresh action is triggered. In both cases the GrepOutputView
becomes GrepDialog's parent, and thus will be valid when the dialog is
ready to display results. Also in both cases the search results should
not be displayed in a GrepOutputView from another area if that area
becomes active before GrepDialog::startSearch() is invoked. And there is
no need to raise the GrepOutputView in these cases either.

GrepViewPlugin creates and usually shows GrepDialog for various reasons.
The dialog is modeless, so the user can activate another area before
starting a search in it. The results should be displayed in a
GrepOutputView within the area active at the time of a search start.
Therefore the old IUiController::findToolView()-based implementation
remains for this case.

Restoring search history in a session that contains zero projects (all
closed), could cause a crash in a nested event loop inside
UiController::loadAllAreas(), because UiController::findToolView()
returns nullptr then and GrepDialog::startSearch() does not check the
returned pointer. OktetaDocument can create such a nested event loop if
a binary file is open in the session.

BUG: 456767
FIXED-IN: 5.10.221200
parent 5ace443b
Pipeline #274365 passed with stage
in 25 minutes and 28 seconds
......@@ -168,8 +168,12 @@ bool directoriesInProject(const QString& dir)
const int pathsMaxCount = 25;
GrepDialog::GrepDialog(GrepViewPlugin *plugin, QWidget *parent, bool show)
: QDialog(parent), Ui::GrepWidget(), m_plugin(plugin), m_show(show)
GrepDialog::GrepDialog(GrepViewPlugin* plugin, GrepOutputView* toolView, QWidget* parent, bool show)
: QDialog(parent)
, Ui::GrepWidget()
, m_plugin(plugin)
, m_toolView(toolView)
, m_show(show)
......@@ -515,10 +519,13 @@ void GrepDialog::startSearch()
GrepOutputView *toolView =
GrepOutputView* toolView = m_toolView;
if (!toolView) {
toolView = static_cast<GrepOutputView*>(ICore::self()->uiController()->findToolView(
i18nc("@title:window", "Find/Replace in Files"), m_plugin->toolViewFactory(),
m_settings.fromHistory ? IUiController::Create : IUiController::CreateAndRaise));
Q_ASSERT_X(toolView, Q_FUNC_INFO, "This branch may be taken only after UiController::loadAllAreas() returns.");
if (m_settings.fromHistory) {
// when restored from history, only display the parameters
......@@ -16,6 +16,7 @@
#include "grepjob.h"
#include "ui_grepwidget.h"
class GrepOutputView;
class GrepViewPlugin;
class GrepDialog : public QDialog, private Ui::GrepWidget
......@@ -23,7 +24,10 @@ class GrepDialog : public QDialog, private Ui::GrepWidget
explicit GrepDialog(GrepViewPlugin *plugin, QWidget *parent = nullptr, bool show = true);
/// Search results are displayed in: @p toolView if it is not null,
/// or in a possibly created and raised GrepOutputView in the current area.
explicit GrepDialog(GrepViewPlugin* plugin, GrepOutputView* toolView = nullptr, QWidget* parent = nullptr,
bool show = true);
~GrepDialog() override;
void setSettings(const GrepJobSettings &settings);
......@@ -69,6 +73,7 @@ private:
void updateSettings();
GrepViewPlugin * m_plugin;
GrepOutputView* const m_toolView;
///Allow to show a dialog
const bool m_show;
///Current setting
......@@ -168,7 +168,7 @@ GrepOutputView::GrepOutputView(QWidget* parent, GrepViewPlugin* plugin)
// rerun the grep jobs with settings from the history
auto* dlg = new GrepDialog(m_plugin, this, false);
auto* const dlg = new GrepDialog(m_plugin, this, this, false);
......@@ -354,7 +354,7 @@ void GrepOutputView::refresh()
refresh_history.first().fromHistory = false;
auto* dlg = new GrepDialog(m_plugin, this, false);
auto* const dlg = new GrepDialog(m_plugin, this, this, false);
......@@ -164,7 +164,7 @@ void GrepViewPlugin::showDialog(bool setLastUsed, const QString& pattern, bool s
// check if dialog pointers are still valid, remove them otherwise
auto* dlg = new GrepDialog( this, core()->uiController()->activeMainWindow(), show );
auto* const dlg = new GrepDialog(this, nullptr, core()->uiController()->activeMainWindow(), show);
m_currentDialogs << dlg;
GrepJobSettings dlgSettings = dlg->settings();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment