Make settings history consistent across references

Revert ChangeID code
This commit is contained in:
Lars Brubaker 2016-09-07 15:53:52 -07:00
parent ced3d5174f
commit 92f01f894e
3 changed files with 34 additions and 51 deletions

View file

@ -19,7 +19,7 @@ namespace MatterHackers.MatterControl.SetupWizard
ScrollableWidget scrollWindow;
public PrinterProfileHistoryPage()
: base(unlocalizedTextForTitle: "Profile History")
: base(unlocalizedTextForTitle: "Settings History")
{
scrollWindow = new ScrollableWidget()
{

View file

@ -441,55 +441,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class PrinterInfo
{
public string ComPort { get; set; }
private string id;
public string ID
{
get { return id; }
set
{
if (this.id == value)
{
return;
}
// Ensure the local file with the old ID moves with the new ID change
string existingProfilePath = ProfilePath;
if (this.id != value
&& File.Exists(existingProfilePath))
{
// Profile ID change must come after existingProfilePath calculation and before ProfilePath getter
// this will change the profile path
this.id = value;
// and update the name of the file
File.Move(existingProfilePath, ProfilePath);
}
else
{
this.id = value;
}
// If we are changing the active profile
if (ActiveSliceSettings.Instance.ID == this.ID)
{
ActiveSliceSettings.Instance.ID = value;
}
if (File.Exists(ProfilePath))
{
var profile = PrinterSettings.LoadFile(ProfilePath);
if (profile.ID != value)
{
profile.ID = value;
profile.Save();
}
}
ProfileManager.Instance.Save();
}
}
public string ID { get; set; }
public string Name { get; set; }
public string Make { get; set; }
public string Model { get; set; }
@ -498,6 +450,37 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public bool MarkedForDelete { get; set; } = false;
public string SHA1 { get; set; }
public void ChangeID(string newID)
{
// Update in memory state if IDs match
if (ActiveSliceSettings.Instance.ID == this.ID)
{
ActiveSliceSettings.Instance.ID = newID;
}
// Ensure the local file with the old ID moves with the new ID change
string existingProfilePath = ProfilePath;
if (File.Exists(existingProfilePath))
{
// Profile ID change must come after existingProfilePath calculation and before ProfilePath getter
this.ID = newID;
File.Move(existingProfilePath, ProfilePath);
}
else
{
this.ID = newID;
}
if (File.Exists(ProfilePath))
{
var profile = PrinterSettings.LoadFile(ProfilePath);
profile.ID = newID;
profile.Save();
}
ProfileManager.Instance.Save();
}
[JsonIgnore]
public string ProfilePath => ProfileManager.Instance.ProfilePath(this);
}

View file

@ -112,7 +112,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
sliceOptionsMenuDropList.AddItem("Export".Localize()).Selected += (s, e) => { WizardWindow.Show<ExportSettingsPage>("ExportSettingsPage", "Export Settings"); };
MenuItem settingsHistory = sliceOptionsMenuDropList.AddItem("Settings History".Localize());
settingsHistory.Selected += (s, e) => { WizardWindow.Show<PrinterProfileHistoryPage>("PrinterProfileHistory", "Profile History"); };
settingsHistory.Selected += (s, e) => { WizardWindow.Show<PrinterProfileHistoryPage>("PrinterProfileHistory", "Settings History"); };
settingsHistory.Enabled = ApplicationController.Instance.GetSessionUsername() != null;