/// <summary> /// Displays the imported books dialog box (virtual to allow tests to suppress display /// of dialog box). /// </summary> /// <param name="backupSavedVersion">The saved version for backups of any overwritten /// books.</param> protected virtual void DisplayImportedBooksDlg(IScrDraft backupSavedVersion) { using (var dlg = new ImportedBooks(Cache, ImportedVersion, backupSavedVersion, UndoManager.ImportedBooks.Keys, m_helpTopicProvider, m_app)) { dlg.ShowOrSave(m_mainWnd, true); } }
/// <summary> /// Undoes the entire import. Presumably there was either nothing in the file, or the /// user canceled during the first book. /// </summary> public void UndoEntireImport() { if (CollapseAllUndoActions()) { Cache.ActionHandlerAccessor.Undo(); } ImportedBooks.Clear(); ImportedVersion = null; BackupVersion = null; }
/// <summary> /// Creator of this object MUST call this after import is done, whether or not it /// succeeded. /// </summary> /// <param name="fRollbackLastSequence"><c>false</c> if import completed normally or was /// stopped by user after importing one or more complete books. <c>true</c> if an error /// occurred during import or user cancelled import in the middle of a book.</param> public void DoneImportingFiles(bool fRollbackLastSequence) { if (Cache.ActionHandlerAccessor.CurrentDepth == 0) { Logger.WriteEvent("DoneImportingFiles called when no UOW is in progress"); Debug.Fail("DoneImportingFiles called when no UOW is in progress"); return; } if (fRollbackLastSequence) { Cache.ActionHandlerAccessor.Rollback(0); ImportedBooks.Remove(m_lastBookAddedToImportedBooks); } else { Cache.ActionHandlerAccessor.EndUndoTask(); } Cache.ServiceLocator.WritingSystemManager.Save(); }
/// <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)); }
/// <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); }