public void CopyProperties(FamilyModel copyModel) { PersonSettings = new PersonSettings(); PersonSettings.CopyProperties(copyModel.PersonSettings); RelationshipSettings = new RelationshipSettings(); RelationshipSettings.CopyProperties(copyModel.RelationshipSettings); Tree = new Tree(); Tree.CopyProperties(copyModel.Tree); Members = new ObservableCollection<PersonModel>() { }; Members = copyModel.Members; Relationships = new ObservableCollection<RelationshipModel>() { }; Relationships = copyModel.Relationships; }
public bool IsEqual(FamilyModel compareModel) { if (!PersonSettings.IsEqual(compareModel.PersonSettings)) { return false; } if (!RelationshipSettings.IsEqual(compareModel.RelationshipSettings)) { return false; } if (!Tree.IsEqual(compareModel.Tree)) { return false; } if (Members.Count() != compareModel.Members.Count()) { return false; } for (int i = 0; i < Members.Count; i++) { if (!Members[i].IsEqual(compareModel.Members[i])) { return false; } } if (Relationships.Count() != compareModel.Relationships.Count()) { return false; } for (int i = 0; i < Relationships.Count; i++) { if (!Relationships[i].IsEqual(compareModel.Relationships[i])) { return false; } } return true; }
public void Redo_Executed() { // Return if there are no recorded models if (UndoneFamilyModels.Count < 1) { return; } // Do not record changes during the redo disableChangeRecording = true; // Get the recorded model that was undone FamilyModel modelToRestore = UndoneFamilyModels.Last(); // Remove the records UndoneFamilyModels.Remove(modelToRestore); RedoDescriptions.Remove(RedoDescriptions.Last()); // Record the current model in the done list FamilyModel recordModel = new FamilyModel(); recordModel.CopyProperties(currentFamilyModel); RecordedFamilyModels.Add(recordModel); UndoDescriptions.Add(Redo_ToolTip.Replace("Redo", "Undo")); // Refresh the undo-redo tooltips if (UndoDescriptions.Count() > 0) { Undo_ToolTip = UndoDescriptions.Last(); } else { Undo_ToolTip = "Undo..."; } if (RedoDescriptions.Count() > 0) { Redo_ToolTip = RedoDescriptions.Last(); } else { Redo_ToolTip = "Redo..."; } // Restore RestoreFamilyModel(modelToRestore); disableChangeRecording = false; }
private void CreateNewFamily() { // Create a personmodel PersonModel personModel = new PersonModel(); personModel.FirstName = "First Name"; personModel.LastName = "Last Name"; personModel.Gender = "Not Specified"; personModel.DOB = DateTime.Now; personModel.GenerationIndex = 0; personModel.SiblingIndex = 0; // Create a familymodel and add the personmodel FamilyModel newFamily = new FamilyModel(); newFamily.PersonSettings = new PersonSettings(); newFamily.RelationshipSettings = new RelationshipSettings(); newFamily.Tree = new Tree(); newFamily.Members = new ObservableCollection<PersonModel>() { }; newFamily.Relationships = new ObservableCollection<RelationshipModel>() { }; newFamily.Members.Add(personModel); // Mark the personmodel as selected newFamily.Tree.SelectedPersonId = personModel.Id; // Restore this new familymodel into the workspace RestoreFamilyModel(newFamily); newFamily.CopyProperties(GetCurrentFamilyModel()); SavedFamilyModel = newFamily; SavedFamilyModel.CopyProperties(GetCurrentFamilyModel()); // Set the title Title = "Family Explorer - NewFamily.fex"; // Clear undo-redo records RecordedFamilyModels.Clear(); UndoneFamilyModels.Clear(); }
private FamilyModel GetCurrentFamilyModel() { FamilyModel currentFamilyModel = new FamilyModel(); currentFamilyModel.PersonSettings = Settings.Instance.Person; currentFamilyModel.RelationshipSettings = Settings.Instance.Relationship; currentFamilyModel.Tree = Tree; if (SelectedPerson != null) { currentFamilyModel.Tree.SelectedPersonId = SelectedPerson.Id; } if (SelectedRelationship != null) { currentFamilyModel.Tree.SelectedRelationshipId = SelectedRelationship.Id; } currentFamilyModel.Members = new ObservableCollection<PersonModel>() { }; foreach (PersonView personView in Members) { PersonModel personModel = new PersonModel(); personModel.CopyBaseProperties(personView); currentFamilyModel.Members.Add(personModel); } currentFamilyModel.Relationships = new ObservableCollection<RelationshipModel> { }; foreach (RelationshipView relationshipView in Relationships) { RelationshipModel relationshipModel = new RelationshipModel(); relationshipModel.CopyBaseProperties(relationshipView); currentFamilyModel.Relationships.Add(relationshipModel); } return currentFamilyModel; }
private void RestoreFamilyModel(FamilyModel model) { disableChangeRecording = true; Settings.Instance.Person = new PersonSettings(); if (model.PersonSettings != null) { Settings.Instance.Person.CopyProperties(model.PersonSettings); } Settings.Instance.Relationship = new RelationshipSettings(); if (model.RelationshipSettings != null) { Settings.Instance.Relationship.CopyProperties(model.RelationshipSettings); } Members.Clear(); if (model.Members != null) { foreach (PersonModel personModel in model.Members) { PersonView personView = new PersonView(GetNextID()); personView.CopyBaseProperties(personModel); Members.Add(personView); } } Relationships.Clear(); if (model.Relationships != null) { foreach (RelationshipModel relationshipModel in model.Relationships) { RelationshipView relationshipView = new RelationshipView(relationshipModel.Id); relationshipView.CopyBaseProperties(relationshipModel); Relationships.Add(relationshipView); } } Tree = new Tree(); if (model.Tree != null) { Tree.CopyProperties(model.Tree); } SelectedPerson = GetPerson(Tree.SelectedPersonId); if (SelectedPerson != null) { SelectedPerson.Selected = true; } SelectedRelationship = GetRelationship(Tree.SelectedRelationshipId); if (SelectedRelationship != null) { SelectedRelationship.Selected = true; } RefreshTreeLayout(); SubscribeToEvents(); CurrentFamilyModel = GetCurrentFamilyModel(); Undo.RaiseCanExecuteChanged(); Redo.RaiseCanExecuteChanged(); lastChangeTime = DateTime.Now; disableChangeRecording = false; FamilyTreeCursor = Cursors.Arrow; SelectCommandInProgressType = 0; }
private void RecordFamilyChange(string changeDescription) { // Do not record redo-undo commands if (disableChangeRecording) { return; } // If this change occurred within the last xxx ms of the previous change, assume it is a cascading change and ingnore if (lastChangeTime != null) { if (DateTime.Now - lastChangeTime < new TimeSpan(0, 0, 0, 0, 50)) { // Make note of the new status CurrentFamilyModel = GetCurrentFamilyModel(); lastChangeTime = DateTime.Now; return; } } // Record the status before the change FamilyModel recordModel = new FamilyModel(); recordModel.CopyProperties(currentFamilyModel); RecordedFamilyModels.Add(recordModel); //TODO: need to create a new object, currently storing the same object repeatedly UndoDescriptions.Add("Undo " + changeDescription); // Clear redo list on new changes UndoneFamilyModels.Clear(); RedoDescriptions.Clear(); // Make note of the new status CurrentFamilyModel = GetCurrentFamilyModel(); Undo_ToolTip = UndoDescriptions.Last(); // Refresh undo-redo tooltips if (UndoDescriptions.Count() > 0) { Undo_ToolTip = UndoDescriptions.Last(); } else { Undo_ToolTip = "Undo..."; } Redo_ToolTip = "Redo..."; // Check if different from saved copy //if (SavedFamilyModel.IsEqual(GetCurrentFamilyModel())) { HasChanges = false; } //else { HasChanges = true; } // Refresh can executes Undo.RaiseCanExecuteChanged(); Redo.RaiseCanExecuteChanged(); // Record change time lastChangeTime = DateTime.Now; }