浏览代码

Merge branch 'develop' into fix_2118_menu_hotkeys

Tig 2 年之前
父节点
当前提交
f04e7c108f

+ 2 - 1
Terminal.Gui/Core/ContextMenu.cs

@@ -116,7 +116,8 @@ namespace Terminal.Gui {
 				Y = position.Y,
 				Y = position.Y,
 				Width = 0,
 				Width = 0,
 				Height = 0,
 				Height = 0,
-				UseSubMenusSingleFrame = UseSubMenusSingleFrame
+				UseSubMenusSingleFrame = UseSubMenusSingleFrame,
+				Key = Key
 			};
 			};
 
 
 			menuBar.isContextMenuLoading = true;
 			menuBar.isContextMenuLoading = true;

+ 7 - 2
Terminal.Gui/Views/Menu.cs

@@ -630,7 +630,7 @@ namespace Terminal.Gui {
 					}
 					}
 				}
 				}
 			}
 			}
-			return false;
+			return host.ProcessHotKey (kb);
 		}
 		}
 
 
 		void RunSelected ()
 		void RunSelected ()
@@ -905,6 +905,11 @@ namespace Terminal.Gui {
 			}
 			}
 		}
 		}
 
 
+		/// <summary>
+		/// The <see cref="Gui.Key"/> used to activate the menu bar by keyboard.
+		/// </summary>
+		public Key Key { get; set; } = Key.F9;
+
 		/// <summary>
 		/// <summary>
 		/// Initializes a new instance of the <see cref="MenuBar"/>.
 		/// Initializes a new instance of the <see cref="MenuBar"/>.
 		/// </summary>
 		/// </summary>
@@ -1674,7 +1679,7 @@ namespace Terminal.Gui {
 		///<inheritdoc/>
 		///<inheritdoc/>
 		public override bool ProcessHotKey (KeyEvent kb)
 		public override bool ProcessHotKey (KeyEvent kb)
 		{
 		{
-			if (kb.Key == Key.F9) {
+			if (kb.Key == Key) {
 				if (!IsMenuOpen)
 				if (!IsMenuOpen)
 					OpenMenu ();
 					OpenMenu ();
 				else
 				else

+ 14 - 0
UnitTests/ContextMenuTests.cs

@@ -888,5 +888,19 @@ namespace Terminal.Gui.Core {
 │ SubMenu7  │────┘
 │ SubMenu7  │────┘
 ", output);
 ", output);
 		}
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Key_Open_And_Close_The_ContextMenu ()
+		{
+			var tf = new TextField ();
+			var top = Application.Top;
+			top.Add (tf);
+			Application.Begin (top);
+
+			Assert.True (tf.ProcessKey (new KeyEvent (Key.F10 | Key.ShiftMask, new KeyModifiers ())));
+			Assert.True (tf.ContextMenu.MenuBar.IsMenuOpen);
+			Assert.True (top.Subviews [1].ProcessKey (new KeyEvent (Key.F10 | Key.ShiftMask, new KeyModifiers ())));
+			Assert.Null (tf.ContextMenu.MenuBar);
+		}
 	}
 	}
 }
 }

+ 26 - 0
UnitTests/MenuTests.cs

@@ -1484,5 +1484,31 @@ Edit
 			pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
 			pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
 			Assert.Equal (new Rect (2, 0, 22, 1), pos);
 			Assert.Equal (new Rect (2, 0, 22, 1), pos);
 		}
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Key_Open_And_Close_The_MenuBar ()
+		{
+			var menu = new MenuBar (new MenuBarItem [] {
+				new MenuBarItem ("File", new MenuItem [] {
+					new MenuItem ("New", "", null)
+				})
+			});
+			Application.Top.Add (menu);
+			Application.Begin (Application.Top);
+
+			Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ())));
+			Assert.True (menu.IsMenuOpen);
+			Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ())));
+			Assert.False (menu.IsMenuOpen);
+
+			menu.Key = Key.F10 | Key.ShiftMask;
+			Assert.False (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ())));
+			Assert.False (menu.IsMenuOpen);
+
+			Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F10 | Key.ShiftMask, new KeyModifiers ())));
+			Assert.True (menu.IsMenuOpen);
+			Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F10 | Key.ShiftMask, new KeyModifiers ())));
+			Assert.False (menu.IsMenuOpen);
+		}
 	}
 	}
 }
 }

+ 8 - 0
docfx/overrides/Terminal_Gui_Application.md

@@ -0,0 +1,8 @@
+---
+uid: Terminal.Gui.Application
+summary: '*You can override summary for the API here using *MARKDOWN* syntax'
+---
+
+*Please type below more information about this API:*
+
+![Sample](images/sample.png)