示例#1
0
        // Token: 0x06007C33 RID: 31795 RVA: 0x0022EB24 File Offset: 0x0022CD24
        public static IList <DependencyObject> GetSelectedNodes(object selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }
            ITextPointer        textPointer = null;
            ITextPointer        position    = null;
            IList <TextSegment> list;

            TextSelectionHelper.CheckSelection(selection, out textPointer, out position, out list);
            IList <DependencyObject> list2 = new List <DependencyObject>();

            if (textPointer.CompareTo(position) == 0)
            {
                list2.Add(((TextPointer)textPointer).Parent);
                return(list2);
            }
            TextPointer textPointer2 = (TextPointer)textPointer.CreatePointer();

            while (((ITextPointer)textPointer2).CompareTo(position) < 0)
            {
                DependencyObject parent = textPointer2.Parent;
                if (!list2.Contains(parent))
                {
                    list2.Add(parent);
                }
                textPointer2.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            return(list2);
        }
        // Token: 0x06006855 RID: 26709 RVA: 0x001D677C File Offset: 0x001D497C
        private TextPointer FindElementPosition(IInputElement e, bool isLimitedToTextView)
        {
            TextPointer textPointer = null;

            if (e is TextElement)
            {
                if ((e as TextElement).TextContainer == this._structuralCache.TextContainer)
                {
                    textPointer = new TextPointer((e as TextElement).ElementStart);
                }
            }
            else
            {
                if (this._structuralCache.TextContainer.Start == null || this._structuralCache.TextContainer.End == null)
                {
                    return(null);
                }
                TextPointer textPointer2 = new TextPointer(this._structuralCache.TextContainer.Start);
                while (textPointer == null && ((ITextPointer)textPointer2).CompareTo(this._structuralCache.TextContainer.End) < 0)
                {
                    TextPointerContext pointerContext = textPointer2.GetPointerContext(LogicalDirection.Forward);
                    if (pointerContext == TextPointerContext.EmbeddedElement)
                    {
                        DependencyObject adjacentElement = textPointer2.GetAdjacentElement(LogicalDirection.Forward);
                        if ((adjacentElement is ContentElement || adjacentElement is UIElement) && (adjacentElement == e as ContentElement || adjacentElement == e as UIElement))
                        {
                            textPointer = new TextPointer(textPointer2);
                        }
                    }
                    textPointer2.MoveToNextContextPosition(LogicalDirection.Forward);
                }
            }
            if (textPointer != null && isLimitedToTextView)
            {
                this._textView = this.GetTextView();
                Invariant.Assert(this._textView != null);
                for (int i = 0; i < ((ITextView)this._textView).TextSegments.Count; i++)
                {
                    if (((ITextPointer)textPointer).CompareTo(((ITextView)this._textView).TextSegments[i].Start) >= 0 && ((ITextPointer)textPointer).CompareTo(((ITextView)this._textView).TextSegments[i].End) < 0)
                    {
                        return(textPointer);
                    }
                }
                textPointer = null;
            }
            return(textPointer);
        }
示例#3
0
        /// <summary>
        ///     Gets the tree elements spanned by the selection.
        /// </summary>
        /// <param name="selection">the selection to examine</param>
        /// <returns>a list of elements spanned by the selection; never returns
        /// null</returns>
        /// <exception cref="ArgumentNullException">selection is null</exception>
        /// <exception cref="ArgumentException">selection is of wrong type</exception>
        public static IList <DependencyObject> GetSelectedNodes(Object selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException("selection");
            }

            IList <TextSegment> segments;
            ITextPointer        start = null;
            ITextPointer        end   = null;

            CheckSelection(selection, out start, out end, out segments);

            IList <DependencyObject> list = new List <DependencyObject>();

            // If the selection is of length 0, then we simply add the parent of the
            // text container and return.
            if (start.CompareTo(end) == 0)
            {
                list.Add(((TextPointer)start).Parent);

                return(list);
            }

            TextPointer current = (TextPointer)start.CreatePointer();

            while (((ITextPointer)current).CompareTo(end) < 0)
            {
                DependencyObject node = current.Parent;

                if (!list.Contains(node))
                {
                    list.Add(node);
                }

                current.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            return(list);
        }
示例#4
0
        /// <summary>
        /// UpdateAccessKey - Scans forward in the tree looking for the access key marker, replacing it with access key element. We only support one find.
        /// </summary>
        private void UpdateAccessKey()
        {
            TextPointer navigator = new TextPointer(TextContainer.Start);

            while (!_accessKeyLocated && navigator.CompareTo(TextContainer.End) < 0)
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                case TextPointerContext.Text:
                    string text  = navigator.GetTextInRun(LogicalDirection.Forward);
                    int    index = FindAccessKeyMarker(text);
                    if (index != -1 && index < text.Length - 1)
                    {
                        string      keyText = StringInfo.GetNextTextElement(text, index + 1);
                        TextPointer keyEnd  = navigator.GetPositionAtOffset(index + 1 + keyText.Length);

                        _accessKey       = new Run(keyText);
                        _accessKey.Style = AccessKeyStyle;

                        RegisterAccessKey();

                        HasCustomSerializationStorage.SetValue(_accessKey, true);
                        _accessKeyLocated = true;

                        UninitializeTextContainerListener();

                        TextContainer.BeginChange();
                        try
                        {
                            TextPointer underlineStart = new TextPointer(navigator, index);
                            TextRangeEdit.DeleteInlineContent(underlineStart, keyEnd);
                            _accessKey.RepositionWithContent(underlineStart);
                        }
                        finally
                        {
                            TextContainer.EndChange();
                            InitializeTextContainerListener();
                        }
                    }

                    break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            // Convert double _ to single _
            navigator = new TextPointer(TextContainer.Start);
            string accessKeyMarker       = AccessKeyMarker.ToString();
            string doubleAccessKeyMarker = accessKeyMarker + accessKeyMarker;

            while (navigator.CompareTo(TextContainer.End) < 0)
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                case TextPointerContext.Text:
                    string text    = navigator.GetTextInRun(LogicalDirection.Forward);
                    string nexText = text.Replace(doubleAccessKeyMarker, accessKeyMarker);
                    if (text != nexText)
                    {
                        TextPointer keyStart = new TextPointer(navigator, 0);
                        TextPointer keyEnd   = new TextPointer(navigator, text.Length);

                        UninitializeTextContainerListener();
                        TextContainer.BeginChange();
                        try
                        {
                            keyEnd.InsertTextInRun(nexText);
                            TextRangeEdit.DeleteInlineContent(keyStart, keyEnd);
                        }
                        finally
                        {
                            TextContainer.EndChange();
                            InitializeTextContainerListener();
                        }
                    }

                    break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }
        }
示例#5
0
        // Token: 0x06004211 RID: 16913 RVA: 0x0012E228 File Offset: 0x0012C428
        private void UpdateAccessKey()
        {
            TextPointer textPointer = new TextPointer(this.TextContainer.Start);

            while (!this._accessKeyLocated && textPointer.CompareTo(this.TextContainer.End) < 0)
            {
                TextPointerContext pointerContext = textPointer.GetPointerContext(LogicalDirection.Forward);
                if (pointerContext == TextPointerContext.Text)
                {
                    string textInRun = textPointer.GetTextInRun(LogicalDirection.Forward);
                    int    num       = AccessText.FindAccessKeyMarker(textInRun);
                    if (num != -1 && num < textInRun.Length - 1)
                    {
                        string      nextTextElement  = StringInfo.GetNextTextElement(textInRun, num + 1);
                        TextPointer positionAtOffset = textPointer.GetPositionAtOffset(num + 1 + nextTextElement.Length);
                        this._accessKey       = new Run(nextTextElement);
                        this._accessKey.Style = AccessText.AccessKeyStyle;
                        this.RegisterAccessKey();
                        AccessText.HasCustomSerializationStorage.SetValue(this._accessKey, true);
                        this._accessKeyLocated = true;
                        this.UninitializeTextContainerListener();
                        this.TextContainer.BeginChange();
                        try
                        {
                            TextPointer textPointer2 = new TextPointer(textPointer, num);
                            TextRangeEdit.DeleteInlineContent(textPointer2, positionAtOffset);
                            this._accessKey.RepositionWithContent(textPointer2);
                        }
                        finally
                        {
                            this.TextContainer.EndChange();
                            this.InitializeTextContainerListener();
                        }
                    }
                }
                textPointer.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            textPointer = new TextPointer(this.TextContainer.Start);
            string text     = AccessText.AccessKeyMarker.ToString();
            string oldValue = text + text;

            while (textPointer.CompareTo(this.TextContainer.End) < 0)
            {
                TextPointerContext pointerContext2 = textPointer.GetPointerContext(LogicalDirection.Forward);
                if (pointerContext2 == TextPointerContext.Text)
                {
                    string textInRun2 = textPointer.GetTextInRun(LogicalDirection.Forward);
                    string text2      = textInRun2.Replace(oldValue, text);
                    if (textInRun2 != text2)
                    {
                        TextPointer start        = new TextPointer(textPointer, 0);
                        TextPointer textPointer3 = new TextPointer(textPointer, textInRun2.Length);
                        this.UninitializeTextContainerListener();
                        this.TextContainer.BeginChange();
                        try
                        {
                            textPointer3.InsertTextInRun(text2);
                            TextRangeEdit.DeleteInlineContent(start, textPointer3);
                        }
                        finally
                        {
                            this.TextContainer.EndChange();
                            this.InitializeTextContainerListener();
                        }
                    }
                }
                textPointer.MoveToNextContextPosition(LogicalDirection.Forward);
            }
        }