public GetTextPropId ( SelLimitType type ) : int | ||
type | SelLimitType | |
Résultat | int |
protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit) { if (sel == null) return -1; int tag = sel.GetTextPropId(limit); if (tag == AffixRuleFormulaVc.ktagLeftEmpty || tag == AffixRuleFormulaVc.ktagRightEmpty || tag == MoAffixProcessTags.kflidOutput) return tag; foreach (SelLevInfo level in sel.GetLevelInfo(limit)) { if (level.tag == MoAffixProcessTags.kflidOutput) return level.tag; if (level.tag == MoAffixProcessTags.kflidInput) return level.hvo; } return -1; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns whether or not the selection is in a user prompt. (Unless it is in a /// picture..I (JohnT) am not sure how a picture selection comes to seem to be in a user /// prompt, but see TE-7813: double-clicking one crashes here if we don't check.) /// </summary> /// <param name="helper">The selection to check.</param> /// <returns>true if the selection is in a user prompt; otherwise, false.</returns> /// ------------------------------------------------------------------------------------ private bool IsSelectionInPrompt(SelectionHelper helper) { return (helper != null && helper.Selection.SelType != VwSelType.kstPicture && helper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) == SimpleRootSite.kTagUserPrompt && helper.GetTextPropId(SelectionHelper.SelLimitType.End) == SimpleRootSite.kTagUserPrompt); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes a section heading. /// </summary> /// <param name="helper">Selection information</param> /// <param name="allowHeadingText">if <code>true</code> section head will be deleted /// even if heading contains text</param> /// <param name="positionAtEnd">if <code>true</code> IP will be at end of paragraph /// before top point of current selection</param> /// <returns><code>true</code> if deletion was done</returns> /// ------------------------------------------------------------------------------------ private bool DeleteSectionHead(SelectionHelper helper, bool allowHeadingText, bool positionAtEnd) { ILocationTracker tracker = ((ITeView)Control).LocationTracker; if (helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) != tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent)) return false; int tag = helper.GetTextPropId(SelectionHelper.SelLimitType.Top); if (tag != (int)StTxtPara.StTxtParaTags.kflidContents && tag != SimpleRootSite.kTagUserPrompt) { // Currently this is the only possible leaf property in draft view; // if this changes somehow, we'll probably need to enhance this code. Debug.Assert(false); return false; } int hvoBook = tracker.GetBookHvo(helper, SelectionHelper.SelLimitType.Top); if (hvoBook < 0) { Debug.Assert(false); return false; } ScrBook book = new ScrBook(m_cache, hvoBook); int iSection = tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top); if (iSection < 0) { // Something changed catastrophically. Book has something in it other than sections. Debug.Assert(false); return false; } IScrSection section = book.SectionsOS[iSection]; 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; } // For now we just handle the heading. if (helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag != (int)ScrSection.ScrSectionTags.kflidHeading) { // Add code here if desired to handle bsp/del at boundary of body. return false; } // OK, we're dealing with a change at the boundary of a section heading // (in a paragraph of an StText that is the heading of an ScrSection in an ScrBook). IStText text = section.HeadingOA; int ihvoPara = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo; IStTxtPara para = (IStTxtPara)(text.ParagraphsOS[ihvoPara]); if (!allowHeadingText && para.Contents.Length > 0) { // The current heading paragraph has something in it! // For now we won't try to handle this. // (The problem is knowing what to do with the undeleted header text... // make it part of the previous section? The previous header? Delete it?) return false; } if (text.ParagraphsOS.Count != 1) { // Backspace at start or delete at end of non-empty section, and the paragraph is // empty. Do nothing. return false; // Other options: // - delete the section? But what do we do with the rest of its heading? // - delete the empty paragraph? That's easy...just // text.ParagraphsOS.RemoveAt(ihvoPara); // But where do we put the IP afterwards? At the end of the previous body, // for bsp, or the start of our own body, for del? Or keep it in the heading? } // OK, we're in a completely empty section heading. // If it's the very first section of the book, we can't join it to the previous // section, so do nothing. (May eventually enhance to join the two books... // perhaps after asking for confirmation!) if (iSection == 0) return false; // Finally...we know we're going to merge the two sections. MergeContentWithPreviousSection(helper, book, section, iSection, positionAtEnd); return true; }
protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit) { int tag = sel.GetTextPropId(limit); switch (tag) { case MetaRuleFormulaVc.ktagLeftEnv: return PhMetathesisRule.kidxLeftEnv; case MetaRuleFormulaVc.ktagLeftSwitch: return PhMetathesisRule.kidxLeftSwitch; case MetaRuleFormulaVc.ktagRightSwitch: return PhMetathesisRule.kidxRightSwitch; case MetaRuleFormulaVc.ktagRightEnv: return PhMetathesisRule.kidxRightEnv; } int hvo = GetItemHvo(sel, limit); if (hvo == 0) return -1; return Rule.GetStrucChangeIndex(hvo); }
/// -------------------------------------------------------------------------------- /// <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); }
protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit) { int tag = sel.GetTextPropId(limit); switch (tag) { case MetaRuleFormulaVc.ktagLeftEnv: return PhMetathesisRuleTags.kidxLeftEnv; case MetaRuleFormulaVc.ktagLeftSwitch: return PhMetathesisRuleTags.kidxLeftSwitch; case MetaRuleFormulaVc.ktagRightSwitch: return PhMetathesisRuleTags.kidxRightSwitch; case MetaRuleFormulaVc.ktagRightEnv: return PhMetathesisRuleTags.kidxRightEnv; } var obj = GetItem(sel, limit); if (obj == null) return -1; return Rule.GetStrucChangeIndex(obj as IPhSimpleContext); }
/// ------------------------------------------------------------------------------------ /// <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)}; ; }
protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit) { if (sel == null) return -1; foreach (SelLevInfo level in sel.GetLevelInfo(limit)) { if (IsCellFlid(level.tag)) return level.tag; } if (IsCellFlid(sel.GetTextPropId(limit))) return sel.GetTextPropId(limit); return -1; }