11// Copyright (c) 2024 Files Community
22// Licensed under the MIT License. See the LICENSE.
33
4+ using Microsoft . Extensions . Logging ;
45using Microsoft . UI . Xaml ;
56using Microsoft . UI . Xaml . Input ;
67using System . IO ;
8+ using System . Runtime . InteropServices ;
79using System . Windows . Input ;
810using Windows . ApplicationModel . DataTransfer ;
911using Windows . ApplicationModel . DataTransfer . DragDrop ;
@@ -18,6 +20,7 @@ namespace Files.App.ViewModels.Layouts
1820 public sealed class BaseLayoutViewModel : IDisposable
1921 {
2022 protected ICommandManager Commands { get ; } = Ioc . Default . GetRequiredService < ICommandManager > ( ) ;
23+ private ILogger ? Logger { get ; } = Ioc . Default . GetRequiredService < ILogger < App > > ( ) ;
2124
2225 private readonly IShellPage _associatedInstance ;
2326
@@ -119,47 +122,54 @@ public async Task DragOverAsync(DragEventArgs e)
119122 }
120123 else
121124 {
122- e . DragUIOverride . IsCaptionVisible = true ;
123- if ( pwd . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) )
125+ try
124126 {
125- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
126- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
127- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
127+ e . DragUIOverride . IsCaptionVisible = true ;
128+ if ( pwd . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) )
129+ {
130+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
131+ // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
132+ e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
133+ }
134+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Alt ) || e . Modifiers . HasFlag ( DragDropModifiers . Control | DragDropModifiers . Shift ) )
135+ {
136+ e . DragUIOverride . Caption = string . Format ( "LinkToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
137+ e . AcceptedOperation = DataPackageOperation . Link ;
138+ }
139+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Control ) )
140+ {
141+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
142+ e . AcceptedOperation = DataPackageOperation . Copy ;
143+ }
144+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Shift ) )
145+ {
146+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
147+ // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
148+ e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
149+ }
150+ else if ( draggedItems . Any ( x =>
151+ x . Item is ZipStorageFile ||
152+ x . Item is ZipStorageFolder ) ||
153+ ZipStorageFolder . IsZipPath ( pwd ) )
154+ {
155+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
156+ e . AcceptedOperation = DataPackageOperation . Copy ;
157+ }
158+ else if ( draggedItems . AreItemsInSameDrive ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
159+ {
160+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
161+ // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
162+ e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
163+ }
164+ else
165+ {
166+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
167+ e . AcceptedOperation = DataPackageOperation . Copy ;
168+ }
128169 }
129- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Alt ) || e . Modifiers . HasFlag ( DragDropModifiers . Control | DragDropModifiers . Shift ) )
170+ catch ( COMException ex ) when ( ex . Message . Contains ( "RPC server is unavailable" ) )
130171 {
131- e . DragUIOverride . Caption = string . Format ( "LinkToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
132- e . AcceptedOperation = DataPackageOperation . Link ;
133- }
134- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Control ) )
135- {
136- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
137- e . AcceptedOperation = DataPackageOperation . Copy ;
138- }
139- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Shift ) )
140- {
141- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
142- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
143- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
144- }
145- else if ( draggedItems . Any ( x =>
146- x . Item is ZipStorageFile ||
147- x . Item is ZipStorageFolder ) ||
148- ZipStorageFolder . IsZipPath ( pwd ) )
149- {
150- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
151- e . AcceptedOperation = DataPackageOperation . Copy ;
152- }
153- else if ( draggedItems . AreItemsInSameDrive ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
154- {
155- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
156- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
157- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
158- }
159- else
160- {
161- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
162- e . AcceptedOperation = DataPackageOperation . Copy ;
172+ Logger ? . LogDebug ( ex , ex . Message ) ;
163173 }
164174 }
165175 }
0 commit comments