public void InsertVerseNumber_AtTitle() { CheckDisposed(); IVwRootBox rootBox = m_draftView.RootBox; rootBox.MakeSimpleSel(true, true, false, true); IVwSelection sel = m_draftView.TeEditingHelper.CurrentSelection.Selection; int tag; int hvoSel; m_draftView.TeEditingHelper.GetSelectedScrElement(out tag, out hvoSel); Assert.AreEqual((int)ScrBook.ScrBookTags.kflidTitle, tag, "First para in view was not a Title"); ITsString tss; int ich; bool fAssocPrev; int hvoObj; int enc; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); string str = tss.Text; m_draftView.InsertVerseNumber(); // may destroy or move selection? Make another one to be sure. rootBox.MakeSimpleSel(true, true, false, true); sel = m_draftView.TeEditingHelper.CurrentSelection.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); string str2 = tss.Text; Assert.AreEqual(str, str2, "Should not have inserted verse num into title para"); }
/// <summary> /// Selects the contents of the whole rootbox. /// </summary> /// <param name="rootb"></param> /// <param name="fEditable">if set to <c>true</c> tries to start and end the selection in an editable field.</param> /// <param name="fInstall">if set to <c>true</c> installs the selection.</param> /// <returns></returns> internal static IVwSelection SelectAll(IVwRootBox rootb, bool fEditable, bool fInstall) { IVwSelection selDocument = null; IVwSelection selStart = rootb.MakeSimpleSel(true, fEditable, false, false); IVwSelection selEnd = rootb.MakeSimpleSel(false, fEditable, false, false); if (selStart != null && selEnd != null) { selDocument = rootb.MakeRangeSelection(selStart, selEnd, fInstall); } return(selDocument); }
public void PasteMultiParasIntoFootnote() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Scripture text", Cache.DefaultVernWs); StFootnote footnote1 = m_scrInMemoryCache.AddFootnote(book, para, 9, "footnote 1"); int footnote1Length = ((StTxtPara)footnote1.ParagraphsOS[0]).Contents.Length; m_hvoRoot = book.Hvo; ShowForm(DummyBasicViewVc.DisplayType.kNormal); IVwRootBox rootBox = m_basicView.RootBox; ITsStrBldr strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "New heading line1", StyleUtils.CharStyleTextProps(null, 1)); strBldr.Replace(strBldr.Length, strBldr.Length, "\r\n", StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph)); strBldr.Replace(strBldr.Length, strBldr.Length, "heading line2\r\nNew heading line3", StyleUtils.CharStyleTextProps(null, 1)); ILgWritingSystemFactory wsf = rootBox.DataAccess.WritingSystemFactory; ILgTsStringPlusWss tssencs = LgTsStringPlusWssClass.Create(); tssencs.set_String(wsf, strBldr.GetString()); m_dobjClipboard = LgTsDataObjectClass.Create(); m_dobjClipboard.Init(tssencs); Clipboard.SetDataObject(m_dobjClipboard, false); // Make selection at the end of the footnote rootBox.MakeSimpleSel(false, true, false, true); // Paste contents of clipboard at current selection. m_basicView.EditingHelper.PasteClipboard(true); // We expect that the footnote will only have one paragraph with the extra paragraphs // in the paragraph ignored. Assert.AreEqual(1, footnote1.ParagraphsOS.Count); Assert.AreEqual("footnote 1New heading line1", ((StTxtPara)footnote1.ParagraphsOS[0]).Contents.Text); }
public void VerifyParagraphStyleApplied() { CheckDisposed(); // ENHANCE (EberhardB): This test could be in unit tests. But right now we don't // have a view that has styles associated with it. DummyDraftView draftView = m_draftForm.DraftView; IVwRootBox rootBox = draftView.RootBox; // 1. Test: IP at end of text rootBox.MakeSimpleSel(false, true, false, true); // set IP at end of text IVwSelection sel; ITsTextProps[] vttp; IVwPropertyStore[] vvps; int hvoText, tagText, ihvoFirst, ihvoLast; draftView.GetParagraphProps(out sel, out hvoText, out tagText, out vvps, out ihvoFirst, out ihvoLast, out vttp); Assert.AreEqual(1, vttp.Length); if (vttp[0] != null) // null is a valid value, so don't check that { string oldStyle = vttp[0].GetStrPropValue((int)VwStyleProperty.kspNamedStyle); Assert.IsFalse(oldStyle == "Quote", "Database not in expected state."); } draftView.EditingHelper.ApplyParagraphStyle("Quote"); draftView.GetParagraphProps(out sel, out hvoText, out tagText, out vvps, out ihvoFirst, out ihvoLast, out vttp); Assert.AreEqual(1, vttp.Length); string newStyle = vttp[0].GetStrPropValue((int)VwStyleProperty.kspNamedStyle); Assert.AreEqual("Quote", newStyle, "The style was not applied correctly."); // This doesn't work at the moment, so no test for that right now. // // // 2. Test: selection across multiple sections // SelectionHelper selAnchor = draftView.SelectRangeOfChars(2, 3, 4, 0, 0); // SelectionHelper selEnd = draftView.SelectRangeOfChars(2, 5, 0, 114, 114); // IVwSelection vwSel = draftView.RootBox.MakeRangeSelection(selAnchor.Selection, // selEnd.Selection, true); }
public void PasteMultiParasIntoFootnote() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); IScrSection section = AddSectionToMockedBook(book); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "Scripture text", Cache.DefaultVernWs); IStFootnote footnote1 = AddFootnote(book, para, 9, "footnote 1"); int footnote1Length = ((IStTxtPara)footnote1.ParagraphsOS[0]).Contents.Length; m_hvoRoot = Cache.LangProject.TranslatedScriptureOA.Hvo; ShowForm(DummyBasicViewVc.DisplayType.kNormal); IVwRootBox rootBox = m_basicView.RootBox; ITsStrBldr strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "New heading line1", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); strBldr.Replace(strBldr.Length, strBldr.Length, Environment.NewLine, StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph)); strBldr.Replace(strBldr.Length, strBldr.Length, "heading line2" + Environment.NewLine + "New heading line3", StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); EditingHelper.SetTsStringOnClipboard(strBldr.GetString(), false, Cache.WritingSystemFactory); // Make selection at the end of the footnote Assert.IsNotNull(rootBox.MakeSimpleSel(false, true, false, true)); // Paste contents of clipboard at current selection. m_basicView.EditingHelper.PasteClipboard(); // We expect that the footnote will only have one paragraph with the extra paragraphs // concatenated, separated with spaces. Assert.AreEqual(1, footnote1.ParagraphsOS.Count); Assert.AreEqual("footnote 1New heading line1 heading line2 New heading line3", ((IStTxtPara)footnote1.ParagraphsOS[0]).Contents.Text); }
/// <summary> /// Selects the contents of the whole rootbox. /// </summary> /// <param name="rootb"></param> /// <param name="fEditable">if set to <c>true</c> tries to start and end the selection in an editable field.</param> /// <param name="fInstall">if set to <c>true</c> installs the selection.</param> /// <returns></returns> internal static IVwSelection SelectAll(IVwRootBox rootb, bool fEditable, bool fInstall) { IVwSelection selDocument = null; IVwSelection selStart = rootb.MakeSimpleSel(true, fEditable, false, false); IVwSelection selEnd = rootb.MakeSimpleSel(false, fEditable, false, false); if (selStart != null && selEnd != null) selDocument = rootb.MakeRangeSelection(selStart, selEnd, fInstall); return selDocument; }
private void SelectAndScrollToCurrentRecord() { bool fOldForce = BaseVirtualHandler.ForceBulkLoadIfPossible; // Scroll the display to the given record. (See LT-927 for explanation.) try { BaseVirtualHandler.ForceBulkLoadIfPossible = true; // disable "compute-every-time" // Todo JohnT: move IP to specified record. (The following code does this, // but makes a range selection of the entire object instead of an IP.) // Also override HandleSelChange to update current record. RecordClerk clerk = Clerk; IVwRootBox rootb = (m_mainView as IVwRootSite).RootBox; if (rootb != null) { int idx = clerk.CurrentIndex; if (idx < 0) { return; } // Review JohnT: is there a better way to obtain the needed rgvsli[]? IVwSelection sel = rootb.Selection; if (sel == null) { sel = rootb.MakeSimpleSel(true, false, false, true); } int cvsli = sel.CLevels(false) - 1; // Out variables for AllTextSelInfo. int ihvoRoot; int tagTextProp; int cpropPrevious; int ichAnchor; int ichEnd; int ws; bool fAssocPrev; int ihvoEnd; ITsTextProps ttpBogus; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttpBogus); rgvsli[cvsli - 1].ihvo = idx; sel = rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, true); if (sel == null) { // If the current selection is in a property that the new selection // lacks, making the selection can fail. If that happens, try again at // a higher level. See LT-6011. int cvsliNew = cvsli - 1; while (sel == null && cvsliNew > 0) { // Shift the SelLevInfo values down one place in the array, getting // rid of the first one. for (int i = 1; i <= cvsliNew; ++i) { rgvsli[i - 1] = rgvsli[i]; } sel = rootb.MakeTextSelInObj(ihvoRoot, cvsliNew, rgvsli, 0, null, false, false, false, true, true); --cvsliNew; } } // TODO: implement and use kssoCenter. (m_mainView as IVwRootSite).ScrollSelectionIntoView(sel, VwScrollSelOpts.kssoDefault); // It's a pity this next step is needed! rootb.Activate(VwSelectionState.vssEnabled); } } catch { // not much we can do to handle errors, but don't let the program die just // because the display hasn't yet been laid out, so selections can't fully be // created and displayed. } finally { BaseVirtualHandler.ForceBulkLoadIfPossible = fOldForce; // reenable "compute-every-time" } }