Skip to content

Commit

Permalink
undo expand/collapse
Browse files Browse the repository at this point in the history
first draft - works but needs cleaning
  • Loading branch information
ivaylo-matov committed Apr 17, 2024
1 parent ec08a19 commit 2158ef1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/DynamoCore/Core/UndoRedoRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
Expand Down
17 changes: 15 additions & 2 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ public double TextBlockHeight
}
}


private double textMaxWidth;
/// <summary>
/// Returns the maxWidth of text area of the group
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid> modelGuids, string propertyName, string value)
{
if (modelGuids == null || (!modelGuids.Any()))
Expand Down
43 changes: 42 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -931,7 +941,7 @@ private void CollapseGroupContents(bool collapseConnectors)

if (!collapseConnectors) return;

CollapseConnectors();
CollapseConnectors();

Analytics.TrackEvent(Actions.Collapsed, Categories.GroupOperations);
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 2158ef1

Please sign in to comment.