예제 #1
0
        void projectTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (sender is TreeView)
            {
                Point pt = new Point(e.X, e.Y);
                pt = ((TreeView)sender).PointToClient(pt);
                dropOnNode = ((TreeView)sender).GetNodeAt(pt);

                if (e.Data.GetData("DraggedPageNode") != null)
                {
                    if (dropOnNode != null && dropOnNode.Parent != null && dropOnNode is PageNode)
                    {
                        if (dropOnNode != draggedPageNode)
                        {
                            draggedPageNode.Remove();
                            int mouseOverIndex = dropOnNode.Index;

                            if (dropOnNode.Parent != null)
                            {
                                dropOnNode.Parent.Nodes.Insert(mouseOverIndex, draggedPageNode);

                                foreach (TreeNode pageNode in dropOnNode.Parent.Nodes)
                                {
                                    if (pageNode is PageNode)
                                    {
                                        ((PageNode)pageNode).Page.Position = pageNode.Index;
                                        ((PageNode)pageNode).Page.SaveToDb();
                                    }
                                }
                            }
                        }
                    }
                }
                if (e.Data.GetData("DraggedTemplateNode") != null)
                {
                    if (dropOnNode != null && dropOnNode is PageNode)
                    {
                        int dropOnNodePosition = ((PageNode)dropOnNode).Page.Position;
                        SelectView(((PageNode)dropOnNode).Page.view.Name);
                        Template template = new Template(this.mainForm.mediator);
                        template.CreateFromTemplate((TemplateNode)draggedTemplateNode, dropOnNodePosition);

                        int mouseOverIndex = dropOnNodePosition;

                        if (dropOnNode != null && dropOnNode.Parent != null)
                        {
                            foreach (TreeNode pageNode in dropOnNode.Parent.Nodes)
                            {
                                if (pageNode is PageNode)
                                {
                                    ((PageNode)pageNode).Page.Position = pageNode.Index;
                                    ((PageNode)pageNode).Page.SaveToDb();
                                }
                            }
                        }

                        Page selectedPage = this.mainForm.mediator.ProjectExplorer.SelectedPage;
                        this.mainForm.mediator.projectExplorer_PageSelected(selectedPage);
                    }
                    else if (dropOnNode != null && dropOnNode is ViewNode)
                    {
                        if (draggedTemplateNode.FullPath.Contains(@"Templates\Pages\"))
                        {
                            int dropOnNodePosition = ((ViewNode)dropOnNode).Nodes.Count;
                            SelectView(((ViewNode)dropOnNode).Text);
                            Template template = new Template(this.mainForm.mediator);
                            template.CreateFromTemplate((TemplateNode)draggedTemplateNode, dropOnNodePosition);
                            int mouseOverIndex = dropOnNodePosition;
                            if (dropOnNode != null && dropOnNode.Parent != null)
                            {
                                foreach (TreeNode pageNode in dropOnNode.Parent.Nodes)
                                {
                                    if (pageNode is PageNode)
                                    {
                                        ((PageNode)pageNode).Page.Position = pageNode.Index;
                                        ((PageNode)pageNode).Page.SaveToDb();
                                    }
                                }
                            }
                            Page selectedPage = this.mainForm.mediator.ProjectExplorer.SelectedPage;
                            this.mainForm.mediator.projectExplorer_PageSelected(selectedPage);
                        }
                        else
                        new Template(this.mainForm.mediator).CreateFromTemplate((TemplateNode)draggedTemplateNode, new Point(0, 0));
                    }
                }
            }

            dropOnNode = null;
        }