/// <summary>
        /// Deletes the currently selected writing system.
        /// </summary>
        public void DeleteCurrent()
        {
            if (!_usingRepository)
            {
                throw new InvalidOperationException("Unable to delete current selection when there is no writing system store.");
            }
            if (!HasCurrentSelection)
            {
                throw new InvalidOperationException("Unable to delete current selection when there is no current selection.");
            }

            var whatToDo = new WhatToDoWithDataInWritingSystemToBeDeletedEventArgs(CurrentDefinition);
            if(AskUserWhatToDoWithDataInWritingSystemToBeDeleted != null)
            {
                AskUserWhatToDoWithDataInWritingSystemToBeDeleted(this, whatToDo);
            }

            switch(whatToDo.WhatToDo)
            {
                case WhatToDos.Nothing:
                        return;
                case WhatToDos.Conflate:
                    var wsToConflateWith = whatToDo.WritingSystemIdToConflateWith;
                        var okToConflateEventArgs = new AskIfOkToConflateEventArgs(CurrentDefinition.Id,
                                                                                    wsToConflateWith.Id);
                        if (AskIfOkToConflateWritingSystems != null)
                        {
                            AskIfOkToConflateWritingSystems(this, okToConflateEventArgs);
                        }
                        if (!okToConflateEventArgs.CanConflate)
                        {
                            string message = okToConflateEventArgs.ErrorMessage ?? String.Empty;
                            ErrorReport.NotifyUserOfProblem(
                                String.Format("Can not conflate the input system {0} to {1}. {2}",
                                                CurrentDefinition.Id,
                                                wsToConflateWith, message));
                            return;
                        }
                        if (CurrentDefinition != null && _writingSystemRepository.Contains(CurrentDefinition.Id))
                        {
                            if (wsToConflateWith != null)
                            {
                                _writingSystemRepository.Conflate(CurrentDefinition.Id, wsToConflateWith.Id);
                            }
                        }
                    break;
                case WhatToDos.Delete:
                    var okToDeleteEventArgs = new AskIfOkToDeleteEventArgs(CurrentDefinition.Id);
                    if (AskIfOkToDeleteWritingSystems != null)
                    {
                        AskIfOkToDeleteWritingSystems(this, okToDeleteEventArgs);
                    }
                    if (!okToDeleteEventArgs.CanDelete)
                    {
                        string message = okToDeleteEventArgs.ErrorMessage ?? String.Empty;
                        ErrorReport.NotifyUserOfProblem(
                            String.Format("Can not delete the input system {0}. {1}",
                                            CurrentDefinition.Id, message));
                        return;
                    }
                    if (CurrentDefinition != null && _writingSystemRepository.Contains(CurrentDefinition.Id))
                    {
                        _writingSystemRepository.Remove(CurrentDefinition.Id);
                    }
                    break;
            }
            // new index will be next writing system or previous if this was the last in the list
            int newIndex = (CurrentIndex == WritingSystemCount - 1) ? CurrentIndex - 1 : CurrentIndex;
            CurrentDefinition.MarkedForDeletion = true;
            _deletedWritingSystemDefinitions.Add(CurrentDefinition);
            WritingSystemDefinitions.RemoveAt(CurrentIndex);
            CurrentIndex = newIndex;
            OnAddOrDelete();
        }
			public void OnAskUserWhatToDoWithDataInWritingSystemToBeDeleted_Nothing(object sender, WhatToDoWithDataInWritingSystemToBeDeletedEventArgs args)
			{
				AskUserWhatToDoWithDataInWritingSystemToBeDeletedFired = true;
				args.WhatToDo = WhatToDos.Nothing;
			}
        /// <summary>
        /// Deletes the currently selected writing system.
        /// </summary>
        public void DeleteCurrent()
        {
            if (!_usingRepository)
            {
                throw new InvalidOperationException("Unable to delete current selection when there is no writing system store.");
            }
            if (!HasCurrentSelection)
            {
                throw new InvalidOperationException("Unable to delete current selection when there is no current selection.");
            }

            var whatToDo = new WhatToDoWithDataInWritingSystemToBeDeletedEventArgs(CurrentDefinition);
            if(AskUserWhatToDoWithDataInWritingSystemToBeDeleted != null)
            {
                AskUserWhatToDoWithDataInWritingSystemToBeDeleted(this, whatToDo);
            }

            switch(whatToDo.WhatToDo)
            {
                case WhatToDos.Nothing:
                        return;
                case WhatToDos.Conflate:
                    var wsToConflateWith = whatToDo.WritingSystemIdToConflateWith;
                        var okToConflateEventArgs = new AskIfOkToConflateEventArgs(CurrentDefinition.Id,
                                                                                    wsToConflateWith.Id);
                        if (AskIfOkToConflateWritingSystems != null)
                        {
                            AskIfOkToConflateWritingSystems(this, okToConflateEventArgs);
                        }
                        if (!okToConflateEventArgs.CanConflate)
                        {
                            string message = okToConflateEventArgs.ErrorMessage ?? String.Empty;
                            ErrorReport.NotifyUserOfProblem(
                                String.Format("Can not conflate the input system {0} to {1}. {2}",
                                                CurrentDefinition.Id,
                                                wsToConflateWith, message));
                            return;
                        }
                        if (CurrentDefinition != null && _writingSystemRepository.Contains(CurrentDefinition.Id))
                        {
                            if (wsToConflateWith != null)
                            {
                                _writingSystemRepository.Conflate(CurrentDefinition.Id, wsToConflateWith.Id);
                            }
                        }
                    break;
                case WhatToDos.Delete:
                    var okToDeleteEventArgs = new AskIfOkToDeleteEventArgs(CurrentDefinition.Id);
                    if (AskIfOkToDeleteWritingSystems != null)
                    {
                        AskIfOkToDeleteWritingSystems(this, okToDeleteEventArgs);
                    }
                    if (!okToDeleteEventArgs.CanDelete)
                    {
                        string message = okToDeleteEventArgs.ErrorMessage ?? String.Empty;
                        ErrorReport.NotifyUserOfProblem(
                            String.Format("Can not delete the input system {0}. {1}",
                                            CurrentDefinition.Id, message));
                        return;
                    }
                    // If you play around with renaming/revising writing systems, the Id assigned to
                    // the writing system keeps up with the changes, but the StoreID which is the
                    // real key for IWritingSystemRepository methods stays the same.  I find this
                    // a questionable design decision myself, but there may be good reasons for it.
                    // However, not calling _writingSystemRepository.Remove() can cause problems
                    // with data getting out of sync.  (See https://jira.sil.org/browse/WS-281 for
                    // an example of such problems.)
                    if (CurrentDefinition != null && _writingSystemRepository.Contains(CurrentDefinition.StoreID))
                    {
                        _writingSystemRepository.Remove(CurrentDefinition.StoreID);
                    }
                    break;
            }
            // new index will be next writing system or previous if this was the last in the list
            int newIndex = (CurrentIndex == WritingSystemCount - 1) ? CurrentIndex - 1 : CurrentIndex;
            CurrentDefinition.MarkedForDeletion = true;
            _deletedWritingSystemDefinitions.Add(CurrentDefinition);
            WritingSystemDefinitions.RemoveAt(CurrentIndex);
            CurrentIndex = newIndex;
            OnAddOrDelete();
        }
			public void OnAskUserWhatToDoWithDataInWritingSystemToBeDeleted_Conflate(object sender, WhatToDoWithDataInWritingSystemToBeDeletedEventArgs args)
			{
				AskUserWhatToDoWithDataInWritingSystemToBeDeletedFired = true;
				args.WhatToDo = WhatToDos.Conflate;
				args.WritingSystemIdToConflateWith = WritingSystemDefinition.Parse("de");
			}