Skip to content

Commit

Permalink
draft - clean code working
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov committed Apr 17, 2024
1 parent 2158ef1 commit 4824298
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 47 deletions.
82 changes: 36 additions & 46 deletions src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,33 +262,20 @@ public bool IsExpanded
get => annotationModel.IsExpanded;
set
{
// ip code:
// before we update the value we must record the current state of the group
// This change is triggered by the user interaction in the View.
// Before we updating the value in the Model and ViewModel
// we record the current state in the UndoRedoStack.
// This ensures that any modifications can be reverted by the user.
var undoRecorder = WorkspaceViewModel.Model.UndoRecorder;
using (undoRecorder.BeginActionGroup())
{
undoRecorder.RecordModificationForUndo(annotationModel);
}

annotationModel.IsExpanded = value;
InPorts.Clear();
OutPorts.Clear();
if (value)
{
this.ShowGroupContents();
}
else
{
this.SetGroupInputPorts();
this.SetGroupOutPorts();
this.CollapseGroupContents(true);
RaisePropertyChanged(nameof(NodeContentCount));
}
WorkspaceViewModel.HasUnsavedChanges = true;
AddGroupToGroupCommand.RaiseCanExecuteChanged();
RaisePropertyChanged(nameof(IsExpanded));
RedrawConnectors();
ReportNodesPosition();

// Methods to collapse or expand the group based on the new value of IsExpanded.
ManageAnnotationMVExpansionAndCollapse();
}
}

Expand Down Expand Up @@ -1061,6 +1048,32 @@ private void UpdateConnectorsAndPortsOnShowContents(IEnumerable<ModelBase> nodes
}
}


/// <summary>
/// Handles the expansion or collapse of the annotation group in the view model.
/// </summary>
private void ManageAnnotationMVExpansionAndCollapse()
{
InPorts.Clear();
OutPorts.Clear();
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 UpdateFontSize(object parameter)
{
if (parameter == null) return;
Expand Down Expand Up @@ -1216,37 +1229,14 @@ private void model_PropertyChanged(object sender, System.ComponentModel.Property

// ip code:
case nameof(IsExpanded):
UpdateAnnotationAfterUndo();
//UpdateAnnotationAfterUndo();
ManageAnnotationMVExpansionAndCollapse();
//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
4 changes: 3 additions & 1 deletion src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand Down Expand Up @@ -115,6 +115,8 @@ private void SetTextMaxWidth()
this.ViewModel.AnnotationModel.TextMaxWidth = formattedText.Width + margin;
}


// ip comment: maybe use this logic for IsExpanded
private void OnNodeColorSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems == null || (e.AddedItems.Count <= 0))
Expand Down

0 comments on commit 4824298

Please sign in to comment.