Ejemplo n.º 1
0
        public override void Execute()
        {
            // Queue objects sent to back
            Dictionary <int, ObjectInstance> backMap = new Dictionary <int, ObjectInstance>();

            foreach (ObjectInstance inst in _toBack)
            {
                backMap.Add(_objectSource.ObjectIndex(inst), inst);
            }

            List <int> backKeys = new List <int>(backMap.Keys);

            backKeys.Sort();

            foreach (ObjectRecord record in _objects)
            {
                record.NewIndex += backKeys.Count;
            }

            for (int i = 0; i < backKeys.Count; i++)
            {
                _objects.Add(new ObjectRecord()
                {
                    Instance  = backMap[backKeys[i]],
                    PrevIndex = backKeys[i],
                    NewIndex  = i,
                });
            }

            // Sort objects moved relatively
            _objects.Sort((u, v) => {
                return(u.PrevIndex.CompareTo(v.PrevIndex));
            });

            // Queue objects sent to front
            Dictionary <int, ObjectInstance> frontMap = new Dictionary <int, ObjectInstance>();

            foreach (ObjectInstance inst in _toFront)
            {
                frontMap.Add(_objectSource.ObjectIndex(inst), inst);
            }

            List <int> frontKeys = new List <int>(frontMap.Keys);

            frontKeys.Sort();

            for (int i = 0; i < frontKeys.Count; i++)
            {
                _objects.Add(new ObjectRecord()
                {
                    Instance  = frontMap[frontKeys[i]],
                    PrevIndex = frontKeys[i],
                    NewIndex  = _objectSource.ObjectCount - 1,
                });
            }

            // Execute command
            foreach (ObjectRecord record in _objects)
            {
                _objectSource.MoveToIndex(record.Instance, record.NewIndex);
            }
        }