Exemple #1
0
        private void UpdateInterestingTexts()
        {
            // Need to add the new text(s). Have to find which ones to add.
            var coreTextsSet = new HashSet <IStText>(CoreTexts);
            int count        = 0;

            foreach (var newText in (from sttext in GetCoreTexts() where !coreTextsSet.Contains(sttext) select sttext))
            {
                count++;
                CoreTexts.Add(newText);
                if (m_interestingTests != null)
                {
                    m_interestingTests.Add(newText);
                }
            }
            RaiseInterestingTextsChanged(CoreTexts.Count - count, count, 0);
            ClearInvalidObjects(CoreTexts, 0, true);
        }
Exemple #2
0
        /// <summary>
        /// This is invoked when TE (or some other program) invokes a link, typically to a Scripture Section text not in our filter.
        /// If possible, add it to the filter and return true. Also add any other sections in the same chapter.
        /// Also when jumping from Notebook to a text that is excluded.
        /// Todo JohnT: get it called from TE and test it; not currently used by TE (ported from parts of old InterlinearTextsVirtualHandler)
        /// </summary>
        public bool AddChapterToInterestingTexts(IStText newText)
        {
            int oldCount       = m_scriptureTexts.Count;
            int targetPosition = TextPosition(newText);

            if (targetPosition < 0)
            {
                var excludedCoreTextIdList = ExcludedCoreTextIdList();
                if (newText.Owner is IText && excludedCoreTextIdList.Contains(newText.Guid))
                {
                    CoreTexts.Add(newText);
                    if (m_interestingTests != null)
                    {
                        m_interestingTests.Add(newText);
                    }
                    excludedCoreTextIdList.Remove(newText.Guid);
                    UpdateExcludedCoreTexts(excludedCoreTextIdList);
                    RaiseInterestingTextsChanged(CoreTexts.Count - 1, 1, 0);
                    return(true);             // added sucessfully
                }
                return(false);                // not a text in current Scripture.
            }
            int index;

            for (index = 0; index < m_scriptureTexts.Count; index++)
            {
                if (TextPosition(m_scriptureTexts[index]) > targetPosition)
                {
                    break;
                }
            }
            m_scriptureTexts.Insert(index, newText);
            // Also insert the other text in the same section
            var sec = newText.Owner as IScrSection;

            if (sec != null)             // not a book title
            {
                if (newText == sec.ContentOA && sec.HeadingOA != null)
                {
                    if (index == 0 || m_scriptureTexts[index - 1] != sec.HeadingOA)
                    {
                        m_scriptureTexts.Insert(index, sec.HeadingOA);
                    }
                    else
                    {
                        index--;                         // move index to point at heading
                    }
                }
                else if (sec.ContentOA != null)
                {
                    if (index >= m_scriptureTexts.Count - 1 || m_scriptureTexts[index + 1] != sec.ContentOA)
                    {
                        m_scriptureTexts.Insert(index + 1, sec.ContentOA);
                    }
                }
                // At this point the heading and contents of the section for the inserted text
                // are at index. We look for adjacent sections in the same chapter and if necessary
                // add them too.
                int indexAfter = index + 1;
                if (sec.ContentOA != null && sec.HeadingOA != null)
                {
                    indexAfter++;
                }
                // It would be nicer to use ScrReference, but not worth adding a whole project reference.
                int chapMax = sec.VerseRefMax / 1000;
                int chapMin = sec.VerseRefMin / 1000;
                var book    = (IScrBook)sec.Owner;
                int csec    = book.SectionsOS.Count;
                int isecCur = sec.IndexInOwner;
                for (int isec = isecCur + 1; isec < csec; isec++)
                {
                    IScrSection secNext = book.SectionsOS[isec];
                    if (secNext.VerseRefMin / 1000 != chapMax)
                    {
                        break;                         // different chapter.
                    }
                    indexAfter = AddAfter(indexAfter, secNext.HeadingOA);
                    indexAfter = AddAfter(indexAfter, secNext.ContentOA);
                }
                for (int isec = isecCur - 1; isec >= 0; isec--)
                {
                    IScrSection secPrev = book.SectionsOS[isec];
                    if (secPrev.VerseRefMax / 1000 != chapMin)
                    {
                        break;
                    }
                    index = AddBefore(index, secPrev.ContentOA);
                    index = AddBefore(index, secPrev.HeadingOA);
                }
            }
            // We could get fancy and try to figure the exact range that changed, but this is close enough.
            RaiseInterestingTextsChanged(CoreTexts.Count, m_scriptureTexts.Count, oldCount);
            return(true);
        }
Exemple #3
0
        public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
        {
            switch (tag)
            {
            case TextTags.kflidContents:
                if (cvIns > 0 && cvDel == 0)
                {
                    var text = m_textRepository.GetObject(hvo);
                    CoreTexts.Add(text.ContentsOA);
                    if (m_interestingTests != null)
                    {
                        m_interestingTests.Add(text.ContentsOA);
                    }
                    RaiseInterestingTextsChanged(CoreTexts.Count - 1, 1, 0);
                }
                else if (cvIns == 1 && cvDel == 1)
                {
                    ClearInvalidObjects(CoreTexts, 0, false);                             // get rid of the old one but do NOT raise notification.
                    var text = m_textRepository.GetObject(hvo);
                    CoreTexts.Add(text.ContentsOA);
                    if (m_interestingTests != null)
                    {
                        m_interestingTests.Add(text.ContentsOA);
                    }
                    // We don't know where the old one was removed, safest to treat as changing all.
                    RaiseInterestingTextsChanged(0, CoreTexts.Count, CoreTexts.Count);
                }
                else
                {
                    // We could try getting the text and removing its ContentsOA from the list,
                    // but that assumes a lot about the implementation of deleting objects,
                    // such as that when a Text is deleted, it is still present in its repository
                    // at the moment we clear ContentsOA. I think it's safest to do something generic.
                    ClearInvalidObjects(CoreTexts, 0, true);
                }
                break;

            case RnGenericRecTags.kflidText:
                UpdateInterestingTexts();
                break;

            case ScrSectionTags.kflidHeading:
            case ScrSectionTags.kflidContent:
            case ScrBookTags.kflidSections:
            case ScriptureTags.kflidScriptureBooks:
            case ScrBookTags.kflidTitle:
            case ScrBookTags.kflidFootnotes:
                if (cvDel > 0)
                {
                    if (ClearInvalidObjects(m_scriptureTexts, CoreTexts.Count, IncludeScripture))
                    {
                        if (!m_propertyTable.IsDisposed)
                        {
                            UpdatePropertyTable();
                        }
                    }
                }
                break;

            default:
                if (tag == Cache.ServiceLocator.GetInstance <Virtuals>().LangProjTexts)
                {
                    UpdateInterestingTexts();
                }
                break;
            }
        }