diff options
author | Christian Stenger <christian.stenger@theqtcompany.com> | 2015-03-30 07:47:07 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@theqtcompany.com> | 2015-03-30 14:52:48 +0300 |
commit | 91677381795e0f261c286ef6c5170702362c826b (patch) | |
tree | 53cd7deeeb1425fd486e495ec85ee6dcf5db445e | |
parent | 377408b1b05df5dbc9ed9584408ac9750a81fb33 (diff) |
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>
-rw-r--r-- | plugins/autotest/autotestconstants.h | 4 | ||||
-rw-r--r-- | plugins/autotest/autotestplugin.cpp | 58 | ||||
-rw-r--r-- | plugins/autotest/autotestplugin.h | 3 | ||||
-rw-r--r-- | plugins/autotest/testnavigationwidget.cpp | 25 | ||||
-rw-r--r-- | plugins/autotest/testnavigationwidget.h | 2 |
5 files changed, 60 insertions, 32 deletions
diff --git a/plugins/autotest/autotestconstants.h b/plugins/autotest/autotestconstants.h index d1ed659079..ed9c495149 100644 --- a/plugins/autotest/autotestconstants.h +++ b/plugins/autotest/autotestconstants.h @@ -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"; diff --git a/plugins/autotest/autotestplugin.cpp b/plugins/autotest/autotestplugin.cpp index 581ed8a195..724841f025 100644 --- a/plugins/autotest/autotestplugin.cpp +++ b/plugins/autotest/autotestplugin.cpp @@ -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; diff --git a/plugins/autotest/autotestplugin.h b/plugins/autotest/autotestplugin.h index 8bf2664b40..b7a02d89e7 100644 --- a/plugins/autotest/autotestplugin.h +++ b/plugins/autotest/autotestplugin.h @@ -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; }; diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp index e23ebb5c88..dea7b97874 100644 --- a/plugins/autotest/testnavigationwidget.cpp +++ b/plugins/autotest/testnavigationwidget.cpp @@ -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) { diff --git a/plugins/autotest/testnavigationwidget.h b/plugins/autotest/testnavigationwidget.h index 5e0ec2197e..a4b4c6f061 100644 --- a/plugins/autotest/testnavigationwidget.h +++ b/plugins/autotest/testnavigationwidget.h @@ -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(); |