Example #1
0
 // Token: 0x060085B2 RID: 34226 RVA: 0x0024A47B File Offset: 0x0024867B
 internal ReconversionMenuItem(TextEditorContextMenu.EditorContextMenu menu, int index)
 {
     this._menu  = menu;
     this._index = index;
 }
Example #2
0
        internal static void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null || textEditor.TextView == null)
            {
                return;
            }
            Point       position    = Mouse.GetPosition(textEditor.TextView.RenderScope);
            ContextMenu contextMenu = null;
            bool        flag        = false;

            if (textEditor.IsReadOnly)
            {
                if ((e.CursorLeft != -1.0 && !textEditor.Selection.Contains(position)) || (e.CursorLeft == -1.0 && textEditor.Selection.IsEmpty))
                {
                    return;
                }
            }
            else if ((textEditor.Selection.IsEmpty || e.TargetElement is TextElement) && e.TargetElement != null)
            {
                contextMenu = (ContextMenu)e.TargetElement.GetValue(FrameworkElement.ContextMenuProperty);
            }
            else if (e.CursorLeft == -1.0)
            {
                TextPointer textPointer = TextEditorContextMenu.GetContentPosition(textEditor.Selection.Start) as TextPointer;
                if (textPointer != null)
                {
                    for (TextElement textElement = textPointer.Parent as TextElement; textElement != null; textElement = (textElement.Parent as TextElement))
                    {
                        contextMenu = (ContextMenu)textElement.GetValue(FrameworkElement.ContextMenuProperty);
                        if (contextMenu != null)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
            }
            if (e.CursorLeft != -1.0)
            {
                if (!TextEditorMouse.IsPointWithinInteractiveArea(textEditor, Mouse.GetPosition(textEditor.UiScope)))
                {
                    return;
                }
                if (contextMenu == null || !(e.TargetElement is UIElement))
                {
                    using (textEditor.Selection.DeclareChangeBlock())
                    {
                        if (!textEditor.Selection.Contains(position))
                        {
                            TextEditorMouse.SetCaretPositionOnMouseEvent(textEditor, position, MouseButton.Right, 1);
                        }
                    }
                }
            }
            if (contextMenu == null)
            {
                if (textEditor.UiScope.ReadLocalValue(FrameworkElement.ContextMenuProperty) == null)
                {
                    return;
                }
                contextMenu = textEditor.UiScope.ContextMenu;
            }
            textEditor.IsContextMenuOpen = true;
            if (contextMenu != null && !flag)
            {
                contextMenu.HorizontalOffset = 0.0;
                contextMenu.VerticalOffset   = 0.0;
                contextMenu.Closed          += TextEditorContextMenu.OnContextMenuClosed;
                return;
            }
            textEditor.CompleteComposition();
            if (contextMenu == null)
            {
                contextMenu = new TextEditorContextMenu.EditorContextMenu();
                ((TextEditorContextMenu.EditorContextMenu)contextMenu).AddMenuItems(textEditor, e.UserInitiated);
            }
            contextMenu.Placement       = PlacementMode.RelativePoint;
            contextMenu.PlacementTarget = textEditor.UiScope;
            ITextPointer     textPointer2  = null;
            SpellingError    spellingError = (contextMenu is TextEditorContextMenu.EditorContextMenu) ? textEditor.GetSpellingErrorAtSelection() : null;
            LogicalDirection logicalDirection;

            if (spellingError != null)
            {
                textPointer2     = spellingError.End;
                logicalDirection = LogicalDirection.Backward;
            }
            else if (e.CursorLeft == -1.0)
            {
                textPointer2     = textEditor.Selection.Start;
                logicalDirection = LogicalDirection.Forward;
            }
            else
            {
                logicalDirection = LogicalDirection.Forward;
            }
            if (textPointer2 != null && textPointer2.CreatePointer(logicalDirection).HasValidLayout)
            {
                double horizontalOffset;
                double verticalOffset;
                TextEditorContextMenu.GetClippedPositionOffsets(textEditor, textPointer2, logicalDirection, out horizontalOffset, out verticalOffset);
                contextMenu.HorizontalOffset = horizontalOffset;
                contextMenu.VerticalOffset   = verticalOffset;
            }
            else
            {
                Point position2 = Mouse.GetPosition(textEditor.UiScope);
                contextMenu.HorizontalOffset = position2.X;
                contextMenu.VerticalOffset   = position2.Y;
            }
            contextMenu.Closed += TextEditorContextMenu.OnContextMenuClosed;
            contextMenu.IsOpen  = true;
            e.Handled           = true;
        }