private async void CommitRename(TextBox textBox) { EndRename(textBox); string newItemName = textBox.Text.Trim().TrimEnd('.'); bool successful = await UIFilesystemHelpers.RenameFileItemAsync(renamingItem, oldItemName, newItemName, ParentShellPageInstance); if (!successful) { renamingItem.ItemName = oldItemName; } }
private async void AllView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { e.EditingElement.LosingFocus -= EditingElement_LosingFocus; if (e.EditAction == DataGridEditAction.Cancel || renamingTextBox == null) { return; } renamingTextBox.Text = renamingTextBox.Text.Trim().TrimEnd('.'); var selectedItem = e.Row.DataContext as ListedItem; string newItemName = renamingTextBox.Text; bool successful = await UIFilesystemHelpers.RenameFileItemAsync(selectedItem, oldItemName, newItemName, ParentShellPageInstance); if (!successful) { selectedItem.ItemName = oldItemName; renamingTextBox.Text = oldItemName; } }
public async Task SaveChangesAsync(ListedItem item) { if (BaseProperties is DriveProperties) { var drive = (BaseProperties as DriveProperties).Drive; if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { if (AppInstance.FilesystemViewModel != null) { await AppInstance.ServiceConnection?.SendMessageAsync(new ValueSet() { { "Arguments", "SetVolumeLabel" }, { "drivename", drive.Path }, { "newlabel", ViewModel.ItemName } }); _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { await drive.UpdateLabelAsync(); await AppInstance.FilesystemViewModel?.SetWorkingDirectoryAsync(drive.Path); }); } } } else { if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.RenameFileItemAsync(item, ViewModel.OriginalItemName, ViewModel.ItemName, AppInstance)); } // Handle the hidden attribute if (BaseProperties is CombinedProperties) { // Handle each file independently var items = (BaseProperties as CombinedProperties).List; foreach (var fileOrFolder in items) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(fileOrFolder, ViewModel.IsHidden, AppInstance.SlimContentPage)); } } else { // Handle the visibility attribute for a single file await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(item, ViewModel.IsHidden, AppInstance.SlimContentPage)); } } }
public async Task SaveChangesAsync(ListedItem item) { if (BaseProperties is DriveProperties driveProps) { var drive = driveProps.Drive; if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { if (AppInstance.FilesystemViewModel != null) { await AppInstance.ServiceConnection?.SendMessageAsync(new ValueSet() { { "Arguments", "SetVolumeLabel" }, { "drivename", drive.Path }, { "newlabel", ViewModel.ItemName } }); _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { await drive.UpdateLabelAsync(); await AppInstance.FilesystemViewModel?.SetWorkingDirectoryAsync(drive.Path); }); } } } else if (BaseProperties is LibraryProperties libProps) { var library = libProps.Library; var newName = ViewModel.ItemName; if (!string.IsNullOrWhiteSpace(newName) && ViewModel.OriginalItemName != newName) { if (AppInstance.FilesystemViewModel != null && App.LibraryManager.CanCreateLibrary(newName).result) { var libraryPath = library.ItemPath; var renamed = await AppInstance.FilesystemHelpers.RenameAsync(new StorageFileWithPath(null, libraryPath), newName, Windows.Storage.NameCollisionOption.FailIfExists, false); if (renamed == Enums.ReturnResult.Success) { var newPath = Path.Combine(Path.GetDirectoryName(libraryPath), $"{newName}{ShellLibraryItem.EXTENSION}"); _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { await AppInstance.FilesystemViewModel?.SetWorkingDirectoryAsync(newPath); }); } } } } else { if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.RenameFileItemAsync(item, ViewModel.OriginalItemName, ViewModel.ItemName, AppInstance)); } // Handle the hidden attribute if (BaseProperties is CombinedProperties combinedProps) { // Handle each file independently foreach (var fileOrFolder in combinedProps.List) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(fileOrFolder, ViewModel.IsHidden, AppInstance.SlimContentPage.ItemManipulationModel)); } } else { // Handle the visibility attribute for a single file await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(item, ViewModel.IsHidden, AppInstance.SlimContentPage.ItemManipulationModel)); } } }
public override async Task <bool> SaveChangesAsync(ListedItem item) { if (BaseProperties is DriveProperties driveProps) { var drive = driveProps.Drive; ViewModel.ItemName = ItemFileName.Text; // Make sure ItemName is updated if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { var remDrive = new System.Text.RegularExpressions.Regex(@"\s*\(\w:\)$"); ViewModel.ItemName = remDrive.Replace(ViewModel.ItemName, ""); // Remove "(C:)" from the new label var connection = await AppServiceConnectionHelper.Instance; if (connection != null && AppInstance.FilesystemViewModel != null) { _ = await connection.SendMessageForResponseAsync(new ValueSet() { { "Arguments", "SetVolumeLabel" }, { "drivename", drive.Path }, { "newlabel", ViewModel.ItemName } }); _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { await drive.UpdateLabelAsync(); await AppInstance.FilesystemViewModel?.SetWorkingDirectoryAsync(drive.Path); }); return(true); } } } else if (BaseProperties is LibraryProperties libProps) { var library = libProps.Library; ViewModel.ItemName = ItemFileName.Text; // Make sure ItemName is updated var newName = ViewModel.ItemName; if (!string.IsNullOrWhiteSpace(newName) && ViewModel.OriginalItemName != newName) { if (AppInstance.FilesystemViewModel != null && App.LibraryManager.CanCreateLibrary(newName).result) { var libraryPath = library.ItemPath; var renamed = await AppInstance.FilesystemHelpers.RenameAsync(new StorageFileWithPath(null, libraryPath), newName, Windows.Storage.NameCollisionOption.FailIfExists, false); if (renamed == Enums.ReturnResult.Success) { var newPath = Path.Combine(Path.GetDirectoryName(libraryPath), $"{newName}{ShellLibraryItem.EXTENSION}"); _ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async() => { await AppInstance.FilesystemViewModel?.SetWorkingDirectoryAsync(newPath); }); return(true); } } } } else { ViewModel.ItemName = ItemFileName.Text; // Make sure ItemName is updated if (!string.IsNullOrWhiteSpace(ViewModel.ItemName) && ViewModel.OriginalItemName != ViewModel.ItemName) { return(await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.RenameFileItemAsync(item, ViewModel.OriginalItemName, ViewModel.ItemName, AppInstance))); } // Handle the hidden attribute if (BaseProperties is CombinedProperties combinedProps) { // Handle each file independently if (AppInstance?.SlimContentPage?.ItemManipulationModel != null) // null on homepage { foreach (var fileOrFolder in combinedProps.List) { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(fileOrFolder, ViewModel.IsHidden, AppInstance.SlimContentPage.ItemManipulationModel)); } } return(true); } else { // Handle the visibility attribute for a single file if (AppInstance?.SlimContentPage?.ItemManipulationModel != null) // null on homepage { await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIFilesystemHelpers.SetHiddenAttributeItem(item, ViewModel.IsHidden, AppInstance.SlimContentPage.ItemManipulationModel)); } return(true); } } return(false); }
private async void CommitRename(TextBox textBox) { EndRename(textBox); string newItemName = textBox.Text.Trim().TrimEnd('.'); await UIFilesystemHelpers.RenameFileItemAsync(RenamingItem, newItemName, ParentShellPageInstance); }