private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args) { switch (args.Action) { case NotifyCollectionChangedAction.Add: foreach (Channel channel in args.NewItems.Cast <Channel>()) { ChannelTabControl.AddChannel(channel); } break; case NotifyCollectionChangedAction.Remove: foreach (Channel channel in args.OldItems.Cast <Channel>()) { ChannelTabControl.RemoveChannel(channel); var loaded = loadedChannels.Find(c => c.Channel == channel); if (loaded != null) { loadedChannels.Remove(loaded); // Because the container is only cleared in the async load callback of a new channel, it is forcefully cleared // to ensure that the previous channel doesn't get updated after it's disposed currentChannelContainer.Remove(loaded); loaded.Dispose(); } } break; } }
public TestCaseChannelTabControl() { SpriteText currentText; Add(new Container { RelativeSizeAxes = Axes.X, Origin = Anchor.Centre, Anchor = Anchor.Centre, Children = new Drawable[] { channelTabControl = new ChannelTabControl { RelativeSizeAxes = Axes.X, Origin = Anchor.Centre, Anchor = Anchor.Centre, Height = 50 }, new Box { Colour = Color4.Black.Opacity(0.1f), RelativeSizeAxes = Axes.X, Height = 50, Depth = -1, Origin = Anchor.Centre, Anchor = Anchor.Centre, } } }); Add(new Container { Origin = Anchor.TopLeft, Anchor = Anchor.TopLeft, Children = new Drawable[] { currentText = new SpriteText { Text = "Currently selected channel:" } } }); channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel); channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString(); AddStep("Add random private channel", addRandomUser); AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2); AddRepeatStep("Add 3 random private channels", addRandomUser, 3); AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5); AddStep("Add random public channel", () => addChannel(RNG.Next().ToString())); AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count())), 20); }
public TestCaseChannelTabControl() { SpriteText currentText; Add(new Container { RelativeSizeAxes = Axes.X, Origin = Anchor.Centre, Anchor = Anchor.Centre, Children = new Drawable[] { channelTabControl = new ChannelTabControl { RelativeSizeAxes = Axes.X, Origin = Anchor.Centre, Anchor = Anchor.Centre, Height = 50 }, new Box { Colour = Color4.Black.Opacity(0.1f), RelativeSizeAxes = Axes.X, Height = 50, Depth = -1, Origin = Anchor.Centre, Anchor = Anchor.Centre, } } }); Add(new Container { Origin = Anchor.TopLeft, Anchor = Anchor.TopLeft, Children = new Drawable[] { currentText = new SpriteText { Text = "Currently selected channel:" } } }); channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel); channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString(); AddStep("Add random private channel", addRandomPrivateChannel); AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2); AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3); AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5); AddStep("Add random public channel", () => addChannel(RNG.Next().ToString())); AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count() - 1)), 20); Channel channelBefore = channelTabControl.Items.First(); AddStep("set first channel", () => channelTabControl.Current.Value = channelBefore); AddStep("select selector tab", () => channelTabControl.Current.Value = channelTabControl.Items.Last()); AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value); AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value); AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First()); AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value); AddUntilStep(() => { var first = channelTabControl.Items.First(); if (first.Name == "+") { return(true); } channelTabControl.RemoveChannel(first); return(false); }, "remove all channels"); AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value); }