1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Merge pull request #18536 from bdach/safe-file-chooser-textbox-disposal

Improve safety of file chooser textbox disposal
This commit is contained in:
Dean Herbert 2022-06-03 13:50:41 +09:00 committed by GitHub
commit 678229fdab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
@ -9,6 +11,7 @@ using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
@ -27,10 +30,10 @@ namespace osu.Game.Screens.Edit.Setup
public IEnumerable<string> HandledExtensions => handledExtensions;
private readonly Bindable<FileInfo> currentFile = new Bindable<FileInfo>();
private readonly Bindable<FileInfo?> currentFile = new Bindable<FileInfo?>();
[Resolved]
private OsuGameBase game { get; set; }
private OsuGameBase game { get; set; } = null!;
public FileChooserLabelledTextBox(params string[] handledExtensions)
{
@ -45,7 +48,7 @@ namespace osu.Game.Screens.Edit.Setup
currentFile.BindValueChanged(onFileSelected);
}
private void onFileSelected(ValueChangedEvent<FileInfo> file)
private void onFileSelected(ValueChangedEvent<FileInfo?> file)
{
if (file.NewValue == null)
return;
@ -65,14 +68,16 @@ namespace osu.Game.Screens.Edit.Setup
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
game.UnregisterImportHandler(this);
if (game.IsNotNull())
game.UnregisterImportHandler(this);
}
public override Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile);
private class FileChooserPopover : OsuPopover
{
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo> currentFile)
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> currentFile)
{
Child = new Container
{