diff --git a/MatterControlLib/ControlElements/StyledMessageBoxWindow.cs b/MatterControlLib/ControlElements/StyledMessageBoxWindow.cs index 1df76a020..57dff5ca1 100644 --- a/MatterControlLib/ControlElements/StyledMessageBoxWindow.cs +++ b/MatterControlLib/ControlElements/StyledMessageBoxWindow.cs @@ -304,6 +304,7 @@ namespace MatterHackers.MatterControl } var yesButton = theme.CreateDialogButton(yesText); + yesButton.Name = "Yes Button"; yesButton.Click += (s, e) => { // If applicable, invoke the callback @@ -316,6 +317,7 @@ namespace MatterHackers.MatterControl this.AddPageAction(yesButton, true); var noButton = theme.CreateDialogButton(noText); + noButton.Name = "No Button"; noButton.Click += (s, e) => { // If applicable, invoke the callback @@ -328,8 +330,7 @@ namespace MatterHackers.MatterControl this.AddPageAction(noButton); this.WindowTitle = "MatterControl - " + "Please Confirm".Localize(); - yesButton.Name = "Yes Button"; - this.SetCancelButtonName("No Button"); + this.SetCancelButtonName("Cancel Button"); this.AdjustTextWrap(); } diff --git a/MatterControlLib/PartPreviewWindow/Tabs.cs b/MatterControlLib/PartPreviewWindow/Tabs.cs index 36f53da37..d46266593 100644 --- a/MatterControlLib/PartPreviewWindow/Tabs.cs +++ b/MatterControlLib/PartPreviewWindow/Tabs.cs @@ -475,6 +475,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UiThread.RunOnIdle(async () => { await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges); + + this.CloseClicked?.Invoke(this, null); // Must be called after CloseClicked otherwise listeners are cleared before event is invoked this.parentTabControl.CloseTab(this); diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index e3abbf204..bee6c35bd 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -1202,7 +1202,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.DragOperationActive = true; // ContentStore is null for plated gcode, call ClearPlate to exit mode and return to bed mcx - if (sceneContext.EditContext.ContentStore == null) + if (sceneContext.Printer?.Bed?.LoadedGCode != null) { this.ClearPlate(); } diff --git a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs index b0e666402..de6a156d8 100644 --- a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs +++ b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs @@ -841,7 +841,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return theme.CreateSplitButton(new SplitButtonParams() { ButtonText = "Save".Localize(), - ButtonName = "Save", + ButtonName = "Save Button", Icon = StaticData.Instance.LoadIcon("save_grey_16x.png", 16, 16).SetToColor(theme.TextColor), ButtonAction = (menuButton) => { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index cc9acbd56..255aa2aa1 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit cc9acbd562493175ae80bab2c23fbe6e2d25a006 +Subproject commit 255aa2aa1a9a157fb44e0aa9a62438173de67905 diff --git a/Tests/MatterControl.AutomationTests/CreateLibraryFolder.cs b/Tests/MatterControl.AutomationTests/CreateLibraryFolder.cs index 7fe0f12ec..8cfc62375 100644 --- a/Tests/MatterControl.AutomationTests/CreateLibraryFolder.cs +++ b/Tests/MatterControl.AutomationTests/CreateLibraryFolder.cs @@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); testRunner.NavigateToFolder("Local Library Row Item Collection"); testRunner.InvokeLibraryCreateFolderDialog(); diff --git a/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs b/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs index ab4336e9c..66824ad30 100644 --- a/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs +++ b/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs @@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); var primitive = "Cube"; var primitiveName = "Row Item " + primitive; @@ -130,7 +130,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); var primitive = "Cube"; var primitiveName = "Row Item " + primitive; diff --git a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs index 8238adc54..58e8c27d9 100644 --- a/Tests/MatterControl.AutomationTests/PartPreviewTests.cs +++ b/Tests/MatterControl.AutomationTests/PartPreviewTests.cs @@ -1,5 +1,8 @@ -using System.Threading; +using System.IO; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg.UI; +using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintQueue; using NUnit.Framework; @@ -14,7 +17,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); testRunner.AddItemToBed(); @@ -29,24 +32,113 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.Select3DPart("Calibration - Box.stl") // Click Copy button and count Scene.Children .ClickByName("Duplicate Button") - .WaitFor(() => scene.Children.Count == 2); - Assert.AreEqual(2, scene.Children.Count, "Should have 2 parts after copy"); + .Require(() => scene.Children.Count == 2, "Should have 2 parts after copy"); // Click Copy button a second time and count Scene.Children testRunner.ClickByName("Duplicate Button"); - testRunner.WaitFor(() => scene.Children.Count > 2); - Assert.AreEqual(3, scene.Children.Count, "Should have 3 parts after 2nd copy"); + testRunner.Require(() => scene.Children.Count == 3, "Should have 3 parts after 2nd copy"); return Task.CompletedTask; }, overrideWidth: 1300, maxTimeToRun: 60); } + [Test] + public async Task DesignTabFileOpperations() + { + await MatterControlUtilities.RunTest((testRunner) => + { + testRunner.OpenPartTab(false); + + // Get View3DWidget + var view3D = testRunner.GetWidgetByName("View3DWidget", out SystemWindow systemWindow, 3) as View3DWidget; + var scene = view3D.Object3DControlLayer.Scene; + + testRunner.Require(() => scene.Children.Count == 1, "Should have 1 part (the phil)"); + + var tempFilaname = "Temp Test Save.mcx"; + var tempFullPath = Path.Combine(ApplicationDataStorage.Instance.MyDocumentsDirectory, tempFilaname); + + // delete the temp file if it exists in the Downloads folder + void DeleteTempFile() + { + if (File.Exists(tempFullPath)) + { + File.Delete(tempFullPath); + } + } + + DeleteTempFile(); + + // Make sure the tab is named 'New Design' + Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design")); + + // Click the save button + testRunner.ClickByName("Save Button") + // Cancle the save as + .ClickByName("Cancel Wizard Button"); + + // Make sure the tab is named 'New Design' + Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design")); + + // Click the close tab button + testRunner.ClickByName("Close Tab Button") + // Select Cancel + .ClickByName("Cancel Button"); + + // Make sure the tab is named 'New Design' + Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design")); + + // Click the close tab button + testRunner.ClickByName("Close Tab Button") + // Select 'Save' + .ClickByName("Yes Button") + // Cancel the 'Save As' + .ClickByName("Cancel Wizard Button"); + + // Make sure the window is still open and the tab is named 'New Design' + Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design")); + + // Click the save button + testRunner.ClickByName("Save Button") + // Save a temp file to the downloads folder + .DoubleClickByName("Computer Row Item Collection") + .DoubleClickByName("Downloads Row Item Collection") + .ClickByName("Design Name Edit Field") + .Type(tempFilaname) + .ClickByName("Accept Button"); + // Verify it is there + Assert.IsTrue(File.Exists(tempFullPath)); + // And that the tab got the name + Assert.IsNotNull(systemWindow.GetVisibleWigetWithText(tempFilaname)); + // and the tooltip is right + Assert.IsTrue(systemWindow.GetVisibleWigetWithText(tempFilaname).ToolTipText == tempFullPath); + // Add a part to the bed + testRunner.AddItemToBed(); + // Click the close tab button (we have an edit so it should show the save request) + testRunner.ClickByName("Close Tab Button") + // Click the 'Cancel' + .ClickByName("Cancel Button") + // Click the 'Save' button + .ClickByName("Save Button") + // Click the close button (now we have no edit it should cancel without request) + .ClickByName("Close Tab Button"); + + // Verify the tab closes without requesting save + testRunner.Require(() => systemWindow.GetVisibleWigetWithText(tempFilaname) == null, "The tab should have closed"); + + // delete the temp file if it exists in the Downloads folder + DeleteTempFile(); + + return Task.CompletedTask; + }, maxTimeToRun: 60); + } + [Test] public async Task GroupAndUngroup() { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); testRunner.AddItemToBed(); @@ -63,8 +155,7 @@ namespace MatterHackers.MatterControl.Tests.Automation for (int i = 2; i <= 6; i++) { testRunner.ClickByName("Duplicate Button") - .WaitFor(() => scene.Children.Count == i); - Assert.AreEqual(i, scene.Children.Count, $"Should have {i} parts after copy"); + .Require(() => scene.Children.Count == i, $"Should have {i} parts after copy"); } // Get MeshGroupCount before Group is clicked @@ -75,12 +166,10 @@ namespace MatterHackers.MatterControl.Tests.Automation // select all .Type("^a") .ClickByName("Group Button") - .WaitFor(() => scene.Children.Count == 1); - Assert.AreEqual(1, scene.Children.Count, $"Should have 1 parts after group"); + .Require(() => scene.Children.Count == 1, $"Should have 1 parts after group"); testRunner.ClickByName("Ungroup Button") - .WaitFor(() => scene.Children.Count == 6); - Assert.AreEqual(6, scene.Children.Count, $"Should have 6 parts after ungroup"); + .Require(() => scene.Children.Count == 6, $"Should have 6 parts after ungroup"); return Task.CompletedTask; }, overrideWidth: 1300); @@ -91,7 +180,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); testRunner.AddItemToBed(); @@ -172,4 +261,35 @@ namespace MatterHackers.MatterControl.Tests.Automation }); } } + + public static class WidgetExtensions + { + /// + /// Search the widget stack for a widget that is both visible on screen and has it's text set to the visibleText string + /// + /// The root widget to search + /// the name to search for + /// + public static GuiWidget GetVisibleWigetWithText(this GuiWidget widget, string visibleText) + { + if (widget.ActuallyVisibleOnScreen()) + { + if (widget.Text == visibleText) + { + return widget; + } + + foreach(var child in widget.Children) + { + var childWithText = GetVisibleWigetWithText(child, visibleText); + if (childWithText != null) + { + return childWithText; + } + } + } + + return null; + } + } } diff --git a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs index 19457e1ab..59ac011f0 100644 --- a/Tests/MatterControl.AutomationTests/PrintQueueTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintQueueTests.cs @@ -165,7 +165,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab(); + testRunner.OpenPartTab(); testRunner.AddTestAssetsToLibrary(new[] { "Batman.stl" }); diff --git a/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs b/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs index ee71e7149..4150fd5bf 100644 --- a/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs +++ b/Tests/MatterControl.AutomationTests/SqLiteLibraryProvider.cs @@ -13,7 +13,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { await MatterControlUtilities.RunTest((testRunner) => { - testRunner.OpenEmptyPartTab() + testRunner.OpenPartTab() .AddItemToBed(); var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget; diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 8e2c8e7e7..3109a5068 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -238,7 +238,7 @@ namespace MatterHackers.MatterControl.Tests.Automation return testRunner; } - public static AutomationRunner OpenEmptyPartTab(this AutomationRunner testRunner) + public static AutomationRunner OpenPartTab(this AutomationRunner testRunner, bool removeDefaultPhil = true) { SystemWindow systemWindow; testRunner.GetWidgetByName("Hardware Tab", out systemWindow, 10); @@ -250,7 +250,10 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Start New Design"); } - testRunner.VerifyAndRemovePhil(); + if (removeDefaultPhil) + { + testRunner.VerifyAndRemovePhil(); + } return testRunner; }