Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve drag&drop #5273

Merged
merged 9 commits into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 0 additions & 161 deletions Files.Launcher/DragDropForm.cs

This file was deleted.

4 changes: 1 addition & 3 deletions Files.Launcher/Files.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DeviceWatcher.cs" />
<Compile Include="DragDropForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="LogWriter.cs" />
<Compile Include="FilePermissions.cs" />
<Compile Include="NetworkDrivesAPI.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QuickLook.cs" />
<Compile Include="RemoteDataObject.cs" />
<Compile Include="Win32API.cs" />
<Compile Include="Win32API_ContextMenu.cs" />
</ItemGroup>
Expand Down
51 changes: 37 additions & 14 deletions Files.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ private static void Main(string[] args)
librariesWatcher.Renamed += (object _, RenamedEventArgs e) => OnLibraryChanged(e.ChangeType, e.OldFullPath, e.FullPath);
librariesWatcher.EnableRaisingEvents = true;

// Create cancellation token for drop window
cancellation = new CancellationTokenSource();

// Connect to app service and wait until the connection gets closed
appServiceExit = new ManualResetEvent(false);
InitializeAppServiceConnection();
Expand All @@ -116,8 +113,6 @@ private static void Main(string[] args)
handleTable?.Dispose();
deviceWatcher?.Dispose();
librariesWatcher?.Dispose();
cancellation?.Cancel();
cancellation?.Dispose();
appServiceExit?.Dispose();
}
}
Expand Down Expand Up @@ -157,7 +152,6 @@ private static async void RecycleBinWatcher_Changed(object sender, FileSystemEve

private static NamedPipeServerStream connection;
private static ManualResetEvent appServiceExit;
private static CancellationTokenSource cancellation;
private static Win32API.DisposableDictionary handleTable;
private static IList<FileSystemWatcher> binWatchers;
private static DeviceWatcher deviceWatcher;
Expand Down Expand Up @@ -872,17 +866,46 @@ await Win32API.StartSTATask(() =>
break;

case "DragDrop":
cancellation.Cancel();
cancellation.Dispose();
cancellation = new CancellationTokenSource();
var dropPath = (string)message["droppath"];
var dropText = (string)message["droptext"];
var drops = Win32API.StartSTATask<List<string>>(() =>
var result2 = await Win32API.StartSTATask(() =>
{
var form = new DragDropForm(dropPath, dropText, cancellation.Token);
System.Windows.Forms.Application.Run(form);
return form.DropTargets;
var rdo = new RemoteDataObject(System.Windows.Forms.Clipboard.GetDataObject());

foreach (RemoteDataObject.DataPackage package in rdo.GetRemoteData())
{
try
{
if (package.ItemType == RemoteDataObject.StorageType.File)
{
string directoryPath = Path.GetDirectoryName(dropPath);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

string uniqueName = Win32API.GenerateUniquePath(Path.Combine(dropPath, package.Name));
using (FileStream stream = new FileStream(uniqueName, FileMode.CreateNew))
{
package.ContentStream.CopyTo(stream);
}
}
else
{
string directoryPath = Path.Combine(dropPath, package.Name);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
}
}
finally
{
package.Dispose();
}
}
return true;
});
await Win32API.SendMessageAsync(connection, new ValueSet() { { "Success", result2 } }, message.Get("RequestID", (string)null));
break;

case "DeleteItem":
Expand Down
Loading