瀏覽代碼

Dynamic menu/statusbar and Enable property fix. (#1489)

* Fixes both dynamic menu and status bar broken scenarios.

* Fix a bug where the subviews oldEnabled can be overridden, even the superview Enable property hasn't changed.
BDisp 3 年之前
父節點
當前提交
9d767a4171
共有 3 個文件被更改,包括 20 次插入17 次删除
  1. 10 9
      Terminal.Gui/Core/View.cs
  2. 4 3
      UICatalog/Scenarios/DynamicMenuBar.cs
  3. 6 5
      UICatalog/Scenarios/DynamicStatusBar.cs

+ 10 - 9
Terminal.Gui/Core/View.cs

@@ -2154,15 +2154,16 @@ namespace Terminal.Gui {
 					}
 					OnEnabledChanged ();
 					SetNeedsDisplay ();
-				}
-				if (subviews != null) {
-					foreach (var view in subviews) {
-						if (!value) {
-							view.oldEnabled = view.Enabled;
-							view.Enabled = value;
-						} else {
-							view.Enabled = view.oldEnabled;
-							view.addingView = false;
+
+					if (subviews != null) {
+						foreach (var view in subviews) {
+							if (!value) {
+								view.oldEnabled = view.Enabled;
+								view.Enabled = value;
+							} else {
+								view.Enabled = view.oldEnabled;
+								view.addingView = false;
+							}
 						}
 					}
 				}

+ 4 - 3
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -12,10 +12,11 @@ namespace UICatalog {
 	[ScenarioMetadata (Name: "Dynamic MenuBar", Description: "Demonstrates how to add and remove a MenuBar, Menus and change titles dynamically.")]
 	[ScenarioCategory ("Dynamic")]
 	class DynamicMenuBar : Scenario {
-		public override void Run ()
+		public override void Init (Toplevel top, ColorScheme colorScheme)
 		{
-			Top.Add (new DynamicMenuBarSample (Win.Title));
-			base.Run ();
+			Application.Init ();
+			Top = Application.Top;
+			Top.Add (new DynamicMenuBarSample ($"CTRL-Q to Close - Scenario: {GetName ()}"));
 		}
 	}
 

+ 6 - 5
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -9,10 +9,11 @@ namespace UICatalog {
 	[ScenarioMetadata (Name: "Dynamic StatusBar", Description: "Demonstrates how to add and remove a StatusBar and change items dynamically.")]
 	[ScenarioCategory ("Dynamic")]
 	class DynamicStatusBar : Scenario {
-		public override void Run ()
+		public override void Init (Toplevel top, ColorScheme colorScheme)
 		{
-			Top.Add (new DynamicStatusBarSample (Win.Title));
-			base.Run ();
+			Application.Init ();
+			Top = Application.Top;	
+			Top.Add (new DynamicStatusBarSample ($"CTRL-Q to Close - Scenario: {GetName ()}"));
 		}
 	}
 
@@ -222,6 +223,7 @@ namespace UICatalog {
 				_statusBar.AddItemAt (_currentSelectedStatusBar, newStatusItem);
 				DataContext.Items.Add (new DynamicStatusItemList (newStatusItem.Title, newStatusItem));
 				_lstItems.MoveDown ();
+				SetFrameDetails ();
 			};
 
 			_btnRemove.Clicked += () => {
@@ -310,8 +312,7 @@ namespace UICatalog {
 
 			StatusItem CreateNewStatusBar (DynamicStatusItem item)
 			{
-				StatusItem newStatusItem;
-				newStatusItem = new StatusItem (ShortcutHelper.GetShortcutFromTag (
+				var newStatusItem = new StatusItem (ShortcutHelper.GetShortcutFromTag (
 					item.shortcut, StatusBar.ShortcutDelimiter),
 					item.title, _frmStatusBarDetails.CreateAction (item));