Continue consolidating Printer load operations
This commit is contained in:
parent
9694e9775f
commit
80a75a40fe
10 changed files with 117 additions and 120 deletions
|
|
@ -49,79 +49,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public static event EventHandler MaterialPresetChanged;
|
||||
|
||||
static bool showConnectionHelp = false;
|
||||
public static void ShowComPortConnectionHelp() { showConnectionHelp = true; }
|
||||
|
||||
private static PrinterSettings activeInstance;
|
||||
public static PrinterSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return activeInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (activeInstance != value
|
||||
&& value != null)
|
||||
{
|
||||
// If we have an active printer, run Disable
|
||||
if (activeInstance != PrinterSettings.Empty)
|
||||
{
|
||||
activeInstance?.printer.Connection.Disable();
|
||||
}
|
||||
|
||||
activeInstance = value;
|
||||
|
||||
BedSettings.SetMakeAndModel(activeInstance.GetValue(SettingsKey.make), activeInstance.GetValue(SettingsKey.model));
|
||||
|
||||
SwitchToPrinterTheme();
|
||||
|
||||
OnActivePrinterChanged(null);
|
||||
|
||||
if (!MatterControlApplication.IsLoading)
|
||||
{
|
||||
if (activeInstance.PrinterSelected
|
||||
&& activeInstance.GetValue<bool>(SettingsKey.auto_connect))
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
activeInstance.printer.Connection.Connect(showConnectionHelp);
|
||||
showConnectionHelp = false;
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ActiveSliceSettings()
|
||||
{
|
||||
activeInstance = PrinterSettings.Empty;
|
||||
}
|
||||
public static PrinterSettings Instance => ApplicationController.Instance.ActivePrinter.Settings;
|
||||
|
||||
public static void OnSettingChanged(string slicerConfigName)
|
||||
{
|
||||
SettingChanged.CallEvents(null, new StringEventArgs(slicerConfigName));
|
||||
}
|
||||
|
||||
public static void RefreshActiveInstance(PrinterSettings updatedProfile)
|
||||
{
|
||||
bool themeChanged = activeInstance.GetValue(SettingsKey.active_theme_name) != updatedProfile.GetValue(SettingsKey.active_theme_name);
|
||||
|
||||
activeInstance = updatedProfile;
|
||||
|
||||
ActiveSliceSettings.SettingChanged.CallEvents(null, new StringEventArgs(SettingsKey.printer_name));
|
||||
|
||||
if (themeChanged)
|
||||
{
|
||||
UiThread.RunOnIdle(SwitchToPrinterTheme);
|
||||
}
|
||||
else
|
||||
{
|
||||
UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches to the ActivePrinter theme without firing the ThemeChanged event. This is useful when changing printers and
|
||||
/// allows the theme state to be updated before the ActivePrinterChanged event fires, resulting in a single ReloadAll
|
||||
|
|
@ -140,13 +74,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
internal static async Task SwitchToProfile(string printerID)
|
||||
{
|
||||
ProfileManager.Instance.LastProfileID = printerID;
|
||||
Instance = (await ProfileManager.LoadProfileAsync(printerID)) ?? PrinterSettings.Empty;
|
||||
}
|
||||
|
||||
private static void OnActivePrinterChanged(EventArgs e)
|
||||
public static void OnActivePrinterChanged(EventArgs e)
|
||||
{
|
||||
ActivePrinterChanged.CallEvents(null, e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue