Esempio n. 1
0
        public void MoveSourceUp(SongSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            int i = sources.IndexOf(source);

            if (i < 0)
            {
                throw new ArgumentException("list of sources does not contain that source", "source");
            }

            Action undo = () =>
            {
                sources.Remove(source);
                sources.Insert(i, source);
                OnPropertyChanged("FirstSource");
            };

            Action redo = () =>
            {
                sources.Remove(source);
                sources.Insert(0, source);
                OnPropertyChanged("FirstSource");
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "MoveSourceUp");
            redo();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new source from a string (can be undone).
        /// </summary>
        /// <param name="source">The string.</param>
        /// <returns>The added <see cref="SongSource"/> object.</returns>
        public SongSource AddSource(string source)
        {
            var src = SongSource.Parse(source, this);

            AddSource(src);
            return(src);
        }
Esempio n. 3
0
        /// <summary>
        /// Generated a <see cref="SongSource"/> by parsing a string.
        /// A variety of formats is supported, e.g. '[Book] / [Nr]' or '[Book], Nr. [Nr]'.
        /// </summary>
        /// <param name="source">The string to parse.</param>
        /// <returns>The parsed source object.</returns>
        public static SongSource Parse(string source, Song root)
        {
            SongSource result = new SongSource(root);

            if (String.IsNullOrWhiteSpace(source))
            {
                return(result);
            }

            bool success = false;
            int  n;

            if (source.Contains("/"))
            {
                var parts = source.Split('/');
                result.songbook = parts[0].Trim();
                if (int.TryParse(parts[1].Trim(), out n))
                {
                    result.number = n;
                    success       = true;
                }
            }

            if (!success)
            {
                int index = source.LastIndexOfAny(new char[] { ' ', '.', ',' });
                if (index >= 0 && int.TryParse(source.Substring(index + 1).Trim(), out n))
                {
                    result.Number = n;
                    string book = source.Substring(0, index + 1).Trim();
                    if (book.EndsWith("Nr."))
                    {
                        book = book.Substring(0, book.Length - 3).Trim();
                    }
                    if (book.EndsWith(","))
                    {
                        book = book.Substring(0, book.Length - 1).Trim();
                    }
                    result.songbook = book;
                }
                else
                {
                    result.songbook = source;
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Removes a source from the list of sources for this song (can be undone).
        /// </summary>
        /// <param name="source">The source to remove.</param>
        public void RemoveSource(SongSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (sources.Count <= 1)
            {
                throw new InvalidOperationException("Can't remove last source");
            }

            int i = sources.IndexOf(source);

            if (i < 0)
            {
                throw new ArgumentException("list of sources does not contain that source", "source");
            }

            Action undo = () =>
            {
                sources.Insert(i, source);
                if (i == 0)
                {
                    OnPropertyChanged("FirstSource");
                }
            };

            Action redo = () =>
            {
                sources.Remove(source);
                if (i == 0)
                {
                    OnPropertyChanged("FirstSource");
                }
            };

            Undo.ChangeFactory.OnChanging(this, undo, redo, "RemoveSource");
            redo();
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a source to the song (can be undone).
        /// </summary>
        /// <param name="source">The source to add.</param>
        public void AddSource(SongSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (source.Root != this)
            {
                throw new ArgumentException("source has wrong root");
            }

            if (sources.Contains(source))
            {
                throw new InvalidOperationException("source already added to the list, cannot add one source multiple times");
            }

            Undo.ChangeFactory.OnChanging(this,
                                          () => { sources.Remove(source); },
                                          () => { sources.Add(source); },
                                          "AddSource");
            sources.Add(source);
        }
Esempio n. 6
0
        public void SourceMoveUp()
        {
            var sources = new SongSource[] {
                SongSource.Parse("Book / 1", song),
                SongSource.Parse("Book / 2", song),
                SongSource.Parse("Book / 3", song)
            };
            song.SetSources(sources);
            ClearUndoRedoStack();

            song.MoveSourceUp(sources[2]);
            Assert.Equal(3, song.Sources.Count);
            Assert.ReferenceEquals(sources[2], song.FirstSource);
            Assert.Equal(1, UndoStackSize);
            Undo();
            for (int i = 0; i < 3; i++)
            {
                Assert.Equal("Book", song.Sources[i].Songbook);
                Assert.Equal(i + 1, song.Sources[i].Number);
            }
            Redo();
            Assert.Equal(3, song.Sources.Count);
            Assert.ReferenceEquals(sources[2], song.FirstSource);
        }
Esempio n. 7
0
 public void SourceRemoveUndoRedo()
 {
     var sources = new SongSource[] {
         SongSource.Parse("Book / 1", song),
         SongSource.Parse("Book / 2", song),
         SongSource.Parse("Book / 3", song)
     };
     song.SetSources(sources);
     ClearUndoRedoStack();
     song.RemoveSource(song.FirstSource);
     song.RemoveSource(song.FirstSource);
     Assert.Equal(1, song.Sources.Count);
     Undo();
     Undo();
     for (int i = 0; i < 3; i++)
     {
         Assert.Equal("Book", song.Sources[i].Songbook);
         Assert.Equal(i + 1, song.Sources[i].Number);
     }
     Redo();
     Redo();
     Assert.Equal(1, song.Sources.Count);
 }
Esempio n. 8
0
        public void SourceSetUndoRedo()
        {
            song.SetSources(new SongSource[] { });
            this.ClearUndoRedoStack();
            Assert.Equal(1, song.Sources.Count);
            var sources = new SongSource[] {
                SongSource.Parse("Book / 1", song),
                SongSource.Parse("Book / 2", song),
                SongSource.Parse("Book / 3", song)
            };

            Assert.Equal(0, UndoStackSize);
            song.SetSources(sources);
            Assert.Equal(1, UndoStackSize);
            Undo();
            Assert.Equal(1, song.Sources.Count);
            Assert.Equal(String.Empty, song.FirstSource.ToString());
            Redo();
            Assert.Equal(3, song.Sources.Count);
            for (int i = 0; i < 3; i++)
            {
                Assert.Equal("Book", song.Sources[i].Songbook);
                Assert.Equal(i + 1, song.Sources[i].Number);
            }
        }
Esempio n. 9
0
        public void SourceSetMultiple()
        {
            song.SetSources(new SongSource[] { });
            Assert.Equal(1, song.Sources.Count);
            var sources = new SongSource[] {
                SongSource.Parse("Book / 1", song),
                SongSource.Parse("Book / 2", song),
                SongSource.Parse("Book / 3", song)
            };

            song.SetSources(sources);
            Assert.Equal(3, song.Sources.Count);
            for (int i = 0; i < 3; i++)
            {
                Assert.Equal("Book", song.Sources[i].Songbook);
                Assert.Equal(i + 1, song.Sources[i].Number);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Generated a <see cref="SongSource"/> by parsing a string.
        /// A variety of formats is supported, e.g. '[Book] / [Nr]' or '[Book], Nr. [Nr]'.
        /// </summary>
        /// <param name="source">The string to parse.</param>
        /// <returns>The parsed source object.</returns>
        public static SongSource Parse(string source, Song root)
        {
            SongSource result = new SongSource(root);

            if(String.IsNullOrWhiteSpace(source))
                return result;

            bool success = false;
            int n;

            if (source.Contains("/"))
            {
                var parts = source.Split('/');
                result.songbook = parts[0].Trim();
                if (int.TryParse(parts[1].Trim(), out n))
                {
                    result.number = n;
                    success = true;
                }
            }

            if (!success)
            {
                int index = source.LastIndexOfAny(new char[] {' ','.',','});
                if (index >= 0 && int.TryParse(source.Substring(index+1).Trim(), out n))
                {
                    result.Number = n;
                    string book = source.Substring(0, index+1).Trim();
                    if (book.EndsWith("Nr."))
                        book = book.Substring(0, book.Length - 3).Trim();
                    if (book.EndsWith(","))
                        book = book.Substring(0, book.Length - 1).Trim();
                    result.songbook = book;
                }
                else
                {
                    result.songbook = source;
                }
            }

            return result;
        }
Esempio n. 11
0
 public void SetSource(SongSource source)
 {
     control.ExecuteJavascript("presentation.setSource(" + JsonConvert.SerializeObject(source.ToString()) + ")");
 }
Esempio n. 12
0
		/// <summary>
		/// Adds a source to the song (can be undone).
		/// </summary>
		/// <param name="source">The source to add.</param>
		public void AddSource(SongSource source)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			if (source.Root != this)
				throw new ArgumentException("source has wrong root");

			if (sources.Contains(source))
				throw new InvalidOperationException("source already added to the list, cannot add one source multiple times");

			Undo.ChangeFactory.OnChanging(this,
				() => { sources.Remove(source); },
				() => { sources.Add(source); },
				"AddSource");
			sources.Add(source);
		}
Esempio n. 13
0
		public void MoveSourceUp(SongSource source)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			int i = sources.IndexOf(source);

			if (i < 0)
				throw new ArgumentException("list of sources does not contain that source", "source");

			Action undo = () =>
			{
				sources.Remove(source);
				sources.Insert(i, source);
				OnPropertyChanged("FirstSource");
			};

			Action redo = () =>
			{
				sources.Remove(source);
				sources.Insert(0, source);
				OnPropertyChanged("FirstSource");
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "MoveSourceUp");
			redo();
		}
Esempio n. 14
0
		/// <summary>
		/// Removes a source from the list of sources for this song (can be undone).
		/// </summary>
		/// <param name="source">The source to remove.</param>
		public void RemoveSource(SongSource source)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			if (sources.Count <= 1)
				throw new InvalidOperationException("Can't remove last source");

			int i = sources.IndexOf(source);

			if (i < 0)
				throw new ArgumentException("list of sources does not contain that source", "source");

			Action undo = () =>
			{
				sources.Insert(i, source);
				if (i == 0) OnPropertyChanged("FirstSource");
			};

			Action redo = () =>
			{
				sources.Remove(source);
				if (i == 0) OnPropertyChanged("FirstSource");
			};

			Undo.ChangeFactory.OnChanging(this, undo, redo, "RemoveSource");
			redo();
		}
Esempio n. 15
0
 /// <summary>
 /// Sets the sources of this song, replacing all previous ones (can be undone).
 /// If the enumeration is empty, a single empty source is added.
 /// </summary>
 /// <param name="newSources">The new sources as strings, which are first parsed.</param>
 public void SetSources(IEnumerable <string> newSources)
 {
     SetSources(newSources.Select(src => SongSource.Parse(src, this)));
 }