1
1
// Copyright (c) 2024 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
+ using Microsoft . Extensions . Logging ;
4
5
using Microsoft . UI . Xaml ;
5
6
using Microsoft . UI . Xaml . Input ;
6
7
using System . IO ;
8
+ using System . Runtime . InteropServices ;
7
9
using System . Windows . Input ;
8
10
using Windows . ApplicationModel . DataTransfer ;
9
11
using Windows . ApplicationModel . DataTransfer . DragDrop ;
@@ -18,6 +20,7 @@ namespace Files.App.ViewModels.Layouts
18
20
public sealed class BaseLayoutViewModel : IDisposable
19
21
{
20
22
protected ICommandManager Commands { get ; } = Ioc . Default . GetRequiredService < ICommandManager > ( ) ;
23
+ private ILogger ? Logger { get ; } = Ioc . Default . GetRequiredService < ILogger < App > > ( ) ;
21
24
22
25
private readonly IShellPage _associatedInstance ;
23
26
@@ -119,47 +122,54 @@ public async Task DragOverAsync(DragEventArgs e)
119
122
}
120
123
else
121
124
{
122
- e . DragUIOverride . IsCaptionVisible = true ;
123
- if ( pwd . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) )
125
+ try
124
126
{
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
+ }
128
169
}
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" ) )
130
171
{
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 ) ;
163
173
}
164
174
}
165
175
}
0 commit comments