Пример #1
0
        public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null)
        {
            ReferenceSegment reference;

            if (textView != null)
            {
                reference = textView.GetReferenceSegmentAtMousePosition();
            }
            else if (listBox?.SelectedItem is SearchResult result)
            {
                reference = new ReferenceSegment {
                    Reference = result.Member
                }
            }
            ;
            else
            {
                reference = null;
            }
            var position = textView != null?textView.GetPositionFromMousePosition() : null;

            var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null;

            return(new TextViewContext {
                TreeView = treeView,
                SelectedTreeNodes = selectedTreeNodes,
                TextView = textView,
                Reference = reference,
                Position = position
            });
        }
Пример #2
0
        void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            SharpTreeNode[] selectedNodes = treeView.GetTopLevelSelection().ToArray();
            if (selectedNodes.Length == 0)
            {
                e.Handled = true;                 // don't show the menu
                return;
            }
            ContextMenu menu = new ContextMenu();

            foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
            {
                bool needSeparatorForCategory = true;
                foreach (var entryPair in category)
                {
                    IContextMenuEntry entry = entryPair.Value;
                    if (entry.IsVisible(selectedNodes))
                    {
                        if (needSeparatorForCategory && menu.Items.Count > 0)
                        {
                            menu.Items.Add(new Separator());
                            needSeparatorForCategory = false;
                        }
                        MenuItem menuItem = new MenuItem();
                        menuItem.Header = entryPair.Metadata.Header;
                        if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                        {
                            menuItem.Icon = new Image {
                                Width  = 16,
                                Height = 16,
                                Source = Images.LoadImage(entry, entryPair.Metadata.Icon)
                            };
                        }
                        if (entryPair.Value.IsEnabled(selectedNodes))
                        {
                            menuItem.Click += delegate
                            {
                                entry.Execute(selectedNodes);
                            };
                        }
                        else
                        {
                            menuItem.IsEnabled = false;
                        }
                        menu.Items.Add(menuItem);
                    }
                }
            }
            if (menu.Items.Count > 0)
            {
                treeView.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
Пример #3
0
        public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null)
        {
            var reference = textView != null?textView.GetReferenceSegmentAtMousePosition() : null;

            var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null;

            return(new TextViewContext {
                TreeView = treeView,
                SelectedTreeNodes = selectedTreeNodes,
                TextView = textView,
                Reference = reference
            });
        }
Пример #4
0
        ///// <summary>
        ///// Returns the reference the mouse cursor is currently hovering above.
        ///// Returns null, if there was no reference found.
        ///// </summary>
        //public ReferenceSegment Reference { get; private set; }

        ///// <summary>
        ///// Returns the position in TextView the mouse cursor is currently hovering above.
        ///// Returns null, if TextView returns null;
        ///// </summary>
        //public TextViewPosition? Position { get; private set; }

        public static TextViewContext Create(SharpTreeView treeView = null, ListBox listBox = null)
        {
            //ReferenceSegment reference;
            //if (textView != null)
            //    reference = textView.GetReferenceSegmentAtMousePosition();
            //else if (listBox != null)
            //    reference = new ReferenceSegment { Reference = ((SearchResult)listBox.SelectedItem).Member };
            //else
            //    reference = null;
            //var position = textView != null ? textView.GetPositionFromMousePosition() : null;
            var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null;

            return(new TextViewContext
            {
                TreeView = treeView,
                SelectedTreeNodes = selectedTreeNodes,
                //TextView = textView,
                //Reference = reference,
                //Position = position
            });
        }
Пример #5
0
        public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null, TabControl tabControl = null, HexBox hexBox = null, bool openedFromKeyboard = false)
        {
            TextViewPosition?position = null;

            if (textView != null)
            {
                position = openedFromKeyboard ? textView.TextEditor.TextArea.Caret.Position : textView.GetPositionFromMousePosition();
            }
            ReferenceSegment reference;

            if (textView != null)
            {
                reference = textView.GetReferenceSegmentAt(position);
            }
            else if (listBox != null && listBox.SelectedItem is SearchResult)
            {
                reference = new ReferenceSegment {
                    Reference = ((SearchResult)listBox.SelectedItem).MDTokenProvider
                }
            }
            ;
            else
            {
                reference = null;
            }
            var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null;

            return(new TextViewContext {
                TreeView = treeView,
                SelectedTreeNodes = selectedTreeNodes,
                TextView = textView,
                TabControl = tabControl,
                HexBox = hexBox,
                ListBox = listBox,
                Reference = reference,
                Position = position,
                OpenedFromKeyboard = openedFromKeyboard,
            });
        }
Пример #6
0
        public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null, DataGrid dataGrid = null)
        {
            ReferenceSegment reference;

            if (textView != null)
            {
                reference = textView.GetReferenceSegmentAtMousePosition();
            }
            else if (listBox?.SelectedItem is SearchResult result)
            {
                reference = new ReferenceSegment {
                    Reference = result.Reference
                }
            }
            ;
            else if (listBox?.SelectedItem is TreeNodes.IMemberTreeNode provider)
            {
                reference = new ReferenceSegment {
                    Reference = provider.Member
                }
            }
            ;
            else if (listBox?.SelectedItem != null)
            {
                reference = new ReferenceSegment {
                    Reference = listBox.SelectedItem
                }
            }
            ;
            else if (dataGrid?.SelectedItem is TreeNodes.IMemberTreeNode provider2)
            {
                reference = new ReferenceSegment {
                    Reference = provider2.Member
                }
            }
            ;
            else if (dataGrid?.SelectedItem != null)
            {
                reference = new ReferenceSegment {
                    Reference = dataGrid.SelectedItem
                }
            }
            ;
            else
            {
                reference = null;
            }
            var position = textView != null?textView.GetPositionFromMousePosition() : null;

            var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null;

            return(new TextViewContext {
                ListBox = listBox,
                DataGrid = dataGrid,
                TreeView = treeView,
                SelectedTreeNodes = selectedTreeNodes,
                TextView = textView,
                Reference = reference,
                Position = position,
                MousePosition = ((Visual)textView ?? treeView ?? (Visual)listBox ?? dataGrid).PointToScreen(Mouse.GetPosition((IInputElement)textView ?? treeView ?? (IInputElement)listBox ?? dataGrid))
            });
        }