aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/CopySegmentCommand.cs
blob: a041ee6404b6b3e32e32ae365fbc9c616c91693b (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Logging;
using Tango.PPC.Jobs.Models;

namespace Tango.PPC.Jobs.UndoRedoCommands
{
    public class CopySegmentCommand : IUndoRedoCommand
    {
        private JobModel _jobModel;
       
        public CopySegmentCommand(JobModel jobModel)
        {
            _jobModel = jobModel;
        }
        public void Execute()
        {
            List<ISegmentModel> SegmentsToCopy = new List<ISegmentModel>(_jobModel.SegmentsToCopy);
            SegmentsToCopy.Clear();

            if (false == _jobModel.Segments.ToList().Any(x => x.IsSelected))
                return;
            //LogManager.Log("Copy selected segments.");
            int indexToPasteCopySegments = -1;

            foreach (var segment in _jobModel.GroupingSegments.Where(i => i.IsSelected).ToList())
            {
                //segment.IsSelected = false;
                SegmentsToCopy.Add(segment.Clone());
                var index = _jobModel.GroupingSegments.ToList().IndexOf(segment);
                indexToPasteCopySegments = index > indexToPasteCopySegments? index: indexToPasteCopySegments;
                
            }
            _jobModel.SegmentsToCopy = SegmentsToCopy;
            _jobModel.IndexToPasteCopySegments = indexToPasteCopySegments;
        }

        public void UnExecute()
        {
            _jobModel.SegmentsToCopy= new List<ISegmentModel>();
        }
    }
}