/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes the selection in in the Scripture reference of the specified annotation.
        /// </summary>
        /// <param name="vc">The vc.</param>
        /// <param name="bookIndex">Index of the book.</param>
        /// <param name="iAnnotation">Index of the annotation.</param>
        /// <param name="notesDataEntryView">The notes data entry view.</param>
        /// ------------------------------------------------------------------------------------
        internal void MakeSelectionInNoteRef(TeNotesVc vc, int bookIndex, int iAnnotation,
                                             NotesDataEntryView notesDataEntryView)
        {
            EnsureNoteIsVisible(vc, bookIndex, iAnnotation, notesDataEntryView);

            SelectionHelper selHelper = new SelectionHelper();

            selHelper.NumberOfLevels             = 2;
            selHelper.LevelInfo[0].cpropPrevious = 0;
            selHelper.LevelInfo[0].ich           = -1;
            selHelper.LevelInfo[0].ihvo          = iAnnotation;
            selHelper.LevelInfo[0].tag           = ScrBookAnnotationsTags.kflidNotes;
            selHelper.LevelInfo[0].ws            = 0;
            selHelper.LevelInfo[1].cpropPrevious = 0;
            selHelper.LevelInfo[1].ich           = -1;
            selHelper.LevelInfo[1].ihvo          = bookIndex;
            selHelper.LevelInfo[1].tag           = ScriptureTags.kflidBookAnnotations;
            selHelper.LevelInfo[1].ws            = 0;
            selHelper.IchAnchor  = 0;
            selHelper.AssocPrev  = false;
            selHelper.TextPropId = -2;
            selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
                                    CmBaseAnnotationTags.kflidBeginRef);

            selHelper.SetSelection(notesDataEntryView, true, true, VwScrollSelOpts.kssoDefault);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Ensures the annotation is mostly visible by making an uninstalled selection
        /// toward the end of the modified date.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal void EnsureNoteIsVisible(TeNotesVc vc, int bookIndex, int iAnnotation,
                                          IVwRootSite notesDataEntryView)
        {
            SelectionHelper selHelper = new SelectionHelper();

            selHelper.NumberOfLevels             = 2;
            selHelper.LevelInfo[0].cpropPrevious = 0;
            selHelper.LevelInfo[0].ich           = -1;
            selHelper.LevelInfo[0].ihvo          = iAnnotation;
            selHelper.LevelInfo[0].tag           = ScrBookAnnotationsTags.kflidNotes;
            selHelper.LevelInfo[0].ws            = 0;
            selHelper.LevelInfo[1].cpropPrevious = 0;
            selHelper.LevelInfo[1].ich           = -1;
            selHelper.LevelInfo[1].ihvo          = bookIndex;
            selHelper.LevelInfo[1].tag           = ScriptureTags.kflidBookAnnotations;
            selHelper.LevelInfo[1].ws            = 0;
            selHelper.AssocPrev = false;

            // Put the selection at the end of the shortest possible date value. It doesn't
            // have to be right at the end, but the closer it is, the more reliable it will
            // be that it is fully scrolled into view.
            selHelper.IchAnchor = 8;

            selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
                                    CmAnnotationTags.kflidDateModified);

            selHelper.SetSelection(notesDataEntryView, false, true, VwScrollSelOpts.kssoDefault);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Scroll new note into view.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="fromUndoRedo">True if the event was fired from an undo (or rollback) or
        /// redo, false otherwise.</param>
        /// ------------------------------------------------------------------------------------
        private void ScrollAfterPropChangedCompleted(object sender, bool fromUndoRedo)
        {
            // In test teardown, cache may already have been cleared
            if (Cache == null)
            {
                return;
            }
            ((IActionHandlerExtensions)Cache.ActionHandlerAccessor).PropChangedCompleted -= ScrollAfterPropChangedCompleted;
            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[m_bookNewNote - 1];
            IScrScriptureNote   annotation  = annotations.NotesOS[m_indexNewNote];
            TeNotesVc           notesVc     = CurrentNotesVc;

            if (notesVc != null)
            {
                // tell the VC that the newly inserted item should be expanded. That will cause
                // the view to be updated to show the new note.
                notesVc.ExpandItem(annotation.Hvo, EditedRootBox);
                notesVc.ExpandItem(annotation.DiscussionOA.Hvo, EditedRootBox);
            }

            if (Control != null)
            {
                Control.Focus();
            }

            // Make a selection in the discussion so the user can start to type
            int iPos = m_indexNewNote;

            if (notesVc != null)
            {
                // Get the corresponding index in the virtual property.
                iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess).
                       GetFilteredIndexOfItem(annotations.Hvo, iPos);
                // New note doesn't match current filter - need to turn it off
                if (iPos < 0)
                {
                    // Turn off the filter so the new note will show
                    ((NotesDataEntryView)Control).OnChangeFilter(null);
                    iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess).
                           GetFilteredIndexOfItem(annotations.Hvo, m_indexNewNote);
                    Debug.Assert(iPos >= 0);
                }
            }

            IVwRootSite rootSite = Control as IVwRootSite;

            MakeSelectionInNote(notesVc, m_bookNewNote - 1, iPos, rootSite, true);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        /// ------------------------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose(disposing);

            if (disposing)
            {
                if (m_vc != null)
                {
                    m_vc.Dispose();
                }
            }
            m_vc = null;
        }
예제 #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        /// ------------------------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose(disposing);

            if (disposing)
            {
                if (m_vc != null)
                {
                    m_vc.Dispose();
                }
            }
            m_vc = null;
            m_baseInfoBarCaption = null;
            m_scr      = null;
            m_UserView = null;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes the root
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void MakeRoot()
        {
            CheckDisposed();

            if (m_fdoCache == null || DesignMode)
            {
                return;
            }

            // Check for non-existing rootbox before creating a new one. By doing that we
            // can mock the rootbox in our tests. However, this might cause problems in our
            // real code - altough I think MakeRoot() should be called only once.
            if (m_rootb == null)
            {
                m_rootb = VwRootBoxClass.Create();
            }

            m_rootb.SetSite(this);

            m_rootb.DataAccess =
                new FilteredDomainDataByFlidDecorator(m_fdoCache, null, ScrBookAnnotationsTags.kflidNotes);

            // Set up a new view constructor.
            HorizMargin = 10;
            Debug.Assert(IsHandleCreated);
            m_vc = new TeNotesVc(m_fdoCache, Zoom);
            OnChangeFilter(null);

//			m_vc.HotLinkClick += new DraftViewVc.HotLinkClickHandler(DoHotLinkAction);

            //EditingHelper.RootObjects = new int[]{ScriptureObj.Hvo};
            m_rootb.SetRootObject(m_scr.Hvo, m_vc, (int)ScrFrags.kfrScripture, m_styleSheet);

            base.MakeRoot();
            m_dxdLayoutWidth = kForceLayout;             // Don't try to draw until we get OnSize and do layout.

            Synchronize(m_rootb);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes a selection in the specified annotation (without scrolling the annotation in
        /// the view).
        /// </summary>
        /// <param name="vc">The notes view constructor</param>
        /// <param name="fScrollNearTop">if set to <c>true</c> scrolls the specified note to a
        /// position near the top of the view.</param>
        /// <param name="bookIndex">Index of the book.</param>
        /// <param name="iAnnotation">Index of the annotation.</param>
        /// <param name="iResponse">Index of the response (0 if setting the selection in one of
        /// the StJournalText fields rather than in a response.</param>
        /// <param name="noteTag">The tag indicating the field of the annotation where the
        /// selection is to be made.</param>
        /// <param name="rootSite">The root site.</param>
        /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so
        /// that the whole annotation can be scrolled into view. if set to <c>false</c> only
        /// make a selection at the start of the annotation.</param>
        /// ------------------------------------------------------------------------------------
        internal void MakeSelectionInNote(TeNotesVc vc, bool fScrollNearTop, int bookIndex,
                                          int iAnnotation, int iResponse, int noteTag,
                                          IVwRootSite rootSite, bool fNoteIsExpanded)
        {
            if (vc == null)
            {
                return;
            }

            SelectionHelper selHelper;

            if (fScrollNearTop)
            {
                // Make an un-installed selection at the top of the annotation in order to scroll the
                // annotation to the top of the view.
                selHelper = new SelectionHelper();
                selHelper.NumberOfLevels             = 2;
                selHelper.LevelInfo[0].cpropPrevious = 0;
                selHelper.LevelInfo[0].ich           = -1;
                selHelper.LevelInfo[0].ihvo          = iAnnotation;
                selHelper.LevelInfo[0].tag           = ScrBookAnnotationsTags.kflidNotes;
                selHelper.LevelInfo[0].ws            = 0;
                selHelper.LevelInfo[1].cpropPrevious = 0;
                selHelper.LevelInfo[1].ich           = -1;
                selHelper.LevelInfo[1].ihvo          = bookIndex;
                selHelper.LevelInfo[1].tag           = ScriptureTags.kflidBookAnnotations;
                selHelper.LevelInfo[1].ws            = 0;
                selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, -2);
                selHelper.IchAnchor             = 0;
                selHelper.AssocPrev             = false;
                selHelper.NumberOfPreviousProps = 2;
                if (fNoteIsExpanded)
                {
                    selHelper.SetSelection(rootSite, true, true, VwScrollSelOpts.kssoNearTop);
                }
                else
                {
                    // Annotation is collapsed. Only attempt a selection at the start of it.
                    selHelper.SetSelection(rootSite, true, true);
                    return;
                }
            }
            else
            {
                EnsureNoteIsVisible(vc, bookIndex, iAnnotation, rootSite);
            }

            // Now make the real (installed) selection in the desired field of the annotation.
            bool fIsResponse = (noteTag == ScrScriptureNoteTags.kflidResponses);

            selHelper = new SelectionHelper();
            selHelper.NumberOfLevels             = 4;
            selHelper.LevelInfo[0].tag           = StTextTags.kflidParagraphs;
            selHelper.LevelInfo[0].ihvo          = 0;
            selHelper.LevelInfo[1].tag           = (int)noteTag;
            selHelper.LevelInfo[1].ihvo          = iResponse;
            selHelper.LevelInfo[1].cpropPrevious = (fIsResponse ? 0 : 1);
            selHelper.LevelInfo[2].tag           = ScrBookAnnotationsTags.kflidNotes;
            selHelper.LevelInfo[2].ihvo          = iAnnotation;
            selHelper.LevelInfo[3].tag           = ScriptureTags.kflidBookAnnotations;
            selHelper.LevelInfo[3].ihvo          = bookIndex;
            selHelper.IchAnchor  = 0;
            selHelper.AssocPrev  = false;
            selHelper.TextPropId = StTxtParaTags.kflidContents;
            selHelper.SetSelection(rootSite, true, true);
        }
 /// --------------------------------------------------------------------------------
 /// <summary>
 /// Makes a selection in the discussion of an annotation after first scrolling the
 /// annotation to near the top of the view.
 /// </summary>
 /// <param name="vc">The notes view constructor</param>
 /// <param name="bookIndex">Index of the book.</param>
 /// <param name="iAnnotation">Index of the annotation.</param>
 /// <param name="rootSite">The root site.</param>
 /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so
 /// that the whole annotation can be scrolled into view. if set to <c>false</c> only
 /// make a selection at the start of the annotation.</param>
 /// --------------------------------------------------------------------------------
 internal void MakeSelectionInNote(TeNotesVc vc, int bookIndex, int iAnnotation,
                                   IVwRootSite rootSite, bool fNoteIsExpanded)
 {
     MakeSelectionInNote(vc, true, bookIndex, iAnnotation, 0,
                         ScrScriptureNoteTags.kflidDiscussion, rootSite, fNoteIsExpanded);
 }
예제 #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts a note referencing the currently selected paragraph.
        /// </summary>
        /// <param name="noteType">Type of note</param>
        /// <param name="startRef">reference at beginning of selection</param>
        /// <param name="endRef">reference at end of selection</param>
        /// <param name="topObj">The object where quoted text begins.</param>
        /// <param name="bottomObj">The object where quoted text ends.</param>
        /// <param name="wsSelector">The writing system selector.</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="tssQuote">The text of the quote.</param>
        /// <returns>The inserted note</returns>
        /// ------------------------------------------------------------------------------------
        public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef,
                                                    BCVRef endRef, CmObject topObj, CmObject bottomObj, int wsSelector,
                                                    int startOffset, int endOffset, ITsString tssQuote)
        {
            CheckDisposed();
            TeNotesVc notesVc = CurrentNotesVc;

            IScrScriptureNote annotation;
            string            sUndo, sRedo;
            int iPos;

            ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[startRef.Book - 1];

            TeResourceHelper.MakeUndoRedoLabels("kstidInsertAnnotation", out sUndo, out sRedo);
            string sType = noteType.Name.UserDefaultWritingSystem;

            sUndo = string.Format(sUndo, sType);
            sRedo = string.Format(sRedo, sType);
            using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.MainCacheAccessor,
                                                                      Control as IVwRootSite, sUndo, sRedo, false))
            {
                try
                {
                    StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache);
                    quoteParaBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark);
                    quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote);
                    annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid,
                                                        wsSelector, startOffset, endOffset, quoteParaBldr, null, null, null,
                                                        out iPos);

                    if (notesVc != null)
                    {
                        // tell the VC that the newly inserted item should be expanded. That will cause
                        // the view to be updated to show the new note.
                        notesVc.ExpandItem(annotation.Hvo);
                        notesVc.ExpandItem(annotation.DiscussionOAHvo);
                    }
                }
                catch
                {
                    undoTaskHelper.EndUndoTask = false;
                    FwApp.App.RefreshAllViews(m_cache);
                    throw;
                }
            }

            if (Control != null)
            {
                Control.Focus();
            }

            // Make a selection in the discussion so the user can start to type
            if (notesVc != null && notesVc.NotesSequenceHandler != null)
            {
                // Get the corresponding index in the virtual property.
                iPos = notesVc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, iPos);
            }

            IVwRootSite rootSite = Control as IVwRootSite;

            MakeSelectionInNote(notesVc, startRef.Book - 1, iPos, rootSite, true);

            // REVIEW: Do we need to create a synch record?
            return(annotation);
        }