Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// Handle the CommitText event. Transfer to GUI thread if neccessary.
        /// </summary>
        private void CommitTextEventHandler(string text)
        {
            if (AssociatedSimpleRootSite.InvokeRequired)
            {
                AssociatedSimpleRootSite.SafeBeginInvoke(
                    new CommitDelegate(CommitTextEventHandler), new object[] { text });
                return;
            }

            IActionHandler actionHandler = AssociatedSimpleRootSite.DataAccess.GetActionHandler();

            try
            {
                if (actionHandler != null)
                {
                    actionHandler.BeginUndoTask(Resources.ksUndoTyping, Resources.ksRedoTyping);
                }

                // Save existing Preedit Selection and existing left-over preedit string.
                var       preeditSelection = SavePreeditSelection();
                ITsString preedit;
                preeditSelection.Selection.GetSelectionString(out preedit, String.Empty);

                // Change selection to a insertion point (unless we moved the selection before,
                // which happens when we come here as part of processing a mouse click)
                // And insert commit text.
                var selHelper = new SelectionHelper(
                    m_savedPreeditSelection ?? AssociatedSimpleRootSite.EditingHelper.CurrentSelection);
                if (m_savedPreeditSelection == null)
                {
                    selHelper.ReduceToIp(SelectionHelper.SelLimitType.Anchor);
                }

                selHelper.SetSelection(true);
                AssociatedSimpleRootSite.EditingHelper.OnCharAux(text, VwShiftStatus.kfssNone,
                                                                 Keys.None);

                int deletedChars = TrimBeginningBackspaces(ref text);

                // Update the saved preedit selection to take account of the inserted text
                // text is in NFC, but the view uses it in NFD, so we have to convert it.
                // We don't do this if we moved the selection prior to this method.
                int textLenNFD = m_savedPreeditSelection != null ? 0 :
                                 Icu.Normalize(text, Icu.UNormalizationMode.UNORM_NFD).Length;
                int anchor = preeditSelection.IchAnchor + textLenNFD - deletedChars;

                // select the text we just inserted
                // TODO: underline the text so that it is more obvious that this is just preedit text
                preeditSelection.SetIch(SelectionHelper.SelLimitType.Anchor, anchor);
                preeditSelection.SetIch(SelectionHelper.SelLimitType.End,
                                        preeditSelection.IchEnd + textLenNFD - deletedChars);

                // reshow the preedit selection
                RestorePreeditSelection(preeditSelection);
                preeditSelection.Selection.ReplaceWithTsString(preedit);
                preeditSelection.SetSelection(true);
            }
            finally
            {
                m_savedPreeditSelection = null;
                if (actionHandler != null)
                {
                    actionHandler.EndUndoTask();
                }
            }
        }