Пример #1
0
        public void RemoveAt(int index)
        {
            Script scriptToRemove = null;
              Brick brickToRemove = null;

              int count = 0;
              foreach (Script script in scripts)
              {
            if (count == index)
            {
              scriptToRemove = script;
              break;
            }

            count++;
            foreach (Brick brick in script.Bricks.Bricks)
            {
              if (count == index)
              {
            scriptToRemove = script;
            brickToRemove = brick;

            lastDeletedBrick = brick;
            lastDeletedIndex = index;

            break;
              }

              count++;
            }

            if (brickToRemove != null)
              break;
              }

              if (brickToRemove == null)
              {
            scripts.Remove(scriptToRemove);

            OnScriptRemoved(scriptToRemove, index);

              }
              else
              {
            if (scriptToRemove != null)
            {
              scriptToRemove.Bricks.Bricks.Remove(brickToRemove);
              OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, brickToRemove, index));
            }
              }
        }
Пример #2
0
        public void Insert(int index, object value)
        {
            if (PreventIsertOfNext != null && PreventIsertOfNext == value)
              {
            PreventIsertOfNext = null;
            return;
              }

              int count = 0;

              if (value is Script) // TODO: test me
              {
            int scriptIndex = 0;

            foreach (Script script in scripts)
            {
              if (count > index)
            break;

              count += script.Bricks.Bricks.Count + 1;
              scriptIndex++;
            }

            scripts.Insert(scriptIndex, (Script)value);
            OnScriptAdded((Script)value, count + 1);
              }

              if (value is Brick)
              {
            int brickCount = 0;
            lastInsertedBrick = (Brick)value;
            lastInsertedIndex = index;

            if (index == 0) // Cannot insert brick before first sprite
              index = 1;

            foreach (Script script in scripts)
            {
              count++;
              foreach (Brick brick in script.Bricks.Bricks)
              {
            if (count == index)
            {
              script.Bricks.Bricks.Insert(brickCount, (Brick)value);
              OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, value, index));
              return;
            }

            count++;
            brickCount++;
              }

              if (count == index)
              {
            script.Bricks.Bricks.Insert(brickCount, (Brick)value);
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, value, index));
            return;
              }

              brickCount = 0;
            }
              }
        }