本文整理汇总了C#中SIL.FieldWorks.Common.RootSites.SelectionHelper.GetIch方法的典型用法代码示例。如果您正苦于以下问题:C# SelectionHelper.GetIch方法的具体用法?C# SelectionHelper.GetIch怎么用?C# SelectionHelper.GetIch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SIL.FieldWorks.Common.RootSites.SelectionHelper
的用法示例。
在下文中一共展示了SelectionHelper.GetIch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentRefRange
/// ------------------------------------------------------------------------------------
/// <summary>
/// Common utility for the CurrentRef* properties
/// </summary>
/// <param name="selection"></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 virtual ScrReference[] GetCurrentRefRange(SelectionHelper selection,
SelectionHelper.SelLimitType selLimit)
{
if (m_cache == null || selection == 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(selection, selLimit);
if (iBook >= 0 && BookFilter.BookCount > 0)
{
try
{
ScrBook book = BookFilter.GetBook(iBook);
// if there is not a current section, then use the book and chapter/verse of 0.
int hvoSection = tracker.GetSectionHvo(CurrentSelection, selLimit);
if (hvoSection >= 0)
{
// If there is a section...
ScrSection section = new ScrSection(m_cache, hvoSection);
int paraHvo = selection.GetLevelInfoForTag(
(int)StText.StTextTags.kflidParagraphs, selLimit).hvo;
ScrTxtPara scrPara = new ScrTxtPara(m_cache, 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;
SelLevInfo segInfo;
int refWs;
if (selection.GetLevelInfoForTag(StTxtPara.SegmentsFlid(Cache), 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.UnderlyingTsString; // for check below on range of ich.
CmBaseAnnotation seg = new CmBaseAnnotation(Cache, segInfo.hvo);
ich = seg.BeginOffset;
Debug.Assert(seg.BeginObjectRAHvo == scrPara.Hvo);
refWs = -1; // ich is in the paragraph itself, not some CmTranslation
}
else
{
ich = selection.GetIch(selLimit);
// Get the TsString, whether in vern or BT
tss = selection.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)
{
scrPara.GetBCVRefAtPosition(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)}; ;
}
示例2: IsBookSelection
/// ------------------------------------------------------------------------------------
/// <summary>
/// Determines if the selection is an entire book
/// </summary>
/// <param name="helper"></param>
/// <param name="topInfo"></param>
/// <param name="bottomInfo"></param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
private bool IsBookSelection (SelectionHelper helper, SelLevInfo[] topInfo,
SelLevInfo[] bottomInfo)
{
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
int bookTitleLevelCount = tracker.GetLevelCount((int)ScrBook.ScrBookTags.kflidTitle);
if (topInfo.Length == bookTitleLevelCount && bottomInfo.Length == bookTitleLevelCount)
{
// Verify that selection goes from beginning of book title to
// beginning of title in next book.
return (tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top) ==
tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Bottom) - 1 &&
topInfo[1].tag == (int)ScrBook.ScrBookTags.kflidTitle &&
topInfo[1].ihvo == 0 &&
topInfo[0].tag == (int)StText.StTextTags.kflidParagraphs &&
topInfo[0].ihvo == 0 &&
bottomInfo[1].tag == (int)ScrBook.ScrBookTags.kflidTitle &&
bottomInfo[1].ihvo == 0 &&
bottomInfo[0].tag == (int)StText.StTextTags.kflidParagraphs &&
bottomInfo[0].ihvo == 0 &&
helper.IchAnchor == 0 &&
helper.IchEnd == 0);
}
else if (topInfo.Length == bookTitleLevelCount && bottomInfo.Length ==
tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent))
{
// Check that selection is at start of title
bool bookSel = (tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top) ==
tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Bottom) &&
topInfo[1].tag == (int)ScrBook.ScrBookTags.kflidTitle &&
topInfo[1].ihvo == 0 &&
topInfo[0].tag == (int)StText.StTextTags.kflidParagraphs &&
topInfo[0].ihvo == 0 &&
helper.GetIch(SelectionHelper.SelLimitType.Top) == 0);
if (bookSel)
{
// Get information about last paragraph of the book
ScrBook book = new ScrBook(m_cache,
tracker.GetBookHvo(helper, SelectionHelper.SelLimitType.Top));
int iSection = book.SectionsOS.Count - 1;
IScrSection section = book.SectionsOS[iSection];
int iPara = section.ContentOA.ParagraphsOS.Count - 1;
StTxtPara para = (StTxtPara) section.ContentOA.ParagraphsOS[iPara];
int ichEnd = para.Contents.Length;
// Check that selection is at end of last paragraph of book
bookSel = (tracker.GetSectionIndexInBook(helper,
SelectionHelper.SelLimitType.Bottom) == iSection &&
bottomInfo[1].tag == (int)ScrSection.ScrSectionTags.kflidContent &&
bottomInfo[0].ihvo == iPara &&
bottomInfo[0].tag == (int)StText.StTextTags.kflidParagraphs &&
helper.GetIch(SelectionHelper.SelLimitType.Bottom) == ichEnd);
}
return bookSel;
}
return false;
}
示例3: DeleteMultiSectionContentRange
/// ------------------------------------------------------------------------------------
/// <summary>
/// Delete the given selection, removing any spanned sections. Selection is assumed to
/// start in content of one section and end in content of another section.
/// </summary>
/// <param name="helper"></param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
private bool DeleteMultiSectionContentRange(SelectionHelper helper)
{
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
int ihvoBook = tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top);
int ihvoSectionStart =
tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top);
int ihvoSectionEnd =
tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Bottom);
if (ihvoBook < 0 || ihvoSectionStart < 0 || ihvoSectionEnd < 0)
{
// Something changed catastrophically. Maybe we added introductory material?
Debug.Assert(false);
return false;
}
ScrBook book = BookFilter.GetBook(ihvoBook);
IScrSection sectionStart = book.SectionsOS[ihvoSectionStart];
IScrSection sectionEnd = book.SectionsOS[ihvoSectionEnd];
int ihvoParaStart = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo;
StTxtPara paraStart = (StTxtPara) sectionStart.ContentOA.ParagraphsOS[ihvoParaStart];
int ihvoParaEnd = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[0].ihvo;
StTxtPara paraEnd = (StTxtPara) sectionEnd.ContentOA.ParagraphsOS[ihvoParaEnd];
int ichStart = helper.GetIch(SelectionHelper.SelLimitType.Top);
int ichEnd = helper.GetIch(SelectionHelper.SelLimitType.Bottom);
if (helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].tag !=
(int)StText.StTextTags.kflidParagraphs)
{
// Something changed catastrophically. StText has something in it other than paragraphs!
Debug.Assert(false);
return false;
}
// Remove footnotes of sections that will be deleted entirely
int iSection = ihvoSectionStart;
int iPara = ihvoParaStart;
int ich = ichStart;
int tag = (int)ScrSection.ScrSectionTags.kflidContent;
ScrFootnote firstFootnoteToDelete = ScrFootnote.FindNextFootnote(m_cache,
book, ref iSection, ref iPara, ref ich, ref tag, false);
if (iSection < ihvoSectionEnd || (iSection == ihvoSectionEnd &&
(iPara < ihvoParaEnd || (iPara == ihvoParaEnd && ich <= ichEnd))) ||
tag != (int)ScrSection.ScrSectionTags.kflidContent)
{
iSection = ihvoSectionEnd;
iPara = ihvoParaEnd;
ich = ichEnd;
tag = (int)ScrSection.ScrSectionTags.kflidContent;
ScrFootnote lastFootnoteToDelete = ScrFootnote.FindPreviousFootnote(m_cache,
book, ref iSection, ref iPara, ref ich, ref tag, true);
if (iSection > ihvoSectionStart || (iSection == ihvoSectionStart &&
(iPara > ihvoParaStart || (iPara == ihvoParaStart && ich >= ichStart))) ||
tag != (int)ScrSection.ScrSectionTags.kflidContent)
{
DeleteFootnotes(book, firstFootnoteToDelete, lastFootnoteToDelete,
paraStart.Hvo, paraEnd.Hvo);
}
}
// Remove any trailing portion of the start section that is selected
IStText content = sectionStart.ContentOA;
for (iPara = content.ParagraphsOS.Count - 1; iPara > ihvoParaStart; iPara--)
content.ParagraphsOS.RemoveAt(iPara);
ITsStrBldr startContentBldr = paraStart.Contents.UnderlyingTsString.GetBldr();
startContentBldr.Replace(ichStart, startContentBldr.Length, string.Empty, null);
// Copy any trailing portion (not selected) of the end section to the start section.
int ihvoMoveStart;
// Move whole ending paragraph of the selection if selection ends at the beginning
// of the paragraph
if (ichEnd == 0)
ihvoMoveStart = ihvoParaEnd;
else
ihvoMoveStart = ihvoParaEnd + 1;
if (ihvoMoveStart < sectionEnd.ContentOA.ParagraphsOS.Count)
m_cache.MoveOwningSequence(sectionEnd.ContentOAHvo,
(int)StText.StTextTags.kflidParagraphs, ihvoMoveStart,
sectionEnd.ContentOA.ParagraphsOS.Count - 1, sectionStart.ContentOAHvo,
(int)StText.StTextTags.kflidParagraphs,
sectionStart.ContentOA.ParagraphsOS.Count);
// Copy end of last paragraph of selection to end of first paragraph of selection
if (ichEnd > 0)
{
AboutToDelete(helper, paraEnd.Hvo, sectionEnd.ContentOA.Hvo,
(int)StText.StTextTags.kflidParagraphs, ihvoParaEnd, false);
ITsStrBldr endContentBldr = paraEnd.Contents.UnderlyingTsString.GetBldr();
endContentBldr.Replace(0, ichEnd, string.Empty, null);
int curEnd = startContentBldr.Length;
startContentBldr.ReplaceTsString(curEnd, curEnd, endContentBldr.GetString());
//.........这里部分代码省略.........
示例4: IsSectionDeletion
/// ------------------------------------------------------------------------------------
/// <summary>
/// If a single section is wholly selected or the selection goes from the top of one
/// section to the top of the following section, then the selected section may be
/// deleted.
/// </summary>
/// <param name="helper"></param>
/// <param name="topInfo"></param>
/// <param name="bottomInfo"></param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
private bool IsSectionDeletion(SelectionHelper helper, SelLevInfo[] topInfo,
SelLevInfo[] bottomInfo)
{
bool sectionDeletion = false;
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
int clev = tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent);
int levelText = helper.GetLevelForTag((int)ScrSection.ScrSectionTags.kflidContent);
if (levelText < 0)
levelText = helper.GetLevelForTag((int)ScrSection.ScrSectionTags.kflidHeading);
int levelPara = helper.GetLevelForTag((int)StText.StTextTags.kflidParagraphs);
// the selection must be the right number of levels deep.
if (topInfo.Length == clev && bottomInfo.Length == clev && levelText >= 0 && levelPara >= 0)
{
// if the selection is in the same scripture and the same book...
if (tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top) ==
tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Bottom) &&
// not selecting something weird
topInfo[levelText - 1].tag == (int)StText.StTextTags.kflidParagraphs &&
bottomInfo[levelText - 1].tag == (int)StText.StTextTags.kflidParagraphs)
{
// Selection top is in one section and bottom is in a following one
if (tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top) <=
tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Bottom) - 1 &&
// if the selection begins and ends in section heading
topInfo[levelText].tag == (int)ScrSection.ScrSectionTags.kflidHeading &&
bottomInfo[levelText].tag == (int)ScrSection.ScrSectionTags.kflidHeading &&
topInfo[levelText].ihvo == 0 &&
bottomInfo[levelText].ihvo == 0 &&
// and the selection begins and ends in the first paragraph of those headings
topInfo[levelPara].ihvo == 0 &&
bottomInfo[levelPara].ihvo == 0)
{
// Does selection go from the beginning of one heading to the beginning of another?
sectionDeletion = (helper.IchAnchor == 0 && helper.IchEnd == 0);
}
// Selection starts at beginning of one section heading and ends
// at end of content of another section.
else if (tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top) <=
tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Bottom) &&
// Selection top is in section heading and bottom is in content
topInfo[levelText].tag == (int)ScrSection.ScrSectionTags.kflidHeading &&
bottomInfo[levelText].tag == (int)ScrSection.ScrSectionTags.kflidContent &&
topInfo[levelText].ihvo == 0 &&
bottomInfo[levelText].ihvo == 0 &&
// Top of selection is in first heading paragraph
topInfo[levelPara].ihvo == 0)
{
int ichTop = helper.GetIch(SelectionHelper.SelLimitType.Top);
sectionDeletion =
ichTop == 0 && IsSelectionAtEndOfSection(helper, bottomInfo, clev);
}
}
}
return sectionDeletion;
}
示例5: IsSelectionAtEndOfSection
/// ------------------------------------------------------------------------------------
/// <summary>
/// Selections at end of section.
/// </summary>
/// <param name="helper">The helper.</param>
/// <param name="bottomInfo">The bottom info.</param>
/// <param name="clev">The clev.</param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
private bool IsSelectionAtEndOfSection(SelectionHelper helper, SelLevInfo[] bottomInfo,
int clev)
{
bool atEndOfSection = false;
// Is the bottom of the selection in the last para of the section?
ScrSection bottomSection = new ScrSection(m_cache,
((ITeView)Control).LocationTracker.GetSectionHvo(
helper, SelectionHelper.SelLimitType.Bottom));
IStText bottomContent = bottomSection.ContentOA;
int levelPara = helper.GetLevelForTag((int)StText.StTextTags.kflidParagraphs);
if (bottomInfo[levelPara].ihvo == bottomContent.ParagraphsOS.Count - 1)
{
StTxtPara lastPara = new StTxtPara(m_cache, bottomInfo[levelPara].hvo);
ITsString lastParaContents = lastPara.Contents.UnderlyingTsString;
int ichBottom = helper.GetIch(SelectionHelper.SelLimitType.Bottom);
atEndOfSection = ichBottom == lastParaContents.Length;
}
return atEndOfSection;
}
示例6: GetInsertionIndex
private void GetInsertionIndex(SelectionHelper sel, out ComplexConcPatternNode parent, out int index)
{
ComplexConcPatternNode curNode = GetNode(sel, SelectionHelper.SelLimitType.Top);
if (m_patternModel.Root.IsLeaf || curNode == null)
{
parent = m_patternModel.Root;
index = 0;
return;
}
parent = curNode.Parent;
int ich = sel.GetIch(SelectionHelper.SelLimitType.Top);
index = GetNodeIndex(curNode);
if (ich != 0)
index++;
}
示例7: AdjustTextStructure
//.........这里部分代码省略.........
else
{
// If selection bottoms at the last paragraph of the heading, move heading
// paragraphs to content of this section
if (section.HeadingOA.ParagraphsOS.Count - 1 == bottom[0].ihvo)
{
section.MoveHeadingParasToContent(top[0].ihvo);
iPara = 0;
}
else
// The selection must be only inner paragraphs in the section head,
// not including the first or last paragraphs.
// In this case, we want the selected paragraph(s) to become content for
// the heading paragraph(s) above it, and the following section head
// paragraph(s) become the heading of a new section object.
{
int iParaStart = top[0].ihvo;
int iParabottom = bottom[0].ihvo;
section.SplitSectionHeading(iSection, iParaStart, iParabottom);
iPara = 0;
}
}
// Select all paragraphs in content that were part of section heading (and have
// now been moved to iSection, iPara)
SetInsertionPoint(iBook, iSection, iPara, 0, false);
// Get bottom point of selection and update it to point to beginning of
// last paragraph of old heading. Use offsets of current selection.
SelectionHelper newHelper = SelectionHelper.Create(Callbacks.EditedRootBox.Site);
SelLevInfo[] levInfo = newHelper.GetLevelInfo(SelectionHelper.SelLimitType.End);
levInfo[0].ihvo += bottom[0].ihvo - top[0].ihvo;
newHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, levInfo);
newHelper.IchAnchor = selHelper.GetIch(SelectionHelper.SelLimitType.Top);
newHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
newHelper.SetSelection(true);
} //bottom of CASE 1 "Change a section head to a scripture paragraph"
// CASE 2: Change scripture paragraph to a section head
// - only if the new style has "section head" structure, the selection is in
// one paragraph, and that paragraph is part of the section content
else if (top[1].tag == (int)ScrSection.ScrSectionTags.kflidContent &&
newStyle.Structure == StructureValues.Heading)
{
// Check selected paragraphs for chapter or verse numbers - style will not be
// changed if any are found.
ScrSection section = new ScrSection(m_cache, tracker.GetSectionHvo(selHelper,
SelectionHelper.SelLimitType.Top));
for (int i = top[0].ihvo; i <= bottom[0].ihvo; i++)
{
ScrTxtPara para =
new ScrTxtPara(m_cache, section.ContentOA.ParagraphsOS.HvoArray[i]);
if (para.HasChapterOrVerseNumbers())
{
// Cancel the request if chapter or verse numbers are present.
// display message box if not running in a test
if (!InTestMode)
{
MessageBox.Show(Control,
TeResourceHelper.GetResourceString("kstidParaHasNumbers"),
TeResourceHelper.GetResourceString("kstidApplicationName"),
MessageBoxButtons.OK);
}
return false;
}
}
示例8: GetInsertionIndex
protected virtual int GetInsertionIndex(int[] hvos, SelectionHelper sel)
{
if (hvos.Length == 0)
{
return 0;
}
else
{
int curHvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Top);
int ich = sel.GetIch(SelectionHelper.SelLimitType.Top);
for (int i = 0; i < hvos.Length; i++)
{
// if the current ich is 0, then we can safely assume we are at the beginning of
// the current item, so insert before it, otherwise we are in the middle in which
// case the entire item is selected or at the end, so we insert after
if (hvos[i] == curHvo)
return ich == 0 ? i : i + 1;
}
return hvos.Length;
}
}
示例9: LocationInfo
/// --------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="LocationInfo"/> class.
/// </summary>
/// <param name="helper">The selection helper used to initialize this location.
/// </param>
/// --------------------------------------------------------------------------------
public LocationInfo(SelectionHelper helper)
{
m_location = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom);
m_tag = helper.GetTextPropId(SelectionHelper.SelLimitType.Bottom);
m_ichMin = m_ichLim = helper.GetIch(SelectionHelper.SelLimitType.Bottom);
m_cpropPrev = helper.GetNumberOfPreviousProps(SelectionHelper.SelLimitType.Bottom);
m_ws = SelectionHelper.GetFirstWsOfSelection(helper.Selection);
}
示例10: 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
{
//.........这里部分代码省略.........
示例11: GetInsertionIndex
protected virtual int GetInsertionIndex(ICmObject[] objs, SelectionHelper sel)
{
if (objs.Length == 0)
{
return 0;
}
ICmObject curObj = GetCmObject(sel, SelectionHelper.SelLimitType.Top);
int ich = sel.GetIch(SelectionHelper.SelLimitType.Top);
for (int i = 0; i < objs.Length; i++)
{
// if the current ich is 0, then we can safely assume we are at the beginning of
// the current item, so insert before it, otherwise we are in the middle in which
// case the entire item is selected or at the end, so we insert after
if (objs[i] == curObj)
return ich == 0 ? i : i + 1;
}
return objs.Length;
}
示例12: DeletePicture
/// ------------------------------------------------------------------------------------
/// <summary>
/// Deletes the picture specified by the hvo.
/// </summary>
/// <param name="helper">Selection containing the picture.</param>
/// <param name="hvoPic">hvo of picture.</param>
/// ------------------------------------------------------------------------------------
protected void DeletePicture(SelectionHelper helper, int hvoPic)
{
SelLevInfo info = helper.GetLevelInfoForTag(StTextTags.kflidParagraphs);
int paraHvo = info.hvo;
Debug.Assert(paraHvo != 0);
int iPara = info.ihvo;
IStTxtPara para = m_repoScrTxtPara.GetObject(paraHvo);
int tag, hvo;
bool fGotSelectedScrElement = GetSelectedScrElement(out tag, out hvo);
Debug.Assert(fGotSelectedScrElement);
int iBook = ((ITeView)Control).LocationTracker.GetBookIndex(helper,
SelectionHelper.SelLimitType.Anchor);
int iSection = ((ITeView)Control).LocationTracker.GetSectionIndexInBook(helper,
SelectionHelper.SelLimitType.Anchor);
int ichOrc = -1;
int iSegment = -1;
if (IsBackTranslation)
{
ICmPictureRepository repo = Cache.ServiceLocator.GetInstance<ICmPictureRepository>();
ISegment segment;
if (helper.GetLevelInfoForTag(StTxtParaTags.kflidSegments, out info))
{
segment = m_cache.ServiceLocator.GetInstance<ISegmentRepository>().GetObject(info.hvo);
iSegment = segment.IndexInOwner;
}
else
segment = para.GetSegmentForOffsetInFreeTranslation(helper.GetIch(SelectionHelper.SelLimitType.Top), RootVcDefaultWritingSystem);
ITsString contents = segment.FreeTranslation.get_String(RootVcDefaultWritingSystem);
Guid guidPic = Cache.ServiceLocator.GetInstance<ICmPictureRepository>().GetObject(hvoPic).Guid;
for (int i = 0; i < contents.RunCount; i++)
{
string str = contents.get_Properties(i).GetStrPropValue((int)FwTextPropType.ktptObjData);
if (str != null && MiscUtils.GetGuidFromObjData(str.Substring(1)) == guidPic)
{
ichOrc = contents.get_MinOfRun(i);
int limOfRun = contents.get_LimOfRun(i);
ITsStrBldr bldr = contents.GetBldr();
bldr.Replace(ichOrc, limOfRun, string.Empty, null);
segment.FreeTranslation.set_String(RootVcDefaultWritingSystem, bldr.GetString());
if (ContentType == StVc.ContentTypes.kctSimpleBT)
ichOrc += para.GetOffsetInFreeTranslationForStartOfSegment(segment, RootVcDefaultWritingSystem);
break;
}
}
}
else
ichOrc = para.DeletePicture(hvoPic);
Debug.Assert(ichOrc >= 0);
// TODO (TE-4967): do a prop change that actually works.
// m_cache.DomainDataByFlid.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
// para.Hvo, StTxtParaTags.kflidContents,
// startOfRun, 0, 1);
if (m_app != null)
m_app.RefreshAllViews();
SelectRangeOfChars(iBook, iSection, tag, iPara, iSegment, ichOrc, ichOrc, true, true,
true, VwScrollSelOpts.kssoDefault);
}
示例13: DeleteMultiSectionContentRange
/// ------------------------------------------------------------------------------------
/// <summary>
/// Delete the given selection, removing any spanned sections. Selection is assumed to
/// start in content of one section and end in content of another section.
/// </summary>
/// <param name="helper"></param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
private bool DeleteMultiSectionContentRange(SelectionHelper helper)
{
if (helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].tag !=
StTextTags.kflidParagraphs)
{
// Something changed catastrophically. StText has something in it other than paragraphs!
Debug.Assert(false);
return false;
}
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
int iBook = tracker.GetBookIndex(helper, SelectionHelper.SelLimitType.Top);
int iSectionStart = tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top);
int iSectionEnd = tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Bottom);
if (iBook < 0 || iSectionStart < 0 || iSectionEnd < 0)
{
// Something changed catastrophically. Maybe we added introductory material?
Debug.Assert(false);
return false;
}
int iParaStart = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo;
int iParaEnd = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[0].ihvo;
int ichStart = helper.GetIch(SelectionHelper.SelLimitType.Top);
int ichEnd = helper.GetIch(SelectionHelper.SelLimitType.Bottom);
// Do the deletion
IScrBook book = BookFilter.GetBook(iBook);
book.DeleteMultiSectionContentRange(iSectionStart, iSectionEnd, iParaStart,
iParaEnd, ichStart, ichEnd);
// Set the insertion point.
SetInsertionPoint(iBook, iSectionStart, iParaStart, ichStart,
helper.AssocPrev);
return true;
}
示例14: AdjustTextStructure
//.........这里部分代码省略.........
section.SplitSectionHeading_ExistingParaBecomesContent(top[0].ihvo,
bottom[0].ihvo, newStyle);
// update insertion point to first paragraph(s) of new section content
iPara = 0;
}
}
else
{
// If selection bottoms at the last paragraph of the heading, move heading
// paragraphs to content of this section
if (section.HeadingOA.ParagraphsOS.Count - 1 == bottom[0].ihvo)
{
section.MoveHeadingParasToContent(top[0].ihvo, newStyle);
iPara = 0;
}
else
// The selection must be only inner paragraphs in the section head,
// not including the first or last paragraphs.
// In this case, we want the selected paragraph(s) to become content for
// the heading paragraph(s) above it, and the following section head
// paragraph(s) to become the heading of a new section object.
{
int iParaStart = top[0].ihvo;
int iParabottom = bottom[0].ihvo;
section.SplitSectionHeading_ExistingParaBecomesContent(iParaStart, iParabottom, newStyle);
iPara = 0;
}
}
// Select the original range of paragraphs and characters, now in the new content para
// TODO: FWR-1542 Currently, a selection made during a unit of work can only be an insertion point.
SelectRangeOfChars(iBook, iSection, ScrSectionTags.kflidContent, iPara,
selHelper.GetIch(SelectionHelper.SelLimitType.Top),
selHelper.GetIch(SelectionHelper.SelLimitType.Top),
true, true, selHelper.AssocPrev);
} //bottom of CASE 1 "Change a section head to a scripture paragraph"
// CASE 2: Change scripture paragraph to a section head
// - only if the new style has "section head" structure and the paragraph(s)
// is/are part of the section content.
else if (top[1].tag == ScrSectionTags.kflidContent &&
newStyle.Structure == StructureValues.Heading)
{
IScrSection section = tracker.GetSection(selHelper, SelectionHelper.SelLimitType.Top);
int iBook = tracker.GetBookIndex(selHelper, SelectionHelper.SelLimitType.Top);
int iSection = tracker.GetSectionIndexInBook(selHelper, SelectionHelper.SelLimitType.Top);
int iPara;
IScrBook book = (IScrBook)section.Owner;
// bool indicates if this section is the last one in either Intro or Scripture
bool lastSectionInContext;
if (iSection == book.SectionsOS.Count - 1) // last section ends book
lastSectionInContext = true;
else
lastSectionInContext = !SectionsHaveSameContext(section, section.NextSection);
try
{
if (AreAllParagraphsSelected(top, bottom, section.ContentOA))
{
if (!lastSectionInContext)
{
// Need to combine this section with the following section.
// Heading of combined section will be section1.Heading +
示例15: UpdateSelectionForReplacingPreeditText
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);
}
}