@@ -820,130 +820,56 @@ public async void DeleteItem_Click(object sender, RoutedEventArgs e)
820
820
}
821
821
}
822
822
823
- public async void RenameItem_Click ( object sender , RoutedEventArgs e )
823
+ public void RenameItem_Click ( object sender , RoutedEventArgs e )
824
824
{
825
-
826
825
if ( App . selectedTabInstance . accessibleContentFrame . SourcePageType == typeof ( GenericFileBrowser ) )
827
826
{
828
- var CurrentInstance = App . selectedTabInstance ;
829
- RenameDialog renameDialog = new RenameDialog ( ) ;
830
- renameDialog . inputBox . Text = "" ;
831
-
832
- try
833
- {
834
- var ItemSelected = ( CurrentInstance . accessibleContentFrame . Content as GenericFileBrowser ) . data . SelectedIndex ;
835
- var RowData = tabInstance . instanceViewModel . FilesAndFolders [ ItemSelected ] ;
836
- await renameDialog . ShowAsync ( ) ;
837
- var input = renameDialog . storedRenameInput ;
838
- if ( input != null )
839
- {
840
- if ( RowData . FileType == "Folder" )
841
- {
842
- var item = await StorageFolder . GetFolderFromPathAsync ( RowData . FilePath ) ;
843
- await item . RenameAsync ( input , NameCollisionOption . FailIfExists ) ;
844
- tabInstance . instanceViewModel . RemoveFileOrFolder ( RowData ) ;
845
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
846
- {
847
- FileName = input ,
848
- FileDateReal = DateTimeOffset . Now ,
849
- EmptyImgVis = Visibility . Collapsed ,
850
- FolderImg = Visibility . Visible ,
851
- FileIconVis = Visibility . Collapsed ,
852
- FileType = "Folder" ,
853
- FileImg = null ,
854
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input )
855
- } ) ;
856
- }
857
- else
858
- {
859
- var item = await StorageFile . GetFileFromPathAsync ( RowData . FilePath ) ;
860
- await item . RenameAsync ( input + RowData . DotFileExtension , NameCollisionOption . FailIfExists ) ;
861
- tabInstance . instanceViewModel . RemoveFileOrFolder ( RowData ) ;
862
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
863
- {
864
- FileName = input ,
865
- FileDateReal = DateTimeOffset . Now ,
866
- EmptyImgVis = Visibility . Visible ,
867
- FolderImg = Visibility . Collapsed ,
868
- FileIconVis = Visibility . Collapsed ,
869
- FileType = RowData . FileType ,
870
- FileImg = null ,
871
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input + RowData . DotFileExtension ) ,
872
- DotFileExtension = RowData . DotFileExtension
873
- } ) ;
874
- }
875
- }
876
-
877
- }
878
- catch ( Exception )
879
- {
880
- MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
881
- await itemAlreadyExistsDialog . ShowAsync ( ) ;
882
- }
883
- CurrentInstance . FS . isEnabled = false ;
827
+ var fileBrowser = App . selectedTabInstance . accessibleContentFrame . Content as GenericFileBrowser ;
828
+ fileBrowser . AllView . BeginEdit ( ) ;
884
829
}
885
830
else if ( App . selectedTabInstance . accessibleContentFrame . SourcePageType == typeof ( PhotoAlbum ) )
886
831
{
887
- var CurrentInstance = App . selectedTabInstance ;
888
- RenameDialog renameDialog = new RenameDialog ( ) ;
889
- renameDialog . inputBox . Text = "" ;
832
+ var photoAlbum = App . selectedTabInstance . accessibleContentFrame . Content as PhotoAlbum ;
833
+ photoAlbum . ShowRenameDialog ( ) ;
834
+ }
835
+ }
890
836
891
- try
837
+ public async Task < bool > RenameFileItem ( ListedItem item , string oldName , string newName )
838
+ {
839
+ if ( oldName == newName )
840
+ return true ;
841
+ try
842
+ {
843
+ if ( newName != "" )
892
844
{
893
- var ItemSelected = ( tabInstance . accessibleContentFrame . Content as PhotoAlbum ) . gv . SelectedIndex ;
894
- var BoxData = tabInstance . instanceViewModel . FilesAndFolders [ ItemSelected ] ;
895
- await renameDialog . ShowAsync ( ) ;
896
- var input = renameDialog . storedRenameInput ;
897
- if ( input != null )
845
+ if ( item . FileType == "Folder" )
898
846
{
899
- if ( BoxData . FileType == "Folder" )
900
- {
901
- var item = await StorageFolder . GetFolderFromPathAsync ( BoxData . FilePath ) ;
902
- await item . RenameAsync ( input , NameCollisionOption . FailIfExists ) ;
903
- tabInstance . instanceViewModel . RemoveFileOrFolder ( BoxData ) ;
904
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
905
- {
906
- FileName = input ,
907
- FileDateReal = DateTimeOffset . Now ,
908
- EmptyImgVis = Visibility . Collapsed ,
909
- FolderImg = Visibility . Visible ,
910
- FileIconVis = Visibility . Collapsed ,
911
- FileType = "Folder" ,
912
- FileImg = null ,
913
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input )
914
- } ) ;
915
- }
847
+ var folder = await StorageFolder . GetFolderFromPathAsync ( item . FilePath ) ;
848
+ if ( oldName . ToLower ( ) == newName . ToLower ( ) )
849
+ await folder . RenameAsync ( newName , NameCollisionOption . ReplaceExisting ) ;
916
850
else
917
- {
918
- var item = await StorageFile . GetFileFromPathAsync ( BoxData . FilePath ) ;
919
- await item . RenameAsync ( input + BoxData . DotFileExtension , NameCollisionOption . FailIfExists ) ;
920
- tabInstance . instanceViewModel . RemoveFileOrFolder ( BoxData ) ;
921
- tabInstance . instanceViewModel . AddFileOrFolder ( new ListedItem ( item . FolderRelativeId )
922
- {
923
- FileName = input ,
924
- FileDateReal = DateTimeOffset . Now ,
925
- EmptyImgVis = Visibility . Visible ,
926
- FolderImg = Visibility . Collapsed ,
927
- FileIconVis = Visibility . Collapsed ,
928
- FileType = BoxData . FileType ,
929
- FileImg = null ,
930
- FilePath = Path . Combine ( tabInstance . instanceViewModel . Universal . path , input + BoxData . DotFileExtension ) ,
931
- DotFileExtension = BoxData . DotFileExtension
932
- } ) ;
933
- }
851
+ await folder . RenameAsync ( newName , NameCollisionOption . FailIfExists ) ;
852
+ }
853
+ else
854
+ {
855
+ var file = await StorageFile . GetFileFromPathAsync ( item . FilePath ) ;
856
+ if ( oldName . ToLower ( ) == newName . ToLower ( ) )
857
+ await file . RenameAsync ( newName , NameCollisionOption . ReplaceExisting ) ;
858
+ else
859
+ await file . RenameAsync ( newName , NameCollisionOption . FailIfExists ) ;
934
860
}
935
-
936
- }
937
- catch ( Exception )
938
- {
939
- MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
940
- await itemAlreadyExistsDialog . ShowAsync ( ) ;
941
861
}
942
- CurrentInstance . FS . isEnabled = false ;
943
862
}
863
+ catch ( Exception )
864
+ {
865
+ MessageDialog itemAlreadyExistsDialog = new MessageDialog ( "An item with this name already exists in this folder" , "Try again" ) ;
866
+ await itemAlreadyExistsDialog . ShowAsync ( ) ;
867
+ return false ;
868
+ }
869
+ tabInstance . FS . isEnabled = false ;
870
+ return true ;
944
871
}
945
872
946
-
947
873
public List < DataGridRow > dataGridRows = new List < DataGridRow > ( ) ;
948
874
public List < GridViewItem > gridViewItems = new List < GridViewItem > ( ) ;
949
875
public async void CutItem_Click ( object sender , RoutedEventArgs e )
0 commit comments