Skip to content

Commit 083309a

Browse files
committed
Switch to dragover, [WIP] remove ftp drop
1 parent 2596f9f commit 083309a

16 files changed

+39
-253
lines changed

Files.Launcher/DragDropForm.cs

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

Files.Launcher/Files.Launcher.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@
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" />

Files.Launcher/Program.cs

Lines changed: 2 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,16 +866,10 @@ 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+
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+
return false;
885873
});
886874
break;
887875

Files.Launcher/Win32API.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static Task<T> StartSTATask<T>(Func<T> func)
2727
var tcs = new TaskCompletionSource<T>();
2828
Thread thread = new Thread(() =>
2929
{
30+
Ole32.OleInitialize();
3031
try
3132
{
3233
tcs.SetResult(func());
@@ -37,7 +38,15 @@ public static Task<T> StartSTATask<T>(Func<T> func)
3738
Program.Logger.Info(ex, ex.Message);
3839
//tcs.SetException(e);
3940
}
40-
});
41+
finally
42+
{
43+
Ole32.OleUninitialize();
44+
}
45+
})
46+
{
47+
IsBackground = true,
48+
Priority = ThreadPriority.Normal
49+
};
4150
thread.SetApartmentState(ApartmentState.STA);
4251
thread.Start();
4352
return tcs.Task;

Files/BaseLayout.cs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -528,47 +528,6 @@ protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceiv
528528
}
529529
}
530530

531-
private async void Item_DragStarting(object sender, DragStartingEventArgs e)
532-
{
533-
List<IStorageItem> selectedStorageItems = new List<IStorageItem>();
534-
535-
if (sender is DataGridRow dataGridRow)
536-
{
537-
if (dataGridRow.DataContext is ListedItem item)
538-
{
539-
ParentShellPageInstance.SlimContentPage.SelectedItems.Add(item);
540-
}
541-
}
542-
543-
foreach (ListedItem item in ParentShellPageInstance.SlimContentPage.SelectedItems)
544-
{
545-
if (item is ShortcutItem)
546-
{
547-
// Can't drag shortcut items
548-
continue;
549-
}
550-
else if (item.PrimaryItemAttribute == StorageItemTypes.File)
551-
{
552-
await ParentShellPageInstance.FilesystemViewModel.GetFileFromPathAsync(item.ItemPath)
553-
.OnSuccess(t => selectedStorageItems.Add(t));
554-
}
555-
else if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
556-
{
557-
await ParentShellPageInstance.FilesystemViewModel.GetFolderFromPathAsync(item.ItemPath)
558-
.OnSuccess(t => selectedStorageItems.Add(t));
559-
}
560-
}
561-
562-
if (selectedStorageItems.Count == 0)
563-
{
564-
e.Cancel = true;
565-
return;
566-
}
567-
568-
e.Data.SetStorageItems(selectedStorageItems, false);
569-
e.DragUI.SetContentFromDataPackage();
570-
}
571-
572531
protected async void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
573532
{
574533
List<IStorageItem> selectedStorageItems = new List<IStorageItem>();
@@ -713,7 +672,6 @@ protected void InitializeDrag(UIElement element)
713672
if (item != null)
714673
{
715674
element.AllowDrop = false;
716-
element.DragStarting -= Item_DragStarting;
717675
element.DragOver -= Item_DragOver;
718676
element.DragLeave -= Item_DragLeave;
719677
element.Drop -= Item_Drop;
@@ -730,7 +688,6 @@ protected void InitializeDrag(UIElement element)
730688
protected void UninitializeDrag(UIElement element)
731689
{
732690
element.AllowDrop = false;
733-
element.DragStarting -= Item_DragStarting;
734691
element.DragOver -= Item_DragOver;
735692
element.DragLeave -= Item_DragLeave;
736693
element.Drop -= Item_Drop;
@@ -743,9 +700,9 @@ protected void UninitializeDrag(UIElement element)
743700

744701
public abstract void Dispose();
745702

746-
protected void ItemsLayout_DragEnter(object sender, DragEventArgs e)
703+
protected void ItemsLayout_DragOver(object sender, DragEventArgs e)
747704
{
748-
CommandsViewModel?.DragEnterCommand?.Execute(e);
705+
CommandsViewModel?.DragOverCommand?.Execute(e);
749706
}
750707

751708
protected void ItemsLayout_Drop(object sender, DragEventArgs e)

Files/Filesystem/FilesystemOperations/FilesystemOperations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ await DialogDisplayHelper.ShowDialogAsync(
264264
}
265265
}
266266

267-
if (Path.GetDirectoryName(destination) == associatedInstance.FilesystemViewModel.WorkingDirectory)
267+
if (Path.GetDirectoryName(destination) == associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath())
268268
{
269269
await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
270270
{
@@ -469,7 +469,7 @@ await DialogDisplayHelper.ShowDialogAsync(
469469
errorCode?.Report(fsResult.ErrorCode);
470470
}
471471

472-
if (Path.GetDirectoryName(destination) == associatedInstance.FilesystemViewModel.WorkingDirectory)
472+
if (Path.GetDirectoryName(destination) == associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath())
473473
{
474474
await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
475475
{

Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.Common;
22
using Files.DataModels.NavigationControlItems;
33
using Files.Extensions;
4+
using Files.Helpers;
45
using Files.UserControls;
56
using Files.ViewModels;
67
using Files.Views;
@@ -257,9 +258,9 @@ public static bool AreItemsInSameDrive(this IEnumerable<IStorageItem> storageIte
257258
try
258259
{
259260
return storageItems.Any(storageItem =>
260-
Path.GetPathRoot(storageItem.Path).Equals(
261-
Path.GetPathRoot(destinationPath),
262-
StringComparison.OrdinalIgnoreCase));
261+
Path.GetPathRoot(storageItem.Path).Equals(
262+
Path.GetPathRoot(destinationPath),
263+
StringComparison.OrdinalIgnoreCase));
263264
}
264265
catch
265266
{
@@ -272,8 +273,8 @@ public static bool AreItemsAlreadyInFolder(this IEnumerable<IStorageItem> storag
272273
try
273274
{
274275
return storageItems.All(storageItem =>
275-
Directory.GetParent(storageItem.Path).FullName.Equals(
276-
destinationPath, StringComparison.OrdinalIgnoreCase));
276+
Path.GetDirectoryName(storageItem.Path).Equals(
277+
destinationPath.TrimPath(), StringComparison.OrdinalIgnoreCase));
277278
}
278279
catch
279280
{

Files/Helpers/PathNormalization.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Files.Helpers
55
{
6-
public class PathNormalization
6+
public static class PathNormalization
77
{
88
public static string GetPathRoot(string path)
99
{
@@ -61,6 +61,11 @@ public static string NormalizePath(string path)
6161
}
6262
}
6363

64+
public static string TrimPath(this string path)
65+
{
66+
return path?.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
67+
}
68+
6469
public static string GetParentDir(string path)
6570
{
6671
if (string.IsNullOrEmpty(path))

0 commit comments

Comments
 (0)