Esempio n. 1
0
		/*
		public void DoCopy(IDataObject dataObject, IListItemEx destination)
		{
				var handle = this.Handle;
				var thread = new Thread(() =>
				{
						var items = new IShellItem[0];
						if (dataObject.GetDataPresent("FileDrop"))
								items = ((F.DataObject)dataObject).GetFileDropList().OfType<String>().Select(s => FileSystemListItem.ToFileSystemItem(IntPtr.Zero, s.ToShellParsingName()).ComInterface).ToArray();
						else
								items = dataObject.ToShellItemArray().ToArray();

						try
						{
								var fo = new IIFileOperation(handle);
								foreach (var item in items)
								{
										fo.CopyItem(item, destination);
								}

								fo.PerformOperations();
						}
						catch (SecurityException)
						{
								throw;
						}
				});
				thread.SetApartmentState(ApartmentState.STA);
				thread.Start();
		}
		*/

		/// <summary>
		/// Pasted the files in the clipboard to the <see cref="ShellTreeView"/>'s currentlt <see cref="TreeView.SelectedNode">Selected Node</see> on a separate thread
		/// </summary>
		private void PasteAvailableFiles() {
			var selectedItem = this.ShellTreeView.SelectedNode.Tag as IListItemEx;
			if (selectedItem == null) return;
			var handle = this.Handle;
			var thread = new Thread(() => {
				var dataObject = F.Clipboard.GetDataObject();
				IShellItemArray items = null;
				if (dataObject.GetDataPresent("FileDrop")) {
					//TODO: Fix FileDorp option
					//items = ((F.DataObject)dataObject).GetFileDropList().OfType<String>().Select(s => FileSystemListItem.ToFileSystemItem(IntPtr.Zero, s.ToShellParsingName()).ComInterface).ToArray();
				}
				else {
					items = dataObject.ToShellItemArray();
				}

				try {
					var fo = new IIFileOperation(handle);
					if (dataObject.ToDropEffect() == System.Windows.DragDropEffects.Copy)
						fo.CopyItems(items, selectedItem);
					else
						fo.MoveItems(items, selectedItem);

					fo.PerformOperations();
				}
				catch (SecurityException) {
					throw;
				}
			});

			thread.SetApartmentState(ApartmentState.STA);
			thread.Start();
		}
Esempio n. 2
0
    public void PasteAvailableFiles() {
      var handle = this.Handle;
      var view = this;
      var thread = new Thread(() => {
        var dataObject = F.Clipboard.GetDataObject();
        var dropEffect = dataObject.ToDropEffect();
        if (dataObject != null && dataObject.GetDataPresent("Shell IDList Array")) {
          var shellItemArray = dataObject.ToShellItemArray();
          var items = shellItemArray.ToArray();

          try {
            var sink = new FOperationProgressSink(view);
            var controlItem = FileSystemListItem.InitializeWithIShellItem(this.LVHandle, items.First()).Parent;
            var fo = new IIFileOperation(sink, handle, true, controlItem.Equals(this.CurrentFolder));
            if (dropEffect == System.Windows.DragDropEffects.Copy) {
              fo.CopyItems(shellItemArray, this.CurrentFolder);
            } else {
              fo.MoveItems(shellItemArray, this.CurrentFolder);
            }

            fo.PerformOperations();
            Marshal.ReleaseComObject(shellItemArray);
          } catch (SecurityException) {
            throw;
          }
        } else if (dataObject != null && dataObject.GetDataPresent("FileDrop")) {
          var items = ((String[])dataObject.GetData("FileDrop")).Select(s => ShellItem.ToShellParsingName(s).ComInterface).ToArray();
          try {
            var sink = new FOperationProgressSink(view);
            var controlItem = FileSystemListItem.InitializeWithIShellItem(this.LVHandle, items.First()).Parent;
            var fo = new IIFileOperation(sink, handle, true, controlItem.Equals(this.CurrentFolder));
            foreach (var item in items) {
              if (dropEffect == System.Windows.DragDropEffects.Copy)
                fo.CopyItem(item, this.CurrentFolder);
              else
                fo.MoveItem(item, this.CurrentFolder, null);
            }

            fo.PerformOperations();
          } catch (SecurityException) {
            throw;
          }
        }
        this.LargeImageList.SupressThumbnailGeneration(false);
      });

      thread.SetApartmentState(ApartmentState.STA);
      thread.Start();
      Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
    }