Skip to content

Commit

Permalink
Improve channel input selection handling
Browse files Browse the repository at this point in the history
input value is now trimmed, as well as input being processed on enter
  • Loading branch information
pizzaboxer committed Jun 28, 2023
1 parent fe885cb commit 991005c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Bloxstrap/UI/Menu/ViewModels/InstallationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;

using CommunityToolkit.Mvvm.Input;
Expand Down Expand Up @@ -65,9 +64,9 @@ private async Task LoadChannelDeployInfo(string channel)

private void BrowseInstallLocation()
{
using var dialog = new FolderBrowserDialog();
using var dialog = new System.Windows.Forms.FolderBrowserDialog();

if (dialog.ShowDialog() != DialogResult.OK)
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;

if (!dialog.SelectedPath.EndsWith(App.ProjectName))
Expand Down Expand Up @@ -96,6 +95,7 @@ public string Channel
get => App.Settings.Prop.Channel;
set
{
value = value.Trim();
Task.Run(() => LoadChannelDeployInfo(value));
App.Settings.Prop.Channel = value;
}
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Menu/Views/Pages/InstallationPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Choose which release channel to download Roblox 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}" />
<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" />
</Grid>
</ui:CardExpander.Header>
<StackPanel>
Expand Down
23 changes: 22 additions & 1 deletion Bloxstrap/UI/Menu/Views/Pages/InstallationPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Bloxstrap.UI.Menu.ViewModels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

using Bloxstrap.UI.Menu.ViewModels;

namespace Bloxstrap.UI.Menu.Views.Pages
{
Expand All @@ -12,5 +17,21 @@ public InstallationPage()
DataContext = new InstallationViewModel();
InitializeComponent();
}

// https://stackoverflow.com/a/13289118/11852173
// yes this doesnt fully conform to xaml but whatever
private void TextBox_KeyEnterUpdate(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
TextBox tBox = (TextBox)sender;
DependencyProperty prop = TextBox.TextProperty;

BindingExpression binding = BindingOperations.GetBindingExpression(tBox, prop);

if (binding is not null)
binding.UpdateSource();
}
}
}
}

0 comments on commit 991005c

Please sign in to comment.