本文整理汇总了C#中SIL.FieldWorks.Common.RootSites.SelectionHelper.SetSelection方法的典型用法代码示例。如果您正苦于以下问题:C# SelectionHelper.SetSelection方法的具体用法?C# SelectionHelper.SetSelection怎么用?C# SelectionHelper.SetSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SIL.FieldWorks.Common.RootSites.SelectionHelper
的用法示例。
在下文中一共展示了SelectionHelper.SetSelection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectFootnoteMarkNextToIP
/// ------------------------------------------------------------------------------------
/// <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;
}
示例2: MakeSelectionInNote
/// ------------------------------------------------------------------------------------
/// <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);
}
示例3: EnsureNoteIsVisible
/// ------------------------------------------------------------------------------------
/// <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);
}
示例4: MergeParasInTable
/// ------------------------------------------------------------------------------------
/// <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;
}
示例5: InsertVerseNumber
//.........这里部分代码省略.........
// 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);
}
示例6: SelectRangeOfChars
/// ------------------------------------------------------------------------------------
/// <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;
}
示例7: MakeSelectionInPictureCaption
/// ------------------------------------------------------------------------------------
/// <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?
}
示例8: InsertSection_EndFirstHeadingPara
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");
}
示例9: ReduceSelectionToIp
/// ------------------------------------------------------------------------------------
/// <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;
}
示例10: InsertSection_BetweenHeadingParas
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");
}
示例11: InsertSection_WithinHeading
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");
}
示例12: InsertSection_AtSectionHeadingBeginning
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");
}
示例13: GetCurrentRefRange
/// ------------------------------------------------------------------------------------
/// <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
{
//.........这里部分代码省略.........
示例14: MergeParasInTable
/// ------------------------------------------------------------------------------------
/// <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;
}
示例15: HandleFootnoteAnchorIconSelected
/// ------------------------------------------------------------------------------------
/// <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);
}
}
}