-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileDropHandler.cs
61 lines (47 loc) · 1.68 KB
/
ProfileDropHandler.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using GongSolutions.Wpf.DragDrop;
using System.Windows;
namespace Elite_Dangerous_Addon_Launcher_V2
{
public class ProfileDropHandler : IDropTarget
{
#region Private Fields
private Profile _profile;
#endregion Private Fields
#region Public Constructors
public ProfileDropHandler(Profile profile)
{
_profile = profile;
}
#endregion Public Constructors
#region Public Methods
public void DragOver(IDropInfo dropInfo)
{
var sourceItem = dropInfo.Data as MyApp;
var targetItem = dropInfo.TargetItem as MyApp;
if (sourceItem != null && targetItem != null)
{
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
dropInfo.Effects = DragDropEffects.Move;
}
}
public void Drop(IDropInfo dropInfo)
{
var sourceItem = dropInfo.Data as MyApp;
var targetItem = dropInfo.TargetItem as MyApp;
if (sourceItem != null && targetItem != null)
{
int sourceIndex = _profile.Apps.IndexOf(sourceItem);
int targetIndex = _profile.Apps.IndexOf(targetItem);
// Remove and insert the source item at the correct location
_profile.Apps.RemoveAt(sourceIndex);
_profile.Apps.Insert(targetIndex, sourceItem);
// Update the order property of all apps
for (int i = 0; i < _profile.Apps.Count; i++)
{
_profile.Apps[i].Order = i;
}
}
}
#endregion Public Methods
}
}