11
11
using Windows . ApplicationModel . DataTransfer . DragDrop ;
12
12
using Windows . Storage ;
13
13
using Windows . System ;
14
+ using Microsoft . UI . Xaml . Controls ;
14
15
15
16
namespace Files . App . ViewModels . Layouts
16
17
{
@@ -100,17 +101,22 @@ public async Task DragOverAsync(DragEventArgs e)
100
101
return ;
101
102
}
102
103
103
- if ( FilesystemHelpers . HasDraggedStorageItems ( e . DataView ) )
104
+ if ( ! FilesystemHelpers . HasDraggedStorageItems ( e . DataView ) )
104
105
{
105
- e . Handled = true ;
106
-
107
- var draggedItems = await FilesystemHelpers . GetDraggedStorageItems ( e . DataView ) ;
108
-
109
- var pwd = _associatedInstance . ShellViewModel . WorkingDirectory . TrimPath ( ) ;
110
- var folderName = Path . IsPathRooted ( pwd ) && Path . GetPathRoot ( pwd ) == pwd ? Path . GetPathRoot ( pwd ) : Path . GetFileName ( pwd ) ;
106
+ deferral . Complete ( ) ;
107
+ return ;
108
+ }
109
+
110
+ e . Handled = true ;
111
+ var draggedItems = await FilesystemHelpers . GetDraggedStorageItems ( e . DataView ) ;
112
+ var pwd = _associatedInstance . ShellViewModel . WorkingDirectory . TrimPath ( ) ;
113
+ var folderName = Path . IsPathRooted ( pwd ) && Path . GetPathRoot ( pwd ) == pwd ? Path . GetPathRoot ( pwd ) : Path . GetFileName ( pwd ) ;
111
114
115
+ try
116
+ {
112
117
// As long as one file doesn't already belong to this folder
113
- if ( _associatedInstance . InstanceViewModel . IsPageTypeSearchResults || draggedItems . Any ( ) && draggedItems . AreItemsAlreadyInFolder ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
118
+ if ( _associatedInstance . InstanceViewModel . IsPageTypeSearchResults || draggedItems . Any ( ) &&
119
+ draggedItems . AreItemsAlreadyInFolder ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
114
120
{
115
121
e . AcceptedOperation = DataPackageOperation . None ;
116
122
}
@@ -120,80 +126,106 @@ public async Task DragOverAsync(DragEventArgs e)
120
126
}
121
127
else
122
128
{
123
- try
129
+ e . DragUIOverride . IsCaptionVisible = true ;
130
+ if ( e . DataView . Properties . TryGetValue ( "Files_ActionBinder" , out var actionBinder ) && actionBinder is "Files_ShelfBinder" )
124
131
{
125
- e . DragUIOverride . IsCaptionVisible = true ;
126
- if ( pwd . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) )
127
- {
128
- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
129
- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
130
- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
131
- }
132
- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Alt ) || e . Modifiers . HasFlag ( DragDropModifiers . Control | DragDropModifiers . Shift ) )
133
- {
134
- e . DragUIOverride . Caption = string . Format ( "LinkToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
135
- e . AcceptedOperation = DataPackageOperation . Link ;
136
- }
137
- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Control ) )
138
- {
139
- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
140
- e . AcceptedOperation = DataPackageOperation . Copy ;
141
- }
142
- else if ( e . Modifiers . HasFlag ( DragDropModifiers . Shift ) )
143
- {
144
- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
145
- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
146
- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
147
- }
148
- else if ( draggedItems . Any ( x =>
149
- x . Item is ZipStorageFile ||
150
- x . Item is ZipStorageFolder ) ||
151
- ZipStorageFolder . IsZipPath ( pwd ) )
152
- {
153
- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
154
- e . AcceptedOperation = DataPackageOperation . Copy ;
155
- }
156
- else if ( draggedItems . AreItemsInSameDrive ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
157
- {
158
- e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
159
- // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
160
- e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
161
- }
162
- else
163
- {
164
- e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
165
- e . AcceptedOperation = DataPackageOperation . Copy ;
166
- }
132
+ e . DragUIOverride . Caption = string . Format ( "LinkToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
133
+ e . AcceptedOperation = DataPackageOperation . Link ;
134
+ }
135
+ else if ( pwd . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) )
136
+ {
137
+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
167
138
168
- _itemManipulationModel . ClearSelection ( ) ;
139
+ // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
140
+ e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
169
141
}
170
- catch ( COMException ex ) when ( ex . Message . Contains ( "RPC server is unavailable" ) )
142
+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Alt ) || e . Modifiers . HasFlag ( DragDropModifiers . Control | DragDropModifiers . Shift ) )
171
143
{
172
- Logger ? . LogDebug ( ex , ex . Message ) ;
144
+ e . DragUIOverride . Caption = string . Format ( "LinkToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
145
+ e . AcceptedOperation = DataPackageOperation . Link ;
173
146
}
147
+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Control ) )
148
+ {
149
+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
150
+ e . AcceptedOperation = DataPackageOperation . Copy ;
151
+ }
152
+ else if ( e . Modifiers . HasFlag ( DragDropModifiers . Shift ) )
153
+ {
154
+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
155
+
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 if ( draggedItems . Any ( x =>
160
+ x . Item is ZipStorageFile ||
161
+ x . Item is ZipStorageFolder ) ||
162
+ ZipStorageFolder . IsZipPath ( pwd ) )
163
+ {
164
+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
165
+ e . AcceptedOperation = DataPackageOperation . Copy ;
166
+ }
167
+ else if ( draggedItems . AreItemsInSameDrive ( _associatedInstance . ShellViewModel . WorkingDirectory ) )
168
+ {
169
+ e . DragUIOverride . Caption = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
170
+
171
+ // Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
172
+ e . AcceptedOperation = DataPackageOperation . Move | DataPackageOperation . Copy ;
173
+ }
174
+ else
175
+ {
176
+ e . DragUIOverride . Caption = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) ;
177
+ e . AcceptedOperation = DataPackageOperation . Copy ;
178
+ }
179
+
180
+ _itemManipulationModel . ClearSelection ( ) ;
174
181
}
175
182
}
176
-
177
- deferral . Complete ( ) ;
183
+ catch ( COMException ex ) when ( ex . Message . Contains ( "RPC server is unavailable" ) )
184
+ {
185
+ Logger ? . LogDebug ( ex , ex . Message ) ;
186
+ }
187
+ finally
188
+ {
189
+ deferral . Complete ( ) ;
190
+ }
178
191
}
179
192
180
193
public async Task DropAsync ( DragEventArgs e )
181
194
{
182
195
e . Handled = true ;
196
+ var deferral = e . GetDeferral ( ) ;
183
197
184
- if ( FilesystemHelpers . HasDraggedStorageItems ( e . DataView ) )
198
+ try
185
199
{
186
- var deferral = e . GetDeferral ( ) ;
200
+ if ( ! FilesystemHelpers . HasDraggedStorageItems ( e . DataView ) )
201
+ return ;
187
202
188
- try
189
- {
190
- await _associatedInstance . FilesystemHelpers . PerformOperationTypeAsync ( e . AcceptedOperation , e . DataView , _associatedInstance . ShellViewModel . WorkingDirectory , false , true ) ;
191
- await _associatedInstance . RefreshIfNoWatcherExistsAsync ( ) ;
192
- }
193
- finally
203
+ if ( e . DataView . Properties . TryGetValue ( "Files_ActionBinder" , out var actionBinder ) && actionBinder is "Files_ShelfBinder" )
194
204
{
195
- deferral . Complete ( ) ;
205
+ if ( e . OriginalSource is not UIElement uiElement )
206
+ return ;
207
+
208
+ var pwd = _associatedInstance . ShellViewModel . WorkingDirectory . TrimPath ( ) ;
209
+ var folderName = Path . IsPathRooted ( pwd ) && Path . GetPathRoot ( pwd ) == pwd ? Path . GetPathRoot ( pwd ) : Path . GetFileName ( pwd ) ;
210
+ var menuFlyout = new MenuFlyout ( )
211
+ {
212
+ Items =
213
+ {
214
+ new MenuFlyoutItem ( ) { Text = string . Format ( "CopyToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) } ,
215
+ new MenuFlyoutItem ( ) { Text = string . Format ( "MoveToFolderCaptionText" . GetLocalizedResource ( ) , folderName ) } ,
216
+ }
217
+ } ;
218
+
219
+ menuFlyout . ShowAt ( uiElement , e . GetPosition ( uiElement ) ) ;
220
+ return ;
196
221
}
222
+
223
+ await _associatedInstance . FilesystemHelpers . PerformOperationTypeAsync ( e . AcceptedOperation , e . DataView , _associatedInstance . ShellViewModel . WorkingDirectory , false , true ) ;
224
+ await _associatedInstance . RefreshIfNoWatcherExistsAsync ( ) ;
225
+ }
226
+ finally
227
+ {
228
+ deferral . Complete ( ) ;
197
229
}
198
230
}
199
231
0 commit comments