diff --git a/avogadro/mainwindow.cpp b/avogadro/mainwindow.cpp index e520f007..d1446339 100644 --- a/avogadro/mainwindow.cpp +++ b/avogadro/mainwindow.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -1184,10 +1185,26 @@ bool populateTools(T* glWidget) PluginManager* plugin = PluginManager::instance(); QList toolPluginFactories = plugin->pluginFactories(); + + // Initialize counter for shortcuts + int shortcutKey = Qt::Key_1; + foreach (ToolPluginFactory* factory, toolPluginFactories) { ToolPlugin* tool = factory->createInstance(QCoreApplication::instance()); if (tool) glWidget->addTool(tool); + // Create a new shortcut for the tool + QShortcut* shortcut = new QShortcut(QKeySequence(shortcutKey), glWidget); + QObject::connect(shortcut, &QShortcut::activated, [=]() { + glWidget->setActiveTool(tool->objectName()); + // Pretty sure we need one of the below but all out of scope + // this->toolActivated() + // toolActivated() + // this->setActiveTool() + }); + + // Increment the shortcut key for the next tool + ++shortcutKey; } glWidget->setDefaultTool("Navigator"); glWidget->setActiveTool("Navigator");