1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Show editor file choosers in a popover rather than inline

Supersedes and closes #14370.
Closes #14367.
This commit is contained in:
Dean Herbert 2021-08-23 18:12:35 +09:00
parent 233b222c6f
commit c2c9a93e2c

View File

@ -8,22 +8,27 @@ using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
namespace osu.Game.Screens.Edit.Setup
{
/// <summary>
/// A labelled textbox which reveals an inline file chooser when clicked.
/// </summary>
internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles
internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles, IHasPopover
{
private readonly string[] handledExtensions;
public IEnumerable<string> HandledExtensions => handledExtensions;
/// <summary>
@ -51,23 +56,9 @@ namespace osu.Game.Screens.Edit.Setup
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
CornerRadius = CORNER_RADIUS,
OnFocused = DisplayFileChooser
OnFocused = this.ShowPopover
};
public void DisplayFileChooser()
{
OsuFileSelector fileSelector;
Target.Child = fileSelector = new OsuFileSelector(currentFile.Value?.DirectoryName, handledExtensions)
{
RelativeSizeAxes = Axes.X,
Height = 400,
CurrentFile = { BindTarget = currentFile }
};
sectionsContainer.ScrollTo(fileSelector);
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -111,5 +102,23 @@ namespace osu.Game.Screens.Edit.Setup
GetContainingInputManager().TriggerFocusContention(this);
}
}
public Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile);
private class FileChooserPopover : OsuPopover
{
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo> currentFile)
{
Child = new Container
{
Size = new Vector2(600, 400),
Child = new OsuFileSelector(currentFile.Value?.DirectoryName, handledExtensions)
{
RelativeSizeAxes = Axes.Both,
CurrentFile = { BindTarget = currentFile }
},
};
}
}
}
}