1
- using Files . Shared ;
2
1
using Files . App . Dialogs ;
3
- using Files . Shared . Enums ;
4
- using Files . Shared . Extensions ;
5
2
using Files . App . Filesystem ;
6
3
using Files . App . Filesystem . StorageItems ;
7
4
using Files . App . Interacts ;
8
5
using Files . App . ViewModels ;
9
6
using Files . App . Extensions ;
7
+ using Files . Backend . Enums ;
8
+ using Files . Shared ;
9
+ using Files . Shared . Enums ;
10
+ using Files . Shared . Extensions ;
11
+ using Microsoft . UI . Xaml . Controls ;
10
12
using System ;
11
13
using System . Collections . Concurrent ;
12
14
using System . IO ;
13
15
using System . Linq ;
14
16
using System . Threading ;
15
17
using System . Threading . Tasks ;
16
- using Windows . ApplicationModel . AppService ;
17
18
using Windows . ApplicationModel . DataTransfer ;
18
- using Windows . Foundation . Collections ;
19
19
using Windows . Storage ;
20
- using Files . Backend . Enums ;
21
20
using Windows . System ;
22
- using Microsoft . UI . Xaml . Controls ;
23
21
24
22
namespace Files . App . Helpers
25
23
{
@@ -255,26 +253,24 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
255
253
StringComparison . Ordinal ) ;
256
254
newName = $ "{ ads . MainStreamName } :{ newName } ";
257
255
}
256
+ else if ( string . IsNullOrEmpty ( item . Name ) )
257
+ {
258
+ newName = string . Concat ( newName , item . FileExtension ) ;
259
+ }
258
260
else
259
261
{
260
262
newName = item . ItemNameRaw . Replace ( item . Name , newName , StringComparison . Ordinal ) ;
261
263
}
264
+
262
265
if ( item . ItemNameRaw == newName || string . IsNullOrEmpty ( newName ) )
263
266
{
264
267
return true ;
265
268
}
266
269
270
+ FilesystemItemType itemType = ( item . PrimaryItemAttribute == StorageItemTypes . Folder ) ? FilesystemItemType . Directory : FilesystemItemType . File ;
271
+
267
272
ReturnResult renamed = ReturnResult . InProgress ;
268
- if ( item . PrimaryItemAttribute == StorageItemTypes . Folder )
269
- {
270
- renamed = await associatedInstance . FilesystemHelpers . RenameAsync ( StorageHelpers . FromPathAndType ( item . ItemPath , FilesystemItemType . Directory ) ,
271
- newName , NameCollisionOption . FailIfExists , true ) ;
272
- }
273
- else
274
- {
275
- renamed = await associatedInstance . FilesystemHelpers . RenameAsync ( StorageHelpers . FromPathAndType ( item . ItemPath , FilesystemItemType . File ) ,
276
- newName , NameCollisionOption . FailIfExists , true ) ;
277
- }
273
+ renamed = await associatedInstance . FilesystemHelpers . RenameAsync ( StorageHelpers . FromPathAndType ( item . ItemPath , itemType ) , newName , NameCollisionOption . FailIfExists , true ) ;
278
274
279
275
if ( renamed == ReturnResult . Success )
280
276
{
@@ -286,7 +282,7 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
286
282
287
283
public static async void CreateFileFromDialogResultType ( AddItemDialogItemType itemType , ShellNewEntry itemInfo , IShellPage associatedInstance )
288
284
{
289
- _ = await CreateFileFromDialogResultTypeForResult ( itemType , itemInfo , associatedInstance ) ;
285
+ await CreateFileFromDialogResultTypeForResult ( itemType , itemInfo , associatedInstance ) ;
290
286
}
291
287
292
288
// WINUI3
@@ -305,12 +301,11 @@ public static async Task<IStorageItem> CreateFileFromDialogResultTypeForResult(A
305
301
if ( associatedInstance . SlimContentPage != null )
306
302
{
307
303
currentPath = associatedInstance . FilesystemViewModel . WorkingDirectory ;
308
- if ( App . LibraryManager . TryGetLibrary ( currentPath , out var library ) )
309
- {
310
- if ( ! library . IsEmpty && library . Folders . Count == 1 ) // TODO: handle libraries with multiple folders
311
- {
312
- currentPath = library . Folders . First ( ) ;
313
- }
304
+ if ( App . LibraryManager . TryGetLibrary ( currentPath , out var library ) &&
305
+ ! library . IsEmpty &&
306
+ library . Folders . Count == 1 ) // TODO: handle libraries with multiple folders
307
+ {
308
+ currentPath = library . Folders . First ( ) ;
314
309
}
315
310
}
316
311
0 commit comments