From 31084d83cef664418792dac790c45bc9ccd5f4e5 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 3 Sep 2017 22:34:34 +0200 Subject: [PATCH] Bugfix for key bindings Now, aliases are taken into account: when a path points to the same function than another path, the key bindings are synchronized. --- src/lay/lay/layMainConfigPages.cc | 27 ++++++++++++++++++++++++++- src/lay/lay/layMainConfigPages.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/lay/lay/layMainConfigPages.cc b/src/lay/lay/layMainConfigPages.cc index 179d102c0..d09abe1bf 100644 --- a/src/lay/lay/layMainConfigPages.cc +++ b/src/lay/lay/layMainConfigPages.cc @@ -420,6 +420,10 @@ KeyBindingsConfigPage::reset_clicked () void KeyBindingsConfigPage::apply (const std::vector > &key_bindings) { + // build the path to item table and the alias table + m_item_for_path.clear (); + m_paths_for_action.clear (); + // get the current bindings m_current_bindings.clear (); fill_paths (*lay::MainWindow::instance ()->menu (), std::string (), m_current_bindings); @@ -463,10 +467,15 @@ KeyBindingsConfigPage::apply (const std::vectorfirst == tl_menu) { QTreeWidgetItem *item = new QTreeWidgetItem (top_level_item); + lay::Action action = lay::MainWindow::instance ()->menu ()->action (cb->first); item->setData (0, Qt::DisplayRole, tl::to_qstring (rem_path)); - item->setData (1, Qt::DisplayRole, tl::to_qstring (lay::MainWindow::instance ()->menu ()->action (cb->first).get_title ())); + item->setData (1, Qt::DisplayRole, tl::to_qstring (action.get_title ())); item->setData (2, Qt::DisplayRole, tl::to_qstring (cb->second)); item->setData (0, Qt::UserRole, tl::to_qstring (path)); + m_item_for_path[path] = item; + if (action.qaction ()) { + m_paths_for_action[action.qaction ()].push_back (path); + } } } @@ -535,6 +544,22 @@ KeyBindingsConfigPage::current_changed (QTreeWidgetItem *current, QTreeWidgetIte m_current_bindings[path] = shortcut; + // Set the aliases too + const lay::AbstractMenu &menu = *lay::MainWindow::instance ()->menu (); + if (menu.is_valid (path)) { + QAction *qaction = menu.action (path).qaction (); + std::map >::const_iterator a = m_paths_for_action.find (qaction); + if (a != m_paths_for_action.end ()) { + for (std::vector::const_iterator p = a->second.begin (); p != a->second.end (); ++p) { + m_current_bindings[*p] = shortcut; + std::map::const_iterator i = m_item_for_path.find (*p); + if (i != m_item_for_path.end ()) { + i->second->setData (2, Qt::DisplayRole, tl::to_qstring (shortcut)); + } + } + } + } + } if (current && !current->data (0, Qt::UserRole).isNull ()) { diff --git a/src/lay/lay/layMainConfigPages.h b/src/lay/lay/layMainConfigPages.h index 10b57f671..da1e0037d 100644 --- a/src/lay/lay/layMainConfigPages.h +++ b/src/lay/lay/layMainConfigPages.h @@ -43,6 +43,7 @@ namespace Ui { } class QTreeWidgetItem; +class QAction; namespace lay { @@ -192,6 +193,8 @@ public slots: private: Ui::KeyBindingsConfigPage *mp_ui; std::map m_current_bindings; + std::map m_item_for_path; + std::map > m_paths_for_action; bool m_enable_event; static std::vector > m_default_bindings;