ReduceToIp() public method

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.
public ReduceToIp ( SelLimitType limit, bool fMakeVisible, bool fInstall ) : IVwSelection
limit SelLimitType The current selection limit to reduce to
fMakeVisible bool Indicates whether to scroll the IP into view.
fInstall bool True to install the created selection, false otherwise
return IVwSelection
Esempio n. 1
0
		/// ------------------------------------------------------------------------------------
		/// <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.
						footnotePara.Contents.UnderlyingTsString = tssSelected;

						// Do a prop change to get the footnote updated in all views
						m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, book.Hvo,
							(int)ScrBook.ScrBookTags.kflidFootnotes, iFootnote, 1, 0);
					}
					else
					{
						// Inserting footnote reference ORC into a back translation
						ICmTranslation btParaTrans = para.GetOrCreateBT();
						ITsString btTss = btParaTrans.Translation.GetAlternative(ws).UnderlyingTsString;
						footnote = FindVernParaFootnote(ichSel, btTss, para);
						if (footnote != null)
						{
							// Insert footnote reference ORC into back translation paragraph.
							ITsStrBldr tssBldr = btTss.GetBldr();
							//if reference to footnote already somewhere else in para, delete it first
							int ichDel = StTxtPara.DeleteBtFootnoteMarker(tssBldr, footnote.Guid);
							if (ichDel >= 0 && ichSel > ichDel)
								ichSel -= footnote.FootnoteMarker.Length;

							footnote.InsertRefORCIntoTrans(tssBldr, ichSel, ws);
							btParaTrans.Translation.SetAlternative(tssBldr.GetString(), ws);
							iFootnote = footnote.IndexInOwner;

							if (tssSelected.Length > 0)
							{
								ICmTranslation btFootnoteTrans = ((StTxtPara) footnote.ParagraphsOS[0]).GetOrCreateBT();
								ITsString btFootnoteTss = btFootnoteTrans.Translation.GetAlternative(ws).UnderlyingTsString;

								// Insert any selected text into this back translation for the footnote paragraph.
								btFootnoteTrans.Translation.SetAlternative(tssSelected, ws);
							}
						}
						else
						{
							iFootnote = -1;
							MiscUtils.ErrorBeep(); // No footnote reference ORC inserted
						}
					}
				}
				catch
				{
					undoTaskHelper.EndUndoTask = false;
					throw; // rethrow the original exception
				}
			}
			return footnote;
		}
Esempio n. 2
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
Esempio n. 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets a (new) selection helper that represents an insertion point at the specified
		/// limit of this selection
		/// </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>
		/// ------------------------------------------------------------------------------------
		public virtual SelectionHelper ReduceSelectionToIp(SelLimitType limit, bool fMakeVisible,
			bool fInstall)
		{
			SelectionHelper textSelHelper = new SelectionHelper(this);
			return textSelHelper.ReduceToIp(limit, fMakeVisible, fInstall) == null ? null : textSelHelper;
		}
Esempio n. 4
0
		/// ------------------------------------------------------------------------------------
		/// <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 IStFootnote InsertFootnote(SelectionHelper selHelper, string styleName,
			out int iFootnote)
		{
			CheckDisposed();
			// Get any selected text.
			ITsString tssSelectedText;
			IVwSelection vwsel = selHelper.Selection;
			if (!IsSelectionInUserPrompt && IsSelectionInOneEditableProp(vwsel))
				vwsel.GetSelectionString(out tssSelectedText, string.Empty);
			else
				tssSelectedText = TsStringUtils.MakeTss(string.Empty, m_cache.DefaultVernWs);

			int hvoObj;
			ITsString tssSel; // This is either the vernacular or the BT, depending on the selection location.
			int propTag;
			int ws;
			selHelper.ReduceToIp(SelectionHelper.SelLimitType.Bottom, false, false);
			int ichSel = GetSelectionInfo(selHelper, out hvoObj, out propTag, out tssSel, out ws);
			if (propTag == StTxtParaTags.kflidContents)
				ws = Cache.DefaultVernWs;

			// Make sure the selection is updated with the new ich position in case it was wrong
			// (e.g. If the selection is in a user prompt) (TE-8919)
			selHelper.IchAnchor = selHelper.IchEnd = ichSel;

			// get book info
			IScrBook book = GetCurrentBook(m_cache);

			// get paragraph info
			int paraHvo = selHelper.GetLevelInfoForTag(StTextTags.kflidParagraphs).hvo;
			IScrTxtPara para = m_repoScrTxtPara.GetObject(paraHvo);

			tssSelectedText = TsStringUtils.GetCleanTsString(tssSelectedText, ScrStyleNames.ChapterAndVerse);
			Debug.Assert(tssSelectedText != null);
			if (tssSelectedText.Length > 0)
			{
				ITsStrBldr bldr = tssSelectedText.GetBldr();
				bldr.SetStrPropValue(0, bldr.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.ReferencedText);
				bldr.ReplaceRgch(bldr.Length, bldr.Length, " ", 1, StyleUtils.CharStyleTextProps(null, ws));
				tssSelectedText = bldr.GetString();
			}

			//Cache.ActionHandlerAccessor.AddAction(new UndoWithRefreshAction());
			IScrFootnote footnote = null;
			iFootnote = -1;
			if (propTag == StTxtParaTags.kflidContents)
			{
				// Inserting footnote into the vernacular paragraph
				iFootnote = FindFootnotePosition(book, selHelper);
				ITsStrBldr tsStrBldr = para.Contents.GetBldr();
				// create the footnote and insert its marker into the paragraph's string
				// builder.
				footnote = book.InsertFootnoteAt(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.
				IStTxtPara footnotePara = footnote.AddNewTextPara(styleName);

				// update the paragraph contents to include the footnote marker
				para.Contents = tsStrBldr.GetString();

				// Insert the selected text (or an empty run) into the footnote paragraph.
				footnotePara.Contents = tssSelectedText;
			}
			else
			{
				IMultiString bt = null;
				if (propTag == SegmentTags.kflidFreeTranslation)
				{
					// Inserting footnote reference ORC into a segment free translation
					ISegment segment = m_repoSegment.GetObject(selHelper.GetLevelInfoForTag(StTxtParaTags.kflidSegments).hvo);
					bt = segment.FreeTranslation;
					footnote = FindVernParaFootnote(segment, ws);
				}
				else if (propTag == CmTranslationTags.kflidTranslation)
				{
					// Inserting footnote reference ORC into a back translation
					footnote = FindVernParaFootnote(ichSel, tssSel, para);
					bt = para.GetBT().Translation;
				}

				if (footnote != null)
				{
					// Insert footnote reference ORC into back translation paragraph.
					ITsStrBldr tssBldr = tssSel.GetBldr();
					//if reference to footnote already somewhere else in para, delete it first
					int ichDel = TsStringUtils.DeleteOrcFromBuilder(tssBldr, footnote.Guid);
					if (ichDel >= 0 && ichSel > ichDel)
						ichSel--;

					TsStringUtils.InsertOrcIntoPara(footnote.Guid, FwObjDataTypes.kodtNameGuidHot,
						tssBldr, ichSel, ichSel, ws);
					bt.set_String(ws, tssBldr.GetString());
					iFootnote = footnote.IndexInOwner;

					if (tssSelectedText.Length > 0)
					{
						ICmTranslation btFootnoteTrans = ((IStTxtPara)footnote.ParagraphsOS[0]).GetBT();
						ITsString btFootnoteTss = btFootnoteTrans.Translation.get_String(ws);

						// Insert any selected text into this back translation for the footnote paragraph.
						btFootnoteTrans.Translation.set_String(ws, tssSelectedText);
					}
				}
			}

			if (footnote == null)
				MiscUtils.ErrorBeep(); // No footnote reference ORC inserted
			else
			{
				// Update the selection in the view that the footnote was inserted.
				selHelper.UpdateScrollLocation(); // Make sure this is up-to-date
				selHelper = new SelectionHelper(selHelper); // Get a new copy, so any subsequent changes won't affect us.
				selHelper.IchAnchor++;
				selHelper.AssocPrev = false; // Associate away from the newly inserted marker to avoid shifting scroll position by a couple pixels
				selHelper.IchEnd = selHelper.IchAnchor;
				Callbacks.RequestVisibleSelectionAtEndOfUow(selHelper);
			}

			return footnote;
		}