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.
This commit is contained in:
BDisp
2021-10-25 20:29:27 +01:00
committed by GitHub
parent d55ae77331
commit 9d767a4171
3 changed files with 20 additions and 17 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -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 ()}"));
}
}

View File

@@ -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));