diff --git a/osu.Game/Collections/DrawableCollectionList.cs b/osu.Game/Collections/DrawableCollectionList.cs
index 96013314c7..e87a79f2e8 100644
--- a/osu.Game/Collections/DrawableCollectionList.cs
+++ b/osu.Game/Collections/DrawableCollectionList.cs
@@ -140,12 +140,35 @@ namespace osu.Game.Collections
var previous = PlaceholderItem;
placeholderContainer.Clear(false);
- placeholderContainer.Add(PlaceholderItem = new DrawableCollectionListItem(new BeatmapCollection().ToLiveUnmanaged(), false));
+ placeholderContainer.Add(PlaceholderItem = new NewCollectionEntryItem());
return previous;
}
}
+ private class NewCollectionEntryItem : DrawableCollectionListItem
+ {
+ [Resolved]
+ private RealmAccess realm { get; set; } = null!;
+
+ public NewCollectionEntryItem()
+ : base(new BeatmapCollection().ToLiveUnmanaged(), false)
+ {
+ }
+
+ protected override void LoadComplete()
+ {
+ base.LoadComplete();
+
+ TextBox.OnCommit += (sender, newText) =>
+ {
+ if (newText && !string.IsNullOrEmpty(TextBox.Current.Value))
+ realm.Write(r => r.Add(new BeatmapCollection(TextBox.Current.Value)));
+ TextBox.Text = string.Empty;
+ };
+ }
+ }
+
///
/// The flow of . Disables layout easing unless a drag is in progress.
///
diff --git a/osu.Game/Collections/DrawableCollectionListItem.cs b/osu.Game/Collections/DrawableCollectionListItem.cs
index e71368c079..a17a50e232 100644
--- a/osu.Game/Collections/DrawableCollectionListItem.cs
+++ b/osu.Game/Collections/DrawableCollectionListItem.cs
@@ -28,6 +28,10 @@ namespace osu.Game.Collections
private const float item_height = 35;
private const float button_width = item_height * 0.75f;
+ protected TextBox TextBox => content.TextBox;
+
+ private ItemContent content = null!;
+
///
/// Creates a new .
///
@@ -48,7 +52,7 @@ namespace osu.Game.Collections
CornerRadius = item_height / 2;
}
- protected override Drawable CreateContent() => new ItemContent(Model);
+ protected override Drawable CreateContent() => content = new ItemContent(Model);
///
/// The main content of the .
@@ -57,10 +61,7 @@ namespace osu.Game.Collections
{
private readonly Live collection;
- private ItemTextBox textBox = null!;
-
- [Resolved]
- private RealmAccess realm { get; set; } = null!;
+ public ItemTextBox TextBox { get; private set; } = null!;
public ItemContent(Live collection)
{
@@ -80,7 +81,7 @@ namespace osu.Game.Collections
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
- IsTextBoxHovered = v => textBox.ReceivePositionalInputAt(v)
+ IsTextBoxHovered = v => TextBox.ReceivePositionalInputAt(v)
}
: Empty(),
new Container
@@ -89,7 +90,7 @@ namespace osu.Game.Collections
Padding = new MarginPadding { Right = collection.IsManaged ? button_width : 0 },
Children = new Drawable[]
{
- textBox = new ItemTextBox
+ TextBox = new ItemTextBox
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
@@ -107,18 +108,14 @@ namespace osu.Game.Collections
base.LoadComplete();
// Bind late, as the collection name may change externally while still loading.
- textBox.Current.Value = collection.PerformRead(c => c.IsValid ? c.Name : string.Empty);
- textBox.OnCommit += onCommit;
+ TextBox.Current.Value = collection.PerformRead(c => c.IsValid ? c.Name : string.Empty);
+ TextBox.OnCommit += onCommit;
}
private void onCommit(TextBox sender, bool newText)
{
- if (collection.IsManaged)
- collection.PerformWrite(c => c.Name = textBox.Current.Value);
- else if (!string.IsNullOrEmpty(textBox.Current.Value))
- realm.Write(r => r.Add(new BeatmapCollection(textBox.Current.Value)));
-
- textBox.Text = string.Empty;
+ if (collection.IsManaged && newText)
+ collection.PerformWrite(c => c.Name = TextBox.Current.Value);
}
}