예제 #1
0
        private void NodeDelete_Click(object sender, RoutedEventArgs e)
        {
            KmlNode node        = ((sender as MenuItem).DataContext as KmlNode);
            string  nodeName    = "node";
            string  specialText = "";

            if (node is KmlKerbal)
            {
                nodeName = "kerbal";
                if ((node as KmlKerbal).AssignedPart != null)
                {
                    specialText = "\n\n- The kerbal will be removed from assigned crew part";
                }
            }
            else if (node is KmlVessel)
            {
                nodeName = "vessel";
                if ((node as KmlVessel).AssignedCrew.Count > 0)
                {
                    specialText = "\n\n- Kerbal crew will be send home to astronaut complex\n" +
                                  "- Their state will be set to 'Available'\n" +
                                  "- Experience or contract progress may get lost";
                }
            }
            else if (node is KmlPart)
            {
                nodeName    = "part";
                specialText = "\n\n- Part will be removed from vessel structure\n" +
                              "- Attachment indices will be updated";
                if (node.Parent is KmlVessel)
                {
                    foreach (KmlKerbal kerbal in (node.Parent as KmlVessel).AssignedCrew)
                    {
                        if (kerbal.AssignedPart == node)
                        {
                            specialText += "\n- Kerbal crew will be send home to astronaut complex\n" +
                                           "- Their state will be set to 'Available'\n" +
                                           "- Experience or contract progress may get lost";
                            break;
                        }
                    }
                }
            }
            if (DlgConfirmation.Show("Do you really want to delete this " + nodeName + " and all its content?\n" +
                                     node + specialText, "DELETE " + nodeName, Icons.Delete))
            {
                node.Delete();
                // View will be refreshed in parent's ChildrenChanged event
                // Special case: PartGraph is currently shown
                if (Parent is GuiVesselsPartGraphNode)
                {
                    GuiVesselsPartGraphNode pgn = (GuiVesselsPartGraphNode)Parent;
                    if (pgn.Parent is Canvas)
                    {
                        Canvas cnv = (Canvas)pgn.Parent;
                        foreach (var line in pgn.Lines)
                        {
                            cnv.Children.Remove(line);
                        }
                        cnv.Children.Remove(pgn);
                    }
                }
            }
        }