コード例 #1
0
        /// <summary>
        /// This class creates text, it must delete it here when UNDO is commanded
        /// so it can update InterestingTexts.
        /// </summary>

/*		public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 *              {
 *                      if (cvDel != 1)
 *                              return;
 *                      SaveOnChangeRecord();
 *                      SuppressSaveOnChangeRecord = true;
 *                      try
 *                      {
 *                              m_list.DeleteCurrentObject();
 *                      }
 *                      finally
 *                      {
 *                              SuppressSaveOnChangeRecord = false;
 *                      }
 *                      GetInterestingTextList().UpdateInterestingTexts();
 *              } */

        #region IBookImporter Members
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="importBt">True to import only the back translation, false to import
        /// only the main translation</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook Import(int bookNum, Form owningForm, bool importBt)
        {
            IScripture scr = Cache.LangProject.TranslatedScriptureOA;
            bool       haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                IScrImportSet importSettings   = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6);
                importSettings.StyleSheet      = ScriptureStylesheet;
                IScrText paratextProj          = ParatextHelper.GetAssociatedProject(Cache.ProjectId);
                importSettings.ParatextScrProj = paratextProj.Name;
                importSettings.StartRef        = new BCVRef(bookNum, 0, 0);
                int chapter           = paratextProj.Versification.LastChapter(bookNum);
                importSettings.EndRef = new BCVRef(bookNum, chapter, paratextProj.Versification.LastVerse(bookNum, chapter));
                if (!importBt)
                {
                    importSettings.ImportTranslation     = true;
                    importSettings.ImportBackTranslation = false;
                }
                else
                {
                    List <IScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList();
                    if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) ||
                                                 !btProjects.Any(st => st.Name == importSettings.ParatextBTProj)))
                    {
                        importSettings.ParatextBTProj = btProjects[0].Name;
                    }
                    if (string.IsNullOrEmpty(importSettings.ParatextBTProj))
                    {
                        return(false);
                    }
                    importSettings.ImportTranslation     = false;
                    importSettings.ImportBackTranslation = true;
                }
                ParatextHelper.LoadProjectMappings(importSettings);
                ScrMappingList importMap     = importSettings.GetMappingListForDomain(ImportDomain.Main);
                ImportMappingInfo figureInfo = importMap[@"\fig"];
                if (figureInfo != null)
                {
                    figureInfo.IsExcluded = true;
                }
                importSettings.SaveSettings();
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll",
                                                                                                 "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet,
                                                                        (FwApp)m_mediator.PropertyTable.GetValue("App")))
            {
                return(scr.FindBook(bookNum));
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// This class creates text, it must delete it here when UNDO is commanded
        /// so it can update InterestingTexts.
        /// </summary>

/*		public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 *              {
 *                      if (cvDel != 1)
 *                              return;
 *                      SaveOnChangeRecord();
 *                      SuppressSaveOnChangeRecord = true;
 *                      try
 *                      {
 *                              m_list.DeleteCurrentObject();
 *                      }
 *                      finally
 *                      {
 *                              SuppressSaveOnChangeRecord = false;
 *                      }
 *                      GetInterestingTextList().UpdateInterestingTexts();
 *              } */

        #region IBookImporter Members
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="importBt">True to import only the back translation, false to import
        /// only the main translation</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook Import(int bookNum, Form owningForm, bool importBt)
        {
            IScripture scr = Cache.LangProject.TranslatedScriptureOA;
            bool       haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                IScrImportSet importSettings   = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6);
                ScrText paratextProj           = ParatextHelper.GetAssociatedProject(Cache.ProjectId);
                importSettings.ParatextScrProj = paratextProj.Name;
                importSettings.IncludeBooks(bookNum, bookNum, paratextProj.Versification);
                if (!importBt)
                {
                    importSettings.ImportTranslation     = true;
                    importSettings.ImportBackTranslation = false;
                }
                else
                {
                    List <ScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList();
                    if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) ||
                                                 !btProjects.Any(st => st.Name == importSettings.ParatextBTProj)))
                    {
                        importSettings.ParatextBTProj = btProjects[0].Name;
                    }
                    if (string.IsNullOrEmpty(importSettings.ParatextBTProj))
                    {
                        return(false);
                    }
                    importSettings.ImportTranslation     = false;
                    importSettings.ImportBackTranslation = true;
                }
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll",
                                                                                                 "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet,
                                                                        (FwApp)m_mediator.PropertyTable.GetValue("App")))
            {
                return(scr.FindBook(bookNum));
            }
            return(null);
        }
コード例 #3
0
        private bool FillInBookChildren(TreeNode bookNode)
        {
            IScrBook book    = bookNode.Tag as IScrBook;
            int      bookNum = (book == null) ? (int)bookNode.Tag : book.CanonicalNum;
            Form     owner   = FindForm();

            while (owner != null && !owner.Visible)
            {
                owner = owner.Owner;
            }
            if (owner == null)
            {
                owner = Form.ActiveForm ?? Application.OpenForms[0];
            }

            if (book == null || (m_associatedPtText != null && m_associatedPtText.BookPresent(book.CanonicalNum) &&
                                 !m_associatedPtText.IsCheckSumCurrent(book.CanonicalNum, book.ImportedCheckSum)))
            {
                // The book for this node is out-of-date with the Paratext book data
                IScrBook importedBook = m_bookImporter.Import(bookNum, owner, false);
                if (importedBook != null)
                {
                    bookNode.Tag = book = importedBook;
                }
                if (book == null)
                {
                    return(false);
                }
            }

            if (m_associatedPtText != null)
            {
                ScrText btProject = ParatextHelper.GetBtsForProject(m_associatedPtText).FirstOrDefault();
                if (btProject != null && !btProject.IsCheckSumCurrent(book.CanonicalNum,
                                                                      book.ImportedBtCheckSum.get_String(book.Cache.DefaultAnalWs).Text))
                {
                    // The BT for this book node is out-of-date with the Paratext BT data
                    m_bookImporter.Import(bookNum, owner, true);
                }
            }

            bookNode.Nodes.Clear();             // Gets rid of dummy.
            //IScrBook book = (IScrBook)bookNode.Tag;
            // Add Title node.
            if (book.TitleOA != null)
            {
                TreeNode titleNode =
                    new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle"));
                titleNode.Name = book.TitleOA.ToString();
                titleNode.Tag  = book.TitleOA;
                bookNode.Nodes.Add(titleNode);
            }

            // Add Sections.
            foreach (IScrSection section in book.SectionsOS)
            {
                string chapterVerseBridge = m_scr.ChapterVerseBridgeAsString(section);
                if (section.HeadingOA != null)
                {
                    // Include the heading text if it's not empty.  See LT-8764.
                    int cTotal = 0;
                    foreach (IScrTxtPara para in section.HeadingOA.ParagraphsOS)
                    {
                        cTotal += para.Contents.Length;
                    }
                    if (cTotal > 0)
                    {
                        string   sFmt = ResourceHelper.GetResourceString("kstidSectionHeading");
                        TreeNode node = new TreeNode(String.Format(sFmt, chapterVerseBridge));
                        node.Name = String.Format(sFmt, section);
                        node.Tag  = section.HeadingOA;                        // expect an StText
                        bookNode.Nodes.Add(node);
                    }
                }
                TreeNode sectionNode = new TreeNode(chapterVerseBridge);
                sectionNode.Name = section.ToString();
                sectionNode.Tag  = section.ContentOA;                // expect an StText
                bookNode.Nodes.Add(sectionNode);
            }

            // Add Footnotes in reverse order, so we can insert them in the proper order.
            List <IScrFootnote> footnotes = new List <IScrFootnote>(book.FootnotesOS);

            footnotes.Reverse();
            foreach (IScrFootnote scrFootnote in footnotes)
            {
                // insert under the relevant section, if any (LTB-408)
                IScrSection containingSection;
                IStText     containingTitle = null;
                if (scrFootnote.TryGetContainingSection(out containingSection) ||
                    scrFootnote.TryGetContainingTitle(out containingTitle))
                {
                    string   nodeName     = m_scr.ContainingRefAsString(scrFootnote);
                    TreeNode footnoteNode = new TreeNode(nodeName);
                    footnoteNode.Tag  = scrFootnote;
                    footnoteNode.Name = "Footnote";

                    // see if we can lookup the node of this section.
                    int nodeIndex = bookNode.Nodes.IndexOfKey(
                        containingSection != null ? containingSection.ToString() : containingTitle.ToString());
                    //TreeNode[] sectionNodes = bookNode.Nodes.Find(hvoSection.ToString(), false);
                    //if (sectionNodes != null && sectionNodes.Length > 0)
                    if (nodeIndex >= 0)
                    {
                        bookNode.Nodes.Insert(nodeIndex + 1, footnoteNode);
                    }
                    else
                    {
                        bookNode.Nodes.Add(footnoteNode);                               // insert at end.
                    }
                }
            }
            return(true);
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Fill in the children for a particular book. This is typically done when it gets
        /// expanded or when we need a list including the children. Separating it from the
        /// initial load saves a lot of time when we have a long list of books.
        /// </summary>
        /// <param name="bookNode">The book node.</param>
        /// <returns><c>true</c> if the dummy node was replaced by real child node(s)</returns>
        /// <remarks>protected virtual for unit tests</remarks>
        /// ------------------------------------------------------------------------------------
        protected virtual bool FillInBookChildren(TreeNode bookNode)
        {
            var book       = bookNode.Tag as IScrBook;
            var bookNum    = book?.CanonicalNum ?? (int)bookNode.Tag;
            var owningForm = FindForm();

            while (owningForm != null && !owningForm.Visible)
            {
                owningForm = owningForm.Owner;
            }
            if (owningForm == null)
            {
                owningForm = Form.ActiveForm ?? Application.OpenForms[0];
            }

            if (m_associatedPtText != null)
            {
                // Update main text, if possible/needed.
                if (m_associatedPtText.BookPresent(bookNum))
                {
                    // PT has it.
                    // If we don't have it, OR if our copy is stale, then get updated copy.
                    if (book == null || !m_associatedPtText.IsCheckSumCurrent(bookNum, book.ImportedCheckSum))
                    {
                        // Get new/fresh version from PT.
                        var importedBook = ImportBook(owningForm, bookNum);
                        if (importedBook != null)
                        {
                            book         = importedBook;
                            bookNode.Tag = importedBook;
                        }
                    }
                }
                if (book == null)
                {
                    // No book, so don't fret about a back translation
                    return(false);
                }

                // Update back translation
                IScrText btProject = ParatextHelper.GetBtsForProject(m_associatedPtText).FirstOrDefault();
                if (btProject != null && btProject.BookPresent(book.CanonicalNum) && !btProject.IsCheckSumCurrent(book.CanonicalNum, book.ImportedBtCheckSum.get_String(book.Cache.DefaultAnalWs).Text))
                {
                    // The BT for this book node is out-of-date with the Paratext BT data
                    ImportBackTranslation(owningForm, bookNum, btProject);
                }
            }

            bookNode.Nodes.Clear();             // Gets rid of dummy.
            // Add Title node.
            if (book.TitleOA != null)
            {
                var titleNode = new TreeNode(ResourceHelper.GetResourceString("kstidScriptureTitle"))
                {
                    Name = book.TitleOA.ToString(),
                    Tag  = book.TitleOA
                };
                bookNode.Nodes.Add(titleNode);
            }

            // Add Sections.
            foreach (var section in book.SectionsOS)
            {
                var chapterVerseBridge = m_scr.ChapterVerseBridgeAsString(section);
                // Include the heading text if it's not empty.  See LT-8764.
                var cTotal = section.HeadingOA?.ParagraphsOS.Cast <IScrTxtPara>().Sum(para => para.Contents.Length);
                if (cTotal > 0)
                {
                    var sFmt = ResourceHelper.GetResourceString("kstidSectionHeading");
                    var node = new TreeNode(string.Format(sFmt, chapterVerseBridge))
                    {
                        Name = string.Format(sFmt, section),
                        Tag  = section.HeadingOA                        // expect an StText
                    };
                    bookNode.Nodes.Add(node);
                }
                var sectionNode = new TreeNode(chapterVerseBridge)
                {
                    Name = section.ToString(),
                    Tag  = section.ContentOA                    // expect an StText
                };
                bookNode.Nodes.Add(sectionNode);
            }

            // Add Footnotes in reverse order, so we can insert them in the proper order.
            var footnotes = new List <IScrFootnote>(book.FootnotesOS);

            footnotes.Reverse();
            foreach (var scrFootnote in footnotes)
            {
                // insert under the relevant section, if any (LTB-408)
                IScrSection containingSection;
                IStText     containingTitle = null;
                if (!scrFootnote.TryGetContainingSection(out containingSection) && !scrFootnote.TryGetContainingTitle(out containingTitle))
                {
                    continue;
                }
                var nodeName     = m_scr.ContainingRefAsString(scrFootnote);
                var footnoteNode = new TreeNode(nodeName)
                {
                    Tag  = scrFootnote,
                    Name = "Footnote"
                };

                // see if we can lookup the node of this section.
                var nodeIndex = bookNode.Nodes.IndexOfKey(containingSection?.ToString() ?? containingTitle.ToString());
                if (nodeIndex >= 0)
                {
                    bookNode.Nodes.Insert(nodeIndex + 1, footnoteNode);
                }
                else
                {
                    bookNode.Nodes.Add(footnoteNode);                           // insert at end.
                }
            }
            return(true);
        }