Skip to content

Commit 956f133

Browse files
authored
Improve drag&drop (#5273)
1 parent 811fdc5 commit 956f133

26 files changed

+617
-330
lines changed

Files.Launcher/DragDropForm.cs

Lines changed: 0 additions & 161 deletions
This file was deleted.

Files.Launcher/Files.Launcher.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,13 @@
126126
</ItemGroup>
127127
<ItemGroup>
128128
<Compile Include="DeviceWatcher.cs" />
129-
<Compile Include="DragDropForm.cs">
130-
<SubType>Form</SubType>
131-
</Compile>
132129
<Compile Include="LogWriter.cs" />
133130
<Compile Include="FilePermissions.cs" />
134131
<Compile Include="NetworkDrivesAPI.cs" />
135132
<Compile Include="Program.cs" />
136133
<Compile Include="Properties\AssemblyInfo.cs" />
137134
<Compile Include="QuickLook.cs" />
135+
<Compile Include="RemoteDataObject.cs" />
138136
<Compile Include="Win32API.cs" />
139137
<Compile Include="Win32API_ContextMenu.cs" />
140138
</ItemGroup>

Files.Launcher/Program.cs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ private static void Main(string[] args)
8787
librariesWatcher.Renamed += (object _, RenamedEventArgs e) => OnLibraryChanged(e.ChangeType, e.OldFullPath, e.FullPath);
8888
librariesWatcher.EnableRaisingEvents = true;
8989

90-
// Create cancellation token for drop window
91-
cancellation = new CancellationTokenSource();
92-
9390
// Connect to app service and wait until the connection gets closed
9491
appServiceExit = new ManualResetEvent(false);
9592
InitializeAppServiceConnection();
@@ -116,8 +113,6 @@ private static void Main(string[] args)
116113
handleTable?.Dispose();
117114
deviceWatcher?.Dispose();
118115
librariesWatcher?.Dispose();
119-
cancellation?.Cancel();
120-
cancellation?.Dispose();
121116
appServiceExit?.Dispose();
122117
}
123118
}
@@ -157,7 +152,6 @@ private static async void RecycleBinWatcher_Changed(object sender, FileSystemEve
157152

158153
private static NamedPipeServerStream connection;
159154
private static ManualResetEvent appServiceExit;
160-
private static CancellationTokenSource cancellation;
161155
private static Win32API.DisposableDictionary handleTable;
162156
private static IList<FileSystemWatcher> binWatchers;
163157
private static DeviceWatcher deviceWatcher;
@@ -872,17 +866,46 @@ await Win32API.StartSTATask(() =>
872866
break;
873867

874868
case "DragDrop":
875-
cancellation.Cancel();
876-
cancellation.Dispose();
877-
cancellation = new CancellationTokenSource();
878869
var dropPath = (string)message["droppath"];
879-
var dropText = (string)message["droptext"];
880-
var drops = Win32API.StartSTATask<List<string>>(() =>
870+
var result2 = await Win32API.StartSTATask(() =>
881871
{
882-
var form = new DragDropForm(dropPath, dropText, cancellation.Token);
883-
System.Windows.Forms.Application.Run(form);
884-
return form.DropTargets;
872+
var rdo = new RemoteDataObject(System.Windows.Forms.Clipboard.GetDataObject());
873+
874+
foreach (RemoteDataObject.DataPackage package in rdo.GetRemoteData())
875+
{
876+
try
877+
{
878+
if (package.ItemType == RemoteDataObject.StorageType.File)
879+
{
880+
string directoryPath = Path.GetDirectoryName(dropPath);
881+
if (!Directory.Exists(directoryPath))
882+
{
883+
Directory.CreateDirectory(directoryPath);
884+
}
885+
886+
string uniqueName = Win32API.GenerateUniquePath(Path.Combine(dropPath, package.Name));
887+
using (FileStream stream = new FileStream(uniqueName, FileMode.CreateNew))
888+
{
889+
package.ContentStream.CopyTo(stream);
890+
}
891+
}
892+
else
893+
{
894+
string directoryPath = Path.Combine(dropPath, package.Name);
895+
if (!Directory.Exists(directoryPath))
896+
{
897+
Directory.CreateDirectory(directoryPath);
898+
}
899+
}
900+
}
901+
finally
902+
{
903+
package.Dispose();
904+
}
905+
}
906+
return true;
885907
});
908+
await Win32API.SendMessageAsync(connection, new ValueSet() { { "Success", result2 } }, message.Get("RequestID", (string)null));
886909
break;
887910

888911
case "DeleteItem":

0 commit comments

Comments
 (0)