Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Selects the paragraph in the DraftView or FootnoteView associated with the style.
        /// </summary>
        /// <param name="origSelection">selection user originally made</param>
        /// <param name="view">The DraftView or FootnoteView</param>
        /// ------------------------------------------------------------------------------------
        private void SelectAssociatedPara(SelectionHelper origSelection, IVwRootSite view)
        {
            SelLevInfo paraInfoAnchor = origSelection.GetLevelInfoForTag(
                StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Top);
            SelLevInfo paraInfoEnd = origSelection.GetLevelInfoForTag(
                StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Bottom);

            if (paraInfoAnchor.hvo != m_prevPara1Hvo || paraInfoEnd.hvo != m_prevPara2Hvo)
            {
                // The selection changed paragraphs, so update the selection in the
                // DraftView or FootnoteView
                IStTxtPara      para1  = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoAnchor.hvo);
                IStTxtPara      para2  = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoEnd.hvo);
                SelectionHelper helper = MakeSelection(para1, para2, view);
                IVwSelection    sel    = helper.SetSelection(view, true, false);
                // If the selection fails then try selecting the user prompt.
                if (sel == null)
                {
                    AdjustSelectionForPrompt(helper, para1, para2);
                    sel = helper.SetSelection(view, true, false);
                }

                Debug.Assert(sel != null || ((SimpleRootSite)view).ReadOnlyView);
                m_prevPara1Hvo = paraInfoAnchor.hvo;
                m_prevPara2Hvo = paraInfoEnd.hvo;
            }
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Retrieves the flid and hvo corresponding to the current Scripture element (e.g.,
        /// section heading, section contents, or title) selected.
        /// </summary>
        /// <param name="tag">The flid of the selected owning element</param>
        /// <param name="hvoSel">The hvo of the selected owning element (hvo of either section
        /// or book)</param>
        /// <returns>
        /// True, if a known element is found at this current selection
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override bool GetSelectedScrElement(out int tag, out int hvoSel)
        {
            CheckDisposed();

            hvoSel = 0;
            tag    = 0;
            if (CurrentSelection == null)
            {
                return(false);
            }

            try
            {
                SelectionHelper helper = CurrentSelection;
                SelLevInfo      selLevInfo;
                if (!helper.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidFootnotes,
                                               SelectionHelper.SelLimitType.Top, out selLevInfo))
                {
                    return(base.GetSelectedScrElement(out tag, out hvoSel));
                }
                tag    = selLevInfo.tag;
                hvoSel = m_cache.GetOwnerOfObject(selLevInfo.hvo);
            }
            catch
            {
            }
            return(true);
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle Mouse up
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                base.OnMouseUp(e);
                return;
            }

            NotesMainWnd notesMainWnd = TheMainWnd as NotesMainWnd;

            if (notesMainWnd == null || notesMainWnd.TMAdapter == null)
            {
                return;
            }

            Rectangle rcSrcRoot;
            Rectangle rcDstRoot;

            GetCoordRects(out rcSrcRoot, out rcDstRoot);
            Point        pt      = new Point(e.X, e.Y);
            IVwSelection sel     = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            int          noteHvo = 0;

            if (sel != null)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo      annInfo   = selHelper.GetLevelInfoForTag(m_currentNotesTag);
                noteHvo = annInfo.hvo;
            }

            pt = PointToScreen(new Point(e.X, e.Y));
            notesMainWnd.TMAdapter.PopupMenu("cmnuNotesDataEntryView", pt.X, pt.Y);
        }
Esempio n. 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the HVO of the current section, or -1 if we're not in a section (e.g. the IP is
        /// in a title).
        /// </summary>
        /// <param name="selHelper">The selection helper.</param>
        /// <param name="selLimitType">Which end of the selection</param>
        /// <returns>The section hvo.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual int GetSectionHvo(SelectionHelper selHelper, SelectionHelper.SelLimitType selLimitType)
        {
            if (selHelper == null)
            {
                return(-1);
            }

            SelLevInfo levInfo;

            if (selHelper.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidSections,
                                             selLimitType, out levInfo))
            {
                return(levInfo.hvo);
            }
            return(-1);
        }
Esempio n. 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the HVO of the current book, or -1 if there is no current book (e.g. no
        /// selection or empty view).
        /// </summary>
        /// <param name="selHelper">The selection helper.</param>
        /// <param name="selLimitType">Which end of the selection</param>
        /// <returns>The book hvo.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual int GetBookHvo(SelectionHelper selHelper,
                                      SelectionHelper.SelLimitType selLimitType)
        {
            if (selHelper == null)
            {
                return(-1);
            }

            SelLevInfo levInfo;

            if (selHelper.GetLevelInfoForTag(BookTag, selLimitType, out levInfo))
            {
                return(levInfo.hvo);
            }
            return(-1);
        }
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the current book, or null if there is no current book (e.g. no selection or
        /// empty view).
        /// </summary>
        /// <param name="selHelper">The selection helper.</param>
        /// <param name="selLimitType">Which end of the selection</param>
        /// <returns>The book, or null if there isn't a current book.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual IScrBook GetBook(SelectionHelper selHelper,
                                        SelectionHelper.SelLimitType selLimitType)
        {
            if (selHelper == null)
            {
                return(null);
            }

            SelLevInfo levInfo;

            if (selHelper.GetLevelInfoForTag(BookTag, selLimitType, out levInfo))
            {
                return(m_cache.ServiceLocator.GetInstance <IScrBookRepository>().GetObject(levInfo.hvo));
            }
            return(null);
        }
Esempio n. 7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the current section, or null if we're not in a section (e.g. the IP is in a
        /// title).
        /// </summary>
        /// <param name="selHelper">The selection helper.</param>
        /// <param name="selLimitType">Which end of the selection</param>
        /// <returns>The section or null if we're not in a section.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual IScrSection GetSection(SelectionHelper selHelper,
                                              SelectionHelper.SelLimitType selLimitType)
        {
            if (selHelper == null)
            {
                return(null);
            }

            SelLevInfo levInfo;

            if (selHelper.GetLevelInfoForTag(ScrBookTags.kflidSections,
                                             selLimitType, out levInfo))
            {
                IScrSection section;
                if (m_cache.ServiceLocator.GetInstance <IScrSectionRepository>().TryGetObject(levInfo.hvo, out section))
                {
                    return(section);
                }
            }
            return(null);
        }
Esempio n. 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This is called by a view when the views code is about to delete a paragraph. We
        /// need to save the back translations by moving them to whatever paragraph the deleted
        /// one is merging with.
        /// </summary>
        /// <param name="selHelper">The selection helper</param>
        /// <param name="hvoObject">Paragraph to be deleted</param>
        /// <param name="hvoOwner">StText that owns the para</param>
        /// <param name="tag">flid in which para is owned</param>
        /// <param name="ihvo">index of paragraph in text</param>
        /// <param name="fMergeNext"><c>true</c> if this paragraph is merging with the
        /// following paragraph.</param>
        /// ------------------------------------------------------------------------------------
        public virtual void AboutToDelete(SelectionHelper selHelper, int hvoObject,
                                          int hvoOwner, int tag, int ihvo, bool fMergeNext)
        {
            CheckDisposed();

            if (tag != (int)StText.StTextTags.kflidParagraphs)
            {
                return;
            }

            StTxtPara paraToDelete = new StTxtPara(m_cache, hvoObject);

            // If the paragraph that is being deleted is empty, then do not attempt to save a back
            // translation for it.
            if (paraToDelete.Contents.Text == null)
            {
                return;
            }

            // ihvoTop is either the paragraph before the IP or the first paragraph in a range selection
            int ihvoTop           = ihvo - 1;
            int hvoOwnerSurviving = hvoOwner;

            // Figure out what is being deleted and what is staying.
            // NOTE: it is possible that the selection is no longer valid. This is ok for our purposes here,
            // since all information we access here is already retrieved and stored in member variables of
            // SelectionHelper.
            if (selHelper.IsRange)
            {
                int          paraLev      = selHelper.GetLevelForTag(tag, SelectionHelper.SelLimitType.Top);
                SelLevInfo[] rgSelLevInfo = selHelper.GetLevelInfo(SelectionHelper.SelLimitType.Top);
                ihvoTop = rgSelLevInfo[paraLev].ihvo;
                if (paraLev + 1 < rgSelLevInfo.Length)
                {
                    hvoOwnerSurviving = rgSelLevInfo[paraLev + 1].hvo;
                }
                int ihvoBottom = selHelper.GetLevelInfoForTag(tag, SelectionHelper.SelLimitType.Bottom).ihvo;

                // Pretty sure that if we get here top will NEVER equal bottom.
                Debug.Assert(ihvoTop != ihvoBottom || hvoOwnerSurviving != hvoOwner);
                if (hvoOwnerSurviving == hvoOwner)
                {
                    if (ihvoTop == ihvoBottom)
                    {
                        return;
                    }

                    int ichEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo == ihvoBottom && ichEnd == paraToDelete.Contents.Length)
                    {
                        return;
                    }
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo > ihvoTop && ihvo < ihvoBottom)
                    {
                        return;
                    }
                }
            }

            // Determine the surviving paragraph.
            StText    text = new StText(m_cache, hvoOwnerSurviving);
            StTxtPara paraSurviving;

            if (fMergeNext)
            {
                // when merging with next and there are no more paragraphs, then the BT can be discarded.
                if (text.ParagraphsOS.Count < ihvo + 1)
                {
                    return;
                }
                // The surviving paragraph will be the one following the one that is deleted
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvo + 1];
            }
            else
            {
                // If we are deleting the first paragraph in the surviving text, the BT should
                // also be deleted, so we're done.
                if (ihvo == 0 && hvoOwnerSurviving == hvoOwner)
                {
                    return;
                }
                // The surviving paragraph will be the top one in the selection
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvoTop];
            }

            ITsStrBldr bldr;
            ILgWritingSystemFactory wsf;
            List <int> writingSystems = GetWsList(out wsf);

            foreach (ICmTranslation transToDelete in paraToDelete.TranslationsOC)
            {
                // Find or create surviving translation of the same type.
                ICmTranslation transSurviving = paraSurviving.GetOrCreateTrans(transToDelete.TypeRA);

                // Merge back translations of the surviving and paragraph to be deleted for each writing system
                foreach (int ws in writingSystems)
                {
                    TsStringAccessor tssAccToDelete = transToDelete.Translation.GetAlternative(ws);
                    if (tssAccToDelete.Text != null)
                    {
                        TsStringAccessor tssAccSurviving = transSurviving.Translation.GetAlternative(ws);
                        bldr = tssAccSurviving.UnderlyingTsString.GetBldr();

                        // If the surviving paragraph ends with white space of the paragraph to delete
                        // begins with white space, add white space.
                        string textSurviving = bldr.Text;
                        ILgCharacterPropertyEngine charPropEng = m_cache.UnicodeCharProps;
                        if (textSurviving != null &&
                            !charPropEng.get_IsSeparator(textSurviving[textSurviving.Length - 1]) &&
                            !charPropEng.get_IsSeparator(tssAccToDelete.Text[0]))
                        {
                            bldr.ReplaceRgch(textSurviving.Length, textSurviving.Length, " ", 1, null);
                        }

                        int cch = bldr.Length;
                        bldr.ReplaceTsString(cch, cch, tssAccToDelete.UnderlyingTsString);
                        tssAccSurviving.UnderlyingTsString = bldr.GetString();
                    }
                }
            }
        }