mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Show editor file choosers in a popover rather than inline
Supersedes and closes #14370. Closes #14367.
This commit is contained in:
@ -8,22 +8,27 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Setup
|
namespace osu.Game.Screens.Edit.Setup
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A labelled textbox which reveals an inline file chooser when clicked.
|
/// A labelled textbox which reveals an inline file chooser when clicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles
|
internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles, IHasPopover
|
||||||
{
|
{
|
||||||
private readonly string[] handledExtensions;
|
private readonly string[] handledExtensions;
|
||||||
|
|
||||||
public IEnumerable<string> HandledExtensions => handledExtensions;
|
public IEnumerable<string> HandledExtensions => handledExtensions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -51,23 +56,9 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
CornerRadius = CORNER_RADIUS,
|
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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
@ -111,5 +102,23 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
GetContainingInputManager().TriggerFocusContention(this);
|
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 }
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user