Skip to content

Commit

Permalink
Application.Current removed (#71)
Browse files Browse the repository at this point in the history
* Application.Current removed

seems to work with Civils 3D

* Update TuneUpWindowViewModel.cs
  • Loading branch information
ivaylo-matov authored Oct 28, 2024
1 parent 041d190 commit 2731d1c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class TuneUpWindowViewModel : NotificationObject, IDisposable
private Dictionary<Guid, ProfiledNodeViewModel> groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
// Maps AnnotationModel GUIDs to a list of associated ProfiledNodeViewModel instances.
private Dictionary<Guid, List<ProfiledNodeViewModel>> groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();
private Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource>();

private HomeWorkspaceModel CurrentWorkspace
{
Expand Down Expand Up @@ -320,6 +321,12 @@ internal void ResetProfiledNodes()
ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection<ProfiledNodeViewModel>();

collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> {
{ ProfiledNodesLatestRun, ProfiledNodesCollectionLatestRun },
{ProfiledNodesPreviousRun, ProfiledNodesCollectionPreviousRun },
{ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted }
};

nodeDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();
Expand Down Expand Up @@ -546,7 +553,7 @@ private void CalculateGroupNodes()
groupDictionary[pGroup.NodeGUID] = pGroup;
groupModelDictionary[pNode.GroupGUID].Add(pGroup);

System.Windows.Application.Current.Dispatcher.Invoke(() =>
ProfiledNodesCollectionLatestRun.Dispatcher.Invoke(() =>
{
ProfiledNodesNotExecuted.Add(pGroup);
});
Expand Down Expand Up @@ -612,7 +619,7 @@ private void CreateGroupNodesForCollection(ObservableCollection<ProfiledNodeView
// Create an register a new time node
var timeNode = CreateAndRegisterGroupTimeNode(pGroup);

System.Windows.Application.Current.Dispatcher.Invoke(() =>
GetCollectionViewSource(collection).Dispatcher.Invoke(() =>
{
collection.Add(timeNode);
collection.Add(pGroup);
Expand Down Expand Up @@ -1030,6 +1037,14 @@ private void UpdateTableVisibility()
RaisePropertyChanged(nameof(NotExecutedTableVisibility));
}

/// <summary>
/// Returns the corresponding CollectionViewSource for the given ObservableCollection of ProfiledNodeViewModel.
/// </summary>
internal CollectionViewSource GetCollectionViewSource(ObservableCollection<ProfiledNodeViewModel> collection)
{
return collectionMapping.TryGetValue(collection, out var collectionViewSource) ? collectionViewSource : null;
}

/// <summary>
/// Resets group-related properties of the node and unregisters it from the group model dictionary.
/// </summary>
Expand Down Expand Up @@ -1267,7 +1282,7 @@ private void SortCollectionViewForProfiledNodesCollection(ObservableCollection<P
/// </summary>
private void MoveNodeToCollection(ProfiledNodeViewModel profiledNode, ObservableCollection<ProfiledNodeViewModel> targetCollection)
{
System.Windows.Application.Current.Dispatcher.Invoke(() =>
GetCollectionViewSource(targetCollection).Dispatcher.Invoke(() =>
{
var collections = new[]
{
Expand All @@ -1292,7 +1307,7 @@ private void RemoveNodeFromStateCollection(ProfiledNodeViewModel pNode, Profiled
{
var collection = GetObservableCollectionFromState(state);

System.Windows.Application.Current.Dispatcher.Invoke(() =>
GetCollectionViewSource(collection).Dispatcher.Invoke(() =>
{
collection?.Remove(pNode);
});
Expand Down

0 comments on commit 2731d1c

Please sign in to comment.