Tuple <string, VoidDelegate> [] CreatePopupMenu()
        {
            var ret = new List <Tuple <string, VoidDelegate> > {
                new Tuple <string, VoidDelegate>("create node", CreateNodeDelegate)
            };
            var objectUnderMouseCursor = graphViewer.ObjectUnderMouseCursor;
            var vedge = objectUnderMouseCursor as IViewerEdge;

            if (vedge != null)
            {
                ret.Add(new Tuple <string, VoidDelegate>("remove edge", () => { graphViewer.RemoveEdge(vedge, false); }));
                ret.Add(ColorChangeMenuTuple(vedge.Edge.Attr));
            }
            else
            {
                var vnode = objectUnderMouseCursor as IViewerNode;
                if (vnode != null)
                {
                    ret.Add(ColorChangeMenuTuple(vnode.Node.Attr));
                    ret.Add(new Tuple <string, VoidDelegate>("remove node", () => graphViewer.RemoveNode(vnode, false)));
                }
            }

            ret.Add(new Tuple <string, VoidDelegate>("find a node to pan here", PanToNode));

            return(ret.ToArray());
        }
Beispiel #2
0
        private void Grid_KeyDown(object sender, KeyEventArgs evt)
        {
            if (_currentCmd == "node editing")
            {
                return;
            }
            switch (evt.Key)
            {
            case Key.V:
                selectBtn.IsChecked = true;
                pressingBtn(selectBtn);
                _currentCmd = "select";
                break;

            case Key.E:
                edgeBtn.IsChecked = true;
                pressingBtn(edgeBtn);
                _currentCmd = "add edge";
                break;

            case Key.N:
                nodeBtn.IsChecked = true;
                pressingBtn(nodeBtn);
                _currentCmd = "add node";
                break;

            case Key.Space:
                _graphViewer.Panning = true;
                var sresInfo = Application.GetResourceStream(new Uri("cur_scroll.cur", UriKind.Relative));
                var cur      = new System.Windows.Input.Cursor(sresInfo.Stream);
                this.Cursor = cur;
                break;

            case Key.T:
                VDebug.D.tag++;
                this.Title = $"trigged{selfcounter++}";
                break;

            case Key.Delete:
                if (_currentCmd == "select")
                {
                    foreach (var obj in _graphViewer.LayoutEditor.dragGroup)
                    {
                        var vnode = obj as VNode;
                        if (vnode != null)
                        {
                            _graphViewer.RemoveNode(vnode, true);
                            continue;
                        }
                        var vedge = obj as VEdge;
                        if (vedge != null)
                        {
                            _graphViewer.RemoveEdge(vedge, true);
                            continue;
                        }
                        var vlabel = obj as VLabel;
                        if (vlabel != null)
                        {
                            _graphViewer.RemoveLabel(vlabel);
                        }
                    }
                    _graphViewer.LayoutEditor.Clear();
                }
                break;
            }
        }