Channel selection - editable textbox, error icon

This commit is contained in:
pizzaboxer 2023-07-13 13:15:03 +01:00
parent 431c07ee07
commit 054379d4f0
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 70 additions and 68 deletions

View File

@ -42,17 +42,11 @@
<TextBlock FontSize="14" Text="Deployment channel" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Choose which release channel Roblox should be downloaded from." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
<ComboBox Grid.Column="1" Margin="8,0,8,0" Padding="10,5,10,5" Width="200" ItemsSource="{Binding Channels, Mode=OneWay}" SelectedItem="{Binding Channel, Mode=TwoWay}" Visibility="{Binding ChannelComboBoxVisibility, Mode=OneWay}" />
<ui:TextBox Grid.Column="1" Margin="8,0,8,0" Padding="10,5,10,5" Width="200" Text="{Binding Channel, Mode=TwoWay}" Visibility="{Binding ChannelTextBoxVisibility, Mode=OneWay}" KeyUp="TextBox_KeyEnterUpdate" />
<ComboBox Grid.Column="1" Margin="8,0,8,0" Padding="10,5,10,5" Width="200" IsEditable="True" ItemsSource="{Binding Channels, Mode=OneWay}" Text="{Binding SelectedChannel, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" KeyUp="ComboBox_KeyEnterUpdate" />
</Grid>
</ui:CardExpander.Header>
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Column="0" Margin="0,0,4,0">
<Grid Margin="0,0,4,0">
<Grid.Style>
<Style>
<Setter Property="Grid.Visibility" Value="Visible"/>
@ -97,12 +91,10 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:ProgressRing Grid.Column="0" Margin="6" IsIndeterminate="True" />
<ui:ProgressRing Grid.Column="0" Margin="6" IsIndeterminate="True" Visibility="{Binding LoadingSpinnerVisibility, Mode=OneWay}" />
<Image Grid.Column="0" Margin="6" Width="60" Height="60" Visibility="{Binding LoadingErrorVisibility, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Error.png" />
<TextBlock Grid.Column="1" Margin="16" VerticalAlignment="Center" Text="{Binding ChannelInfoLoadingText, Mode=OneWay}" />
</Grid>
<CheckBox Grid.Column="1" Margin="4,0,0,0" Content="Manually enter channel name" VerticalAlignment="Top" IsChecked="{Binding ManualChannelEntry, Mode=TwoWay}" />
</Grid>
</StackPanel>
</ui:CardExpander>

View File

@ -20,14 +20,14 @@ namespace Bloxstrap.UI.Menu.Pages
// https://stackoverflow.com/a/13289118/11852173
// yes this doesnt fully conform to xaml but whatever
private void TextBox_KeyEnterUpdate(object sender, KeyEventArgs e)
private void ComboBox_KeyEnterUpdate(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
TextBox tBox = (TextBox)sender;
DependencyProperty prop = TextBox.TextProperty;
ComboBox box = (ComboBox)sender;
DependencyProperty prop = ComboBox.TextProperty;
BindingExpression binding = BindingOperations.GetBindingExpression(tBox, prop);
BindingExpression binding = BindingOperations.GetBindingExpression(box, prop);
if (binding is not null)
binding.UpdateSource();

View File

@ -26,10 +26,14 @@ namespace Bloxstrap.UI.ViewModels.Menu
private async Task LoadChannelDeployInfo(string channel)
{
LoadingSpinnerVisibility = Visibility.Visible;
LoadingErrorVisibility = Visibility.Collapsed;
ChannelInfoLoadingText = "Fetching latest deploy info, please wait...";
OnPropertyChanged(nameof(ChannelInfoLoadingText));
ChannelDeployInfo = null;
OnPropertyChanged(nameof(LoadingSpinnerVisibility));
OnPropertyChanged(nameof(LoadingErrorVisibility));
OnPropertyChanged(nameof(ChannelInfoLoadingText));
OnPropertyChanged(nameof(ChannelDeployInfo));
try
@ -47,11 +51,19 @@ namespace Bloxstrap.UI.ViewModels.Menu
}
catch (Exception)
{
ChannelInfoLoadingText = "Failed to get deploy info.\nIs the channel name valid?";
LoadingSpinnerVisibility = Visibility.Collapsed;
LoadingErrorVisibility = Visibility.Visible;
ChannelInfoLoadingText = "Could not get deployment information. Is the channel name valid?";
OnPropertyChanged(nameof(LoadingSpinnerVisibility));
OnPropertyChanged(nameof(LoadingErrorVisibility));
OnPropertyChanged(nameof(ChannelInfoLoadingText));
}
}
public Visibility LoadingSpinnerVisibility { get; private set; } = Visibility.Visible;
public Visibility LoadingErrorVisibility { get; private set; } = Visibility.Collapsed;
public DeployInfo? ChannelDeployInfo { get; private set; } = null;
public string ChannelInfoLoadingText { get; private set; } = null!;
@ -69,12 +81,16 @@ namespace Bloxstrap.UI.ViewModels.Menu
public IEnumerable<string> Channels => RobloxDeployment.SelectableChannels;
public string Channel
public string SelectedChannel
{
get => App.Settings.Prop.Channel;
set
{
value = value.Trim();
if (String.IsNullOrEmpty(value))
value = RobloxDeployment.DefaultChannel;
Task.Run(() => LoadChannelDeployInfo(value));
App.Settings.Prop.Channel = value;
}
@ -90,20 +106,14 @@ namespace Bloxstrap.UI.ViewModels.Menu
if (!value)
{
// roblox typically sets channels in all lowercase, so here we find if a case insensitive match exists
string? matchingChannel = Channels.Where(x => x.ToLowerInvariant() == Channel.ToLowerInvariant()).FirstOrDefault();
Channel = string.IsNullOrEmpty(matchingChannel) ? RobloxDeployment.DefaultChannel : matchingChannel;
string? matchingChannel = Channels.Where(x => x.ToLowerInvariant() == SelectedChannel.ToLowerInvariant()).FirstOrDefault();
SelectedChannel = string.IsNullOrEmpty(matchingChannel) ? RobloxDeployment.DefaultChannel : matchingChannel;
}
OnPropertyChanged(nameof(Channel));
OnPropertyChanged(nameof(ChannelComboBoxVisibility));
OnPropertyChanged(nameof(ChannelTextBoxVisibility));
OnPropertyChanged(nameof(SelectedChannel));
}
}
// cant use data bindings so i have to do whatever tf this is
public Visibility ChannelComboBoxVisibility => ManualChannelEntry ? Visibility.Collapsed : Visibility.Visible;
public Visibility ChannelTextBoxVisibility => ManualChannelEntry ? Visibility.Visible : Visibility.Collapsed;
// todo - move to enum attributes?
public IReadOnlyDictionary<string, ChannelChangeMode> ChannelChangeModes => new Dictionary<string, ChannelChangeMode>
{