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()) { for (const Accelerator& accel : m_key->accels()) {
if (i != m_hotAccel || !m_changeButton) { 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())); gfx::Point(bounds.x + g_sep, y + 2*guiscale()));
} }
@ -426,25 +431,15 @@ private:
std::string text = key->triggerString(); std::string text = key->triggerString();
switch (key->keycontext()) { switch (key->keycontext()) {
case KeyContext::SelectionTool: case KeyContext::SelectionTool:
text = "Selection Tool: " + text;
break;
case KeyContext::TranslatingSelection: case KeyContext::TranslatingSelection:
text = "Translating Selection: " + text;
break;
case KeyContext::ScalingSelection: case KeyContext::ScalingSelection:
text = "Scaling Selection: " + text;
break;
case KeyContext::RotatingSelection: case KeyContext::RotatingSelection:
text = "Rotating Selection: " + text;
break;
case KeyContext::MoveTool: case KeyContext::MoveTool:
text = "Move Tool: " + text;
break;
case KeyContext::FreehandTool: case KeyContext::FreehandTool:
text = "Freehand Tools: " + text;
break;
case KeyContext::ShapeTool: case KeyContext::ShapeTool:
text = "Shape Tools: " + text; text =
convertKeyContextToUserFriendlyString(key->keycontext())
+ ": " + text;
break; break;
} }
KeyItem* keyItem = new KeyItem(text, key, NULL, 0); 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()) { switch (key->type()) {
case KeyType::Command: { case KeyType::Command: {
const char* keycontextStr = NULL;
elem.SetAttribute("command", key->command()->id().c_str()); elem.SetAttribute("command", key->command()->id().c_str());
switch (key->keycontext()) { if (key->keycontext() != KeyContext::Any)
case KeyContext::Any: elem.SetAttribute(
// Without "context" attribute "context", convertKeyContextToString(key->keycontext()).c_str());
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);
for (const auto& param : key->params()) { for (const auto& param : key->params()) {
if (param.second.empty()) if (param.second.empty())
@ -733,4 +702,54 @@ std::string key_tooltip(const char* str, app::Key* key)
return res; 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 } // namespace app

View File

@ -186,6 +186,9 @@ namespace app {
str, KeyboardShortcuts::instance()->action(keyAction)); str, KeyboardShortcuts::instance()->action(keyAction));
} }
std::string convertKeyContextToString(KeyContext keyContext);
std::string convertKeyContextToUserFriendlyString(KeyContext keyContext);
} // namespace app } // namespace app
namespace base { namespace base {