public GetTss ( SelLimitType limit ) : ITsString | ||
limit | SelLimitType | the part of the selection where tss is to be retrieved (top, /// bottom, end, anchor) |
Résultat | ITsString |
private bool SelIsInEmptyTranslation(SelectionHelper helper, int flid, int hvo) { if (helper.IsRange) return false; // range can't be in empty comment. if (flid != SegmentTags.kflidFreeTranslation && flid != SegmentTags.kflidLiteralTranslation) return false; // translation is always a comment. if (helper.GetTss(SelectionHelper.SelLimitType.Anchor).Length != 0) return false; // translation is non-empty. return true; }
/// ------------------------------------------------------------------------------------ /// <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)}; ; }
private bool SelIsInEmptyTranslation(SelectionHelper helper, int flid, int hvo) { if (helper.IsRange) return false; // range can't be in empty comment. if (flid != (int)CmAnnotation.CmAnnotationTags.kflidComment) return false; // translation is always a comment. if (helper.GetTss(SelectionHelper.SelLimitType.Anchor).Length != 0) return false; // translation is non-empty. int hvoType = Cache.GetObjProperty(hvo, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType); return (hvoType == m_vc.FtSegmentDefn || hvoType == m_vc.LtSegmentDefn); }
protected int GetIndexToRemove(int[] hvos, SelectionHelper sel, bool forward) { int hvo = GetItemHvo(sel, SelectionHelper.SelLimitType.Top); for (int i = 0; i < hvos.Length; i++) { if (hvos[i] == hvo) { ITsString tss = sel.GetTss(SelectionHelper.SelLimitType.Anchor); // if the current ich is at the end of the current string, then we can safely assume // we are at the end of the current item, so remove it or the next item based on what // key was pressed, otherwise we are in the middle in which // case the entire item is selected, or at the beginning, so we remove it or the previous // item based on what key was pressed if (sel.IchAnchor == tss.Length) { if (forward) return i == hvos.Length ? -1 : i + 1; else return i; } else { if (forward) return i == hvos.Length ? -1 : i; else return i - 1; } } } return -1; }
protected int GetIndexToRemove(ICmObject[] objs, SelectionHelper sel, bool forward) { ICmObject obj = GetCmObject(sel, SelectionHelper.SelLimitType.Top); for (int i = 0; i < objs.Length; i++) { if (objs[i] == obj) { var tss = sel.GetTss(SelectionHelper.SelLimitType.Anchor); // if the current ich is at the end of the current string, then we can safely assume // we are at the end of the current item, so remove it or the next item based on what // key was pressed, otherwise we are in the middle in which // case the entire item is selected, or at the beginning, so we remove it or the previous // item based on what key was pressed if (sel.IchAnchor == tss.Length) { if (forward) return i == objs.Length ? -1 : i + 1; return i; } if (forward) return i == objs.Length ? -1 : i; return i - 1; } } return -1; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Common utility for the CurrentRef* properties /// </summary> /// <param name="selhelper">The selection helper representing the current selection /// (or sometimes the current reduced to an IP)</param> /// <param name="selLimit">The limit of the selection (anchor, end, etc.) to get the /// reference of</param> /// <returns>the start and end reference of the given selection, as an array of two /// ScrReference objects</returns> /// ------------------------------------------------------------------------------------ protected ScrReference[] GetCurrentRefRange(SelectionHelper selhelper, SelectionHelper.SelLimitType selLimit) { if (m_cache == null || selhelper == null || BookFilter == null) return new ScrReference[] {ScrReference.Empty, ScrReference.Empty}; ILocationTracker tracker = ((ITeView)Control).LocationTracker; // If there is a current book... BCVRef start = new BCVRef(); BCVRef end = new BCVRef(); int iBook = tracker.GetBookIndex(selhelper, selLimit); if (iBook >= 0 && BookFilter.BookCount > 0) { try { IScrBook book = BookFilter.GetBook(iBook); // if there is not a current section, then use the book and chapter/verse of 0. IScrSection section = tracker.GetSection(selhelper, selLimit); if (section != null) { // If there is a section... int paraHvo = selhelper.GetLevelInfoForTag(StTextTags.kflidParagraphs, selLimit).hvo; IScrTxtPara scrPara = m_cache.ServiceLocator.GetInstance<IScrTxtParaRepository>().GetObject(paraHvo); // Get the ich at either the beginning or the end of the selection, // as specified with limit. (NB that this is relative to the property, not the whole paragraph.) int ich; // Get the TsString, whether in vern or BT ITsString tss; int refWs; SelLevInfo segInfo; int textPropTag = 0; if (selhelper.GetLevelInfoForTag(StTxtParaTags.kflidSegments, selLimit, out segInfo)) { // selection is in a segmented BT segment. Figure the reference based on where the segment is // in the underlying paragraph. tss = scrPara.Contents; // for check below on range of ich. ISegment seg = m_repoSegment.GetObject(segInfo.hvo); ich = seg.BeginOffset; Debug.Assert(seg.Paragraph == scrPara); refWs = -1; // ich is in the paragraph itself, not some CmTranslation } else { textPropTag = selhelper.GetTextPropId(selLimit); if (textPropTag == SimpleRootSite.kTagUserPrompt) { ich = 0; tss = null; } else { ich = selhelper.GetIch(selLimit); tss = selhelper.GetTss(selLimit); // Get the TsString, whether in vern or BT if (ich < 0 || tss == null) { HandleFootnoteAnchorIconSelected(selhelper.Selection, (hvo, flid, wsDummy, ichAnchor) => { SelectionHelper helperTemp = new SelectionHelper(selhelper); ich = helperTemp.IchAnchor = helperTemp.IchEnd = ichAnchor; helperTemp.SetSelection(false, false); tss = helperTemp.GetTss(selLimit); }); } } refWs = GetCurrentBtWs(selLimit); // figures out whether it's in a CmTranslation or the para itself. } Debug.Assert(tss == null || ich <= tss.Length); if ((tss != null && ich <= tss.Length) || textPropTag == SimpleRootSite.kTagUserPrompt) { scrPara.GetRefsAtPosition(refWs, ich, true, out start, out end); // If the chapter number is 0, then use the chapter from the section reference if (end.Chapter == 0) end.Chapter = BCVRef.GetChapterFromBcv(section.VerseRefMin); if (start.Chapter == 0) start.Chapter = BCVRef.GetChapterFromBcv(section.VerseRefMin); } } else { // either it didn't find a level or it didn't find an index. Either way, // it couldn't find a section. start.Book = end.Book = book.CanonicalNum; } } catch { // Bummer man, something went wrong... don't sweat it though, it happens... // This can occur if you are in the introduction or other location that lacks // relevant information or other necessary stuff. } } return new ScrReference[] {new ScrReference(start, m_scr.Versification), new ScrReference(end, m_scr.Versification)}; ; }