コード例 #1
0
        private ContextMenu CreateGraphCanvasContextMenu()
        {
            ContextMenu result = new ContextMenu();

            MenuItem menuItemAddActionNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Actions-tool-animator-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Action", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddActionNode.Click += delegate {
                AddNode("Action", result, delegate {
                    ActionNodeConfiguration newActionNode = new ActionNodeConfiguration();
                    #region Add a default action
                    ActionType actionType = ConfigManager.Configuration.GetActionTypes().First();
                    ActionConfiguration action = new ActionConfiguration(actionType.Name) {
                        Configuration = new SerializableXDocument(new XDocument(new XElement(XName.Get("objectConfig"))))
                    };
                    newActionNode.Actions.Add(action);
                    #endregion
                    return newActionNode;
                });
            };

            MenuItem menuItemAddCbrNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/nfs-unmount-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "CBR", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddCbrNode.Click += delegate {
                AddNode("CBR", result, delegate { return new CbrNodeConfiguration(); });
            };

            MenuItem menuItemAddTerminatorNode = new MenuItem {
                Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/XRouter.Gui;component/Resources/Button-exit-icon.png")), Height = 20 },
                Header = new TextBlock { Text = "Terminator", FontSize = 14, FontWeight = FontWeights.Bold }
            };
            menuItemAddTerminatorNode.Click += delegate {
                Point menuLocationOnCanvas = result.TranslatePoint(new Point(), graphCanvas.Canvas);
                AddNode("Terminator", result, delegate { return new TerminatorNodeConfiguration(); });
            };

            MenuItem menuItemAdd = new MenuItem {
                Header = new TextBlock { Text = "Add node...", FontSize = 14 }  
            };
            menuItemAdd.Items.Add(menuItemAddActionNode);
            menuItemAdd.Items.Add(menuItemAddCbrNode);
            menuItemAdd.Items.Add(menuItemAddTerminatorNode);

            result.Items.Add(menuItemAdd);
            return result;
        }
コード例 #2
0
        private void AddNode(string baseName, ContextMenu menu, Func<NodeConfiguration> nodeFactory)
        {
            NodeConfiguration node = nodeFactory();

            #region Set unique name
            int index = 1;
            string[] existingNames = Messageflow.Nodes.Select(n => n.Name).ToArray();
            while (existingNames.Contains(baseName + index.ToString())) {
                index++;
            }
            node.Name  = baseName + index.ToString();
            #endregion

            Point menuLocationOnCanvas = menu.TranslatePoint(new Point(), graphCanvas.Canvas);
            node.Location = menuLocationOnCanvas - graphCanvas.CanvasLocationOffset;
            Messageflow.Nodes.Add(node);
            MessageflowGraphPresenter.RaiseGraphChanged();

            ThreadUtils.InvokeLater(TimeSpan.FromSeconds(0.5), delegate {
                NodeSelectionManager.SelectNode(node);
            });
        }