Creating an ActivePrinterProfile singleton and starting to move the code from PrinterCommunication into that.

This commit is contained in:
larsbrubaker 2014-02-14 11:54:21 -08:00
parent 999e3ea551
commit 5036b364c0
4 changed files with 56 additions and 10 deletions

51
ActivePrinterProfile.cs Normal file
View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using System.Text;
using System.IO;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.VectorMath;
using MatterHackers.MatterControl.ContactForm;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl
{
public class ActivePrinterProfile
{
static ActivePrinterProfile globalInstance = null;
// private so that it can only be gotten through the Instance
ActivePrinterProfile()
{
}
public Printer ActivePrinter { get; set; }
public static ActivePrinterProfile Instance
{
get
{
if (globalInstance == null)
{
globalInstance = new ActivePrinterProfile();
}
return globalInstance;
}
set
{
if (globalInstance != value)
{
PrinterCommunication.Instance.Disable();
globalInstance = value;
PrinterCommunication.Instance.OnActivePrinterChanged(null);
}
}
}
}
}

View file

@ -72,6 +72,7 @@
<Compile Include="ActionBar\PrintActionRow.cs" />
<Compile Include="ActionBar\PrinterActionRow.cs" />
<Compile Include="ActionBar\PrintStatusRow.cs" />
<Compile Include="ActivePrinterProfile.cs" />
<Compile Include="CustomWidgets\ExportQueueItemWindow.cs" />
<Compile Include="CustomWidgets\ExportToFolderFeedbackWindow.cs" />
<Compile Include="FieldValidation.cs" />

View file

@ -198,7 +198,6 @@ namespace MatterHackers.MatterControl
Thread readFromPrinterThread;
Thread connectThread;
private Printer activePrinter;
private PrintItemWrapper activePrintItem;
int lastRemainingSecondsReported = 0;
@ -411,17 +410,11 @@ namespace MatterHackers.MatterControl
{
get
{
return this.activePrinter;
return ActivePrinterProfile.Instance.ActivePrinter;
}
set
{
if (this.activePrinter != value)
{
Disable();
this.activePrinter = value;
this.CommunicationState = CommunicationStates.Disconnected;
OnActivePrinterChanged(null);
}
ActivePrinterProfile.Instance.ActivePrinter = value;
}
}
@ -1362,7 +1355,7 @@ namespace MatterHackers.MatterControl
FanSpeedSet.CallEvents(this, e);
}
void OnActivePrinterChanged(EventArgs e)
public void OnActivePrinterChanged(EventArgs e)
{
ActivePrinterChanged.CallEvents(this, e);
}

View file

@ -67,6 +67,7 @@ namespace MatterHackers.MatterControl
SettingsChanged.CallEvents(this, null);
}
// private so that it can only be gotten through the Instance
ActiveSliceSettings()
{
}