Move drag & drop support logic to chooser component

This commit is contained in:
Bartłomiej Dach
2021-04-04 12:34:52 +02:00
parent 294d911426
commit 9394af32f5
2 changed files with 51 additions and 52 deletions

View File

@ -1,36 +1,25 @@
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
namespace osu.Game.Screens.Edit.Setup
{
internal class ResourcesSection : SetupSection, ICanAcceptFiles
internal class ResourcesSection : SetupSection
{
private LabelledTextBox audioTrackTextBox;
public override LocalisableString Title => "Resources";
public IEnumerable<string> HandledExtensions => AudioExtensions;
public static string[] AudioExtensions { get; } = { ".mp3", ".ogg" };
[Resolved]
private OsuGameBase game { get; set; }
[Resolved]
private MusicController music { get; set; }
@ -54,7 +43,7 @@ namespace osu.Game.Screens.Edit.Setup
Children = new Drawable[]
{
audioTrackTextBox = new FileChooserLabelledTextBox
audioTrackTextBox = new FileChooserLabelledTextBox(".mp3", ".ogg")
{
Label = "Audio Track",
PlaceholderText = "Click to select a track",
@ -68,31 +57,6 @@ namespace osu.Game.Screens.Edit.Setup
audioTrackTextBox.Current.BindValueChanged(audioTrackChanged);
}
Task ICanAcceptFiles.Import(params string[] paths)
{
Schedule(() =>
{
var firstFile = new FileInfo(paths.First());
audioTrackTextBox.Text = firstFile.FullName;
});
return Task.CompletedTask;
}
Task ICanAcceptFiles.Import(params ImportTask[] tasks) => throw new NotImplementedException();
protected override void LoadComplete()
{
base.LoadComplete();
game.RegisterImportHandler(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
game?.UnregisterImportHandler(this);
}
public bool ChangeAudioTrack(string path)
{
var info = new FileInfo(path);