GShortcut.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <LibGUI/GShortcut.h>
  2. #include <AK/StringBuilder.h>
  3. static String to_string(KeyCode key)
  4. {
  5. switch (key) {
  6. case Key_Escape: return "Escape";
  7. case Key_Tab: return "Tab";
  8. case Key_Backspace: return "Backspace";
  9. case Key_Return: return "Return";
  10. case Key_Insert: return "Insert";
  11. case Key_Delete: return "Delete";
  12. case Key_PrintScreen: return "PrintScreen";
  13. case Key_SysRq: return "SysRq";
  14. case Key_Home: return "Home";
  15. case Key_End: return "End";
  16. case Key_Left: return "Left";
  17. case Key_Up: return "Up";
  18. case Key_Right: return "Right";
  19. case Key_Down: return "Down";
  20. case Key_PageUp: return "PageUp";
  21. case Key_PageDown: return "PageDown";
  22. case Key_Shift: return "Shift";
  23. case Key_Control: return "Control";
  24. case Key_Alt: return "Alt";
  25. case Key_CapsLock: return "CapsLock";
  26. case Key_NumLock: return "NumLock";
  27. case Key_ScrollLock: return "ScrollLock";
  28. case Key_F1: return "F1";
  29. case Key_F2: return "F2";
  30. case Key_F3: return "F3";
  31. case Key_F4: return "F4";
  32. case Key_F5: return "F5";
  33. case Key_F6: return "F6";
  34. case Key_F7: return "F7";
  35. case Key_F8: return "F8";
  36. case Key_F9: return "F9";
  37. case Key_F10: return "F10";
  38. case Key_F11: return "F11";
  39. case Key_F12: return "F12";
  40. case Key_Space: return "Space";
  41. case Key_ExclamationPoint: return "!";
  42. case Key_DoubleQuote: return "\"";
  43. case Key_Hashtag: return "#";
  44. case Key_Dollar: return "$";
  45. case Key_Percent: return "%";
  46. case Key_Ampersand: return "&";
  47. case Key_Apostrophe: return "'";
  48. case Key_LeftParen: return "(";
  49. case Key_RightParen: return ")";
  50. case Key_Asterisk: return "*";
  51. case Key_Plus: return "+";
  52. case Key_Comma: return ",";
  53. case Key_Minus: return "-";
  54. case Key_Period: return ",";
  55. case Key_Slash: return "/";
  56. case Key_0: return "0";
  57. case Key_1: return "1";
  58. case Key_2: return "2";
  59. case Key_3: return "3";
  60. case Key_4: return "4";
  61. case Key_5: return "5";
  62. case Key_6: return "6";
  63. case Key_7: return "7";
  64. case Key_8: return "8";
  65. case Key_9: return "9";
  66. case Key_Colon: return ":";
  67. case Key_Semicolon: return ";";
  68. case Key_LessThan: return "<";
  69. case Key_Equal: return "=";
  70. case Key_GreaterThan: return ">";
  71. case Key_QuestionMark: return "?";
  72. case Key_AtSign: return "@";
  73. case Key_A: return "A";
  74. case Key_B: return "B";
  75. case Key_C: return "C";
  76. case Key_D: return "D";
  77. case Key_E: return "E";
  78. case Key_F: return "F";
  79. case Key_G: return "G";
  80. case Key_H: return "H";
  81. case Key_I: return "I";
  82. case Key_J: return "J";
  83. case Key_K: return "K";
  84. case Key_L: return "L";
  85. case Key_M: return "M";
  86. case Key_N: return "N";
  87. case Key_O: return "O";
  88. case Key_P: return "P";
  89. case Key_Q: return "Q";
  90. case Key_R: return "R";
  91. case Key_S: return "S";
  92. case Key_T: return "T";
  93. case Key_U: return "U";
  94. case Key_V: return "V";
  95. case Key_W: return "W";
  96. case Key_X: return "X";
  97. case Key_Y: return "Y";
  98. case Key_Z: return "Z";
  99. case Key_LeftBracket: return "[";
  100. case Key_RightBracket: return "]";
  101. case Key_Backslash: return "\\";
  102. case Key_Circumflex: return "^";
  103. case Key_Underscore: return "_";
  104. case Key_LeftBrace: return "{";
  105. case Key_RightBrace: return "}";
  106. case Key_Pipe: return "|";
  107. case Key_Tilde: return "~";
  108. case Key_Backtick: return "`";
  109. case Key_Invalid: return "Invalid";
  110. default:
  111. ASSERT_NOT_REACHED();
  112. }
  113. }
  114. String GShortcut::to_string() const
  115. {
  116. Vector<String, 8> parts;
  117. if (m_modifiers & Mod_Ctrl)
  118. parts.append("Ctrl");
  119. if (m_modifiers & Mod_Shift)
  120. parts.append("Shift");
  121. if (m_modifiers & Mod_Alt)
  122. parts.append("Alt");
  123. if (m_modifiers & Mod_Logo)
  124. parts.append("Logo");
  125. parts.append(::to_string(m_key));
  126. StringBuilder builder;
  127. for (int i = 0; i < parts.size(); ++i) {
  128. builder.append(parts[i]);
  129. if (i != parts.size() - 1)
  130. builder.append('+');
  131. }
  132. return builder.to_string();
  133. }