Fix state handling of parser...

...and enable/disable respective menu items accordingly.
Now it should be impossible to trigger more than one parse
at a time or setting a state and invalidating a state with
higher priority.

Change-Id: I0bcbeca6626209918e0a74b0bd2722583fc47bb3
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-04-14 15:24:31 +02:00
parent a1e8cc5e44
commit b88bfbb55a
2 changed files with 15 additions and 8 deletions

View File

@@ -126,8 +126,10 @@ void AutotestPlugin::initializeMenuEntries()
TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree); TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree);
menu->addAction(command); menu->addAction(command);
ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu); ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS);
connect(menu->menu(), &QMenu::aboutToShow, this, &AutotestPlugin::updateMenuItemsEnabledState); toolsMenu->addMenu(menu);
connect(toolsMenu->menu(), &QMenu::aboutToShow,
this, &AutotestPlugin::updateMenuItemsEnabledState);
} }
bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString) bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString)
@@ -175,7 +177,8 @@ void AutotestPlugin::onRunSelectedTriggered()
void AutotestPlugin::updateMenuItemsEnabledState() void AutotestPlugin::updateMenuItemsEnabledState()
{ {
const bool enabled = !TestRunner::instance()->isTestRunning(); const bool enabled = !TestRunner::instance()->isTestRunning()
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
const bool hasTests = TestTreeModel::instance()->hasTests(); const bool hasTests = TestTreeModel::instance()->hasTests();
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(enabled && hasTests); ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(enabled && hasTests);

View File

@@ -86,10 +86,15 @@ ProjectExplorer::Project *currentProject()
void TestCodeParser::setState(State state) void TestCodeParser::setState(State state)
{ {
m_parserState = state;
// avoid triggering parse before code model parsing has finished // avoid triggering parse before code model parsing has finished
if (!m_parserEnabled) if (!m_parserEnabled)
return; return;
if ((state == Disabled || state == Idle)
&& (m_parserState == PartialParse || m_parserState == FullParse))
return;
m_parserState = state;
if (m_parserState == Disabled) { if (m_parserState == Disabled) {
m_fullUpdatePostponed = m_partialUpdatePostponed = false; m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear(); m_postponedFiles.clear();
@@ -738,8 +743,8 @@ void TestCodeParser::onAllTasksFinished(Core::Id type)
return; return;
m_parserEnabled = true; m_parserEnabled = true;
// avoid illegal parser state if respective widgets became hidden while parsing // avoid illegal parser state if respective widgets became hidden while parsing
if (m_parserState == Disabled) setState(Idle);
m_parserState = Idle;
if (m_fullUpdatePostponed) if (m_fullUpdatePostponed)
updateTestTree(); updateTestTree();
else if (m_partialUpdatePostponed) { else if (m_partialUpdatePostponed) {
@@ -902,8 +907,7 @@ void TestCodeParser::onProFileEvaluated()
foreach (auto projectFile, p->files) foreach (auto projectFile, p->files)
files.append(projectFile.path); files.append(projectFile.path);
// avoid illegal parser state when respective widgets became hidden while evaluating // avoid illegal parser state when respective widgets became hidden while evaluating
if (m_parserState == Disabled) setState(Idle);
m_parserState = Idle;
scanForTests(files); scanForTests(files);
} }
} }