Skip to content

Commit

Permalink
Fix: Fixed NullReferenceException when renaming files (files-communit…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Jan 4, 2024
1 parent fa2caab commit 71742c3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,27 @@ protected override void EndRename(TextBox textBox)
{
Popup? popup = gridViewItem.FindDescendant("EditPopup") as Popup;
TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;
popup!.IsOpen = false;
textBlock!.Opacity = (textBlock.DataContext as ListedItem)!.Opacity;

if (popup is not null)
popup.IsOpen = false;

if (textBlock is not null)
textBlock.Opacity = (textBlock.DataContext as ListedItem)!.Opacity;
}
else if (FolderSettings.LayoutMode == FolderLayoutModes.TilesView)
{
TextBlock? textBlock = gridViewItem.FindDescendant("ItemName") as TextBlock;

textBox.Visibility = Visibility.Collapsed;
textBlock!.Visibility = Visibility.Visible;

if (textBlock is not null)
textBlock.Visibility = Visibility.Visible;
}

// Unsubscribe from events
if (textBox is not null)
{
textBox!.LostFocus -= RenameTextBox_LostFocus;
textBox.LostFocus -= RenameTextBox_LostFocus;
textBox.KeyDown -= RenameTextBox_KeyDown;
}

Expand Down Expand Up @@ -430,15 +437,17 @@ private async void FileList_ItemTapped(object sender, TappedRoutedEventArgs e)
if (FolderSettings.LayoutMode == FolderLayoutModes.GridView)
{
Popup popup = gridViewItem.FindDescendant("EditPopup") as Popup;
var textBox = popup.Child as TextBox;
var textBox = popup?.Child as TextBox;

await CommitRenameAsync(textBox);
if (textBox is not null)
await CommitRenameAsync(textBox);
}
else
{
var textBox = gridViewItem.FindDescendant("TileViewTextBoxItemName") as TextBox;

await CommitRenameAsync(textBox);
if (textBox is not null)
await CommitRenameAsync(textBox);
}
}
}
Expand Down

0 comments on commit 71742c3

Please sign in to comment.