11using Files . Common ;
22using Files . Dialogs ;
33using Files . Enums ;
4+ using Files . Extensions ;
45using Files . Filesystem ;
56using Files . Filesystem . StorageItems ;
67using Files . Interacts ;
8+ using Files . ViewModels ;
79using Microsoft . Toolkit . Uwp ;
810using System ;
911using System . Collections . Concurrent ;
1012using System . IO ;
1113using System . Linq ;
14+ using System . Threading ;
1215using System . Threading . Tasks ;
1316using Windows . ApplicationModel . AppService ;
17+ using Windows . ApplicationModel . Core ;
1418using Windows . ApplicationModel . DataTransfer ;
1519using Windows . Foundation . Collections ;
1620using Windows . Storage ;
@@ -32,17 +36,32 @@ public static async void CutItem(IShellPage associatedInstance)
3236 // First, reset DataGrid Rows that may be in "cut" command mode
3337 associatedInstance . SlimContentPage . ItemManipulationModel . RefreshItemsOpacity ( ) ;
3438
39+ var itemsCount = associatedInstance . SlimContentPage . SelectedItems . Count ;
40+ PostedStatusBanner banner = itemsCount > 50 ? App . OngoingTasksViewModel . PostOperationBanner (
41+ string . Empty ,
42+ string . Format ( "StatusPreparingItemsDetails_Plural" . GetLocalized ( ) , itemsCount ) ,
43+ 0 ,
44+ ReturnResult . InProgress ,
45+ FileOperationType . Prepare , new CancellationTokenSource ( ) ) : null ;
46+
3547 try
3648 {
37- await Task . WhenAll ( associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . Select ( async listedItem =>
49+ await associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . ParallelForEach ( async listedItem =>
3850 {
51+ if ( banner != null )
52+ {
53+ ( ( IProgress < float > ) banner . Progress ) . Report ( items . Count / ( float ) itemsCount * 100 ) ;
54+ }
55+
3956 // FTP don't support cut, fallback to copy
4057 if ( listedItem is not FtpItem )
4158 {
42- // Dim opacities accordingly
43- listedItem . Opacity = Constants . UI . DimItemOpacity ;
59+ _ = CoreApplication . MainView . DispatcherQueue . TryEnqueue ( Windows . System . DispatcherQueuePriority . Low , ( ) =>
60+ {
61+ // Dim opacities accordingly
62+ listedItem . Opacity = Constants . UI . DimItemOpacity ;
63+ } ) ;
4464 }
45-
4665 if ( listedItem is FtpItem ftpItem )
4766 {
4867 if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
@@ -72,7 +91,7 @@ await Task.WhenAll(associatedInstance.SlimContentPage.SelectedItems.ToList().Sel
7291 throw new IOException ( $ "Failed to process { listedItem . ItemPath } .", ( int ) result . ErrorCode ) ;
7392 }
7493 }
75- } ) ) ;
94+ } , 10 , banner ? . CancellationToken ?? default ) ;
7695 }
7796 catch ( Exception ex )
7897 {
@@ -92,13 +111,17 @@ await Task.WhenAll(associatedInstance.SlimContentPage.SelectedItems.ToList().Sel
92111 } ) ;
93112 if ( status == AppServiceResponseStatus . Success )
94113 {
114+ banner ? . Remove ( ) ;
95115 return ;
96116 }
97117 }
98118 }
99119 associatedInstance . SlimContentPage . ItemManipulationModel . RefreshItemsOpacity ( ) ;
120+ banner ? . Remove ( ) ;
100121 return ;
101122 }
123+
124+ banner ? . Remove ( ) ;
102125 }
103126
104127 var onlyStandard = items . All ( x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder ) ;
@@ -130,14 +153,25 @@ public static async Task CopyItem(IShellPage associatedInstance)
130153 } ;
131154 ConcurrentBag < IStorageItem > items = new ConcurrentBag < IStorageItem > ( ) ;
132155
133- string copySourcePath = associatedInstance . FilesystemViewModel . WorkingDirectory ;
134-
135156 if ( associatedInstance . SlimContentPage . IsItemSelected )
136157 {
158+ var itemsCount = associatedInstance . SlimContentPage . SelectedItems . Count ;
159+ PostedStatusBanner banner = itemsCount > 50 ? App . OngoingTasksViewModel . PostOperationBanner (
160+ string . Empty ,
161+ string . Format ( "StatusPreparingItemsDetails_Plural" . GetLocalized ( ) , itemsCount ) ,
162+ 0 ,
163+ ReturnResult . InProgress ,
164+ FileOperationType . Prepare , new CancellationTokenSource ( ) ) : null ;
165+
137166 try
138167 {
139- await Task . WhenAll ( associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . Select ( async listedItem =>
168+ await associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . ParallelForEach ( async listedItem =>
140169 {
170+ if ( banner != null )
171+ {
172+ ( ( IProgress < float > ) banner . Progress ) . Report ( items . Count / ( float ) itemsCount * 100 ) ;
173+ }
174+
141175 if ( listedItem is FtpItem ftpItem )
142176 {
143177 if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
@@ -167,7 +201,7 @@ await Task.WhenAll(associatedInstance.SlimContentPage.SelectedItems.ToList().Sel
167201 throw new IOException ( $ "Failed to process { listedItem . ItemPath } .", ( int ) result . ErrorCode ) ;
168202 }
169203 }
170- } ) ) ;
204+ } , 10 , banner ? . CancellationToken ?? default ) ;
171205 }
172206 catch ( Exception ex )
173207 {
@@ -178,17 +212,25 @@ await Task.WhenAll(associatedInstance.SlimContentPage.SelectedItems.ToList().Sel
178212 if ( connection != null )
179213 {
180214 string filePaths = string . Join ( '|' , associatedInstance . SlimContentPage . SelectedItems . Select ( x => x . ItemPath ) ) ;
181- await connection . SendMessageAsync ( new ValueSet ( )
215+ AppServiceResponseStatus status = await connection . SendMessageAsync ( new ValueSet ( )
182216 {
183217 { "Arguments" , "FileOperation" } ,
184218 { "fileop" , "Clipboard" } ,
185219 { "filepath" , filePaths } ,
186220 { "operation" , ( int ) DataPackageOperation . Copy }
187221 } ) ;
222+ if ( status == AppServiceResponseStatus . Success )
223+ {
224+ banner ? . Remove ( ) ;
225+ return ;
226+ }
188227 }
189228 }
229+ banner ? . Remove ( ) ;
190230 return ;
191231 }
232+
233+ banner ? . Remove ( ) ;
192234 }
193235
194236 var onlyStandard = items . All ( x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder ) ;
0 commit comments