Show KeyContext in the keyboard shortcut dialog

This commit is contained in:
David Capello 2017-10-23 13:03:18 -03:00
parent 745dc0734e
commit 9171c59745
3 changed files with 65 additions and 48 deletions

View File

@ -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);

View File

@ -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

View File

@ -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 {