2
0
Эх сурвалжийг харах

No need to create another MenuBarItem. Added a new constructor to the MenuBarItem allowing a list of MenuItem arrays.

BDisp 4 жил өмнө
parent
commit
149561a964

+ 26 - 0
Terminal.Gui/Views/Menu.cs

@@ -239,6 +239,32 @@ namespace Terminal.Gui {
 			Children = children;
 		}
 
+		/// <summary>
+		/// Initializes a new <see cref="MenuBarItem"/> with separate list of items.
+		/// </summary>
+		/// <param name="title">Title for the menu item.</param>
+		/// <param name="children">The list of items in the current menu.</param>
+		/// <param name="parent">The parent <see cref="MenuItem"/> of this if exist, otherwise is null.</param>
+		public MenuBarItem (ustring title, List<MenuItem []> children, MenuItem parent = null)
+		{
+			if (children == null) {
+				throw new ArgumentNullException (nameof (children), "The parameter cannot be null. Use an empty array instead.");
+			}
+			SetTitle (title ?? "");
+			if (parent != null) {
+				Parent = parent;
+			}
+			MenuItem [] childrens = new MenuItem [] { };
+			foreach (var item in children) {
+				for (int i = 0; i < item.Length; i++) {
+					SetChildrensParent (item);
+					Array.Resize (ref childrens, childrens.Length + 1);
+					childrens [childrens.Length - 1] = item [i];
+				}
+			}
+			Children = childrens;
+		}
+
 		/// <summary>
 		/// Initializes a new <see cref="MenuBarItem"/>.
 		/// </summary>

+ 27 - 18
UICatalog/UICatalog.cs

@@ -167,7 +167,6 @@ namespace UICatalog {
 				}),
 				new MenuBarItem ("_Color Scheme", CreateColorSchemeMenuItems()),
 				new MenuBarItem ("Diag_nostics", CreateDiagnosticMenuItems()),
-				new MenuBarItem ("_Size Style", CreateSizeStyle()),
 				new MenuBarItem ("_Help", new MenuItem [] {
 					new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://migueldeicaza.github.io/gui.cs/articles/overview.html"), null, null, Key.F1),
 					new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/migueldeicaza/gui.cs"), null, null, Key.F2),
@@ -275,28 +274,33 @@ namespace UICatalog {
 			return _runningScenario;
 		}
 
+		static List<MenuItem []> CreateDiagnosticMenuItems ()
+		{
+			List<MenuItem []> menuItems = new List<MenuItem []> ();
+			menuItems.Add (CreateDiagnosticFlagsMenuItems ());
+			menuItems.Add (new MenuItem [] { null });
+			menuItems.Add (CreateSizeStyle ());
+			return menuItems;
+		}
+
 		static MenuItem [] CreateSizeStyle ()
 		{
 			List<MenuItem> menuItems = new List<MenuItem> ();
-			for (int i = 0; i < 2; i++) {
-				var item = new MenuItem ();
-				item.Title = i == 0 ? "_Normal" : "_As Buffer";
-				item.Shortcut = Key.CtrlMask | Key.AltMask | (Key)item.Title.ToString ().Substring (1, 1) [0];
-				item.CheckType |= MenuItemCheckStyle.Radio;
-				item.Checked = i == 0 && !Application.HeightAsBuffer ? true : false;
-				item.Action += () => {
-					item.Checked = !item.Checked;
-					Application.HeightAsBuffer = item.Title == "_Normal" ? false : true;
-					foreach (var menuItem in menuItems) {
-						menuItem.Checked = menuItem.Title.Equals (item.Title);
-					}
-				};
-				menuItems.Add (item);
-			}
+			var item = new MenuItem ();
+			item.Title = "_Height As Buffer";
+			item.Shortcut = Key.CtrlMask | Key.AltMask | (Key)item.Title.ToString ().Substring (1, 1) [0];
+			item.CheckType |= MenuItemCheckStyle.Checked;
+			item.Checked = Application.HeightAsBuffer;
+			item.Action += () => {
+				item.Checked = !item.Checked;
+				Application.HeightAsBuffer = item.Checked;
+			};
+			menuItems.Add (item);
+
 			return menuItems.ToArray ();
 		}
 
-		static MenuItem [] CreateDiagnosticMenuItems ()
+		static MenuItem [] CreateDiagnosticFlagsMenuItems ()
 		{
 			const string OFF = "Diagnostics: _Off";
 			const string FRAME_RULER = "Diagnostics: Frame _Ruler";
@@ -310,7 +314,12 @@ namespace UICatalog {
 				item.Shortcut = Key.AltMask + index.ToString () [0];
 				index++;
 				item.CheckType |= MenuItemCheckStyle.Checked;
-				item.Checked = _diagnosticFlags.HasFlag (diag);
+				if (GetDiagnosticsTitle (ConsoleDriver.DiagnosticFlags.Off) == item.Title) {
+					item.Checked = (_diagnosticFlags & (ConsoleDriver.DiagnosticFlags.FramePadding
+					| ConsoleDriver.DiagnosticFlags.FrameRuler)) == 0;
+				} else {
+					item.Checked = _diagnosticFlags.HasFlag (diag);
+				}
 				item.Action += () => {
 					var t = GetDiagnosticsTitle (ConsoleDriver.DiagnosticFlags.Off);
 					if (item.Title == t && !item.Checked) {