From 4824298cc9f66f9c697f72057ae68230f7efd13c Mon Sep 17 00:00:00 2001 From: Ivo Petrov <48355182+ivaylo-matov@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:36:42 +0100 Subject: [PATCH] draft - clean code working --- .../ViewModels/Core/AnnotationViewModel.cs | 82 ++++++++----------- .../Views/Core/AnnotationView.xaml.cs | 4 +- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs index 9264d9d7ccc..1b48f94ad2d 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs @@ -262,8 +262,10 @@ 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()) { @@ -271,24 +273,9 @@ public bool IsExpanded } 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(); } } @@ -1061,6 +1048,32 @@ private void UpdateConnectorsAndPortsOnShowContents(IEnumerable nodes } } + + /// + /// Handles the expansion or collapse of the annotation group in the view model. + /// + 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; @@ -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"); diff --git a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs index e11e93d31fb..e7787d6cd57 100644 --- a/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs +++ b/src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -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))