private void RestoreFromUndoStep() { if (this._undoChain.Any()) { _lastProjectState = this._undoChain.Last(); this._undoChain.Remove(_lastProjectState); this.Project = SerializableProjectViewModel.ToProjectViewModel(_lastProjectState); } }
private void SaveUndoStep() { this._undoChain.Add(_lastProjectState); _lastProjectState = SerializableProjectViewModel.FromProjectViewModel(this.Project); if (this._undoChain.Count > 30) { this._undoChain.RemoveAt(0); } }
public AppViewModel() { this.LoadedProjectPath = ""; // Load the project and set the last undo state this.Project = new ProjectViewModel { Name = "Hello world!" }; this._lastProjectState = SerializableProjectViewModel.FromProjectViewModel(this.Project); this._undoChain = new List <SerializableProjectViewModel>(); this.SimulationTool = new SimulationToolViewModel(this); this.SimulationTool.SimulationComplete += SimulationToolOnSimulationComplete; this.Notifications = new ObservableCollection <NotificationViewModel>(); }
public void OpenProject() { var dialog = new OpenFileDialog { Filter = "Project Foresight JSON File (.prfj) | *.prfj", DefaultExt = ".prfj", FileName = this.LoadedProjectPath }; if (dialog.ShowDialog() == true) { this._isAutoSimulateOn = false; this.LoadedProjectPath = dialog.FileName; var text = File.ReadAllText(this.LoadedProjectPath); var working = JsonConvert.DeserializeObject <SerializableProjectViewModel>(text); this.Project = SerializableProjectViewModel.ToProjectViewModel(working); this._lastProjectState = SerializableProjectViewModel.FromProjectViewModel(this.Project); this.AddNotification($"Opened project '{Path.GetFileName(dialog.FileName)}'", 5, new SolidColorBrush(Colors.LightGreen)); this._undoChain.Clear(); } }
public void SaveProjectAs() { var dialog = new SaveFileDialog { Filter = "Project Foresight JSON File (.prfj) | *.prfj", DefaultExt = ".prfj", FileName = this.LoadedProjectPath }; if (dialog.ShowDialog() == true) { this.LoadedProjectPath = dialog.FileName; File.WriteAllText(this.LoadedProjectPath, JsonConvert.SerializeObject(SerializableProjectViewModel.FromProjectViewModel(this.Project), Formatting.Indented)); this.AddNotification($"Saved project '{Path.GetFileName(dialog.FileName)}'", 5, new SolidColorBrush(Colors.Aqua)); } }
public void SaveProject() { if (string.IsNullOrEmpty(this.LoadedProjectPath) || !File.Exists(this.LoadedProjectPath)) { this.SaveProjectAs(); } else { File.WriteAllText(this.LoadedProjectPath, JsonConvert.SerializeObject(SerializableProjectViewModel.FromProjectViewModel(this.Project), Formatting.Indented)); this.AddNotification($"Saved project '{Path.GetFileName(this.LoadedProjectPath)}'", 5, new SolidColorBrush(Colors.Aqua)); } }
/// <summary> /// Create a deep copy of a ProjectViewModel, including new objects rather than links /// </summary> /// <param name="project"></param> /// <returns></returns> public static ProjectViewModel DeepCopy(ProjectViewModel project) { var serialized = SerializableProjectViewModel.FromProjectViewModel(project); return(SerializableProjectViewModel.ToProjectViewModel(serialized)); }