Browse Source

Fixes #1202. CheckBox now deals with a functional '_' underscore hotkey. (#1203)

BDisp 4 years ago
parent
commit
328276f490
1 changed files with 20 additions and 2 deletions
  1. 20 2
      Terminal.Gui/Views/Checkbox.cs

+ 20 - 2
Terminal.Gui/Views/Checkbox.cs

@@ -100,8 +100,11 @@ namespace Terminal.Gui {
 				hot_pos = -1;
 				hot_key = (char)0;
 				foreach (Rune c in text) {
-					if (Rune.IsUpper (c)) {
-						hot_key = c;
+					//if (Rune.IsUpper (c)) {
+					if (c == '_') {
+						hot_key = text [i + 1];
+						HotKey = (Key)(char)hot_key.ToString ().ToUpper () [0];
+						text = text.ToString ().Replace ("_", "");
 						hot_pos = i;
 						break;
 					}
@@ -145,6 +148,21 @@ namespace Terminal.Gui {
 			return base.ProcessKey (kb);
 		}
 
+		///<inheritdoc/>
+		public override bool ProcessHotKey (KeyEvent ke)
+		{
+			if (ke.Key == (Key.AltMask | HotKey)) {
+				SetFocus ();
+				var previousChecked = Checked;
+				Checked = !Checked;
+				OnToggled (previousChecked);
+				SetNeedsDisplay ();
+				return true;
+			}
+
+			return false;
+		}
+
 		///<inheritdoc/>
 		public override bool MouseEvent (MouseEvent me)
 		{