@@ -42,6 +42,7 @@ public sealed partial class PhotoAlbum : Page
42
42
public TextBlock EmptyTextPA ;
43
43
public string inputForRename ;
44
44
public ProgressBar progressBar ;
45
+ public ListedItem renamingItem ;
45
46
ItemViewModel viewModelInstance ;
46
47
ProHome tabInstance ;
47
48
public EmptyFolderTextState TextState { get ; set ; } = new EmptyFolderTextState ( ) ;
@@ -311,34 +312,73 @@ private void RightClickContextMenu_Opened(object sender, object e)
311
312
}
312
313
}
313
314
314
- public async void ShowRenameDialog ( )
315
+ public void StartRename ( )
315
316
{
316
- try
317
+ renamingItem = gv . SelectedItem as ListedItem ;
318
+ GridViewItem gridViewItem = gv . ContainerFromItem ( renamingItem ) as GridViewItem ;
319
+ StackPanel stackPanel = ( gridViewItem . ContentTemplateRoot as Grid ) . Children [ 1 ] as StackPanel ;
320
+ TextBlock textBlock = stackPanel . Children [ 0 ] as TextBlock ;
321
+ TextBox textBox = stackPanel . Children [ 1 ] as TextBox ;
322
+ int extensionLength = renamingItem . DotFileExtension ? . Length ?? 0 ;
323
+
324
+ textBlock . Visibility = Visibility . Collapsed ;
325
+ textBox . Visibility = Visibility . Visible ;
326
+ textBox . Focus ( FocusState . Pointer ) ;
327
+ textBox . LostFocus += RenameTextBox_LostFocus ;
328
+ textBox . KeyDown += RenameTextBox_KeyDown ;
329
+ textBox . Select ( 0 , renamingItem . FileName . Length - extensionLength ) ;
330
+ }
331
+
332
+ private void RenameTextBox_KeyDown ( object sender , KeyRoutedEventArgs e )
333
+ {
334
+ if ( e . Key == VirtualKey . Escape )
317
335
{
318
- var selectedItem = FileList . SelectedItem as ListedItem ;
319
- RenameDialog renameDialog = new RenameDialog ( ) ;
320
- var textBox = renameDialog . inputBox ;
321
- int extensionLength = selectedItem . DotFileExtension ? . Length ?? 0 ;
336
+ TextBox textBox = sender as TextBox ;
337
+ textBox . LostFocus -= RenameTextBox_LostFocus ;
338
+ EndRename ( textBox ) ;
339
+ }
340
+ else if ( e . Key == VirtualKey . Enter )
341
+ {
342
+ TextBox textBox = sender as TextBox ;
343
+ CommitRename ( textBox ) ;
344
+ }
345
+ }
322
346
323
- textBox . Text = selectedItem . FileName ;
324
- textBox . Select ( 0 , selectedItem . FileName . Length - extensionLength ) ;
347
+ private void RenameTextBox_LostFocus ( object sender , RoutedEventArgs e )
348
+ {
349
+ TextBox textBox = e . OriginalSource as TextBox ;
350
+ CommitRename ( textBox ) ;
351
+ }
325
352
326
- await renameDialog . ShowAsync ( ) ;
353
+ private async void CommitRename ( TextBox textBox )
354
+ {
355
+ EndRename ( textBox ) ;
327
356
357
+ try
358
+ {
359
+ var selectedItem = renamingItem ;
328
360
string currentName = selectedItem . FileName ;
329
- string newName = renameDialog . storedRenameInput ;
361
+ string newName = textBox . Text ;
330
362
331
363
if ( newName == null )
332
364
return ;
333
365
334
- Debug . WriteLine ( currentName ) ;
335
- Debug . WriteLine ( newName ) ;
336
366
await tabInstance . instanceInteraction . RenameFileItem ( selectedItem , currentName , newName ) ;
337
367
}
338
368
catch ( Exception )
339
369
{
340
370
341
371
}
342
372
}
373
+
374
+ private void EndRename ( TextBox textBox )
375
+ {
376
+ StackPanel parentPanel = textBox . Parent as StackPanel ;
377
+ TextBlock textBlock = parentPanel . Children [ 0 ] as TextBlock ;
378
+ textBox . Visibility = Visibility . Collapsed ;
379
+ textBlock . Visibility = Visibility . Visible ;
380
+ textBox . LostFocus -= RenameTextBox_LostFocus ;
381
+ textBox . KeyDown += RenameTextBox_KeyDown ;
382
+ }
343
383
}
344
384
}
0 commit comments