mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 16:27:55 +01:00
Merge branch 'added-removing-view-events' of https://github.com/BDisp/gui.cs into combobox_fixes2
This commit is contained in:
@@ -132,7 +132,7 @@ namespace Terminal.Gui {
|
||||
/// <summary>
|
||||
/// Event fired when a subview is being removed from this view.
|
||||
/// </summary>
|
||||
public Action<View> Removing;
|
||||
public Action<View> Removed;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the view gets focus.
|
||||
@@ -607,12 +607,12 @@ namespace Terminal.Gui {
|
||||
if (view == null || subviews == null)
|
||||
return;
|
||||
|
||||
OnRemoving (view);
|
||||
SetNeedsLayout ();
|
||||
SetNeedsDisplay ();
|
||||
var touched = view.Frame;
|
||||
subviews.Remove (view);
|
||||
view.container = null;
|
||||
OnRemoved (view);
|
||||
|
||||
if (subviews.Count < 1)
|
||||
this.CanFocus = false;
|
||||
@@ -958,9 +958,9 @@ namespace Terminal.Gui {
|
||||
/// Method invoked when a subview is being removed from this view.
|
||||
/// </summary>
|
||||
/// <param name="view">The subview being removed.</param>
|
||||
public virtual void OnRemoving (View view)
|
||||
public virtual void OnRemoved (View view)
|
||||
{
|
||||
view.Removing?.Invoke (this);
|
||||
view.Removed?.Invoke (this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -135,5 +135,26 @@ namespace Terminal.Gui {
|
||||
sub2.Width = Dim.Width (sub2);
|
||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Added_Removing ()
|
||||
{
|
||||
var v = new View (new Rect (0, 0, 10, 24));
|
||||
var t = new View ();
|
||||
|
||||
v.Added += (View e) => {
|
||||
Assert.True (v.SuperView == e);
|
||||
};
|
||||
|
||||
v.Removed += (View e) => {
|
||||
Assert.True (v.SuperView == null);
|
||||
};
|
||||
|
||||
t.Add (v);
|
||||
Assert.True (t.Subviews.Count == 1);
|
||||
|
||||
t.Remove (v);
|
||||
Assert.True (t.Subviews.Count == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user