Wire up Delete printer

This commit is contained in:
John Lewin 2016-05-17 18:27:08 -07:00
parent 83a8a84965
commit a6ba5767d3
4 changed files with 28 additions and 3 deletions

View file

@ -103,6 +103,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
// TODO: Upload new profiles to webservice
}
ProfileData.Profiles.CollectionChanged += Profiles_CollectionChanged;
foreach(string filePath in Directory.GetFiles(profilesPath, "*.json"))
{
string fileName = Path.GetFileName(filePath);
@ -154,6 +156,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ActiveSliceSettings.LoadStartupProfile();
}
private static void Profiles_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
string profilePath = Path.Combine(profilesPath, Instance.ID + ".json");
if (File.Exists(profilePath))
{
File.Delete(profilePath);
}
// Refresh after remove
UiThread.RunOnIdle(() => Instance = new SettingsProfile(LoadEmptyProfile()));
}
}
public static LayeredProfile LoadEmptyProfile()
{
return new LayeredProfile(new OemProfile(), LoadMatterHackersBaseLayer());

View file

@ -49,6 +49,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
using DataStorage;
using Agg.PlatformAbstract;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
public class SettingsProfile
{
private static string configFileExtension = "slice";
@ -1151,7 +1152,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class ProfileData
{
public List<PrinterInfo> Profiles { get; set; } = new List<PrinterInfo>();
public ObservableCollection<PrinterInfo> Profiles { get; set; } = new ObservableCollection<PrinterInfo>();
}
public class PrinterInfo