Skip to content

Commit

Permalink
- Added threading to fileoperations
Browse files Browse the repository at this point in the history
- Added owner to  fileoperation dialogs
- UI fixes for SizeChart window
- other small fixes
  • Loading branch information
DimitarCC committed Apr 11, 2014
1 parent 5f96b71 commit 61e6cbd
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 93 deletions.
2 changes: 1 addition & 1 deletion BExplorer/BetterExplorer/MainWindow.xaml.cs
Expand Up @@ -5430,7 +5430,7 @@ void misng_Click(object sender, RoutedEventArgs e)

private void inRibbonGallery1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (IsViewSelection)
//if (IsViewSelection)
{
switch (ViewGallery.SelectedIndex)
{
Expand Down
Expand Up @@ -84,7 +84,7 @@ private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
Pie.Height = this.ActualHeight;
legend1.Margin = new Thickness(0);
legend1.Height = this.ActualHeight - 40;
legend1.Width = 245;
legend1.Width = 238;
}
}
}
8 changes: 5 additions & 3 deletions Shell/FileOperation/IIFileOperation.cs
Expand Up @@ -18,9 +18,11 @@ public class IIFileOperation : IDisposable
private uint _sinkCookie;

public IIFileOperation() : this(null, false) { }
public IIFileOperation(IntPtr owner, Boolean isRecycle) : this(null, owner, isRecycle) { }
public IIFileOperation(IntPtr owner) : this(null, owner, false) { }
public IIFileOperation(Boolean isRecycle) : this(null, isRecycle) { }
public IIFileOperation(FileOperationProgressSink callbackSink, Boolean isRecycle) : this(callbackSink, null, isRecycle) { }
public IIFileOperation(FileOperationProgressSink callbackSink, IWin32Window owner, Boolean isRecycle)
public IIFileOperation(FileOperationProgressSink callbackSink, Boolean isRecycle) : this(callbackSink, IntPtr.Zero, isRecycle) { }
public IIFileOperation(FileOperationProgressSink callbackSink, IntPtr owner, Boolean isRecycle)
{
_callbackSink = callbackSink;
_fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);
Expand All @@ -30,7 +32,7 @@ public IIFileOperation(FileOperationProgressSink callbackSink, IWin32Window owne
else
_fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
if (_callbackSink != null) _sinkCookie = _fileOperation.Advise(_callbackSink);
if (owner != null) _fileOperation.SetOwnerWindow((uint)owner.Handle);
if (owner != IntPtr.Zero) _fileOperation.SetOwnerWindow((uint)owner);
}


Expand Down
230 changes: 142 additions & 88 deletions Shell/ShellViewEx.cs
Expand Up @@ -1872,140 +1872,194 @@ public void CopySelectedFiles()

public void PasteAvailableFiles()
{
var dataObject = System.Windows.Forms.Clipboard.GetDataObject();
var dragDropEffect = System.Windows.DragDropEffects.Copy;
var dropEffect = dataObject.ToDropEffect();
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in items)
var handle = this.Handle;
var thread = new Thread(() =>
{
var dataObject = System.Windows.Forms.Clipboard.GetDataObject();
var dragDropEffect = System.Windows.DragDropEffects.Copy;
var dropEffect = dataObject.ToDropEffect();
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
if (dropEffect == System.Windows.DragDropEffects.Copy)
{
fo.CopyItem(item, this.CurrentFolder.m_ComInterface, String.Empty);
}
else
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in items)
{
fo.MoveItem(item, this.CurrentFolder.m_ComInterface, null);
if (dropEffect == System.Windows.DragDropEffects.Copy)
{
fo.CopyItem(item, this.CurrentFolder.m_ComInterface, String.Empty);
}
else
{
fo.MoveItem(item, this.CurrentFolder.m_ComInterface, null);
}
}
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}

public void DoCopy(ShellItem destination)
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
var handle = this.Handle;
var thread = new Thread(() =>
{
fo.CopyItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
{
fo.CopyItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
public void DoCopy(System.Windows.Forms.IDataObject dataObject, ShellItem destination)
{
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
var handle = this.Handle;
var thread = new Thread(() =>
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in items)
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in items)
{
fo.CopyItem(item, destination.m_ComInterface, String.Empty);
}
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}

public void DoCopy(System.Windows.IDataObject dataObject, ShellItem destination)
{
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
var handle = this.Handle;
var thread = new Thread(() =>
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in items)
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
fo.CopyItem(item, destination.m_ComInterface, String.Empty);
}
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in items)
{
fo.CopyItem(item, destination.m_ComInterface, String.Empty);
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
public void DoMove(System.Windows.Forms.IDataObject dataObject, ShellItem destination)
{
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
var handle = this.Handle;
var thread = new Thread(() =>
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in items)
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in items)
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}

public void DoMove(System.Windows.IDataObject dataObject, ShellItem destination)
{
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
var handle = this.Handle;
var thread = new Thread(() =>
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in items)
var shellItemArray = dataObject.ToShellItemArray();
var items = shellItemArray.ToArray();
try
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in items)
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
fo.PerformOperations();
}
catch (SecurityException)
{
throw;
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}

public void DoMove(ShellItem destination)
{
IIFileOperation fo = new IIFileOperation();
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
var handle = this.Handle;
var thread = new Thread(() =>
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
IIFileOperation fo = new IIFileOperation(handle);
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
{
fo.MoveItem(item, destination.m_ComInterface, null);
}
fo.PerformOperations();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}

public void DeleteSelectedFiles(Boolean isRecycling)
{
IIFileOperation fo = new IIFileOperation(isRecycling);
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
var handle = this.Handle;
var thread = new Thread(() =>
{
fo.DeleteItem(item);
}
fo.PerformOperations();
IIFileOperation fo = new IIFileOperation(handle, isRecycling);
foreach (var item in this.SelectedItems.Select(s => s.m_ComInterface).ToArray())
{
fo.DeleteItem(item);
}
fo.PerformOperations();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}
public void RenameShellItem(IShellItem item, String newName){
IIFileOperation fo = new IIFileOperation(true);
Expand Down

0 comments on commit 61e6cbd

Please sign in to comment.