예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Attempts to scroll to an annotation whose BeginObjectRAHvo is the same as the hvo
        /// of the paragraph where the anchor is in the specified editing helper's selection.
        /// </summary>
        /// <param name="editingHelper">The TE editing helper with information about the
        /// selection in the Scripture pane.</param>
        /// <param name="selectedText">The selected text or the word containing the IP if the
        /// selection is not a range.</param>
        /// <param name="fExactMatchOnly">if set to <c>true</c> then only scroll to a found
        /// note if the cited text is an exact match.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private bool ScrollToAnnotationByPara(TeEditingHelper editingHelper,
                                              string selectedText, bool fExactMatchOnly)
        {
            if (editingHelper == null || editingHelper.CurrentSelection == null)
            {
                return(false);
            }

            ScrReference scrRef = editingHelper.CurrentStartRef;

            SelLevInfo[] info = editingHelper.CurrentSelection.GetLevelInfo(
                SelectionHelper.SelLimitType.Anchor);

            if (info.Length == 0)
            {
                return(false);
            }

            int bookHvo = m_scr.BookAnnotationsOS[scrRef.Book - 1].Hvo;

            int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo,
                                                         m_vc.NotesSequenceHandler.Tag, false);

            if (annHvos.Length == 0)
            {
                return(false);
            }

            int ich = editingHelper.CurrentSelection.IchAnchor;

            // Go through the annotations for the book and find the one whose
            // begin object is in the same as the selection's paragraph.
            for (int i = 0; i < annHvos.Length; i++)
            {
                ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, annHvos[i]);
                if (ann.BeginObjectRAHvo == info[0].hvo)
                {
                    // When matching on the cited text, allow for the possibility that the
                    // begin offset is off by a little bit since leading spaces and/or ORCs
                    // may have been trimmed and subsequent editing may have messed up the
                    // offsets a little.
                    int adjustedBeginOffset = ann.BeginOffset -
                                              (string.IsNullOrEmpty(ann.CitedText) ? 1 : ann.CitedText.Length);

                    if ((!fExactMatchOnly && ich >= ann.BeginOffset && ich <= ann.EndOffset) ||
                        (ich >= adjustedBeginOffset && selectedText == ann.CitedText))
                    {
                        m_vc.SelectedNoteHvo = ann.Hvo;
                        NotesEditingHelper.MakeSelectionInNote(m_vc, scrRef.Book - 1, i, this,
                                                               m_vc.IsExpanded(ann.Hvo));
                        return(true);
                    }
                }
            }

            return(false);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Looks for any annotations in the curtrently filtered set whose reference range
        /// covers the given Scripture reference. Any such annotations are expanded and the
        /// first on is scrolled to near the top of the view.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal void ScrollRefIntoView(ScrReference reference, string quotedText)
        {
            CheckDisposed();
            if (reference.Book <= 0)
            {
                return;
            }

            bool fSaveSendSyncScrollMsg = m_fSendSyncScrollMsg;

            try
            {
                m_fSendSyncScrollMsg = false;
                int   bookHvo = m_scr.BookAnnotationsOS[reference.Book - 1].Hvo;
                int[] annHvos = ((ISilDataAccessManaged)m_rootb.DataAccess).VecProp(bookHvo,
                                                                                    kCurrentNotesTag);

                int exactMatchingAnnotation = -1;
                int firstMatchingAnnotation = -1;

                for (int i = 0; i < annHvos.Length; i++)
                {
                    IScrScriptureNote ann =
                        Cache.ServiceLocator.GetInstance <IScrScriptureNoteRepository>().GetObject(annHvos[i]);
                    if (ann.BeginRef <= reference && ann.EndRef >= reference)
                    {
                        if (firstMatchingAnnotation < 0)
                        {
                            firstMatchingAnnotation = i;
                        }

                        string qtext = ((IStTxtPara)ann.QuoteOA[0]).Contents.Text;
                        if (!string.IsNullOrEmpty(qtext) && !string.IsNullOrEmpty(quotedText) &&
                            qtext == quotedText && exactMatchingAnnotation < 0)
                        {
                            exactMatchingAnnotation = i;
                        }
                    }
                    else if (firstMatchingAnnotation >= 0)
                    {
                        break;
                    }
                }

                int idx = Math.Max(exactMatchingAnnotation, firstMatchingAnnotation);
                if (idx >= 0)
                {
                    NotesEditingHelper.MakeSelectionInNote(m_vc, reference.Book - 1, idx, this, m_vc.IsExpanded(annHvos[idx]));
                }
            }
            finally
            {
                m_fSendSyncScrollMsg = fSaveSendSyncScrollMsg;
            }
        }
예제 #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Looks for any annotations in the curtrently filtered set whose reference range
        /// covers the given Scripture reference. Any such annotations are expanded and the
        /// first on is scrolled to near the top of the view.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal void ScrollRefIntoView(ScrReference reference, string quotedText)
        {
            CheckDisposed();
            if (reference.Book <= 0)
            {
                return;
            }

            bool fSaveSendSyncScrollMsg = m_fSendSyncScrollMsg;

            try
            {
                m_fSendSyncScrollMsg = false;
                int   bookHvo = m_scr.BookAnnotationsOS[reference.Book - 1].Hvo;
                int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo,
                                                             m_vc.NotesSequenceHandler.Tag, false);

                int exactMatchingAnnotation = -1;
                int firstMatchingAnnotation = -1;

                for (int i = 0; i < annHvos.Length; i++)
                {
                    ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, annHvos[i]);
                    if (ann.BeginRef <= reference && ann.EndRef >= reference)
                    {
                        if (firstMatchingAnnotation < 0)
                        {
                            firstMatchingAnnotation = i;
                        }

                        string qtext = ((StTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text;
                        if (!string.IsNullOrEmpty(qtext) && !string.IsNullOrEmpty(quotedText) &&
                            qtext == quotedText && exactMatchingAnnotation < 0)
                        {
                            exactMatchingAnnotation = i;
                        }
                    }
                    else if (firstMatchingAnnotation >= 0)
                    {
                        break;
                    }
                }

                int idx = Math.Max(exactMatchingAnnotation, firstMatchingAnnotation);
                if (idx >= 0)
                {
                    NotesEditingHelper.MakeSelectionInNote(m_vc, reference.Book - 1, idx, this, m_vc.IsExpanded(annHvos[idx]));
                }
            }
            finally
            {
                m_fSendSyncScrollMsg = fSaveSendSyncScrollMsg;
            }
        }
예제 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Attempts to scroll to the first annotation whose beginning reference's book is
        /// the same as the specified book.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool ScrollToNonScrAnnotationByBook(int book, string selectedText)
        {
            int bookHvo = m_scr.BookAnnotationsOS[book - 1].Hvo;

            int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo,
                                                         m_vc.NotesSequenceHandler.Tag, false);

            if (annHvos.Length == 0)
            {
                return(false);
            }

            int ihvo = 0;
            ScrScriptureNote ann;
            BCVRef           bcvRef;

            // Go through the annotations for the book and find the one whose
            // cited text is the same as the specified selected text.
            for (int i = 0; i < annHvos.Length; i++)
            {
                ann    = new ScrScriptureNote(m_fdoCache, annHvos[i]);
                bcvRef = new BCVRef(ann.BeginRef);
                if (ann.CitedText == selectedText && bcvRef.Chapter == 0)
                {
                    ihvo = i;
                    break;
                }
            }

            ann    = new ScrScriptureNote(m_fdoCache, annHvos[ihvo]);
            bcvRef = new BCVRef(ann.BeginRef);
            if (bcvRef.Chapter > 0)
            {
                return(false);
            }

            NotesEditingHelper.MakeSelectionInNote(m_vc, book - 1, ihvo, this, m_vc.IsExpanded(ann.Hvo));
            return(true);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Attempts to scroll to the first annotation whose beginning reference's book is
        /// the same as the specified book.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool ScrollToNonScrAnnotationByBook(int book, string selectedText)
        {
            int bookHvo = m_scr.BookAnnotationsOS[book - 1].Hvo;

            int[] annHvos = ((ISilDataAccessManaged)m_rootb.DataAccess).VecProp(bookHvo,
                                                                                kCurrentNotesTag);

            if (annHvos.Length == 0)
            {
                return(false);
            }

            int ihvo = 0;
            IScrScriptureNote ann;
            BCVRef            bcvRef;

            // Go through the annotations for the book and find the one whose
            // cited text is the same as the specified selected text.
            for (int i = 0; i < annHvos.Length; i++)
            {
                ann    = Cache.ServiceLocator.GetInstance <IScrScriptureNoteRepository>().GetObject(annHvos[i]);
                bcvRef = new BCVRef(ann.BeginRef);
                if (ann.CitedText == selectedText && bcvRef.Chapter == 0)
                {
                    ihvo = i;
                    break;
                }
            }

            ann    = Cache.ServiceLocator.GetInstance <IScrScriptureNoteRepository>().GetObject(annHvos[ihvo]);
            bcvRef = new BCVRef(ann.BeginRef);
            if (bcvRef.Chapter > 0)
            {
                return(false);
            }

            NotesEditingHelper.MakeSelectionInNote(m_vc, book - 1, ihvo, this, m_vc.IsExpanded(ann.Hvo));
            return(true);
        }
예제 #6
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Call MouseUp on the rootbox
        /// </summary>
        /// -----------------------------------------------------------------------------------
        protected override void CallMouseUp(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            IVwSelection     sel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            ScrScriptureNote ann = CurrentAnnotation;

            ScrScriptureNote.ScrScriptureNoteTags noteTagToSelect =
                ScrScriptureNote.ScrScriptureNoteTags.kflidDiscussion;

            bool fMakeSelInFirstResponse = false;

            if (sel != null && sel.SelType == VwSelType.kstPicture)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo[]    info      = selHelper.LevelInfo;

                if (info.Length >= 1 &&
                    info[0].tag == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidDiscussion ||
                    info[0].tag == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidRecommendation ||
                    m_fdoCache.GetClassOfObject(info[0].hvo) == StJournalText.kClassId)
                {
                    bool fExpanding = m_vc.ToggleItemExpansion(info[0].hvo, m_rootb);
                    if (fExpanding)
                    {
                        // If  the tag is not a valid tag, the assumption
                        // is we're expanding the responses.
                        fMakeSelInFirstResponse = (info[0].tag < 0);
                        noteTagToSelect         = (ScrScriptureNote.ScrScriptureNoteTags)info[0].tag;
                    }
                }
                else if (selHelper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) ==
                         -(int)NotesFrags.kfrConnotCategory)                // This is not a real flid, just a unique number to match on.
                {
                    SetAnnotationCategory(ann);
                }
                else if (info.Length >= 2 && info[1].tag == m_currentNotesTag)
                {
                    m_ignoreSelChanged = !m_vc.ToggleItemExpansion(info[1].hvo, m_rootb);
                }
            }

            base.CallMouseUp(pt, rcSrcRoot, rcDstRoot);
            m_ignoreSelChanged = false;

            if (!m_pictureSelected)
            {
                return;
            }

            m_pictureSelected = false;

            if (ann == null || m_vc.NotesSequenceHandler == null)
            {
                return;
            }

            // Make a selection in the proper place in the annotation.
            int book = BCVRef.GetBookFromBcv(ann.BeginRef) - 1;
            ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[book];
            int index = m_vc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, ann.IndexInOwner);

            if (fMakeSelInFirstResponse)
            {
                NotesEditingHelper.MakeSelectionInNote(book, index, 0,
                                                       ScrScriptureNote.ScrScriptureNoteTags.kflidResponses);
            }
            else if (m_vc.IsExpanded(ann.Hvo) &&
                     m_vc.IsExpanded(Cache.GetObjProperty(ann.Hvo, (int)noteTagToSelect)))
            {
                NotesEditingHelper.MakeSelectionInNote(m_vc, false, book,
                                                       index, 0, noteTagToSelect, this, true);
            }
            else
            {
                NotesEditingHelper.MakeSelectionInNoteRef(m_vc, book, index, this);
            }
        }
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Call MouseUp on the rootbox
        /// </summary>
        /// -----------------------------------------------------------------------------------
        protected override void CallMouseUp(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            IVwSelection      sel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            IScrScriptureNote ann = CurrentAnnotation;

            int  noteTagToSelect         = ScrScriptureNoteTags.kflidDiscussion;
            bool fMakeSelInFirstResponse = false;

            if (sel != null && sel.SelType == VwSelType.kstPicture)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo[]    info      = selHelper.LevelInfo;

                if (info.Length >= 1 &&
                    info[0].tag == ScrScriptureNoteTags.kflidDiscussion ||
                    info[0].tag == ScrScriptureNoteTags.kflidRecommendation ||
                    m_fdoCache.ServiceLocator.ObjectRepository.GetClsid(info[0].hvo) == StJournalTextTags.kClassId)
                {
                    if (m_vc.ToggleItemExpansion(info[0].hvo, m_rootb))
                    {
                        // If the tag is not a valid tag, the assumption
                        // is we're expanding the responses.
                        fMakeSelInFirstResponse = (info[0].tag < 0);
                        noteTagToSelect         = info[0].tag;
                    }
                }
                else if (selHelper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) ==
                         -(int)NotesFrags.kfrConnotCategory)                // This is not a real flid, just a unique number to match on.
                {
                    SetAnnotationCategory(ann);
                }
                else if (info.Length >= 2 && info[1].tag == kCurrentNotesTag)
                {
                    m_vc.ToggleItemExpansion(info[1].hvo, m_rootb);
                    m_ignoreSelChanged = true;
                }
            }

            m_suspendHighlightChange = true;
            try
            {
                base.CallMouseUp(pt, rcSrcRoot, rcDstRoot);
            }
            finally
            {
                m_ignoreSelChanged       = false;
                m_suspendHighlightChange = false;
            }

            UpdateNoteHighlight(ann);

            if (!m_pictureSelected)
            {
                return;
            }

            m_pictureSelected = false;

            if (ann == null)
            {
                return;
            }

            // Make a selection in the proper place in the annotation.
            int book = BCVRef.GetBookFromBcv(ann.BeginRef) - 1;
            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[book];
            int index = m_rootb.DataAccess.GetObjIndex(annotations.Hvo, ScrBookAnnotationsTags.kflidNotes, ann.Hvo);

            if (fMakeSelInFirstResponse)
            {
                NotesEditingHelper.MakeSelectionInNote(book, index, 0, ScrScriptureNoteTags.kflidResponses);
            }
            else if (m_vc.IsExpanded(ann.Hvo) &&
                     m_vc.IsExpanded(m_rootb.DataAccess.get_ObjectProp(ann.Hvo, noteTagToSelect)))
            {
                NotesEditingHelper.MakeSelectionInNote(m_vc, false, book,
                                                       index, 0, noteTagToSelect, this, true);
            }
            else
            {
                NotesEditingHelper.MakeSelectionInNoteRef(m_vc, book, index, this);
            }
        }