GuiWiget Children working as a SafeList

This commit is contained in:
LarsBrubaker 2019-06-28 22:22:58 -07:00 committed by jlewin
parent 106db7e7f1
commit 58e77cfe60
40 changed files with 104 additions and 102 deletions

View file

@ -360,7 +360,7 @@ namespace MatterHackers.MatterControl
allowDisabledOrHidden: false);
// If the context changed, update the UI
if (namedChildren.LastOrDefault()?.widget is GuiWidget firstUnderMouse
if (namedChildren.LastOrDefault()?.Widget is GuiWidget firstUnderMouse
&& firstUnderMouse != this.InspectedWidget)
{
this.InspectedWidget = firstUnderMouse;

View file

@ -411,7 +411,7 @@ namespace MatterHackers.MatterControl
SystemWindow topSystemWindow = AppContext.RootSystemWindow;
if (topSystemWindow != null)
{
topSystemWindow.CloseOnIdle();
topSystemWindow.Close();
return true;
}
#endif

View file

@ -2194,7 +2194,7 @@ namespace MatterHackers.MatterControl
}
catch (Exception ex)
{
reloadingOverlay?.CloseOnIdle();
reloadingOverlay?.Close();
UiThread.RunOnIdle(() =>
{
@ -3930,7 +3930,7 @@ Support and tutorials:
ReportStartupProgress(0.02, "First draw->RunOnIdle");
//UiThread.RunOnIdle(() =>
Task.Run(async () =>
Task.Run((Func<Task>)(async () =>
{
try
{
@ -3952,7 +3952,7 @@ Support and tutorials:
}
catch (Exception ex)
{
UiThread.RunOnIdle(() =>
UiThread.RunOnIdle((Action)(() =>
{
statusText.Visible = false;
@ -3988,11 +3988,11 @@ Support and tutorials:
progressBar.Visible = false;
progressPanel.AddChild(closeButton);
});
}));
}
AppContext.IsLoading = false;
});
}));
}
ReportStartupProgress(0, "ShowAsSystemWindow");

View file

@ -87,7 +87,7 @@ namespace MatterHackers.MatterControl
saveButton.Click += (s,e) =>
{
ApplicationController.Plugins.Save();
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
};
this.AddPageAction(saveButton);

View file

@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl
var affirmativeButton = theme.CreateDialogButton(yesOk);
affirmativeButton.Click += (s, e) =>
{
UiThread.RunOnIdle(this.DialogWindow.Close);
this.DialogWindow.Close();
// If applicable, invoke the callback
responseCallback?.Invoke(true);

View file

@ -100,15 +100,16 @@ namespace MatterHackers.MatterControl.CustomWidgets
public void RemovePage(string key, bool allowRebuild = true)
{
foreach(var tab in allTabs)
foreach (var tab in allTabs)
{
if(tab.key == key)
if (tab.key == key)
{
allTabs.Remove(tab);
if (allowRebuild)
{
this.Rebuild();
}
return;
}
}
@ -153,7 +154,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
this.ControlIsPinned = !this.ControlIsPinned;
this.printer.ViewState.DockWindowFloating = false;
UiThread.RunOnIdle(this.Rebuild);
this.Rebuild();
};
return pinTabButton;

View file

@ -195,7 +195,7 @@ namespace MatterHackers.MatterControl
DoExport(libraryItems, printer, activePlugin, centerOnBed, showInFolderAfterSave?.Checked == true);
this.Parent.CloseOnIdle();
this.Parent.Close();
};

View file

@ -39,7 +39,12 @@ namespace MatterHackers.MatterControl
: base(label, textColor)
{
var imageWidget = new ImageWidget(image);
this.AddChild(imageWidget, this.Children.IndexOf(labelTextWidget));
var index = 0;
this.Children.ReadOnly((list) =>
{
index = list.IndexOf(labelTextWidget);
});
this.AddChild(imageWidget, index);
imageWidget.Margin = new BorderDouble(8, 5);
labelTextWidget.Margin = new BorderDouble(8, 0);

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;

View file

@ -157,12 +157,12 @@ namespace MatterHackers.MatterControl.EeProm
// the bottom button bar
var buttonSave = theme.CreateDialogButton("Save to EEProm".Localize());
buttonSave.Click += (s, e) =>UiThread.RunOnIdle(() =>
buttonSave.Click += (s, e) =>
{
SaveSettingsToActive();
currentEePromSettings.SaveToEeProm();
this.DialogWindow.Close();
});
};
this.AddPageAction(buttonSave);
var exportButton = theme.CreateDialogButton("Export".Localize());

View file

@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl.EeProm
{
if (!printer.Connection.IsConnected)
{
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
}
}
}
@ -172,13 +172,11 @@ namespace MatterHackers.MatterControl.EeProm
var buttonSave = theme.CreateDialogButton("Save To EEPROM".Localize());
buttonSave.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
currentEePromSettings.Save(printer.Connection);
currentEePromSettings.Clear();
this.DialogWindow.Close();
});
currentEePromSettings.Save(printer.Connection);
currentEePromSettings.Clear();
this.DialogWindow.Close();
};
this.AddPageAction(buttonSave);
var exportButton = theme.CreateDialogButton("Export".Localize());

View file

@ -548,11 +548,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
if (item.Enabled)
{
item.Click += (s, e) => UiThread.RunOnIdle(() =>
item.Click += (s, e) =>
{
menu.Close();
menuAction.Action.Invoke(this.SelectedItems.Select(o => o.Model), this);
});
};
}
}
}

View file

@ -359,11 +359,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
else if (menuAction.IsEnabled(this.listViewItem.ListView.SelectedItems, this.listViewItem.ListView))
{
var item = menu.CreateMenuItem(menuAction.Title, menuAction.Icon);
item.Click += (s, e) => UiThread.RunOnIdle(() =>
item.Click += (s, e) =>
{
menu.Close();
menuAction.Action.Invoke(this.listViewItem.ListView.SelectedItems.Select(o => o.Model), this.listViewItem.ListView);
});
};
}
}

View file

@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl
writableContainer);
}
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
};
this.AddPageAction(acceptButton);

View file

@ -166,20 +166,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
AltMate = new MateOptions(MateEdge.Left, MateEdge.Bottom)
});
await Task.Run(async () =>
await Task.Run((Func<Task>)(async () =>
{
// Start index generation
await HelpIndex.RebuildIndex();
UiThread.RunOnIdle(() =>
UiThread.RunOnIdle((Action)(() =>
{
// Close popover
popover.Close();
// Continue to original task
ShowSearchPanel();
});
});
}));
}));
}
catch
{
@ -190,7 +190,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
else
{
searchPanel?.CloseOnIdle();
searchPanel?.Close();
searchPanelOpenOnMouseDown = false;
}
}

View file

@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl
editWidget.Text.Replace("\n", "\\n"),
userInitiated: true);
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
};
this.AddPageAction(saveButton);

View file

@ -150,7 +150,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
tumbleCubeControl = view3DWidget.InteractionLayer.Children<TumbleCubeControl>().FirstOrDefault();
var position = view3DWidget.InteractionLayer.Children.IndexOf(trackball);
var position = 0;
view3DWidget.InteractionLayer.Children.ReadOnly((list) =>
{
position = list.IndexOf(trackball);
});
gcodePanel = new GCodePanel(this, printer, sceneContext, theme)
{
@ -311,11 +315,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Margin = new BorderDouble(10, 10, 0, 15)
};
unloadFilamentButton.Click += (s, e2) => UiThread.RunOnIdle(() =>
unloadFilamentButton.Click += (s, e2) =>
{
unloadFilamentButton.Parents<SystemWindow>().First().Close();
DialogWindow.Show(new UnloadFilamentWizard(printer, extruderIndex: 0));
});
};
theme.ApplyPrimaryActionStyle(unloadFilamentButton);

View file

@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return;
}
var firstChild = this.Children[0];
var firstChild = this.Children.FirstOrDefault();
var bounds = this.LocalBounds;
// Get the first child bounds in our coords

View file

@ -106,7 +106,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
double blend = Easing.Cubic.In(ratio);
box.Position = new VectorMath.Vector2(startX + (xdistance * blend), startY);
//Console.WriteLine("Ms: {0}, Ratio: {1}, Easing: {2}, Position: {3}", elapsedMs, ratio, blend, box.Position);
// Console.WriteLine("Ms: {0}, Ratio: {1}, Easing: {2}, Position: {3}", elapsedMs, ratio, blend, box.Position);
box.Invalidate();
}
else

View file

@ -40,7 +40,7 @@ namespace MatterHackers.MatterControl.PrinterControls
protected override void OnCancel(out bool abortCancel)
{
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
abortCancel = true;
}
}

View file

@ -136,7 +136,7 @@ namespace MatterHackers.MatterControl
var savePresetsButton = theme.CreateDialogButton("Save".Localize());
savePresetsButton.Name = "Save Leveling Button";
savePresetsButton.Click += (s, e) => UiThread.RunOnIdle(() =>
savePresetsButton.Click += (s, e) =>
{
PrintLevelingData newLevelingData = printer.Settings.Helpers.PrintLevelingData;
@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl
printer.Settings.Helpers.PrintLevelingData = newLevelingData;
this.DialogWindow.Close();
});
};
this.AddPageAction(savePresetsButton);
var exportButton = theme.CreateDialogButton("Export".Localize());

View file

@ -128,6 +128,7 @@ namespace MatterHackers.MatterControl
{
settingString.Append(",");
}
first = false;
settingString.Append(axisLabels[i]);
@ -147,7 +148,7 @@ namespace MatterHackers.MatterControl
printer.Bed.GCodeRenderer?.Clear3DGCode();
}
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
};
this.AddPageAction(savePresetsButton);

View file

@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
// Construct buttons
nextButton = theme.CreateDialogButton("Done".Localize());
nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close);
nextButton.Click += (s, e) => Parent.Close();
nextButton.Visible = false;
connectButton = theme.CreateDialogButton("Connect".Localize());
@ -191,7 +191,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
printerComPortError.Text = "Connection succeeded".Localize() + "!";
nextButton.Visible = true;
connectButton.Visible = false;
UiThread.RunOnIdle(() => this?.Parent?.Close());
this?.Parent?.Close();
}
else if (printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect)
{

View file

@ -119,21 +119,21 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
Margin = new BorderDouble(0, 8),
TextColor = theme.TextColor
};
skipConnectionLink.Click += (s, e) => UiThread.RunOnIdle(() =>
skipConnectionLink.Click += (s, e) =>
{
printer.Connection.HaltConnectionThread();
Parent.Close();
});
};
container.AddChild(skipConnectionLink);
contentRow.AddChild(container);
//Construct buttons
// Construct buttons
var nextButton = theme.CreateDialogButton("Continue".Localize());
nextButton.Click += (s, e) => UiThread.RunOnIdle(() =>
nextButton.Click += (s, e) =>
{
DialogWindow.ChangeToPage(new SetupStepComPortTwo(printer));
});
};
this.AddPageAction(nextButton);
}

View file

@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
//Construct buttons
nextButton = theme.CreateDialogButton("Done".Localize());
nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close);
nextButton.Click += (s, e) => Parent.Close();
nextButton.Visible = false;
connectButton = theme.CreateDialogButton("Connect".Localize());
@ -177,7 +177,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
printerErrorMessage.Text = "Connection succeeded".Localize() + "!";
nextButton.Visible = true;
connectButton.Visible = false;
UiThread.RunOnIdle(() => this?.Parent?.Close());
this?.Parent?.Close();
}
else if (printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect)
{

View file

@ -263,10 +263,10 @@ namespace MatterHackers.MatterControl
// We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
eventArgs.Cancel = true;
UiThread.RunOnIdle(() =>
UiThread.RunOnIdle((Action)(() =>
{
StyledMessageBox.ShowMessageBox(
(exitConfirmed) =>
(Action<bool>)((exitConfirmed) =>
{
// Record that the exitDialog has closed
exitDialogOpen = false;
@ -283,20 +283,20 @@ namespace MatterHackers.MatterControl
printer.Connection.Disable();
}
this.CloseOnIdle();
this.Close();
}
},
}),
message,
caption,
StyledMessageBox.MessageType.YES_NO_WITHOUT_HIGHLIGHT);
});
}));
}
else if (!ApplicationController.Instance.ApplicationExiting)
{
// cancel the close so that we can save all our active work spaces
eventArgs.Cancel = true;
UiThread.RunOnIdle(async () =>
UiThread.RunOnIdle((Action)(async () =>
{
var application = ApplicationController.Instance;
@ -307,8 +307,8 @@ namespace MatterHackers.MatterControl
// Make sure we tell the Application Controller to shut down. This will release the slicing thread if running.
application.Shutdown();
this.CloseOnIdle();
});
this.Close();
}));
}
}

View file

@ -203,7 +203,7 @@ namespace MatterHackers.MatterControl
public virtual void ClosePage(bool allowAbort = true)
{
// Close this dialog window
this.CloseOnIdle();
this.Close();
}
public override void OnClosed(EventArgs e)
@ -237,7 +237,7 @@ namespace MatterHackers.MatterControl
this.ChangeToPage(panel);
// in the event of a reload all make sure we rebuild the contents correctly
ApplicationController.Instance.DoneReloadingAll.RegisterEvent((s,e) =>
ApplicationController.Instance.DoneReloadingAll.RegisterEvent((EventHandler)((s,e) =>
{
// Normal theme references are safe to hold in widgets because they're rebuild on ReloadAll. DialogWindow
// survives and must refresh its reference on reload
@ -256,11 +256,11 @@ namespace MatterHackers.MatterControl
DialogWindow = this
};
this.AddChild(newPanel, thisIndex);
panel.CloseOnIdle();
panel.Close();
// remember the new content
panel = newPanel;
}, ref unregisterEvents);
}), ref unregisterEvents);
return panel;
}

View file

@ -55,11 +55,8 @@ namespace MatterHackers.MatterControl
if (settingsToImport.QualityLayers.Count == 0 && settingsToImport.MaterialLayers.Count == 0)
{
// Only main setting so don't ask what to merge just do it.
UiThread.RunOnIdle(() =>
{
DisplayFailedToImportMessage(settingsFilePath);
this.Parents<SystemWindow>().First().Close();
});
DisplayFailedToImportMessage(settingsFilePath);
this.Parents<SystemWindow>().First().Close();
}
this.settingsFilePath = settingsFilePath;

View file

@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl
if (!string.IsNullOrEmpty(newName))
{
action.Invoke(newName);
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
}
};
this.AddPageAction(actionButton);

View file

@ -72,7 +72,7 @@ public class LicenseAgreementPage : DialogPage
protected override void OnCancel(out bool abortCancel)
{
// Exit if EULA is not accepted
UiThread.RunOnIdle(MatterHackers.MatterControl.AppContext.RootSystemWindow.Close);
MatterHackers.MatterControl.AppContext.RootSystemWindow.Close();
abortCancel = false;
}

View file

@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl
printerLoaded?.Invoke(printer);
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
}
}
@ -102,7 +102,7 @@ namespace MatterHackers.MatterControl
});
}
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
base.OnContinue(treeNode);
}

View file

@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl.SetupWizard
printer.SwapToSettings(printerSettings);
}
UiThread.RunOnIdle(DialogWindow.Close);
DialogWindow.Close();
}
};
this.AddPageAction(revertButton);

View file

@ -63,10 +63,10 @@ namespace MatterHackers.MatterControl.Tour
// Filter to on-screen items
var visibleTourItems = tourLocations.Where(t =>
{
var widget = visibleTourWidgets.FirstOrDefault(w => w.name == t.WidgetName && w.widget.ActuallyVisibleOnScreen());
var widget = visibleTourWidgets.FirstOrDefault(w => w.Name == t.WidgetName && w.Widget.ActuallyVisibleOnScreen());
// Update widget reference on tour object
t.Widget = widget?.widget;
t.Widget = widget?.Widget;
return widget != null;
});

View file

@ -170,7 +170,7 @@ namespace MatterHackers.MatterControl
ConditionalAbort("Are you sure you want to abort calibration?".Localize(), () =>
{
closeConfirmed = true;
this.CloseOnIdle();
this.Close();
});
}

View file

@ -80,7 +80,7 @@ namespace MatterHackers.MatterControl.Tour
closeButton.Margin = 0;
closeButton.Click += (s, e) =>
{
this.Parent.CloseOnIdle();
this.Parent.Close();
};
row.AddChild(closeButton);

View file

@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.Tour
nextButton.Name = "Next Button";
nextButton.Click += (s, e) =>
{
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
UiThread.RunOnIdle(ProductTour.StartTour);
};

View file

@ -75,35 +75,30 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var duplicateButton = theme.CreateDialogButton("Duplicate".Localize());
duplicateButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
string sanitizedName = numberMatch.Replace(inlineNameEdit.Text, "").Trim();
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
string sanitizedName = numberMatch.Replace(inlineNameEdit.Text, "").Trim();
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
var clonedLayer = presetsContext.PersistenceLayer.Clone();
clonedLayer.Name = newProfileName;
presetsContext.PresetLayers.Add(clonedLayer);
var clonedLayer = presetsContext.PersistenceLayer.Clone();
clonedLayer.Name = newProfileName;
presetsContext.PresetLayers.Add(clonedLayer);
presetsContext.SetAsActive(clonedLayer.LayerID);
presetsContext.PersistenceLayer = clonedLayer;
presetsContext.SetAsActive(clonedLayer.LayerID);
presetsContext.PersistenceLayer = clonedLayer;
sliceSettingsWidget.Close();
sliceSettingsWidget = CreateSliceSettingsWidget(printer, clonedLayer);
contentRow.AddChild(sliceSettingsWidget);
sliceSettingsWidget.Close();
sliceSettingsWidget = CreateSliceSettingsWidget(printer, clonedLayer);
contentRow.AddChild(sliceSettingsWidget);
inlineNameEdit.Text = newProfileName;
});
inlineNameEdit.Text = newProfileName;
};
this.AddPageAction(duplicateButton);
var deleteButton = theme.CreateDialogButton("Delete".Localize());
deleteButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
{
presetsContext.DeleteLayer();
this.DialogWindow.Close();
});
presetsContext.DeleteLayer();
this.DialogWindow.Close();
};
this.AddPageAction(deleteButton);
}

View file

@ -141,7 +141,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
this.ValueChanged?.Invoke(this, null);
this.DialogWindow.CloseOnIdle();
this.DialogWindow.Close();
};
this.AddPageAction(saveButton);
}

@ -1 +1 @@
Subproject commit 48b38a00c1ce80ed5e4a2d80d30f23db2e2b181f
Subproject commit e87d2c150c1f410a6c360eecfd1a9bbdbfb72e58

View file

@ -824,7 +824,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
testMethod,
maxTimeToRun,
defaultTestImages,
closeWindow: () =>
closeWindow: (Action)(() =>
{
foreach(var printer in ApplicationController.Instance.ActivePrinters)
{
@ -835,7 +835,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
}
rootSystemWindow.Close();
});
}));
}
public static void LibraryEditSelectedItem(AutomationRunner testRunner)