Example #1
0
        /// <summary>
        /// Sets the current book, particularly picking the right set of annotations
        /// to add new ones to. Also (and more conspicuously) ends the current Undo task
        /// and makes a new one for importing the new book. Should therefore be called
        /// BEFORE setting up the Undo action for the creation of the book.
        /// </summary>
        /// <param name="nCanonicalBookNumber">The canonical book number.</param>
        /// <param name="fVernacular">if set to <c>true</c> currently importing the vernacular.
        /// </param>
        /// <returns>The existing book in the current imported version, if any; otherwise
        /// <c>null</c></returns>
        /// <remarks>If importing annotations and/or BTs without importing the vernacular, the
        /// importer is responsible for calling this directly.</remarks>
        private IScrBook SetCurrentBook(int nCanonicalBookNumber, bool fVernacular)
        {
            if (nCanonicalBookNumber <= 0 || nCanonicalBookNumber > BCVRef.LastBook)
            {
                throw new ArgumentOutOfRangeException(nameof(nCanonicalBookNumber), nCanonicalBookNumber, @"Expected a canonical book number.");
            }

            var actionHandler = Cache.DomainDataByFlid.GetActionHandler();

            // We want a new undo task for each new book, except the first one
            if (ImportedBooks.Count > 0)
            {
                actionHandler.EndUndoTask();
            }

            if (actionHandler.CurrentDepth == 0)
            {
                // No need to use localizable string from resources because the user will never
                // see these labels because we collapse to a single undo task when the import
                // completes.
                actionHandler.BeginUndoTask("Undo Import Book " + nCanonicalBookNumber, "Redo Import Book " + nCanonicalBookNumber);
            }
            if (ImportedBooks.ContainsKey(nCanonicalBookNumber))
            {
                m_lastBookAddedToImportedBooks = 0;
            }
            else
            {
                m_lastBookAddedToImportedBooks      = nCanonicalBookNumber;
                ImportedBooks[nCanonicalBookNumber] = fVernacular;
            }

            m_annotations = m_scr.BookAnnotationsOS[nCanonicalBookNumber - 1];

            return(ImportedVersion?.FindBook(nCanonicalBookNumber));
        }
Example #2
0
        /// <summary>
        /// Called when we are about to import a book but are not importing the main translation.
        /// </summary>
        /// <param name="nCanonicalBookNumber"></param>
        /// <param name="fMakeBackup">This should be true if we are importing a back
        /// translation.</param>
        /// <returns>The version of the book in the imported version if available; otherwise
        /// the current version of the book (in which case a backup will be made first if
        /// <c>fMakeBackup</c> is <c>true</c>.</returns>
        public IScrBook PrepareBookNotImportingVern(int nCanonicalBookNumber, bool fMakeBackup)
        {
            var isvBook = SetCurrentBook(nCanonicalBookNumber, false);

            if (isvBook != null && ImportedBooks.ContainsKey(nCanonicalBookNumber))
            {
                return(isvBook);
            }

            var cvBook = m_scr.FindBook(nCanonicalBookNumber);

            if (cvBook != null && fMakeBackup)
            {
                // Replace any existing book with the imported one.
                var oldBook = BackupVersion.FindBook(nCanonicalBookNumber);
                if (oldBook != null)
                {
                    BackupVersion.BooksOS.Remove(oldBook);
                }
                BackupVersion.AddBookCopy(cvBook);
            }

            return(cvBook);
        }