Merge pull request #1849 from jlewin/master

Convert public EventHandler fields to events
This commit is contained in:
johnlewin 2017-01-25 10:16:00 -08:00 committed by GitHub
commit cb130c318d
8 changed files with 25 additions and 37 deletions

View file

@ -296,8 +296,6 @@ namespace MatterHackers.MatterControl
return monoSpacedTypeFace;
}
private set { }
}
/// <summary>

View file

@ -45,19 +45,20 @@ namespace MatterHackers.MatterControl.CreatorPlugins
public delegate void UnlockRegisterFunction(EventHandler functionToCallOnEvent, ref EventHandler functionThatWillBeCalledToUnregisterEvent);
public UnlockRegisterFunction unlockRegisterFunction;
public EventHandler functionToLaunchCreator;
public Action Show;
public string iconPath;
public string description;
public bool paidAddOnFlag;
public CreatorInformation(EventHandler functionToLaunchCreator,
public CreatorInformation(
Action showFunction,
string iconPath, string description,
bool paidAddOnFlag = false,
UnlockFunction unlockFunction = null,
PermissionFunction permissionFunction = null,
UnlockRegisterFunction unlockRegisterFunction = null)
{
this.functionToLaunchCreator = functionToLaunchCreator;
this.Show = showFunction;
this.iconPath = iconPath;
this.description = description;
this.paidAddOnFlag = paidAddOnFlag;

View file

@ -259,13 +259,11 @@ namespace MatterHackers.MatterControl.CreatorPlugins
private void CloseOnIdle(object state)
{
Close();
CreatorInformation callCorrectFunctionHold = state as CreatorInformation;
if (callCorrectFunctionHold != null)
CreatorInformation creatorInfo = state as CreatorInformation;
if (creatorInfo != null)
{
UiThread.RunOnIdle(() =>
{
callCorrectFunctionHold.functionToLaunchCreator(null, null);
});
UiThread.RunOnIdle(creatorInfo.Show);
}
}
}

View file

@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class ViewGcodeWidget : GuiWidget
{
public EventHandler DoneLoading;
public event EventHandler DoneLoading;
public ProgressChangedEventHandler LoadingProgressChanged;

View file

@ -34,7 +34,6 @@ using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.FieldValidation;
using MatterHackers.MatterControl.PrinterControls;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
@ -43,15 +42,13 @@ namespace MatterHackers.MatterControl
public class EditMacrosWindow : SystemWindow
{
public GCodeMacro ActiveMacro;
public EventHandler FunctionToCallOnSave;
private static EditMacrosWindow editMacrosWindow = null;
public EditMacrosWindow(EventHandler functionToCallOnSave)
public EditMacrosWindow()
: base(560, 420)
{
AlwaysOnTopOfMain = true;
Title = "Macro Editor".Localize();
this.FunctionToCallOnSave = functionToCallOnSave;
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
ChangeToMacroList();
ShowAsSystemWindow();
@ -62,7 +59,7 @@ namespace MatterHackers.MatterControl
{
if (editMacrosWindow == null)
{
editMacrosWindow = new EditMacrosWindow(ReloadMacros);
editMacrosWindow = new EditMacrosWindow();
editMacrosWindow.Closed += (popupWindowSender, popupWindowSenderE) => { editMacrosWindow = null; };
}
else
@ -88,7 +85,7 @@ namespace MatterHackers.MatterControl
UiThread.RunOnIdle(DoChangeToMacroList);
}
protected static void ReloadMacros(object sender, EventArgs e)
public void RefreshMacros()
{
ActiveSliceSettings.Instance.Save();
ApplicationController.Instance.ReloadAll();
@ -284,7 +281,8 @@ namespace MatterHackers.MatterControl
if (ValidateMacroForm())
{
SaveActiveMacro();
windowController.FunctionToCallOnSave(this, null);
windowController.RefreshMacros();
windowController.ChangeToMacroList();
}
});
@ -372,8 +370,8 @@ namespace MatterHackers.MatterControl
macroRow.AddChild(new HorizontalSpacer());
// You can't pass a foreach variable into a link function or it wall always be the last item.
// So we make a local variable copy of it and pass that. This will get the right one.
// You can't use the foreach variable inside the lambda functions directly or it will always be the last item.
// We make a local variable to create a closure around it to ensure we get the correct instance
var localMacroReference = macro;
Button editLink = linkButtonFactory.Generate("edit".Localize());
@ -388,7 +386,8 @@ namespace MatterHackers.MatterControl
removeLink.Click += (sender, e) =>
{
ActiveSliceSettings.Instance.Macros.Remove(localMacroReference);
windowController.FunctionToCallOnSave(this, null);
windowController.RefreshMacros();
windowController.ChangeToMacroList();
};
macroRow.AddChild(removeLink);

@ -1 +1 @@
Subproject commit 96c879330d24238469b5f5a91df84d4842f0e527
Subproject commit 87b30048af006ae4c3028d790594daac31cb9c6e

View file

@ -121,7 +121,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.Wait(.1);
}
[Test, Apartment(ApartmentState.STA)]
[Test, Apartment(ApartmentState.STA) /* Test will fail if screen size is and "HeatBeforeHoming" falls below the fold */]
public async Task ClearingCheckBoxClearsUserOverride()
{
AutomationTest testToRun = (testRunner) =>

View file

@ -37,17 +37,14 @@ namespace MatterHackers.MatterControl.Plugins.TextCreator
{
public class TextCreatorPlugin : MatterControlPlugin
{
public TextCreatorPlugin()
{
}
private GuiWidget mainApplication;
public override void Initialize(GuiWidget application)
{
CreatorInformation information = new CreatorInformation(LaunchNewTextCreator, "TC_32x32.png", "Text Creator".Localize());
var information = new CreatorInformation(
() => new TextCreatorMainWindow(),
"TC_32x32.png",
"Text Creator".Localize());
RegisteredCreators.Instance.RegisterLaunchFunction(information);
mainApplication = application;
}
public override string GetPluginInfoJSon()
@ -60,10 +57,5 @@ namespace MatterHackers.MatterControl.Plugins.TextCreator
"\"URL\": \"https://www.matterhackers.com\"" +
"}";
}
public void LaunchNewTextCreator(object sender, EventArgs e)
{
TextCreatorMainWindow mainWindow = new TextCreatorMainWindow();
}
}
}