Ejemplo n.º 1
0
        protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew)
        {
            CheckDisposed();

            base.HandleSelectionChange(rootb, vwselNew);

            // JohnT: it's remotely possible that the base, in calling commit, made this
            // selection no longer useable.
            if (!vwselNew.IsValid)
            {
                return;
            }

            IWfiWordform wordform;

            if (!GetSelectedWordform(vwselNew, out wordform))
            {
                wordform = null;
            }
            m_mediator.PropertyTable.SetProperty("TextSelectedWord", wordform);
            m_mediator.PropertyTable.SetPropertyPersistence("TextSelectedWord", false);

            SelectionHelper helper = SelectionHelper.Create(vwselNew, this);

            if (helper != null && helper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) == RawTextVc.kTagUserPrompt)
            {
                vwselNew.ExtendToStringBoundaries();
                EditingHelper.SetKeyboardForSelection(vwselNew);
            }
        }
Ejemplo n.º 2
0
        private bool DisplayOption(object option)
        {
            RuleInsertType  type   = ((InsertOption)option).Type;
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId == -1 || cellId == -2)
            {
                return(false);
            }

            switch (cellId)
            {
            case AffixRuleFormulaVc.ktagLeftEmpty:
            case AffixRuleFormulaVc.ktagRightEmpty:
                return(type != RuleInsertType.Index);

            case MoAffixProcessTags.kflidOutput:
                return(type == RuleInsertType.Index || type == RuleInsertType.Phoneme || type == RuleInsertType.MorphemeBoundary);

            default:
                var ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId);
                if (ctxtOrVar.ClassID == PhVariableTags.kClassId)
                {
                    return(false);
                }
                return(type != RuleInsertType.Index);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Try to find a WfiWordform object corresponding the the focus selection.
        /// If successful return its guid, otherwise, return Guid.Empty.
        /// </summary>
        /// <returns></returns>
        private ITsString ActiveWord()
        {
            if (InFriendliestTool)
            {
                // we should be able to get our info from the current record clerk.
                // but return null if we can't get the info, otherwise we allow the user to
                // bring up the change spelling dialog and crash because no wordform can be found (LT-8766).
                var clerk   = m_propertyTable.GetValue <RecordClerk>("ActiveClerk");
                var tssVern = (clerk?.CurrentObject as IWfiWordform)?.Form?.BestVernacularAlternative;
                return(tssVern);
            }
            var app   = m_propertyTable.GetValue <IApp>("App");
            var roots = (app?.ActiveMainWindow as FwXWindow)?.ActiveView?.AllRootBoxes();

            if (roots == null || roots.Count < 1 || roots[0] == null)
            {
                return(null);
            }
            var tssWord = SelectionHelper.Create(roots[0].Site)?.SelectedWord;

            if (tssWord != null)
            {
                // Check for a valid vernacular writing system.  (See LT-8892.)
                var ws    = TsStringUtils.GetWsAtOffset(tssWord, 0);
                var cache = m_propertyTable.GetValue <LcmCache>("cache");
                CoreWritingSystemDefinition wsObj = cache.ServiceLocator.WritingSystemManager.Get(ws);
                if (cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Contains(wsObj))
                {
                    return(tssWord);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private bool CanAddWordBoundary(object option)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return(true);
            }

            SelectionHelper sel = SelectionHelper.Create(m_view);

            if (sel.IsRange)
            {
                return(false);
            }
            ComplexConcPatternNode parent;
            int index;

            GetInsertionIndex(sel, out parent, out index);
            if (parent.IsLeaf)
            {
                return(false);
            }

            if (index == 0)
            {
                return(parent.Children[index] is ComplexConcMorphNode);
            }

            if (index == parent.Children.Count)
            {
                return(parent.Children[index - 1] is ComplexConcMorphNode);
            }

            return(parent.Children[index - 1] is ComplexConcMorphNode && parent.Children[index] is ComplexConcMorphNode);
        }
Ejemplo n.º 5
0
        private bool DisplayColumnOption(object option)
        {
            SelectionHelper sel = SelectionHelper.Create(m_view);

            if (sel.IsRange)
            {
                return(false);
            }

            int cellId = GetCell(sel);

            if (cellId == -1 || cellId == -2)
            {
                return(false);
            }
            switch (cellId)
            {
            case AffixRuleFormulaVc.ktagLeftEmpty:
            case AffixRuleFormulaVc.ktagRightEmpty:
            case MoAffixProcessTags.kflidOutput:
                return(false);

            default:
                return(GetColumnInsertIndex(sel) != -1);
            }
        }
Ejemplo n.º 6
0
        public void MoveIPToStartOfNextFootnoteViaRightKey()
        {
            ((IStTxtPara)m_Jude.FootnotesOS[1].ParagraphsOS[0]).Contents =
                TsStringUtils.MakeTss(string.Empty, Cache.DefaultVernWs);

            // Put IP at the beginning of the first footnote.
            MakeFootnoteSelection(1, 0, 0);

            // Use the End key to get the IP to the end of the first footnote.
            m_footnoteView.OnKeyDown(new KeyEventArgs(Keys.End));

            // Verify we're still in footnote zero.
            SelectionHelper selHelper = SelectionHelper.Create(m_footnoteView);

            Assert.AreEqual(0, selHelper.LevelInfo[1].ihvo, "Selection should still be in footnote 0");

            // Now simulate pressing the Right key.
            m_footnoteView.OnKeyDown(new KeyEventArgs(Keys.Right));

            // Check results
            selHelper = SelectionHelper.Create(m_footnoteView);
            Assert.AreEqual(1, selHelper.LevelInfo[1].ihvo, "Selection should have moved to next footnote");
            Assert.AreEqual(0, selHelper.IchAnchor, "IchAnchor should be at start of footnote");
            Assert.AreEqual(0, selHelper.IchEnd, "IchEnd should be at start of footnote");
        }
Ejemplo n.º 7
0
        private bool CanAddConstraint(object option)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return(true);
            }

            SelectionHelper        sel        = SelectionHelper.Create(m_view);
            ComplexConcPatternNode anchorNode = GetNode(sel, SelectionHelper.SelLimitType.Anchor);
            ComplexConcPatternNode endNode    = GetNode(sel, SelectionHelper.SelLimitType.End);

            if (anchorNode == null || endNode == null || anchorNode.Parent != endNode.Parent)
            {
                return(false);
            }

            ComplexConcPatternNode parent;
            int start, end;

            if (!sel.IsRange)
            {
                int index;
                GetInsertionIndex(sel, out parent, out index);
                start = index - 1;
                end   = index;
            }
            else
            {
                parent = anchorNode.Parent;
                start  = (sel.Selection.EndBeforeAnchor ? GetNodeIndex(endNode) : GetNodeIndex(anchorNode)) - 1;
                end    = (sel.Selection.EndBeforeAnchor ? GetNodeIndex(anchorNode) : GetNodeIndex(endNode)) + 1;
            }

            return((start == -1 || !(parent.Children[start] is ComplexConcWordBdryNode)) && (end == parent.Children.Count || !(parent.Children[end] is ComplexConcWordBdryNode)));
        }
Ejemplo n.º 8
0
        public void GoToNextSection()
        {
            FdoOwningSequence <IScrBook> books = m_scr.ScriptureBooksOS;

            // Start in the title of the second book.
            m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0);

            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last section of the first book.
            IScrBook book = books[0];

            m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                                          0, book.SectionsOS.Count - 1);

            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, 1, 0, (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0);

            // Start in the last para of the contents of the last section of the last book.
            int iBook = books.Count - 1;

            book = books[iBook];
            int         iSection    = book.SectionsOS.Count - 1;
            IScrSection lastSection = book.SectionsOS[iSection];
            int         iPara       = lastSection.ContentOA.ParagraphsOS.Count - 1;

            m_draftView.TeEditingHelper.SetInsertionPoint(iBook, iSection, iPara, 2, true);

            // Nothing should move
            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, iBook, iSection, (int)ScrSection.ScrSectionTags.kflidContent,
                            2, 2);

            // Check the para
            SelectionHelper selHelper = SelectionHelper.Create(m_draftView);

            Assert.AreEqual(iPara, selHelper.LevelInfo[0].ihvo);

            // Start with a multi-text range selection
            IScrBook startBook = books[0];

            m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading,
                                                          0, startBook.SectionsOS.Count - 2);
            IVwSelection vwsel1 = m_draftView.RootBox.Selection;

            m_draftView.TeEditingHelper.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                                          0, startBook.SectionsOS.Count - 3);
            IVwSelection vwsel2 = m_draftView.RootBox.Selection;

            m_draftView.RootBox.MakeRangeSelection(vwsel1, vwsel2, true);

            m_draftView.TeEditingHelper.GoToNextSection();

            VerifySelection(4, 0, startBook.SectionsOS.Count - 1,
                            (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the alpha variables on the currently selected natural class simple context.
        /// </summary>
        public void SetContextVariables()
        {
            SelectionHelper sel         = SelectionHelper.Create(m_view);
            bool            reconstruct = false;

            using (new UndoRedoTaskHelper(m_cache, MEStrings.ksRegRuleUndoSetVariables, MEStrings.ksRegRuleRedoSetVariables))
            {
                using (FeatureConstraintChooserDlg featChooser = new FeatureConstraintChooserDlg())
                {
                    IPhSimpleContextNC ctxt = new PhSimpleContextNC(m_cache, CurrentContextHvo);
                    featChooser.SetDlgInfo(m_cache, Mediator, new PhRegularRule(m_cache, RHS.OwnerHVO), ctxt);
                    DialogResult res = featChooser.ShowDialog();
                    if (res != DialogResult.Cancel)
                    {
                        featChooser.HandleJump();
                    }
                    reconstruct = res == DialogResult.OK;
                }
            }

            m_view.Select();
            if (reconstruct)
            {
                m_view.RootBox.Reconstruct();
                sel.RestoreSelectionAndScrollPos();
            }
        }
Ejemplo n.º 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle Mouse up
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                base.OnMouseUp(e);
                return;
            }

            NotesMainWnd notesMainWnd = TheMainWnd as NotesMainWnd;

            if (notesMainWnd == null || notesMainWnd.TMAdapter == null)
            {
                return;
            }

            Rectangle rcSrcRoot;
            Rectangle rcDstRoot;

            GetCoordRects(out rcSrcRoot, out rcDstRoot);
            Point        pt      = new Point(e.X, e.Y);
            IVwSelection sel     = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            int          noteHvo = 0;

            if (sel != null)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo      annInfo   = selHelper.GetLevelInfoForTag(m_currentNotesTag);
                noteHvo = annInfo.hvo;
            }

            pt = PointToScreen(new Point(e.X, e.Y));
            notesMainWnd.TMAdapter.PopupMenu("cmnuNotesDataEntryView", pt.X, pt.Y);
        }
Ejemplo n.º 11
0
        public void GetBookHvoWithFootnotes()
        {
            IScripture scr     = Cache.LangProject.TranslatedScriptureOA;
            IScrBook   genesis = scr.ScriptureBooksOS[0];
            // Add a footnote in the first book, first section, first paragraph
            IScrSection section  = genesis.SectionsOS[0];
            IStFootnote footnote = AddFootnote(genesis,
                                               (IStTxtPara)section.ContentOA.ParagraphsOS[0], 2, "A footnote");

            m_ScrPubCtrl.CallRefreshDisplay();
            m_ScrPubCtrl.CreatePages();
            m_ScrPubCtrl.PrepareToDrawPages(0, m_ScrPubCtrl.AutoScrollMinSize.Height * 2);

            // Simulate setting the IP at the beginning of the footnote
            bool fFoundPageWithFootnotes = false;

            foreach (DummyPage page in m_ScrPubCtrl.Pages)
            {
                if (page.DependentObjectsRootStream != null)
                {
                    fFoundPageWithFootnotes = true;
                    ((IVwRootBox)page.DependentObjectsRootStream).MakeSimpleSel(true, true, false, true);
                    m_ScrPubCtrl.FocusedStream = page.DependentObjectsRootStream;
                    break;
                }
            }
            Assert.IsTrue(fFoundPageWithFootnotes, "Can't run this test without finding any footnotes");

            SelectionHelper selHelper = SelectionHelper.Create(m_ScrPubCtrl);
            IScrBook        book      = m_ScrPubCtrl.GetBook(selHelper, SelectionHelper.SelLimitType.Anchor);

            Assert.AreEqual(genesis, book);
        }
        /// <summary>
        /// Sets the alpha variables on the currently selected natural class simple context.
        /// </summary>
        public void SetContextVariables()
        {
            var  sel         = SelectionHelper.Create(m_view);
            bool reconstruct = false;

            UndoableUnitOfWorkHelper.Do(MEStrings.ksRegRuleUndoSetVariables, MEStrings.ksRegRuleRedoSetVariables, RHS, () =>
            {
                using (var featChooser = new FeatureConstraintChooserDlg())
                {
                    var ctxt = CurrentContext as IPhSimpleContextNC;
                    featChooser.SetDlgInfo(m_cache, Mediator, RHS.OwningRule, ctxt);
                    DialogResult res = featChooser.ShowDialog();
                    if (res != DialogResult.Cancel)
                    {
                        featChooser.HandleJump();
                    }
                    reconstruct = res == DialogResult.OK;
                }
            });

            m_view.Select();
            if (reconstruct)
            {
                m_view.RootBox.Reconstruct();
                sel.RestoreSelectionAndScrollPos();
            }
        }
Ejemplo n.º 13
0
        private void InstallTextRangeSelection()
        {
            // create a new selection based off our Editable range and install it.
            var sh = SelectionHelper.Create(Selection, m_site);

            sh.SetSelection(m_site, true, true);
        }
Ejemplo n.º 14
0
        private bool DisplayVariableOption(object option)
        {
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId == -1 || cellId == -2)
            {
                return(false);
            }

            switch (cellId)
            {
            case AffixRuleFormulaVc.ktagLeftEmpty:
            case AffixRuleFormulaVc.ktagRightEmpty:
                return(true);

            case MoAffixProcessTags.kflidOutput:
                return(false);

            default:
                var ctxtOrVar = m_cache.ServiceLocator.GetInstance <IPhContextOrVarRepository>().GetObject(cellId);
                if (ctxtOrVar.ClassID == PhSequenceContextTags.kClassId)
                {
                    var seqCtxt = (IPhSequenceContext)ctxtOrVar;
                    if (seqCtxt.MembersRS.Count == 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 15
0
        void Tag_Item_Click(object sender, EventArgs e)
        {
            var item = sender as TagPossibilityMenuItem;

            if (item == null)
            {
                return;
            }
            // save current selection info. (e.g. EnsureSelectedWordformsAndSegAreAllReal() can destroy it).
            var sh = SelectionHelper.Create(this);

            if (item.Checked)
            {
                UndoableUnitOfWorkHelper.Do(ITextStrings.ksUndoDeleteTextTag, ITextStrings.ksRedoDeleteTextTag,
                                            Cache.ActionHandlerAccessor, () => RemoveTextTagInstance(item.Possibility));
            }
            else
            {
                UndoableUnitOfWorkHelper.Do(ITextStrings.ksUndoAddTextTag, ITextStrings.ksRedoAddTextTag,
                                            Cache.ActionHandlerAccessor, () => MakeTextTagInstance(item.Possibility));
            }
            // We might try later to see if we can do without this! Nope.
            if (sh != null)
            {
                sh.RestoreSelectionAndScrollPos();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Try to keep the selection from including any of the characters in a writing system label.
        /// See LT-8396.
        /// </summary>
        protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
        {
            base.HandleSelectionChange(prootb, vwselNew);
            // 1) We don't want to recurse into here.
            // 2) If the selection is invalid we can't use it.
            // 3) If the selection is entirely formattable ("IsSelectionInOneFormattableProp"), we don't need to do
            //    anything.
            if (s_fProcessingSelectionChanged || !vwselNew.IsValid || EditingHelper.IsSelectionInOneFormattableProp())
            {
                return;
            }
            try
            {
                s_fProcessingSelectionChanged = true;

                SelectionHelper hlpr         = SelectionHelper.Create(vwselNew, this);
                bool            fRange       = hlpr.IsRange;
                bool            fChangeRange = false;
                if (fRange)
                {
                    bool fAnchorEditable = vwselNew.IsEditable;
                    hlpr.GetIch(SelectionHelper.SelLimitType.Anchor);
                    int tagAnchor = hlpr.GetTextPropId(SelectionHelper.SelLimitType.Anchor);
                    hlpr.GetIch(SelectionHelper.SelLimitType.End);
                    int  tagEnd           = hlpr.GetTextPropId(SelectionHelper.SelLimitType.End);
                    bool fEndBeforeAnchor = vwselNew.EndBeforeAnchor;
                    if (fEndBeforeAnchor)
                    {
                        if (fAnchorEditable && tagAnchor > 0 && tagEnd < 0)
                        {
                            hlpr.SetTextPropId(SelectionHelper.SelLimitType.End, tagAnchor);
                            hlpr.SetIch(SelectionHelper.SelLimitType.End, 0);
                            fChangeRange = true;
                        }
                    }
                    else
                    {
                        if (!fAnchorEditable && tagAnchor < 0 && tagEnd > 0)
                        {
                            hlpr.SetTextPropId(SelectionHelper.SelLimitType.Anchor, tagEnd);
                            hlpr.SetIch(SelectionHelper.SelLimitType.Anchor, 0);
                            fChangeRange = true;
                        }
                    }
                }
                if (fChangeRange)
                {
                    hlpr.SetSelection(true);
                }
            }
            finally
            {
                s_fProcessingSelectionChanged = false;
            }
        }
Ejemplo n.º 17
0
        private string DisplayNoOptsMsg()
        {
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);

            if (cellId == -1 || cellId == 2)
            {
                return(null);
            }
            return(MEStrings.ksAffixRuleNoOptsMsg);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Sets the number of occurrences of a context.
        /// </summary>
        /// <param name="min">The min.</param>
        /// <param name="max">The max.</param>
        public void SetContextOccurrence(int min, int max)
        {
            CheckDisposed();
            SelectionHelper sel    = SelectionHelper.Create(m_view);
            int             cellId = GetCell(sel);
            ICmObject       obj    = GetCmObject(sel, SelectionHelper.SelLimitType.Anchor);
            var             ctxt   = (IPhPhonContext)obj;
            int             index  = -1;

            UndoableUnitOfWorkHelper.Do(MEStrings.ksRegRuleUndoSetOccurrence, MEStrings.ksRegRuleRedoSetOccurrence, ctxt, () =>
            {
                if (ctxt.ClassID == PhIterationContextTags.kClassId)
                {
                    // if there is an existing iteration context, just update it or remove it if it can occur only once
                    var iterCtxt = (IPhIterationContext)ctxt;
                    if (min == 1 && max == 1)
                    {
                        // We want to replace the iteration context with the original (simple?) context which it
                        // specifies repeat counts for. That is, we will replace the iterCtxt with its own MemberRA.
                        // Then we will delete the iteration context (false argument).
                        // We have to do this carefully, however, because when a PhIterationContext is deleted,
                        // it also deletes its MemberRA. So if the MemberRA is still linked to the simple context,
                        // both get deleted, and the replace unexpectedly fails (LT-13566).
                        // So, we must break the link before we do the replacement.
                        IPhPhonContext temp = iterCtxt.MemberRA;
                        iterCtxt.MemberRA   = null;
                        index = OverwriteContext(temp, iterCtxt, cellId == PhSegRuleRHSTags.kflidLeftContext, false);
                    }
                    else
                    {
                        iterCtxt.Minimum = min;
                        iterCtxt.Maximum = max;
                    }
                }
                else if (min != 1 || max != 1)
                {
                    // create a new iteration context
                    IPhIterationContext iterCtxt = m_cache.ServiceLocator.GetInstance <IPhIterationContextFactory>().Create();
                    index             = OverwriteContext(iterCtxt, ctxt, cellId == PhSegRuleRHSTags.kflidLeftContext, true);
                    iterCtxt.MemberRA = ctxt;
                    iterCtxt.Minimum  = min;
                    iterCtxt.Maximum  = max;
                }
            });

            if (index == -1)
            {
                IPhPhonContext     envCtxt = cellId == PhSegRuleRHSTags.kflidLeftContext ? Rhs.LeftContextOA : Rhs.RightContextOA;
                IPhSequenceContext seqCtxt;
                index = GetIndex(ctxt, envCtxt, out seqCtxt);
            }

            ReconstructView(cellId, index, true);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public bool OnDisplayPatternNodeSetCriteria(object commandObject, ref UIItemDisplayProperties display)
        {
            CheckDisposed();
            SelectionHelper sel = SelectionHelper.Create(m_view);

            ComplexConcPatternNode[] nodes = CurrentNodes;
            bool enable = sel.IsRange && nodes.Length == 1 && (nodes[0] is ComplexConcWordNode || nodes[0] is ComplexConcMorphNode || nodes[0] is ComplexConcTagNode);

            display.Enabled = enable;
            display.Visible = enable;
            return(true);
        }
Ejemplo n.º 21
0
        public bool OnDisplayPatternNodeSetOccurrence(object commandObject, ref UIItemDisplayProperties display)
        {
            CheckDisposed();
            SelectionHelper sel = SelectionHelper.Create(m_view);

            ComplexConcPatternNode[] nodes = CurrentNodes;
            bool enable = sel.IsRange && !(nodes[0] is ComplexConcOrNode) && !(nodes[nodes.Length - 1] is ComplexConcOrNode);

            display.Enabled = enable;
            display.Visible = enable;
            return(true);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Update the new selection. This is called by rule formula view when selection changes.
        /// </summary>
        /// <param name="vwselNew">The new selection.</param>
        private void UpdateSelection(IVwSelection vwselNew)
        {
            CheckDisposed();
            SelectionHelper sel = SelectionHelper.Create(vwselNew, this);

            if (sel != null)
            {
                object ctxt = m_patternControl.GetContext(sel);
                // if context is null then we are trying to select outside of a single context
                if (ctxt == null)
                {
                    if (sel.IsRange)
                    {
                        // ensure that a range selection only occurs within one context
                        object topCtxt    = m_patternControl.GetContext(sel, SelectionHelper.SelLimitType.Top);
                        object bottomCtxt = m_patternControl.GetContext(sel, SelectionHelper.SelLimitType.Bottom);
                        var    limit      = SelectionHelper.SelLimitType.Top;
                        if (topCtxt != null)
                        {
                            limit = SelectionHelper.SelLimitType.Top;
                            ctxt  = topCtxt;
                        }
                        else if (bottomCtxt != null)
                        {
                            limit = SelectionHelper.SelLimitType.Bottom;
                            ctxt  = bottomCtxt;
                        }

                        if (ctxt != null)
                        {
                            IVwSelection newSel = SelectCell(ctxt, limit == SelectionHelper.SelLimitType.Bottom, false);
                            sel.ReduceToIp(limit);
                            IVwSelection otherSel = sel.SetSelection(this, false, false);
                            if (sel.Selection.EndBeforeAnchor)
                            {
                                RootBox.MakeRangeSelection(limit == SelectionHelper.SelLimitType.Top ? newSel : otherSel,
                                                           limit == SelectionHelper.SelLimitType.Top ? otherSel : newSel, true);
                            }
                            else
                            {
                                RootBox.MakeRangeSelection(limit == SelectionHelper.SelLimitType.Top ? otherSel : newSel,
                                                           limit == SelectionHelper.SelLimitType.Top ? newSel : otherSel, true);
                            }
                        }
                    }
                }
                else
                {
                    AdjustSelection(sel);
                }
            }
        }
Ejemplo n.º 23
0
        public void MoveIPToStartOfCurrentFootnoteViaLeftKey()
        {
            // Put IP at the second editable character in the first footnote.
            MakeFootnoteSelection(1, 0, 1);

            m_footnoteView.OnKeyDown(new KeyEventArgs(Keys.Left));

            // Check results
            SelectionHelper selHelper = SelectionHelper.Create(m_footnoteView);

            Assert.AreEqual(0, selHelper.IchAnchor, "IchAnchor should be at start of footnote");
            Assert.AreEqual(0, selHelper.IchEnd, "IchEnd should be at start of footnote");
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Sets the phonological features for the currently selected natural class simple context with
        /// a feature-based natural class.
        /// </summary>
        public void SetContextFeatures()
        {
            SelectionHelper sel = SelectionHelper.Create(m_view);
            bool            reconstruct;

            using (var featChooser = new PhonologicalFeatureChooserDlg())
            {
                var ctxt     = (IPhSimpleContextNC)CurrentContext;
                var natClass = (IPhNCFeatures)ctxt.FeatureStructureRA;
                featChooser.Title = MEStrings.ksRuleFeatsChooserTitle;
                if (m_obj is IPhSegRuleRHS)
                {
                    featChooser.ShowFeatureConstraintValues = true;
                    if (natClass.FeaturesOA != null)
                    {
                        var rule = m_obj as IPhSegRuleRHS;
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable, rule.OwningRule, ctxt);
                    }
                    else
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable, natClass, PhNCFeaturesTags.kflidFeatures);
                    }
                }
                else
                {
                    if (natClass.FeaturesOA != null)
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable, natClass.FeaturesOA);
                    }
                    else
                    {
                        featChooser.SetDlgInfo(m_cache, Mediator, m_propertyTable);
                    }
                }
                // FWR-2405: Setting the Help topic requires that the Mediator be already set!
                featChooser.SetHelpTopic("khtpChoose-Grammar-PhonRules-SetPhonologicalFeatures");
                DialogResult res = featChooser.ShowDialog();
                if (res != DialogResult.Cancel)
                {
                    featChooser.HandleJump();
                }
                reconstruct = res == DialogResult.OK;
            }

            m_view.Select();
            if (reconstruct)
            {
                m_view.RootBox.Reconstruct();
                sel.RestoreSelectionAndScrollPos();
            }
        }
Ejemplo n.º 25
0
        protected int GetIndexOfLineChoice(IVwSelection selTest)
        {
            var helper = SelectionHelper.Create(selTest, this);

            if (helper == null)
            {
                return(-1);
            }

            var props = helper.SelProps;
            int dummyvar;

            return(props.GetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, out dummyvar));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Try to find a WfiWordform object corresponding the the focus selection.
        /// If successful return its guid, otherwise, return Guid.Empty.
        /// </summary>
        /// <returns></returns>
        internal static Guid ActiveWordform(FdoCache cache, Mediator mediator)
        {
            IApp app = mediator.PropertyTable.GetValue("App") as IApp;

            if (app == null)
            {
                return(Guid.Empty);
            }
            IFwMainWnd window = app.ActiveMainWindow as IFwMainWnd;

            if (window == null)
            {
                return(Guid.Empty);
            }
            IRootSite activeView = window.ActiveView;

            if (activeView == null)
            {
                return(Guid.Empty);
            }
            List <IVwRootBox> roots = activeView.AllRootBoxes();

            if (roots.Count < 1)
            {
                return(Guid.Empty);
            }
            SelectionHelper helper = SelectionHelper.Create(roots[0].Site);

            if (helper == null)
            {
                return(Guid.Empty);
            }
            ITsString word = helper.SelectedWord;

            if (word == null || word.Length == 0)
            {
                return(Guid.Empty);
            }
#if WANTPORT // FWR-2784
            int hvoWordform = cache.LangProject.WordformInventoryOA.GetWordformId(word);
            if (hvoWordform == 0 || cache.IsDummyObject(hvoWordform))
            {
                return(Guid.Empty);
            }
            return(cache.GetGuidFromId(hvoWordform));
#else
            return(Guid.Empty);
#endif
        }
Ejemplo n.º 27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Performs a bunch of verifications in a draft view after a scripture book has been
        /// inserted.
        /// </summary>
        /// <param name="sTitle">Book main title expected in the draft view.</param>
        /// <param name="book">The ScrBook inserted in the draft view. The test assumes this
        /// is canonically the first book in the view.</param>
        /// ------------------------------------------------------------------------------------
        private void VerifyInsertedBookInDraftView(string sTitle, IScrBook book)
        {
            bool            fAssocPrev;
            int             ich, hvoObj, tag, enc;
            ITsString       tss;
            SelectionHelper selHelper = SelectionHelper.Create(m_mainWnd.TheDraftView);

            // Make sure that IP has been given appropriate properties for typing regular
            // vernacular text (not continuing to enter text using "Chapter Number" style).
            Assert.AreEqual(4, selHelper.NumberOfLevels);
            // This better be the first book in the view.
            Assert.AreEqual(0, selHelper.LevelInfo[3].ihvo);
            // Since this book was just inserted, we should be in the first section.
            Assert.AreEqual(0, selHelper.LevelInfo[2].ihvo);
            // The InsertBook command should leave our insertion point in the Content of
            // this section (as opposed to the section Heading).
            Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent,
                            selHelper.LevelInfo[1].tag);
            // We should be in the first paragraph of that section's content.
            Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo);
            // We should have a simple IP, not a range selection
            IVwSelection sel = selHelper.Selection;

            Assert.IsFalse(sel.IsRange);
            Assert.AreEqual(1, selHelper.IchAnchor, "IP should follow chapter number");
            // If the user starts typing, they should be entering regular vernacular text
            Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_wsVern), selHelper.SelProps);

            // Put cursor in the book title. If TestLangProj ever contains a book before sTitle
            // (i.e., canonically), then this will no longer be the first book in the view.
            m_mainWnd.TheDraftView.TeEditingHelper.GoToFirstBook();
            sel = m_mainWnd.TheDraftView.RootBox.Selection;
            sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc);
            Assert.IsNull(tss.Text, "book title has a title");

            // Put the cursor in the empty section heading and verify stuff about the section
            // heading.
            m_mainWnd.TheDraftView.TeEditingHelper.GoToFirstSection();
            sel = m_mainWnd.TheDraftView.RootBox.Selection;
            sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc);
            AssertEx.RunIsCorrect(tss, 0, null, null, m_wsVern);

            // Make sure the chapter number is set
            m_mainWnd.TheDraftView.SetInsertionPoint(0, 0, 0, 0, true);
            sel = m_mainWnd.TheDraftView.RootBox.Selection;
            sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc);
            AssertEx.RunIsCorrect(tss, 0, "1", ScrStyleNames.ChapterNumber, m_wsVern);
        }
Ejemplo n.º 28
0
        // Insert an invisible space at the place clicked. Return true to suppress normal MouseDown processing.
        private bool InsertInvisibleSpace(MouseEventArgs e)
        {
            var sel = GetSelectionAtViewPoint(e.Location, false);

            if (sel == null)
            {
                return(false);
            }
            if (e.Button == MouseButtons.Right || (ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                return(false);                // don't interfere with right clicks or shifr-clicks.
            }
            var helper = SelectionHelper.Create(sel, this);
            var text   = helper.GetTss(SelectionHelper.SelLimitType.Anchor).Text;

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            // We test for space (rather than zwsp) because when in this mode, the option to make the ZWS's visible
            // is always on, which means they are spaces in the string we retrieve.
            // If we don't want to suppress inserting one next to a regular space, we'll need to check the chararacter properties
            // to distinguish the magic spaces from regular ones.
            int ich = helper.GetIch(SelectionHelper.SelLimitType.Anchor);

            if (ich > 0 && ich <= text.Length && text[ich - 1] == ' ')
            {
                return(false);                // don't insert second ZWS following existing one (or normal space).
            }
            if (ich < text.Length && text[ich] == ' ')
            {
                return(false);                // don't insert second ZWS before existing one (or normal space).
            }
            int nVar;
            int ws = helper.GetSelProps(SelectionHelper.SelLimitType.Anchor).GetIntPropValues((int)FwTextPropType.ktptWs,
                                                                                              out nVar);

            if (ws != 0)
            {
                UndoableUnitOfWorkHelper.Do(ITextStrings.ksUndoInsertInvisibleSpace, ITextStrings.ksRedoInsertInvisibleSpace,
                                            Cache.ActionHandlerAccessor,
                                            () => sel.ReplaceWithTsString(Cache.TsStrFactory.MakeString(AnalysisOccurrence.KstrZws, ws)));
            }
            helper.SetIch(SelectionHelper.SelLimitType.Anchor, ich + 1);
            helper.SetIch(SelectionHelper.SelLimitType.End, ich + 1);
            helper.SetSelection(true, true);
            return(true);            // we already made an appropriate selection.
        }
Ejemplo n.º 29
0
        public void SetMappingNaturalClass()
        {
            SelectionHelper.Create(m_view);

            var natClasses = new HashSet <ICmObject>();

            foreach (var nc in m_cache.LangProject.PhonologicalDataOA.NaturalClassesOS)
            {
                if (nc.ClassID == PhNCFeaturesTags.kClassId)
                {
                    natClasses.Add(nc);
                }
            }
            var selectedNc = DisplayChooser(MEStrings.ksRuleNCOpt, MEStrings.ksRuleNCChooserLink,
                                            "naturalClassedit", "RuleNaturalClassFlatList", natClasses) as IPhNCFeatures;

            m_view.Select();
            if (selectedNc != null)
            {
                int index = -1;
                UndoableUnitOfWorkHelper.Do(MEStrings.ksAffixRuleUndoSetNC,
                                            MEStrings.ksAffixRuleRedoSetNC, m_cache.ActionHandlerAccessor, () =>
                {
                    var curObj = CurrentObject;
                    switch (curObj.ClassID)
                    {
                    case MoCopyFromInputTags.kClassId:
                        var copy      = (IMoCopyFromInput)curObj;
                        var newModify = m_cache.ServiceLocator.GetInstance <IMoModifyFromInputFactory>().Create();
                        Rule.OutputOS.Insert(copy.IndexInOwner, newModify);
                        newModify.ModificationRA = selectedNc;
                        newModify.ContentRA      = copy.ContentRA;
                        index = newModify.IndexInOwner;

                        Rule.OutputOS.Remove(copy);
                        break;

                    case MoModifyFromInputTags.kClassId:
                        var modify            = (IMoModifyFromInput)curObj;
                        modify.ModificationRA = selectedNc;
                        index = modify.IndexInOwner;
                        break;
                    }
                });

                ReconstructView(MoAffixProcessTags.kflidOutput, index, true);
            }
        }
Ejemplo n.º 30
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Updates the saved selection to the selection that is currently in the view.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 internal void ResetSelection()
 {
     // If selHelper is not null, that means that the view probably just updated the
     // values of the existing selection instead of requesting a new selection at the
     // end of the UOW.
     // NOTE: This will not work correctly if we don't destroy the selection in
     // RequestSelectionAtEndOfUOW.
     if (m_selHelper != null)
     {
         m_selHelper = SelectionHelper.Create(m_selHelper.Selection, m_selHelper.RootSite);
     }
     else if (m_rootSite != null)
     {
         m_selHelper = SelectionHelper.Create(m_rootSite);
     }
 }