void MainTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Effect == DragDropEffects.None) { return; } var targetNode = new DnDData(MainTree.GetNodeAt(MainTree.PointToClient(new System.Drawing.Point(e.X, e.Y))) as PrjExplorerNode); if (targetNode == null) { return; } MainTree.SelectedNode = targetNode.Node; bool LastState = IsCut; IsCut = e.Effect == System.Windows.Forms.DragDropEffects.Move; if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop)) { foreach (var file in e.Data.GetData(DataFormats.FileDrop) as string[]) { DoPaste(file, targetNode); } } else if (e.Data.GetDataPresent(typeof(DnDData))) { DoPaste(e.Data.GetData(typeof(DnDData)) as DnDData, targetNode); } IsCut = LastState; }
void MainTree_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = System.Windows.Forms.DragDropEffects.None; var targetNode = new DnDData(MainTree.GetNodeAt(MainTree.PointToClient(new System.Drawing.Point(e.X, e.Y))) as PrjExplorerNode); if (targetNode == null) { return; } MainTree.SelectedNode = targetNode.Node; if (targetNode.Node != null) { targetNode.Node.Expand(); } if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop)) { var files = e.Data.GetData(DataFormats.FileDrop) as string[]; // Force all files to be droppable foreach (var file in files) { if (!IsDropAllowed(file, targetNode.Node)) { return; } } e.Effect = System.Windows.Forms.DragDropEffects.Copy; } else if (e.Data.GetDataPresent(typeof(DnDData))) { var d = e.Data.GetData(typeof(DnDData)) as DnDData; if (!IsDropAllowed(d.Path, targetNode.Node)) { return; } // If src prj and dest prj are equal, set default action to 'move' bool Move = d.Project == targetNode.Project; // If ctrl is pressed anyway, turn action if ((e.KeyState & 8) == 8) { Move = !Move; } if (!Move) // If ctrl has been pressed { e.Effect = System.Windows.Forms.DragDropEffects.Copy; } else { e.Effect = System.Windows.Forms.DragDropEffects.Move; // Move file/dir by default } } }
/// <summary> /// Note: We will be only allowed to COPY files, not move them /// </summary> /// <param name="file"></param> /// <param name="dropNode"></param> public void DoPaste(string file, DnDData dropNode) { // Solution if (file.EndsWith(Solution.SolutionExtension)) { IDEManager.Instance.OpenFile(file); return; } // Project bool isPrj = false; AbstractLanguageBinding.SearchBinding(file, out isPrj); if (isPrj && dropNode.IsSln) { IDEManager.ProjectManagement.AddExistingProjectToSolution(dropNode.Solution, file); } else if (isPrj) // Ignore already existing projects { return; } bool IsDir = Directory.Exists(file); var dropFile = dropNode.Path; // 'Pre-expand' our drop node - when the tree gets updated if (!dropNode.IsPrj) { _ExpandedNodes.Add(dropNode.Node.FullPath); } var dropDir = ""; if (dropNode.IsDir) { dropDir = (dropNode.Node as DirectoryNode).RelativePath; } else if (dropNode.IsFile) { dropDir = Path.GetDirectoryName((dropNode.Node as FileNode).RelativeFilePath); } if (IsDir) { IDEManager.FileManagement.AddExistingDirectoryToProject(file, dropNode.Project, dropDir); } else { IDEManager.FileManagement.AddExistingSourceToProject(dropNode.Project, dropDir, file); } }
public void DoPaste(DnDData data, DnDData dropNode) { // 'Pre-expand' our drop node - when the tree gets updated if (!dropNode.IsPrj) { _ExpandedNodes.Add(dropNode.Node.FullPath); } if (data.IsDir) { var src_path = (data.Node as DirectoryNode).RelativePath; var src_prj = data.Project; var dest_path = dropNode.IsDir?(dropNode.Node as DirectoryNode).RelativePath: ""; if (dropNode.IsFile) { dest_path = Path.GetDirectoryName(dropNode.Path); } var dest_prj = dropNode.Project; dest_path = dest_prj.ToRelativeFileName(dest_path); if (dest_prj != null) { if (IsCut) { IDEManager.FileManagement.MoveDirectory(src_prj, src_path, dest_prj, dest_path); } else { IDEManager.FileManagement.CopyDirectory(src_prj, src_path, dest_prj, dest_path); } } } else if (data.IsFile) { var src_path = (data.Node as FileNode).RelativeFilePath; var src_prj = data.Project; var dest_path = dropNode.IsDir ? (dropNode.Node as DirectoryNode).RelativePath : ""; if (dropNode.IsFile) { dest_path = Path.GetDirectoryName(dropNode.Path); } var dest_prj = dropNode.Project; dest_path = dest_prj.ToRelativeFileName(dest_path); if (dest_prj != null) { if (IsCut) { IDEManager.FileManagement.MoveFile(src_prj, src_path, dest_prj, dest_path); } else { IDEManager.FileManagement.CopyFile(src_prj, src_path, dest_prj, dest_path); } } } }
/// <summary> /// Note: We will be only allowed to COPY files, not move them /// </summary> /// <param name="file"></param> /// <param name="dropNode"></param> public void DoPaste(string file,DnDData dropNode) { // Solution if (file.EndsWith(Solution.SolutionExtension)) { IDEManager.Instance.OpenFile(file); return; } // Project bool isPrj = false; AbstractLanguageBinding.SearchBinding(file, out isPrj); if (isPrj && dropNode.IsSln) IDEManager.ProjectManagement.AddExistingProjectToSolution(dropNode.Solution, file); else if (isPrj) // Ignore already existing projects return; bool IsDir = Directory.Exists(file); var dropFile = dropNode.Path; // 'Pre-expand' our drop node - when the tree gets updated if(!dropNode.IsPrj) _ExpandedNodes.Add(dropNode.Node.FullPath); var dropDir = ""; if (dropNode.IsDir) dropDir = (dropNode.Node as DirectoryNode).RelativePath; else if (dropNode.IsFile) dropDir = Path.GetDirectoryName( (dropNode.Node as FileNode).RelativeFilePath); if (IsDir) IDEManager.FileManagement.AddExistingDirectoryToProject(file, dropNode.Project, dropDir); else IDEManager.FileManagement.AddExistingSourceToProject(dropNode.Project, dropDir, file); }
public void DoPaste(DnDData data, DnDData dropNode) { // 'Pre-expand' our drop node - when the tree gets updated if (!dropNode.IsPrj) _ExpandedNodes.Add(dropNode.Node.FullPath); if (data.IsDir) { var src_path = (data.Node as DirectoryNode).RelativePath; var src_prj = data.Project; var dest_path = dropNode.IsDir?(dropNode.Node as DirectoryNode).RelativePath: ""; if (dropNode.IsFile) dest_path = Path.GetDirectoryName(dropNode.Path); var dest_prj = dropNode.Project; dest_path = dest_prj.ToRelativeFileName(dest_path); if (dest_prj != null) if (IsCut) IDEManager.FileManagement.MoveDirectory(src_prj, src_path, dest_prj, dest_path); else IDEManager.FileManagement.CopyDirectory(src_prj, src_path, dest_prj, dest_path); } else if (data.IsFile) { var src_path = (data.Node as FileNode).RelativeFilePath; var src_prj = data.Project; var dest_path = dropNode.IsDir ? (dropNode.Node as DirectoryNode).RelativePath : ""; if (dropNode.IsFile) dest_path = Path.GetDirectoryName(dropNode.Path); var dest_prj = dropNode.Project; dest_path = dest_prj.ToRelativeFileName(dest_path); if (dest_prj != null) if (IsCut) IDEManager.FileManagement.MoveFile(src_prj, src_path, dest_prj, dest_path); else IDEManager.FileManagement.CopyFile(src_prj, src_path, dest_prj, dest_path); } }
void MainTree_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = System.Windows.Forms.DragDropEffects.None; var targetNode = new DnDData( MainTree.GetNodeAt(MainTree.PointToClient(new System.Drawing.Point(e.X, e.Y))) as PrjExplorerNode); if (targetNode == null) return; MainTree.SelectedNode = targetNode.Node; if (targetNode.Node != null) targetNode.Node.Expand(); if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop)) { var files = e.Data.GetData(DataFormats.FileDrop) as string[]; // Force all files to be droppable foreach (var file in files) if (!IsDropAllowed(file, targetNode.Node)) return; e.Effect = System.Windows.Forms.DragDropEffects.Copy; } else if (e.Data.GetDataPresent(typeof(DnDData))) { var d = e.Data.GetData(typeof(DnDData)) as DnDData; if(!IsDropAllowed(d.Path,targetNode.Node)) return; // If src prj and dest prj are equal, set default action to 'move' bool Move=d.Project==targetNode.Project; // If ctrl is pressed anyway, turn action if((e.KeyState & 8) == 8) Move=!Move; if (!Move) // If ctrl has been pressed e.Effect = System.Windows.Forms.DragDropEffects.Copy; else e.Effect = System.Windows.Forms.DragDropEffects.Move; // Move file/dir by default } }
void MainTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Effect == DragDropEffects.None) return; var targetNode = new DnDData(MainTree.GetNodeAt(MainTree.PointToClient(new System.Drawing.Point(e.X, e.Y))) as PrjExplorerNode); if (targetNode == null) return; MainTree.SelectedNode = targetNode.Node; bool LastState = IsCut; IsCut = e.Effect == System.Windows.Forms.DragDropEffects.Move; if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop)) foreach (var file in e.Data.GetData(DataFormats.FileDrop) as string[]) DoPaste(file,targetNode); else if (e.Data.GetDataPresent(typeof(DnDData))) DoPaste(e.Data.GetData(typeof(DnDData)) as DnDData, targetNode); IsCut = LastState; }