本文整理汇总了C#中SIL.FieldWorks.Common.RootSites.SelectionHelper.GetLevelInfoForTag方法的典型用法代码示例。如果您正苦于以下问题:C# SelectionHelper.GetLevelInfoForTag方法的具体用法?C# SelectionHelper.GetLevelInfoForTag怎么用?C# SelectionHelper.GetLevelInfoForTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SIL.FieldWorks.Common.RootSites.SelectionHelper
的用法示例。
在下文中一共展示了SelectionHelper.GetLevelInfoForTag方法的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: 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;
}
示例3: 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)
{
int paraHvo = helper.GetLevelInfoForTag((int)StText.StTextTags.kflidParagraphs).hvo;
Debug.Assert(paraHvo != 0);
int iBook, iSection;
iBook = ((ITeView)Control).LocationTracker.GetBookIndex(helper,
SelectionHelper.SelLimitType.Anchor);
iSection = ((ITeView)Control).LocationTracker.GetSectionIndexInBook(helper,
SelectionHelper.SelLimitType.Anchor);
StTxtPara para = new StTxtPara(m_cache, paraHvo);
// Find the ORC and delete it from the paragraph
ITsString contents = para.Contents.UnderlyingTsString;
int startOfRun = 0;
for(int i = 0; i < contents.RunCount; i++)
{
string str = contents.get_Properties(i).GetStrPropValue(
(int)FwTextPropType.ktptObjData);
if (str != null)
{
Guid guid = MiscUtils.GetGuidFromObjData(str.Substring(1));
int hvo = m_cache.GetIdFromGuid(guid);
if (hvo == hvoPic)
{
ITsStrBldr bldr = contents.GetBldr();
startOfRun = contents.get_MinOfRun(i);
bldr.Replace(startOfRun, contents.get_LimOfRun(i),
string.Empty, null);
para.Contents.UnderlyingTsString = bldr.GetString();
break;
}
}
}
// TODO (TE-4967): do a prop change that actually works.
// m_cache.PropChanged(null, PropChangeType.kpctNotifyAll,
// para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents,
// startOfRun, 0, 1);
if (FwApp.App != null)
FwApp.App.RefreshAllViews(m_cache);
m_cache.DeleteObject(hvoPic);
// TODO (TimS): This code to create a selection in the paragraph the picture was
// in probably won't work when deleting a picture in back translation
// material (which isn't possible to insert yet).
((ITeView)Control).LocationTracker.SetBookAndSection(helper,
SelectionHelper.SelLimitType.Anchor, iBook, iSection);
helper.RemoveLevel((int)StTxtPara.StTxtParaTags.kflidContents);
if (Callbacks != null && Callbacks.EditedRootBox != null) // may not exist in tests.
{
try
{
MakeSimpleTextSelection(helper.LevelInfo,
(int)StTxtPara.StTxtParaTags.kflidContents, startOfRun);
}
catch
{
// If we couldn't make the selection in the contents, it's probably because
// we are in a user prompt, so try that instead.
MakeSimpleTextSelection(helper.LevelInfo, (int)SimpleRootSite.kTagUserPrompt,
startOfRun);
}
Callbacks.EditedRootBox.Site.ScrollSelectionIntoView(Callbacks.EditedRootBox.Selection,
VwScrollSelOpts.kssoNearTop);
}
}
示例4: InsertFootnote
/// ------------------------------------------------------------------------------------
/// <summary>
/// Inserts a footnote at the given selection
/// </summary>
/// <param name="selHelper">Current selection information</param>
/// <param name="styleName">style name for created footnote</param>
/// <param name="iFootnote">out: If selHelper is in vernacular para, the ihvo of the
/// footnote just inserted. If selHelper is in back trans, the ihvo of the footnote
/// corresponding to the ref ORC just inserted in the BT, or -1 no corresponding</param>
/// <returns>The created/corresponding footnote</returns>
/// ------------------------------------------------------------------------------------
public virtual ScrFootnote InsertFootnote(SelectionHelper selHelper, string styleName,
out int iFootnote)
{
CheckDisposed();
// Get any selected text.
ITsString tssSelected;
IVwSelection vwsel = selHelper.Selection;
if (IsSelectionInOneEditableProp(vwsel))
vwsel.GetSelectionString(out tssSelected, string.Empty);
else
tssSelected = StringUtils.MakeTss(string.Empty, m_cache.DefaultVernWs);
int hvoObj;
ITsString tssPara;
int propTag;
int ws;
selHelper.ReduceToIp(SelectionHelper.SelLimitType.Bottom, false, false);
int ichSel = GetSelectionInfo(selHelper, out hvoObj, out propTag, out tssPara, out ws);
if (propTag == (int)StTxtPara.StTxtParaTags.kflidContents)
ws = Cache.DefaultVernWs;
// get book info
IScrBook book = GetCurrentBook(m_cache);
// get paragraph info
int paraHvo = selHelper.GetLevelInfoForTag((int)StText.StTextTags.kflidParagraphs).hvo;
StTxtPara para = new StTxtPara(m_cache, paraHvo);
if (tssSelected.Length > 0)
{
tssSelected = StringUtils.RemoveORCsAndStylesFromTSS(tssSelected,
new List<string>(new string[] {ScrStyleNames.ChapterNumber, ScrStyleNames.VerseNumber}),
false, m_cache.LanguageWritingSystemFactoryAccessor);
if (tssSelected.Length > 0)
{
ITsStrBldr bldr = tssSelected.GetBldr();
bldr.SetStrPropValue(0, bldr.Length, (int) FwTextPropType.ktptNamedStyle, ScrStyleNames.ReferencedText);
bldr.ReplaceRgch(bldr.Length, bldr.Length, " ", 1, StyleUtils.CharStyleTextProps(null, ws));
tssSelected = bldr.GetString();
}
}
ScrFootnote footnote = null;
string undo;
string redo;
if (styleName == ScrStyleNames.CrossRefFootnoteParagraph)
TeResourceHelper.MakeUndoRedoLabels("kstidInsertCrossReference", out undo, out redo);
else
TeResourceHelper.MakeUndoRedoLabels("kstidInsertFootnote", out undo, out redo);
using (UndoTaskHelper undoTaskHelper =
new UndoTaskHelper(Callbacks.EditedRootBox.Site, undo, redo, true))
{
try
{
if (propTag == (int)StTxtPara.StTxtParaTags.kflidContents)
{
// Inserting footnote into the vernacular paragraph
iFootnote = FindFootnotePosition(book, selHelper);
ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
// create the footnote and insert its marker into the paragraph's string
// builder.
footnote = ScrFootnote.InsertFootnoteAt(book, styleName, iFootnote, tsStrBldr, ichSel);
// BEFORE we insert the ORC in the paragraph, we need to insert an empty
// paragraph into the new StFootnote, because the para style is needed to
// determine the footnote marker type.
StTxtPara footnotePara = new StTxtPara();
footnote.ParagraphsOS.Append(footnotePara);
// If we wait for this to be created by the VC, its creation won't be part of the
// Undo task, and we won't be able to Undo creating the footnote, because the paragraph
// will own something that Undo doesn't know to delete (TE-7988).
footnotePara.GetOrCreateBT();
ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
styleName);
footnotePara.StyleRules = propsBldr.GetTextProps();
// Record information, as if we were typing the footnote caller, that allows
// segment boundaries to be adjusted properly.
OnAboutToEdit();
// update the paragraph contents to include the footnote marker
para.Contents.UnderlyingTsString = tsStrBldr.GetString();
// Finish off any necessary annotation adjustments.
m_annotationAdjuster.OnFinishedEdit();
// Insert the selected text (or an empty run) into the footnote paragraph.
//.........这里部分代码省略.........
示例5: HandleBsOrDelAtTextBoundary
/// ------------------------------------------------------------------------------------
/// <summary>
/// Try to do something about an IP selection deletion that is at the start or end of an
/// StText. If successful return true, otherwise false.
/// </summary>
/// <param name="helper"></param>
/// <param name="dpt"></param>
/// <returns><c>true</c> if we successfully handled the deletion.</returns>
/// ------------------------------------------------------------------------------------
internal bool HandleBsOrDelAtTextBoundary(SelectionHelper helper, VwDelProbType dpt)
{
CheckDisposed();
SelLevInfo[] levInfo = helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor);
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
// bail out if we are not in a paragraph within a scripture section
if (levInfo.Length !=
tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent) ||
tracker.GetSectionIndexInView(helper, SelectionHelper.SelLimitType.Anchor) < 0 ||
levInfo[0].tag != (int)StText.StTextTags.kflidParagraphs)
{
// Assume we are in a book title
SelLevInfo dummyInfo;
if (helper.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidTitle, out dummyInfo))
return MergeParasInTable(helper, dpt);
return false;
}
// Level 1 will have tags showing which field of section is selected
int iLevelSection = helper.GetLevelForTag((int)ScrSection.ScrSectionTags.kflidHeading);
if (iLevelSection >= 0)
{
if (levInfo[0].ihvo == 0 && dpt == VwDelProbType.kdptBsAtStartPara)
{
// first paragraph of section head
return HandleBackspaceAfterEmptyContentParagraph(helper);
}
else if (levInfo[0].ihvo == 0 && helper.IchAnchor == 0)
{
// Delete was pressed in an empty section head - try to combine with previous
// return DeleteSectionHead(helper, false, false);
if (dpt == VwDelProbType.kdptBsAtStartPara)
return HandleBackspaceAfterEmptySectionHeadParagraph(helper);
return HandleDeleteBeforeEmptySectionHeadParagraph(helper);
}
// NOTE: we check the vector size for the parent of the paragraph (levInfo[1].hvo)
// but with our own tag (levInfo[0].tag)!
else if (levInfo[0].ihvo == m_cache.GetVectorSize(levInfo[iLevelSection].hvo,
levInfo[0].tag) - 1
&& dpt == VwDelProbType.kdptDelAtEndPara)
{
// last paragraph of section head
return HandleDeleteBeforeEmptySectionContentParagraph(helper);
}
else
{
// other problem deletion: e.g. delete in BT side-by-side view. Because
// we're displaying the paragraphs in a table with two columns, the views
// code can't handle that. We have to merge the two paragraphs manually.
return MergeParasInTable(helper, dpt);
}
}
else if (helper.GetLevelForTag((int)ScrSection.ScrSectionTags.kflidContent) >= 0)
{
iLevelSection = helper.GetLevelForTag((int)ScrSection.ScrSectionTags.kflidContent);
if (levInfo[0].ihvo == 0 && dpt == VwDelProbType.kdptBsAtStartPara)
{
// first paragraph of section
return HandleBackspaceAfterEmptySectionHeadParagraph(helper);
}
else if (levInfo[0].ihvo == 0 && helper.IchAnchor == 0)
{
// Delete was pressed in an empty section content - try to combine with previous
if (dpt == VwDelProbType.kdptBsAtStartPara)
return HandleBackspaceAfterEmptyContentParagraph(helper);
return HandleDeleteBeforeEmptySectionContentParagraph(helper);
}
// NOTE: we check the vector size for the parent of the paragraph (levInfo[1].hvo)
// but with our own tag (levInfo[0].tag)!
else if (levInfo[0].ihvo == m_cache.GetVectorSize(levInfo[iLevelSection].hvo,
levInfo[0].tag) - 1 && dpt == VwDelProbType.kdptDelAtEndPara)
{
// last paragraph of section
return HandleDeleteBeforeEmptySectionHeadParagraph(helper);
}
else
{
// other problem deletion: e.g. delete in BT side-by-side view. Because
// we're displaying the paragraphs in a table with two columns, the views
// code can't handle that. We have to merge the two paragraphs manually.
return MergeParasInTable(helper, dpt);
}
}
return false;
}
示例6: GetBookIndex
/// ------------------------------------------------------------------------------------
/// <summary>
/// Get the index of the current book in the book filter, or -1 if there is no
/// current book (e.g. no selection or empty view).
/// </summary>
/// <param name="selHelper">The selection helper.</param>
/// <param name="selLimitType">Which end of the selection</param>
/// <returns>
/// Index of the current book, or -1 if there is no current book.
/// </returns>
/// <remarks>The returned value is suitable for making a selection.</remarks>
/// ------------------------------------------------------------------------------------
public virtual int GetBookIndex(SelectionHelper selHelper,
SelectionHelper.SelLimitType selLimitType)
{
if (selHelper == null)
return -1;
SelLevInfo levInfo;
if (selHelper.GetLevelInfoForTag(BookTag, selLimitType, out levInfo))
return levInfo.ihvo;
return -1;
}
示例7: 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
{
//.........这里部分代码省略.........
示例8: 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);
}
示例9: InsertVerseNumber
/// ------------------------------------------------------------------------------------
/// <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 || IsSelectionInPrompt(selHelper));
// 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);
// The current run is a chapter number and IP is either at the beginning of the line or
// in the middle of the chapter number, we need to jump past it to insert the verse number
// otherwise it will insert it before the chapter number or in the chapter number.
int iRun = tssSel.get_RunAt(ichSelOrig);
if (tssSel.Style(iRun) == ScrStyleNames.ChapterNumber &&
(ichSelOrig == 0 || ichSelOrig > tssSel.get_MinOfRun(iRun)))
ichSelOrig = tssSel.get_LimOfRun(iRun);
// Adjust the insertion position to the beginning of a word - not in the middle
// (may move to an existing verse number too)
int ichWord = tssSel.FindWordBoundary(ichSelOrig, UnicodeCharProps, ScrStyleNames.ChapterAndVerse);
// 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);
SelLevInfo paraInfo = selHelper.GetLevelInfoForTag(StTextTags.kflidParagraphs);
IScrTxtPara para = m_cache.ServiceLocator.GetInstance<IScrTxtParaRepository>().GetObject(paraInfo.hvo);
// 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 == StTxtParaTags.kflidContents)
{
// Insert missing verse number in vernacular
para.InsertMissingVerseNumberInVern(ichSelOrig, ichWord, out sVerseNumIns,
out ichLimIns);
}
}
// 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 == StTxtParaTags.kflidContents)
{
// Update verse number in vernacular
para.UpdateExistingVerseNumberInVern(ichMin, ichLim, out sVerseNumIns,
out ichLimIns);
}
else
{
//Update verse number in back translation
para.UpdateExistingVerseNumberInBt(wsAlt, ichMin, ichLim, 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 == StTxtParaTags.kflidContents)
{
para.InsertNextVerseNumberInVern(ichWord, out sVerseNumIns, out ichLimIns);
}
else
{
para.InsertNextVerseNumberInBt(wsAlt, ichWord, out sVerseNumIns,
//.........这里部分代码省略.........
示例10: SelectAssociatedPara
/// ------------------------------------------------------------------------------------
/// <summary>
/// Selects the paragraph in the DraftView or FootnoteView associated with the style.
/// </summary>
/// <param name="origSelection">selection user originally made</param>
/// <param name="view">The DraftView or FootnoteView</param>
/// ------------------------------------------------------------------------------------
private void SelectAssociatedPara(SelectionHelper origSelection, IVwRootSite view)
{
SelLevInfo paraInfoAnchor = origSelection.GetLevelInfoForTag(
StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Top);
SelLevInfo paraInfoEnd = origSelection.GetLevelInfoForTag(
StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Bottom);
if (paraInfoAnchor.hvo != m_prevPara1Hvo || paraInfoEnd.hvo != m_prevPara2Hvo)
{
// The selection changed paragraphs, so update the selection in the
// DraftView or FootnoteView
IStTxtPara para1 = m_fdoCache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(paraInfoAnchor.hvo);
IStTxtPara para2 = m_fdoCache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(paraInfoEnd.hvo);
SelectionHelper helper = MakeSelection(para1, para2, view);
IVwSelection sel = helper.SetSelection(view, true, false);
// If the selection fails then try selecting the user prompt.
if (sel == null)
{
AdjustSelectionForPrompt(helper, para1, para2);
sel = helper.SetSelection(view, true, false);
}
Debug.Assert(sel != null || ((SimpleRootSite)view).ReadOnlyView);
m_prevPara1Hvo = paraInfoAnchor.hvo;
m_prevPara2Hvo = paraInfoEnd.hvo;
}
}
示例11: GetPara
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets an StTxtPara representing the paragraph of the given selection.
/// </summary>
/// ------------------------------------------------------------------------------------
private IStTxtPara GetPara(SelectionHelper helper, out IStText text, out int iPara, out int tag)
{
SelLevInfo paraLevInfo;
if (!helper.GetLevelInfoForTag(StTextTags.kflidParagraphs, out paraLevInfo))
{
text = null;
iPara = tag = -1;
return null;
}
iPara = paraLevInfo.ihvo;
ILocationTracker tracker = ((ITeView)Control).LocationTracker;
IScrBook book = tracker.GetBook(helper, SelectionHelper.SelLimitType.Top);
IScrSection section = tracker.GetSection(helper, SelectionHelper.SelLimitType.Top);
if (section == null)
{
text = book.TitleOA;
tag = ScrBookTags.kflidTitle;
}
else
{
tag = (helper.GetLevelForTag(ScrSectionTags.kflidContent) >= 0 ?
ScrSectionTags.kflidContent : ScrSectionTags.kflidHeading);
text = (tag == ScrSectionTags.kflidHeading ? section.HeadingOA : section.ContentOA);
}
return text[iPara];
}
示例12: GetSection
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the current section, or null if we're not in a section (e.g. the IP is in a
/// title).
/// </summary>
/// <param name="selHelper">The selection helper.</param>
/// <param name="selLimitType">Which end of the selection</param>
/// <returns>The section or null if we're not in a section.</returns>
/// ------------------------------------------------------------------------------------
public virtual IScrSection GetSection(SelectionHelper selHelper,
SelectionHelper.SelLimitType selLimitType)
{
if (selHelper == null)
return null;
SelLevInfo levInfo;
if (selHelper.GetLevelInfoForTag(ScrBookTags.kflidSections,
selLimitType, out levInfo))
{
IScrSection section;
if (m_cache.ServiceLocator.GetInstance<IScrSectionRepository>().TryGetObject(levInfo.hvo, out section))
return section;
}
return null;
}
示例13: GetSectionIndexInView
/// ------------------------------------------------------------------------------------
/// <summary>
/// Get the index of the section (relative to RootBox), or -1 if we're not in a section
/// (e.g. the IP is in a title).
/// </summary>
/// <param name="selHelper">The selection helper.</param>
/// <param name="selLimitType">Which end of the selection</param>
/// <returns>
/// Index of the section, or -1 if we're not in a section.
/// </returns>
/// <remarks>The returned value is suitable for making a selection.</remarks>
/// ------------------------------------------------------------------------------------
public virtual int GetSectionIndexInView(SelectionHelper selHelper,
SelectionHelper.SelLimitType selLimitType)
{
if (selHelper == null)
return -1;
SelLevInfo levInfo;
if (selHelper.GetLevelInfoForTag(ScrBookTags.kflidSections, selLimitType, out levInfo))
{
return levInfo.ihvo;
}
return -1;
}
示例14: GetBook
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the current book, or null if there is no current book (e.g. no selection or
/// empty view).
/// </summary>
/// <param name="selHelper">The selection helper.</param>
/// <param name="selLimitType">Which end of the selection</param>
/// <returns>The book, or null if there isn't a current book.</returns>
/// ------------------------------------------------------------------------------------
public virtual IScrBook GetBook(SelectionHelper selHelper,
SelectionHelper.SelLimitType selLimitType)
{
if (selHelper == null)
return null;
SelLevInfo levInfo;
if (selHelper.GetLevelInfoForTag(BookTag, selLimitType, out levInfo))
return m_cache.ServiceLocator.GetInstance<IScrBookRepository>().GetObject(levInfo.hvo);
return null;
}
示例15: MoveToNextTranslation
/// ------------------------------------------------------------------------------------
/// <summary>
/// Find and select the next translation meeting a given condition
/// </summary>
/// <param name="selection">The selection where to start the search.
/// NOTE: The selection must have all of the info set in the LevelInfo (hvo, ihvo)</param>
/// <param name="condition">Condition the cack translation must meet</param>
/// ------------------------------------------------------------------------------------
private void MoveToNextTranslation(SelectionHelper selection,
Func<ICmTranslation, bool> condition)
{
SelLevInfo bookInfo;
SelLevInfo paraInfo;
SelLevInfo sectionInfo;
bool fFoundBookLevel = selection.GetLevelInfoForTag(BookFilter.Tag, out bookInfo);
bool fFoundSectionLevel = selection.GetLevelInfoForTag(
ScrBookTags.kflidSections, out sectionInfo);
int secLev = selection.GetLevelForTag(ScrBookTags.kflidSections);
bool fFoundParaLevel = selection.GetLevelInfoForTag(
StTextTags.kflidParagraphs, out paraInfo);
if (!fFoundBookLevel || !fFoundParaLevel)
return;
// Look through all the books in the book filter
int bookStartIndex = bookInfo.ihvo;
int sectionStartIndex = 0;
int sectionTag;
int paraStartIndex = paraInfo.ihvo + 1;
int paraIndex;
if (fFoundSectionLevel)
{
// start with current section
sectionStartIndex = sectionInfo.ihvo;
sectionTag = selection.LevelInfo[secLev - 1].tag;
}
else
{
// no section, so this must be the title - Look through the title paragraphs
IScrBook checkBook = BookFilter.GetBook(bookStartIndex);
paraIndex = FindNextTranslationInText(checkBook.TitleOA, paraStartIndex, condition);
if (paraIndex >= 0)
{
// select the title paragraph
SetInsertionPoint(ScrBookTags.kflidTitle, bookStartIndex, 0, paraIndex);
return;
}
// continue the search with the current book
sectionTag = ScrSectionTags.kflidHeading;
paraStartIndex = 0;
}
for (int bookIndex = bookStartIndex; bookIndex < BookFilter.BookCount; bookIndex++)
{
IScrBook checkBook = BookFilter.GetBook(bookIndex);
if (bookIndex > bookStartIndex)
{
// Look through the title paragraphs
paraIndex = FindNextTranslationInText(checkBook.TitleOA, 0, condition);
if (paraIndex >= 0)
{
// select the title paragraph
SetInsertionPoint(ScrBookTags.kflidTitle, bookIndex, 0, paraIndex);
return;
}
}
// Look through the sections in order.
for (int sectionIndex = sectionStartIndex;
sectionIndex < checkBook.SectionsOS.Count; sectionIndex++)
{
IScrSection checkSection = checkBook.SectionsOS[sectionIndex];
// Look in the paragraphs (could be either content or heading)
IStText text = (sectionTag == ScrSectionTags.kflidHeading) ?
checkSection.HeadingOA : checkSection.ContentOA;
paraIndex = FindNextTranslationInText(text, paraStartIndex, condition);
if (paraIndex >= 0)
{
// select the paragraph
SetInsertionPoint(sectionTag, bookIndex, sectionIndex, paraIndex);
return;
}
// Look in the content paragraphs, if we haven't already
if (sectionTag == ScrSectionTags.kflidHeading)
{
sectionTag = ScrSectionTags.kflidContent;
paraIndex = FindNextTranslationInText(checkSection.ContentOA, 0, condition);
if (paraIndex >= 0)
{
// select the content paragraph
SetInsertionPoint(sectionTag, bookIndex, sectionIndex, paraIndex);
return;
}
}
sectionTag = ScrSectionTags.kflidHeading;
paraStartIndex = 0;
//.........这里部分代码省略.........