Add shortcuts to Run Tests options

Change-Id: Ia738420baeb51940865c59b66908068c85d658c1
Reviewed-by: Riitta-Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-03-30 07:47:07 +02:00
parent 377408b1b0
commit 9167738179
5 changed files with 60 additions and 32 deletions

View File

@@ -25,7 +25,9 @@
namespace Autotest { namespace Autotest {
namespace Constants { 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 MENU_ID[] = "AutoTest.Menu";
const char AUTOTEST_ID[] = "AutoTest.ATP"; const char AUTOTEST_ID[] = "AutoTest.ATP";
const char AUTOTEST_CONTEXT[] = "Auto Tests"; const char AUTOTEST_CONTEXT[] = "Auto Tests";

View File

@@ -52,6 +52,7 @@
#endif #endif
using namespace Autotest::Internal; using namespace Autotest::Internal;
using namespace Core;
static AutotestPlugin *m_instance = 0; static AutotestPlugin *m_instance = 0;
@@ -101,17 +102,32 @@ bool AutotestPlugin::checkLicense()
void AutotestPlugin::initializeMenuEntries() void AutotestPlugin::initializeMenuEntries()
{ {
QAction *action = new QAction(tr("Re&scan Tests"), this); ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID);
Core::Command *command = Core::ActionManager::registerAction(action, Constants::ACTION_ID, menu->menu()->setTitle(tr("Tests"));
Core::Context(Core::Constants::C_GLOBAL));
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"))); command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+S")));
connect(action, &QAction::triggered, connect(action, &QAction::triggered,
TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree); TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree);
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
menu->menu()->setTitle(tr("Tests"));
menu->addAction(command); 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) bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString)
@@ -124,7 +140,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
initializeMenuEntries(); initializeMenuEntries();
m_settings->fromSettings(Core::ICore::settings()); m_settings->fromSettings(ICore::settings());
addAutoReleasedObject(new TestSettingsPage(m_settings)); addAutoReleasedObject(new TestSettingsPage(m_settings));
addAutoReleasedObject(new TestNavigationWidgetFactory); addAutoReleasedObject(new TestNavigationWidgetFactory);
addAutoReleasedObject(TestResultsPane::instance()); addAutoReleasedObject(TestResultsPane::instance());
@@ -141,6 +157,32 @@ ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
return SynchronousShutdown; 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 *> AutotestPlugin::createTestObjects() const
{ {
QList<QObject *> tests; QList<QObject *> tests;

View File

@@ -49,6 +49,9 @@ public:
private: private:
bool checkLicense(); bool checkLicense();
void initializeMenuEntries(); void initializeMenuEntries();
void onRunAllTriggered();
void onRunSelectedTriggered();
void updateMenuItemsEnabledState();
QList<QObject *> createTestObjects() const; QList<QObject *> createTestObjects() const;
const QSharedPointer<TestSettings> m_settings; const QSharedPointer<TestSettings> m_settings;
}; };

View File

@@ -32,6 +32,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
#include <utils/progressindicator.h> #include <utils/progressindicator.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
@@ -88,19 +89,15 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
const bool enabled = !TestRunner::instance()->isTestRunning(); const bool enabled = !TestRunner::instance()->isTestRunning();
const bool hasTests = m_model->hasTests(); const bool hasTests = m_model->hasTests();
QMenu menu; QMenu menu;
QAction *runAll = new QAction(tr("Run All Tests"), &menu); QAction *runAll = Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action();
QAction *runSelected = new QAction(tr("Run Selected Tests"), &menu); QAction *runSelected = Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action();
QAction *selectAll = new QAction(tr("Select All"), &menu); QAction *selectAll = new QAction(tr("Select All"), &menu);
QAction *deselectAll = new QAction(tr("Deselect All"), &menu); QAction *deselectAll = new QAction(tr("Deselect All"), &menu);
// TODO remove? // 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(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll);
connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll); connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll);
connect(rescan, &QAction::triggered, TestTreeModel::instance()->parser(),
&TestCodeParser::updateTestTree);
runAll->setEnabled(enabled && hasTests); runAll->setEnabled(enabled && hasTests);
runSelected->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() void TestNavigationWidget::onSortClicked()
{ {
if (m_sortAlphabetically) { if (m_sortAlphabetically) {

View File

@@ -62,8 +62,6 @@ public slots:
private slots: private slots:
void onItemActivated(const QModelIndex &index); void onItemActivated(const QModelIndex &index);
void onRunAllTriggered();
void onRunSelectedTriggered();
void onSortClicked(); void onSortClicked();
void onFilterMenuTriggered(QAction *action); void onFilterMenuTriggered(QAction *action);
void onParsingStarted(); void onParsingStarted();