forked from qt-creator/qt-creator
AutoTest: Consolidate handling of global menu items
Change-Id: I6ad07775d63206864ec330ad87d3b65e5ecaf76c Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "autotestplugin.h"
|
||||
#include "autotestconstants.h"
|
||||
#include "autotesticons.h"
|
||||
#include "testcodeparser.h"
|
||||
#include "testframeworkmanager.h"
|
||||
#include "testrunner.h"
|
||||
@@ -42,12 +43,14 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
@@ -98,18 +101,23 @@ void AutotestPlugin::initializeMenuEntries()
|
||||
menu->setOnAllDisabledBehavior(ActionContainer::Show);
|
||||
|
||||
QAction *action = new QAction(tr("Run &All Tests"), this);
|
||||
action->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR.icon());
|
||||
action->setToolTip(tr("Run All Tests"));
|
||||
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_ID);
|
||||
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+A")));
|
||||
connect(action, &QAction::triggered,
|
||||
this, &AutotestPlugin::onRunAllTriggered);
|
||||
connect(action, &QAction::triggered, this, &AutotestPlugin::onRunAllTriggered);
|
||||
action->setEnabled(false);
|
||||
menu->addAction(command);
|
||||
|
||||
action = new QAction(tr("&Run Selected Tests"), this);
|
||||
Utils::Icon runSelectedIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
||||
for (const Utils::IconMaskAndColor &maskAndColor : Icons::RUN_SELECTED_OVERLAY)
|
||||
runSelectedIcon.append(maskAndColor);
|
||||
action->setIcon(runSelectedIcon.icon());
|
||||
action->setToolTip(tr("Run Selected Tests"));
|
||||
command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_ID);
|
||||
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+R")));
|
||||
connect(action, &QAction::triggered,
|
||||
this, &AutotestPlugin::onRunSelectedTriggered);
|
||||
connect(action, &QAction::triggered, this, &AutotestPlugin::onRunSelectedTriggered);
|
||||
action->setEnabled(false);
|
||||
menu->addAction(command);
|
||||
|
||||
@@ -128,6 +136,8 @@ void AutotestPlugin::initializeMenuEntries()
|
||||
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
||||
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
||||
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
||||
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
|
||||
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
||||
connect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
|
||||
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
||||
}
|
||||
@@ -137,9 +147,8 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(errorString)
|
||||
|
||||
initializeMenuEntries();
|
||||
|
||||
m_frameworkManager = TestFrameworkManager::instance();
|
||||
initializeMenuEntries();
|
||||
m_frameworkManager->registerTestFramework(new QtTestFramework);
|
||||
m_frameworkManager->registerTestFramework(new QuickTestFramework);
|
||||
m_frameworkManager->registerTestFramework(new GTestFramework);
|
||||
@@ -185,7 +194,9 @@ void AutotestPlugin::updateMenuItemsEnabledState()
|
||||
{
|
||||
const bool enabled = !ProjectExplorer::BuildManager::isBuilding()
|
||||
&& !TestRunner::instance()->isTestRunning()
|
||||
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
|
||||
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle
|
||||
&& ProjectExplorer::ProjectExplorerPlugin::canRunStartupProject(
|
||||
ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
const bool hasTests = TestTreeModel::instance()->hasTests();
|
||||
|
||||
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(enabled && hasTests);
|
||||
|
||||
@@ -51,13 +51,13 @@ public:
|
||||
bool initialize(const QStringList &arguments, QString *errorString) override;
|
||||
void extensionsInitialized() override;
|
||||
ShutdownFlag aboutToShutdown() override;
|
||||
void updateMenuItemsEnabledState();
|
||||
|
||||
private:
|
||||
bool checkLicense();
|
||||
void initializeMenuEntries();
|
||||
void onRunAllTriggered();
|
||||
void onRunSelectedTriggered();
|
||||
void updateMenuItemsEnabledState();
|
||||
QList<QObject *> createTestObjects() const override;
|
||||
const QSharedPointer<TestSettings> m_settings;
|
||||
TestFrameworkManager *m_frameworkManager = nullptr;
|
||||
|
||||
@@ -155,9 +155,6 @@ TestResultsPane::TestResultsPane(QObject *parent) :
|
||||
this, &TestResultsPane::onTestRunFinished);
|
||||
connect(TestRunner::instance(), &TestRunner::testResultReady,
|
||||
this, &TestResultsPane::addTestResult);
|
||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
||||
&ProjectExplorer::ProjectExplorerPlugin::updateRunActions,
|
||||
this, &TestResultsPane::updateRunActions);
|
||||
}
|
||||
|
||||
void TestResultsPane::createToolButtons()
|
||||
@@ -175,19 +172,10 @@ void TestResultsPane::createToolButtons()
|
||||
});
|
||||
|
||||
m_runAll = new QToolButton(m_treeView);
|
||||
m_runAll->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR.icon());
|
||||
m_runAll->setToolTip(tr("Run All Tests"));
|
||||
m_runAll->setEnabled(false);
|
||||
connect(m_runAll, &QToolButton::clicked, this, &TestResultsPane::onRunAllTriggered);
|
||||
m_runAll->setDefaultAction(Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action());
|
||||
|
||||
m_runSelected = new QToolButton(m_treeView);
|
||||
Utils::Icon runSelectedIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
||||
for (const Utils::IconMaskAndColor &maskAndColor : Icons::RUN_SELECTED_OVERLAY)
|
||||
runSelectedIcon.append(maskAndColor);
|
||||
m_runSelected->setIcon(runSelectedIcon.icon());
|
||||
m_runSelected->setToolTip(tr("Run Selected Tests"));
|
||||
m_runSelected->setEnabled(false);
|
||||
connect(m_runSelected, &QToolButton::clicked, this, &TestResultsPane::onRunSelectedTriggered);
|
||||
m_runSelected->setDefaultAction(Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action());
|
||||
|
||||
m_stopTestRun = new QToolButton(m_treeView);
|
||||
m_stopTestRun->setIcon(Utils::Icons::STOP_SMALL_TOOLBAR.icon());
|
||||
@@ -286,20 +274,8 @@ void TestResultsPane::clearContents()
|
||||
m_textOutput->clear();
|
||||
}
|
||||
|
||||
void TestResultsPane::visibilityChanged(bool visible)
|
||||
void TestResultsPane::visibilityChanged(bool /*visible*/)
|
||||
{
|
||||
if (visible == m_wasVisibleBefore)
|
||||
return;
|
||||
if (visible) {
|
||||
connect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
|
||||
this, &TestResultsPane::updateRunActions);
|
||||
// make sure run/run all are in correct state
|
||||
updateRunActions();
|
||||
} else {
|
||||
disconnect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
|
||||
this, &TestResultsPane::updateRunActions);
|
||||
}
|
||||
m_wasVisibleBefore = visible;
|
||||
}
|
||||
|
||||
void TestResultsPane::setFocus()
|
||||
@@ -514,10 +490,7 @@ void TestResultsPane::onTestRunStarted()
|
||||
{
|
||||
m_testRunning = true;
|
||||
m_stopTestRun->setEnabled(true);
|
||||
m_runAll->setEnabled(false);
|
||||
Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(false);
|
||||
m_runSelected->setEnabled(false);
|
||||
Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(false);
|
||||
AutotestPlugin::instance()->updateMenuItemsEnabledState();
|
||||
m_summaryWidget->setVisible(false);
|
||||
}
|
||||
|
||||
@@ -526,13 +499,7 @@ void TestResultsPane::onTestRunFinished()
|
||||
m_testRunning = false;
|
||||
m_stopTestRun->setEnabled(false);
|
||||
|
||||
const bool runEnabled = !ProjectExplorer::BuildManager::isBuilding()
|
||||
&& TestTreeModel::instance()->hasTests()
|
||||
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
|
||||
m_runAll->setEnabled(runEnabled); // TODO unify Run* actions
|
||||
Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(runEnabled);
|
||||
m_runSelected->setEnabled(runEnabled);
|
||||
Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(runEnabled);
|
||||
AutotestPlugin::instance()->updateMenuItemsEnabledState();
|
||||
updateSummaryLabel();
|
||||
m_summaryWidget->setVisible(true);
|
||||
m_model->removeCurrentTestMessage();
|
||||
@@ -548,18 +515,6 @@ void TestResultsPane::onScrollBarRangeChanged(int, int max)
|
||||
m_treeView->verticalScrollBar()->setValue(max);
|
||||
}
|
||||
|
||||
void TestResultsPane::updateRunActions()
|
||||
{
|
||||
QString whyNot;
|
||||
TestTreeModel *model = TestTreeModel::instance();
|
||||
const bool enable = !m_testRunning && !model->parser()->isParsing() && model->hasTests()
|
||||
&& !ProjectExplorer::BuildManager::isBuilding()
|
||||
&& ProjectExplorer::ProjectExplorerPlugin::canRunStartupProject(
|
||||
ProjectExplorer::Constants::NORMAL_RUN_MODE, &whyNot);
|
||||
m_runAll->setEnabled(enable);
|
||||
m_runSelected->setEnabled(enable);
|
||||
}
|
||||
|
||||
void TestResultsPane::onCustomContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
const bool resultsAvailable = m_filterModel->hasResults();
|
||||
|
||||
@@ -108,7 +108,6 @@ private:
|
||||
void onTestRunStarted();
|
||||
void onTestRunFinished();
|
||||
void onScrollBarRangeChanged(int, int max);
|
||||
void updateRunActions();
|
||||
void onCustomContextMenuRequested(const QPoint &pos);
|
||||
const TestResult *getTestResult(const QModelIndex &idx);
|
||||
void onCopyItemTriggered(const TestResult *result);
|
||||
@@ -133,7 +132,6 @@ private:
|
||||
QToolButton *m_outputToggleButton;
|
||||
QPlainTextEdit *m_textOutput;
|
||||
QMenu *m_filterMenu;
|
||||
bool m_wasVisibleBefore = false;
|
||||
bool m_autoScroll = false;
|
||||
bool m_atEnd = false;
|
||||
bool m_testRunning = false;
|
||||
|
||||
Reference in New Issue
Block a user