forked from apple1417/bagpipe
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfileDropHandler.cs
More file actions
36 lines (31 loc) · 1 KB
/
ProfileDropHandler.cs
File metadata and controls
36 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using GongSolutions.Wpf.DragDrop;
using System.Linq;
namespace bagpipe {
class ProfileDropHandler : DefaultDropHandler {
private readonly Profile profile;
private readonly ProfileViewModel profileVM;
public ProfileDropHandler(Profile profile, ProfileViewModel profileVM) {
this.profile = profile;
this.profileVM = profileVM;
}
public override void Drop(IDropInfo dropInfo) {
if (dropInfo?.DragInfo == null) {
return;
}
int insertIndex = GetInsertIndex(dropInfo);
IOrderedEnumerable<ProfileEntryViewModel> selectedItems = (
ExtractData(dropInfo.Data)
.Cast<ProfileEntryViewModel>()
.OrderBy(entryVM => profileVM.Entries.IndexOf(entryVM))
);
foreach (ProfileEntryViewModel entryVM in selectedItems) {
int index = profileVM.Entries.IndexOf(entryVM);
if (insertIndex > index) {
insertIndex--;
}
profile.Entries.Move(index, insertIndex);
insertIndex++;
}
}
}
}