@@ -565,130 +565,61 @@ public async void DeleteItem_Click(object sender, RoutedEventArgs e)
565
565
}
566
566
}
567
567
568
- public async void RenameItem_Click ( object sender , RoutedEventArgs e )
568
+ public void RenameItem_Click ( object sender , RoutedEventArgs e )
569
569
{
570
-
571
570
if ( App . selectedTabInstance . accessibleContentFrame . SourcePageType == typeof ( GenericFileBrowser ) )
572
571
{
573
- var CurrentInstance = App . selectedTabInstance ;
574
- RenameDialog renameDialog = new RenameDialog ( ) ;
575
- renameDialog . inputBox . Text = "" ;
576
-
577
- try
578
- {
579
- var ItemSelected = ( CurrentInstance . accessibleContentFrame . Content as GenericFileBrowser ) . data . SelectedIndex ;
580
- var RowData = tabInstance . instanceViewModel . FilesAndFolders [ ItemSelected ] ;
581
- await renameDialog . ShowAsync ( ) ;
582
- var input = renameDialog . storedRenameInput ;
583
- if ( input != null )
584
- {
585
- if ( RowData . FileType == "Folder" )
586
- {
587
- var item = await StorageFolder . GetFolderFromPathAsync ( RowData . FilePath ) ;
588
- await item . RenameAsync ( input , NameCollisionOption . FailIfExists ) ;
589
- tabInstance . instanceViewModel . RemoveFileOrFolder ( RowData ) ;
590
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
591
- {
592
- FileName = input ,
593
- FileDateReal = DateTimeOffset . Now ,
594
- EmptyImgVis = Visibility . Collapsed ,
595
- FolderImg = Visibility . Visible ,
596
- FileIconVis = Visibility . Collapsed ,
597
- FileType = "Folder" ,
598
- FileImg = null ,
599
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input )
600
- } ) ;
601
- }
602
- else
603
- {
604
- var item = await StorageFile . GetFileFromPathAsync ( RowData . FilePath ) ;
605
- await item . RenameAsync ( input + RowData . DotFileExtension , NameCollisionOption . FailIfExists ) ;
606
- tabInstance . instanceViewModel . RemoveFileOrFolder ( RowData ) ;
607
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
608
- {
609
- FileName = input ,
610
- FileDateReal = DateTimeOffset . Now ,
611
- EmptyImgVis = Visibility . Visible ,
612
- FolderImg = Visibility . Collapsed ,
613
- FileIconVis = Visibility . Collapsed ,
614
- FileType = RowData . FileType ,
615
- FileImg = null ,
616
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input + RowData . DotFileExtension ) ,
617
- DotFileExtension = RowData . DotFileExtension
618
- } ) ;
619
- }
620
- }
621
-
622
- }
623
- catch ( Exception )
624
- {
625
- MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
626
- await itemAlreadyExistsDialog . ShowAsync ( ) ;
627
- }
628
- CurrentInstance . FS . isEnabled = false ;
572
+ var fileBrowser = App . selectedTabInstance . accessibleContentFrame . Content as GenericFileBrowser ;
573
+ if ( fileBrowser . AllView . SelectedItem != null )
574
+ fileBrowser . AllView . CurrentColumn = fileBrowser . AllView . Columns [ 1 ] ;
575
+ fileBrowser . AllView . BeginEdit ( ) ;
629
576
}
630
577
else if ( App . selectedTabInstance . accessibleContentFrame . SourcePageType == typeof ( PhotoAlbum ) )
631
578
{
632
- var CurrentInstance = App . selectedTabInstance ;
633
- RenameDialog renameDialog = new RenameDialog ( ) ;
634
- renameDialog . inputBox . Text = "" ;
579
+ var photoAlbum = App . selectedTabInstance . accessibleContentFrame . Content as PhotoAlbum ;
580
+ photoAlbum . StartRename ( ) ;
581
+ }
582
+ }
635
583
636
- try
584
+ public async Task < bool > RenameFileItem ( ListedItem item , string oldName , string newName )
585
+ {
586
+ if ( oldName == newName )
587
+ return true ;
588
+ bool isRenamedSameNameDiffCase = oldName . ToLower ( ) == newName . ToLower ( ) ;
589
+ try
590
+ {
591
+ if ( newName != "" )
637
592
{
638
- var ItemSelected = ( tabInstance . accessibleContentFrame . Content as PhotoAlbum ) . gv . SelectedIndex ;
639
- var BoxData = tabInstance . instanceViewModel . FilesAndFolders [ ItemSelected ] ;
640
- await renameDialog . ShowAsync ( ) ;
641
- var input = renameDialog . storedRenameInput ;
642
- if ( input != null )
593
+ if ( item . FileType == "Folder" )
643
594
{
644
- if ( BoxData . FileType == "Folder" )
645
- {
646
- var item = await StorageFolder . GetFolderFromPathAsync ( BoxData . FilePath ) ;
647
- await item . RenameAsync ( input , NameCollisionOption . FailIfExists ) ;
648
- tabInstance . instanceViewModel . RemoveFileOrFolder ( BoxData ) ;
649
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
650
- {
651
- FileName = input ,
652
- FileDateReal = DateTimeOffset . Now ,
653
- EmptyImgVis = Visibility . Collapsed ,
654
- FolderImg = Visibility . Visible ,
655
- FileIconVis = Visibility . Collapsed ,
656
- FileType = "Folder" ,
657
- FileImg = null ,
658
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input )
659
- } ) ;
660
- }
595
+ var folder = await StorageFolder . GetFolderFromPathAsync ( item . FilePath ) ;
596
+ if ( isRenamedSameNameDiffCase )
597
+ throw new InvalidOperationException ( ) ;
598
+ //await folder.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
661
599
else
662
- {
663
- var item = await StorageFile . GetFileFromPathAsync ( BoxData . FilePath ) ;
664
- await item . RenameAsync ( input + BoxData . DotFileExtension , NameCollisionOption . FailIfExists ) ;
665
- tabInstance . instanceViewModel . RemoveFileOrFolder ( BoxData ) ;
666
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
667
- {
668
- FileName = input ,
669
- FileDateReal = DateTimeOffset . Now ,
670
- EmptyImgVis = Visibility . Visible ,
671
- FolderImg = Visibility . Collapsed ,
672
- FileIconVis = Visibility . Collapsed ,
673
- FileType = BoxData . FileType ,
674
- FileImg = null ,
675
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input + BoxData . DotFileExtension ) ,
676
- DotFileExtension = BoxData . DotFileExtension
677
- } ) ;
678
- }
600
+ await folder . RenameAsync ( newName , NameCollisionOption . FailIfExists ) ;
601
+ }
602
+ else
603
+ {
604
+ var file = await StorageFile . GetFileFromPathAsync ( item . FilePath ) ;
605
+ if ( isRenamedSameNameDiffCase )
606
+ throw new InvalidOperationException ( ) ;
607
+ //await file.RenameAsync(newName, NameCollisionOption.ReplaceExisting);
608
+ else
609
+ await file . RenameAsync ( newName , NameCollisionOption . FailIfExists ) ;
679
610
}
680
-
681
- }
682
- catch ( Exception )
683
- {
684
- MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
685
- await itemAlreadyExistsDialog . ShowAsync ( ) ;
686
611
}
687
- CurrentInstance . FS . isEnabled = false ;
688
612
}
613
+ catch ( Exception )
614
+ {
615
+ MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
616
+ await itemAlreadyExistsDialog . ShowAsync ( ) ;
617
+ return false ;
618
+ }
619
+ tabInstance . FS . isEnabled = false ;
620
+ return true ;
689
621
}
690
622
691
-
692
623
public List < DataGridRow > dataGridRows = new List < DataGridRow > ( ) ;
693
624
public List < GridViewItem > gridViewItems = new List < GridViewItem > ( ) ;
694
625
public async void CutItem_Click ( object sender , RoutedEventArgs e )
0 commit comments