diff --git a/src/DynamoCore/Core/UndoRedoRecorder.cs b/src/DynamoCore/Core/UndoRedoRecorder.cs index 2ef56d8c5a4..d5606fb03de 100644 --- a/src/DynamoCore/Core/UndoRedoRecorder.cs +++ b/src/DynamoCore/Core/UndoRedoRecorder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Xml; diff --git a/src/DynamoCore/Graph/Annotations/AnnotationModel.cs b/src/DynamoCore/Graph/Annotations/AnnotationModel.cs index 1dc80cce685..8439382b0fe 100644 --- a/src/DynamoCore/Graph/Annotations/AnnotationModel.cs +++ b/src/DynamoCore/Graph/Annotations/AnnotationModel.cs @@ -262,7 +262,6 @@ public double TextBlockHeight } } - private double textMaxWidth; /// /// Returns the maxWidth of text area of the group @@ -367,6 +366,10 @@ public bool IsExpanded get { return isExpanded; } set { + // ip comment: + // this is called on undo! + // at the moment IsCollapsed is not called in the VM + // need to RaiseProperty changed from here? isExpanded = value; UpdateBoundaryFromSelection(); UpdateErrorAndWarningIconVisibility(); @@ -657,6 +660,9 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams) case nameof(AnnotationDescriptionText): AnnotationDescriptionText = value; break; + case nameof(IsExpanded): + IsExpanded = Convert.ToBoolean(value); + break; } return base.UpdateValueCore(updateValueParams); @@ -680,6 +686,7 @@ void SerializeCore(XmlElement element, SaveContext context) helper.SetAttribute("TextblockHeight", this.TextBlockHeight); helper.SetAttribute("backgrouund", (this.Background == null ? "" : this.Background.ToString())); helper.SetAttribute(nameof(IsSelected), IsSelected); + helper.SetAttribute(nameof(IsExpanded), IsExpanded); //Serialize Selected models XmlDocument xmlDoc = element.OwnerDocument; @@ -711,13 +718,16 @@ protected override void DeserializeCore(XmlElement element, SaveContext context) this.textBlockHeight = helper.ReadDouble("TextblockHeight", DoubleValue); this.InitialTop = helper.ReadDouble("InitialTop", DoubleValue); this.InitialHeight = helper.ReadDouble("InitialHeight", DoubleValue); - this.IsSelected = helper.ReadBoolean(nameof(IsSelected), false); + this.IsSelected = helper.ReadBoolean(nameof(IsSelected), false); + this.IsExpanded = helper.ReadBoolean(nameof(IsExpanded), false); if (IsSelected) DynamoSelection.Instance.Selection.Add(this); else DynamoSelection.Instance.Selection.Remove(this); + + //Deserialize Selected models if (element.HasChildNodes) { @@ -756,6 +766,9 @@ protected override void DeserializeCore(XmlElement element, SaveContext context) RaisePropertyChanged(nameof(GroupStyleId)); RaisePropertyChanged(nameof(AnnotationText)); RaisePropertyChanged(nameof(Nodes)); + // ip comment: + // this is called on Undo. Is VM listening? + RaisePropertyChanged(nameof(IsExpanded)); this.ReportPosition(); } diff --git a/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs b/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs index 23ff3951986..dd481427175 100644 --- a/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs +++ b/src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs @@ -2081,6 +2081,8 @@ internal void SendModelEvent(Guid modelGuid, string eventName, int value) HasUnsavedChanges = true; } + + // ip comment : this must be called ? internal void UpdateModelValue(IEnumerable modelGuids, string propertyName, string value) { if (modelGuids == null || (!modelGuids.Any())) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index 578447dcdb7..9264d9d7ccc 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -6,9 +6,11 @@ using System.Windows.Input; using System.Windows.Media; using Dynamo.Configuration; +using Dynamo.Core; using Dynamo.Graph; using Dynamo.Graph.Annotations; using Dynamo.Graph.Nodes; +using Dynamo.Graph.Workspaces; using Dynamo.Logging; using Dynamo.Models; using Dynamo.Selection; @@ -260,6 +262,14 @@ public bool IsExpanded get => annotationModel.IsExpanded; set { + // ip code: + // before we update the value we must record the current state of the group + var undoRecorder = WorkspaceViewModel.Model.UndoRecorder; + using (undoRecorder.BeginActionGroup()) + { + undoRecorder.RecordModificationForUndo(annotationModel); + } + annotationModel.IsExpanded = value; InPorts.Clear(); OutPorts.Clear(); @@ -931,7 +941,7 @@ private void CollapseGroupContents(bool collapseConnectors) if (!collapseConnectors) return; - CollapseConnectors(); + CollapseConnectors(); Analytics.TrackEvent(Actions.Collapsed, Categories.GroupOperations); } @@ -1203,9 +1213,40 @@ private void model_PropertyChanged(object sender, System.ComponentModel.Property RaisePropertyChanged(nameof(AnnotationModel.Position)); UpdateProxyPortsPosition(); break; + + // ip code: + case nameof(IsExpanded): + UpdateAnnotationAfterUndo(); + //RaisePropertyChanged("IsExpanded"); + break; + } } + private void UpdateAnnotationAfterUndo() + //{ + // this.IsExpanded = this.annotationModel.IsExpanded; + //} + { + if (annotationModel.IsExpanded) + { + this.ShowGroupContents(); + } + + else + { + this.SetGroupInputPorts(); + this.SetGroupOutPorts(); + this.CollapseGroupContents(true); + RaisePropertyChanged(nameof(NodeContentCount)); + } + WorkspaceViewModel.HasUnsavedChanges = true; + AddGroupToGroupCommand.RaiseCanExecuteChanged(); + RaisePropertyChanged(nameof(IsExpanded)); + RedrawConnectors(); + ReportNodesPosition(); + } + private void OnModelRemovedFromGroup(object sender, EventArgs e) { Analytics.TrackEvent(Actions.RemovedFrom, Categories.GroupOperations, "Node");