Skip to content

Commit

Permalink
Don't reload tree viewmodels when they were changed from tree - the t…
Browse files Browse the repository at this point in the history
…ree state should already be consistent with configuration and it improves performance.
  • Loading branch information
dominikgolda committed May 17, 2019
1 parent 772efa3 commit 36e5a86
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class SubjectTreeViewModel : IHandleDoubleClick, IDropTarget
/// </summary>
private ObservableCollection<SubjectGroupViewModel> subjectGroups;

/// <summary>
/// Flag indicating that <see cref="ConfigurationChanged"/> event is triggered - used to ignore updates of model.
/// </summary>
private bool configurationChanging;

public event EventHandler ConfigurationChanged;

/// <summary>
Expand Down Expand Up @@ -105,7 +110,7 @@ public void Drop(IDropInfo dropInfo)
this.DropSubject(dropInfo, draggedSubject);
}

this.ConfigurationChanged?.Invoke(this, EventArgs.Empty);
this.OnConfigurationChanged(this, EventArgs.Empty);
}

/// <summary>
Expand Down Expand Up @@ -134,6 +139,11 @@ public void Init(ObservationScheduler scheduler, ApplicationConfiguration config
/// <param name="configuration">Changed configuration.</param>
public void Update(ApplicationConfiguration configuration)
{
if (this.configurationChanging)
{
return;
}

log.Debug("Initializing {name}", nameof(SubjectTreeViewModel));
var grouping = this.ParseConfiguration(configuration).ToList();
foreach (var group in grouping)
Expand Down Expand Up @@ -225,6 +235,24 @@ public void ApplyGroupExpansionState(IList<GroupExpansionSettings> groupExpansio
}
}

/// <summary>
/// Calls <see cref="ConfigurationChanged"/> event.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">Event args.</param>
protected void OnConfigurationChanged(object sender, EventArgs args)
{
try
{
this.configurationChanging = true;
this.ConfigurationChanged?.Invoke(sender, args);
}
finally
{
this.configurationChanging = false;
}
}

/// <summary>
/// Moves object given by <paramref name="source"/> to <paramref name="target"/>
/// </summary>
Expand Down

0 comments on commit 36e5a86

Please sign in to comment.