public override void Drop(DragEventArgs e, int index) { Debug.Assert(Context.CanDragAndDrop); if (!Context.CanDragAndDrop) { return; } var nodeIndexes = e.Data.GetData(FileTVConstants.DATAFORMAT_COPIED_ROOT_NODES) as int[]; if (nodeIndexes != null) { Debug.Assert(DropNodes != null); DropNodes?.Invoke(index, nodeIndexes); return; } var filenames = e.Data.GetData(DataFormats.FileDrop) as string[]; if (filenames != null) { Debug.Assert(DropFiles != null); DropFiles?.Invoke(index, filenames); return; } Debug.Fail("Unknown drop data format"); }
public override void Drop(DragEventArgs e, int index) { Debug.Assert(Context.CanDragAndDrop); if (!Context.CanDragAndDrop) { return; } if (e.Data.GetData(DocumentTreeViewConstants.DATAFORMAT_COPIED_ROOT_NODES) is int[] nodeIndexes) { Debug2.Assert(DropNodes is not null); DropNodes?.Invoke(index, nodeIndexes); return; } if (e.Data.GetData(DataFormats.FileDrop) is string[] filenames) { Debug2.Assert(DropFiles is not null); DropFiles?.Invoke(index, filenames); return; } Debug.Fail("Unknown drop data format"); }
public static void DropFile(IntPtr hWnd, IList<MmdDropFile> files) { var names = Encoding.Unicode.GetBytes(string.Join("\0", files.Select(_ => _.FullName).ToArray()) + "\0\0"); var pipes = files.Where(_ => _.IsPipe).Select(_ => new { Pipe = new NamedPipeServerStream(_.FileName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous), File = _ }).ToArray(); var dropFilesSize = Marshal.SizeOf(typeof(DropFiles)); var hGlobal = Marshal.AllocHGlobal(dropFilesSize + names.Length); var dropFiles = new DropFiles { pFiles = (uint)dropFilesSize, x = 0, y = 0, fNC = false, fWide = true }; Marshal.StructureToPtr(dropFiles, hGlobal, true); Marshal.Copy(names, 0, new IntPtr(hGlobal.ToInt32() + dropFiles.pFiles), names.Length); PostMessage(hWnd, WM_DROPFILES, hGlobal, IntPtr.Zero); // Marshal.FreeHGlobal(hGlobal); foreach (var i in pipes) using (var handle = new ManualResetEvent(false)) { var success = false; i.Pipe.BeginWaitForConnection(ar => { try { i.Pipe.EndWaitForConnection(ar); success = true; try { i.File.Stream.CopyTo(i.Pipe, (int)i.File.Stream.Length); i.Pipe.WaitForPipeDrain(); } catch (IOException) { } i.Pipe.Dispose(); i.File.Stream.Dispose(); handle.Set(); } catch (ObjectDisposedException) { } }, null); if (i.File.Timeout != -1) ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(i.File.Timeout); if (!success && !i.Pipe.IsConnected) { i.Pipe.Dispose(); i.File.Stream.Dispose(); handle.Set(); } }); handle.WaitOne(); } }
public static void DropFile(IntPtr hWnd, IList <MmdDropFile> files) { var names = Encoding.Unicode.GetBytes(string.Join("\0", files.Select(_ => _.FullName).ToArray()) + "\0\0"); var pipes = files.Where(_ => _.IsPipe).Select(_ => new { Pipe = new NamedPipeServerStream(_.FileName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous), File = _ }).ToArray(); var dropFilesSize = Marshal.SizeOf(typeof(DropFiles)); var hGlobal = Marshal.AllocHGlobal(dropFilesSize + names.Length); var dropFiles = new DropFiles { pFiles = (uint)dropFilesSize, x = 0, y = 0, fNC = false, fWide = true }; Marshal.StructureToPtr(dropFiles, hGlobal, true); Marshal.Copy(names, 0, new IntPtr(hGlobal.ToInt64() + dropFiles.pFiles), names.Length); PostMessage(hWnd, WM_DROPFILES, hGlobal, IntPtr.Zero); // Marshal.FreeHGlobal(hGlobal); foreach (var i in pipes) { using (var handle = new ManualResetEvent(false)) { var success = false; i.Pipe.BeginWaitForConnection(ar => { try { i.Pipe.EndWaitForConnection(ar); success = true; try { i.File.Stream.CopyTo(i.Pipe, (int)i.File.Stream.Length); i.Pipe.WaitForPipeDrain(); } catch (IOException) {} i.Pipe.Dispose(); i.File.Stream.Dispose(); handle.Set(); } catch (ObjectDisposedException) {} }, null); if (i.File.Timeout != -1) { ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(i.File.Timeout); if (!success && !i.Pipe.IsConnected) { i.Pipe.Dispose(); i.File.Stream.Dispose(); handle.Set(); } }); } handle.WaitOne(); } } }
private void OnDropFiles(string[] files) => DropFiles?.Invoke(this, files);