SetSelection() public method

Sets the selection
public SetSelection ( IVwRootSite rootSite ) : IVwSelection
rootSite IVwRootSite The root site
return IVwSelection
Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks to see if there's a footnote on either side of the IP. If there is, then
		/// it's selected.
		/// </summary>
		/// <returns><c>true</c> if a footnote marker is sucessfully selected next to the IP.
		/// Otherwise, <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		public bool SelectFootnoteMarkNextToIP()
		{
			if (CurrentSelection == null)
				return false;

			SelectionHelper helper = new SelectionHelper(CurrentSelection);

			// If the selection is a range then just return what SelectionIsFootnoteMarker determines.
			if (helper.Selection.IsRange)
				return SelectionIsFootnoteMarker(helper.Selection);

			// Now that we know the selection is not a range, look to both sides of the IP
			// to see if we are next to a footnote marker.

			// First, look on the side where the IP is associated. If there's a marker there,
			// select it and get out.
			if (SelectionIsFootnoteMarker(helper.Selection))
			{
				helper.IchEnd = helper.AssocPrev ? (helper.IchAnchor - 1) : (helper.IchAnchor + 1);
				helper.SetSelection(true);
				return true;
			}

			// Check the other side of the IP and select the marker if there's one there.
			helper.AssocPrev = !helper.AssocPrev;
			helper.SetSelection(false);
			if (SelectionIsFootnoteMarker(helper.Selection))
			{
				helper.IchEnd = helper.AssocPrev ? (helper.IchAnchor - 1) : (helper.IchAnchor + 1);
				helper.SetSelection(true);
				return true;
			}

			return false;
		}
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Makes a selection in the specified annotation (without scrolling the annotation in
		/// the view).
		/// </summary>
		/// <param name="vc">The notes view constructor</param>
		/// <param name="fScrollNearTop">if set to <c>true</c> scrolls the specified note to a
		/// position near the top of the view.</param>
		/// <param name="bookIndex">Index of the book.</param>
		/// <param name="iAnnotation">Index of the annotation.</param>
		/// <param name="iResponse">Index of the response (0 if setting the selection in one of
		/// the StJournalText fields rather than in a response.</param>
		/// <param name="noteTag">The tag indicating the field of the annotation where the
		/// selection is to be made.</param>
		/// <param name="rootSite">The root site.</param>
		/// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so
		/// that the whole annotation can be scrolled into view. if set to <c>false</c> only
		/// make a selection at the start of the annotation.</param>
		/// ------------------------------------------------------------------------------------
		internal void MakeSelectionInNote(TeNotesVc vc, bool fScrollNearTop, int bookIndex,
			int iAnnotation, int iResponse, ScrScriptureNote.ScrScriptureNoteTags noteTag,
			IVwRootSite rootSite, bool fNoteIsExpanded)
		{
			if (vc == null || vc.NotesSequenceHandler == null)
				return;

			SelectionHelper selHelper;
			if (fScrollNearTop)
			{
				// Make an un-installed selection at the top of the annotation in order to scroll the
				// annotation to the top of the view.
				selHelper = new SelectionHelper();
				selHelper.NumberOfLevels = 2;
				selHelper.LevelInfo[0].cpropPrevious = 0;
				selHelper.LevelInfo[0].ich = -1;
				selHelper.LevelInfo[0].ihvo = iAnnotation;
				selHelper.LevelInfo[0].tag = vc.NotesSequenceHandler.Tag;
				selHelper.LevelInfo[0].ws = 0;
				selHelper.LevelInfo[1].cpropPrevious = 0;
				selHelper.LevelInfo[1].ich = -1;
				selHelper.LevelInfo[1].ihvo = bookIndex;
				selHelper.LevelInfo[1].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations;
				selHelper.LevelInfo[1].ws = 0;
				selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, -2);
				selHelper.IchAnchor = 0;
				selHelper.AssocPrev = false;
				selHelper.NumberOfPreviousProps = 2;
				if (fNoteIsExpanded)
				{
					selHelper.SetSelection(rootSite, true, true, VwScrollSelOpts.kssoNearTop);
				}
				else
				{
					// Annotation is collapsed. Only attempt a selection at the start of it.
					selHelper.SetSelection(rootSite, true, true);
					return;
				}
			}
			else
				EnsureNoteIsVisible(vc, bookIndex, iAnnotation, rootSite);

			// Now make the real (installed) selection in the desired field of the annotation.
			bool fIsResponse = (noteTag == ScrScriptureNote.ScrScriptureNoteTags.kflidResponses);
			selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 4;
			selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 0;
			selHelper.LevelInfo[1].tag = (int)noteTag;
			selHelper.LevelInfo[1].ihvo = iResponse;
			selHelper.LevelInfo[1].cpropPrevious = (fIsResponse ? 0 : 1);
			selHelper.LevelInfo[2].tag = vc.NotesSequenceHandler.Tag;
			selHelper.LevelInfo[2].ihvo = iAnnotation;
			selHelper.LevelInfo[3].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations;
			selHelper.LevelInfo[3].ihvo = bookIndex;
			selHelper.IchAnchor = 0;
			selHelper.AssocPrev = false;
			selHelper.SetSelection(rootSite, true, true);
		}
Exemplo n.º 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Ensures the annotation is mostly visible by making an uninstalled selection
		/// toward the end of the modified date.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		internal void EnsureNoteIsVisible(TeNotesVc vc, int bookIndex, int iAnnotation,
			IVwRootSite notesDataEntryView)
		{
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 2;
			selHelper.LevelInfo[0].cpropPrevious = 0;
			selHelper.LevelInfo[0].ich = -1;
			selHelper.LevelInfo[0].ihvo = iAnnotation;
			selHelper.LevelInfo[0].tag = vc.NotesSequenceHandler.Tag;
			selHelper.LevelInfo[0].ws = 0;
			selHelper.LevelInfo[1].cpropPrevious = 0;
			selHelper.LevelInfo[1].ich = -1;
			selHelper.LevelInfo[1].ihvo = bookIndex;
			selHelper.LevelInfo[1].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations;
			selHelper.LevelInfo[1].ws = 0;
			selHelper.AssocPrev = false;

			// Put the selection at the end of the shortest possible date value. It doesn't
			// have to be right at the end, but the closer it is, the more reliable it will
			// be that it is fully scrolled into view.
			selHelper.IchAnchor = 8;

			selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
				(int)CmAnnotation.CmAnnotationTags.kflidDateModified);

			selHelper.SetSelection(notesDataEntryView, false, true, VwScrollSelOpts.kssoDefault);
		}
Exemplo n.º 4
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.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Low-level implementation of insert verse number.
		/// </summary>
		/// <param name="selHelper">the given SelectionHelper</param>
		/// ------------------------------------------------------------------------------------
		public void InsertVerseNumber(SelectionHelper selHelper)
		{
			CheckDisposed();
			Debug.Assert(selHelper != null);
			Debug.Assert(!selHelper.IsRange);

			// Get the details about the current selection
			int ichSelOrig; //the character offset of the selection in the ITsString
			int hvoObj; //the id of the object the selection is in (StTxtPara or CmTranslation)
			int propTag; //property tag of object
			ITsString tssSel; //ITsString containing the selection
			int wsAlt; //the WS of the multiString alt, if selection is in a back translation
			ichSelOrig = GetSelectionInfo(selHelper, out hvoObj, out propTag, out tssSel, out wsAlt);

			// If we're at the start of a paragraph and the first run is a chapter number,
			// we need to jump past it to insert the verse number otherwise it will insert
			// it before the chapter number, which for some reason feels brain dead.
			if (ichSelOrig == 0)
			{
				ITsTextProps ttp = tssSel.get_Properties(0);
				if (ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle) ==
					ScrStyleNames.ChapterNumber)
				{
					ichSelOrig = tssSel.get_LimOfRun(0);
				}
			}

			// Adjust the insertion position to the beginning of a word - not in the middle
			//  (may move to an existing verse number too)
			int ichWord = MoveToWordBoundary(tssSel, ichSelOrig);

			//			TomB and MarkB have decided we won't do this, at least for now
			//			// If the start of the Bt does not match the vernacular, adjust it if required.
			//			if (ichWord > 0)
			//				cInsDel = SetVerseAtStartOfBtIfNeeded();
			//			ichWord += cInsDel; //adjust

			// some key variables set by Update or Insert methods, etc
			string sVerseNumIns = null; // will hold the verse number string we inserted; could be
			//   a simple number, a verse bridge, or the end number added to a bridge
			string sChapterNumIns = null; // will hold chapter number string inserted or null if none
			int ichLimIns = -1; //will hold the end of the new chapter/verse numbers we update or insert

			// Is ichWord in or next to a verse number? (if so, get its ich range)
			bool fCheckForChapter = (wsAlt != 0); //check for chapter in BT only
			int ichMin; // min of the verse number run, if we are on one
			int ichLim; // lim of the verse number run, if we are on one
			bool fFoundExistingRef =
				InReference(tssSel, ichWord, fCheckForChapter, out ichMin, out ichLim);

			// If we moved the selection forward (over spaces or punctuation) to an
			//  existing verse number ...
			if (fFoundExistingRef && (ichSelOrig < ichWord))
			{
				//Attempt to insert a verse number at the IP, if one is missing there.
				// if selection is in vernacular...
				if (propTag == (int)StTxtPara.StTxtParaTags.kflidContents)
				{
					// Insert missing verse number in vernacular
					InsertMissingVerseNumberInVern(hvoObj, propTag, selHelper, ichSelOrig,
						ichWord, ref tssSel, out sVerseNumIns, out ichLimIns);
				}
				//else
				//{
				//    InsertMissingVerseNumberInBt(hvoObj, propTag, selHelper, wsAlt,
				//        ichSelOrig, ichWord, ref tssSel, ref ichLim,
				//        out sVerseNumIns, out sChapterNumIns);
				//}
				// if a verse number was not inserted, sVerseNumIns is null
			}

			// If no verse number inserted yet...
			if (sVerseNumIns == null)
			{
				if (fFoundExistingRef)
				{
					//We must update the existing verse number at ichWord
					// is selection in vern or BT?
					if (propTag == (int)StTxtPara.StTxtParaTags.kflidContents)
					{
						// Update verse number in vernacular
						UpdateExistingVerseNumberInVern(hvoObj, propTag, selHelper,
							ichMin, ichLim, ref tssSel, out sVerseNumIns, out ichLimIns);
					}
					else
					{
						//Update verse number in back translation
						UpdateExistingVerseNumberInBt(hvoObj, propTag, selHelper, wsAlt,
							ichMin, ichLim, ref tssSel, out sVerseNumIns, out sChapterNumIns,
							out ichLimIns);
					}
				}
				else
				{
					// We're NOT on an existing verse number, so insert the next appropriate one.
					// is selection in vern or BT?
					if (propTag == (int)StTxtPara.StTxtParaTags.kflidContents)
					{
						InsertNextVerseNumberInVern(hvoObj, propTag, selHelper, ichWord,
							ref tssSel, out sVerseNumIns, out ichLimIns);
					}
					else
					{
						InsertNextVerseNumberInBt(hvoObj, propTag, selHelper, wsAlt, ichWord,
							ref tssSel, out	sVerseNumIns, out sChapterNumIns, out ichLimIns);
						selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
							(int)CmTranslation.CmTranslationTags.kflidTranslation);
						selHelper.SetTextPropId(SelectionHelper.SelLimitType.End,
							(int)CmTranslation.CmTranslationTags.kflidTranslation);
					}
				}
			}

			if (sVerseNumIns == null)
			{
				MiscUtils.ErrorBeep(); // No verse number inserted or updated
				return;
			}

			// set new IP behind the verse number
			selHelper.IchAnchor = ichLimIns;
			selHelper.IchEnd = ichLimIns;
			selHelper.AssocPrev = true;
			selHelper.SetSelection(true);

			// Remove any duplicate chapter/verse numbers following the new verse number.
			RemoveDuplicateVerseNumbers(hvoObj, propTag, tssSel, wsAlt, sChapterNumIns,
				sVerseNumIns, ichLimIns);

			// Issue property change event for inserted verse.
			m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoObj,
				StTxtPara.ktagVerseNumbers, 0, 1, 1);
		}
Exemplo n.º 6
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.º 7
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.º 8
0
		public void InsertSection_EndFirstHeadingPara()
		{
			CheckDisposed();

			int nSectionsExpected = m_exodus.SectionsOS.Count;

			// Create second heading paragraph
			int iSectionIns = 1;
			IScrSection section = m_exodus.SectionsOS[iSectionIns];
			StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);
			paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead);
			paraBldr.AppendRun("Second Paragraph", StyleUtils.CharStyleTextProps(null,
				Cache.DefaultVernWs));
			paraBldr.CreateParagraph(section.HeadingOAHvo);
			Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count);

			// Put the IP into the heading of section 2 at end of first heading paragraph
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 4;
			selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 0;
			selHelper.LevelInfo[1].tag = (int)ScrSection.ScrSectionTags.kflidHeading;
			selHelper.LevelInfo[1].ihvo = 0;
			selHelper.LevelInfo[2].tag = (int)ScrBook.ScrBookTags.kflidSections;
			selHelper.LevelInfo[2].ihvo = iSectionIns;
			selHelper.LevelInfo[3].tag = m_draftView.BookFilter.Tag;
			selHelper.LevelInfo[3].ihvo = m_exodus.OwnOrd;
			selHelper.IchAnchor = 9; // end of "Heading 2"
			int cContentParas = section.ContentOA.ParagraphsOS.Count;

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(m_draftView, true, true);

			// InsertSection should add a section
			m_draftView.TeEditingHelper.CreateSection(false);
			nSectionsExpected++;
			Assert.AreEqual(nSectionsExpected, m_exodus.SectionsOS.Count, "Should add a section");
			IScrSection newSection = m_exodus.SectionsOS[iSectionIns];
			IScrSection oldSection = m_exodus.SectionsOS[iSectionIns + 1];
			Assert.AreEqual(02001001, newSection.VerseRefMin,
				"Wrong start reference for new section");
			Assert.AreEqual(02001001, newSection.VerseRefMax,
				"Wrong end reference for new section");
			Assert.AreEqual(02001001, oldSection.VerseRefMin,
				"Wrong start reference for existing section");
			Assert.AreEqual(02001005, oldSection.VerseRefMax,
				"Wrong end reference for existing section");

			Assert.AreEqual(1, newSection.HeadingOA.ParagraphsOS.Count);
			Assert.AreEqual("Heading 2",
				((StTxtPara)newSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text,
				"Wrong heading in new section");
			Assert.IsNull(((StTxtPara)newSection.ContentOA.ParagraphsOS.FirstItem).Contents.Text,
				"Content of new section is not empty");
			Assert.AreEqual(1, oldSection.HeadingOA.ParagraphsOS.Count,
				"Wrong number of paragraphs in old section");
			Assert.AreEqual("Second Paragraph",
				((StTxtPara)oldSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text,
				"Wrong heading in old section");
			Assert.AreEqual(cContentParas,
				oldSection.ContentOA.ParagraphsOS.Count,
				"Wrong number of paragraphs in old content");
		}
Exemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This is the workhorse that actually reduces a range selection to a simple insertion
		/// point, given the specified index to indicate the limit where the IP is to be
		/// created.
		/// </summary>
		/// <param name="limit">Specify Top to place the IP at the top-most limit of the
		/// selection. Specify Bottom to place the IP at the bottom-most limit of the selection.
		/// Specify Anchor to place the IP at the point where the user initiated the selection.
		/// Specify End to place the IP at the point where the user completed the selection. Be
		/// aware the user may select text in either direction, thus the end of the selection\
		/// could be visually before the anchor. For a simple insertion point or a selection
		/// entirely within a single StText, this parameter doesn't actually make any
		/// difference.</param>
		/// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param>
		/// <param name="fInstall">True to install the created selection, false otherwise</param>
		/// ------------------------------------------------------------------------------------
		protected virtual SelectionHelper ReduceSelectionToIp(SelLimitType limit, bool fMakeVisible,
			bool fInstall)
		{
			SelectionHelper textSelHelper = new SelectionHelper(this);
			textSelHelper.ReduceToIp(limit);

			// and make the selection
			if (fInstall)
				textSelHelper.SetSelection(m_rootSite, true, fMakeVisible);
			return textSelHelper;
		}
Exemplo n.º 10
0
		public void InsertSection_BetweenHeadingParas()
		{
			int nSectionsExpected = m_exodus.SectionsOS.Count;

			// Create second heading paragraph
			int iSectionIns = 1;
			IScrSection section = m_exodus.SectionsOS[iSectionIns];
			StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);
			paraBldr.ParaStyleName = ScrStyleNames.SectionHead;
			paraBldr.AppendRun("Second Paragraph", StyleUtils.CharStyleTextProps(null,
				Cache.DefaultVernWs));
			paraBldr.CreateParagraph(section.HeadingOA);
			Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count);
			m_actionHandler.BreakUndoTask("another task", "redo it"); // must do this for view to see second paragraph.

			// Put the IP into the heading of section 3 at beginning of second heading paragraph
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 4;
			selHelper.LevelInfo[0].tag = StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 1;
			selHelper.LevelInfo[1].tag = ScrSectionTags.kflidHeading;
			selHelper.LevelInfo[1].ihvo = 0;
			selHelper.LevelInfo[2].tag = ScrBookTags.kflidSections;
			selHelper.LevelInfo[2].ihvo = iSectionIns;
			selHelper.LevelInfo[3].tag = m_draftView.BookFilter.Tag;
			selHelper.LevelInfo[3].ihvo = m_exodus.OwnOrd;
			selHelper.IchAnchor = 0;
			selHelper.TextPropId = StTxtParaTags.kflidContents;
			int cContentParas = section.ContentOA.ParagraphsOS.Count;

			// Now that all the preparation to set the IP is done, set it.
			selHelper.SetSelection(m_draftView, true, true);

			// InsertSection should add a section
			m_draftView.TeEditingHelper.CreateSection(false);
			nSectionsExpected++;
			Assert.AreEqual(nSectionsExpected, m_exodus.SectionsOS.Count, "Should add a section");
			IScrSection newSection = m_exodus.SectionsOS[iSectionIns];
			IScrSection oldSection = m_exodus.SectionsOS[iSectionIns + 1];
			Assert.AreEqual(02001001, newSection.VerseRefMin,
				"Wrong start reference for new section");
			Assert.AreEqual(02001001, newSection.VerseRefMax,
				"Wrong end reference for new section");
			Assert.AreEqual(02001001, oldSection.VerseRefMin,
				"Wrong start reference for existing section");
			Assert.AreEqual(02001005, oldSection.VerseRefMax,
				"Wrong end reference for existing section");

			Assert.AreEqual(1, newSection.HeadingOA.ParagraphsOS.Count);
			Assert.AreEqual("Heading 2",
				newSection.HeadingOA[0].Contents.Text,
				"Wrong heading in new section");
			Assert.IsNull(newSection.ContentOA[0].Contents.Text,
				"Content of new section is not empty");
			Assert.AreEqual(1, oldSection.HeadingOA.ParagraphsOS.Count);
			Assert.AreEqual("Second Paragraph",
				oldSection.HeadingOA[0].Contents.Text,
				"Wrong heading in old section");
			Assert.AreEqual(cContentParas,
				oldSection.ContentOA.ParagraphsOS.Count,
				"Wrong number of paragraphs in old content");
		}
Exemplo n.º 11
0
		public void InsertSection_WithinHeading()
		{
			CheckDisposed();

			int nSectionsExpected = m_exodus.SectionsOS.Count;

			// Put the IP into the heading of section 2
			int iSectionIns = 1;
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 4;
			selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 0;
			selHelper.LevelInfo[1].tag = (int)ScrSection.ScrSectionTags.kflidHeading;
			selHelper.LevelInfo[1].ihvo = 0;
			selHelper.LevelInfo[2].tag = (int)ScrBook.ScrBookTags.kflidSections;
			selHelper.LevelInfo[2].ihvo = iSectionIns;
			selHelper.LevelInfo[3].tag = m_draftView.BookFilter.Tag;
			selHelper.LevelInfo[3].ihvo = m_exodus.OwnOrd;
			IScrSection section = m_exodus.SectionsOS[iSectionIns];
			Assert.AreEqual(1, section.HeadingOA.ParagraphsOS.Count);
			StTxtPara para = (StTxtPara) section.HeadingOA.ParagraphsOS[0];
			selHelper.IchAnchor = 7;
			int cContentParas = section.ContentOA.ParagraphsOS.Count;

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(m_draftView, true, true);

			// InsertSection should add a section
			m_draftView.TeEditingHelper.CreateSection(false);
			nSectionsExpected++;
			Assert.AreEqual(nSectionsExpected, m_exodus.SectionsOS.Count, "Should add a section");
			IScrSection newSection = m_exodus.SectionsOS[iSectionIns];
			IScrSection oldSection = m_exodus.SectionsOS[iSectionIns + 1];
			Assert.AreEqual(02001001, newSection.VerseRefMin,
				"Wrong start reference for new section");
			Assert.AreEqual(02001001, newSection.VerseRefMax,
				"Wrong end reference for new section");
			Assert.AreEqual(02001001, oldSection.VerseRefMin,
				"Wrong start reference for existing section");
			Assert.AreEqual(02001005, oldSection.VerseRefMax,
				"Wrong end reference for existing section");

			Assert.AreEqual("Heading",
				((StTxtPara)newSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text,
				"Wrong heading in new section");
			Assert.IsNull(((StTxtPara)newSection.ContentOA.ParagraphsOS.FirstItem).Contents.Text,
				"Content of new section is not empty");
			Assert.AreEqual(" 2",
				((StTxtPara)oldSection.HeadingOA.ParagraphsOS.FirstItem).Contents.Text,
				"Wrong heading in old section");
			Assert.AreEqual(cContentParas,
				oldSection.ContentOA.ParagraphsOS.Count,
				"Wrong number of paragraphs in old content");
		}
Exemplo n.º 12
0
		public void InsertSection_AtSectionHeadingBeginning()
		{
			int nSectionsExpected = m_exodus.SectionsOS.Count;

			// Put the IP into the heading of section 3
			int iSectionIns = 1;
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 4;
			selHelper.LevelInfo[0].tag = StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 0;
			selHelper.LevelInfo[1].tag = ScrSectionTags.kflidHeading;
			selHelper.LevelInfo[1].ihvo = 0;
			selHelper.LevelInfo[2].tag = ScrBookTags.kflidSections;
			selHelper.LevelInfo[2].ihvo = iSectionIns;
			selHelper.LevelInfo[3].tag = m_draftView.BookFilter.Tag;
			selHelper.LevelInfo[3].ihvo = m_exodus.OwnOrd;
			selHelper.TextPropId = StTxtParaTags.kflidContents;

			// Now that all the preparation to set the IP is done, set it.
			selHelper.SetSelection(m_draftView, true, true);

			// InsertSection should add a section
			m_draftView.TeEditingHelper.CreateSection(false);
			nSectionsExpected++;
			Assert.AreEqual(nSectionsExpected, m_exodus.SectionsOS.Count, "Should add a section");
			IScrSection newSection = m_exodus.SectionsOS[iSectionIns];
			IScrSection oldSection = m_exodus.SectionsOS[iSectionIns + 1];
			Assert.AreEqual(02001001, newSection.VerseRefMin,
				"Wrong start reference for new section");
			Assert.AreEqual(02001001, newSection.VerseRefMax,
				"Wrong end reference for new section");
			Assert.AreEqual(02001001, oldSection.VerseRefMin,
				"Wrong start reference for existing section");
			Assert.AreEqual(02001005, oldSection.VerseRefMax,
				"Wrong end reference for existing section");

			Assert.IsNull(newSection.HeadingOA[0].Contents.Text,
				"Wrong section heading for new section");
			Assert.IsNull(newSection.ContentOA[0].Contents.Text,
				"Content of new section is not empty");
			Assert.AreEqual("Heading 2",
				oldSection.HeadingOA[0].Contents.Text,
				"Wrong section heading for old section");
		}
Exemplo n.º 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Common utility for the CurrentRef* properties
		/// </summary>
		/// <param name="selhelper">The selection helper representing the current selection
		/// (or sometimes the current reduced to an IP)</param>
		/// <param name="selLimit">The limit of the selection (anchor, end, etc.) to get the
		/// reference of</param>
		/// <returns>the start and end reference of the given selection, as an array of two
		/// ScrReference objects</returns>
		/// ------------------------------------------------------------------------------------
		protected ScrReference[] GetCurrentRefRange(SelectionHelper selhelper,
			SelectionHelper.SelLimitType selLimit)
		{
			if (m_cache == null || selhelper == null || BookFilter == null)
				return new ScrReference[] {ScrReference.Empty, ScrReference.Empty};

			ILocationTracker tracker = ((ITeView)Control).LocationTracker;

			// If there is a current book...
			BCVRef start = new BCVRef();
			BCVRef end = new BCVRef();
			int iBook = tracker.GetBookIndex(selhelper, selLimit);
			if (iBook >= 0 && BookFilter.BookCount > 0)
			{
				try
				{
					IScrBook book = BookFilter.GetBook(iBook);

					// if there is not a current section, then use the book and chapter/verse of 0.
					IScrSection section = tracker.GetSection(selhelper, selLimit);
					if (section != null)
					{
						// If there is a section...
						int paraHvo = selhelper.GetLevelInfoForTag(StTextTags.kflidParagraphs, selLimit).hvo;
						IScrTxtPara scrPara = m_cache.ServiceLocator.GetInstance<IScrTxtParaRepository>().GetObject(paraHvo);
						// Get the ich at either the beginning or the end of the selection,
						// as specified with limit. (NB that this is relative to the property, not the whole paragraph.)
						int ich;
						// Get the TsString, whether in vern or BT
						ITsString tss;
						int refWs;
						SelLevInfo segInfo;
						int textPropTag = 0;
						if (selhelper.GetLevelInfoForTag(StTxtParaTags.kflidSegments, selLimit, out segInfo))
						{
							// selection is in a segmented BT segment. Figure the reference based on where the segment is
							// in the underlying paragraph.
							tss = scrPara.Contents; // for check below on range of ich.
							ISegment seg = m_repoSegment.GetObject(segInfo.hvo);
							ich = seg.BeginOffset;
							Debug.Assert(seg.Paragraph == scrPara);
							refWs = -1; // ich is in the paragraph itself, not some CmTranslation
						}
						else
						{
							textPropTag = selhelper.GetTextPropId(selLimit);
							if (textPropTag == SimpleRootSite.kTagUserPrompt)
							{
								ich = 0;
								tss = null;
							}
							else
							{
								ich = selhelper.GetIch(selLimit);
								tss = selhelper.GetTss(selLimit); // Get the TsString, whether in vern or BT
								if (ich < 0 || tss == null)
								{
									HandleFootnoteAnchorIconSelected(selhelper.Selection, (hvo, flid, wsDummy, ichAnchor) =>
									{
										SelectionHelper helperTemp = new SelectionHelper(selhelper);
										ich = helperTemp.IchAnchor = helperTemp.IchEnd = ichAnchor;
										helperTemp.SetSelection(false, false);
										tss = helperTemp.GetTss(selLimit);
									});
								}
							}
							refWs = GetCurrentBtWs(selLimit); // figures out whether it's in a CmTranslation or the para itself.
						}
						Debug.Assert(tss == null || ich <= tss.Length);
						if ((tss != null && ich <= tss.Length) || textPropTag == SimpleRootSite.kTagUserPrompt)
						{
							scrPara.GetRefsAtPosition(refWs, ich, true, out start, out end);

							// If the chapter number is 0, then use the chapter from the section reference
							if (end.Chapter == 0)
								end.Chapter = BCVRef.GetChapterFromBcv(section.VerseRefMin);
							if (start.Chapter == 0)
								start.Chapter = BCVRef.GetChapterFromBcv(section.VerseRefMin);
						}
					}
					else
					{
						// either it didn't find a level or it didn't find an index. Either way,
						// it couldn't find a section.
						start.Book = end.Book = book.CanonicalNum;
					}
				}
				catch
				{
					// Bummer man, something went wrong... don't sweat it though, it happens...
					// This can occur if you are in the introduction or other location that lacks
					// relevant information or other necessary stuff.
				}
			}
			return new ScrReference[] {new ScrReference(start, m_scr.Versification),
				new ScrReference(end, m_scr.Versification)}; ;
		}
Exemplo n.º 14
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.º 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Performs the delegated action if the given selection is for a footnote anchor icon.
		/// ENHANCE: This code currently assumes that any iconic representation of an ORC is
		/// for a footnote anchor. When we support showing picture anchors (or anything else)
		/// iconically, this will have to be changed to account for that.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected static void HandleFootnoteAnchorIconSelected(IVwSelection sel,
			FootnoteAnchorFoundDelegate action)
		{
			if (sel == null)
				throw new ArgumentNullException("sel");
			if (action == null)
				throw new ArgumentNullException("action");

			if (sel.SelType == VwSelType.kstPicture)
			{
				// See if this is a ORC-replacement picture, in which case we treat it
				// as a clickable object rather than a picture.
				int ichAnchor = sel.get_ParagraphOffset(false);
				int ichEnd = sel.get_ParagraphOffset(true);
				if (ichAnchor >= 0 && ichAnchor < ichEnd)
				{
					SelectionHelper selHelperOrc = SelectionHelper.Create(sel, sel.RootBox.Site);
					SelLevInfo info;
					bool found = false;
					switch (selHelperOrc.TextPropId)
					{
						case StTxtParaTags.kflidContents:
							found = selHelperOrc.GetLevelInfoForTag(StTextTags.kflidParagraphs, out info);
							break;
						case CmTranslationTags.kflidTranslation:
							found = (selHelperOrc.GetLevelInfoForTag(-1, out info) && selHelperOrc.Ws > 0);
							break;
						case SegmentTags.kflidFreeTranslation:
							if (selHelperOrc.GetLevelInfoForTag(StTxtParaTags.kflidSegments, out info) && selHelperOrc.Ws > 0)
							{
								// adjust anchor offset to be a segment offset - need to subtract off the beginning offset
								// for the segment.
								SelectionHelper selHelperStartOfSeg = new SelectionHelper(selHelperOrc);
								selHelperStartOfSeg.IchAnchor = selHelperStartOfSeg.IchEnd = 0;
								IVwSelection selSegStart = selHelperStartOfSeg.SetSelection(selHelperOrc.RootSite, false, false);
								ichAnchor -= selSegStart.get_ParagraphOffset(false);
								found = true;
							}
							break;
						default:
							// Ignore everything else because it doesn't have footnotes.
							return;
					}
					if (found)
						action(info.hvo, selHelperOrc.TextPropId, selHelperOrc.Ws, ichAnchor);
				}
			}
		}
Exemplo n.º 16
0
		/// <summary>
		/// Moves the cursor to the specified position in the specified cell.
		/// </summary>
		/// <param name="cellId">The cell id.</param>
		/// <param name="cellIndex">Index of the item in the cell.</param>
		/// <param name="initial">if <c>true</c> move the cursor to the beginning of the specified item, otherwise it is moved to the end</param>
		/// <param name="editable">if <c>true</c> move the cursor to the first editable position</param>
		/// <param name="install">if <c>true</c> install the selection</param>
		/// <returns>The new selection</returns>
		protected IVwSelection SelectAt(int cellId, int cellIndex, bool initial, bool editable, bool install)
		{
			SelLevInfo[] levels = GetLevelInfo(cellId, cellIndex);
			if (levels == null)
			{
				int count = GetCellCount(cellId);
				if (count == 0)
				{
					SelectionHelper newSel = new SelectionHelper();
					newSel.SetTextPropId(SelectionHelper.SelLimitType.Anchor, GetFlid(cellId));
					return newSel.SetSelection(m_view, install, false);
				}
				else
				{
					levels = GetLevelInfo(cellId, initial ? 0 : count - 1);
				}
			}

			return m_view.RootBox.MakeTextSelInObj(0, levels.Length, levels, 0, null, initial, editable, false, false, install);
		}
Exemplo n.º 17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets a selection helper that represents an insertion point at the specified limit of
		/// the current selection. Use this version instead of calling ReduceSelectionToIp
		/// directly on the selection helper if you want it to work for selections which might
		/// include iconic representations of ORC characters.
		/// </summary>
		/// <returns>A selection helper representing an IP, or <c>null</c> if the given
		/// selection cannot be reduced to an IP</returns>
		/// ------------------------------------------------------------------------------------
		public SelectionHelper GetSelectionReducedToIp(SelectionHelper.SelLimitType selLimit)
		{
			SelectionHelper selHelper = CurrentSelection.ReduceSelectionToIp(
				SelectionHelper.SelLimitType.Top, false, false);
			if (selHelper == null)
			{
				HandleFootnoteAnchorIconSelected(CurrentSelection.Selection, (hvo, flid, ws, ich) =>
					{
						selHelper = new SelectionHelper(CurrentSelection);
						selHelper.IchAnchor = selHelper.IchEnd = ich;
						IVwSelection sel = selHelper.SetSelection(false, false);
						if (sel == null)
							selHelper = null;
					});
			}
			return selHelper;
		}
Exemplo n.º 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Navigate to the beginning of any Scripture element: Title, Section Head, or Section
		/// Content.
		/// </summary>
		/// <param name="tag">Indicates whether selection should be made in the title, section
		/// Heading or section Content</param>
		/// <param name="book">The 0-based index of the Scripture book in which to put the
		/// insertion point</param>
		/// <param name="section">The 0-based index of the Scripture section in which to put the
		/// insertion point. Ignored if tag is <see cref="ScrBook.ScrBookTags.kflidTitle"/></param>
		/// <param name="paragraph">The 0-based index of the paragraph which to put the
		/// insertion point.</param>
		/// <param name="character">index of character where insertion point will be set</param>
		/// <param name="fAssocPrev">True if the properties of the text entered at the new
		/// insertion point should be associated with the properties of the text before the new
		/// insertion point. False if text entered at the new insertion point should be
		/// associated with the text following the new insertion point.</param>
		/// <returns>True if it succeeded, false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public bool SetInsertionPoint(int tag, int book, int section, int paragraph, int character,
			bool fAssocPrev)
		{
			CheckDisposed();

			SelectionHelper selHelper = new SelectionHelper(); //SelectionHelper.Create(Callbacks.EditedRootBox.Site);// new SelectionHelper();
			int cLev;
			if (tag == (int)ScrBook.ScrBookTags.kflidTitle)
			{
				cLev = kBookTitleLevelCount;
				selHelper.NumberOfLevels = cLev;
				selHelper.LevelInfo[cLev - 1].tag = tag;
			}
			else
			{
				cLev = kSectionLevelCount;
				selHelper.NumberOfLevels = cLev;
				selHelper.LevelInfo[cLev - 1].tag = (int)ScrBook.ScrBookTags.kflidSections;
				selHelper.LevelInfo[cLev - 1].ihvo = section;
				selHelper.LevelInfo[cLev - 2].tag = tag;
			}
			selHelper.LevelInfo[0].ihvo = paragraph;
			selHelper.AssocPrev = fAssocPrev;

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

			selHelper.SetIhvoRoot(SelectionHelper.SelLimitType.Anchor, book);
			selHelper.SetIhvoRoot(SelectionHelper.SelLimitType.End, book);

			// Now that all the preparation to set the IP is done, set it.
			IVwSelection vwsel = selHelper.SetSelection(this, true, true);

			// Now set the scroll position where the IP will be centered vertically.
			AutoScrollPosition = new Point(-AutoScrollPosition.X,
				-(AutoScrollPosition.Y - IPDistanceFromWindowTop(vwsel) + Height / 2));

			// If the selection is still not visible (which should only be the case if
			// we're at the end of the view), just take whatever MakeSelectionVisible()
			// gives us.
			if (!IsSelectionVisible(vwsel))
				ScrollSelectionIntoView(vwsel, VwScrollSelOpts.kssoDefault);

			if (vwsel == null)
				Debug.WriteLine("SetSelection failed in DiffView.SetInsertionPoint()");
			return (vwsel != null);
		}
Exemplo n.º 19
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.º 20
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.º 21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Goes to the text referenced in the ScrScriptureNote. If it does not find the text,
		/// it makes the closest selection to the referenced text that it can.
		/// </summary>
		/// <param name="note">the note containing the Scripture reference to find</param>
		/// <param name="sendSyncMsg"><c>true</c> to not send a focus sychronization message
		/// when the selection is changed by going to the scripture ref.</param>
		/// ------------------------------------------------------------------------------------
		public void GoToScrScriptureNoteRef(IScrScriptureNote note, bool sendSyncMsg)
		{
			// TODO (TE-1729): Use this method correctly from Annotations view.

			ScrReference scrRef = new ScrReference(note.BeginRef, m_scr.Versification);
			ScrBook book = BookFilter.GetBookByOrd(scrRef.Book);
			if (book == null)
				return;

			int iBook = BookFilter.GetBookIndex(book.Hvo);
			bool fOrigIgnoreAnySyncMessages = false;
			if (m_syncHandler != null)
			{
				fOrigIgnoreAnySyncMessages = m_syncHandler.IgnoreAnySyncMessages;
				m_syncHandler.IgnoreAnySyncMessages = true;
			}

			try
			{
				if (note.Flid == (int)CmPicture.CmPictureTags.kflidCaption)
				{
					SelectCitedTextInPictureCaption(iBook, note);
					return;
				}

				int ichStart, ichEnd;
				string citedText = note.CitedText;
				ITsString citedTextTss = note.CitedTextTss;
				StTxtPara para = note.BeginObjectRA as StTxtPara;
				if (para != null && m_cache.GetOwnerOfObjectOfClass(para.Hvo, ScrDraft.kClassId) == 0)
				{
					if (para.Owner is StFootnote)
					{
						// Make selection in footnote.
						if (TextAtExpectedLoc(para.Contents.Text, citedText, note.BeginOffset, note.EndOffset))
						{
							// Select text in footnote.
							StFootnote footnote = para.Owner as StFootnote;
							if (footnote == null)
								return;

							SelectionHelper selHelper = new SelectionHelper();
							selHelper.AssocPrev = false;
							selHelper.NumberOfLevels = 3;
							selHelper.LevelInfo[2].tag = BookFilter.Tag;
							selHelper.LevelInfo[2].ihvo = iBook;
							selHelper.LevelInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
							selHelper.LevelInfo[1].ihvo = footnote.IndexInOwner;
							selHelper.LevelInfo[0].ihvo = 0;

							// Prepare to move the IP to the specified character in the paragraph.
							selHelper.IchAnchor = note.BeginOffset;
							selHelper.IchEnd = note.EndOffset;

							// Now that all the preparation to set the IP is done, set it.
							selHelper.SetSelection(Callbacks.EditedRootBox.Site, true, true);
						}
						return;
					}

					// Make selection in Scripture text
					if (TextAtExpectedLoc(para.Contents.Text, citedText, note.BeginOffset, note.EndOffset))
					{
						SelectRangeOfChars(iBook, para, note.BeginOffset, note.EndOffset);
						return;
					}

					if (scrRef.Verse == 0)
					{
						// Either a missing chapter number or something in intro material.
						// Not much chance of finding it by reference (even if the chapter number
						// has been added, we never find the 0th verse, and 99% of the time that
						// chapter number would have been added to the same paragraph where it
						// was missing in the first place), so just try to find the text in the
						// paragraph, if it still exists.
						if (string.IsNullOrEmpty(citedText))
						{
							SelectRangeOfChars(iBook, para, note.BeginOffset, note.BeginOffset);
							return;
						}

						// The text may be null if the paragraph only contains the prompt. TE-8315
						if (para.Contents.Text != null)
						{
							int i = para.Contents.Text.IndexOf(citedText);
							if (i >= 0)
							{
								SelectRangeOfChars(iBook, para, i, i + citedText.Length);
								return;
							}
						}
					}
				}


				// A selection could not be made at the specified location. Attempt to go to
				// the specified verse and then try to find the text.

				// REVIEW (TimS): Why do we call GotoVerse here when we select the characters
				// down below? We might consider doing this only if we fail down below.
				if (sendSyncMsg)
					GotoVerse(scrRef);
				else
					GotoVerse_WithoutSynchMsg(scrRef);

				int iSection, iPara;
				if (citedText != null && FindTextInVerse(m_scr, citedTextTss, scrRef, false, out iSection,
					out iPara, out ichStart, out ichEnd))
				{
					// We found the text in the verse at a different character offset.
					SelectRangeOfChars(iBook, iSection, iPara, ichStart, ichEnd);
				}
				else if (note.BeginOffset > 0 && para != null &&
					IsOffsetValidLoc(para.Contents.Text, note.BeginOffset))
				{
					// We couldn't find the cited text at the specified offset, nor anywhere
					// in the paragraph. Therefore, just set the IP at the begin offset.
					SelectRangeOfChars(iBook, para, note.BeginOffset, note.BeginOffset);
				}
			}
			finally
			{
				if (m_syncHandler != null)
					m_syncHandler.IgnoreAnySyncMessages = fOrigIgnoreAnySyncMessages;
			}
		}
Exemplo n.º 22
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.º 23
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.º 24
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Scrolls a footnote paragraph into view.
		/// </summary>
		/// <param name="diff">The sub-diff, which contains the id of the paragraph in the
		/// footnote which is to be scrolled into view. Or null if no footnote is specified.</param>
		/// ------------------------------------------------------------------------------------
		public void ScrollToFootnotePara(Difference diff)
		{
			CheckDisposed();

// TODO:  TE-4610 temporary? ignore scrolling when no footnote in this diff
			//Debug.Assert(diff != null);
			if (diff == null)
				return;

			// Get the paragraph which contains the difference.
			StTxtPara para = new StTxtPara(Cache, diff.HvoCurr != 0 ? diff.HvoCurr : diff.HvoRev);

			// Get the footnote which contains the paragraph.
			StFootnote footnote = new StFootnote(Cache, para.OwnerHVO);

			// Find the index of the paragraph.
			int iPara = para.IndexInOwner;
			if (iPara < 0)
				return;

			// Find index of the footnote.
			int iFootnote = footnote.IndexInOwner;
			if (iFootnote < 0)
				return;

			// Create selection pointing to this footnote.
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = false;
			selHelper.NumberOfLevels = 2;
			selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = iPara;
			selHelper.LevelInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			selHelper.LevelInfo[1].ihvo = iFootnote;
			// note: We don't care about seting the ich stuff for this temporary selection.
			// (The view constructor takes care of highlighting the proper ich range.)
			// Our mission here is only to scroll to the paragraph.
			selHelper.IchAnchor = 0;
			selHelper.IchEnd = 0;

			// Set the selection.
			selHelper.SetSelection(this, true, true);
			ScrollSelectionIntoView(null, VwScrollSelOpts.kssoNearTop);
		}
Exemplo n.º 25
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.º 26
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.º 27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Makes the selection in in the Scripture reference of the specified annotation.
		/// </summary>
		/// <param name="vc">The vc.</param>
		/// <param name="bookIndex">Index of the book.</param>
		/// <param name="iAnnotation">Index of the annotation.</param>
		/// <param name="notesDataEntryView">The notes data entry view.</param>
		/// ------------------------------------------------------------------------------------
		internal void MakeSelectionInNoteRef(TeNotesVc vc, int bookIndex, int iAnnotation,
			NotesDataEntryView notesDataEntryView)
		{
			EnsureNoteIsVisible(vc, bookIndex, iAnnotation, notesDataEntryView);

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.NumberOfLevels = 2;
			selHelper.LevelInfo[0].cpropPrevious = 0;
			selHelper.LevelInfo[0].ich = -1;
			selHelper.LevelInfo[0].ihvo = iAnnotation;
			selHelper.LevelInfo[0].tag = vc.NotesSequenceHandler.Tag;
			selHelper.LevelInfo[0].ws = 0;
			selHelper.LevelInfo[1].cpropPrevious = 0;
			selHelper.LevelInfo[1].ich = -1;
			selHelper.LevelInfo[1].ihvo = bookIndex;
			selHelper.LevelInfo[1].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations;
			selHelper.LevelInfo[1].ws = 0;
			selHelper.IchAnchor = 0;
			selHelper.AssocPrev = false;
			selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor,
				(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginRef);

			selHelper.SetSelection(notesDataEntryView, true, true, VwScrollSelOpts.kssoDefault);
		}
Exemplo n.º 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Make a selection (IP) in the given footnote
		/// </summary>
		/// <param name="iBook">Index of the book (note TestLangProj has footnotes in books 1
		/// and 2)</param>
		/// <param name="iFootnote">Index of the footnote</param>
		/// <param name="ich">index of the character where the IP is to be put</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private void MakeFootnoteSelection(int iBook, int iFootnote, int ich)
		{
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = (ich > 0);
			selHelper.NumberOfLevels = 3;
			selHelper.LevelInfo[2].tag = m_footnoteView.BookFilter.Tag;
			selHelper.LevelInfo[2].ihvo = iBook;
			selHelper.LevelInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			selHelper.LevelInfo[1].ihvo = iFootnote;
			selHelper.LevelInfo[0].ihvo = 0;

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

			// Now that all the preparation to set the IP is done, set it.
			selHelper.SetSelection(m_footnoteView, true, true);
			Application.DoEvents();
		}
Exemplo n.º 29
0
		public void ScrollFootnotePane_OnDraftViewSelectionChange()
		{
			// make sure the option is set to enable synchronous scrolling
			bool saveOldSynchSetting = Options.FootnoteSynchronousScrollingSetting;
			Options.FootnoteSynchronousScrollingSetting = true;

			// Show the footnote pane
			m_firstMainWnd.TheDraftViewWrapper.ShowFootnoteView(null);

			// Set the insertion point into James, just after it's 10th footnote.
			m_firstMainWnd.TheDraftView.SetInsertionPoint(1, 8, 1, 402, false);
			Application.DoEvents();

			// Set up a selection pointing to tenth footnote in footnote pane
			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = false;
			selHelper.NumberOfLevels = 3;
			selHelper.LevelInfo[0].tag = StTextTags.kflidParagraphs;
			selHelper.LevelInfo[0].ihvo = 0;
			selHelper.LevelInfo[1].tag = ScrBookTags.kflidFootnotes;
			selHelper.LevelInfo[1].ihvo = 9;
			selHelper.LevelInfo[2].tag = m_firstDraftView.BookFilter.Tag;
			selHelper.LevelInfo[2].ihvo = 1; //James
			selHelper.IchAnchor = 0;
			selHelper.TextPropId = StTxtParaTags.kflidContents;

			// Verify that our desired footnote selection is visible.
			FootnoteView fnView = m_firstMainWnd.TheDraftViewWrapper.FootnoteView;
			selHelper.SetSelection(fnView, true, false); // not forced to be visible
			Assert.IsTrue(fnView.IsSelectionVisible(selHelper.Selection));

			// reset the synchronous scrolling setting
			Options.FootnoteSynchronousScrollingSetting = saveOldSynchSetting;
		}
Exemplo n.º 30
0
		private void UpdateSelectionForReplacingPreeditText(SelectionHelper selHelper, int countBackspace)
		{
			if ((m_ActionHandler == null || !m_ActionHandler.get_TasksSinceMark(true))
				&& m_InitialSelection != null && m_EndOfPreedit != null)
			{
				// we don't have an action handler (or we have nothing to rollback) which means
				// we didn't roll back the preedit. This means we have to create a range selection
				// that deletes the preedit.
				var bottom = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
				selHelper.IchAnchor = Math.Max(0,
					m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Top) - countBackspace);
				selHelper.IchEnd = Math.Max(bottom,
					m_EndOfPreedit.GetIch(SelectionHelper.SelLimitType.Bottom));
				selHelper.SetSelection(true);
			}
		}