Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("Usage: rdwrtp7 -r|-w project book chapter|0 fileName");
                Environment.Exit(-1);
            }

            ScrTextCollection.Initialize();

            string operation = args[0];
            string project = args[1];
            string book = args[2];
            string chapter = args[3];
            string file = args[4];

            ScrText scr = ScrTextCollection.Get(project);
            if (scr == null)
            {
                Console.WriteLine("Error: unknown project");
                Environment.Exit(-1);
            }

            VerifyBook(book);
            VerifyChapter(chapter);

            VerseRef vref = new VerseRef(book, chapter, "1", scr.Versification);

            try
            {
                if (operation == "-r")
                    DoRead(scr, vref, file);
                else if (operation == "-w")
                    DoWrite(scr, vref, file);
                else
                {
                    Console.WriteLine("Error: unknown operation");
                    Environment.Exit(-1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 2
0
        private void LoadSavedSelectionItem_Click(object sender, EventArgs e)
        {
            SavedScrTextList savedList =
                (sender as ToolStripMenuItem).Tag as SavedScrTextList;

            rightItems = new List <ScrText>();
            foreach (string scrTextName in savedList.ScrTextNames)
            {
                ScrText scrText = ScrTextCollection.Get(scrTextName);
                if (scrText != null)
                {
                    rightItems.Add(scrText);
                }
            }
            UpdateRightList();
            UpdateSavedSelectionLinks();
        }
Ejemplo n.º 3
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.
            // We pass the directory (rather than passing no arguments, and letting the paratext dll figure
            // it out) because the figuring out goes wrong on Linux, where both programs are simulating
            // the registry.
            ScrTextCollection.Initialize(ParatextHelper.ProjectsDirectory, false);
            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();
                }
            }
        }
Ejemplo n.º 4
0
 public IScrText Get(string project)
 {
     return(new PT8ScrTextWrapper(ScrTextCollection.Get(project)));
 }
Ejemplo n.º 5
0
        public bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain)
        {
            // If the new project ID is null, then do not load mappings.
            if (project == null)
            {
                return(false);
            }

            // Load the tags from the paratext project and create mappings for them.
            ScrText scParatextText;

            try
            {
                // REVIEW (EberhardB): I'm not sure if ScrTextCollection.Get() returns a
                // reference to a ScrText or a new object (in which case we would have to
                // call Dispose() on it)
                scParatextText = ScrTextCollection.Get(project);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }

            mappingList.ResetInUseFlags(domain);
            try
            {
                foreach (ScrTag tag in scParatextText.DefaultStylesheet.Tags)
                {
                    if (tag == null)
                    {
                        break;
                    }
                    string marker    = @"\" + tag.Marker;
                    string endMarker = string.Empty;
                    if (!String.IsNullOrEmpty(tag.Endmarker))
                    {
                        endMarker = @"\" + tag.Endmarker;
                    }

                    // When the nth marker has an end marker, the nth + 1 marker will be
                    // that end marker. Therefore, we have to skip those "end style" markers.
                    if (tag.StyleType == ScrStyleType.scEndStyle)
                    {
                        continue;
                    }

                    // Create a new mapping for this marker.
                    mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
                }
                ScrParser parser = scParatextText.Parser();
                foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers())
                {
                    foreach (UsfmToken token in parser.GetUsfmTokens(new VerseRef(bookNum, 0, 0), false, true))
                    {
                        if (token.Marker == null)
                        {
                            continue;                             // Tokens alternate between text and marker types
                        }
                        ImportMappingInfo mapping = mappingList[@"\" + token.Marker];
                        if (mapping != null)
                        {
                            mapping.SetIsInUse(domain, true);
                        }

                        // ENHANCE (TE-4408): Consider Detecting markers that occur in the data but are missing
                        // from the STY file. How can we write a test for this?
                        //else if (ScrImportFileInfo.IsValidMarker(sMarker))
                        //{
                        //    mappingList.AddDefaultMappingIfNeeded(sMarker,domain, false, true);
                        //}
                        //else
                        //{
                        //    throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                        //        sMarker + sText, new ScrReference(scParatextTextSegment.FirstReference.BBCCCVVV));
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Method adapted from TextCollectionControl method of same name, to use our dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        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];
            }

            ScrTextCollection.Initialize();             // Re-initialize, just in case
            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)
                    {
                        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?
                }
            }


            ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
                ScrTextCollection.ScrTexts, 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();
            }
        }
Ejemplo n.º 7
0
            private bool LoadProjectMappings(string project, ScrMappingList mappingList, ImportDomain domain)
            {
                // If the new project ID is null, then do not load mappings.
                if (string.IsNullOrEmpty(project))
                {
                    return(false);
                }

                // Load the tags from the paratext project and create mappings for them.
                ScrText scParatextText;

                try
                {
                    // REVIEW (EberhardB): I'm not sure if ScrTextCollection.Get() returns a
                    // reference to a ScrText or a new object (in which case we would have to
                    // call Dispose() on it)
                    scParatextText = ScrTextCollection.Get(project);
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    m_IsParatextInitialized = false;
                    return(false);
                }

                foreach (ImportMappingInfo mapping in mappingList)
                {
                    mapping.SetIsInUse(domain, false);
                }
                try
                {
                    foreach (ScrTag tag in scParatextText.DefaultStylesheet.Tags)
                    {
                        if (tag == null)
                        {
                            break;
                        }
                        string marker    = @"\" + tag.Marker;
                        string endMarker = string.Empty;
                        if (!String.IsNullOrEmpty(tag.Endmarker))
                        {
                            endMarker = @"\" + tag.Endmarker;
                        }

                        // When the nth marker has an end marker, the nth + 1 marker will be
                        // that end marker. Therefore, we have to skip those "end style" markers.
                        if (tag.StyleType == ScrStyleType.scEndStyle)
                        {
                            continue;
                        }

                        // Create a new mapping for this marker.
                        mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false);
                    }
                    ScrParser parser = scParatextText.Parser;
                    foreach (int bookNum in scParatextText.BooksPresentSet.SelectedBookNumbers)
                    {
                        foreach (UsfmToken token in parser.GetUsfmTokens(new VerseRef(bookNum, 0, 0), false, true))
                        {
                            if (token.Marker == null)
                            {
                                continue;                                 // Tokens alternate between text and marker types
                            }
                            ImportMappingInfo mapping = mappingList[@"\" + token.Marker];
                            if (mapping != null)
                            {
                                mapping.SetIsInUse(domain, true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    // A lot goes on in the try block, so this exception doesn't necessarily mean Paratext is inaccessible,
                    // so don't mark Paratext as uninitialized
                    return(false);
                }
                return(true);
            }