Skip to content

Commit

Permalink
#5180: Handle legacy command bindings to save users from having to re…
Browse files Browse the repository at this point in the history
…set all their shortcuts after upgrading.
  • Loading branch information
codereader committed May 16, 2020
1 parent a4dc785 commit 32b4af6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
9 changes: 9 additions & 0 deletions install/input.xml
Expand Up @@ -197,4 +197,13 @@
<shortcut command="GroupSelected" key="G" modifiers="CONTROL+SHIFT" />
<shortcut command="UngroupSelected" key="U" modifiers="CONTROL+SHIFT" />
</shortcuts>
<commandRemappings>
<!-- Commands that have been moved/renamed since 2.8.0 -->
<commandRemapping oldname="CameraForward" newname="CameraMoveForward" />
<commandRemapping oldname="CameraBack" newname="CameraMoveBack" />
<commandRemapping oldname="CameraLeft" newname="CameraMoveLeft" />
<commandRemapping oldname="CameraRight" newname="CameraMoveRight" />
<commandRemapping oldname="CameraUp" newname="CameraMoveUp" />
<commandRemapping oldname="CameraDown" newname="CameraMoveDown" />
</commandRemappings>
</input>
28 changes: 22 additions & 6 deletions radiant/eventmanager/EventManager.cpp
@@ -1,10 +1,8 @@
#include "EventManager.h"

#include "imodule.h"
#include "iradiant.h"
#include "itextstream.h"
#include "icommandsystem.h"
#include "iselection.h"
#include <iostream>
#include <typeinfo>

Expand All @@ -21,11 +19,8 @@
#include "RegistryToggle.h"
#include "KeyEvent.h"
#include "ShortcutSaver.h"
#include "MouseToolManager.h"

#include "debugging/debugging.h"
#include "module/StaticModule.h"
#include <iostream>

namespace ui
{
Expand Down Expand Up @@ -62,6 +57,7 @@ const StringSet& EventManager::getDependencies() const
if (_dependencies.empty())
{
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_COMMANDSYSTEM);
}

return _dependencies;
Expand Down Expand Up @@ -523,13 +519,33 @@ void EventManager::loadAccelerators()

void EventManager::loadAcceleratorFromList(const xml::NodeList& shortcutList)
{
// Load command remappings to migrate legacy shortcuts
std::map<std::string, std::string> commandRemap;

auto remaps = GlobalRegistry().findXPath("user/ui/input//commandRemapping");

for (const auto& node : remaps)
{
commandRemap.emplace(node.getAttributeValue("oldname"), node.getAttributeValue("newname"));
}

for (const xml::Node& shortcutNode : shortcutList)
{
const std::string key = shortcutNode.getAttributeValue("key");
const std::string cmd = shortcutNode.getAttributeValue("command");
// Get the modifier string (e.g. "SHIFT+ALT")
const std::string modifierStr = shortcutNode.getAttributeValue("modifiers");

std::string cmd = shortcutNode.getAttributeValue("command");

auto replacement = commandRemap.find(cmd);

if (replacement != commandRemap.end())
{
rMessage() << "Mapping shortcut of legacy command " << replacement->first <<
" to " << replacement->second << std::endl;
cmd = replacement->second;
}

// Check for a non-empty key string
if (key.empty()) continue;

Expand Down

0 comments on commit 32b4af6

Please sign in to comment.