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.
This commit is contained in:
Matthias Koefferlein 2017-09-03 22:34:34 +02:00
parent dfbe0b3122
commit 31084d83ce
2 changed files with 29 additions and 1 deletions

View File

@ -420,6 +420,10 @@ KeyBindingsConfigPage::reset_clicked ()
void
KeyBindingsConfigPage::apply (const std::vector<std::pair<std::string, std::string> > &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::vector<std::pair<std::string, std::stri
if (t->first == 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<QAction *, std::vector<std::string> >::const_iterator a = m_paths_for_action.find (qaction);
if (a != m_paths_for_action.end ()) {
for (std::vector<std::string>::const_iterator p = a->second.begin (); p != a->second.end (); ++p) {
m_current_bindings[*p] = shortcut;
std::map<std::string, QTreeWidgetItem *>::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 ()) {

View File

@ -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<std::string, std::string> m_current_bindings;
std::map<std::string, QTreeWidgetItem *> m_item_for_path;
std::map<QAction *, std::vector<std::string> > m_paths_for_action;
bool m_enable_event;
static std::vector<std::pair<std::string, std::string> > m_default_bindings;