SetLevelInfo() public method

Sets the array of SelLevInfo.
public SetLevelInfo ( SelLimitType type, SIL.FieldWorks.Common.COMInterfaces.SelLevInfo value ) : void
type SelLimitType type
value SIL.FieldWorks.Common.COMInterfaces.SelLevInfo The level info
return void
Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetupSelectionForRangeAcrossBooks()
        {
            SelectionHelper selHelper = new SelectionHelper();
            selHelper.AssocPrev = true;
            selHelper.NumberOfLevels = 3;

            SelLevInfo[] anchorLevInfo = new SelLevInfo[3];
            anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
            anchorLevInfo[2].ihvo = 1;
            anchorLevInfo[1].tag = ScrBookTags.kflidFootnotes;
            anchorLevInfo[1].ihvo = 31;
            anchorLevInfo[0].tag = StTextTags.kflidParagraphs;
            anchorLevInfo[0].ihvo = 0;
            selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo);
            selHelper.IchAnchor = 1;

            SelLevInfo[] endLevInfo = new SelLevInfo[3];
            endLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
            endLevInfo[2].ihvo = 2;
            endLevInfo[1].tag = ScrBookTags.kflidFootnotes;
            endLevInfo[1].ihvo = 1;
            endLevInfo[0].tag = StTextTags.kflidParagraphs;
            endLevInfo[0].ihvo = 0;
            selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo);
            selHelper.IchEnd = 3;

            // Now that all the preparation to set the selection is done, set it.
            selHelper.SetSelection(m_footnoteView, true, true);
            Application.DoEvents();
        }
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges the paras in table.
		/// </summary>
		/// <param name="helper">The helper.</param>
		/// <param name="dpt">The problem deletion type.</param>
		/// <returns><c>true</c> if we merged the paras, otherwise <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		internal protected bool MergeParasInTable(SelectionHelper helper, VwDelProbType dpt)
		{
			SelLevInfo[] levInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top);
			if (levInfo[0].tag != (int)StText.StTextTags.kflidParagraphs)
				return false;

			ILocationTracker tracker = ((ITeView)Control).LocationTracker;
			IScrBook book = new ScrBook(m_cache, tracker.GetBookHvo(
				helper, SelectionHelper.SelLimitType.Anchor));

			SelLevInfo tmpInfo;
			IStText text;
			if (helper.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidTitle, out tmpInfo))
				text = book.TitleOA;
			else
			{
				IScrSection section = book.SectionsOS[tracker.GetSectionIndexInBook(
					helper,	SelectionHelper.SelLimitType.Anchor)];

				text = (levInfo[1].tag == (int)ScrSection.ScrSectionTags.kflidHeading ?
					section.HeadingOA :	text = section.ContentOA);
			}

			int iPara = helper.GetLevelInfoForTag((int)StText.StTextTags.kflidParagraphs).ihvo;
			StTxtPara currPara = (StTxtPara)text.ParagraphsOS[iPara];
			ITsStrBldr bldr;

			// Backspace at beginning of paragraph
			if (dpt == VwDelProbType.kdptBsAtStartPara)
			{
				if (iPara <= 0)
				{
					MiscUtils.ErrorBeep();
					return false;
				}

				StTxtPara prevPara = (StTxtPara)text.ParagraphsOS[iPara - 1];
				int prevParaLen = prevPara.Contents.Length;

				// Need to make sure we move the back translations
				AboutToDelete(helper, currPara.Hvo, text.Hvo,
					(int)StText.StTextTags.kflidParagraphs, iPara, false);

				bldr = prevPara.Contents.UnderlyingTsString.GetBldr();
				bldr.ReplaceTsString(prevPara.Contents.Length, prevPara.Contents.Length,
					currPara.Contents.UnderlyingTsString);
				prevPara.Contents.UnderlyingTsString = bldr.GetString();
				text.ParagraphsOS.RemoveAt(iPara);
				helper.SetIch(SelectionHelper.SelLimitType.Top, prevParaLen);
				helper.SetIch(SelectionHelper.SelLimitType.Bottom, prevParaLen);
				levInfo[0].ihvo = iPara - 1;
				helper.SetLevelInfo(SelectionHelper.SelLimitType.Top, levInfo);
				helper.SetLevelInfo(SelectionHelper.SelLimitType.Bottom, levInfo);
				helper.SetSelection(true);
				return true;
			}
			// delete at end of a paragraph
			int cParas = text.ParagraphsOS.Count;
			if (iPara + 1 >= cParas)
				return false; // We don't handle merging across StTexts

			StTxtPara nextPara = (StTxtPara)text.ParagraphsOS[iPara + 1];

			// Need to make sure we move the back translations
			AboutToDelete(helper, nextPara.Hvo, text.Hvo,
				(int)StText.StTextTags.kflidParagraphs, iPara + 1, false);

			bldr = currPara.Contents.UnderlyingTsString.GetBldr();
			bldr.ReplaceTsString(currPara.Contents.Length, currPara.Contents.Length,
				nextPara.Contents.UnderlyingTsString);
			currPara.Contents.UnderlyingTsString = bldr.GetString();
			text.ParagraphsOS.RemoveAt(iPara + 1);
			helper.SetSelection(true);
			return true;
		}
Exemplo n.º 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges content of given section into the content of the previous section and then
		/// deletes the given section.
		/// </summary>
		/// <param name="helper"> </param>
		/// <param name="book"></param>
		/// <param name="section"></param>
		/// <param name="ihvoSection"></param>
		/// <param name="fPositionAtEnd">If true position of Selection is placed at end of
		/// paragraph, else at the beginning.</param>
		/// ------------------------------------------------------------------------------------
		private void MergeContentWithPreviousSection(SelectionHelper helper, ScrBook book,
			IScrSection section, int ihvoSection, bool fPositionAtEnd)
		{
			//REVIEW: Can the methods that call this be refactored
			//to use (a refactored?) ScrSection.MergeWithPreviousSection?
			//
			// Get the previous section and move the paragraphs.
			IScrSection sectionPrev = book.SectionsOS[ihvoSection - 1];
			IStText textPrev = sectionPrev.ContentOA;
			ILocationTracker tracker = ((ITeView)Control).LocationTracker;
			int iBook = tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top);
			int cparaPrev = 0;
			if (textPrev == null)
			{
				// Prevent crash when dealing with corrupt database (TE-4869)
				// Since the previous section doesn't have a text, we simply move the entire text
				// object from the current section to the previous section.
				m_cache.ChangeOwner(section.ContentOAHvo, sectionPrev.Hvo,
					(int)ScrSection.ScrSectionTags.kflidContent);
			}
			else
			{
				cparaPrev = textPrev.ParagraphsOS.Count;
				IStText textOldContents = section.ContentOA;
				m_cache.MoveOwningSequence(textOldContents.Hvo, (int)StText.StTextTags.kflidParagraphs,
					0, textOldContents.ParagraphsOS.Count - 1,
					textPrev.Hvo, (int)StText.StTextTags.kflidParagraphs, cparaPrev);
			}
			// protected for some reason...textPrev.ParagraphsOS.Append(text.ParagraphsOS.HvoArray);
			book.SectionsOS.RemoveAt(ihvoSection);
			// Now we have to re-establish a selection. Whatever happens, it will be in the
			// same book as before, and the previous section, and in the body.
			if (InSectionHead || !fPositionAtEnd)
			{
				tracker.SetBookAndSection(helper, SelectionHelper.SelLimitType.Top, iBook,
					ihvoSection - 1);
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag =
					(int)ScrSection.ScrSectionTags.kflidContent;
			}
			Debug.Assert(helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag ==
				(int)ScrSection.ScrSectionTags.kflidContent);

			if (fPositionAtEnd)
			{
				// we want selection at end of last paragraph of old previous section.
				// (That is, at the end of paragraph cparaPrev - 1.)
				Debug.Assert(cparaPrev > 0);
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo = cparaPrev - 1;
				StTxtPara paraPrev = (StTxtPara)(textPrev.ParagraphsOS[cparaPrev - 1]);

				int cchParaPrev = paraPrev.Contents.Length;
				helper.IchAnchor = cchParaPrev;
				helper.IchEnd = cchParaPrev;
				helper.AssocPrev = true;
			}
			else
			{
				// want selection at start of old first paragraph of deleted section.
				// (That is, at the start of paragraph cparaPrev.)
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo = cparaPrev;
				helper.IchAnchor = 0;
				helper.IchEnd = 0;
				helper.AssocPrev = false;
			}
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Bottom,
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top));
			helper.SetSelection(true);
		}
Exemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This is the actual workhorse for all the above methods that allows a selection to
		/// be created.
		/// </summary>
		/// <param name="iBook">The 0-based index of the Scripture book in which to put the
		/// selection</param>
		/// <param name="iSection">The 0-based index of the Scripture section in which to put the
		/// selection</param>
		/// <param name="tag">Indicates whether selection should be made in the section
		/// Heading or Content or in the book title</param>
		/// <param name="isegment">If ContentType == segmentBT, the index of the segment
		/// in which to place the selection; otherwise ignored.</param>
		/// <param name="iPara">The 0-based index of the paragraph in which to put the insertion
		/// point</param>
		/// <param name="startCharacter">The 0-based index of the character at which the
		/// selection begins (or before which the insertion point is to be placed if
		/// startCharacter == endCharacter)</param>
		/// <param name="endCharacter">The character location to end the selection</param>
		/// <param name="fInstall"></param>
		/// <param name="fMakeVisible"></param>
		/// <param name="fAssocPrev">If an insertion point, does it have the properties of the
		/// previous character?</param>
		/// <param name="scrollOption">Where to scroll the selection</param>
		/// <returns>The selection helper</returns>
		/// ------------------------------------------------------------------------------------
		public SelectionHelper SelectRangeOfChars(int iBook, int iSection, int tag,
			int iPara, int isegment, int startCharacter, int endCharacter, bool fInstall, bool fMakeVisible,
			bool fAssocPrev, VwScrollSelOpts scrollOption)
		{
			CheckDisposed();

			if (Callbacks == null || Callbacks.EditedRootBox == null)
				return null;  // can't make a selection

			Debug.Assert(tag == (int)ScrSection.ScrSectionTags.kflidHeading ||
				tag == (int)ScrSection.ScrSectionTags.kflidContent ||
				tag == (int)ScrBook.ScrBookTags.kflidTitle);

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = ((ITeView)Control).LocationTracker.GetLevelCount(tag);
			int levelForPara = LocationTrackerImpl.GetLevelIndexForTag((int)StText.StTextTags.kflidParagraphs,
				m_contentType);

			selHelper.LevelInfo[levelForPara].ihvo = iPara;
			selHelper.LevelInfo[levelForPara + 1].tag = tag;

			((ITeView)Control).LocationTracker.SetBookAndSection(selHelper,
				SelectionHelper.SelLimitType.Anchor, iBook,
				tag == (int)ScrBook.ScrBookTags.kflidTitle ? -1 : iSection);

			if (ContentType == StVc.ContentTypes.kctSimpleBT)
			{
				int levelForBT = LocationTrackerImpl.GetLevelIndexForTag((int)StTxtPara.StTxtParaTags.kflidTranslations,
					m_contentType);
				selHelper.LevelInfo[levelForBT].tag = -1;
				selHelper.LevelInfo[levelForBT].ihvo = 0;
				selHelper.LevelInfo[levelForPara].tag = (int)StText.StTextTags.kflidParagraphs;
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
					(int)CmTranslation.CmTranslationTags.kflidTranslation);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.End,
					(int)CmTranslation.CmTranslationTags.kflidTranslation);
			}
			else if (ContentType == StVc.ContentTypes.kctSegmentBT)
			{
				// In all segment BT views, under the paragraph there is a segment, and under that
				// an object which is the free translation itself.
				selHelper.LevelInfo[2].tag = (int) StText.StTextTags.kflidParagraphs; // JohnT: why don't we need this for non-BT??
				selHelper.LevelInfo[1].ihvo = isegment;
				selHelper.LevelInfo[1].tag = StTxtPara.SegmentsFlid(Cache);
				selHelper.LevelInfo[0].ihvo = 0; // not a sequence.
				selHelper.LevelInfo[0].tag = StTxtPara.SegmentFreeTranslationFlid(Cache);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
					(int)CmAnnotation.CmAnnotationTags.kflidComment);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.End,
					(int)CmAnnotation.CmAnnotationTags.kflidComment);
			}
			// else	selHelper.LevelInfo[0].tag is set automatically by SelectionHelper class

			selHelper.AssocPrev = fAssocPrev;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selHelper.LevelInfo);

			// Prepare to move the IP to the specified character in the paragraph.
			selHelper.IchAnchor = startCharacter;
			selHelper.IchEnd = endCharacter;

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(Callbacks.EditedRootBox.Site, fInstall,
				fMakeVisible, scrollOption);

			// If the selection fails, then try selecting the user prompt.
			if (vwsel == null)
			{
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, SimpleRootSite.kTagUserPrompt);
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, SimpleRootSite.kTagUserPrompt);
				vwsel = selHelper.SetSelection(Callbacks.EditedRootBox.Site, fInstall, fMakeVisible,
					scrollOption);
			}

			if (vwsel == null)
			{
				Debug.WriteLine("SetSelection failed in TeEditinHelper.SelectRangeOfChars()");
			}

			return selHelper;
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Makes a selection in a picture caption.
		/// </summary>
		/// <param name="iBook">The 0-based index of the Scripture book in which to put the
		/// insertion point</param>
		/// <param name="iSection">The 0-based index of the Scripture section in which to put the
		/// insertion point</param>
		/// <param name="tag">Indicates whether the picture ORC is in the section
		/// Heading or Content, the book title</param>
		/// <param name="iPara">The 0-based index of the paragraph containing the ORC</param>
		/// <param name="ichOrcPos">The character position of the orc in the paragraph.</param>
		/// <param name="startCharacter">The 0-based index of the character at which the
		/// selection begins (or before which the insertion point is to be placed if
		/// startCharacter == endCharacter)</param>
		/// <param name="endCharacter">The character location to end the selection</param>
		/// <exception cref="Exception">Requested selection could not be made in the picture
		/// caption.</exception>
		/// ------------------------------------------------------------------------------------
		public void MakeSelectionInPictureCaption(int iBook, int iSection, int tag,
			int iPara, int ichOrcPos, int startCharacter, int endCharacter)
		{
			CheckDisposed();

			if (Callbacks == null || Callbacks.EditedRootBox == null)
				throw new Exception("Requested selection could not be made in the picture caption.");

			Debug.Assert(tag == (int)ScrSection.ScrSectionTags.kflidHeading ||
				tag == (int)ScrSection.ScrSectionTags.kflidContent ||
				tag == (int)ScrBook.ScrBookTags.kflidTitle);
			Debug.Assert(!IsBackTranslation, "ENHANCE: This code not designed to make a selection in the BT of a picture caption");

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = ((ITeView)Control).LocationTracker.GetLevelCount(tag) + 1;
			int levelForPara = LocationTrackerImpl.GetLevelIndexForTag(
				(int)StText.StTextTags.kflidParagraphs, StVc.ContentTypes.kctNormal) + 1;
			int levelForCaption = LocationTrackerImpl.GetLevelIndexForTag(
				(int)CmPicture.CmPictureTags.kflidCaption, StVc.ContentTypes.kctNormal);
			selHelper.LevelInfo[levelForCaption].ihvo = -1;
			selHelper.LevelInfo[levelForCaption].ich = ichOrcPos;
			selHelper.LevelInfo[levelForCaption].tag = (int)StTxtPara.StTxtParaTags.kflidContents;
			selHelper.Ws = m_cache.DefaultVernWs;
			selHelper.LevelInfo[levelForPara].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.LevelInfo[levelForPara].ihvo = iPara;
			selHelper.LevelInfo[levelForPara + 1].tag = tag;

			((ITeView)Control).LocationTracker.SetBookAndSection(selHelper,
				SelectionHelper.SelLimitType.Anchor, iBook,
				tag == (int)ScrBook.ScrBookTags.kflidTitle ? -1 : iSection);

			selHelper.AssocPrev = true;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selHelper.LevelInfo);

			// Prepare to move the IP to the specified character in the paragraph.
			selHelper.IchAnchor = startCharacter;
			selHelper.IchEnd = endCharacter;
			selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)CmPicture.CmPictureTags.kflidCaption);
			selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, (int)CmPicture.CmPictureTags.kflidCaption);

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(Callbacks.EditedRootBox.Site, true,
				true, VwScrollSelOpts.kssoDefault);

			if (vwsel == null)
				throw new Exception("Requested selection could not be made in the picture caption.");

			Application.DoEvents(); // REVIEW: Do we need this? Why?
		}
Exemplo n.º 6
0
		public void CanInsertNumberInElement_TrueAtStartOfScripture()
		{
			IScrBook book = AddBookToMockedScripture(1, "Gen");
			IScrSection section = AddSectionToMockedBook(book);
			IStTxtPara para = AddParaToMockedSectionContent(section, "bla");
			// Simulate IP in section content
			// TODO (TE-2740): Don't allow numbers to be inserted in intro material
			SelLevInfo[] levInfo = new SelLevInfo[2];
			levInfo[0].tag = ScrSectionTags.kflidContent;
			levInfo[0].hvo = para.Owner.Hvo; // arbitrary HVO to prevent assert in production code
			SelectionHelper helper = new SelectionHelper();
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, levInfo);
			helper.TextPropId = StTxtParaTags.kflidContents;

			m_TeEditingHelper.SelectionForTesting = helper;

			Assert.IsTrue(m_TeEditingHelper.CanInsertNumberInElement,
				"CanInsertNumberInElement should be true at the start of Scripture.");
		}
Exemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a range selection (adapted from TePrintLayout.cs).
		/// </summary>
		/// <param name="rootbox">The rootbox.</param>
		/// <param name="iPara">The 0-based index of the paragraph in which to put the insertion
		/// point</param>
		/// <param name="startCharacter">The 0-based index of the character at which the
		/// selection begins (or before which the insertion point is to be placed if
		/// startCharacter == endCharacter)</param>
		/// <param name="endCharacter">The character location to end the selection</param>
		/// <returns>The selection helper</returns>
		/// ------------------------------------------------------------------------------------
		private SelectionHelper SelectRangeOfChars(IVwRootBox rootbox, int iPara,
			int startCharacter, int endCharacter)
		{
			if (rootbox == null)
				return null;  // can't make a selection

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 1;

			selHelper.LevelInfo[0].ihvo = iPara;
			selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.AssocPrev = true;

			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selHelper.LevelInfo);

			// Prepare to move the IP to the specified character in the paragraph.
			selHelper.IchAnchor = startCharacter;
			selHelper.IchEnd = endCharacter;

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(rootbox.Site, true, false,
				VwScrollSelOpts.kssoDefault);

			Assert.IsNotNull(vwsel);
			Application.DoEvents();

			return selHelper;
		}
Exemplo n.º 8
0
		public void CanInsertNumberInElement_TrueAtStartOfScripture()
		{
			CheckDisposed();

			// Simulate IP in section content
			// TODO (TE-2740): Don't allow numbers to be inserted in intro material
			SelLevInfo[] levInfo = new SelLevInfo[2];
			levInfo[0].tag = (int)ScrSection.ScrSectionTags.kflidContent;
			levInfo[0].hvo = Cache.LangProject.Hvo; // arbitrary HVO to prevent assert in production code
			SelectionHelper helper = new SelectionHelper();
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, levInfo);
			m_TeEditingHelper.SelectionForTesting = helper;

			Assert.IsTrue(m_TeEditingHelper.CanInsertNumberInElement,
				"CanInsertNumberInElement should be true at the start of Scripture.");
		}
Exemplo n.º 9
0
		public void CanInsertNumberInElement_FalseInSectionHeading()
		{
			CheckDisposed();

			// Simulate IP in a section heading
			SelLevInfo[] levInfo = new SelLevInfo[2];
			levInfo[0].tag = (int)ScrSection.ScrSectionTags.kflidHeading;
			levInfo[0].hvo = Cache.LangProject.Hvo; // arbitrary HVO to prevent assert in production code
			SelectionHelper helper = new SelectionHelper();
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, levInfo);
			m_TeEditingHelper.SelectionForTesting = helper;

			Assert.IsFalse(m_TeEditingHelper.CanInsertNumberInElement,
				"CanInsertNumberInElement should be false in a section heading");
		}
Exemplo n.º 10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the displayed text for a footnote.
		/// </summary>
		/// <param name="iBook">Index of the book the footnote is in</param>
		/// <param name="iFootnote">Index of the footnote</param>
		/// <param name="footnote">The footnote object</param>
		/// <returns>The TsString representing the text of the footnote, including any displayed
		/// marker, reference, etc.</returns>
		/// ------------------------------------------------------------------------------------
		public ITsString GetDisplayedTextForFootnote(int iBook, int iFootnote,
			StFootnote footnote)
		{
			SelectionHelper helper = new SelectionHelper();

			// Create selection in footnote marker
			SelLevInfo[] anchorLevInfo = new SelLevInfo[4];
			anchorLevInfo[3].tag = BookFilter.Tag;
			anchorLevInfo[3].ihvo = iBook;
			anchorLevInfo[2].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			anchorLevInfo[2].ihvo = iFootnote;
			anchorLevInfo[1].tag = (int)StText.StTextTags.kflidParagraphs;
			anchorLevInfo[1].ihvo = 0;
			anchorLevInfo[0].tag = -1;
			anchorLevInfo[0].ihvo = 0;
			helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo);
			helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
				(int)VwSpecialAttrTags.ktagGapInAttrs);
			helper.IchAnchor = 0;

			SelLevInfo[] endLevInfo = new SelLevInfo[3];
			endLevInfo[2].tag = BookFilter.Tag;
			endLevInfo[2].ihvo = iBook;
			endLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			endLevInfo[1].ihvo = iFootnote;
			endLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			endLevInfo[0].ihvo = 0;
			helper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo);
			helper.SetTextPropId(SelectionHelper.SelLimitType.End,
				(int)StTxtPara.StTxtParaTags.kflidContents);
			string footnoteText = ((StTxtPara)footnote.ParagraphsOS[0]).Contents.Text;
			helper.IchEnd = footnoteText.Length;

			helper.SetSelection(this, true, true);

			IVwSelection sel = RootBox.Selection;
			ITsString tss;
			sel.GetSelectionString(out tss, string.Empty);
			return tss;
		}
Exemplo n.º 11
0
		public void DeleteFootnoteFromContextMenuRangeSelection()
		{
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = true;
			selHelper.NumberOfLevels = 3;

			SelLevInfo[] anchorLevInfo = new SelLevInfo[3];
			anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			anchorLevInfo[2].ihvo = 1;
			anchorLevInfo[1].tag = ScrBookTags.kflidFootnotes;
			anchorLevInfo[1].ihvo = 2;
			anchorLevInfo[0].tag = StTextTags.kflidParagraphs;
			anchorLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo);
			selHelper.IchAnchor = 1;
			selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, StTxtParaTags.kflidContents);

			SelLevInfo[] endLevInfo = new SelLevInfo[3];
			endLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			endLevInfo[2].ihvo = 1;
			endLevInfo[1].tag = ScrBookTags.kflidFootnotes;
			endLevInfo[1].ihvo = 6;
			endLevInfo[0].tag = StTextTags.kflidParagraphs;
			endLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo);
			selHelper.IchEnd = 7;
			selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents);

			// Now that all the preparation to set the selection is done, set it.
			selHelper.SetSelection(m_footnoteView, true, true);
			Application.DoEvents();

			// First get the footnotes we're deleting.
			IScrFootnote[] footnotes = new IScrFootnote[5];
			Guid[] guidFootnotes = new Guid[5];
			IStTxtPara[] paras = new IStTxtPara[5];
			for (int i = 0; i < 5; i++)
			{
				footnotes[i] = Cache.ServiceLocator.GetInstance<IScrFootnoteRepository>().GetObject(m_Jude.FootnotesOS[i + 2].Hvo);
				guidFootnotes[i] = footnotes[i].Guid;
				paras[i] = footnotes[i].ParaContainingOrcRA;
			}

			m_footnoteView.DeleteFootnote();

			foreach (IScrFootnote footnote in footnotes)
				Assert.IsFalse(footnote.IsValidObject);

			// now make sure that we don't find the footnote markers
			for (int i = 0; i < 5; i++)
			{
				VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i]);
				VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsEn);
				VerifyRemovedFootnoteMarker(paras[i], guidFootnotes[i], m_wsDe);
			}
		}
Exemplo n.º 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Merges the paras in table.
		/// </summary>
		/// <param name="helper">The helper.</param>
		/// <param name="dpt">The problem deletion type.</param>
		/// <returns><c>true</c> if we merged the paras, otherwise <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		protected internal bool MergeParasInTable(SelectionHelper helper, VwDelProbType dpt)
		{
			SelLevInfo[] levInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top);
			if (levInfo[0].tag != StTextTags.kflidParagraphs)
				return false;
			IStText text;
			int iPara;
			int tag;
			IStTxtPara currPara = GetPara(helper, out text, out iPara, out tag);

			// Backspace at beginning of paragraph
			ITsStrBldr bldr;
			if (dpt == VwDelProbType.kdptBsAtStartPara)
			{
				if (iPara <= 0)
				{
					MiscUtils.ErrorBeep();
					return false;
				}

				IStTxtPara prevPara = text[iPara - 1];
				int prevParaLen = prevPara.Contents.Length;

				prevPara.MergeParaWithNext();

				helper.SetIch(SelectionHelper.SelLimitType.Top, prevParaLen);
				helper.SetIch(SelectionHelper.SelLimitType.Bottom, prevParaLen);
				levInfo[0].ihvo = iPara - 1;
				helper.SetLevelInfo(SelectionHelper.SelLimitType.Top, levInfo);
				helper.SetLevelInfo(SelectionHelper.SelLimitType.Bottom, levInfo);
				if (DeferSelectionUntilEndOfUOW)
				{
					// We are within a unit of work, so setting the selection will not work now.
					// we request that a selection be made after the unit of work.
					Debug.Assert(!helper.IsRange,
						"Currently, a selection made during a unit of work can only be an insertion point.");
					helper.SetIPAfterUOW(EditedRootBox.Site);
				}
				else
				{
					helper.SetSelection(true);
				}
				return true;
			}
			// delete at end of a paragraph
			int cParas = text.ParagraphsOS.Count;
			if (iPara + 1 >= cParas)
				return false; // We don't handle merging across StTexts

			currPara.MergeParaWithNext();

			if (DeferSelectionUntilEndOfUOW)
			{
				// We are within a unit of work, so setting the selection will not work now.
				// we request that a selection be made after the unit of work.
				Debug.Assert(!helper.IsRange,
					"Currently, a selection made during a unit of work can only be an insertion point.");
				helper.SetIPAfterUOW(EditedRootBox.Site);
			}
			else
			{
				helper.SetSelection(true);
			}
			return true;
		}
Exemplo n.º 13
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// In this simple implementation, we just record the information about the requested
		/// selection.
		/// </summary>
		/// <param name="rootb">The rootbox</param>
		/// <param name="ihvoRoot">Index of root element</param>
		/// <param name="cvlsi">count of levels</param>
		/// <param name="rgvsli">levels</param>
		/// <param name="tagTextProp">tag or flid of property containing the text (TsString)</param>
		/// <param name="cpropPrevious">number of previous occurrences of the text property</param>
		/// <param name="ich">character offset into the text</param>
		/// <param name="wsAlt">The id of the writing system for the selection.</param>
		/// <param name="fAssocPrev">Flag indicating whether to associate the insertion point
		/// with the preceding character or the following character</param>
		/// <param name="selProps">The selection properties.</param>
		/// --------------------------------------------------------------------------------
		public override void RequestSelectionAtEndOfUow(IVwRootBox rootb, int ihvoRoot,
			int cvlsi, SelLevInfo[] rgvsli, int tagTextProp, int cpropPrevious, int ich, int wsAlt,
			bool fAssocPrev, ITsTextProps selProps)
		{
			Assert.AreEqual(RootBox, rootb);
			Assert.IsNull(RequestedSelectionAtEndOfUow);

			RequestedSelectionAtEndOfUow = new SelectionHelper();
			RequestedSelectionAtEndOfUow.RootSite = this;
			RequestedSelectionAtEndOfUow.IhvoRoot = ihvoRoot;
			RequestedSelectionAtEndOfUow.NumberOfLevels = cvlsi;
			RequestedSelectionAtEndOfUow.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, rgvsli);
			RequestedSelectionAtEndOfUow.TextPropId = tagTextProp;
			RequestedSelectionAtEndOfUow.NumberOfPreviousProps = cpropPrevious;
			RequestedSelectionAtEndOfUow.IchAnchor = ich;
			RequestedSelectionAtEndOfUow.Ws = wsAlt;
			RequestedSelectionAtEndOfUow.AssocPrev = fAssocPrev;

			RootBox.DestroySelection(); // Need to act like real program in this regard
		}
Exemplo n.º 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Convert the scripture book tag to a filter tag.  Also, convert book indices to
		/// filtered book indices.  This is done when loading a selection to make it work
		/// in the context of the book filter.
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="selType"></param>
		/// ------------------------------------------------------------------------------------
		private void ConvertBookTagAndIndex(SelectionHelper helper,
			SelectionHelper.SelLimitType selType)
		{
			SelLevInfo[] info = helper.GetLevelInfo(selType);
			int bookPos = info.Length - 1;
			if (info[bookPos].tag == (int)Scripture.ScriptureTags.kflidScriptureBooks)
			{
				info[bookPos].tag = BookFilter.Tag;
				info[bookPos].ihvo = BookFilter.GetBookIndex(info[bookPos].hvo);
				helper.SetLevelInfo(selType, info);
			}
		}
Exemplo n.º 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Convert the scripture book tag to a filter tag.  Also, convert book indices to
		/// filtered book indices.  This is done when loading a selection to make it work
		/// in the context of the book filter.
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="selType"></param>
		/// ------------------------------------------------------------------------------------
		private void ConvertBookTagAndIndex(SelectionHelper helper,
			SelectionHelper.SelLimitType selType)
		{
			SelLevInfo[] info = helper.GetLevelInfo(selType);
			int bookPos = info.Length - 1;
			if (info[bookPos].tag == ScriptureTags.kflidScriptureBooks)
			{
				info[bookPos].tag = BookFilter.Tag;
				info[bookPos].ihvo = BookFilter.GetBookIndex(
					m_fdoCache.ServiceLocator.GetInstance<IScrBookRepository>().GetObject(info[bookPos].hvo));
				helper.SetLevelInfo(selType, info);
			}
		}
Exemplo n.º 16
0
		public void DeleteFootnoteFromContextMenuRangeSelection()
		{
			CheckDisposed();

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = true;
			selHelper.NumberOfLevels = 3;

			SelLevInfo[] anchorLevInfo = new SelLevInfo[3];
			anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			anchorLevInfo[2].ihvo = 1;
			anchorLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			anchorLevInfo[1].ihvo = 2;
			anchorLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			anchorLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo);
			selHelper.IchAnchor = 1;

			SelLevInfo[] endLevInfo = new SelLevInfo[3];
			endLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			endLevInfo[2].ihvo = 1;
			endLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			endLevInfo[1].ihvo = 6;
			endLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			endLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo);
			selHelper.IchEnd = 7;

			// Now that all the preparation to set the selection is done, set it.
			selHelper.SetSelection(m_footnoteView, true, true);
			Application.DoEvents();

			// First get the footnotes we're deleting.
			ScrFootnote[] footnotes = new ScrFootnote[5];
			Guid[] guidFootnotes = new Guid[5];
			int[] hvoParas = new int[5];
			for (int i = 0; i < 5; i++)
			{
				footnotes[i] = new ScrFootnote(Cache, m_Jude.FootnotesOS.HvoArray[i + 2]);
				guidFootnotes[i] = Cache.GetGuidFromId(footnotes[i].Hvo);
				hvoParas[i] = footnotes[i].ContainingParagraphHvo;
			}

			m_footnoteView.DeleteFootnote();

			foreach (ScrFootnote footnote in footnotes)
				Assert.IsFalse(Cache.IsRealObject(footnote.Hvo, StFootnote.kClassId));

			// now make sure that we don't find the footnote markers
			for (int i = 0; i < 5; i++)
			{
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i]);
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i], InMemoryFdoCache.s_wsHvos.En);
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i], InMemoryFdoCache.s_wsHvos.De);
			}
		}
Exemplo n.º 17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Replace the filter book tag with a scrpiture books tag.  This is done before
		/// persisting the selection because the filter tag is not valid across sessions.
		/// Also, any filtered book indices are replaced with real scripture book indices
		/// for the same reason.
		/// </summary>
		/// <param name="helper"></param>
		/// <param name="selType"></param>
		/// ------------------------------------------------------------------------------------
		private void ReplaceBookTagAndIndex(SelectionHelper helper,
			SelectionHelper.SelLimitType selType)
		{
			SelLevInfo[] info = helper.GetLevelInfo(selType);
			int bookPos = info.Length - 1;
			if (info[bookPos].tag == BookFilter.Tag)
			{
				info[bookPos].tag = ScriptureTags.kflidScriptureBooks;
				info[bookPos].ihvo = BookFilter.GetUnfilteredIndex(info[bookPos].ihvo);
				helper.SetLevelInfo(selType, info);
			}
		}
Exemplo n.º 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setups the specifed SelectionHelper for the specified paragraph and StText.
		/// </summary>
		/// <param name="helper">The SelectionHelper.</param>
		/// <param name="text">The StText.</param>
		/// <param name="para">The para.</param>
		/// <param name="limit">The limit.</param>
		/// <param name="view">The view</param>
		/// ------------------------------------------------------------------------------------
		private void SetupSelectionFor(SelectionHelper helper, StText text, StTxtPara para,
			SelectionHelper.SelLimitType limit, FwRootSite view)
		{
			Debug.Assert((view is DraftView && ((DraftView)view).TeEditingHelper != null) ||
				(view is FootnoteView && ((FootnoteView)view).EditingHelper != null));
			if (view is DraftView)
			{
				DraftView draftView = (DraftView)view;

				if ((text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidContent ||
					text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading))
				{
					// text belongs to section heading or contents
					ScrSection section = new ScrSection(m_fdoCache, text.OwnerHVO);
					Debug.Assert(section.OwningFlid == (int)ScrBook.ScrBookTags.kflidSections);

					helper.SetNumberOfLevels(limit, 4);
					SelLevInfo[] info = helper.GetLevelInfo(limit);
					info[0].ihvo = para.IndexInOwner;
					info[0].tag = (int)StText.StTextTags.kflidParagraphs;
					info[1].ihvo = text.IndexInOwner;
					info[1].tag = text.OwningFlid;
					info[2].ihvo = section.IndexInBook;
					info[2].tag = (int)ScrBook.ScrBookTags.kflidSections;
					info[3].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(section.OwnerHVO);
					info[3].tag = draftView.TeEditingHelper.BookFilter.Tag;
					helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
				}
				else
				{
					// text belongs to a book title
					Debug.Assert(text.OwningFlid == (int)ScrBook.ScrBookTags.kflidTitle);
					ScrBook book = new ScrBook(m_fdoCache, text.OwnerHVO);

					helper.SetNumberOfLevels(limit, 3);
					SelLevInfo[] info = helper.GetLevelInfo(limit);
					info[0].ihvo = para.IndexInOwner;
					info[0].tag = (int)StText.StTextTags.kflidParagraphs;
					info[1].ihvo = text.IndexInOwner;
					info[1].tag = text.OwningFlid;
					info[2].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(book.Hvo);
					info[2].tag = draftView.TeEditingHelper.BookFilter.Tag;
					helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
				}
			}
			else if (view is FootnoteView && text.OwningFlid == (int)ScrBook.ScrBookTags.kflidFootnotes)
			{
				// text belongs to a footnote
				FootnoteView footnoteView = (FootnoteView)view;
				StFootnote footnote = new StFootnote(m_fdoCache, para.OwnerHVO);
				ScrBook book = new ScrBook(m_fdoCache, text.OwnerHVO);

				helper.SetNumberOfLevels(limit, 3);
				SelLevInfo[] info = helper.GetLevelInfo(limit);
				info[0].hvo = text.Hvo;
				info[0].tag = (int)StText.StTextTags.kflidParagraphs;
				info[1].hvo = footnote.Hvo;
				info[1].ihvo = footnote.IndexInOwner;
				info[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
				info[2].hvo = book.Hvo;
				info[2].ihvo = footnoteView.BookFilter.GetBookIndex(book.Hvo);
				info[2].tag = footnoteView.BookFilter.Tag;
				info[0].ich = info[1].ich = info[2].ich = -1;
				helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
			}
		}