コード例 #1
0
        private void treeFiles_AfterNodeDrop(object sender, TreeDragDropEventArgs e)
        {
            TagInfo ti = (TagInfo)e.Node.Tag;
            OutputFolder oldParentFolder = Project.Instance.FindFolder(((TagInfo)e.OldParentNode.Tag).Id);
            OutputFolder newParentFolder = Project.Instance.FindFolder(((TagInfo)e.NewParentNode.Tag).Id);
            Node prevNode = e.Node.PrevNode;

            if (prevNode != null && ((TagInfo)prevNode.Tag).FileType == TagInfo.FileTypes.Folder)
            {
                // The user dropped just below a folder, so meant to add to that folder, so we must make the dragged node a child node, not a sibling.
                e.Node.PrevNode.Nodes.Add(e.Node);
                newParentFolder = Project.Instance.FindFolder(((TagInfo)prevNode.Tag).Id);
            }
            switch (ti.FileType)
            {
                case TagInfo.FileTypes.Folder:
                    OutputFolder folder = Project.Instance.FindFolder(((TagInfo)e.Node.Tag).Id);
                    oldParentFolder.Folders.Remove(folder);
                    newParentFolder.Folders.Add(folder);
                    break;
                case TagInfo.FileTypes.NormalFile:
                case TagInfo.FileTypes.ScriptFile:
                    OutputFile normalFile = Project.Instance.FindFile(((TagInfo)e.Node.Tag).Id);
                    oldParentFolder.RemoveFile(normalFile);
                    newParentFolder.Files.Add(normalFile);
                    break;
                default:
                    throw new NotImplementedException("Not coded yet: " + ti.FileType);
            }
            Project.Instance.IsDirty = true;
        }
コード例 #2
0
        private void advTree1_AfterNodeDrop(object sender, TreeDragDropEventArgs e)
        {
            IDesignerHost dh = (IDesignerHost)GetDesignService(typeof(IDesignerHost));
            DesignerTransaction dt = null;
            if (dh != null) dt = dh.CreateTransaction("Move items");

            IComponentChangeService cc = GetDesignService(typeof(IComponentChangeService)) as IComponentChangeService;

            try
            {
                RadialMenuItem movedItem = e.Node.Tag as RadialMenuItem;
                RadialMenuItem parent = movedItem.Parent as RadialMenuItem;
                
                if (cc != null)
                {
                    OnComponentChanging(parent, cc);
                }

                if (parent == null)
                {
                    if (_RadialMenu != null)
                        _RadialMenu.Items.Remove(movedItem);
                    else if (_RadialMenuContainer != null)
                        _RadialMenuContainer.SubItems.Remove(movedItem);
                }
                else
                    parent.SubItems.Remove(movedItem);

                if (cc != null)
                {
                    OnComponentChanged(parent, cc);
                }

                if (e.NewParentNode == null)
                {
                    int index = advTree1.Nodes.IndexOf(e.Node);
                    if (cc != null)
                    {
                        if (_RadialMenu != null)
                            cc.OnComponentChanging(_RadialMenu, TypeDescriptor.GetProperties(_RadialMenu)["Items"]);
                        else if (_RadialMenuContainer != null)
                            cc.OnComponentChanging(_RadialMenuContainer, TypeDescriptor.GetProperties(_RadialMenuContainer)["SubItems"]);
                    }

                    if (_RadialMenu != null)
                        _RadialMenu.Items.Insert(index, movedItem);
                    else if (_RadialMenuContainer != null)
                        _RadialMenuContainer.SubItems.Insert(index, movedItem);

                    if (cc != null)
                    {
                        if (_RadialMenu != null)
                            cc.OnComponentChanged(_RadialMenu, TypeDescriptor.GetProperties(_RadialMenu)["Items"], null, null);
                        else if (_RadialMenuContainer != null)
                            cc.OnComponentChanged(_RadialMenuContainer, TypeDescriptor.GetProperties(_RadialMenuContainer)["SubItems"], null, null);
                    }
                }
                else
                {
                    parent = e.NewParentNode.Tag as RadialMenuItem;
                    int index = e.NewParentNode.Nodes.IndexOf(e.Node);
                    if (cc != null) cc.OnComponentChanging(parent, TypeDescriptor.GetProperties(parent)["SubItems"]);
                    parent.SubItems.Insert(index, movedItem);
                    if (cc != null) cc.OnComponentChanged(parent, TypeDescriptor.GetProperties(parent)["SubItems"], null, null);
                }
            }
            catch
            {
                if (dt != null)
                    dt.Cancel();
                throw;
            }
            finally
            {
                if (dt != null && !dt.Canceled)
                    dt.Commit();
            }
        }