public void SetSupportedDragDropEffects(DragDropEffects effects, DragDropEffects defaultEffect = DragDropEffects.Copy) { ContextMenu.Items.Clear(); foreach (var e in Enum.GetValues(typeof(DragDropEffects))) { DragDropEffects curEffect = (DragDropEffects)e; if (curEffect != DragDropEffects.None && effects.HasFlag(curEffect)) { var header = new TextBlock() { Text = curEffect.ToString() }; if (curEffect.Equals(defaultEffect)) { header.FontWeight = FontWeights.Bold; ContextMenu.Items.Insert(0, new MenuItem() { Tag = e, Header = header }); } else { ContextMenu.Items.Add(new MenuItem() { Tag = e, Header = header }); } } } }
/// <summary> /// Occurs when the left mouse button is released in the area /// occupied by the dropTarget (specified in the constructor). /// You must likely will provide your own method; make sure /// to define Drop in DataConsumerActions. /// /// See DropTarget_DragEnter in DropManager for additional comments. /// </summary> private void DropTarget_Drop(object sender, DragEventArgs e) { //throw new NotImplementedException("Drop not implemented"); #if PRINT2BUFFER DragDropBuffer.buf0.Append('D'); #endif DragDropEffects effects = e.Effects; if (DragDrop_Drop != null) { DragDrop_Drop(sender, e); } if (e.Handled) { return; } #if TESTING e.Effects = DragDropEffects.Move; e.Handled = true; #else foreach (IDataConsumer dragDropConsumer in this._dragDropConsumers) { if ((dragDropConsumer.DataConsumerActions & DataConsumerActions.Drop) != 0) { dragDropConsumer.DropTarget_Drop(sender, e); if (e.Handled) { break; } } } if (!e.Handled) { e.Effects = DragDropEffects.None; e.Handled = true; } #endif #if PRINT2OUTPUT Debug.WriteLine( "D Handled=" + e.Handled.ToString() + " sender=" + sender.GetType().ToString() + " Source=" + e.Source.GetType().ToString() + " OriginalSource=" + e.OriginalSource.GetType().ToString() + " Effects=" + effects.ToString() + " ReturnedEffects=" + e.Effects.ToString() + " AllowedEffects=" + e.AllowedEffects + this.DropObjectFormat(e) ); #endif #if PRINT2BUFFER DragDropBuffer.buf1.Append('D'); #endif }
/// <summary> /// Retured effects are passed to *_DragEnter in both Effects and AllowedEffects; /// even effects not included in DoDragDrop's allowedEffects can be used. /// </summary> private void DropTarget_DragLeave(object sender, DragEventArgs e) { //throw new NotImplementedException("DragLeave not implemented"); #if PRINT2BUFFER ((Window1)Application.Current.MainWindow).buf0.Append('L'); #endif DragDropEffects effects = e.Effects; #if TESTING e.Effects = DragDropEffects.Link; e.Handled = true; #else foreach (IDataConsumer dragDropConsumer in this._dragDropConsumers) { if ((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragLeave) != 0) { dragDropConsumer.DropTarget_DragLeave(sender, e); if (e.Handled) { break; } } } if (!e.Handled) { e.Effects = DragDropEffects.None; e.Handled = true; } #endif #if PRINT2OUTPUT Debug.WriteLine( "L Handled=" + e.Handled.ToString() + " sender=" + sender.GetType().ToString() + " Source=" + e.Source.GetType().ToString() + " OriginalSource=" + e.OriginalSource.GetType().ToString() + " Effects=" + effects.ToString() + " ReturnedEffects=" + e.Effects.ToString() + " AllowedEffects=" + e.AllowedEffects + this.DropObjectFormat(e) ); #endif #if PRINT2BUFFER ((Window1)Application.Current.MainWindow).buf1.Append('L'); #endif }
/// <summary> /// Initial call, after DoDragDrop is called, has Effects and AllowedEffects set to /// allowedEffects as passed to DoDragDrop. Subsequent Effects and AllowedEffects /// are set to the Effects returned by DragLeave. Note that DragLeave can return /// effects that are not defined in allowedEffects (as passed to DoDragDrop). /// Source and Original source are set to dragSource as passed to DoDragDrop. /// </summary> private void DropTarget_DragEnter(object sender, DragEventArgs e) { //throw new NotImplementedException("DragEnter not implemented"); DragDropEffects effects = e.Effects; #if TESTING e.Effects = DragDropEffects.Copy; e.Handled = true; #else foreach (IDataConsumer dragDropConsumer in this._dragDropConsumers) { if ((dragDropConsumer.DataConsumerActions & DataConsumerActions.DragEnter) != 0) { dragDropConsumer.DropTarget_DragEnter(sender, e); if (e.Handled) { break; } } } if (!e.Handled) { e.Effects = DragDropEffects.None; e.Handled = true; } #endif #if PRINT2OUTPUT Debug.WriteLine( "E Handled=" + e.Handled.ToString() + " sender=" + sender.GetType().ToString() + " Source=" + e.Source.GetType().ToString() + " OriginalSource=" + e.OriginalSource.GetType().ToString() + " Effects=" + effects.ToString() + " ReturnedEffects=" + e.Effects.ToString() + " AllowedEffects=" + e.AllowedEffects + this.DropObjectFormat(e) ); #endif }
public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { PerformInitialization(); Expand(); try { if (dataObject.GetDataPresent(typeof(FileNode))) { FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + fileNode.FileName + "' onto directory '" + this.Directory + "'"); if (!FileUtility.IsEqualFileName(Directory, fileNode.FileName) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(fileNode.FileName)) && !(fileNode.ProjectItem is FileProjectItem && FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(GetFullVirtualName((FileProjectItem)fileNode.ProjectItem))))) { LoggingService.Debug("-> Not in same directory, performing " + effect.ToString()); CopyFileHere(fileNode, effect == DragDropEffects.Move); } else { // Dragging a dependent file onto its parent directory // removes the dependency. LoggingService.Debug("-> In same directory, removing dependency"); ((FileProjectItem)fileNode.ProjectItem).DependentUpon = String.Empty; fileNode.Remove(); if (!File.Exists(fileNode.FileName)) { fileNode.FileNodeStatus = FileNodeStatus.Missing; } else { fileNode.FileNodeStatus = FileNodeStatus.InProject; } fileNode.InsertSorted(this); } } else if (dataObject.GetDataPresent(typeof(DirectoryNode))) { DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode)); CopyDirectoryHere(directoryNode, effect == DragDropEffects.Move); } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])dataObject.GetData(DataFormats.FileDrop); if (files != null) { foreach (string fileName in files) { if (System.IO.Directory.Exists(fileName)) { if (!FileUtility.IsBaseDirectory(fileName, Directory)) { CopyDirectoryHere(fileName, false); } } else { CopyFileHere(fileName, false); } } } } ProjectService.SaveSolution(); } catch (Exception e) { MessageService.ShowException(e); } }
private void CopyOrMove_UpdatedBrowserTreeView(DragDropEffects dragDropEffects, StringCollection sourceFilesAndFolders, string targetFolder, TreeNode targetNode) { try { if (dragDropEffects == DragDropEffects.None) { KryptonMessageBox.Show("Was not able to detect if you select copy or cut object that was pasted or dropped", "Warning...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); return; } if (!Directory.Exists(targetFolder)) { KryptonMessageBox.Show("Target folder is not a valid target folder.\r\nSelected system folder:" + targetNode?.FullPath == null ? "Unkown" : targetNode?.FullPath, "Warning...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); return; } if (IsFileInAnyQueueLock(sourceFilesAndFolders)) { KryptonMessageBox.Show("Can't " + dragDropEffects.ToString() + " files. Files are being used, you need wait until process is finished.", "Warning...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); return; } StringCollection sourceFiles = new StringCollection(); StringCollection sourceFolders = new StringCollection(); StringCollection sourceFilesSameAsTargetFiles = new StringCollection(); StringCollection sourceFoldersSameAsTagetFolders = new StringCollection(); int numberOfFilesAndFolders = 0; string informationTextCopyFromFolders = ""; int countFoldersSelected = 0; foreach (string sourceFileOrFolder in sourceFilesAndFolders) { if (File.Exists(sourceFileOrFolder)) //Check if is a file { if (Path.GetDirectoryName(sourceFileOrFolder) != targetFolder) { sourceFiles.Add(sourceFileOrFolder); numberOfFilesAndFolders++; } else { sourceFilesSameAsTargetFiles.Add(sourceFileOrFolder); } } else if (Directory.Exists(sourceFileOrFolder)) //If not file, check if folder and still exists { if (sourceFileOrFolder != targetFolder) { sourceFolders.Add(sourceFileOrFolder); numberOfFilesAndFolders++; if (numberOfFilesAndFolders <= 51) //Check if lot of files being processed { string[] fileAndFolderEntriesCount = Directory.EnumerateFiles(sourceFileOrFolder, "*", SearchOption.AllDirectories).Take(51).ToArray(); numberOfFilesAndFolders += fileAndFolderEntriesCount.Length; } countFoldersSelected++; if (countFoldersSelected < 3) { informationTextCopyFromFolders += sourceFileOrFolder + "\r\n"; } else if (countFoldersSelected == 4) { informationTextCopyFromFolders += "and more directories...\r\n"; } } else { sourceFoldersSameAsTagetFolders.Add(sourceFileOrFolder); } } } if (numberOfFilesAndFolders >= 1) { if (numberOfFilesAndFolders <= 50 || (MessageBox.Show("You are about to " + dragDropEffects.ToString() + " " + (numberOfFilesAndFolders > 50 ? "over 50+" : numberOfFilesAndFolders.ToString()) + " files and/or folders.\r\n\r\n" + "From:\r\n" + informationTextCopyFromFolders + "\r\n\r\n" + "To folder:\r\n" + targetFolder + "\r\n\r\n" + "Procced?", "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)) { if (dragDropEffects == DragDropEffects.Move) { MoveFilesNoRename_UpdateTreeViewFolderBrowser(treeViewFolderBrowser1, imageListView1, sourceFiles, targetFolder, targetNode); } else { CopyFiles_UpdateTreeViewFolderBrowser(treeViewFolderBrowser1, sourceFiles, targetFolder, targetNode); } foreach (string sourceDirectory in sourceFolders) { string newTagretDirectory = Path.Combine(targetFolder, new DirectoryInfo(sourceDirectory).Name); //Target directory + dragged (drag&drop) direcotry if (dragDropEffects == DragDropEffects.Move) { MoveFolder_UpdateTreeViewFolderBrowser(treeViewFolderBrowser1, sourceDirectory, newTagretDirectory, targetNode); } else { CopyFolder_UpdateTreeViewFolderBrowser(treeViewFolderBrowser1, sourceDirectory, newTagretDirectory, targetNode); } } treeViewFolderBrowser1.SelectedNode = targetNode; treeViewFolderBrowser1.SelectedNode.Expand(); ImageListView_FetchListOfMediaFiles_FromFolder_and_Aggregate(false, true); treeViewFolderBrowser1.Focus(); } } else { string fileMessage = ""; if (sourceFilesSameAsTargetFiles.Count == 1) { fileMessage = "Source file: " + sourceFilesSameAsTargetFiles[0] + "\r\n"; } else if (sourceFilesSameAsTargetFiles.Count >= 1) { fileMessage = "File count: " + sourceFilesSameAsTargetFiles.Count + "\r\n"; } string folderMessage = ""; if (sourceFoldersSameAsTagetFolders.Count == 1) { folderMessage = ""; } else if (sourceFoldersSameAsTagetFolders.Count >= 1) { folderMessage = "Folder count: " + sourceFoldersSameAsTagetFolders.Count + "\r\n"; } KryptonMessageBox.Show("Can't " + dragDropEffects.ToString() + " files. \r\n" + "Source and destiation are the same.\r\n\r\n" + "Target folder: " + targetFolder + "\r\n" + fileMessage + folderMessage, "Warning...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true); } treeViewFolderBrowser1.Focus(); } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show("Following error occured: \r\n" + ex.Message, "Was not able to complete operation", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } }
public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { PerformInitialization(); Expand(); try { if (dataObject.GetDataPresent(typeof(FileNode))) { FileNode fileNode = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + fileNode.FileName + "' onto directory '" + this.Directory + "'"); if (!FileUtility.IsEqualFileName(Directory, fileNode.FileName) && !FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(fileNode.FileName)) && !(fileNode.ProjectItem is FileProjectItem && FileUtility.IsEqualFileName(Directory, Path.GetDirectoryName(GetFullVirtualName((FileProjectItem)fileNode.ProjectItem))))) { LoggingService.Debug("-> Not in same directory, performing " + effect.ToString()); CopyFileHere(fileNode, effect == DragDropEffects.Move); } else { // Dragging a dependent file onto its parent directory // removes the dependency. LoggingService.Debug("-> In same directory, removing dependency"); ((FileProjectItem)fileNode.ProjectItem).DependentUpon = String.Empty; fileNode.Remove(); if (!File.Exists(fileNode.FileName)) { fileNode.FileNodeStatus = FileNodeStatus.Missing; } else { fileNode.FileNodeStatus = FileNodeStatus.InProject; } fileNode.InsertSorted(this); } } else if (dataObject.GetDataPresent(typeof(DirectoryNode))) { DirectoryNode directoryNode = (DirectoryNode)dataObject.GetData(typeof(DirectoryNode)); CopyDirectoryHere(directoryNode, effect == DragDropEffects.Move); } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])dataObject.GetData(DataFormats.FileDrop); foreach (string fileName in files) { if (System.IO.Directory.Exists(fileName)) { if (!FileUtility.IsBaseDirectory(fileName, Directory)) { CopyDirectoryHere(fileName, false); } } else { CopyFileHere(fileName, false); } } } ProjectService.SaveSolution(); } catch (Exception e) { MessageService.ShowException(e); } }
public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { if (dataObject.GetDataPresent(typeof(FileNode))) { // Dragging a file onto another creates a dependency. FileNode other = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + other.FileName + "' onto file '" + this.FileName + "'"); // Copy/move the file to the correct directory // if the target is in a different directory than the source. if (!FileUtility.IsEqualFileName(Path.GetDirectoryName(this.FileName), Path.GetDirectoryName(other.FileName))) { LoggingService.Debug("-> Source file is in different directory, performing " + effect.ToString()); ExtTreeNode p = this; DirectoryNode parentDirectory; do { p = (ExtTreeNode)p.Parent; parentDirectory = p as DirectoryNode; } while (parentDirectory == null && p != null); if (parentDirectory == null) { throw new InvalidOperationException("File '" + this.FileName + "' does not have a parent directory."); } LoggingService.Debug("-> Copying/Moving source file to parent directory of target: " + parentDirectory.Directory); string otherFileName = Path.GetFileName(other.FileName); parentDirectory.CopyFileHere(other, effect == DragDropEffects.Move); // Find the copied or moved file node again other = parentDirectory.AllNodes.OfType <FileNode>().SingleOrDefault(n => FileUtility.IsEqualFileName(Path.GetFileName(n.FileName), otherFileName)); } if (other != null) { other.Remove(); ((FileProjectItem)other.ProjectItem).DependentUpon = Path.GetFileName(this.FileName); other.FileNodeStatus = FileNodeStatus.BehindFile; other.InsertSorted(this); LoggingService.Debug("-> Created new dependency, saving solution"); ProjectService.SaveSolution(); } else { LoggingService.Debug("-> Could not find the copied or moved file node in the new parent directory."); } return; } ((ExtTreeNode)Parent).DoDragDrop(dataObject, effect); }
public override void DoDragDrop(IDataObject dataObject, DragDropEffects effect) { if (dataObject.GetDataPresent(typeof(FileNode))) { // Dragging a file onto another creates a dependency. FileNode other = (FileNode)dataObject.GetData(typeof(FileNode)); LoggingService.Debug("ProjectBrowser: Dragging file '" + other.FileName + "' onto file '" + this.FileName + "'"); // Copy/move the file to the correct directory // if the target is in a different directory than the source. if (!FileUtility.IsEqualFileName(Path.GetDirectoryName(this.FileName), Path.GetDirectoryName(other.FileName))) { LoggingService.Debug("-> Source file is in different directory, performing " + effect.ToString()); ExtTreeNode p = this; DirectoryNode parentDirectory; do { p = (ExtTreeNode)p.Parent; parentDirectory = p as DirectoryNode; } while (parentDirectory == null && p != null); if (parentDirectory == null) { throw new InvalidOperationException("File '" + this.FileName + "' does not have a parent directory."); } LoggingService.Debug("-> Copying/Moving source file to parent directory of target: " + parentDirectory.Directory); string otherFileName = Path.GetFileName(other.FileName); parentDirectory.CopyFileHere(other, effect == DragDropEffects.Move); // Find the copied or moved file node again other = parentDirectory.AllNodes.OfType<FileNode>().SingleOrDefault(n => FileUtility.IsEqualFileName(Path.GetFileName(n.FileName), otherFileName)); } if (other != null) { other.Remove(); ((FileProjectItem)other.ProjectItem).DependentUpon = Path.GetFileName(this.FileName); other.FileNodeStatus = FileNodeStatus.BehindFile; other.InsertSorted(this); LoggingService.Debug("-> Created new dependency, saving solution"); ProjectService.SaveSolution(); } else { LoggingService.Debug("-> Could not find the copied or moved file node in the new parent directory."); } return; } ((ExtTreeNode)Parent).DoDragDrop(dataObject, effect); }
private NativeDragDropEffects ToNative(DragDropEffects dragDropEffects) { NativeDragDropEffects nativeDragDropEffects; if (!NativeDragDropEffects.TryParse (dragDropEffects.ToString(), true, out nativeDragDropEffects)) throw new Exception ("Invalid effect"); return nativeDragDropEffects; }