IfcDoc.FormEdit.toolStripMenuItemEditMoveOut_Click C# (CSharp) Method

toolStripMenuItemEditMoveOut_Click() private method

private toolStripMenuItemEditMoveOut_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void toolStripMenuItemEditMoveOut_Click(object sender, EventArgs e)
        {
            TreeNode tn = this.treeView.SelectedNode;

            if (tn.Tag is DocTemplateDefinition)
            {
                DocTemplateDefinition docSource = (DocTemplateDefinition)tn.Tag;
                DocTemplateDefinition docTarget = (DocTemplateDefinition)tn.Parent.Tag;

                docTarget.Templates.Remove(docSource);

                if (tn.Parent.Parent.Tag is DocTemplateDefinition)
                {
                    // move to sub-level
                    DocTemplateDefinition docParent = (DocTemplateDefinition)tn.Parent.Parent.Tag;
                    int index = docParent.Templates.IndexOf(docTarget) + 1;
                    docParent.Templates.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    tn.Remove();
                    tnParent.Parent.Nodes.Insert(index, tn);
                }
                else
                {
                    // move to top-level
                    int index = this.m_project.Templates.IndexOf(docTarget) + 1;
                    this.m_project.Templates.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    TreeNode tnTarget = tn.Parent.Parent;

                    tn.Parent.Nodes.Remove(tn);
                    tnTarget.Nodes.Insert(index, tn);
                }
            }
            else if (tn.Tag is DocTemplateUsage)
            {
                DocTemplateUsage docSource = (DocTemplateUsage)tn.Tag;
                DocTemplateUsage docTarget = (DocTemplateUsage)tn.Parent.Tag;

                docTarget.Concepts.Remove(docSource);

                if (tn.Parent.Parent.Tag is DocTemplateUsage)
                {
                    // move to sub-level
                    DocTemplateUsage docParent = (DocTemplateUsage)tn.Parent.Parent.Tag;
                    int index = docParent.Concepts.IndexOf(docTarget) + 1;
                    docParent.Concepts.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    tn.Remove();
                    tnParent.Parent.Nodes.Insert(index, tn);
                }
                else
                {
                    // move to top-level
                    DocConceptRoot docParent = (DocConceptRoot)tn.Parent.Parent.Tag;
                    int index = docParent.Concepts.IndexOf(docTarget) + 1;
                    docParent.Concepts.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    TreeNode tnTarget = tn.Parent.Parent;

                    tn.Parent.Nodes.Remove(tn);
                    tnTarget.Nodes.Insert(index, tn);
                }
            }
            else if (tn.Tag is DocExample)
            {
                DocExample docSource = (DocExample)tn.Tag;
                DocExample docTarget = (DocExample)tn.Parent.Tag;

                docTarget.Examples.Remove(docSource);

                if (tn.Parent.Parent.Tag is DocExample)
                {
                    // move to sub-level
                    DocExample docParent = (DocExample)tn.Parent.Parent.Tag;
                    int index = docParent.Examples.IndexOf(docTarget) + 1;
                    docParent.Examples.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    tn.Remove();
                    tnParent.Parent.Nodes.Insert(index, tn);
                }
                else
                {
                    // move to top-level
                    int index = this.m_project.Examples.IndexOf(docTarget) + 1;
                    this.m_project.Examples.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    TreeNode tnTarget = tn.Parent.Parent;

                    tn.Parent.Nodes.Remove(tn);
                    tnTarget.Nodes.Insert(index, tn);
                }
            }
            else if (tn.Tag is DocTerm)
            {
                DocTerm docSource = (DocTerm)tn.Tag;
                DocTerm docTarget = (DocTerm)tn.Parent.Tag;

                docTarget.Terms.Remove(docSource);

                if (tn.Parent.Parent.Tag is DocTerm)
                {
                    // move to sub-level
                    DocTerm docParent = (DocTerm)tn.Parent.Parent.Tag;
                    int index = docParent.Terms.IndexOf(docTarget) + 1;
                    docParent.Terms.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    tn.Remove();
                    tnParent.Parent.Nodes.Insert(index, tn);
                }
                else
                {
                    // move to top-level
                    int index = this.m_project.Terms.IndexOf(docTarget) + 1;
                    this.m_project.Terms.Insert(index, docSource);

                    TreeNode tnParent = tn.Parent;
                    TreeNode tnTarget = tn.Parent.Parent;

                    tn.Parent.Nodes.Remove(tn);
                    tnTarget.Nodes.Insert(index, tn);
                }
            }

            this.treeView.SelectedNode = tn;
            this.m_modified = true;
        }
FormEdit