Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs =================================================================== diff -u -rcf2dc4330cecec3b8c8acae9e195280323fc2a50 -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision cf2dc4330cecec3b8c8acae9e195280323fc2a50) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -21,6 +21,7 @@ using System; using System.Windows.Forms; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; @@ -252,10 +253,11 @@ /// . /// /// The calculation group from which all the children will be removed. + /// The object implementing a method for closing views for the removed children. /// The itself. - public RingtoetsContextMenuBuilder AddRemoveAllChildrenItem(CalculationGroup calculationGroup) + public RingtoetsContextMenuBuilder AddRemoveAllChildrenItem(CalculationGroup calculationGroup, IViewCommands viewCommands) { - contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup)); + contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup, viewCommands)); return this; } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs =================================================================== diff -u -rcf2dc4330cecec3b8c8acae9e195280323fc2a50 -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision cf2dc4330cecec3b8c8acae9e195280323fc2a50) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -22,6 +22,7 @@ using System; using System.Linq; using System.Windows.Forms; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; @@ -372,14 +373,15 @@ /// in the . /// /// The calculation from which to remove all children. + /// The object implementing a method for closing views for the removed children. /// The created . - public static StrictContextMenuItem CreateRemoveAllChildrenFromGroupItem(CalculationGroup calculationGroup) + public static StrictContextMenuItem CreateRemoveAllChildrenFromGroupItem(CalculationGroup calculationGroup, IViewCommands viewCommands) { var menuItem = new StrictContextMenuItem( Resources.CalculationGroup_RemoveAllChildrenFromGroup_Remove_all, Resources.CalculationGroup_RemoveAllChildrenFromGroup_Remove_all_Tooltip, Resources.RemoveAllIcon, - (sender, args) => RemoveAllChildrenFromGroup(calculationGroup)); + (sender, args) => RemoveAllChildrenFromGroup(calculationGroup, viewCommands)); var errorMessage = calculationGroup.Children.Any() ? null : Resources.CalculationGroup_RemoveAllChildrenFromGroup_No_Calculation_or_Group_to_remove; @@ -391,12 +393,16 @@ return menuItem; } - private static void RemoveAllChildrenFromGroup(CalculationGroup calculationGroup) + private static void RemoveAllChildrenFromGroup(CalculationGroup calculationGroup, IViewCommands viewCommands) { if (MessageBox.Show(Resources.CalculationGroup_RemoveAllChildrenFromGroup_Are_you_sure_you_want_to_remove_everything_from_this_group, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } + foreach (var calculation in calculationGroup.GetCalculations()) + { + viewCommands.RemoveAllViewsForItem(calculation); + } calculationGroup.Children.Clear(); calculationGroup.NotifyObservers(); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs =================================================================== diff -u -r2857b234df4622cdaf80bbc75abc58af36667347 -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs (.../RingtoetsContextMenuBuilderTest.cs) (revision 2857b234df4622cdaf80bbc75abc58af36667347) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs (.../RingtoetsContextMenuBuilderTest.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -1597,7 +1597,7 @@ var ringtoetsContextMenuBuilder = new RingtoetsContextMenuBuilder(contextMenuBuilder); // Call - ContextMenuStrip result = ringtoetsContextMenuBuilder.AddRemoveAllChildrenItem(calculationGroup).Build(); + ContextMenuStrip result = ringtoetsContextMenuBuilder.AddRemoveAllChildrenItem(calculationGroup, viewCommandsMock).Build(); // Assert Assert.IsInstanceOf(result); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs =================================================================== diff -u -rae8af28b6d5528cbbaa329dcffea6c8dbbe2a39f -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision ae8af28b6d5528cbbaa329dcffea6c8dbbe2a39f) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -21,6 +21,7 @@ using System.Linq; using Core.Common.Base; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using NUnit.Extensions.Forms; @@ -1315,22 +1316,32 @@ public void CreateRemoveAllChildrenFromGroupItem_NoChildren_CreatesDisabledItemWithTooltipSet() { // Setup + var mocks = new MockRepository(); + var viewCommandsMock = mocks.StrictMock(); + mocks.ReplayAll(); + var calculationGroup = new CalculationGroup(); // Call - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup); + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup, viewCommandsMock); // Assert Assert.AreEqual("Berekeningen map &leegmaken...", toolStripItem.Text); Assert.AreEqual("Er zijn geen berekeningen of mappen om te verwijderen.", toolStripItem.ToolTipText); TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.RemoveAllIcon, toolStripItem.Image); Assert.IsFalse(toolStripItem.Enabled); + + mocks.VerifyAll(); } [Test] public void CreateRemoveAllChildrenFromGroupItem_WithChildren_CreatesEnabledItem() { // Setup + var mocks = new MockRepository(); + var viewCommandsMock = mocks.StrictMock(); + mocks.ReplayAll(); + var calculation = new TestCalculation(); var calculationGroup = new CalculationGroup { @@ -1341,19 +1352,25 @@ }; // Call - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup); + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup, viewCommandsMock); // Assert Assert.AreEqual("Berekeningen map &leegmaken...", toolStripItem.Text); Assert.AreEqual("Verwijder alle berekeningen en mappen binnen deze Berekeningen map.", toolStripItem.ToolTipText); TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.RemoveAllIcon, toolStripItem.Image); Assert.IsTrue(toolStripItem.Enabled); + + mocks.VerifyAll(); } [Test] public void CreateRemoveAllChildrenFromGroupItem_WithChildrenPerformClickOnCreatedItemAndCancelChange_GroupUnchanged() { // Setup + var mocks = new MockRepository(); + var viewCommandsMock = mocks.StrictMock(); + mocks.ReplayAll(); + var calculation = new TestCalculation(); var calculationGroup = new CalculationGroup { @@ -1363,7 +1380,7 @@ } }; - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup); + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup, viewCommandsMock); DialogBoxHandler = (name, wnd) => { @@ -1380,22 +1397,36 @@ { calculation }, calculationGroup.Children); + + mocks.VerifyAll(); } [Test] - public void CreateRemoveAllChildrenFromGroupItem_WithChildrenPerformClickOnCreatedItemAndConfirmChange_ClearsGroup() + public void CreateRemoveAllChildrenFromGroupItem_WithNestedChildrenPerformClickOnCreatedItemAndConfirmChange_ClearsGroup() { // Setup var calculation = new TestCalculation(); + + var mocks = new MockRepository(); + var viewCommandsMock = mocks.StrictMock(); + viewCommandsMock.Expect(vc => vc.RemoveAllViewsForItem(calculation)); + mocks.ReplayAll(); + var calculationGroup = new CalculationGroup { Children = { - calculation + new CalculationGroup + { + Children = + { + calculation + } + } } }; - StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup); + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateRemoveAllChildrenFromGroupItem(calculationGroup, viewCommandsMock); DialogBoxHandler = (name, wnd) => { @@ -1409,6 +1440,8 @@ // Assert CollectionAssert.IsEmpty(calculationGroup.Children); + + mocks.VerifyAll(); } #endregion Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -r1141016ecbde1e84658f0a617eed864a547dd1ac -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 1141016ecbde1e84658f0a617eed864a547dd1ac) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -478,7 +478,7 @@ if (!isNestedGroup) { builder.AddSeparator() - .AddRemoveAllChildrenItem(group); + .AddRemoveAllChildrenItem(group, Gui.ViewCommands); } builder.AddSeparator() Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r1141016ecbde1e84658f0a617eed864a547dd1ac -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 1141016ecbde1e84658f0a617eed864a547dd1ac) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -328,7 +328,7 @@ if (!isNestedGroup) { builder.AddSeparator() - .AddRemoveAllChildrenItem(group); + .AddRemoveAllChildrenItem(group, Gui.ViewCommands); } builder.AddSeparator() Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r4263138ea4c89e88b57b7d76d01c88ae6b750284 -r09c09d852a24510f1c63db1065a50ebc20471f55 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 4263138ea4c89e88b57b7d76d01c88ae6b750284) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 09c09d852a24510f1c63db1065a50ebc20471f55) @@ -653,7 +653,7 @@ if (!isNestedGroup) { builder.AddSeparator() - .AddRemoveAllChildrenItem(group); + .AddRemoveAllChildrenItem(group, Gui.ViewCommands); } builder.AddSeparator()