Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes a footnote
        /// </summary>
        /// <param name="args"></param>
        /// <returns><c>true</c> if we handle this</returns>
        /// ------------------------------------------------------------------------------------
        protected bool OnDeleteFootnote(object args)
        {
            if (DataUpdateMonitor.IsUpdateInProgress(DataAccess))
            {
                return(true);                //discard this event
            }
            if (!ValidFootnoteSelection)
            {
                return(true);
            }

            string undo;
            string redo;

            TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo);
            using (new UndoTaskHelper(this, undo, redo, false))
                using (new DataUpdateMonitor(this, RootBox.DataAccess, this, "DeleteFootnote"))
                {
                    SelectionHelper helper  = SelectionHelper.Create(this);
                    int             fnLevel = helper.GetLevelForTag((int)ScrBook.ScrBookTags.kflidFootnotes);

                    if (helper.Selection.IsRange)
                    {
                        DeleteFootnoteRange(helper);
                    }
                    else
                    {
                        // There's no range selection, so delete only one footnote
                        ScrFootnote footnote = new ScrFootnote(m_fdoCache, helper.LevelInfo[fnLevel].hvo);
                        ScrFootnote.DeleteFootnoteAndMarker(footnote);
                    }

                    if (RootBox.Height <= 0)
                    {
                        DraftView.Focus();
                    }
                    else
                    {
                        int     iBook     = helper.LevelInfo[fnLevel + 1].ihvo;
                        ScrBook book      = m_bookFilter.GetBook(iBook);
                        int     iFootnote = helper.LevelInfo[fnLevel].ihvo;

                        // If the last footnote in the book was deleted find a footnote to move to
                        if (iFootnote >= book.FootnotesOS.Count)
                        {
                            FindNearestFootnote(ref iBook, ref iFootnote);
                        }

                        FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, 0);
                    }
                }

            return(true);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes footnotes when there is a range selection.
        /// </summary>
        /// <param name="helper"></param>
        /// ------------------------------------------------------------------------------------
        private void DeleteFootnoteRange(SelectionHelper helper)
        {
            int nTopLevels    = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top);
            int nBottomLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Bottom);

            // Get the index of the book containing the first footnote in the selection.
            // Then get the index of the footnote within that book.
            int iFirstBook =
                helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 1].ihvo;
            int iFirstFootnote =
                helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 2].ihvo;

            // Get the index of the book containing the last footnote in the selection.
            // Then get the index of the footnote within that book.
            int iLastBook =
                helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 1].ihvo;
            int iLastFootnote =
                helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 2].ihvo;

            // Loop through the books containing footnotes in the selection.
            for (int iBook = iFirstBook; iBook <= iLastBook; iBook++)
            {
                ScrBook book = BookFilter.GetBook(iBook);

                int iBeg = iFirstFootnote;
                if (iFirstBook != iLastBook && iBook > iFirstBook)
                {
                    iBeg = 0;
                }

                int iEnd = iLastFootnote;
                if (iFirstBook != iLastBook && iBook < iLastBook)
                {
                    iEnd = book.FootnotesOS.Count - 1;
                }

                // Loop through the footnotes from the selection that are in the
                // current book. Go in reverse order through the collection.
                for (int i = iEnd; i >= iBeg; i--)
                {
                    // TODO: check filter for each HVO
                    ScrFootnote footnote = new ScrFootnote(m_fdoCache, book.FootnotesOS[i].Hvo);
                    ScrFootnote.DeleteFootnoteAndMarker(footnote);
                }
            }
        }