Skip to content

Commit

Permalink
#5180: Menu item accelerator strings are kept in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 13, 2020
1 parent 8ddc9e6 commit 5375383
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions radiant/eventmanager/EventManager.cpp
Expand Up @@ -365,21 +365,22 @@ void EventManager::unregisterMenuItem(const std::string& eventName, const ui::IM
Accelerator& EventManager::connectAccelerator(int keyCode, unsigned int modifierFlags, const std::string& command)
{
auto result = _accelerators.emplace(command, std::make_shared<Accelerator>(keyCode, modifierFlags));
Accelerator& accel = *result.first->second;

// There might be an event to associate
auto event = findEvent(command);

if (!event->empty())
{
// Command found, connect it to the accelerator by passing its pointer
//event->connectAccelerator(accelerator);
result.first->second->setEvent(event);
accel.setEvent(event);
}
else
{
result.first->second->setStatement(command);
accel.setStatement(command);
}

setMenuItemAccelerator(command, accel.getString(true));

return *result.first->second;
#if 0
else
Expand All @@ -405,6 +406,9 @@ void EventManager::disconnectAccelerator(const std::string& command)

if (existing != _accelerators.end())
{
// Clear menu item accelerator string
setMenuItemAccelerator(command, std::string());

if (existing->second->getEvent())
{
existing->second->getEvent()->disconnectAccelerators();
Expand Down Expand Up @@ -443,6 +447,16 @@ void EventManager::disconnectAccelerator(const std::string& command)
#endif
}

void EventManager::setMenuItemAccelerator(const std::string& command, const std::string& acceleratorStr)
{
auto foundMenuItem = _menuItems.find(command);

if (foundMenuItem != _menuItems.end())
{
foundMenuItem->second.item->setAccelerator(acceleratorStr);
}
}

void EventManager::disableEvent(const std::string& eventName)
{
findEvent(eventName)->setEnabled(false);
Expand Down
2 changes: 2 additions & 0 deletions radiant/eventmanager/EventManager.h
Expand Up @@ -116,6 +116,8 @@ class EventManager :

void loadAcceleratorFromList(const xml::NodeList& shortcutList);

void setMenuItemAccelerator(const std::string& command, const std::string& acceleratorStr);

bool isModifier(wxKeyEvent& ev);
};

Expand Down

0 comments on commit 5375383

Please sign in to comment.