Exemple #1
0
        /// <summary>
        /// Adds a part to the part order (can be undone).
        /// </summary>
        /// <param name="part">The part to add.</param>
        /// <param name="index">The index where to insert it in the order. If omitted, append at the end.</param>
        /// <returns>A reference to the part in the order.</returns>
        public SongPartReference AddPartToOrder(SongPart part, int index = -1)
        {
            if (Parts.IndexOf(part) < 0)
            {
                throw new ArgumentException("part has not been added to this song");
            }

            SongPartReference reference = null;

            Action redo = () =>
            {
                if (index < 0)
                {
                    index = Order.Count;
                }

                reference = new SongPartReference(part);
                order.Insert(index, reference);
            };
            Action undo = () =>
            {
                order.RemoveAt(index);
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "AddPartToOrder");

            redo();

            return(reference);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SongPartReference"/> class.
        /// </summary>
        /// <param name="part">The referenced part.</param>
        public SongPartReference(SongPart part)
        {
            if (part == null)
                throw new ArgumentNullException("part");

            this.root = part.Root;
            this.part = part;
        }
Exemple #3
0
        /// <summary>
        /// Moves a slide to another part (can be undone).
        /// </summary>
        /// <param name="slide">The slide to move.</param>
        /// <param name="target">The target part.</param>
        public void MoveSlide(SongSlide slide, SongPart target)
        {
            var part = FindPartWithSlide(slide);

            using (Undo.ChangeFactory.Batch(this, "MoveSlide"))
            {
                part.RemoveSlide(slide);
                target.AddSlide(slide);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SongPartReference"/> class.
        /// </summary>
        /// <param name="part">The referenced part.</param>
        public SongPartReference(SongPart part)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }

            this.root = part.Root;
            this.part = part;
        }
 public RenamePartWindow(Song song, SongPart part)
 {
     InitializeComponent();
     this.song = song;
     this.part = part;
     this.DataContext = this;
     if (this.part != null)
     {
         this.PartName = this.part.Name;
     }
 }
Exemple #6
0
        /// <summary>
        /// Adds a new part with an empty slide to the song (can be undone).
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>The added part.</returns>
        public SongPart AddPart(string name)
        {
            SongPart newPart;

            using (Undo.ChangeFactory.Batch(this, "AddPart"))
            {
                newPart = new SongPart(this, name, new SongSlide[] { new SongSlide(this) });
                AddPart(newPart);
            }

            return(newPart);
        }
Exemple #7
0
        /// <summary>
        /// Copies a specified part and inserts the copy at the index of a target part.
        /// </summary>
        /// <param name="source">The part to copy.</param>
        /// <param name="name">The name that will be given to the copy.</param>
        /// <param name="target">The target position.</param>
        /// <returns>The created copy.</returns>
        public SongPart CopyPart(SongPart source, string name, SongPart target)
        {
            SongPart newPart;

            using (Undo.ChangeFactory.Batch(this, "CopyPart"))
            {
                newPart = source.Copy(name);
                AddPart(newPart);
                MovePart(newPart, target);
            }
            return(newPart);
        }
Exemple #8
0
        /// <summary>
        /// Copies the specified slide into a given part.
        /// The copy will be appended to the part's slide list
        /// (can be undone).
        /// </summary>
        /// <param name="slide">The slide to copy.</param>
        /// <param name="target">The part where the copy will be inserted.</param>
        /// <returns>The copy.</returns>
        public SongSlide CopySlide(SongSlide slide, SongPart target)
        {
            SongSlide s;
            var       part = FindPartWithSlide(slide);

            using (Undo.ChangeFactory.Batch(this, "CopySlide"))
            {
                s = slide.Copy();
                target.AddSlide(s);
            }

            return(s);
        }
Exemple #9
0
        /// <summary>
        /// Adds a part to the song (can be undone).
        /// </summary>
        /// <param name="part">The part to add.</param>
        public void AddPart(SongPart part)
        {
            Action undo = () =>
            {
                parts.Remove(part);
            };

            Action redo = () =>
            {
                parts.Add(part);
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "AddPart");

            redo();
        }
Exemple #10
0
        /// <summary>
        /// Removes a part from the song (can be undone).
        /// </summary>
        /// <param name="part">The part to remove.</param>
        public void RemovePart(SongPart part)
        {
            int i = Parts.IndexOf(part);

            SongPartReference[] backup = Order.ToArray();

            Action redo = () =>
            {
                //bool notify = false;
                SongPartReference pRef;

                while ((pRef = Order.Where(partRef => partRef.Part == part).FirstOrDefault()) != null)
                {
                    //if (!notify)
                    //{
                    //	OnPropertyChanging("Order");
                    //	notify = true;
                    //}
                    order.Remove(pRef);
                }

                //if (notify)
                //	OnPropertyChanged("Order");

                parts.Remove(part);
            };

            Action undo = () =>
            {
                if (i == Parts.Count && i != 0)
                {
                    i--;
                }

                parts.Insert(i, part);
                SetOrder(backup);
                //OnPropertyChanged("Order");
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "RemovePart");

            redo();
        }
Exemple #11
0
        public void AddPartToOrderUndoRedo()
        {
            var part1 = new SongPart(song, "NewPart1", new SongSlide[] { new SongSlide(song) });
            var part2 = new SongPart(song, "NewPart2", new SongSlide[] { new SongSlide(song) });
            song.AddPart(part1);
            song.AddPart(part2);
            ClearUndoRedoStack();

            song.AddPartToOrder(part1);
            Assert.Equal(2, song.Order.Count);
            Assert.Equal("NewPart1", song.Order[1].Part.Name);
            song.AddPartToOrder(part2, 0);
            Assert.Equal(3, song.Order.Count);
            Assert.Equal("NewPart2", song.Order[0].Part.Name);
            Assert.Equal("NewPart1", song.Order[2].Part.Name);
            Assert.Equal(2, UndoStackSize);
            Undo();
            Assert.Equal("NewPart1", song.Order[1].Part.Name);
            Redo();
            Assert.Equal(3, song.Order.Count);
        }
Exemple #12
0
        /// <summary>
        /// Moves a part to the index of another one in the song structure (can be undone).
        /// </summary>
        /// <param name="part">The part to move.</param>
        /// <param name="target">
        /// The target part position where it will be moved to.
        /// If it was before the target, move it directly after the target,
        /// otherwise move it directly before the target.
        /// </param>
        public void MovePart(SongPart part, SongPart target)
        {
            if (part == target)
            {
                return;
            }

            int originalIndex = Parts.IndexOf(part);
            int newIndex      = Parts.IndexOf(target);

            Action redo = () =>
            {
                parts.Move(originalIndex, newIndex);
            };

            Action undo = () =>
            {
                parts.Move(newIndex, originalIndex);
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "MovePart");

            redo();
        }
Exemple #13
0
		/// <summary>
		/// Adds a part to the part order (can be undone).
		/// </summary>
		/// <param name="part">The part to add.</param>
		/// <param name="index">The index where to insert it in the order. If omitted, append at the end.</param>
		/// <returns>A reference to the part in the order.</returns>
		public SongPartReference AddPartToOrder(SongPart part, int index = -1)
		{
			if (Parts.IndexOf(part) < 0)
				throw new ArgumentException("part has not been added to this song");

			SongPartReference reference = null;

			Action redo = () =>
			{
				if (index < 0)
					index = Order.Count;

				reference = new SongPartReference(part);
				order.Insert(index, reference);
			};
			Action undo = () =>
			{
				order.RemoveAt(index);
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "AddPartToOrder");

			redo();

			return reference;
		}
Exemple #14
0
		/// <summary>
		/// Copies the specified slide into a given part.
		/// The copy will be appended to the part's slide list
		/// (can be undone).
		/// </summary>
		/// <param name="slide">The slide to copy.</param>
		/// <param name="target">The part where the copy will be inserted.</param>
		/// <returns>The copy.</returns>
		public SongSlide CopySlide(SongSlide slide, SongPart target)
		{
			SongSlide s;
			var part = FindPartWithSlide(slide);

			using (Undo.ChangeFactory.Batch(this, "CopySlide"))
			{
				s = slide.Copy();
				target.AddSlide(s);
			}

			return s;
		}
Exemple #15
0
		/// <summary>
		/// Moves a slide to another part (can be undone).
		/// </summary>
		/// <param name="slide">The slide to move.</param>
		/// <param name="target">The target part.</param>
		public void MoveSlide(SongSlide slide, SongPart target)
		{
			var part = FindPartWithSlide(slide);

			using (Undo.ChangeFactory.Batch(this, "MoveSlide"))
			{
				part.RemoveSlide(slide);
				target.AddSlide(slide);
			}
		}
Exemple #16
0
        public void SetBackgroundUndoRedo()
        {
            var part1 = new SongPart(song, "NewPart1", new SongSlide[] { new SongSlide(song) });
            song.AddPart(part1);
            part1.SetBackground(new SongBackground(System.Drawing.Color.Red));
            ClearUndoRedoStack();

            Assert.Equal(System.Drawing.Color.Black.ToArgb(), song.Parts[0].Slides.Single().Background.Color.ToArgb());
            Assert.Equal(System.Drawing.Color.Red.ToArgb(), song.Parts[1].Slides.Single().Background.Color.ToArgb());
            song.SetBackground(new SongBackground(System.Drawing.Color.Green));
            Assert.Equal(System.Drawing.Color.Green.ToArgb(), song.Backgrounds.Single().Color.ToArgb());
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Equal(System.Drawing.Color.Black.ToArgb(), song.Parts[0].Slides.Single().Background.Color.ToArgb());
            Assert.Equal(System.Drawing.Color.Red.ToArgb(), song.Parts[1].Slides.Single().Background.Color.ToArgb());
            Redo();
            Assert.Equal(System.Drawing.Color.Green.ToArgb(), song.Backgrounds.Single().Color.ToArgb());
        }
Exemple #17
0
 public void RemovePartFromOrder()
 {
     var part0 = song.Parts.Single();
     var part1 = new SongPart(song, "NewPart1", new SongSlide[] { new SongSlide(song) });
     song.AddPart(part1);
     var reference = song.AddPartToOrder(part1);
     ClearUndoRedoStack();
     song.RemovePartFromOrder(song.Order[0]);
     Assert.Equal(1, song.Order.Count);
     Assert.Same(reference, song.Order[0]);
 }
Exemple #18
0
        public void MovePartInOrderUndoRedo()
        {
            var part1 = new SongPart(song, "NewPart1", new SongSlide[] { new SongSlide(song) });
            var part2 = new SongPart(song, "NewPart2", new SongSlide[] { new SongSlide(song) });
            song.AddPart(part1);
            song.AddPart(part2);
            var ref1 = song.AddPartToOrder(part1);
            var ref2 = song.AddPartToOrder(part2);
            var ref3 = song.AddPartToOrder(part2);
            ClearUndoRedoStack();

            song.MovePartInOrder(ref2, 0); // move part2 to beginning
            Assert.Same(part2, song.Order[0].Part);
            Assert.Same(ref2, song.Order[0]);
            Assert.Same(ref3, song.Order[3]);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Same(ref2, song.Order[2]);
            Assert.Same(ref3, song.Order[3]);
            Redo();
            Assert.Same(ref2, song.Order[0]);
        }
 public override void Init()
 {
     base.Init();
     part = song.Parts.Single();
     slide = part.Slides.Single();
 }
 private void AddSlide(SongPart part)
 {
     this.StructureTree.SelectItem(part.AddSlide());
 }
 /// <summary>
 /// Show a dialog to prompt for a new name for a part.
 /// </summary>
 /// <param name="part">The part to rename or <c>null</c> to prompt for a name for a new part.</param>
 /// <returns>The window.</returns>
 private RenamePartWindow ShowRenamePartDialog(SongPart part)
 {
     RenamePartWindow win = new RenamePartWindow(song, part);
     win.Owner = parent;
     win.ShowDialog();
     return win;
 }
Exemple #22
0
		/// <summary>
		/// Removes a part from the song (can be undone).
		/// </summary>
		/// <param name="part">The part to remove.</param>
		public void RemovePart(SongPart part)
		{
			int i = Parts.IndexOf(part);
			SongPartReference[] backup = Order.ToArray();

			Action redo = () =>
			{
				//bool notify = false;
				SongPartReference pRef;

				while ((pRef = Order.Where(partRef => partRef.Part == part).FirstOrDefault()) != null)
				{
					//if (!notify)
					//{
					//	OnPropertyChanging("Order");
					//	notify = true;
					//}
					order.Remove(pRef);
				}

				//if (notify)
				//	OnPropertyChanged("Order");

				parts.Remove(part);
			};

			Action undo = () =>
			{
				if (i == Parts.Count && i != 0)
					i--;

				parts.Insert(i, part);
				SetOrder(backup);
				//OnPropertyChanged("Order");
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "RemovePart");

			redo();
		}
Exemple #23
0
        public void CopySlideUndoRedo()
        {
            var part0 = song.Parts.Single();
            var slide = new SongSlide(song);
            var part1 = new SongPart(song, "NewPart", new SongSlide[] { slide });
            song.AddPart(part1);
            ClearUndoRedoStack();

            song.CopySlide(part0.Slides.Single(), part1);
            Assert.Equal(2, part1.Slides.Count);
            Assert.Equal("SimpleLine", part1.Slides[1].Text);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Same(slide, part1.Slides.Single());
            Redo();
            Assert.Equal(2, part1.Slides.Count);
            Assert.Equal(1, part0.Slides.Count);
        }
Exemple #24
0
		/// <summary>
		/// Adds a part to the song (can be undone).
		/// </summary>
		/// <param name="part">The part to add.</param>
		public void AddPart(SongPart part)
		{
			Action undo = () =>
			{
				parts.Remove(part);
			};

			Action redo = () =>
			{
				parts.Add(part);
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "AddPart");

			redo();
		}
Exemple #25
0
        public void MoveSlideAfter()
        {
            var part1 = song.Parts.Single();
            var slide0 = part1.Slides.Single();
            var slide1 = part1.AddSlide();
            var slide2 = new SongSlide(song);
            var part2 = new SongPart(song, "NewPart", new SongSlide[] { slide2 });
            song.AddPart(part2);
            ClearUndoRedoStack();

            song.MoveSlideAfter(slide0, slide2);
            Assert.Equal(1, part1.Slides.Count);
            Assert.Equal(2, part2.Slides.Count);
            Assert.Same(slide0, part2.Slides[1]);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Equal(2, part1.Slides.Count);
            Assert.Equal(1, part2.Slides.Count);
        }
Exemple #26
0
		/// <summary>
		/// Adds a new part with an empty slide to the song (can be undone).
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns>The added part.</returns>
		public SongPart AddPart(string name)
		{
			SongPart newPart;
			using (Undo.ChangeFactory.Batch(this, "AddPart"))
			{
				newPart = new SongPart(this, name, new SongSlide[] { new SongSlide(this) });
				AddPart(newPart);
			}

			return newPart;
		}
Exemple #27
0
        public void RemovePartUndoRedo2()
        {
            var part1 = new SongPart(song, "NewPart1", new SongSlide[] { new SongSlide(song) });
            song.AddPart(part1);
            var reference = song.AddPartToOrder(part1);
            ClearUndoRedoStack();

            Assert.Same(reference, song.Order[1]);
            Assert.Equal(2, song.Order.Count);
            song.RemovePart(part1);
            Assert.Equal(1, song.Parts.Count);
            Assert.Equal(1, song.Order.Count);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Same(reference, song.Order[1]);
            Assert.Equal(2, song.Order.Count);
            Redo();
            Assert.Equal(1, song.Parts.Count);
        }
Exemple #28
0
		/// <summary>
		/// Moves a part to the index of another one in the song structure (can be undone).
		/// </summary>
		/// <param name="part">The part to move.</param>
		/// <param name="target">
		/// The target part position where it will be moved to.
		/// If it was before the target, move it directly after the target,
		/// otherwise move it directly before the target.
		/// </param>
		public void MovePart(SongPart part, SongPart target)
		{
			if (part == target)
				return;

			int originalIndex = Parts.IndexOf(part);
			int newIndex = Parts.IndexOf(target);

			Action redo = () =>
			{
				parts.Move(originalIndex, newIndex);
			};

			Action undo = () =>
			{
				parts.Move(newIndex, originalIndex);
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "MovePart");

			redo();
		}
Exemple #29
0
		/// <summary>
		/// Copies a specified part and inserts the copy at the index of a target part.
		/// </summary>
		/// <param name="source">The part to copy.</param>
		/// <param name="name">The name that will be given to the copy.</param>
		/// <param name="target">The target position.</param>
		/// <returns>The created copy.</returns>
		public SongPart CopyPart(SongPart source, string name, SongPart target)
		{
			SongPart newPart;
			using (Undo.ChangeFactory.Batch(this, "CopyPart"))
			{
				newPart = source.Copy(name);
				AddPart(newPart);
				MovePart(newPart, target);
			}
			return newPart;
		}
 public void PartRemoveClean()
 {
     var weakRef = new WeakReference(part);
     song.IsUndoEnabled = false;
     song.RemovePart(part);
     part = null;
     GC.Collect();
     Assert.False(weakRef.IsAlive);
 }