aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
index 7ecc74c10..90e404307 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
@@ -12,6 +12,9 @@ using Tango.Core.Commands;
using System.Windows;
using Tango.Touch.Controls;
using System.Windows.Media;
+using Tango.DragAndDrop;
+using System.ComponentModel;
+using System.Windows.Data;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -35,6 +38,20 @@ namespace Tango.PPC.Jobs.ViewModels
set { _job = value; RaisePropertyChangedAuto(); }
}
+ private ICollectionView _segmentsCollectionView;
+ /// <summary>
+ /// Gets or sets the job segments collection view.
+ /// </summary>
+ public ICollectionView SegmentsCollectionView
+ {
+ get { return _segmentsCollectionView; }
+ set
+ {
+ _segmentsCollectionView = value;
+ RaisePropertyChangedAuto();
+ }
+ }
+
private List<ColorSpace> _colorSpaces;
/// <summary>
/// Gets or sets the available color spaces.
@@ -109,6 +126,11 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
public RelayCommand<Segment> AddBrushStopCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the segment dropped command.
+ /// </summary>
+ public RelayCommand<DropEventArgs> SegmentDroppedCommand { get; set; }
+
#endregion
#region Constructors
@@ -129,6 +151,12 @@ namespace Tango.PPC.Jobs.ViewModels
AddSolidSegmentCommand = new RelayCommand(() => AddSolidSegment());
AddBrushStopCommand = new RelayCommand<Segment>(AddBrushStop);
AddGradientSegmentCommand = new RelayCommand(() => AddGradientSegment());
+ SegmentDroppedCommand = new RelayCommand<DropEventArgs>((e) =>
+ {
+ DragAndDropSegment(
+ (e.Draggable as FrameworkElement).DataContext as Segment,
+ (e.Droppable as FrameworkElement).DataContext as Segment);
+ });
}
#endregion
@@ -151,6 +179,32 @@ namespace Tango.PPC.Jobs.ViewModels
return Job.AddGradientSegment();
}
+ /// <summary>
+ /// Called when a segment has been dragged and dropped into another segment.
+ /// </summary>
+ /// <param name="draggedJob">The dragged job.</param>
+ /// <param name="droppedJob">The dropped job.</param>
+ private void DragAndDropSegment(Segment draggedSegment, Segment droppedSegment)
+ {
+ if (draggedSegment.SegmentIndex > droppedSegment.SegmentIndex)
+ {
+ draggedSegment.SegmentIndex = droppedSegment.SegmentIndex - 1;
+ }
+ else
+ {
+ draggedSegment.SegmentIndex = droppedSegment.SegmentIndex + 1;
+ }
+
+ int index = 1;
+
+ foreach (var segment in Job.Segments.OrderBy(x => x.SegmentIndex))
+ {
+ segment.SegmentIndex = index++;
+ }
+
+ SegmentsCollectionView.Refresh();
+ }
+
#endregion
#region Brush Stops Management
@@ -185,6 +239,9 @@ namespace Tango.PPC.Jobs.ViewModels
ColorSpaces = _db.ColorSpaces.ToList();
SpoolTypes = _db.SpoolTypes.ToList();
Customers = _db.Customers.Where(x => x.OrganizationGuid == Job.Machine.Organization.Guid).ToList();
+
+ SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments);
+ SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending));
}
#endregion