示例#1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Attaches the annotated objects to the specifed annotation.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void AttachAnnotatedObjects(IScripture scr, int bookNum,
                                                   IScrScriptureNote scrNote)
        {
            int          iSection, iPara, ichStart, ichEnd;
            ScrReference scrRef = new ScrReference(scrNote.BeginRef, scr.Versification);

            if (TeEditingHelper.FindTextInVerse(scr, scrNote.CitedTextTss,
                                                scrRef, true, out iSection, out iPara, out ichStart, out ichEnd))
            {
                IScrBook book = scr.FindBook(bookNum);
                Debug.Assert(book != null);
                scrNote.BeginOffset = ichStart;
                scrNote.EndOffset   = ichEnd;

                if (iSection == -1)
                {
                    scrNote.BeginObjectRA = scrNote.EndObjectRA = book.TitleOA.ParagraphsOS[iPara];
                }
                else
                {
                    scrNote.BeginObjectRA = scrNote.EndObjectRA =
                        book.SectionsOS[iSection].ContentOA.ParagraphsOS[iPara];
                }
            }
        }
示例#2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Although this view considers itself to have a ContentType of BT, it is helpful
        /// in enabling menu options (that are applicable to the LHS) if we do NOT consider
        /// the editing helper to be a BT one.
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected override RootSiteEditingHelper GetInternalEditingHelper()
        {
            TeEditingHelper result = (TeEditingHelper)base.GetInternalEditingHelper();

            result.ContentType = StVc.ContentTypes.kctNormal;
            return(result);
        }
        /// <summary>
        /// Although this view considers itself to have a ContentType of BT, it is helpful
        /// in enabling menu options (that are applicable to the LHS) if we do NOT consider
        /// the editing helper to be a BT one.
        /// </summary>
        /// <returns></returns>
        protected override EditingHelper GetInternalEditingHelper()
        {
            TeEditingHelper result = base.GetInternalEditingHelper() as TeEditingHelper;

            result.ContentType = StVc.ContentTypes.kctNormal;
            result.EnableBtSegmentUpdate(m_BackTranslationWS);
            return(result);
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exposes InsertFootnote to testing
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public IScrFootnote InsertFootnote(SelectionHelper helper, string paraStyleName)
        {
            CheckDisposed();

            int dummyValue;

            return((IScrFootnote)TeEditingHelper.InsertFootnote(helper, paraStyleName,
                                                                out dummyValue));
        }
示例#5
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>
 /// Initializes a new instance of the <see cref="FootnoteEditingHelper"/> class.
 /// </summary>
 /// <param name="callbacks">implementation of <see cref="IEditingCallbacks"/></param>
 /// <param name="cache">The cache for the DB connection</param>
 /// <param name="filterInstance">The special tag for the book filter</param>
 /// <param name="draftView">The corresponding draftview pane. If we determine that the
 /// "other pane" is supposed to be the other pane in the split window, then this
 /// should be used as the other pane as well.</param>
 /// <param name="viewType">Bit-flags indicating type of view.</param>
 /// <param name="app">The app.</param>
 /// ------------------------------------------------------------------------------------
 public FootnoteEditingHelper(IEditingCallbacks callbacks, FdoCache cache,
                              int filterInstance, FwRootSite draftView, TeViewType viewType, IApp app) :
     base(callbacks, cache, filterInstance, viewType, app)
 {
     m_draftView = draftView;
     if (m_draftView != null)             // can be null for tests
     {
         m_draftViewEditingHelper = m_draftView.EditingHelper as TeEditingHelper;
         Debug.Assert(m_draftViewEditingHelper != null);
     }
 }
示例#7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="FootnoteEditingHelper"/> class.
 /// </summary>
 /// <param name="callbacks">implementation of <see cref="IEditingCallbacks"/></param>
 /// <param name="cache">The cache for the DB connection</param>
 /// <param name="filterInstance">The special tag for the book filter</param>
 /// <param name="draftView">The corresponding draftview pane. If we determine that the
 /// "other pane" is supposed to be the other pane in the split window, then this
 /// should be used as the other pane as well.</param>
 /// <param name="isBacktranslation">if set to <c>true</c> we're dealing with
 /// backtranslations.</param>
 /// ------------------------------------------------------------------------------------
 public FootnoteEditingHelper(IEditingCallbacks callbacks, FdoCache cache,
                              int filterInstance, FwRootSite draftView, bool isBacktranslation) :
     base(callbacks, cache, filterInstance, TeViewType.FootnoteView | TeViewType.Horizontal |
          (isBacktranslation ? TeViewType.BackTranslation : TeViewType.Scripture))
 {
     m_draftView = draftView;
     if (m_draftView != null)             // can be null for tests
     {
         m_draftViewEditingHelper = m_draftView.EditingHelper as TeEditingHelper;
         Debug.Assert(m_draftViewEditingHelper != null);
     }
 }
示例#8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sanity check to ensure the scripture texts are valid.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void EnsureScriptureTextsValid()
        {
            foreach (ScrBook book in m_scr.ScriptureBooksOS)
            {
                int[] sectionHvos = book.SectionsOS.HvoArray;
                // Don't crash if we don't have any sections (TE-5380)
                if (sectionHvos.Length == 0)
                {
                    continue;
                }

                ContextValues sectionContext;
                foreach (ScrSection section in book.SectionsOS)
                {
                    // Check the heading paragraphs.
                    if (section.HeadingOA == null)
                    {
                        m_cache.CreateObject(StText.kClassId, section.Hvo,
                                             (int)ScrSection.ScrSectionTags.kflidHeading, 0);
                    }
                    if (section.HeadingOA.ParagraphsOS.Count == 0)
                    {
                        StTxtPara para = new StTxtPara();
                        section.HeadingOA.ParagraphsOS.Append(para);
                        para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead);
                        sectionContext  = ContextValues.Text;
                    }
                    else
                    {
                        IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules);
                        // style could be null. set default context if possible
                        sectionContext = style == null ? ContextValues.Text : style.Context;
                    }

                    // Check the content paragraphs.
                    if (section.ContentOA == null)
                    {
                        m_cache.CreateObject(StText.kClassId, section.Hvo,
                                             (int)ScrSection.ScrSectionTags.kflidContent, 0);
                    }
                    if (section.ContentOA.ParagraphsOS.Count == 0)
                    {
                        StTxtPara para = new StTxtPara();
                        section.ContentOA.ParagraphsOS.Append(para);
                        para.StyleRules = StyleUtils.ParaStyleTextProps(
                            TeEditingHelper.GetDefaultStyleForContext(sectionContext, false));
                        section.AdjustReferences();
                    }
                }
            }
        }
示例#9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="fDisposeManagedObjs"><c>true</c> to release both managed and unmanaged
        /// resources; <c>false</c> to release only unmanaged resources.</param>
        /// ------------------------------------------------------------------------------------
        private void Dispose(bool fDisposeManagedObjs)
        {
            if (fDisposeManagedObjs)
            {
                if (m_libronixLinker != null)
                {
                    m_libronixLinker.PositionChanged -= m_eventHandler;
                    m_libronixLinker.Dispose();
                }
            }

            m_libronixLinker = null;
            m_eventHandler   = null;
            m_editingHelper  = null;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Method to test creation of a publication view.
        /// </summary>
        /// <param name="pub">The publication.</param>
        /// <param name="viewType">Type of the Translation Editor view.</param>
        /// <returns>
        /// a Scripture publication for the specified view type.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        internal static DummyScripturePublication Create(IPublication pub,
                                                         TeViewType viewType, FwStyleSheet stylesheet)
        {
            if (viewType == TeViewType.BackTranslationParallelPrint)
            {
                Debug.Assert(false, "Not yet implemented.");
                return(null);
            }

            DummyScripturePublication pubControl = new DummyScripturePublication(pub.Cache,
                                                                                 stylesheet, 567, pub, viewType, DateTime.Now);

            pubControl.Anchor = AnchorStyles.Top | AnchorStyles.Left |
                                AnchorStyles.Right | AnchorStyles.Bottom;
            pubControl.Dock    = DockStyle.Fill;
            pubControl.Name    = TeEditingHelper.ViewTypeString(viewType);
            pubControl.Visible = false;
            return(pubControl);
        }
示例#11
0
        public ResolveKeyTermRenderingImportConflictDlg(IWin32Window owner, IChkRef occurrence,
                                                        string existingRendering, string importedRendering, IVwStylesheet ss) : this()
        {
            FdoCache     cache  = occurrence.Cache;
            IScripture   scr    = cache.LangProject.TranslatedScriptureOA;
            ScrReference scrRef = (new ScrReference(occurrence.Ref, scr.Versification));

            m_owner                = owner;
            m_lblAnalysis.Text     = occurrence.OwnerOfClass <IChkTerm>().Name.AnalysisDefaultWritingSystem.Text;
            m_lblOriginal.Text     = occurrence.KeyWord.Text;
            m_lblScrReference.Text = scrRef.ToString();
            m_btnExisting.Text     = String.Format(m_btnExisting.Text, existingRendering);
            m_btnImported.Text     = String.Format(m_btnImported.Text, importedRendering);

            // We do this outside the designer-controlled code because it does funny things
            // to FwMultiParaTextBox, owing to the need for a writing system factory, and some
            // properties it should not persist but I can't persuade it not to.
//			IStText text = new NonEditableMultiTss(TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef).ToString(true, " "));
            //m_verseTextLabel = new FwMultiParaTextBox(text, ss);
            m_verseTextLabel = new FwLabel();
            m_verseTextLabel.WritingSystemFactory = cache.WritingSystemFactory; // set ASAP.
            m_verseTextLabel.WritingSystemCode    = cache.DefaultVernWs;
            m_verseTextLabel.StyleSheet           = ss;                         // before setting text, otherwise it gets confused about height needed.
            m_verseTextLabel.Location             = new Point(0, 0);
            m_verseTextLabel.Name      = "m_textBox";
            m_verseTextLabel.Dock      = DockStyle.Fill;
            m_verseTextLabel.TabIndex  = 0;
            m_verseTextLabel.TextAlign = ContentAlignment.TopLeft;
            //m_verseTextLabel.BorderStyle = BorderStyle.None;
            //m_textBox.SuppressEnter = true;
            m_pnlActualVerseText.Controls.Add(m_verseTextLabel);
            // ENHANCE: Figure out how to get each part (paragraph) of the verse onm its own line. Using newlines or hard line breaks doesn't work.
            ITsIncStrBldr bldr = TsIncStrBldrClass.Create();

            foreach (TeEditingHelper.VerseTextSubstring verseTextSubstring in TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef))
            {
                bldr.AppendTsString(verseTextSubstring.Tss);
                bldr.Append(StringUtils.kChHardLB.ToString());
            }
            m_verseTextLabel.Tss = bldr.GetString();
            //m_verseTextLabel.Tss = TeEditingHelper.GetVerseText(cache.LangProject.TranslatedScriptureOA, scrRef).ToString(true, StringUtils.kChHardLB.ToString());
        }
示例#12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Syncs to the current Scripture reference location of the given editing helper.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="editingHelper">The editing helper of the scripture view in which
        /// the IP location changed.</param>
        /// <param name="fSendInternalOnly"><c>true</c> to indicate that this message should
        /// not be broadcast to external apps (e.g., Libronix and Santa Fe apps).</param>
        /// ------------------------------------------------------------------------------------
        public void SyncToScrLocation(object sender, TeEditingHelper editingHelper,
                                      bool fSendInternalOnly)
        {
            Debug.Assert(editingHelper != null);

            if (m_fIgnoreAnySyncMessages || m_fProcessingSyncMessage)
            {
                return;
            }

            if (ScrEditingLocationChanged != null)
            {
                ScrEditingLocationChanged(sender, editingHelper);
            }

            var scrRef = new ScrReference(editingHelper.CurrentStartRef);

            if (!fSendInternalOnly && (scrRef.Valid || scrRef.IsBookTitle))
            {
                m_refTracker.SetCurrentReference(new ScrReference(scrRef));
                SendExternalSyncMessage(scrRef);
            }
        }
示例#13
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Gets the style name that is the default style to use for the given context
 /// </summary>
 /// <param name="nContext">the context</param>
 /// <param name="fCharStyle">set to <c>true</c> for character styles; otherwise
 /// <c>false</c>.</param>
 /// <returns>
 /// Name of the style that is the default for the context
 /// </returns>
 /// ------------------------------------------------------------------------------------
 public override string GetDefaultStyleForContext(int nContext, bool fCharStyle)
 {
     return(TeEditingHelper.GetDefaultStyleForContext((ContextValues)nContext, fCharStyle));
 }
示例#14
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Exposes <see cref="T:SIL.FieldWorks.TE.TeEditingHelper.HandleMouseDown"/> for
 /// testing Insert Verse Numbers mode.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void InsertVerseNumber()
 {
     CheckDisposed();
     TeEditingHelper.InsertVerseNumber();
 }
示例#15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exposes TeEditingHelper.InsertVerseNumber for testing.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void InsertVerseNumber(SelectionHelper sel)
        {
            CheckDisposed();

            TeEditingHelper.InsertVerseNumber(sel);
        }
示例#16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exposes <see cref="TeEditingHelper.InsertChapterNumber"/> for testing.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void InsertChapterNumber()
        {
            CheckDisposed();

            TeEditingHelper.InsertChapterNumber();
        }
示例#17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exposes <see cref="TeEditingHelper.ResetParagraphStyle"/> to testing
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void ResetParagraphStyle()
        {
            CheckDisposed();

            TeEditingHelper.ResetParagraphStyle();
        }
示例#18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Simulate clicking a Insert Book menu item
        /// </summary>
        /// <param name="nBook">Ordinal number of the book to insert (i.e. one-based book
        /// number).</param>
        /// ------------------------------------------------------------------------------------
        public IScrBook InsertBook(int nBook)
        {
            CheckDisposed();

            return(TeEditingHelper.InsertBook(nBook));
        }
示例#19
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Exposes the OnBackTranslationNextMissingBtFootnoteMkr method
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void CallNextMissingBtFootnoteMarker()
 {
     CheckDisposed();
     TeEditingHelper.GoToNextMissingBtFootnoteMkr(TeEditingHelper);
 }
示例#20
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 ScrollRelevantAnnotationIntoView(TeEditingHelper editingHelper)
        {
            CheckDisposed();

            Debug.Assert(editingHelper != null);
            if (editingHelper.BookIndex < 0)
            {
                return;
            }

            bool fSaveSendSyncScrollMsg = m_fSendSyncScrollMsg;

            try
            {
                m_fSendSyncScrollMsg = false;
                ScrReference scrRef = editingHelper.CurrentStartRef;
                if (!scrRef.Valid)
                {
                    return;                     // No valid reference to scroll to
                }
                ITsString tss          = editingHelper.GetCleanSelectedText();
                string    selectedText = (tss != null ? tss.Text : null);

                // If there's no range selection in scripture and the IP is in the
                // same reference as that of the current annotation, then don't scroll
                // to a different annotation, even if there is another one for the
                // same reference.
                if (selectedText == null && CurrentAnnotation != null &&
                    scrRef == CurrentAnnotation.BeginRef)
                {
                    return;
                }

                selectedText = (selectedText ?? editingHelper.CleanSelectedWord);

                // Try to find the exact annotation associated with the selection.
                if (ScrollToAnnotationByPara(editingHelper, selectedText,
                                             CurrentAnnotation != null && scrRef == CurrentAnnotation.BeginRef))
                {
                    return;
                }

                // When the passed editing helper's selection is in a book title, section heading
                // or intro. material, then find the annotation for that selection's paragraph.
                if (editingHelper.InBookTitle || editingHelper.InSectionHead ||
                    editingHelper.InIntroSection)
                {
                    if (ScrollToNonScrAnnotationByBook(scrRef.Book, selectedText))
                    {
                        return;
                    }
                }

                if (CurrentAnnotation == null || scrRef != CurrentAnnotation.BeginRef)
                {
                    ScrollRefIntoView(scrRef, selectedText);
                }
            }
            finally
            {
                m_fSendSyncScrollMsg = fSaveSendSyncScrollMsg;
            }
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Don't do base class initialization
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected override void Init()
 {
     m_bookFilter          = MockRepository.GenerateMock <FilteredScrBooks>();
     m_mockedEditingHelper = MockRepository.GenerateMock <TeEditingHelper>();
 }
示例#22
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusMessageHandling"/> class.
 /// </summary>
 /// <param name="editingHelper">The editing helper.</param>
 /// ------------------------------------------------------------------------------------
 public FocusMessageHandling(TeEditingHelper editingHelper)
 {
     m_editingHelper = editingHelper;
 }