From 9171c597458750cdce9d53700814198416bc35db Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 23 Oct 2017 13:03:18 -0300 Subject: [PATCH] Show KeyContext in the keyboard shortcut dialog --- src/app/commands/cmd_keyboard_shortcuts.cpp | 23 +++--- src/app/ui/keyboard_shortcuts.cpp | 87 +++++++++++++-------- src/app/ui/keyboard_shortcuts.h | 3 + 3 files changed, 65 insertions(+), 48 deletions(-) diff --git a/src/app/commands/cmd_keyboard_shortcuts.cpp b/src/app/commands/cmd_keyboard_shortcuts.cpp index cb1854cc7..18c7b9008 100644 --- a/src/app/commands/cmd_keyboard_shortcuts.cpp +++ b/src/app/commands/cmd_keyboard_shortcuts.cpp @@ -226,7 +226,12 @@ private: for (const Accelerator& accel : m_key->accels()) { if (i != m_hotAccel || !m_changeButton) { - g->drawText(accel.toString(), fg, bg, + std::string s = accel.toString(); + if (m_key->keycontext() != KeyContext::Any) { + s += fmt::format( + " (Context: {0})", convertKeyContextToUserFriendlyString(m_key->keycontext())); + } + g->drawText(s, fg, bg, gfx::Point(bounds.x + g_sep, y + 2*guiscale())); } @@ -426,25 +431,15 @@ private: std::string text = key->triggerString(); switch (key->keycontext()) { case KeyContext::SelectionTool: - text = "Selection Tool: " + text; - break; case KeyContext::TranslatingSelection: - text = "Translating Selection: " + text; - break; case KeyContext::ScalingSelection: - text = "Scaling Selection: " + text; - break; case KeyContext::RotatingSelection: - text = "Rotating Selection: " + text; - break; case KeyContext::MoveTool: - text = "Move Tool: " + text; - break; case KeyContext::FreehandTool: - text = "Freehand Tools: " + text; - break; case KeyContext::ShapeTool: - text = "Shape Tools: " + text; + text = + convertKeyContextToUserFriendlyString(key->keycontext()) + + ": " + text; break; } KeyItem* keyItem = new KeyItem(text, key, NULL, 0); diff --git a/src/app/ui/keyboard_shortcuts.cpp b/src/app/ui/keyboard_shortcuts.cpp index 5a617afcd..280b35f3c 100644 --- a/src/app/ui/keyboard_shortcuts.cpp +++ b/src/app/ui/keyboard_shortcuts.cpp @@ -514,42 +514,11 @@ void KeyboardShortcuts::exportAccel(TiXmlElement& parent, Key* key, const ui::Ac switch (key->type()) { case KeyType::Command: { - const char* keycontextStr = NULL; - elem.SetAttribute("command", key->command()->id().c_str()); - switch (key->keycontext()) { - case KeyContext::Any: - // Without "context" attribute - break; - case KeyContext::Normal: - keycontextStr = "Normal"; - break; - case KeyContext::SelectionTool: - keycontextStr = "Selection"; - break; - case KeyContext::TranslatingSelection: - keycontextStr = "TranslatingSelection"; - break; - case KeyContext::ScalingSelection: - keycontextStr = "ScalingSelection"; - break; - case KeyContext::RotatingSelection: - keycontextStr = "RotatingSelection"; - break; - case KeyContext::MoveTool: - keycontextStr = "MoveTool"; - break; - case KeyContext::FreehandTool: - keycontextStr = "FreehandTool"; - break; - case KeyContext::ShapeTool: - keycontextStr = "ShapeTool"; - break; - } - - if (keycontextStr) - elem.SetAttribute("context", keycontextStr); + if (key->keycontext() != KeyContext::Any) + elem.SetAttribute( + "context", convertKeyContextToString(key->keycontext()).c_str()); for (const auto& param : key->params()) { if (param.second.empty()) @@ -733,4 +702,54 @@ std::string key_tooltip(const char* str, app::Key* key) return res; } +std::string convertKeyContextToString(KeyContext keyContext) +{ + switch (keyContext) { + case KeyContext::Any: + return std::string(); + case KeyContext::Normal: + return "Normal"; + case KeyContext::SelectionTool: + return "Selection"; + case KeyContext::TranslatingSelection: + return "TranslatingSelection"; + case KeyContext::ScalingSelection: + return "ScalingSelection"; + case KeyContext::RotatingSelection: + return "RotatingSelection"; + case KeyContext::MoveTool: + return "MoveTool"; + case KeyContext::FreehandTool: + return "FreehandTool"; + case KeyContext::ShapeTool: + return "ShapeTool"; + } + return std::string(); +} + +std::string convertKeyContextToUserFriendlyString(KeyContext keyContext) +{ + switch (keyContext) { + case KeyContext::Any: + return std::string(); + case KeyContext::Normal: + return "Normal"; + case KeyContext::SelectionTool: + return "Selection"; + case KeyContext::TranslatingSelection: + return "Translating Selection"; + case KeyContext::ScalingSelection: + return "Scaling Selection"; + case KeyContext::RotatingSelection: + return "Rotating Selection"; + case KeyContext::MoveTool: + return "Move Tool"; + case KeyContext::FreehandTool: + return "Freehand Tool"; + case KeyContext::ShapeTool: + return "Shape Tool"; + } + return std::string(); +} + } // namespace app diff --git a/src/app/ui/keyboard_shortcuts.h b/src/app/ui/keyboard_shortcuts.h index f462c299d..d26e27598 100644 --- a/src/app/ui/keyboard_shortcuts.h +++ b/src/app/ui/keyboard_shortcuts.h @@ -186,6 +186,9 @@ namespace app { str, KeyboardShortcuts::instance()->action(keyAction)); } + std::string convertKeyContextToString(KeyContext keyContext); + std::string convertKeyContextToUserFriendlyString(KeyContext keyContext); + } // namespace app namespace base {