Ver código fonte

MenuBar.ShortCutDelimiter cannot be empty.

BDisp 4 anos atrás
pai
commit
4729f46726
2 arquivos alterados com 33 adições e 21 exclusões
  1. 12 5
      Terminal.Gui/Views/Menu.cs
  2. 21 16
      UICatalog/Scenarios/DynamicMenuBar.cs

+ 12 - 5
Terminal.Gui/Views/Menu.cs

@@ -95,7 +95,6 @@ namespace Terminal.Gui {
 					} else {
 						shortCut = value;
 					}
-					ShortCutTag = GetShortCutTag (shortCut);
 				}
 			}
 		}
@@ -103,10 +102,10 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// The keystroke combination used in the <see cref="ShortCut"/> as string.
 		/// </summary>
-		public ustring ShortCutTag { get; private set; } = ustring.Empty;
+		public ustring ShortCutTag => GetShortCutTag (shortCut);
 
 		/// <summary>
-		/// Gets or sets the title. 
+		/// Gets or sets the title.
 		/// </summary>
 		/// <value>The title.</value>
 		public ustring Title {
@@ -297,7 +296,7 @@ namespace Terminal.Gui {
 			var hasCtrl = false;
 			var delimiter = MenuBar.ShortCutDelimiter;
 
-			ustring [] keys = sCut.Split (MenuBar.ShortCutDelimiter);
+			ustring [] keys = sCut.Split (delimiter);
 			for (int i = 0; i < keys.Length; i++) {
 				var k = keys [i];
 				if (k == "Ctrl") {
@@ -887,10 +886,18 @@ namespace Terminal.Gui {
 		/// </summary>
 		public bool UseKeysUpDownAsKeysLeftRight { get; set; } = true;
 
+		static ustring shortCutDelimiter = "+";
 		/// <summary>
 		/// Used for change the shortcut delimiter separator.
 		/// </summary>
-		public static ustring ShortCutDelimiter { get; set; } = "+";
+		public static ustring ShortCutDelimiter {
+			get => shortCutDelimiter;
+			set {
+				if (shortCutDelimiter != value) {
+					shortCutDelimiter = value == ustring.Empty ? " " : value;
+				}
+			}
+		}
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="MenuBar"/>.

+ 21 - 16
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -76,10 +76,10 @@ namespace UICatalog {
 		{
 			DataContext = new DynamicMenuItemModel ();
 
-			var _frmDelimiter = new FrameView ("Delimiter") {
+			var _frmDelimiter = new FrameView ("ShortCut Delimiter:") {
 				X = Pos.Center (),
 				Y = 3,
-				Width = 20,
+				Width = 25,
 				Height = 4
 			};
 
@@ -555,12 +555,14 @@ namespace UICatalog {
 					newMenu = new MenuItem (item.title, item.help, null, null, parent);
 					newMenu.CheckType = item.checkStyle;
 					newMenu.Action = _frmMenuDetails.CreateAction (newMenu, item);
+					newMenu.ShortCut = newMenu.CreateShortCutFromTag (item.shortCut);
 				} else if (item.isTopLevel) {
 					newMenu = new MenuBarItem (item.title, item.help, null);
 					newMenu.Action = _frmMenuDetails.CreateAction (newMenu, item);
 				} else {
 					newMenu = new MenuBarItem (item.title, item.help, null);
 					((MenuBarItem)newMenu).Children [0].Action = _frmMenuDetails.CreateAction (newMenu, item);
+					((MenuBarItem)newMenu).Children [0].ShortCut = newMenu.CreateShortCutFromTag (item.shortCut);
 				}
 
 				return newMenu;
@@ -712,17 +714,12 @@ namespace UICatalog {
 			};
 			_txtShortCut.KeyDown += (e) => {
 				var k = GetModifiersKey (e.KeyEvent);
-				if (_menuItem == null || ((k & (Key.CtrlMask | Key.ShiftMask | Key.AltMask)) == 0 && !CheckFlagRange (k, Key.F1, Key.F12))) {
+				if (((k & (Key.CtrlMask | Key.ShiftMask | Key.AltMask)) == 0 && !CheckFlagRange (k, Key.F1, Key.F12))) {
 					_txtShortCut.Text = "";
 					return;
 				}
 
-				var s = _menuItem.GetShortCutTag (k);
-				if (s.Contains ("Unknow")) {
-					_txtShortCut.Text = "";
-				} else {
-					_txtShortCut.Text = s;
-				}
+				GetShortCut (k);
 				e.Handled = true;
 			};
 
@@ -736,9 +733,20 @@ namespace UICatalog {
 				return false;
 			}
 
+			void GetShortCut (Key k)
+			{
+				var m = _menuItem != null ? _menuItem : new MenuItem ();
+				var s = m.GetShortCutTag (k);
+				if (s.Contains ("Unknow")) {
+					_txtShortCut.Text = "";
+				} else {
+					_txtShortCut.Text = s;
+				}
+			}
+
 			_txtShortCut.KeyUp += (e) => {
 				var k = GetModifiersKey (e.KeyEvent);
-				if (_menuItem == null || (k & (Key.CtrlMask | Key.ShiftMask | Key.AltMask)) == 0 || ((k | Key.D0) == 0 && !CheckFlagRange (k, Key.F1, Key.F12))) {
+				if ((k & (Key.CtrlMask | Key.ShiftMask | Key.AltMask)) == 0 || ((k | Key.D0) == 0 && !CheckFlagRange (k, Key.F1, Key.F12))) {
 					return;
 				}
 
@@ -751,12 +759,8 @@ namespace UICatalog {
 				       (kVal & (Key.CtrlMask | Key.ShiftMask | Key.AltMask)) != 0) && !kVal.ToString ().Contains ("Control")) {
 					return;
 				}
-				var s = _menuItem.GetShortCutTag (k);
-				if (s.Contains ("Unknow")) {
-					_txtShortCut.Text = "";
-				} else {
-					_txtShortCut.Text = s;
-				}
+				GetShortCut (k);
+				e.Handled = true;
 			};
 			Add (_txtShortCut);
 
@@ -802,6 +806,7 @@ namespace UICatalog {
 					_txtHelp.CanFocus = false;
 					_txtAction.Text = "";
 					_txtAction.CanFocus = false;
+					_txtShortCut.Text = "";
 					_txtShortCut.CanFocus = false;
 				} else {
 					if (!hasParent) {