Пример #1
0
        public void CopySelectedNodesToClipboard()
        {
            if (dockPanel.ActiveContent is ConsoleForm)
            {
                Clipboard.SetText((dockPanel.ActiveContent as ConsoleForm).textBox.SelectedText);
                return;
            }

            if (dockPanel.ActiveDocument is GraphLayoutForm)
            {
                GraphLayoutForm activeLayout = dockPanel.ActiveDocument as GraphLayoutForm;

                NodeSelection selection = null;

                if (activeLayout.Desktop.FocusElement is NodeSelection)
                {
                    selection = activeLayout.Desktop.FocusElement as NodeSelection;
                }
                else if (activeLayout.Desktop.FocusElement is Node)
                {
                    selection = new NodeSelection(new Node[] { activeLayout.Desktop.FocusElement as Node });
                }

                if (selection != null)
                {
                    HashSet <int> approvedNodes    = new HashSet <int>();
                    MyNetwork     clipboardNetwork = Project.CreateNode <MyNetwork>();
                    clipboardNetwork.Name = "Clipboard";

                    foreach (MyNodeView nodeView in selection.Nodes)
                    {
                        MyNode selectedNode = nodeView.Node;

                        if (selectedNode is MyWorkingNode)
                        {
                            clipboardNetwork.Children.Add(nodeView.Node);
                            approvedNodes.Add(selectedNode.Id);
                        }

                        if (selectedNode is MyNodeGroup)
                        {
                            (selectedNode as MyNodeGroup).Iterate(true, true, node => approvedNodes.Add(node.Id));
                        }
                    }

                    if (approvedNodes.Count > 0)
                    {
                        clipboardNetwork.PrepareConnections();
                        clipboardNetwork.FilterPreparedCollection(approvedNodes);

                        YAXSerializer networkSerializer = new YAXSerializer(typeof(MyNetwork), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning, YAXSerializationOptions.DontSerializeNullObjects);
                        string        xml = networkSerializer.Serialize(clipboardNetwork);

                        Clipboard.SetText(xml);
                    }
                    else
                    {
                        MyLog.WARNING.WriteLine("Copying is not allowed");
                    }
                }
                else
                {
                    MyLog.WARNING.WriteLine("Selection is empty");
                }
            }
        }