Example #1
0
		// this code was added back when we were trying to display some special UI for editing
		// verse numbers, rather than allowing normal editing.
		///// ------------------------------------------------------------------------------------
		///// <summary>
		///// Changes the mouse cursor if we are over a verse number
		///// </summary>
		///// <param name="sel">The selection</param>
		///// <returns>True if we set a cursor, false otherwise</returns>
		///// ------------------------------------------------------------------------------------
		//protected override bool SetCustomCursor(IVwSelection sel)
		//{
		//    if (Callbacks.EditedRootBox == null)
		//        return false;
		//    SelectionHelper helper = SelectionHelper.Create(sel, Callbacks.EditedRootBox.Site);
		//    if (helper == null || helper.SelProps == null)
		//        return false;
		//    string styleName =
		//        helper.SelProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
		//    if (styleName == ScrStyleNames.VerseNumber)
		//    {
		//        Control.Cursor = Cursors.Arrow;
		//        return true;
		//    }
		//    return false;
		//}

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method is used to get a notification when an owning object-replacement character
		/// (ORC) is deleted. ORCs are used to mark locations in the text of things like pictures
		/// or footnotes. In the case of footnotes, when an owning footnote ORC is deleted, we
		/// need to find the corresponding footnote and delete it.
		/// </summary>
		/// <param name="guid">The GUID of the footnote being deleted.</param>
		/// ------------------------------------------------------------------------------------
		public override void ObjDeleted(ref Guid guid)
		{
			CheckDisposed();

			if (PreventObjDeletions)
				return;

			// This is a check to avoid fallout from a time when we incorrectly imported BT
			// footnote ORCs as owning.
			if (IsBackTranslation)
				return;

			int footnoteHvo = m_cache.GetIdFromGuid(guid);
			if (footnoteHvo == 0)
				return;

			int clsid = m_cache.GetClassOfObject(footnoteHvo);
			if (clsid == 0)
				return;

			// Delete the footnote.
			if (clsid == StFootnote.kClassId)
			{
				using (new WaitCursor(Control))
				{
					ScrFootnote footnote = new ScrFootnote(m_cache, footnoteHvo);
					int paraHvo = footnote.ContainingParagraphHvo;
					// If there's no (vernacular) paragraph with an ORC that references this footnote,
					// there can't be a translation either.
					if (paraHvo > 0)
					{
						StTxtPara para = new StTxtPara(m_cache, paraHvo);
						para.DeleteAnyBtMarkersForFootnote(guid);
					}
					ScrFootnote.DeleteFootnote(footnote);
				}
			}
		}
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete all footnotes between firstFootnoteToDelete and lastFootnoteToDelete. Clean
		/// up BT ORCs for the paragraphs specified.
		/// </summary>
		/// <param name="book">Book that contains the sections to delete</param>
		/// <param name="firstFootnoteToDelete">First footnote that will be deleted
		/// (might be null).</param>
		/// <param name="lastFootnoteToDelete">Last footnote that will be deleted
		/// (might be null).</param>
		/// <param name="hvoFirstPara">First (possibly partial) paragraph being deleted that
		/// might contain ORCs for the first footnotes. Any footnotes being deleted whose ORCs
		/// are in this paragraph will have their corresponding BT ORCs removed as well.
		/// If zero, we don't bother to remove any corresponding BT ORCs in the first para.</param>
		/// <param name="hvoLastPara">Last (possibly partial) paragraph being deleted that
		/// might contain ORCs for the last footnotes. Any footnotes being deleted whose ORCs
		/// are in this paragraph will have their corresponding BT ORCs removed as well.
		/// If zero, we don't bother to remove any corresponding BT ORCs in the last para.</param>
		/// ------------------------------------------------------------------------------------
		private void DeleteFootnotes(IScrBook book, ScrFootnote firstFootnoteToDelete,
			ScrFootnote lastFootnoteToDelete, int hvoFirstPara, int hvoLastPara)
		{
			Debug.Assert((firstFootnoteToDelete == null && lastFootnoteToDelete == null)
				|| (firstFootnoteToDelete != null && lastFootnoteToDelete != null));

			if (firstFootnoteToDelete != null)
			{
				bool fDeleteFootnote = false;
				int[] hvos = book.FootnotesOS.HvoArray;
				for (int i = hvos.Length - 1; i >= 0; i--)
				{
					if (hvos[i] == lastFootnoteToDelete.Hvo)
						fDeleteFootnote = true; // we are now in the range of footnotes to delete

					if (fDeleteFootnote)
					{
						// This code fixes TE-4882.
						ScrFootnote footnote = new ScrFootnote(m_cache, hvos[i]);
						int hvoPara = footnote.ContainingParagraphHvo;
						Debug.Assert(hvoPara > 0);
						if ((hvoPara == hvoFirstPara || hvoPara == hvoLastPara) && hvoPara > 0)
						{
							StTxtPara para = new StTxtPara(m_cache, hvoPara);
							para.DeleteAnyBtMarkersForFootnote(footnote.Guid);
						}
						m_cache.DeleteObject(hvos[i]);
					}

					if (hvos[i] == firstFootnoteToDelete.Hvo)
						break;
				}
			}
		}
Example #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes a footnote along with its marker in the text. This also recalculates the
		/// footnote markers of following footnotes.
		/// </summary>
		/// <param name="footnote"></param>
		/// ------------------------------------------------------------------------------------
		public static void DeleteFootnoteAndMarker(ScrFootnote footnote)
		{
			// Paragraph changes are not monitored by cache - refresh cache for book before
			// doing deletion
			IScrBook book = new ScrBook(footnote.Cache, footnote.OwnerHVO);
			// REVIEW: Probably not needed now??? ((ScrBook)book).RefreshFootnoteRefs();

			// Get paragraph containing footnote and search for run having footnote ref.
			int hvoPara = footnote.ContainingParagraphHvo;
			if (hvoPara != 0)
			{
				StTxtPara para = new StTxtPara(footnote.Cache, hvoPara);
				para.DeleteAnyBtMarkersForFootnote(footnote.Guid);
				ITsString tssContent = para.Contents.UnderlyingTsString;
				TsRunInfo runInfo = new TsRunInfo();
				int i;
				for (i = 0; i < tssContent.RunCount; i++)
				{
					ITsTextProps textProps = tssContent.FetchRunInfo(i, out runInfo);
					string strGuid =
						textProps.GetStrPropValue((int)FwTextPropType.ktptObjData);
					if (strGuid != null)
					{
						Guid guid = MiscUtils.GetGuidFromObjData(strGuid.Substring(1));
						if (footnote.Guid == guid)
							break;
					}
				}
				System.Diagnostics.Debug.Assert(i < tssContent.RunCount, "Footnote marker not found in text");

				// Remove footnote ref from paragraph - then delete the footnote
				ITsStrBldr bldr = tssContent.GetBldr();
				bldr.Replace(runInfo.ichMin, runInfo.ichLim, string.Empty, null);
				para.Contents.UnderlyingTsString = bldr.GetString();
			}
			DeleteFootnote(footnote);
		}