public void GoToNextPara_MultiParaRangeSelection() { ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal | SimpleViewVc.DisplayType.kDuplicateParagraphs); m_basicView.Show(); m_basicView.RefreshDisplay(); m_SelectionHelper = new DummySelectionHelper(null, m_basicView); // Make a bottom-up selection, just to be sure we're not using the anchor instead of // the top. SetSelection(0, 0, 0, 0, 2, 1, 1, false); // Set end SetSelection(0, 1, 0, 0, 1, 12, 12, true); // Set anchor IVwSelection vwsel = m_SelectionHelper.SetSelection(true); Assert.IsNotNull(vwsel, "No selection made"); m_basicView.EditingHelper.GoToNextPara(); // We expect that the selection will be at the start of the second paragraph in // the selected range. SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView); Assert.IsFalse(selectionHelper.IsRange); CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0, 0, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 0, SimpleRootsiteTestsConstants.kflidTextParas, 1, 0); }
public void GoToNextPara_NextFlid() { // Add a title to the root object int hvoTitle = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStText, m_hvoRoot, SimpleRootsiteTestsConstants.kflidDocTitle, -2); int hvoTitlePara = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 0); m_cache.CacheStringProp(hvoTitlePara, SimpleRootsiteTestsConstants.kflidParaContents, TsStringUtils.MakeString("The First Book of the Law given by Moses", m_wsFrn)); ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal | SimpleViewVc.DisplayType.kTitle); m_basicView.Show(); m_basicView.RefreshDisplay(); // Set the IP at the beginning of the only (0th) instance of the only (0th) paragraph // of the only (0th) instance of the second (1th) footnote of the book we're displaying. m_SelectionHelper = new DummySelectionHelper(null, m_basicView); SetSelection(0, 1, 0, 0, 2, 0, 0, true); IVwSelection vwsel = m_SelectionHelper.SetSelection(true); Assert.IsNotNull(vwsel, "No selection made"); Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible"); m_basicView.EditingHelper.GoToNextPara(); // We expect that the selection will be at the start of the book title. SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView); Assert.IsFalse(selectionHelper.IsRange); CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0, 0, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocTitle, 0, 0, SimpleRootsiteTestsConstants.kflidTextParas, 0, 0); }
public void GoToNextPara_LastParaInView() { ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal | SimpleViewVc.DisplayType.kDuplicateParagraphs); m_basicView.Show(); m_basicView.RefreshDisplay(); m_SelectionHelper = new DummySelectionHelper(null, m_basicView); SetSelection(0, 1, 1, 0, 2, 6, 0, true); IVwSelection vwsel = m_SelectionHelper.SetSelection(true); Assert.IsNotNull(vwsel, "No selection made"); Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible"); m_basicView.EditingHelper.GoToNextPara(); // We expect that the selection will be unchanged. SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView); Assert.IsTrue(selectionHelper.IsRange); CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0, 2, 6, 0, true, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 1, SimpleRootsiteTestsConstants.kflidTextParas, 1, 0); CheckSelectionHelperValues(SelectionHelper.SelLimitType.End, selectionHelper, 0, 2, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 1, SimpleRootsiteTestsConstants.kflidTextParas, 1, 0); }
public void ReadOnlySpaceAfterFootnoteMarker() { // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); using (Form form = new Form()) using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache)) { footnoteView.StyleSheet = styleSheet; footnoteView.Dock = DockStyle.Fill; footnoteView.Name = "footnoteView"; footnoteView.Visible = true; form.Controls.Add(footnoteView); form.Show(); try { // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // make sure the marker and the space are read-only and the paragraph not. ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); Assert.IsTrue(cttp >= 3); Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), "Footnote marker is not read-only"); Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), "Space after marker is not read-only"); Assert.IsTrue(SelectionHelper.IsEditable(vttp[2], vvps[2]), "Footnote text is read-only"); Assert.IsTrue(SelectionHelper.IsEditable(vttp[3], vvps[3]), "Footnote text is read-only"); } finally { form.Close(); } } }
public void GetStyleNameFromSelectionTest() { CheckDisposed(); string styleName; // Select a verse number (Phm 1:17) and hope for a character style name. m_draftForm.DraftView.GotoVerse(new ScrReference(57, 1, 17, Paratext.ScrVers.English)); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, m_draftForm.DraftView); selHelper.IchAnchor -= 2; selHelper.SetSelection(m_draftForm.DraftView); int type = m_draftForm.DraftView.EditingHelper.GetStyleNameFromSelection(out styleName); Assert.AreEqual((int)StyleType.kstCharacter, type); Assert.AreEqual("Verse Number", styleName); // Select some text containing a verse number and some text following selHelper.IchAnchor++; selHelper.IchEnd += 8; IVwSelection vwsel = vwsel = selHelper.SetSelection(m_draftForm.DraftView); type = m_draftForm.DraftView.EditingHelper.GetStyleNameFromSelection(out styleName); Assert.AreEqual((int)StyleType.kstParagraph, type); Assert.AreEqual("Paragraph", styleName); // Select multiple paragraphs having different paragraph styles IVwSelection vwsel2 = null; int iBook = selHelper.LevelInfo[3].ihvo; int iSection = selHelper.LevelInfo[2].ihvo - 1; m_draftForm.DraftView.SelectRangeOfChars(iBook, iSection, 0, 1, 2, false, false, out vwsel2); m_draftForm.DraftView.RootBox.MakeRangeSelection(vwsel, vwsel2, true); type = m_draftForm.DraftView.EditingHelper.GetStyleNameFromSelection(out styleName); Assert.AreEqual(-1, type); Assert.AreEqual(null, styleName); // Select multiple paragraphs having the same paragraph styles m_draftForm.DraftView.SelectRangeOfChars(iBook, 3, 0, 30, 40, false, false, out vwsel); m_draftForm.DraftView.SelectRangeOfChars(iBook, 3, 1, 0, 40, false, false, out vwsel2); m_draftForm.DraftView.RootBox.MakeRangeSelection(vwsel, vwsel2, true); type = m_draftForm.DraftView.EditingHelper.GetStyleNameFromSelection(out styleName); Assert.AreEqual((int)StyleType.kstParagraph, type); Assert.AreEqual("Paragraph", styleName); }
public void SpaceAfterFootnoteMarker() { IScrBook book = m_scr.ScriptureBooksOS[0]; IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote"); footnote.FootnoteMarker = Cache.TsStrFactory.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en")); // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // make sure the marker and the space are read-only (maybe have to select each run // separately to make this test truly correct) ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); Assert.IsTrue(cttp >= 2); Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), "Footnote marker is not read-only"); Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), "Space after marker is not read-only"); } }
public void SpaceAfterFootnoteMarker() { // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(m_fdoCache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, (int)StTxtPara.StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // // make sure the marker and the space are read-only and the paragraph not. // ITsTextProps[] vttp; // IVwPropertyStore[] vvps; // int cttp; // SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); // Assert.IsTrue(cttp >= 3); // Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), // "Footnote marker is not read-only"); // Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), // "Space after marker is not read-only"); // Assert.IsTrue(SelectionHelper.IsEditable(vttp[2], vvps[2]), // "Footnote text is read-only"); // Assert.IsTrue(SelectionHelper.IsEditable(vttp[3], vvps[3]), // "Footnote text is read-only"); } }
public void BackspaceInNewParagraphBug() { CheckDisposed(); // Set IP at the beginning of a paragraph (the one containing Philemon 1:17). // Then press backspace. This should merge the last paragraph with the one before, // so the IP should no longer be at the beginning of the paragraph. DummyDraftView draftView = m_draftForm.DraftView; draftView.GotoVerse(new ScrReference(57, 1, 17, Paratext.ScrVers.English)); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, draftView); selHelper.IchAnchor = selHelper.IchEnd = 0; IVwSelection vwsel = selHelper.SetSelection(draftView); draftView.HandleKeyPress('\b', false); selHelper = SelectionHelper.GetSelectionInfo(null, draftView); Assert.IsFalse(selHelper.IchAnchor == 0); Assert.IsFalse(selHelper.IchEnd == 0); }
public void GoToNextPara_FirstFlidInNextObject() { ShowForm(Lng.English, SimpleViewVc.DisplayType.kFootnoteDetailsSeparateParas); m_basicView.Show(); m_basicView.RefreshDisplay(); m_SelectionHelper = new DummySelectionHelper(null, m_basicView); SetSelection(0, 0, 0, 0, 0, 0, 0, true); IVwSelection vwsel = m_SelectionHelper.SetSelection(true); Assert.IsNotNull(vwsel, "No selection made"); Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible"); m_basicView.EditingHelper.GoToNextPara(); // We expect that the selection will be at the start of the second footnote's marker. SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView); Assert.IsFalse(selectionHelper.IsRange); CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0, 0, 0, 0, false, 1, -1, -1, -1, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 1); }
public void FootnoteTranslationTest() { // get an existing footnote IScrBook book = m_scr.ScriptureBooksOS[1]; // book of James IStFootnote footnote = book.FootnotesOS[0]; StTxtPara para = (StTxtPara)footnote.ParagraphsOS[0]; // add a translation to the footnote ICmTranslation translation = para.GetOrCreateBT(); translation.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString = TsStringHelper.MakeTSS("abcde", m_fdoCache.DefaultAnalWs); FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(m_fdoCache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); // Prepare the test by creating a footnote view using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache, true)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, true, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord(); ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("abcde", tss.Text); } }
/// <summary> /// The user has attempted to delete something which the system does not inherently /// know how to delete. If the problem is a "complex range", then try to delete one /// object from the vector displayed in the entry sequence. /// </summary> public override VwDelProbResponse OnProblemDeletion(IVwSelection sel, VwDelProbType dpt) { if (dpt == VwDelProbType.kdptComplexRange) { var helper = SelectionHelper.GetSelectionInfo(sel, this); var clev = helper.NumberOfLevels; var rginfo = helper.LevelInfo; var info = rginfo[clev - 1]; ICmObject cmo; if (info.tag == m_rootFlid && m_cache.ServiceLocator.ObjectRepository.TryGetObject(info.hvo, out cmo)) { var sda = m_cache.DomainDataByFlid as ISilDataAccessManaged; Debug.Assert(sda != null); var rghvos = sda.VecProp(m_rootObj.Hvo, m_rootFlid); var ihvo = -1; for (var i = 0; i < rghvos.Length; ++i) { if (rghvos[i] == cmo.Hvo) { ihvo = i; break; } } if (ihvo >= 0) { var startHeight = m_rootb.Height; if (Cache.MetaDataCacheAccessor.get_IsVirtual(m_rootFlid)) { var obj = m_cache.ServiceLocator.GetObject(rghvos[ihvo]); ILexEntryRef ler = null; if (obj is ILexEntry) { var complex = (ILexEntry)obj; // the selected object in the list is a complex entry which has this as one of // its components. We want to remove this from its components. foreach (var item in complex.EntryRefsOS) { switch (item.RefType) { case LexEntryRefTags.krtComplexForm: case LexEntryRefTags.krtVariant: ler = item; break; default: throw new Exception("Unexpected LexEntryRef type in EntrySequenceVectorReferenceView.OnProblemDeletion"); } } } else if (obj is ILexEntryRef) { ler = (ILexEntryRef)obj; } else { return(VwDelProbResponse.kdprAbort); // we don't know how to delete it. } var fieldName = m_cache.MetaDataCacheAccessor.GetFieldName(m_rootFlid); if (fieldName == "Subentries") { ler.PrimaryLexemesRS.Remove(m_rootObj); } else if (fieldName == "VisibleComplexFormEntries" || fieldName == "VisibleComplexFormBackRefs") { ler.ShowComplexFormsInRS.Remove(m_rootObj); } else if (fieldName == "VariantFormEntries") { ler.ComponentLexemesRS.Remove(m_rootObj); } } else { sda.Replace(m_rootObj.Hvo, m_rootFlid, ihvo, ihvo + 1, new int[0], 0); } if (m_rootb != null) { CheckViewSizeChanged(startHeight, m_rootb.Height); // Redisplay (?) the vector property. m_rootb.SetRootObject(m_rootObj.Hvo, m_VectorReferenceVc, kfragTargetVector, m_rootb.Stylesheet); } return(VwDelProbResponse.kdprDone); } } } return(base.OnProblemDeletion(sel, dpt)); }
private void GetStyleNames(SimpleRootSite rootsite, IVwSelection sel, ref string paraStyleName, ref string charStyleName) { ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); bool fSingleStyle = true; string sStyle = null; for (int ittp = 0; ittp < cttp; ++ittp) { string style = vttp[ittp].Style(); if (ittp == 0) { sStyle = style; } else if (sStyle != style) { fSingleStyle = false; } } if (fSingleStyle && !String.IsNullOrEmpty(sStyle)) { if (ActiveStyleSheet.GetType(sStyle) == (int)StyleType.kstCharacter) { if (sel.CanFormatChar) { charStyleName = sStyle; } } else { if (sel.CanFormatPara) { paraStyleName = sStyle; } } } if (paraStyleName == null) { // Look at the paragraph (if there is one) to get the paragraph style. var helper = SelectionHelper.GetSelectionInfo(sel, rootsite); var info = helper.GetLevelInfo(SelectionHelper.SelLimitType.End); if (info.Length > 0) { var hvo = info[0].hvo; if (hvo != 0) { var cmObjectRepository = m_callbacks.Cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (cmObjectRepository.IsValidObjectId(hvo)) // perhaps some sort of dummy; we can't get paragraph style. { var cmo = cmObjectRepository.GetObject(hvo); if (cmo is IStPara) { paraStyleName = (cmo as IStPara).StyleName; } } } } } }