Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Load the Paratext project and enumerator, preparing us to read the data files.
        /// </summary>
        /// <param name="paratextProjectId">3-letter Paratext project ID</param>
        /// <returns>true if the project was loaded, else false</returns>
        /// ------------------------------------------------------------------------------------
        protected virtual void LoadParatextProject(string paratextProjectId)
        {
            try
            {
                m_ptProjectText = ScriptureProvider.MakeScrText(paratextProjectId);
            }
            catch (Exception e)
            {
                // Can't load Paratext project if Paratext is not installed.
                throw new ParatextLoadException(
                          TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e);
            }

            try
            {
                // create ref objs of the Paratext lib
                Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " +
                                  m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString);

                // Now initialize the TextEnum with the range of Scripture text we want
                m_ptParser   = m_ptProjectText.Parser;
                m_ptCurrBook = ScriptureProvider.MakeVerseRef(m_settings.StartRef.Book, 0, 0);
                ResetParatextState();
            }
            catch (Exception e)
            {
                string msg = string.Format(
                    TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"),
                    paratextProjectId);
                throw new ParatextLoadException(msg, e);
            }
        }
Esempio n. 2
0
        //private bool m_fShowing; // Whether the floaty has been shown or hidden
        #endregion

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make one.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public DockableUsfmBrowser()
        {
            // need to initialize Paratext libraries before versification files are loaded
            ScriptureProvider.Initialize();
            InitializeComponent();
            m_textCollection.Setup(new ScriptureViewSource(true));
        }
Esempio n. 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Resets the state of the paratext import for the beginning of a new book.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void ResetParatextState()
 {
     m_ptParserState  = ScriptureProvider.GetParserState(m_ptProjectText, m_ptCurrBook);
     m_ptBookTokens   = new List <IUsfmToken>(m_ptParser.GetUsfmTokens(m_ptCurrBook, false, true));
     m_ptCurrentToken = 0;
 }
Esempio n. 4
0
        private void SelectTexts()
        {
            // Create list of current items
            List <ScrText> currentItems = new List <ScrText>();

            foreach (TextCollectionItem item in m_textCollection.Items)
            {
                currentItems.Add(item.ScrText);
            }
            TextCollectionItem currentItem = null;

            if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count)
            {
                currentItem = m_textCollection.Items[m_textCollection.CurItem];
            }

            // Re-initialize, just in case.
            ScriptureProvider.Initialize();
            List <string> textNames = ScrTextCollection.ScrTextNames;

            foreach (string nameVar in textNames)
            {
                if (nameVar.Length < 1)
                {
                    continue;
                }

                string name = nameVar.ToLower();

                // Ignore P6 source language texts.
                if (name == "lxx" || name == "grk" || name == "heb")
                {
                    continue;
                }

                try
                {
                    if (ScrTextCollection.Get(nameVar) == null)
                    {
                        // REVIEW: I'm not sure how/if ScrTextCollection gets disposed
                        ScrText scrText = new ScrText(nameVar);
                        ScrTextCollection.Add(scrText);
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show(name + ": " + exception.Message);
                    // TODO What will happen if a text can't be loaded?
                }
            }

            // the two booleans indicate we want all the available texts, including resources (part of the Paratext distribution)
            // and non-scriptural materials (things like commentaries maybe?)
            using (ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
                       ScrTextCollection.ScrTexts(true, true), currentItems))
            {
                if (selForm.ShowDialog(this) == DialogResult.OK)
                {
                    // Create new list of items, keeping data from old one (to preserve zoom etc)
                    List <TextCollectionItem> newItems = new List <TextCollectionItem>();
                    foreach (ScrText scrText in selForm.Selections)
                    {
                        // Attempt to find in old list
                        bool found = false;
                        foreach (TextCollectionItem item in m_textCollection.Items)
                        {
                            if (item.ScrText == scrText)
                            {
                                newItems.Add(item);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            newItems.Add(new TextCollectionItem(scrText, 1));
                        }
                    }
                    m_textCollection.Items = newItems;
                    int curItemIndex = -1;                     // none selected
                    for (int i = 0; i < newItems.Count; i++)
                    {
                        if (newItems[i] == currentItem)
                        {
                            curItemIndex = i;
                            break;
                        }
                    }
                    // select some current item if possible; out of range does not cause problem.
                    // Currently it seems to cause a crash if the item is out of range for the OLD items;
                    // I think this is a bug in the Paratext code.
                    if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0)
                    {
                        curItemIndex = 0;
                    }
                    m_textCollection.CurItem = curItemIndex;

                    tryReloadTextCollection();
                }
            }
        }
Esempio n. 5
0
 public IEnumerable <IScrText> ScrTexts()
 {
     return(ScriptureProvider.WrapPtCollection(ScrTextCollection.ScrTexts(IncludeProjects.ScriptureOnly),
                                               new Func <ScrText, IScrText>(ptText => new PT8ScrTextWrapper(ptText))));
 }
Esempio n. 6
0
 public IEnumerable <IUsfmToken> GetUsfmTokens(IVerseRef verseRef, bool b, bool b1)
 {
     return(ScriptureProvider.WrapPtCollection(ptParser.GetUsfmTokens((VerseRef)verseRef.CoreVerseRef, b, b1),
                                               new Func <UsfmToken, IUsfmToken>(token => new PT8TokenWrapper(token))));
 }
Esempio n. 7
0
 public IEnumerable <IVerseRef> AllVerses(bool v)
 {
     return(ScriptureProvider.WrapPtCollection(ptVerseRef.AllVerses(v),
                                               new Func <VerseRef, IVerseRef>(verseRef => new PT8VerseRefWrapper(verseRef))));
 }