Exemplo n.º 1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the FootnoteView class
 /// </summary>
 /// <param name="cache">The cache.</param>
 /// <param name="filterInstance">The tag that identifies the book filter instance.</param>
 /// <param name="app">The application.</param>
 /// <param name="viewName">The name of the view.</param>
 /// <param name="fEditable"><c>true</c> if view is to be editable.</param>
 /// <param name="viewType">Bit-flags indicating type of view.</param>
 /// <param name="btWs">The back translation writing system (if needed).</param>
 /// <param name="draftView">The corresponding draftview pane</param>
 /// ------------------------------------------------------------------------------------
 public FootnoteView(FdoCache cache, int filterInstance, IApp app, string viewName,
                     bool fEditable, TeViewType viewType, int btWs, DraftView draftView) :
     base(cache, filterInstance, app, viewName, fEditable, viewType, btWs)
 {
     Debug.Assert((viewType & TeViewType.FootnoteView) != 0);
     m_draftView = draftView;
 }
Exemplo n.º 2
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() || !ValidFootnoteSelection)
            {
                return(true);                //discard this event
            }
            string undo;
            string redo;

            TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo);
            using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(this, undo, redo))
                using (new DataUpdateMonitor(this, "DeleteFootnote"))
                {
                    // Put code to do work in separate method for testing
                    DeleteFootnoteAux();
                    undoTaskHelper.RollBack = false;
                }

            // If there are no more footnotes, then give focus back to the main draft view
            if (RootBox.Height <= 0 && DraftView != null)
            {
                DraftView.Focus();
            }

            return(true);
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Method to create the view when needed
        /// </summary>
        /// <param name="host">The control that will host (or "wrap") the view (can be
        /// <c>null</c>)</param>
        /// <returns>The created view</returns>
        /// ------------------------------------------------------------------------------------
        public override Control CreateView(Control host)
        {
            ViewWrapper wrapper   = (ViewWrapper)host;
            DraftView   draftView = new DraftView(m_mainWnd.Cache, m_mainWnd.Handle.ToInt32(),
                                                  m_mainWnd.App, m_name, m_editable, m_showInTable, m_makeRootAutomatically,
                                                  m_viewType, GetBtWs(wrapper), m_mainWnd.App);

            m_mainWnd.RegisterFocusableView(draftView);
            draftView.TheViewWrapper = wrapper;
            return(draftView);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            base.Dispose(disposing);

            m_draftView = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Connect each BT view to its corresponding main view.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            if (e.Control is DataGridView)
            {
                e.Control.ControlAdded += new ControlEventHandler(Control_ControlAdded);
            }
            if (!(e.Control is DraftView))
            {
                return;
            }
            TE.DraftView view = e.Control as DraftView;
            TeViewType   t    = view.ViewType;

            if ((t & TeViewType.BackTranslation) == 0 && (t & TeViewType.FootnoteView) == 0)
            {
                m_mainDraftView = view;
                if (m_mainBtView != null)
                {
                    m_mainBtView.MainTrans = m_mainDraftView;
                }
            }
            else if ((t & TeViewType.BackTranslation) != 0 && (t & TeViewType.FootnoteView) == 0)
            {
                m_mainBtView = view;
                if (m_mainDraftView != null)
                {
                    m_mainBtView.MainTrans = m_mainDraftView;
                }
            }
            else if ((t & TeViewType.BackTranslation) == 0 && (t & TeViewType.FootnoteView) != 0)
            {
                m_ftDraftView = view;
                if (m_ftBtView != null)
                {
                    m_ftBtView.MainTrans = m_ftDraftView;
                }
            }
            else if ((t & TeViewType.BackTranslation) == 0 && (t & TeViewType.FootnoteView) == 0)
            {
                m_ftBtView = view;
                if (m_ftDraftView != null)
                {
                    m_ftBtView.MainTrans = m_ftDraftView;
                }
            }
        }
Exemplo n.º 7
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Focus got set to the footnote view
        /// </summary>
        /// <param name="e">The event data</param>
        /// -----------------------------------------------------------------------------------
        protected override void OnGotFocus(EventArgs e)
        {
            // If there are no footnotes, then don't allow the footnote view to be focused
            if (RootBox.Height <= 0)
            {
                if (DraftView != null)
                {
                    DraftView.Focus();
                }
                return;
            }
            base.OnGotFocus(e);

            if (DesignMode)
            {
                return;
            }

            if (TheMainWnd == null)
            {
                return;
            }

            // Make sure the paragraph styles combo box has the appropriate styles for the footnote pane.
            if (TheMainWnd.ParaStyleListHelper.ActiveView != this)
            {
                TheMainWnd.ParaStyleListHelper.IncludeStylesWithContext.Clear();
                TheMainWnd.ParaStyleListHelper.IncludeStylesWithContext.Add(ContextValues.General);
                TheMainWnd.ParaStyleListHelper.IncludeStylesWithContext.Add(ContextValues.Note);
                TheMainWnd.ParaStyleListHelper.Refresh();
                TheMainWnd.ParaStyleListHelper.ActiveView = this;
            }

            // Make sure the character styles combo box has the appropriate styles for the footnote pane.
            if (TheMainWnd.CharStyleListHelper.ActiveView != this)
            {
                if (m_isBackTranslation)
                {
                    TheMainWnd.CharStyleListHelper.IncludeStylesWithContext.Add(ContextValues.BackTranslation);
                }
                TheMainWnd.CharStyleListHelper.Refresh();
                TheMainWnd.CharStyleListHelper.ActiveView = this;
            }
        }
Exemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes a footnote or footnotes within a text selection.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void DeleteFootnoteAux()
        {
            SelectionHelper helper = SelectionHelper.Create(this);

            if (helper == null)
            {
                return;                 // Better then crashing :)
            }
            int fnLevel = helper.GetLevelForTag(ScrBookTags.kflidFootnotes);

            if (helper.Selection.IsRange)
            {
                DeleteFootnoteRange(helper);
            }
            else
            {
                // There's no range selection, so delete only one footnote
                IScrFootnote footnote =
                    Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(helper.LevelInfo[fnLevel].hvo);
                ((IScrBook)footnote.Owner).FootnotesOS.Remove(footnote);
            }

            if (RootBox.Height <= 0)
            {
                DraftView.Focus();
            }
            else
            {
                int      iBook     = helper.LevelInfo[fnLevel + 1].ihvo;
                IScrBook 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);
            }
        }
Exemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Connect each BT view to its corresponding main view.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.ControlEventArgs"/> that
        /// contains the event data.</param>
        /// ------------------------------------------------------------------------------------
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            if (e.Control is DataGridView)
            {
                e.Control.ControlAdded += DataGridView_ControlAdded;
            }

            if (e.Control is DraftView)
            {
                DraftView view = (DraftView)e.Control;
                if (view.IsBackTranslation)
                {
                    m_mainBtView = view;
                }
                else
                {
                    m_mainDraftView = view;
                }
                if (m_mainBtView != null && m_mainDraftView != null)
                {
                    m_mainBtView.VernacularDraftView = m_mainDraftView;
                }
            }
            else if (e.Control is FootnoteView)
            {
                FootnoteView ftView = (FootnoteView)e.Control;
                if (ftView.IsBackTranslation)
                {
                    m_ftBtView = ftView;
                }
                else
                {
                    m_ftDraftView = ftView;
                }
                if (m_ftBtView != null && m_ftDraftView != null)
                {
                    m_ftBtView.VernacularDraftView = m_ftDraftView;
                }
            }
        }
Exemplo n.º 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets up the specifed SelectionHelper for the specified paragraph and StText.
        /// </summary>
        /// <param name="helper">The SelectionHelper.</param>
        /// <param name="text">The StText.</param>
        /// <param name="para">The para.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="view">The view</param>
        /// ------------------------------------------------------------------------------------
        private void SetupSelectionFor(SelectionHelper helper, IStText text, IStTxtPara para,
                                       SelectionHelper.SelLimitType limit, FwRootSite view)
        {
            Debug.Assert((view is DraftView && ((DraftView)view).TeEditingHelper != null) ||
                         (view is FootnoteView && ((FootnoteView)view).EditingHelper != null));

            helper.SetTextPropId(limit, StTxtParaTags.kflidContents);

            if (view is DraftView)
            {
                DraftView draftView = (DraftView)view;

                if ((text.OwningFlid == ScrSectionTags.kflidContent ||
                     text.OwningFlid == ScrSectionTags.kflidHeading))
                {
                    // text belongs to section heading or contents
                    IScrSection section = (IScrSection)text.Owner;
                    Debug.Assert(section.OwningFlid == ScrBookTags.kflidSections);

                    helper.SetNumberOfLevels(limit, 4);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = StTextTags.kflidParagraphs;
                    info[1].ihvo = 0;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = section.IndexInOwner;
                    info[2].tag  = ScrBookTags.kflidSections;
                    info[3].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex((IScrBook)section.Owner);
                    info[3].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                }
                else
                {
                    // text belongs to a book title
                    Debug.Assert(text.OwningFlid == ScrBookTags.kflidTitle);
                    IScrBook book = (IScrBook)text.Owner;

                    helper.SetNumberOfLevels(limit, 3);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = StTextTags.kflidParagraphs;
                    info[1].ihvo = 0;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(book);
                    info[2].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                }
            }
            else if (view is FootnoteView && text.OwningFlid == ScrBookTags.kflidFootnotes)
            {
                // text belongs to a footnote
                FootnoteView footnoteView = (FootnoteView)view;
                IStFootnote  footnote     = (IStFootnote)para.Owner;
                IScrBook     book         = (IScrBook)text.Owner;

                helper.SetNumberOfLevels(limit, 3);
                SelLevInfo[] info = helper.GetLevelInfo(limit);
                info[0].hvo  = text.Hvo;
                info[0].tag  = StTextTags.kflidParagraphs;
                info[1].hvo  = footnote.Hvo;
                info[1].ihvo = footnote.IndexInOwner;
                info[1].tag  = ScrBookTags.kflidFootnotes;
                info[2].hvo  = book.Hvo;
                info[2].ihvo = footnoteView.BookFilter.GetBookIndex(book);
                info[2].tag  = footnoteView.BookFilter.Tag;
                info[0].ich  = info[1].ich = info[2].ich = -1;
            }
        }
Exemplo n.º 11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the specifed SelectionHelper for the specified paragraph and StText.
        /// </summary>
        /// <param name="helper">The SelectionHelper.</param>
        /// <param name="text">The StText.</param>
        /// <param name="para">The para.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="view">The view</param>
        /// ------------------------------------------------------------------------------------
        private void SetupSelectionFor(SelectionHelper helper, StText text, StTxtPara para,
                                       SelectionHelper.SelLimitType limit, FwRootSite view)
        {
            Debug.Assert((view is DraftView && ((DraftView)view).TeEditingHelper != null) ||
                         (view is FootnoteView && ((FootnoteView)view).EditingHelper != null));
            if (view is DraftView)
            {
                DraftView draftView = (DraftView)view;

                if ((text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidContent ||
                     text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading))
                {
                    // text belongs to section heading or contents
                    ScrSection section = new ScrSection(m_fdoCache, text.OwnerHVO);
                    Debug.Assert(section.OwningFlid == (int)ScrBook.ScrBookTags.kflidSections);

                    helper.SetNumberOfLevels(limit, 4);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                    info[1].ihvo = text.IndexInOwner;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = section.IndexInBook;
                    info[2].tag  = (int)ScrBook.ScrBookTags.kflidSections;
                    info[3].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(section.OwnerHVO);
                    info[3].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                    helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
                }
                else
                {
                    // text belongs to a book title
                    Debug.Assert(text.OwningFlid == (int)ScrBook.ScrBookTags.kflidTitle);
                    ScrBook book = new ScrBook(m_fdoCache, text.OwnerHVO);

                    helper.SetNumberOfLevels(limit, 3);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                    info[1].ihvo = text.IndexInOwner;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(book.Hvo);
                    info[2].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                    helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
                }
            }
            else if (view is FootnoteView && text.OwningFlid == (int)ScrBook.ScrBookTags.kflidFootnotes)
            {
                // text belongs to a footnote
                FootnoteView footnoteView = (FootnoteView)view;
                StFootnote   footnote     = new StFootnote(m_fdoCache, para.OwnerHVO);
                ScrBook      book         = new ScrBook(m_fdoCache, text.OwnerHVO);

                helper.SetNumberOfLevels(limit, 3);
                SelLevInfo[] info = helper.GetLevelInfo(limit);
                info[0].hvo  = text.Hvo;
                info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                info[1].hvo  = footnote.Hvo;
                info[1].ihvo = footnote.IndexInOwner;
                info[1].tag  = (int)ScrBook.ScrBookTags.kflidFootnotes;
                info[2].hvo  = book.Hvo;
                info[2].ihvo = footnoteView.BookFilter.GetBookIndex(book.Hvo);
                info[2].tag  = footnoteView.BookFilter.Tag;
                info[0].ich  = info[1].ich = info[2].ich = -1;
                helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
            }
        }