Skip to content

Commit

Permalink
Don't call ConfigurationChanged event when configuration didn't chang…
Browse files Browse the repository at this point in the history
…e (dragging had no effect).
  • Loading branch information
dominikgolda committed May 30, 2019
1 parent 5e0ddb5 commit 8cb9429
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ public void Drop(IDropInfo dropInfo)
return;
}

var changesExist = false;
if (dropInfo.Data is SubjectGroupViewModel drggedGroup)
{
this.DropGrup(dropInfo, drggedGroup);
changesExist = this.DropGrup(dropInfo, drggedGroup);
}
else if (dropInfo.Data is SubjectViewModel draggedSubject)
{
this.DropSubject(dropInfo, draggedSubject);
changesExist = this.DropSubject(dropInfo, draggedSubject);
}

this.OnConfigurationChanged(this, EventArgs.Empty);
if (changesExist)
{
this.OnConfigurationChanged(this, EventArgs.Empty);
}
}

/// <summary>
Expand Down Expand Up @@ -303,7 +307,8 @@ protected void OnConfigurationChanged(object sender, EventArgs args)
/// <param name="source">Information about source location of moved object.</param>
/// <param name="target">Information about desired location of moved object.</param>
/// <param name="insertPosition">Additional information about where in relation to <paramref name="target"/> the object should be placed.</param>
private static void MoveObject(MovedObjectLocation source, MovedObjectLocation target, RelativeInsertPosition insertPosition)
/// <returns>True if operation caused changes; false otherwise.</returns>
private static bool MoveObject(MovedObjectLocation source, MovedObjectLocation target, RelativeInsertPosition insertPosition)
{
var insertPositionInternal = insertPosition;
if ((insertPositionInternal & RelativeInsertPosition.TargetItemCenter) != 0)
Expand All @@ -326,13 +331,15 @@ private static void MoveObject(MovedObjectLocation source, MovedObjectLocation t

if (source.Index == targetIndex)
{
return;
return false;
}
}

var obj = source.List[source.Index];
source.List.RemoveAt(source.Index);
target.List.Insert(targetIndex, obj);

return true;
}

private IEnumerable<IGrouping<string, SubjectConfiguration>> ParseConfiguration(ApplicationConfiguration configuration)
Expand All @@ -345,39 +352,45 @@ private IEnumerable<IGrouping<string, SubjectConfiguration>> ParseConfiguration(
/// </summary>
/// <param name="dropInfo">All drop information.</param>
/// <param name="droppedSubject">The dropped subject.</param>
private void DropSubject(IDropInfo dropInfo, SubjectViewModel droppedSubject)
/// <returns>True if operation caused changes; false otherwise.</returns>
private bool DropSubject(IDropInfo dropInfo, SubjectViewModel droppedSubject)
{
var currentSubjectGroupModel = this.GetSubjectGroup(droppedSubject);
if (dropInfo.TargetItem is SubjectGroupViewModel model)
{
if (object.ReferenceEquals(currentSubjectGroupModel.List, model.SubjectViewModels))
{
return;
return false;
}

MoveObject(currentSubjectGroupModel, new MovedObjectLocation(model.SubjectViewModels, model.SubjectViewModels.Count - 1), RelativeInsertPosition.AfterTargetItem);
return MoveObject(currentSubjectGroupModel, new MovedObjectLocation(model.SubjectViewModels, model.SubjectViewModels.Count - 1), RelativeInsertPosition.AfterTargetItem);
}

if (dropInfo.TargetItem is SubjectViewModel targetModel)
{
var targetGroup = this.GetSubjectGroup(targetModel);
MoveObject(currentSubjectGroupModel, targetGroup, dropInfo.InsertPosition);
return MoveObject(currentSubjectGroupModel, targetGroup, dropInfo.InsertPosition);
}

return false;
}

/// <summary>
/// Handles dropping of <see cref="SubjectGroupViewModel"/>.
/// </summary>
/// <param name="dropInfo">All drop information.</param>.
/// <param name="droppedGroup">The dropped group.</param>
private void DropGrup(IDropInfo dropInfo, SubjectGroupViewModel droppedGroup)
/// <returns>True if operation caused changes; false otherwise.</returns>
private bool DropGrup(IDropInfo dropInfo, SubjectGroupViewModel droppedGroup)
{
if (dropInfo.TargetItem is SubjectGroupViewModel targetModel)
{
var index = this.SubjectGroups.IndexOf(droppedGroup);
var targetIndex = this.SubjectGroups.IndexOf(targetModel);
MoveObject(new MovedObjectLocation(this.SubjectGroups, index), new MovedObjectLocation(this.SubjectGroups, targetIndex), dropInfo.InsertPosition);
return MoveObject(new MovedObjectLocation(this.SubjectGroups, index), new MovedObjectLocation(this.SubjectGroups, targetIndex), dropInfo.InsertPosition);
}

return false;
}

/// <summary>
Expand Down

0 comments on commit 8cb9429

Please sign in to comment.