Ejemplo n.º 1
0
        /// --------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ImportedBooks"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="importVersion">The ScrDraft containing the imported books.</param>
        /// <param name="backupVersion">where to store stuff overwritten or merged.</param>
        /// <param name="booksImported">The canonical numbers of the books which were
        /// imported (unordered).</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// <param name="app">The application.</param>
        /// --------------------------------------------------------------------------------
        public ImportedBooks(LcmCache cache,
                             IScrDraft importVersion, IScrDraft backupVersion, IEnumerable <int> booksImported,
                             IHelpTopicProvider helpTopicProvider, IApp app) :
            this(cache, importVersion, backupVersion, helpTopicProvider, app)
        {
            foreach (int bookId in booksImported)
            {
                IScrBook rev = importVersion.FindBook(bookId);

                ListViewItem item = new ListViewItem(
                    new[] { rev.Name.UserDefaultWritingSystem.Text, GetBookInfo(rev) });
                item.SubItems.Add(Properties.Resources.kstidUnknown);

                IScrBook curBook = m_scr.FindBook(rev.CanonicalNum);
                if (curBook == null)
                {
                    SetItemStatus(item, ImportedBookStatus.New);
                    // User should not see this undo task so we don't need to localize the strings.
                    UndoableUnitOfWorkHelper.Do("Add book", "Add book",
                                                m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                    {
                        OnBookAdded(m_scr.CopyBookToCurrent(rev));
                    });
                }
                else
                {
                    item.Tag = new BookMerger(m_cache, rev);
                }
                lstImportedBooks.Items.Add(item);
            }
            lstImportedBooks.Items[0].Selected = true;
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the m_btnCopyToCurr control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event
        /// data.</param>
        /// ------------------------------------------------------------------------------------
        private void m_btnCopyToCurr_Click(object sender, EventArgs e)
        {
            // If nothing or a complete archive is selected, do nothing.
            TreeNode node = m_treeArchives.SelectedNode;

            if (node == null || !(node.Tag is IScrBook))
            {
                return;
            }

            IScrBook           savedBook        = (IScrBook)node.Tag;
            IScrBook           originalBook     = (IScrBook)m_scr.FindBook(savedBook.CanonicalNum);
            TreeNode           parentNode       = node.Parent;
            IScrDraft          archive          = (IScrDraft)parentNode.Tag;
            OverwriteType      typeOfOverwrite  = OverwriteType.FullNoDataLoss;
            List <IScrSection> sectionsToRemove = null;

            if (originalBook != null)
            {
                string        sDetails;
                HashSet <int> missingBtWs;
                typeOfOverwrite = originalBook.DetermineOverwritability(savedBook, out sDetails,
                                                                        out sectionsToRemove, out missingBtWs);
                if (typeOfOverwrite == OverwriteType.DataLoss)
                {
                    // There will be data loss if the user overwrites so we don't allow them
                    // to continue.
                    ImportedBooks.ReportDataLoss(originalBook, ScrDraftType.SavedVersion, this, sDetails);
                    return;
                }

                if (missingBtWs != null && !ImportedBooks.ConfirmBtOverwrite(originalBook,
                                                                             ScrDraftType.SavedVersion, sectionsToRemove, missingBtWs, this))
                {
                    // The user might lose back translation(s) if they proceed and they decided
                    // against it.
                    return;
                }
            }

            string stUndo;
            string stRedo;

            TeResourceHelper.MakeUndoRedoLabels("kstidOverwriteCurrentWithSaved", out stUndo, out stRedo);
            using (new WaitCursor(this))
                using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor,
                                                                      null, stUndo, stRedo))
                {
                    if (typeOfOverwrite == OverwriteType.Partial)
                    {
                        // Perform an automerge of the original book and the saved version.
                        using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, savedBook))
                        {
                            using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this, m_cache.ThreadHelper))
                            {
                                progress.Title = DlgResources.ResourceString("kstidOverwriteCaption");
                                progress.RunTask(merger.DoPartialOverwrite, sectionsToRemove);
                            }
                            if (!merger.AutoMerged)
                            {
                                throw new ContinuableErrorException("Partial Overwrite was not successful.");
                            }
                        }
                    }
                    else
                    {
                        // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch
                        List <Form> disabled_forms = new List <Form>();
                        if (MiscUtils.IsUnix)
                        {
                            lock (Application.OpenForms)
                            {
                                foreach (Form form in Application.OpenForms)
                                {
                                    if (form.Enabled == false)
                                    {
                                        disabled_forms.Add(form);
                                    }
                                }
                            }
                            foreach (Form form in disabled_forms)
                            {
                                form.Enabled = true;
                            }
                        }

                        if (originalBook != null)
                        {
                            if (m_cache.ActionHandlerAccessor != null)
                            {
                                // When Undoing, we need to first resurrect the deleted book, then
                                // put it back in the book filter...so we need a RIFF in the sequence
                                // BEFORE the delete.
                                ReplaceInFilterFixer fixer1 = new ReplaceInFilterFixer(originalBook, null, m_app);
                                m_cache.ActionHandlerAccessor.AddAction(fixer1);
                            }
                            m_scr.ScriptureBooksOS.Remove(originalBook);
                        }
                        IScrBook             newBook = m_scr.CopyBookToCurrent(savedBook);
                        ReplaceInFilterFixer fixer   = new ReplaceInFilterFixer(null, newBook, m_app);

                        fixer.Redo();
                        if (m_cache.ActionHandlerAccessor != null)
                        {
                            m_cache.ActionHandlerAccessor.AddAction(fixer);
                        }

                        // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch
                        if (MiscUtils.IsUnix)
                        {
                            foreach (Form form in disabled_forms)
                            {
                                form.Enabled = false;
                            }
                            disabled_forms.Clear();
                        }
                    }
                    undoHelper.RollBack = false;
                }
        }