예제 #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();
		}
예제 #2
0
		private void ShellTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
			if (e.Label != null) {
				if (e.Label.Length > 0) {
					if (e.Label.IndexOfAny(new char[] { '@', '.', ',', '!' }) == -1) {
						// Stop editing without canceling the label change.
						e.Node.EndEdit(false);
						var fo = new IIFileOperation(this.Handle);
						fo.RenameItem((e.Node.Tag as IListItemEx)?.ComInterface, e.Label);
						fo.PerformOperations();
					} else {
						/* Cancel the label edit action, inform the user, and
							 place the node in edit mode again. */
						e.CancelEdit = true;
						MessageBox.Show("Invalid tree node label.\n The invalid characters are: '@','.', ',', '!'", "Node Label Edit");
						e.Node.BeginEdit();
					}
				} else {
					/* Cancel the label edit action, inform the user, and place the node in edit mode again. */
					e.CancelEdit = true;
					MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", "Node Label Edit");
					e.Node.BeginEdit();
				}
			}
		}
예제 #3
0
    private void Do_Copy_OR_Move_Helper_2(Boolean copy, IListItemEx destination, F.IDataObject dataObject) {
      IntPtr handle = this.Handle;
      IShellItemArray shellItemArray = null;
      IShellItem[] items = null;

      if (((F.DataObject)dataObject).ContainsFileDropList()) {
        items = ((F.DataObject)dataObject).GetFileDropList().OfType<String>().Select(s => ShellItem.ToShellParsingName(s).ComInterface).ToArray();
      } else {
        shellItemArray = dataObject.ToShellItemArray();
        items = shellItemArray.ToArray();
      }
      var thread = new Thread(() => {
        try {
          var fo = new IIFileOperation(handle);
          foreach (var item in items) {
            if (copy)
              fo.CopyItem(item, destination);
            else
              fo.MoveItem(item, destination, null);
          }

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

      thread.SetApartmentState(ApartmentState.STA);
      thread.Start();
    }
예제 #4
0
		/// <summary>
		/// Moves the selected items to the destination on a separate thread
		/// </summary>
		/// <param name="dataObject">Contains the items you want to moe</param>
		/// <param name="destination">The place you want to move the items to</param>
		private void DoMove(IDataObject dataObject, IListItemEx destination) {
			var handle = this.Handle;
			var thread = new Thread(() => {
				IShellItem[] items =
					dataObject.GetDataPresent("FileDrop") ?
					items = ((F.DataObject)dataObject).GetFileDropList().OfType<String>().Select(s => FileSystemListItem.ToFileSystemItem(IntPtr.Zero, s.ToShellParsingName()).ComInterface).ToArray()
					:
					dataObject.ToShellItemArray().ToArray();

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

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

			thread.SetApartmentState(ApartmentState.STA);
			thread.Start();
		}
예제 #5
0
    private void Do_Copy_OR_Move_Helper(Boolean copy, IListItemEx destination, IShellItem[] items) {
      var handle = this.Handle;
      var thread = new Thread(() => {
        var fo = new IIFileOperation(handle);
        foreach (var item in items) {
          if (copy)
            fo.CopyItem(item, destination);
          else
            fo.MoveItem(item, destination, null);
        }
        fo.PerformOperations();
      });

      thread.SetApartmentState(ApartmentState.STA);
      thread.Start();
    }
예제 #6
0
    /// <summary>
    /// Creates a new folder in the current directory and assigns a default name if none is specified. Returns the name
    /// </summary>
    /// <param name="name">The name of the new folder</param>
    /// <returns>Returns the name and assigns a default name if none is specified</returns>
    public String CreateNewFolder(String name) {
      if (String.IsNullOrEmpty(name)) {
        name = User32.LoadResourceString(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"), 30396, "New Folder");
      }

      var fo = new IIFileOperation(this.Handle, false);
      fo.NewItem(this.CurrentFolder, name, FileAttributes.Directory | FileAttributes.Normal);
      fo.PerformOperations();

      return name;
    }
예제 #7
0
 public void RenameShellItem(IShellItem item, String newName, Boolean isAddFileExtension, String extension = "") {
   var handle = this.Handle;
   var sink = new FOperationProgressSink(this);
   var fo = new IIFileOperation(sink, handle, false);
   fo.RenameItem(item, isAddFileExtension ? newName + extension : newName);
   fo.PerformOperations();
   if (fo.GetAnyOperationAborted()) {
     this._IsCanceledOperation = true;
   }
 }
예제 #8
0
    public void DeleteSelectedFiles(Boolean isRecycling) {
      var handle = this.Handle;
      var view = this;
      var thread = new Thread(() => {
        var sink = new FOperationProgressSink(view);
        var fo = new IIFileOperation(sink, handle, isRecycling);
        foreach (var item in this.SelectedItems) {
          fo.DeleteItem(item);
          this.BeginInvoke(new MethodInvoker(() => {
            this._IIListView.SetItemState(item.ItemIndex, LVIF.LVIF_STATE, LVIS.LVIS_SELECTED, 0);
          }));
        }

        fo.PerformOperations();
        if (isRecycling) {
          this.RaiseRecycleBinUpdated();
        }
      });
      thread.SetApartmentState(ApartmentState.STA);
      thread.Start();
    }
예제 #9
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);
    }