Commit 91677381 authored by Christian Stenger's avatar Christian Stenger
Browse files

Add shortcuts to Run Tests options



Change-Id: Ia738420baeb51940865c59b66908068c85d658c1
Reviewed-by: default avatarRiitta-Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 377408b1
......@@ -25,7 +25,9 @@
namespace Autotest {
namespace Constants {
const char ACTION_ID[] = "AutoTest.Action";
const char ACTION_SCAN_ID[] = "AutoTest.ScanAction";
const char ACTION_RUN_ALL_ID[] = "AutoTest.RunAll";
const char ACTION_RUN_SELECTED_ID[] = "AutoTest.RunSelected";
const char MENU_ID[] = "AutoTest.Menu";
const char AUTOTEST_ID[] = "AutoTest.ATP";
const char AUTOTEST_CONTEXT[] = "Auto Tests";
......
......@@ -52,6 +52,7 @@
#endif
using namespace Autotest::Internal;
using namespace Core;
static AutotestPlugin *m_instance = 0;
......@@ -101,17 +102,32 @@ bool AutotestPlugin::checkLicense()
void AutotestPlugin::initializeMenuEntries()
{
QAction *action = new QAction(tr("Re&scan Tests"), this);
Core::Command *command = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
Core::Context(Core::Constants::C_GLOBAL));
ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID);
menu->menu()->setTitle(tr("Tests"));
QAction *action = new QAction(tr("Run &All Tests"), this);
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);
menu->addAction(command);
action = new QAction(tr("&Run Selected Tests"), this);
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);
menu->addAction(command);
action = new QAction(tr("Re&scan Tests"), this);
command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID);
command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+S")));
connect(action, &QAction::triggered,
TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree);
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
menu->menu()->setTitle(tr("Tests"));
menu->addAction(command);
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
connect(menu->menu(), &QMenu::aboutToShow, this, &AutotestPlugin::updateMenuItemsEnabledState);
}
bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString)
......@@ -124,7 +140,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
initializeMenuEntries();
m_settings->fromSettings(Core::ICore::settings());
m_settings->fromSettings(ICore::settings());
addAutoReleasedObject(new TestSettingsPage(m_settings));
addAutoReleasedObject(new TestNavigationWidgetFactory);
addAutoReleasedObject(TestResultsPane::instance());
......@@ -141,6 +157,32 @@ ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
return SynchronousShutdown;
}
void AutotestPlugin::onRunAllTriggered()
{
TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getAllTestCases());
runner->runTests();
}
void AutotestPlugin::onRunSelectedTriggered()
{
TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getSelectedTests());
runner->runTests();
}
void AutotestPlugin::updateMenuItemsEnabledState()
{
const bool enabled = !TestRunner::instance()->isTestRunning();
const bool hasTests = TestTreeModel::instance()->hasTests();
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(enabled && hasTests);
ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(enabled && hasTests);
ActionManager::command(Constants::ACTION_SCAN_ID)->action()->setEnabled(enabled);
}
QList<QObject *> AutotestPlugin::createTestObjects() const
{
QList<QObject *> tests;
......
......@@ -49,6 +49,9 @@ public:
private:
bool checkLicense();
void initializeMenuEntries();
void onRunAllTriggered();
void onRunSelectedTriggered();
void updateMenuItemsEnabledState();
QList<QObject *> createTestObjects() const;
const QSharedPointer<TestSettings> m_settings;
};
......
......@@ -32,6 +32,7 @@
#include <coreplugin/icore.h>
#include <texteditor/texteditor.h>
#include <utils/progressindicator.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <QAction>
#include <QMenu>
......@@ -88,19 +89,15 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
const bool enabled = !TestRunner::instance()->isTestRunning();
const bool hasTests = m_model->hasTests();
QMenu menu;
QAction *runAll = new QAction(tr("Run All Tests"), &menu);
QAction *runSelected = new QAction(tr("Run Selected Tests"), &menu);
QAction *runAll = Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action();
QAction *runSelected = Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action();
QAction *selectAll = new QAction(tr("Select All"), &menu);
QAction *deselectAll = new QAction(tr("Deselect All"), &menu);
// TODO remove?
QAction *rescan = new QAction(tr("Rescan"), &menu);
QAction *rescan = Core::ActionManager::command(Constants::ACTION_SCAN_ID)->action();
connect(runAll, &QAction::triggered, this, &TestNavigationWidget::onRunAllTriggered);
connect(runSelected, &QAction::triggered, this, &TestNavigationWidget::onRunSelectedTriggered);
connect(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll);
connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll);
connect(rescan, &QAction::triggered, TestTreeModel::instance()->parser(),
&TestCodeParser::updateTestTree);
runAll->setEnabled(enabled && hasTests);
runSelected->setEnabled(enabled && hasTests);
......@@ -165,20 +162,6 @@ void TestNavigationWidget::onItemActivated(const QModelIndex &index)
}
}
void TestNavigationWidget::onRunAllTriggered()
{
TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(m_model->getAllTestCases());
runner->runTests();
}
void TestNavigationWidget::onRunSelectedTriggered()
{
TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(m_model->getSelectedTests());
runner->runTests();
}
void TestNavigationWidget::onSortClicked()
{
if (m_sortAlphabetically) {
......
......@@ -62,8 +62,6 @@ public slots:
private slots:
void onItemActivated(const QModelIndex &index);
void onRunAllTriggered();
void onRunSelectedTriggered();
void onSortClicked();
void onFilterMenuTriggered(QAction *action);
void onParsingStarted();
......
Markdown is supported
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