From 9d767a41716d14f87db9bd7f7b034f53d8733841 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 25 Oct 2021 20:29:27 +0100 Subject: [PATCH] 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. --- Terminal.Gui/Core/View.cs | 19 ++++++++++--------- UICatalog/Scenarios/DynamicMenuBar.cs | 7 ++++--- UICatalog/Scenarios/DynamicStatusBar.cs | 11 ++++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 7d0e7b6d2..0a87f4182 100644 --- a/Terminal.Gui/Core/View.cs +++ b/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; + } } } } diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs index 13918064d..4b0c1bfa8 100644 --- a/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/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 ()}")); } } diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs index be4f960af..474f5fac0 100644 --- a/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/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));